-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
299 lines (227 loc) · 8.64 KB
/
admin.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
// session_start();
// session_destroy();
// if (!(isset($_SESSION['auth']) && $_SESSION['auth'] === true)) {
// header("Location: admin.php?access=false");
// exit();
// }
// else {
// $admin = $_SESSION['admin'];
// }
require 'includes/snippet.php';
require 'includes/db-inc.php';
include "includes/header.php";
// if(isset($_SESSION['admin'])){
// $admin = $_SESSION['admin'];
// // echo "Hello $user";
// }
if(isset($_POST['submit'])){
$news = sanitize(trim($_POST['news']));
$sql = "INSERT into news (announcement) values ('$news')";
$query = mysqli_query($conn,$sql);
$error = false;
if($query){
$error = true;
}
else{
echo "<script>alert('Not successful!! Try again.');
</script>";
}
}
if(isset($_POST['UpDat'])){
$id = sanitize(trim($_POST['id']));
$text = sanitize(trim($_POST['text']));
$sql_up = "UPDATE news set announcement = '$text' where newsId = '$id'";
echo mysqli_error($sql_up);
$result = mysqli_query($conn,$sql_del);
if ($result)
{
echo "<script>
alert('Update successful');
</script>";
}
}
if(isset($_POST['del'])){
$id = sanitize(trim($_POST['id']));
$sql_del = "DELETE from news where newsId = $id";
$result = mysqli_query($conn,$sql_del);
if ($result)
{
// echo "<script>
// var response = confirm('Would you like to delete the user');
// if (response == true) {
// alert('User was successfully deleted from the database');
// location.href ='admin.php';
// }
// else
// {
// alert('Could not delete user');
// }
// </script>";
}
}
?>
<div class="container">
<?php include "includes/nav.php"; ?>
<!-- navbar ends -->
<!-- info alert -->
<div class="alert alert-warning col-lg-7 col-md-12 col-sm-12 col-xs-12 col-lg-offset-2 col-md-offset-0 col-sm-offset-1 col-xs-offset-0" style="margin-top:70px">
<h4 class="center-block"><strong> Welcome</strong> <span>
<?php echo $admin; ?></span> </h4>
</div>
</div>
<div class="container">
<div class="panel panel-default">
<?php if(isset($error)===true) { ?>
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Record Updated Successfully!</strong>
</div>
<?php } ?>
<!-- Default panel contents -->
<div class="panel-heading">
<div class="row">
<h3 class="center-block">Published Announcements</h3>
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>NewsId</th>
<th>Announcement</th>
<th>Delete</th>
</tr>
</thead>
<?php
$sql2 = "SELECT * from news";
$query2 = mysqli_query($conn, $sql2);
$counter = 1;
while ($row = mysqli_fetch_array($query2)) { ?>
<tbody>
<td><?php echo $counter++; ?></td>
<td><?php echo $row['announcement']; ?></td>
<form method='post' action='admin.php'>
<input type='hidden' value="<?php echo $row['newsId']; ?>" name='id'>
<td><button name='del' type='submit' value='Delete' class='btn btn-warning' onclick='return Delete()'>DELETE</button></td>
</form>
</tbody>
<?php }
?>
</tbody>
</table>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title center-block">Publish New Announcements</h2>
</div>
<div class="panel-body">
<form role="form" action="admin.php" method="post">
<div class="input-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group ">
<label for="name">Announcement</label>
<textarea class="form-control" rows="3" draggable="false" name="news">
</textarea>
</div>
</div><br>
<div class="input-group pull-right">
<div class="form-group">
<button class="btn btn-primary" name="submit">SUBMIT</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Confirm delete modal begins here -->
<div class="mod modal fade" id="popUpWindow">
<div class="modal-dialog">
<div class="modal-content">
<!-- header begins here -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title"> Warning</h3>
</div>
<!-- body begins here -->
<div class="modal-body">
<p>Are you sure you want to delete this book?</p>
</div>
<!-- button -->
<div class="modal-footer ">
<button class="col-lg-4 col-sm-4 col-xs-6 col-md-4 btn btn-warning pull-right" style="margin-left: 10px" class="close" data-dismiss="modal">
No
</button>
<button class="col-lg-4 col-sm-4 col-xs-6 col-md-4 btn btn-success pull-right" class="close" data-dismiss="modal" data-toggle="modal" data-target="#info">
Yes
</button>
</div>
</div>
</div>
</div>
<!-- Confirm delete modal ends here -->
<!-- delete message modal starts here -->
<div class="modal fade" id="info">
<div class="modal-dialog">
<div class="modal-content">
<!-- header begins here -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title"> Warning</h3>
</div>
<!-- body begins here -->
<div class="modal-body">
<p>Book deleted <span class="glyphicon glyphicon-ok"></span></p>
</div>
</div>
</div>
</div>
<!-- delete message modal ends here -->
<!-- update modal begins here -->
<div class="modal fade" id="update">
<div class="modal-dialog">
<div class="modal-content">
<!-- header begins here -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title"> Update</h2>
</div>
<!-- body begins here -->
<form role="form" action="admin.php" method="post" enctype="multipart/form-data">
<div class="modal-body">
<div class="input-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> -->
<label for="name">Enter Id </label>
<input type="text" name="id" value=" <?php
echo $row['newsId'];
?>
">
<div class="form-group ">
<label for="name">Announcement</label>
<textarea class="form-control" rows="3" draggable="false" name="text" value="
">
</textarea>
</div>
</div>
</div>
<!-- button -->
<div class="modal-footer">
<button name ="UpDat" class="col-lg-12 col-sm-12 col-xs-12 col-md-12 btn btn-success" data-target="alert">
UPDATE
</button>
</div>
</form>
</div>
</div>
</div>
<!-- update modal ends here -->
<script type="text/javascript">
function Delete() {
return confirm('Would you like to delete the news');
}
function Update() {
return confirm('Would you like to update the news');
}
</script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</body>
</html>