This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
94 lines (84 loc) · 2.78 KB
/
edit.php
File metadata and controls
94 lines (84 loc) · 2.78 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
<?php
include 'include/header.php';
?>
<div class="container mt-3">
<?php
if ($_GET) {
$forum_id = $_GET['forum'];
$category_id = $_GET['category'];
$topic_id = $_GET['topic'];
$post_id = $_GET['post'];
$forum = $database->prepare("SELECT * FROM forums WHERE id = ?;");
$forum->execute(array($forum_id));
$category = $database->prepare("SELECT * FROM categories WHERE id = ?;");
$category->execute(array($category_id));
$topic = $database->prepare("SELECT * FROM topics WHERE id = ?;");
$topic->execute(array($topic_id));
$post = $database->prepare("SELECT * FROM posts WHERE id = ?;");
$post->execute(array($post_id));
$post_row = $post->fetch(PDO::FETCH_OBJ);
$error = '';
if (empty($forum_id) || empty($category_id) || empty($post_id) || empty($topic_id)) {
$error = 'Podane forum, kategoria, temat lub post nie istnieje!';
} else if ($forum->rowCount() <= 0) {
$error = 'Podane forum nie istnieje!';
} else if ($category->rowCount() <= 0) {
$error = 'Podana kategoria nie istnieje!';
} else if ($post->rowCount() <= 0) {
$error = 'Podany post nie istnieje!';
} else if ($topic->rowCount() <= 0) {
$error = 'Podany temat nie istnieje!';
}
if (empty($error)) {
if (USER_ID) {
if (isset($_POST['post'])) {
$content = $_POST['content'];
$post_error = [];
if (empty($content)) {
$post_error = 'Uzupełnij treść tematu!';
} else if (strlen($content) < 12) {
$post_error = 'Treść tematu jest zbyt krótka! Minimalna długość to 12 znaki';
} else if (strlen($content) > 64000) {
$post_error = 'Treść tematu jest zbyt długa! Maksymalna długość to 64,000 znaki.';
}
if (empty($post_error)) {
$edit_post = $database->prepare("UPDATE posts SET content = ?, modified = NOW() WHERE id = ?;");
$edit_post->execute(array($content, $post_id));
alert('success', 'Post został edytowany.');
header("refresh:2;url={$config['default']['link']}topic.php?forum=$forum_id&category=$category_id&topic=$topic_id");
} else {
alert('danger', $post_error);
}
}
?>
<div class="card mb-3">
<div class="card-body">
<form method="post">
<h5>Edycja posta</h5>
<hr>
<textarea name="content" class="form-control" placeholder="Treść posta..." rows="6">
<?= $post_row->content ?>
</textarea>
<br>
<button name="post" class="btn btn-outline-primary btn-block">Zatwierdź</button>
</form>
<script>
CKEDITOR.replace('content');
</script>
</div>
</div>
<?php
} else {
alert("danger", "Musisz być zalogowany aby edytować post!");
}
} else {
alert('danger', $error);
}
} else {
alert("danger", "Podane forum, kategoria, temat lub post nie istnieje!");
}
?>
</div>
<?php
include 'include/footer.php';
?>