-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog-post.php
278 lines (241 loc) · 10.7 KB
/
blog-post.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php include "classes.php" ?>
<?php
$customerId = SessionManager::getCustomerId() == 0 ? null : SessionManager::getCustomerId();
$securityuserid = SessionManager::getSecurityUserId() == 0 ? null : SessionManager::getSecurityUserId();
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST["btnDelete"])){
if(is_numeric($_POST["btnDelete"])){
Blog::remove($_POST["btnDelete"]);
header("location: blog-home.php");
}
}
$returnVal = true;
if(isset($_POST["btnPostComment"])){
isset($_POST["comment"]) && $_POST["comment"] != "" ? $comment = $_POST["comment"] : $returnVal = false;
isset($_POST["hfBlogId"]) && $_POST["hfBlogId"] != "" ? $blogid = $_POST["hfBlogId"] : $returnVal = false;
$currentDate = date('Y-m-d H:i:s');
if($returnVal){
$blogcomment = new Blogcomment(0,$comment,$customerId,1,$blogid,$currentDate, null);
$blogcomment->save();
header("location: blog-post.php?id=$blogid");
}
}
}
if($_SERVER["REQUEST_METHOD"] == "GET"){
if(isset($_GET["id"]) && is_numeric($_GET["id"]) && $_GET["id"] > 0){
$blog = new Blog($_GET["id"]);
if($blog != null){
}
else{
header("location: index.php");
}
}
else{
header("location: index.php");
}
}
$blogCommentList = Blogcomment::loadbyblogid($blog->getId());
?>
<!DOCTYPE html>
<html lang="en">
<?php include "head.php" ?>
<body>
<!-- Navigation -->
<?php include "navbar.php" ?>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<h1 class="mt-4 mb-3">
<?php echo $blog->getTitle() ?>
<small>by
<a href="#">
<?php
$user = new Securityuser($blog->getSecurityUserId());
echo $user->getUsername();
?>
</a>
</small>
</h1>
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="index.php">Home</a>
</li>
<li class="breadcrumb-item">
<a href="blog-home.php">Blog</a>
</li>
<li class="breadcrumb-item active"><?php echo $blog->getTitle() ?></li>
</ol>
<div class="row">
<!-- Post Content Column -->
<div class="col-lg-8">
<!-- Preview Image -->
<img class="img-fluid rounded" src="<?php echo $blog->getImgUrl() ?>" alt="">
<hr>
<!-- Date/Time -->
<p>Posted on <?php echo date_format(date_create($blog->getCreateDate()), 'g:ia \o\n l jS F Y') ?></p>
<hr>
<!-- Post Content -->
<p>
<?php echo nl2br($blog->getDescription()) ?>
</p>
<hr>
<?php
if(!empty($blogCommentList)){
?>
<h3 class="text-center">Comments</h3>
<br>
<?php
foreach ($blogCommentList as $blogcomment){
$customer = new Customer($blogcomment->getCustomerId());
?>
<!-- Single Comment -->
<div class="media mb-4">
<div class="media-body">
<?php
if($securityuserid > 0 || $customerId == $blogcomment->getCustomerId()){
?>
<form method="post">
<input type="hidden" name="hfEventId" value="<?php echo $blog->getId() ?>">
<button type="submit" name="btnDeleteComment" value="<?php echo $blogcomment->getId() ?>" class="btn btn-outline-danger pull-right">Delete</button>
</form>
<?php
}
?>
<h5 class="mt-0 mb-0"><?php echo $customer->getFirstName()." ".$customer->getLastName() ?></h5>
<?php echo $blogcomment->getComment(); ?>
<br>
<small>Posted on <?php echo date_format(date_create($blogcomment->getCreateDate()), 'g:ia \o\n l jS F Y') ?></small>
</div>
</div>
<?php
}
}
if($customerId != null && $customerId > 0){
?>
<!-- Comments Form -->
<b class="lead">Leave a Comment:</b>
<form method="post">
<div class="form-group">
<textarea name="comment" class="form-control" rows="3" required></textarea>
</div>
<button name="btnPostComment" id="btnPostComment" type="submit" class="btn btn-primary">Submit</button>
<input type="hidden" name="hfBlogId" value="<?php echo $blog->getId() ?>">
</form>
<?php
}
else{
?>
<div class="alert alert-warning" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="alert-heading">Hold up!</h5>
<p>Please <a href="login.php">Login</a> or <a href="create-customer.php">register</a> to comment on an blog.</p>
<hr>
<div class="btn-group">
<a class="btn btn-primary" href="login.php">Login</a>
<a class="btn btn-default" href="create-customer.php">Register</a>
</div>
</div>
<?php
}
?>
<!-- Comment with nested comments
<div class="media mb-4">
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
<div class="media-body">
<h5 class="mt-0">Commenter Name</h5>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
<div class="media mt-4">
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
<div class="media-body">
<h5 class="mt-0">Commenter Name</h5>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
<div class="media mt-4">
<img class="d-flex mr-3 rounded-circle" src="http://placehold.it/50x50" alt="">
<div class="media-body">
<h5 class="mt-0">Commenter Name</h5>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
</div>
</div>
</div>
</div> -->
</div>
<!-- Sidebar Widgets Column -->
<div class="col-md-4">
<?php
if($securityuserid > 0){
?>
<div class="dropdown show mb-2">
<a class="btn btn-secondary dropdown-toggle btn-block" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Manage Blog
</a>
<div class="dropdown-menu w-100" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="create-blog.php?id=<?php echo $blog->getId(); ?>&cmd=edit">Edit</a>
<form method="post">
<button name="btnDelete" class="dropdown-item" value="<?php echo $blog->getId()?>">Delete</button>
</form>
</div>
</div>
<?php
}
?>
<!-- Categories Widget -->
<div class="card my-4">
<h5 class="card-header">Categories</h5>
<div class="card-body">
<div class="row">
<?php
$blogCategoryLiat = Blogcategory::loadall();
if(!empty($blogCategoryLiat)){
foreach ($blogCategoryLiat as $bc) {
?>
<div class="col-lg-6">
<a href="blog-home.php?id=<?php echo $bc->getId() ?>"><?php echo $bc->getName() ?></a>
<?php
if($securityuserid > 0){
?>
<a href="create-type.php?cmd=edit&type=blogcategory&id=<?php echo $bc->getId() ?>" class="text-danger"><i class="icon-pencil"></i></a>
<?php
}
?>
</div>
<?php
}
}
?>
</div>
</div>
</div>
<!-- Side Widget -->
<div class="card my-4">
<h5 class="card-header">Side Widget</h5>
<div class="card-body">
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!
</div>
</div>
<!-- Search Widget
<div class="card mb-4">
<h5 class="card-header">Search</h5>
<div class="card-body">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</div>
</div> -->
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<!-- Footer -->
<?php include "footer.php" ?>
<!-- Bootstrap core JavaScript -->
<?php include "scripts.php" ?>
</body>
</html>