forked from MariusTBjercke/BlizzlikeCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_posts.php
executable file
·106 lines (93 loc) · 3.11 KB
/
edit_posts.php
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
<?php
$pagenum = 1;
if(!empty($_GET['pagenum'])) {
$pagenum = filter_input(INPUT_GET, 'pagenum', FILTER_VALIDATE_INT);
if(false === $pagenum) {
$pagenum = 1;
}
}
if (isset($_GET['id'])) {
$post_id = $_GET['id'];
}
?>
<h1>Edit posts</h1>
<?php
if (!empty($_GET['action'])) {
?>
<button onclick="window.location='admin.php?page=edit_posts';">Go back</button>
<?php
} else {
?>
<button onclick="window.location='admin.php';">Go back</button>
<?php
}
if ($_GET['action'] == 'edit') {
$post = new Post($post_id);
// Save details on submit
if (isset($_POST['submit'])) {
$title = $_POST['title'];
$content = $_POST['content'];
$result = $post->saveDetails($title, $content);
if ($result == true) {
echo '<script>alert("The details have been saved.");</script>';
echo '<script>history.back(1);</script>';
} else {
echo '<script>alert("Something went wrong, please try again.");</script>';
echo '<script>history.back(1);</script>';
}
}
$post->getPost();
?>
<div class="edit_post">
<form action="" method="post">
<p><label>Title</label><br><input type="text" value="<?php echo $post->getTitle(); ?>" name="title"></p>
<p><label>Content</label><br><textarea class="tinymce" name="content"><?php echo
$post->getContent();
?></textarea></p>
<p><input type="submit" name="submit" value="Save"></p>
</form>
</div>
<?php
} else if ($_GET['action'] == 'add_post') {
// Save details on submit
if (isset($_POST['addPost_submit'])) {
$admin = new Admin;
$title = $_POST['title'];
$content = $_POST['content'];
$result = $admin->addPost($title, $content);
if ($result == true) {
echo '<script>alert("The details have been saved.");</script>';
echo '<script>window.location="admin.php?page=edit_posts";</script>';
} else {
echo '<script>alert("Something went wrong, please try again.");</script>';
echo '<script>history.back(1);</script>';
}
}
?>
<div class="add_post">
<form action="" method="post">
<p><label>Title</label><br><input type="text" name="title"></p>
<p><label>Content</label><br><textarea class="tinymce" name="content"></textarea></p>
<p><input type="submit" name="addPost_submit" value="Save"></p>
<?php echo $admin->getPosterId(); ?>
</form>
</div>
<?php
} else if ($_GET['action'] == 'delete') {
$del_id = $_GET['id'];
$post = new Post($del_id);
$result = $post->deletePost();
if ($result == true) {
echo '<script>history.back(1);</script>';
} else {
echo '<script>alert("Something went wrong, please try again.");</script>';
echo '<script>history.back(1);</script>';
}
} else {
?>
<button onclick="window.location='admin.php?page=edit_posts&action=add_post';">Add a new post</button>
<?php
$admin = new Admin();
$admin->showPosts($pagenum);
}
?>