-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditComment.php
More file actions
115 lines (101 loc) · 4.02 KB
/
EditComment.php
File metadata and controls
115 lines (101 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php require_once 'Include/Load.php';
$session = App::getSession();
$link = App::getDatabase();
$user = App::getUser();
$validator = App::getValidator();
$user->restrict();
if ($user->has('id')) {
$comment_id = App::get('id');
$comment = $link->query('SELECT * FROM comments WHERE id = :id', ['id' => $comment_id])->fetch();
if ($session->getKey('user_infos')->id !== $comment->user_id){
App::redirect('Posts.php');
}
if ($validator->isPosted()){
if (!empty($_FILES['commentPic'])) {
if ($_FILES['commentPic']['error'] == 0) {
if ($user->upLoadFile($_FILES['commentPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png'])) {
$current_image = $comment->image;
App::deleteFile($current_image, '/Uploads/Comments/');
$link->query('UPDATE comments SET content = :content, image = :image, modified_at = NOW() WHERE id = :id', [
'content' => $_POST['comment'],
'image' => basename($_FILES['commentPic']['name']),
'id' => $comment_id
]);
move_uploaded_file($_FILES['commentPic']['tmp_name'], 'Uploads/Comments/' . basename($_FILES['commentPic']['name']));
} else {
if (is_bool($user->upLoadFile($_FILES['commentPic'], 5242880, ['jpg', 'jpeg', 'gif', 'png']))) {
$session->setFlash('alert', 'Allowed File Extensions are: jpg, jpeg, gif, png');
} else {
$session->setFlash('alert', 'The File must not be more than 5Mo');
}
$link->query('UPDATE comments SET content = :content, modified_at = NOW() WHERE id = :id', [
'content' => $_POST['comment'],
'id' => $comment_id
]);
}
} else {
$current_image = $comment->image;
App::deleteFile($current_image, '/Uploads/Comments/');
$link->query('UPDATE comments SET content = :content, modified_at = NOW() WHERE id = :id', [
'content' => $_POST['comment'],
'id' => $comment_id
]);
}
} else {
$current_image = $comment->image;
App::deleteFile($current_image, '/Uploads/Comments/');
$link->query('UPDATE comments SET content = :content, modified_at = NOW() WHERE id = :id', [
'content' => $_POST['comment'],
'id' => $comment_id
]);
}
$session->setFlash('success', 'The Comment has successfully modified');
}
}
?>
<?php require_once 'Include/Header.php'; ?>
<?php if (!empty($errors)): ?>
<div class="error-msg">
<p>The Information were not filled correctly. These are the possible errors:</p>
<ul>
<?php foreach ($errors as $error): ?>
<li><?= $error ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<style>
.login-box .user-box textarea{
background: none;
color: white;
width: 100%;
padding: 5px;
height: 300px;
}
</style>
<div class="login-box">
<h2>Edit Comment</h2>
<form action="" method="post" enctype="multipart/form-data">
<div class="user-box">
<textarea name="comment" id="content" required><?= isset($comment) ? $comment->content : '' ?></textarea>
</div>
<div class="user-box">
<input type="file" name="commentPic">
<label></label>
</div>
<button type="submit">Submit</button>
</form>
</div>
<?php require_once 'Include/Mode.php' ?>
</body>
</html>