-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_post.php
More file actions
81 lines (73 loc) · 3.62 KB
/
update_post.php
File metadata and controls
81 lines (73 loc) · 3.62 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
<?php
require_once './header.php';
if (isset($_POST['post_btn_submit_update'])) {
$request = new PostRequest($_POST);
Post::updatePost($connection, $request, $_POST['id']);
if (Auth::user()->user_type == 'admin') {
redirect('admin');
} else {
redirect('posts');
}
} elseif (isset($_POST['post_btn_submit_publish'])) {
Post::publishPost($connection, $_POST['id']);
redirect('admin');
} else {
$post = Post::findPostById($connection, $_GET['id']);
}
?>
<section class="section">
<div class="section-body">
<div class="row">
<div class="col-12">
<div class="card mb-0">
<div class="card-body">
<h4 class="m-0">Update Post</h4>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-12">
<div class="card">
<div class="card-body">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<?php echo $post->id; ?>">
<div class="form-group row mb-4">
<label class="col-form-label text-md-right col-12 col-md-3 col-lg-3">Title</label>
<div class="col-sm-12 col-md-7">
<input type="text" class="form-control" name="title" value="<?php echo $post->title; ?>">
</div>
</div>
<div class="form-group row mb-4">
<label class="col-form-label text-md-right col-12 col-md-3 col-lg-3">Category</label>
<div class="col-sm-12 col-md-7">
<select class="form-control" name="category">
<option <?php selected('Tech', $post->category); ?>>Tech</option>
<option <?php selected('News', $post->category); ?>>News</option>
<option <?php selected('Political', $post->category); ?>>Political</option>
</select>
</div>
</div>
<div class="form-group row mb-4">
<label class="col-form-label text-md-right col-12 col-md-3 col-lg-3">Content</label>
<div class="col-sm-12 col-md-7">
<textarea class="summernote-simple" name="body"> <?php echo $post->body ?></textarea>
</div>
</div>
<div class="form-group row mb-4">
<label class="col-form-label text-md-right col-12 col-md-3 col-lg-3"></label>
<div class="col-sm-12 col-md-7">
<button type="submit" class="btn btn-primary" name="post_btn_submit_update">Update Post</button>
<?php if (Auth::getRole() == 'admin') { ?>
<button type="submit" class="btn btn-info" name="post_btn_submit_publish">Publish Post</button>
<?php } ?>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include './footer.php'; ?>