/
admin.php
697 lines (592 loc) · 23.6 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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head -->
<?php
session_start();
require('connect.php');
require('structure/head.php');
if(!isset($_SESSION['username'])){
header('location: index.php');
}
?>
</head>
<body>
<!-- Nav -->
<?php require('structure/nav.php'); ?>
<!-- Sidebar -->
<div class="sidebar sidebar-style-2">
<div class="sidebar-wrapper scrollbar scrollbar-inner">
<div class="sidebar-content">
<ul class="nav nav-primary">
<li class="nav-item">
<a href="index.php">
<i class="fas fa-home"></i>
<p>หน้าแรก</p>
</a>
</li>
<li class="nav-section">
<span class="sidebar-mini-icon">
<i class="fa fa-ellipsis-h"></i>
</span>
<h4 class="text-section">แถบเมนู</h4>
</li>
<li class="nav-item active">
<a href="admin.php">
<i class="fas fa-trophy"></i>
<p>โครงการ/กิจกรรม</p>
</a>
</li>
<?php if($_SESSION['username'] == "admin"){ ?>
<li class="nav-item">
<a data-toggle="collapse" href="#base">
<i class="fas fa-cog"></i>
<p>ตั้งค่าระบบ</p>
<span class="caret"></span>
</a>
<div class="collapse" id="base">
<ul class="nav nav-collapse">
<li>
<a href="admin_config.php">
<span class="sub-item">ตั้งค่าทั่วไป</span>
</a>
</li>
<li>
<a href="admin_dp.php">
<span class="sub-item">ตั้งค่ากลุ่ม/งาน</span>
</a>
</li>
<li>
<a href="admin_user.php">
<span class="sub-item">ตั้งค่าผู้ดูแลระบบ</span>
</a>
</li>
</li>
</ul>
</div>
</li>
<?php } ?>
<li class="nav-item">
<a href="admin_tempate.php" >
<i class="fas fa-file"></i>
<p>เทมเพลต</p>
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- End Sidebar -->
<div class="main-panel">
<div class="content">
<div class="panel-header bg-primary-gradient">
<div class="page-inner py-5">
<div class="text-center">
<div>
<img class="d-inline mb-3" src="img/fav.ico" width="100" height="100">
</div>
<div>
<h2 class="d-block text-white mb-1 fw-bold">ระบบพิมพ์เกียรติบัตรออนไลน์</h2>
<h5 class="d-inline text-white op-7 mb-2"><?= $nameschool_data ?></h5>
</div>
</div>
</div>
</div>
<div class="page-inner mt--5">
<!-- Card -->
<div class="row">
<div class="col-sm-6 col-md-4 d-none d-xl-block">
<div class="card card-stats card-primary card-round">
<div class="card-body">
<div class="row">
<div class="col-5">
<div class="icon-big text-center">
<i class="flaticon-settings"></i>
</div>
</div>
<div class="col-7 col-stats">
<div class="numbers">
<p class="card-category">โครงการ</p>
<h4 class="card-title" id="all_project"></h4>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 d-none d-xl-block">
<div class="card card-stats card-primary card-round">
<div class="card-body">
<div class="row">
<div class="col-5">
<div class="icon-big text-center">
<i class="flaticon-users"></i>
</div>
</div>
<div class="col-7 col-stats">
<div class="numbers">
<p class="card-category">เกียรติบัตร</p>
<h4 class="card-title" id="all_user"></h4>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 d-none d-xl-block">
<div class="card card-stats card-primary card-round">
<div class="card-body ">
<div class="row">
<div class="col-5">
<div class="icon-big text-center">
<i class="flaticon-success"></i>
</div>
</div>
<div class="col-7 col-stats">
<div class="numbers">
<p class="card-category">ผู้ดแลระบบ</p>
<h4 class="card-title" id="all_admin"></h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<h2 class="card-header"> <b>ตั้งค่าโครงการ/กิจกรรม</b>
<div class="float-right text-white">
<button class="btn btn-sm bg-primary text-white" data-toggle="modal" data-target="#AddPj" > <i class="fas fa-plus pe-1"></i> เพิ่ม</dutton>
</div>
</h2>
<div class="card-body">
<table id="loadproject" class="table nowrap" style="width:100%">
<thead class="table-light">
<tr>
<th>ลำดับที่</th>
<th>สถานะ</th>
<th>โครงการ</th>
<th>กลุ่ม/งาน</th>
<th>วันที่</th>
<th>ดำเนินการ</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Footer-->
<?php require('structure/footer.php'); ?>
</div>
</div>
<!-- Script-->
<?php require('structure/script.php'); ?>
<!-- Modal Add Project -->
<div class="modal fade" id="AddPj" tabindex="-1">
<div class="modal-dialog ">
<div class="modal-content ">
<div class="modal-header">
<h3> เพิ่มโครงการ/กิจกรรม </h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="sql/admin/createproject.php" method="post">
<div class="mb-3">
<label class="form-label" for="name">ชื่อโครงการ/กิจกรรม</label>
<input class="form-control" type="text" name="name" placeholder="โครงการ/กิจกรรม" required>
</div>
<div class="mb-3">
<label class="form-label" for="date">วันที่</label>
<input class="form-control" type="date" name="date" required>
<small>กรุณากรอกเป็น ค.ศ. ระบบจะแปลงเป็น พ.ศ. ให้อัตโนมัติ</small>
</div>
<div class="mb-3">
<label for="type" class="form-label">รูปแบบ</label>
<select class="form-control" name="type">
<option value="0" selected>ชื่อ-นามสกุล เท่านั้น</option>
<option value="1">ชื่อ-นามสกุล และเพิ่มอีก 1 บรรทัด</option>
<option value="2">ชื่อ-นามสกุล และเพิ่มอีก 2 บรรทัด</option>
</select>
</div>
<?php if($_SESSION['username'] == "admin"){
$sql_dp = "SELECT * FROM `dp`";
$query_dp = mysqli_query($con, $sql_dp);
if (false === $query_dp) {
die(mysqli_error($con));
}
?>
<div class="mb-3">
<label for="iddp" class="form-label">กลุ่ม/งาน</label>
<select name="iddp" id="iddp" class="form-control">
<option value="" selected value="">กรุณาเลือกกลุ่ม/งาน</option>
<?php foreach ($query_dp as $value_dp) { ?>
<option <?php echo $value_dp['id'] == '1' ? ' selected ' : '';?> value="<?=$value_dp['id']?>"><?=$value_dp['name']?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<div class="text-center">
<button class="btn btn-primary" type="submit" name="submit" class="btn"> <i class="fas fa-save"></i> บันทึก</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Delete -->
<div class="modal fade" id="DeletePj" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">คุณกำลังจะลบโครงการ/กิจกรรม ?</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-center">
<form>
<i class="mt-2 mb-2 fas fa-exclamation-circle fa-8x text-danger"></i>
<h3 class="mt-3">คุณแน่ใจไหมที่จะลบโครงการ/กิจกรรม</h3>
<h4 class="mt-1">ระบบจะลบผู้เข้าร่วมในโครงการ/กิจกรรมนี้ทั้งหมด</h4>
</div>
<div class="mb-4 mt-3 text-center">
<input type="hidden" id="id-d">
<button type="button" onclick="DeletePj()" class="btn btn-danger"><i class="far fa-trash-alt"></i> ลบ</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fas fa-ban"></i> ยกเลิก</button>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
<!-- Modal Edit Project-->
<div class="modal fade" id="EditPj" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">แก้ไขโครงการ/กิจกรรม</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="name" class="form-label">ชื่อโครงการ</label>
<input type="text" class="form-control" id="name">
</div>
<div class="mb-3">
<label for="date" class="form-label">วันที่</label>
<input type="date" class="form-control" id="date">
<div class="form-text">กรุณากรอกเป็น ค.ศ. ระบบจะแปลงเป็น พ.ศ. ให้อัตโนมัติ</div>
</div>
<div class="mb-3">
<label for="type" class="form-label">รูปแบบ</label>
<select class="form-control" id="type">
<option value="0" selected>ชื่อ-นามสกุล เท่านั้น</option>
<option value="1">ชื่อ-นามสกุล และเพิ่มอีก 1 บรรทัด</option>
<option value="2">ชื่อ-นามสกุล และเพิ่มอีก 2 บรรทัด</option>
</select>
</div>
<?php if($_SESSION['username'] == "admin"){
$sql_dp = "SELECT * FROM `dp`";
$query_dp = mysqli_query($con, $sql_dp);
if (false === $query_dp) {
die(mysqli_error($con));
}
?>
<div class="mb-3">
<label for="iddp_e" class="form-label">กลุ่ม/งาน</label>
<select name="iddp_e" id="iddp_e" class="form-control">
<option value="" selected value="">กรุณาเลือกกลุ่ม/งาน</option>
<?php foreach ($query_dp as $value_dp) { ?>
<option value="<?=$value_dp['id']?>"><?=$value_dp['name']?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<input type="hidden" id="id-e">
<div class="text-center">
<button type="button" onclick="EditPj()" class="btn btn-primary"> <i class="fas fa-save"></i> แก้ไข</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Add Project -->
<div class="modal fade" id="AddUser" tabindex="-1">
<div class="modal-dialog ">
<div class="modal-content ">
<div class="modal-header">
<h5> เพิ่มผู้เข้าร่วมโครงการ/กิจกรรม </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="admineditpj_createuser.php" method="post">
<div class="mb-3">
<label class="form-label" for="name">ชื่อ-นามสกุล</label>
<input class="form-control" type="text" name="name" placeholder="ชื่อ-นามสกุล" required>
</div>
<?php
if($type_data == 1 ){
echo '<div class="mb-3">
<label for="line2" class="form-label">บรรทัด 2</label>
<input type="text" class="form-control" name="line2" placeholder="บรรทัด 2">
</div>' ;
}
if($type_data == 2){
echo
'<div class="mb-3">
<label for="line2" class="form-label">บรรทัด 2</label>
<input type="text" class="form-control" name="line2" placeholder="บรรทัด 2">
</div>
<div class="mb-3">
<label for="line3" class="form-label">บรรทัด 3</label>
<input type="text" class="form-control" name="line3" placeholder="บรรทัด 3">
</div>';
}
?>
<input type="hidden" name="id" value="<?=$_GET['id']?>" >
<div class="text-center">
<button class="btn btn-primary" type="submit" name="submit" class="btn"> <i class="fas fa-save"></i> บันทึก</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
setInterval(function(){
$.ajax({
type:'POST',
url:'sql/admin/ajax_count.php',
data : {function:'user'},
dataType : 'json',
success:function(html){
$('#all_user').html(html);
}
});
$.ajax({
type:'POST',
url:'sql/admin/ajax_count.php',
data : {function:'project'},
dataType : 'json',
success:function(html){
$('#all_project').html(html);
}
});
$.ajax({
type:'POST',
url:'sql/admin/ajax_count.php',
data : {function:'admin'},
dataType : 'json',
success:function(html){
$('#all_admin').html(html);
}
});
}, 1000);
});
</script>
<!-- Script DataTable-->
<script >
$(document).ready(function() {
var table = $('#loadproject').DataTable( {
//"processing": true,
"serverSide": true,
"ajax": "sql/admin/loadproject.php?iddp=<?=$iddp_data?>",
"language" : {
"emptyTable": "ไม่มีข้อมูลในตาราง",
"info": "แสดง _START_ ถึง _END_ จาก _TOTAL_ แถว",
"infoEmpty": "แสดง 0 ถึง 0 จาก 0 แถว",
"infoFiltered": "(กรองข้อมูล _MAX_ ทุกแถว)",
"infoThousands": ",",
"lengthMenu": "แสดง _MENU_ แถว",
"loadingRecords": "กำลังโหลดข้อมูล...",
"processing": "กำลังดำเนินการ...",
"search": "ค้นหา: ",
"zeroRecords": "ไม่พบข้อมูล",
"paginate": {
"first": "หน้าแรก",
"previous": "ก่อนหน้า",
"next": "ถัดไป",
"last": "หน้าสุดท้าย"
},
"aria": {
"sortAscending": ": เปิดใช้งานการเรียงข้อมูลจากน้อยไปมาก",
"sortDescending": ": เปิดใช้งานการเรียงข้อมูลจากมากไปน้อย"
},
"autoFill": {
"cancel": "ยกเลิก",
"fill": "กรอกทุกช่องด้วย",
"fillHorizontal": "กรอกตามแนวนอน",
"fillVertical": "กรอกตามแนวตั้ง",
"info": "ข้อมูลเพิ่มเติม"
},
"buttons": {
"collection": "ชุดข้อมูล",
"colvis": "การมองเห็นคอลัมน์",
"colvisRestore": "เรียกคืนการมองเห็น",
"copy": "คัดลอก",
"copyKeys": "กดปุ่ม Ctrl หรือ Command + C เพื่อคัดลอกข้อมูลบนตารางไปยัง Clipboard ที่เครื่องของคุณ"
}
},
"order": [[ 0, "desc" ]],
"columns": [
{ "width": "7%" },
{ "width": "5%" },
{ "width": "35%" },
{ "width": "30%" },
{ "width": "15%" },
{ "width": "5%" }
],
responsive: true
} );
table.on('draw.dt', function () {
var info = table.page.info();
table.column(0, { search: 'applied', order: 'applied', page: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1 + info.start;
});
});
} );
</script>
<!-- Script DataTable - SettingPj Button -->
<script>
function SettingPj(id){
window.location.href='admin_pj.php?id=' + id;
}
</script>
<!-- Script DataTable - DeletePj Button -->
<script>
$('#DeletePj').on('shown.bs.modal', function (event) {
var button = $(event.relatedTarget);
var id = button.data('whatever');
var modal = $(this);
$('#id-d').val(id);
})
function DeletePj(){
var id = $('#id-d').val();
$.ajax({
url:'sql/admin/deleteproject.php',
method: 'POST',
data: {id:id},
success:function(data){
$('#DeletePj').modal('toggle');
swal("สำเร็จ!", "ลบโครงการ/กิจกรรมสำเร็จ [SUCCESS]", {
icon : "success",
buttons: {
confirm: {
text: "ตกลง",
className : 'btn btn-success'
}
},
}).then(function() {
$('#loadproject').DataTable().draw();
});
}
})
}
</script>
<!-- Script DataTable - EditPj Button -->
<script>
$('#EditPj').on('shown.bs.modal', function (event) {
var button = $(event.relatedTarget);
var id = button.data('whatever');
var modal = $(this);
$('#id-e').val(id);
$.ajax({
url:'sql/admin/insertproject.php',
method: 'POST',
data: {id:id},
success:function(data){
var json = $.parseJSON(data);
$("#name").val(json[0].name);
$("#date").val(json[0].date);
$("#type").val(json[0].type);
$("#iddp_e").val(json[0].iddp);
}
})
})
function EditPj(){
var id = $('#id-e').val();
var name = $('#name').val();
var date = $('#date').val();
var type = $('#type').val();
if($('#iddp_e').val() != ''){
var iddp_e = $('#iddp_e').val();
}else{
var iddp_e = '';
}
$.ajax({
url:'sql/admin/editproject.php',
method: 'POST',
data: {id:id,name:name,date:date,type:type,iddp:iddp_e},
success:function(data){
$('#EditPj').modal('toggle');
swal("สำเร็จ!", "แก้ไขโครงการ/กิจกรรมสำเร็จ [SUCCESS]", {
icon : "success",
buttons: {
confirm: {
text: "ตกลง",
className : 'btn btn-success'
}
},
}).then(function() {
$('#loadproject').DataTable().draw();
});
}
})
}
</script>
<?php if(isset($_SESSION['msg_w'])){ ?>
<script>
swal("พบข้อผิดพลาด!", "<?=$_SESSION['msg_w']?>", {
icon : "warning",
buttons: {
confirm: {
text: "ตกลง",
className : 'btn btn-warning'
}
},
}).then(function() {
<?php unset($_SESSION['msg_w']) ?>
//
});
</script>
<?php }; ?>
<?php if(isset($_SESSION['msg_s'])){ ?>
<script>
swal("สำเร็จ!", "<?=$_SESSION['msg_s']?>", {
icon : "success",
buttons: {
confirm: {
text: "ตกลง",
className : 'btn btn-success'
}
},
}).then(function() {
<?php unset($_SESSION['msg_s']) ?>
//
});
</script>
<?php }; ?>