This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
/
admin.php
670 lines (646 loc) · 26.3 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
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<html>
<head>
<title><?php include_once "config.php"; echo $Name; ?></title>
<link rel="stylesheet" href="main.css" type="text/css" />
<script src='js/jq.js' type='text/javascript'></script>
<script src='js/function.js' type='text/javascript' ></script>
<script type='text/javascript'>
function checkInput(formname)
{
if (document.getElementsByName("name")[0].value=='')
{
alert("Please Enter Name");
document.getElementsByName("name")[0].focus();
}
else if (document.getElementsByName("username")[0].value=='')
{
alert("Please Enter username");
document.getElementsByName("username")[0].focus();
}
else if (document.getElementsByName("phone")[0].value.length<10)
{
alert("Please Enter Phone Number of atleast 10 numbers\n for landline numbers prefix the are code");
document.getElementsByName("phone")[0].focus();
}
else
{
checkPassword(formname);
}
}
function rmHead()
{
if (confirm("Are you sure you want to remove this Head?"))
{
document.getElementsByName("rmheadform")[0].submit();
}
}
function rmEvent()
{
if (confirm("Are you sure you want to remove this Event?"))
{
document.getElementsByName("rmeventform")[0].submit();
}
}
function rmCat()
{
if (confirm("Are you sure you want to remove this Catagory?"))
{
document.getElementsByName("rmcatform")[0].submit();
}
}
function checkAddEventInput()
{
if (document.getElementsByName("name")[0].value=='')
{
alert("Please Enter a Name");
}
else if (document.getElementsByName("info")[0].value=='')
{
alert("Please Enter Information about the Event");
}
else
{
document.getElementsByName("addeventform")[0].submit();
}
}
function checkPassword(formname)
{
var pass1 = document.getElementsByName("password1")[0];
var pass2 = document.getElementsByName("password2")[0];
if (pass1.value.length>5 && pass1.value==pass2.value)
{
document.getElementsByName(formname)[0].submit();
}
else
{
alert("minimum length is 6 and both passwords should match");
}
}
</script>
</head>
<body>
<?php include "header.php"; ?>
<?php include "sidebar.php"; ?>
<div id="center">
<?php
// $level from sidebar.php after user check
if (isset($_GET['do']) and $level == 'admin')
{
echo '<center>';
switch ($_GET['do'])
{
case 'resetpass':
// case for password reset
$h = new Head();
if (isset($_POST['resetpass']))
{
if ($_POST['password1'] == $_POST['password2']) // checking if both passwords are equal
{
if ($h->resetPass($_POST['user'], $_POST['password1']) == "done")
{
echo 'Password for ',$_POST['user'], ' changed';
}
else
{
echo 'some error occured';
}
}
else
{
echo "Passwords dont match";
}
}
else
{
echo '<form method ="POST" name="resetform" >Reset Password for<br><select name="user" >';
foreach ( $h->getList() as $head)
{
echo '<option>',$head['username'],'</option>';
}
echo '</select><br>Password<br><input type="password" name="password1" /><br>Confirm<br><input type="password" name="password2" /><br><input type="button" name ="reset" value="Reset" onclick="checkPassword(\'resetform\')"/><input type="hidden" name="resetpass" value="resetpass" /></form>';
}
break;
case 'editcat':
//case for editing Catagory Info
$c = new Catagory();
if (isset($_GET['catid']))
{
if (isset($_POST['editcat']) and isset($_POST['catinfo']))
{
if ($c->setInfo($_GET['catid'],$_POST['catinfo']) == 'done')
{
echo 'Done';
}
else
{
echo "Sorry an error ocurred";
}
}
else
{
$catinfo = $c->getInfo($_GET['catid']);
echo '<form method="POST" name="catinfoform"><table width="40%"><tr><td>Name</td><td>',$catinfo['name'],'</td></tr><tr><td>Info</td><td><textarea rows="10" cols="50" name="catinfo" >',$catinfo['info'],'</textarea></td></tr></table><input type="submit" value="Change" name="editcat"/></form>';
}
}
else
{
echo 'Select a Catgory<br>';
foreach ($c->getList() as $cat)
{
echo '<a href="admin.php?do=editcat&catid=',$cat['catid'],'">',$cat['name'],'</a><br>';
}
}
break;
case 'addhead':
// case addhead
$h = new Head();
if (isset($_POST['addhead']))
{
if (($_POST['password1'] == $_POST['password2']) and ($_POST['password1'] != ''))
{
if ($_POST['username'] and $_POST['name'] and $_POST['level'] and $_POST['phone'])
{
$username = split('[^a-zA-Z0-9_.]',$_POST['username']);//testing username for invalid characters
if ($username[0] == $_POST['username'])
{
$result = $h->add($_POST['username'],$_POST['password1'],$_POST['name'],$_POST['phone'],$_POST['level']);
echo $result;
}
else
{
echo 'Username -> <b>',$_POST['username'],'</b> not supported';
}
}
else
{
echo 'Please fill all the information';
}
}
else
{
echo "Passwords dont match";
}
}
else
{
echo '<form method ="POST" name="addheadform" >Add a new Head<br><table><tr><td>Name</td><td><input type="text" name="name" /></td></tr><tr><td>Username </td><td><input type="text" name="username" ></td></tr><tr><td>Password<td><input type="password" name="password1" /></td></tr><tr><td>Confirm Password</td><td><input type="password" name="password2" /></td></tr><tr><td>Phone</td><td><input type="text" name="phone" /></td></tr><tr><td>Level</td><td>';
echo '<select name="level"><option>reg</option><option>chead</option><option>ehead</option><option>org</option><option>vol</option><option>admin</option></select>';
echo '</table> <input type="button" value="Add" onclick="checkInput(\'addheadform\')"/><input type="hidden" name="addhead" value="addhead" /></form>';
}
break;
case 'addevent':
// case addevent
if (isset($_POST['addevent']))
{
if (isset($_POST['name']) and isset($_POST['info']) and isset($_POST['team']))
{
$e = new Event();
$result = $e->add($_POST['name'],$_POST['team'],$_POST['info']);
echo $result;
}
else
{
echo 'Please check your entries';
}
}
else
{
echo '<form method ="POST" name="addeventform" >Add a new Event<br><table><tr><td>Name</td><td><input type="text" name="name" /></td></tr><tr><td>Info</td><td><textarea name="info" rows="10" cols="50"></textarea></td></tr><tr><td>Team Event</td><td><select name="team"><option>no</option><option>yes</option></select></td></tr></table><input type="button" value="Add" onclick="checkAddEventInput()"/><input type="hidden" name="addevent" value="addevent" /></form>';
}
break;
case 'addcat':
// case addevent
if (isset($_POST['addcat']))
{
if (isset($_POST['name']) and isset($_POST['info']) and isset($_POST['team']))
{
$c = new Catagory();
if ($_POST['team']== 'yes')
{
$team = 1;
}
else
{
$team=0;
}
$result = $c->add($_POST['name'],$_POST['info'],$team);
echo $result;
}
else
{
echo 'Please check your entries';
}
}
else
{
echo '<form method ="POST" name="addeventform" >Add a new Catagory<br><table><tr><td>Name</td><td><input type="text" name="name" /></td></tr><tr><td>Info</td><td><textarea name="info" rows="10" cols="50"></textarea></td></tr></table><input type="button" value="Add" onclick="checkAddEventInput()"/><input type="hidden" name="addcat" value="addcat" /></form>'; // checkAddEventInput will also work for this
}
break;
case 'rmhead':
// case rmhead
if (isset($_POST['rmhead']))
{
if (isset($_POST['name']))
{
$h = new Head();
$result = $h->rem($_POST['name']);
if ($result =="done")
{
echo 'Head <b>',$_POST['name'],'</b> removed';
}
else
{
echo 'an error occured while trying to remove';
}
}
else
{
echo 'Please check your entries';
}
}
else
{
$h = new Head();
echo '<form method="POST" name="rmheadform">Select a User To Remove<br><select name="name">';
foreach($h->getList() as $head)
{
echo '<option>',$head['username'],'</option><br><br>';
}
echo '</select><br><input type="hidden" name="rmhead" value="rmhead"/><input type="button" value="Remove" onclick="rmHead()" /></form>';
}
break;
case 'rmevent':
// case rmevent
if (isset($_POST['rmevent']))
{
if (isset($_POST['name']))
{
$e = new Event();
$result = $e->rem($_POST['name']);
if ($result =="done")
{
echo 'Event <b>',$_POST['name'],'</b> removed';
}
else
{
echo 'an error occured while trying to remove';
}
}
else
{
echo 'Please check your entries';
}
}
else
{
$e = new Event();
echo '<form method="POST" name="rmeventform">Select an Event To Remove<br><select name="name">';
foreach($e->getList() as $event)
{
echo '<option>',$event['name'],'</option><br><br>';
}
echo '</select><br><input type="hidden" name="rmevent" value="rmevent"/><input type="button" value="Remove" onclick="rmEvent()" /></form>';
}
break;
case 'rmcat':
// case -> removing a catagory
if (isset($_POST['rmcat'])) // if a catagory is submited
{
if (isset($_POST['name'])) //if the name of catagory is set
{
$c = new Catagory();
$c->select($_POST['name']); // select the catagory to be removed
$result = $c->rem($c->getId()); // delete the catagory
if ($result =="done")
{
// everything ok
echo 'Catagory <b>',$_POST['name'],'</b> removed';
}
else
{
// some error
echo 'an error occured while trying to remove';
}
}
else
{
// if catagory name was not set
echo 'Please check your entries';
}
}
else
{
// displaying the list of all catagories
$c = new Catagory();
echo '<form method="POST" name="rmcatform">Select a Catagory To Remove<br><select name="name">';
foreach($c->getList() as $cat)
{
// name of all catagories in from the DB
echo '<option>',$cat['name'],'</option><br><br>';
}
// we set a hidden input rmcat to rmcat, so that we know we want to remove a catagory
echo '</select><br><input type="hidden" name="rmcat" value="rmcat"/><input type="button" value="Remove" onclick="rmCat()" /></form>';
}
break;
case 'cathead':
// case -> assign catagory head
if (isset($_POST['cathead'])) // if catagory and head is selected
{
if (isset($_POST['catname']) and isset($_POST['headname'])) //checking if catagory and head names are set
{
$c= new Catagory();
$h= new Head();
if ($c->select($_POST['catname'])) // we try to select the catagory
{
if($h->select($_POST['headname'])) // we try to select the head
{
echo $c->addHead($h->getId()); // assigning the catagory to head
}
else // if we can not select the head
{
echo 'Head Username Does Not Exist';
}
}
else // if we cannot select the catagory
{
echo 'Catagory Does Not Exist';
}
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all catagories and heads
$c = new Catagory();
$h = new Head();
echo '<form method="POST" name="rmcatform">Select a Catagory and Head<br><select name="catname">';
foreach($c->getList() as $cat)
{
// name of all catagories from the DB
echo '<option>',$cat['name'],'</option>';
}
echo '</select><br><select name="headname">';
foreach($h->getHeads('chead') as $head)
{
// name of all catagory heads from the DB
echo '<option>',$head['username'],'</option>';
}
// we set a hidden input cathead to rcathead, so that we know we want to assign a catagory to head
echo '</select><br><input type="hidden" name="cathead" value="cathead"/><input type="submit" value="Assign" /></form>';
}
break;
case 'eventhead':
// case -> assign event head
if (isset($_POST['eventhead'])) // if event and head is selected
{
if (isset($_POST['eventname']) and isset($_POST['headname'])) //checking if event and head names are set
{
$e= new Event();
$h= new Head();
if ($e->select($_POST['eventname'])) // we try to select the event
{
if($h->select($_POST['headname'])) // we try to select the head
{
echo $e->addHead($h->getId(),'head'); // assigning the event to head
}
else // if we can not select the head
{
echo 'Head Username Does Not Exist';
}
}
else // if we cannot select the event
{
echo 'Event Does Not Exist';
}
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all events and heads
$e = new Event();
$h = new Head();
echo '<form method="POST">Select an Event and Head<br><select name="eventname">';
foreach($e->getList() as $event)
{
// name of all events from the DB
echo '<option>',$event['name'],'</option>';
}
echo '</select><br><select name="headname">';
foreach($h->getHeads('ehead') as $head)
{
// name of all event heads from the DB
echo '<option>',$head['username'],'</option>';
}
// we set a hidden input eventhead to eventhead, so that we know we want to assign an event to head
echo '</select><br><input type="hidden" name="eventhead" value="eventhead"/><input type="submit" value="Assign" /></form>';
}
break;
case 'eventorg':
// case -> assign event organiser
if (isset($_POST['eventorg'])) // if event and head is selected
{
if (isset($_POST['eventname']) and isset($_POST['headname'])) //checking if event and head names are set
{
$e= new Event();
$h= new Head();
if ($e->select($_POST['eventname'])) // we try to select the event
{
if($h->select($_POST['headname'])) // we try to select the head
{
echo $e->addHead($h->getId(),'org'); // assigning the event to head
}
else // if we can not select the head
{
echo 'Username Does Not Exist';
}
}
else // if we cannot select the event
{
echo 'Event Does Not Exist';
}
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all events and heads
$e = new Event();
$h = new Head();
echo '<form method="POST">Select an Event and Head<br><select name="eventname">';
foreach($e->getList() as $event)
{
// name of all events from the DB
echo '<option>',$event['name'],'</option>';
}
echo '</select><br><select name="headname">';
foreach($h->getHeads('org') as $head)
{
// name of all event organisers from the DB
echo '<option>',$head['username'],'</option>';
}
// we set a hidden input eventorg to eventorg, so that we know we want to assign an event to organiser
echo '</select><br><input type="hidden" name="eventorg" value="eventorg"/><input type="submit" value="Assign" /></form>';
}
break;
case 'eventvol':
// case -> assign event volunteer
if (isset($_POST['eventvol'])) // if event and head is selected
{
if (isset($_POST['eventname']) and isset($_POST['headname'])) //checking if event and head names are set
{
$e= new Event();
$h= new Head();
if ($e->select($_POST['eventname'])) // we try to select the event
{
if($h->select($_POST['headname'])) // we try to select the head
{
echo $e->addHead($h->getId(),'vol'); // assigning the event to head
}
else // if we can not select the head
{
echo 'Username Does Not Exist';
}
}
else // if we cannot select the event
{
echo 'Event Does Not Exist';
}
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all events and heads
$e = new Event();
$h = new Head();
echo '<form method="POST">Select an Event and Head<br><select name="eventname">';
foreach($e->getList() as $event)
{
// name of all events from the DB
echo '<option>',$event['name'],'</option>';
}
echo '</select><br><select name="headname">';
foreach($h->getHeads('vol') as $head)
{
// name of all event volunteers from the DB
echo '<option>',$head['username'],'</option>';
}
// we set a hidden input eventvol to eventvol, so that we know we want to assign an event to volunteer
echo '</select><br><input type="hidden" name="eventvol" value="eventvol"/><input type="submit" value="Assign" /></form>';
}
break;
case 'eventcat':
// case -> assign event to catagory
if (isset($_POST['eventcat'])) // if event and head is selected
{
if (isset($_POST['eventname']) and isset($_POST['catname'])) //checking if event and catagory names are set
{
$e= new Event();
$c= new Catagory();
if ($e->select($_POST['eventname'])) // we try to select the event
{
if($c->select($_POST['catname'])) // we try to select the catagory
{
echo $c->addEvent($e->getId()); // assigning the event to catagory
}
else // if we can not select the catagory
{
echo 'Catagory Does Not Exist';
}
}
else // if we cannot select the event
{
echo 'Event Does Not Exist';
}
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all events and heads
$e = new Event();
$c = new Catagory();
echo '<form method="POST">Select an Event and Head<br><select name="eventname">';
foreach($e->getList() as $event)
{
// name of all events from the DB
echo '<option>',$event['name'],'</option>';
}
echo '</select><br><select name="catname">';
foreach($c->getList() as $cat)
{
// name of all event catagories from the DB
echo '<option>',$cat['name'],'</option>';
}
// we set a hidden input eventcat to eventcat, so that we know we want to assign an event to Catagory
echo '</select><br><input type="hidden" name="eventcat" value="eventcat"/><input type="submit" value="Assign" /></form>';
}
break;
case 'rmcathead':
// case -> remove catagory head
if (isset($_POST['rmcathead'])) // if catagory or head is selected
{
if (isset($_POST['catname']) or isset($_POST['headname'])) //checking if catagory or head name is set
{
$c= new Catagory();
$h= new Head();
// add here
}
else // if names are not set
{
echo 'Please check your entries';
}
}
else
{
// displaying the list of all catagories and heads
$c = new Catagory();
$h = new Head();
echo '<form method="POST" >Select a Catagory or Head<br><select name="catname">';
foreach($c->getList() as $cat)
{
// name of all catagories from the DB
echo '<option>',$cat['name'],'</option>';
}
echo '</select><br><select name="headname">';
foreach($h->getHeads('chead') as $head)
{
// name of all catagory heads from the DB
echo '<option>',$head['username'],'</option>';
}
// we set a hidden input cathead to rcathead, so that we know we want to assign a catagory to head
echo '</select><br><input type="hidden" name="cathead" value="cathead"/><input type="submit" value="Assign" /></form>';
}
break;
default:
// if none of the above we simply ask to select something
echo "Sorry you selected something that does not exist";
break;
}
echo '</center>';
}
else
{
echo "Please Select Something from Admin";
}
?>
</div>
<?php include "footer.php"; ?>
</body>
</html>