/
account.php
478 lines (473 loc) · 19.6 KB
/
account.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<?php
include('includes/config.php');
$iNew = new iNew_dbConnect();
if(!isset($_SESSION['ses_id']) || $_SESSION['acctype'] != 0){
echo "<script>location.href='/';</script>";
exit();
}
?>
<?php include('header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">
Welcome
</div>
<div class="panel-body">
NAME : <?php echo $iNew->esc($_SESSION['fname'])." ".$iNew->esc($_SESSION['lname']); ?><br>
Account Type : <?php if($_SESSION['acctype'] == 0) { echo "<font color='#ea6153'>Administrator</font>"; } else if ($_SESSION['acctype'] == 1) { echo "<font color='#9b59b6'>Professor</font>"; } else { echo "<font color='#2ecc71'>Student</font>"; } ?>
<?php
if($_SESSION['acctype'] == 2){
?>
Course : <?php echo $iNew->esc($_SESSION['course']); ?>
<?php
}
?>
</div>
</div>
</div>
<div class="col-md-8">
<?php
if(isset($_GET['prof']) && $iNew->esc($_GET['id'])){
if(isset($_GET['delete'])){
$delete = $iNew->dbCon->prepare("DELETE FROM `gs_users` WHERE `id` = :id AND `acctype` = :acctype");
$delete->execute(array("id" => $iNew->esc($_GET['id']), "acctype" => 1));
if($delete->rowCount() > 0){
?>
<div class="alert alert-danger">Account Deleted.</div>
<script type="text/javascript">
setTimeout(function(){
location.href="/account.php?prof";
},3000);
</script>
<?php
}
else {
?>
<div class="alert alert-danger">Account doesn`t exist.<a href="/account.php?prof">Click Here</a> to get back.</div>
<?php
}
}
else {
$profS = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `id` = :id AND `acctype` = :acctype");
$profS->execute(array('id' => $iNew->esc($_GET['id']), 'acctype' => 1));
if($profS->rowCount() > 0){
$dataP = $profS->fetch();
$username = $iNew->esc($dataP['username']);
$fname = $iNew->esc($dataP['fname']);
$lname = $iNew->esc($dataP['lname']);
$course = $iNew->esc($dataP['course']);
?>
<div class="panel panel-info">
<div class="panel-heading">
Edit <font color="#e74c3c"><?php echo $fname; ?> <?php echo $lname; ?></font>`s Account
</div>
<div class="panel-body">
<form class="editInstructor" data-id="<?php echo $iNew->esc($_GET['id']); ?>">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" value="<?php echo $fname ?>" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" value="<?php echo $lname ?>" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" value="<?php echo $username ?>" placeholder="Username" required disabled>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
<a href="account.php?prof" class="btn btn-warning">Back to Professor`s Account list</a>
<a href="account.php?prof&delete&id=<?php echo $iNew->esc($_GET['id']); ?>" class="btn btn-danger" onclick="return confirm('Do you really want to delete it?');">Delete</a>
<button type="submit" class="btn btn-primary editInstructorButt">Edit</button>
</form>
</div>
</div>
<?php
}
else {
echo '<div class="alert alert-danger">This account doesn`t exist. <a href="/account.php?prof">Click here</a> to get back.</div>';
}
}
}
else if(isset($_GET['student']) && $iNew->esc($_GET['id'])){
if(isset($_GET['delete'])){
$delete = $iNew->dbCon->prepare("DELETE FROM `gs_users` WHERE `id` = :id AND `acctype` = :acctype");
$delete->execute(array("id" => $iNew->esc($_GET['id']), "acctype" => 2));
if($delete->rowCount() > 0){
?>
<div class="alert alert-danger">Account Deleted.</div>
<script type="text/javascript">
setTimeout(function(){
location.href="/account.php?student";
},3000);
</script>
<?php
}
else {
?>
<div class="alert alert-danger">Account doesn`t exist.<a href="/account.php?student">Click Here</a> to get back.</div>
<?php
}
}
else {
$selectS = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `id` = :id AND `acctype` = :acctype");
$selectS->execute(array("id"=>$iNew->esc($_GET['id']),"acctype"=>2));
if($selectS->rowCount() > 0){
$dataS = $selectS->fetch();
$fname = $iNew->esc($dataS['fname']);
$lname = $iNew->esc($dataS['lname']);
$username = $iNew->esc($dataS['fname']);
$course = $iNew->esc($dataS['course']);
?>
<div class="panel panel-info">
<div class="panel-heading">
Edit <font color="#e74c3c"><?php echo $fname; ?> <?php echo $lname; ?></font>`s Account
</div>
<div class="panel-body">
<form class="editStudent" data-id="<?php echo $iNew->esc($_GET['id']); ?>">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" value="<?php echo $fname ?>" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" value="<?php echo $lname ?>" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" value="<?php echo $username ?>" placeholder="Username" required disabled>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
<div class="form-group">
<label for="password">Password</label>
<select id="course" class="form-control">
<option value="<?php echo $course; ?>">
<?php
if($course == "BS-IT"){
echo "BS in Information Technology";
}
else if ($course == "BS-CS"){
echo "BS in Computer Science";
}
else if ($course == "BS-HRM"){
echo "BS in Hotel & Restaurant Management";
}
else if ($course == "BS-BA"){
echo "Bachelor of Science in Business Administration";
}
else{
echo "Bachelor of Science in Accountancy";
}
?>
</option>
<option value="BS-IT">BS in Information Technology</option>
<option value="BS-CS">BS in Computer Science</option>
<option value="BS-HRM">BS in Hotel & Restaurant Management</option>
<option value="BS-BA">Bachelor of Science in Business Administration</option>
<option value="BS-A">Bachelor of Science in Accountancy</option>
</select>
</div>
<a href="account.php?student" class="btn btn-warning">Back to Student`s Account list</a>
<a href="account.php?student&delete&id=<?php echo $iNew->esc($_GET['id']); ?>" class="btn btn-danger" onclick="return confirm('Do you really want to delete it?');">Delete</a>
<button type="submit" class="btn btn-primary editStudentButt">Edit</button>
</form>
</div>
</div>
<?php
}
else {
echo '<div class="alert alert-danger">This account doesn`t exist. <a href="/account.php?student">Click here</a> to get back.</div>';
}
}
}
else if (isset($_GET['prof'])){
?>
<!-- List of Professor`s Account -->
<div class="panel panel-info">
<div class="panel-heading">
List of Professor`s Account <button class="btn btn-success pull-right" data-toggle="modal" data-target="#addInstructor">Add</button>
<div style="clear:both"></div>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead style="font-weight:bolder">
<tr>
<td>Instructor</td>
<td>Action</td>
</tr
> </thead>
<tbody>
<?php
$profL = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `acctype` = ? ORDER BY `id` ASC LIMIT 10");
$profL->bindValue(1,1);
$profL->execute();
foreach ($profL->fetchAll() as $profInfo => $a) {
?>
<tr>
<td><a href="account.php?prof&id=<?php echo $a['id']; ?>"><?php echo $iNew->esc($a['fname'])." ".$iNew->esc($a['lname']); ?>(<?php echo $iNew->esc($a['username']); ?>)</a></td>
<td><a href="/account.php?prof&delete&id=<?php echo $a['id']; ?>" onclick="return confirm('Do you really want to delete it?');">Delete</a>|<a href="/account.php?prof&id=<?php echo $a['id']; ?>">Edit</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Add Instructor Modal -->
<div class="modal fade" id="addInstructor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Instructor</h4>
</div>
<div class="modal-body">
<form class="addInstructor">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" placeholder="Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary addInstructorButt">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
else if(isset($_GET['student'])){
?>
<!-- List of Student`s Accounts -->
<div class="panel panel-info">
<div class="panel-heading">
List of Student`s Account <button class="btn btn-success pull-right" data-toggle="modal" data-target="#addStudent">Add</button>
<div style="clear:both"></div>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead style="font-weight:bolder">
<tr>
<td>Student Name</td>
<td>Action</td>
</tr
> </thead>
<tbody>
<?php
$profL = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `acctype` = ? ORDER BY `id` ASC LIMIT 10");
$profL->bindValue(1,2);
$profL->execute();
foreach ($profL->fetchAll() as $profInfo => $a) {
?>
<tr>
<td><a href="account.php?student&id=<?php echo $a['id']; ?>"><?php echo $iNew->esc($a['fname'])." ".$iNew->esc($a['lname']); ?>(<?php echo $iNew->esc($a['username']); ?>)</a></td>
<td><a href="/account.php?student&delete&id=<?php echo $a['id']; ?>" onclick="return confirm('Do you really want to delete it?');">Delete</a>|<a href="/account.php?student&id=<?php echo $a['id']; ?>">Edit</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Add Student Modal -->
<div class="modal fade" id="addStudent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Student</h4>
</div>
<div class="modal-body">
<form class="addStudent">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" placeholder="Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary addStudentButt">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
else {
?>
<!-- List of Professor`s Account -->
<div class="panel panel-info">
<div class="panel-heading">
List of Professor`s Account <button class="btn btn-success pull-right" data-toggle="modal" data-target="#addInstructor">Add</button> <a href="/account.php?prof" class="btn btn-warning pull-right">See All</a>
<div style="clear:both"></div>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead style="font-weight:bolder">
<tr>
<td>Instructor</td>
<td>Action</td>
</tr
> </thead>
<tbody>
<?php
$profL = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `acctype` = ? ORDER BY `id` ASC LIMIT 10");
$profL->bindValue(1,1);
$profL->execute();
foreach ($profL->fetchAll() as $profInfo => $a) {
?>
<tr>
<td><a href="account.php?prof&id=<?php echo $a['id']; ?>"><?php echo $iNew->esc($a['fname'])." ".$iNew->esc($a['lname']); ?>(<?php echo $iNew->esc($a['username']); ?>)</a></td>
<td><a href="/account.php?prof&delete&id=<?php echo $a['id']; ?>" onclick="return confirm('Do you really want to delete it?');">Delete</a>|<a href="/account.php?prof&id=<?php echo $a['id']; ?>">Edit</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Add Instructor Modal -->
<div class="modal fade" id="addInstructor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Instructor</h4>
</div>
<div class="modal-body">
<form class="addInstructor">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" placeholder="Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary addInstructorButt">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- List of Student`s Accounts -->
<div class="panel panel-info">
<div class="panel-heading">
List of Student`s Account <button class="btn btn-success pull-right" data-toggle="modal" data-target="#addStudent">Add</button> <a href="/account.php?student" class="btn btn-warning pull-right">See All</a>
<div style="clear:both"></div>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead style="font-weight:bolder">
<tr>
<td>Student Name</td>
<td>Action</td>
</tr
> </thead>
<tbody>
<?php
$profL = $iNew->dbCon->prepare("SELECT * FROM `gs_users` WHERE `acctype` = ? ORDER BY `id` ASC LIMIT 10");
$profL->bindValue(1,2);
$profL->execute();
foreach ($profL->fetchAll() as $profInfo => $a) {
?>
<tr>
<td><a href="account.php?student&id=<?php echo $a['id']; ?>"><?php echo $iNew->esc($a['fname'])." ".$iNew->esc($a['lname']); ?>(<?php echo $iNew->esc($a['username']); ?>)</a></td>
<td><a href="/account.php?student&delete&id=<?php echo $a['id']; ?>" onclick="return confirm('Do you really want to delete it?');">Delete</a>|<a href="/account.php?student&id=<?php echo $a['id']; ?>">Edit</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Add Student Modal -->
<div class="modal fade" id="addStudent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add Student</h4>
</div>
<div class="modal-body">
<form class="addStudent">
<div class="form-group">
<label for="fname">First Name : </label>
<input type="input" class="form-control" id="fname" placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lname">Last Name : </label>
<input type="input" class="form-control" id="lname" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="username">Username : </label>
<input type="input" class="form-control" id="username" placeholder="Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary addStudentButt">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include('footer.php'); ?>