-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.php
264 lines (259 loc) · 15.5 KB
/
news.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
<?php
session_start();
require 'db/db.php';
$status ="";
if(isset($_POST['cmnt_submit'])){
if(!isset($_SESSION['username'])){
$status = "00";
}
else{
$comment = $_POST['comment'];
$news_id = $_REQUEST['id'];
$user = $_SESSION['username'];
$date = date("Y-m-d H:i:s");
$sql = "INSERT INTO comments (newsId, personName, cmnt, created_on) VALUES ('$news_id', '$user', '$comment', '$date')";
$result = mysqli_query($db, $sql);
if($result){
$status = "1";
}
else{
$status = "0";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>News</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid ">
<a class="navbar-brand border border-dark border-3 rounded px-2" href="index.php"><b>Online News Portal</b></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<!-- <li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li> -->
<?php
if (isset($_SESSION["username"])) {
if ($_SESSION["username"] == "admin") { ?>
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle " href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dashboard
</a>
<ul class="dropdown-menu text-center" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="admin/newsDashboard.php">View News</a></li>
<li><a class="dropdown-item" href="admin/insertData.php">Insert News</a></li>
</ul>
</li>
<?php
}
}
if (isset($_SESSION["username"])) { ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Welcome <strong class="text-black"><?php echo $_SESSION["username"]; ?></strong>
</a>
<ul class="dropdown-menu bg-danger" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item bg-danger text-white fw-bold text-center" href="index.php?logout='1'">logout</a></li>
</ul>
</li>
<?php
}
else { ?>
<li class="nav-item">
<a class="btn btn-outline-primary fw-bold" class="nav-link text-primary" href="login.php">Login</a>
</li>
<?php
}
?>
</div>
</div>
</nav>
<div class="row mt-3">
<div class="col-md-2"></div>
<div class="col-md-8">
<?php require "db/db.php";
$news_query = "select * from news where id='".$_REQUEST['id']."'";
$result = mysqli_query($db, $news_query);
$row = mysqli_fetch_assoc($result);
?>
<div class="row-md-12 fs-6 px-3">
<div class="col-12 align-self-center">
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar-event-fill" viewBox="0 0 16 16">
<path d="M4 .5a.5.5 0 0 0-1 0V1H2a2 2 0 0 0-2 2v1h16V3a2 2 0 0 0-2-2h-1V.5a.5.5 0 0 0-1 0V1H4V.5zM16 14V5H0v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2zm-3.5-7h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5z"/>
</svg> <?= substr($row['create_datetime'],0, 10); ?>
</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71V3.5z"/>
</svg> <?= substr($row['create_datetime'],11, 5); ?>
</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-tags-fill" viewBox="0 0 16 16">
<path d="M2 2a1 1 0 0 1 1-1h4.586a1 1 0 0 1 .707.293l7 7a1 1 0 0 1 0 1.414l-4.586 4.586a1 1 0 0 1-1.414 0l-7-7A1 1 0 0 1 2 6.586V2zm3.5 4a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z"/>
<path d="M1.293 7.793A1 1 0 0 1 1 7.086V2a1 1 0 0 0-1 1v4.586a1 1 0 0 0 .293.707l7 7a1 1 0 0 0 1.414 0l.043-.043-7.457-7.457z"/>
</svg> <?= $row['category']; ?>
</span>
</div>
</div>
<div class="row-md-12 mt-2 text-uppercase text-capitalize text-justify">
<h1 class="col-12 align-self-center shadow p-3 bg-body rounded">
<?= $row['headline']; ?>
</>
</div>
<div class="row-md-12 mt-2">
<img
src="data:image/jpg;charset=utf8;base64,<?php echo base64_encode($row['headIMG']); ?>"
class="card-img-top rounded"
alt="..."
style="
object-fit: cover;
object-position: center;
width: 100%;
/* max-height: 300px; */
margin-bottom: 1rem;"
/>
</div>
<?php
if($row['create_datetime'] != $row['updated_datetime']){
?>
<div class="row-md-12 fs-6 px-3 fst-italic fw-light">
<div class="col-12 align-self-center">
<span>Updated:</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar-event-fill" viewBox="0 0 16 16">
<path d="M4 .5a.5.5 0 0 0-1 0V1H2a2 2 0 0 0-2 2v1h16V3a2 2 0 0 0-2-2h-1V.5a.5.5 0 0 0-1 0V1H4V.5zM16 14V5H0v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2zm-3.5-7h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5z"/>
</svg> <?= substr($row['updated_datetime'],0, 10); ?>
</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71V3.5z"/>
</svg> <?= substr($row['updated_datetime'],11, 5); ?>
</span>
</div>
</div>
<?php
}
?>
<div class="row-md-12 fs-5 mt-2 open-sans-font pb-2 shadow-lg p-3 mb-5 bg-body rounded" style="text-align: justify;">
<?= nl2br($row['content']); ?>
</div>
<div class="row-md-12 mt-4 text-justify">
<div class="col-12">
<div class="row-md-12 fs-2 mb-4 border border-dark border-3 rounded px-2 text-center text-uppercase text-capitalize fw-bold">Comments</div>
<?php
require "db/db.php";
($query = mysqli_query($db,
"Select * from comments where newsId='".$_REQUEST['id']."' "
)) or die(mysqli_error());
while($comment = mysqli_fetch_assoc($query)){
?>
<figure class="shadow-sm p-3 mb-4 bg-body rounded">
<blockquote class="blockquote fs-4">
<p><?= $comment['cmnt'] ?></p>
</blockquote>
<figcaption class="blockquote-footer">
<cite title="Source Title">
<span>
<?= $comment['personName'] ?>
</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar-event-fill" viewBox="0 0 16 16">
<path d="M4 .5a.5.5 0 0 0-1 0V1H2a2 2 0 0 0-2 2v1h16V3a2 2 0 0 0-2-2h-1V.5a.5.5 0 0 0-1 0V1H4V.5zM16 14V5H0v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2zm-3.5-7h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5z"/>
</svg> <?= substr($comment['created_on'],0, 10); ?>
</span>
<span> </span>
<span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71V3.5z"/>
</svg> <?= substr($comment['created_on'],11, 8); ?>
</span>
</cite> <span> </span>
<?php if(isset($_SESSION['username']) && $comment['personName'] == $_SESSION['username']){ ?>
<span>
<a class="btn btn-danger btn-sm" onclick="return confirm('Do You Want to Delete The Comment?')" href="deleteComment.php?id=<?= $_REQUEST['id']; ?>&cmnt_id=<?= $comment['id']; ?>"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
</svg></a>
</span>
<?php } ?>
</figcaption>
</figure>
<?php
}
?>
<div class="row-md-12 mb-3 shadow-lg p-3 mb-3 bg-body rounded">
<form action="" method="post">
<div class="form-group">
<label for="comment" class="fw-bold fs-4">Comment</label>
<textarea class="form-control mb-3" id="comment" rows="3" name="comment" placeholder="Enter your comment" required></textarea>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary" name="cmnt_submit">Submit</button>
</div>
</form>
</div>
<?php if($status != ""){
if($status == "1"){ ?>
<div class="alert alert-success text-center" role="alert">
Comment Posted Successfully
</div>
<?php
} elseif($status == "00"){
?>
<div class="alert alert-danger text-center" role="alert">
You Must Be Login to Comment
</div>
<?php
} else{
?>
<div class="alert alert-warning text-center" role="alert">
Please Try Again Latter
</div>
<?php
} }
?>
</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
</div>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<script
src="js/jquery-3.5.1.slim.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"
integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
crossorigin="anonymous"
></script>
</body>
</html>