-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage-period.php
514 lines (441 loc) · 17.5 KB
/
manage-period.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
<?php
session_start();
include('library/form/connection.php');
include('library/functions/functions.php');
$db = new db();
include('library/functions/checkSession.php');
$search = isset($_GET['search']) ? '%'.$_GET['search'].'%' : '%%';
$trimmedsearch = str_replace('%', '', $search);
$getschoolyear = isset($_GET['schoolyear']) ? $_GET['schoolyear'] : '';
$list_getSchoolYear = $db->connection->prepare('SELECT SchoolYear.SYYear FROM SchoolYear WHERE SchoolYear.idSchoolYear = ?');
$list_getSchoolYear->bindparam(1, $getschoolyear);
$list_getSchoolYear->execute();
$schoolyear = $list_getSchoolYear->fetchColumn();
$getCount = $db->connection->prepare('SELECT COUNT(*) FROM Period WHERE Period.idSchoolYear = ? ');
$getCount->bindparam(1,$getschoolyear);
$getCount->execute();
$total_count = $getCount->fetchColumn();
$total_page = ceil($total_count/10);
$page = isset($_GET['page']) && $_GET['page'] > 0 && $_GET['page'] <= $total_page ? $_GET['page'] : '1';
$offset = $page * 10;
$limit = ($page * 10) - 9;
if($page < 2) {
$disable_previous = 'disabled text-muted';
$disable_previous2 = 'pointer-events: none;';
$bottom_page = 'display:none';
}
else {
$disable_previous = '';
$disable_previous2 = '';
$bottom_page = '';
}
if($total_page < 2) {
$top_page = 'display:none';
}
else {
$top_page = '';
}
if($total_page == $page || $total_page < 1) {
$disable_next = 'disabled text-muted';
$disable_next2 = 'pointer-events: none;';
$top_page = 'display:none';
}
else {
$disable_next = '';
$disable_next2 = '';
$top_page = '';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>CPU Smart Touch Information Kiosk</title>
<link href = "library/css/bootstrap.min.css" rel = " stylesheet">
<link href = "library/css/mystyles.css" rel = "stylesheet">
</head>
<body>
<body>
<div class="modal fade" id="addPeriodForm_MODAL" tabindex="-1" role="dialog" aria-labelledby="Add Period Modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalTitle">Add Period for <?php echo $schoolyear ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id = "addPeriodForm" class="form-horizontal" action="library/form/frmAddPeriod.php" method="post"
name="upload_excel" enctype="multipart/form-data">
<input id = "addPeriodForm_SCHOOLYEAR" type = "text" name = "SCHOOLYEAR" value = "<?php echo $getschoolyear ?>" hidden />
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<select name = "PERIODNAME" class="form-control" id="addPeriodForm_PERIODNAME" required>
<option selected = "true" disabled value = "">Select a Period</option>
<option value = "1ST SEMESTER">1ST SEMESTER</option>
<option value = "2ND SEMESTER">2ND SEMESTER</option>
<option value = "SUMMER">SUMMER</option>
</select>
</div>
<br />
<h6 class = "font-weight-bold float-right">Period Information</h6>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Period Start</span>
</div>
<input id = "addPeriodForm_PERIODSTART" name = "PERIODSTART" type="date" class="form-control" aria-describedby="sizing-addon2" required>
</div>
<br / >
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Period End</span>
</div>
<input id = "addPeriodForm_PERIODEND" name = "PERIODEND" type="date" class="form-control" aria-describedby="sizing-addon2" required>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" id = "addPeriodForm_SUBMIT" class="btn btn-success" name = "ADD" data-loading-text = "Adding.." value = "Add">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="deletePeriodForm_MODAL" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5>Delete Period</h5>
</div>
<form id="deletePeriodForm" method="post" action="library/form/frmDeletePeriod.php">
<div class="modal-body">
<div><input type="text" id="deletePeriodForm_ID" name="ID" style="display: none;"></div>
<p>Do you want to delete this record?</p>
<table class="table">
<thead>
<tr>
<td></td>
<td><b>Period Details</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>School Year: </td>
<td id="deletePeriodForm_SCHOOLYEAR" class = "font-italic"></td>
</tr>
<tr>
<td>Period: </td>
<td id="deletePeriodForm_PERIODNAME"></td>
</tr>
<tr>
<td>Period Start:</td>
<td id="deletePeriodForm_PERIODSTART"></td>
</tr>
<tr>
<td>Period End: </td>
<td id="deletePeriodForm_PERIODEND"></td>
</tr>
<tr>
<td>Date Created:</td>
<td id="deletePeriodForm_DATECREATED"></td>
</tr>
<tr>
<td>Status:</td>
<td id="deletePeriodForm_STATUS"></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="submit" id="deletePeriodForm_SUBMIT" class="btn btn-danger" data-loading-text="Deleting..."> Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal"></span> Close</button>
</div>
</form>
</div>
</div>
</div>
<div class="container">
<div class = "row top-buffer">
<div class = "col-lg-6">
<h1 class = "h1">Period Management for <?php echo $schoolyear ?></h1>
<p class = "text-muted">Manages Period, Example 2018-2019, User Can Add a New Academic Period.</p>
</div>
<div class = "col-lg-6">
<div class = "float-right button-manage-group">
<a href = "manage-school-year.php" class="btn btn-info"><i class="fas fa-arrow-left"></i> Return</a>
<span class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Actions
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a href = "#" data-target = "#addPeriodForm_MODAL" class = "dropdown-item"data-toggle = "modal">Add Period</a>
<a class="dropdown-item" href="mailto:totopaulmanares@yahoo.com?Subject=CPU%20Touch%20Information%20Kiosk%20Concerns" target="_top">Report</a>
</div>
</span>
</div>
</div>
</div>
<div class = "row">
<div class = "col-lg-12">
<hr class="my-4 float-right" width="65%">
</div>
<div class = "col-lg-8">
</div>
<div class = "col-lg-4">
<div class = "input-group">
<input type = "text" id = "txtSearch" class = "form-control" placeholder="Search">
<button id = "btnSearch" class = "btn btn-success">Search</button>
</div>
</div>
</div>
<div class = "row top-buffer">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Period Name</th>
<th scope="col">Period Start</th>
<th scope="col">Period End</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id = "periodList">
</tbody>
</table>
</div>
<div class = "row top-buffer justify-content-md-center">
<div class="col-md-auto top-buffer">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<li class="page-item">
<a class="page-link <?php echo $disable_previous; ?>" style="<?php echo $disable_previous2; ?>" href="manage-term.php?search=<?php echo $search; ?>&page=<?php echo $page - 1; ?>" tabindex="-1">Previous</a>
</li>
<?php
for($i = 1; $i <= $total_page; $i++)
{
?>
<li id = "paginationActive<?php echo $i; ?>" class="page-item">
<a class="page-link" href="manage-term.php?search=<?php echo $search; ?>&page=<?php echo $i; ?>"><?php echo $i; ?></a>
</li>
<?php
}
?>
<li class="page-item">
<a class = "page-link <?php echo $disable_next; ?>" style="<?php echo $disable_next2; ?>" href="manage-term.php?search=<?php echo $search; ?>&page=<?php echo $page + 1; ?>" >Next</a>
</li> </ul>
</nav>
</div>
</div>
<?php include('library/html/footer.html'); ?>
</div>
<script src = "library/js/jquery-3.3.1.min.js"></script>
<script src="library/js/popper.min.js"></script>
<script src="library/js/bootstrap.min.js"></script>
<script src = "library/js/jquery.form.js"></script>
<script src = "library/js/app.js"></script>
<script src="library/js/messagealert.js"></script>
<script src="library/js/all.js"></script>
</body>
</html>
<script>
$(document).ready(function(){
$("#paginationActive<?php echo $page ?>").addClass("active");
$("#txtSearch").val("<?php echo $trimmedsearch ?>");
$( "#btnSearch" ).click(function() {
var searchValue = $("#txtSearch").val().toLowerCase();
window.location.href='manage-period.php?search='+searchValue;
});
$('#txtSearch').keypress(function(e){
if(e.which == 13){ //Enter key pressed
$('#btnSearch').click();//Trigger search button click event
}
});
$("#txtSearch").click(function(){
$("#txtSearch").val("");
})
});
var PageComponent = {
periodList: document.getElementById('periodList')
};
var APForm = {
form: document.getElementById('addPeriodForm'),
schoolyear: document.getElementById('addPeriodForm_SCHOOLYEAR'),
periodname: document.getElementById('addPeriodForm_PERIODNAME'),
periodstart: document.getElementById('addPeriodForm_PERIODSTART'),
periodend: document.getElementById('addPeriodForm_PERIODEND'),
submit: document.getElementById('addPeriodForm_SUBMIT'),
modal: '#addPeriodForm_SUBMIT'
}
APForm.form.onsubmit = function (e)
{
e.preventDefault();
$(this).ajaxSubmit({
beforeSend:function()
{
$(APForm.submit).button('loading');
},
uploadProgress:function(event,position,total,percentComplete)
{
},
success:function(data)
{
$(APForm.submit).button('reset');
var server_message = data.trim();
if(!isWhitespace(GetSuccessMsg(server_message)))
{
$(APForm.modal).modal('hide');
alert('Added Succesfully');
window.location.reload(false);
APForm.form.reset();
}
else if(!isWhitespace(GetWarningMsg(server_message)))
{
alert(GetWarningMsg(server_message));
}
else if(!isWhitespace(GetErrorMsg(server_message)))
{
alert(GetErrorMsg(server_message));
}
else if(!isWhitespace(GetServerMsg(server_message)))
{
alert(GetServerMsg(server_message));
}
else
{
alert('Oh Snap! There is a problem with the server or your connection.');
}
}
});
};
var PDForm = {
form: document.getElementById('deletePeriodForm'),
modal: document.getElementById('deletePeriodForm_MODAL'),
id: document.getElementById('deletePeriodForm_ID'),
schoolyear: document.getElementById('deletePeriodForm_SCHOOLYEAR'),
periodname: document.getElementById('deletePeriodForm_PERIODNAME'),
periodstart: document.getElementById('deletePeriodForm_PERIODSTART'),
periodend: document.getElementById('deletePeriodForm_PERIODEND'),
datecreated: document.getElementById('deletePeriodForm_DATECREATED'),
status: document.getElementById('deletePeriodForm_STATUS'),
submit: document.getElementById('deletePeriodForm_SUBMIT')
}
$(PDForm.form).on('submit', function (e) {
var id = PDForm.id.value;
e.preventDefault();
$(this).ajaxSubmit({
beforeSend:function()
{
$(PDForm.submit).button('loading');
},
uploadProgress:function(event,position,total,percentCompelete)
{
},
success:function(data)
{
$(PDForm.submit).button('reset');
deletePeriod(id);
PDForm.form.reset();
$(PDForm.modal).modal('hide');
alert('Succesfully Deleted');
}
});
});
function deletePeriod(id) {
$('#period_' + id).remove();
}
function openDeletePeriodModal(id) {
PDForm.id.value = id;
PDForm.periodname.innerHTML = document.getElementById('period_NAME_'+id).innerHTML;
PDForm.periodstart.innerHTML = document.getElementById('period_START_'+id).innerHTML;
PDForm.periodend.innerHTML = document.getElementById('period_END_'+id).innerHTML;
PDForm.schoolyear.innerHTML = document.getElementById('period_SCHOOLYEAR_'+id).innerHTML;
PDForm.datecreated.innerHTML = document.getElementById('period_DATECREATED_'+id).innerHTML;
PDForm.status.innerHTML = document.getElementById('period_STATUS_'+id).innerHTML;
$(PDForm.modal).modal('show');
}
function addPeriodList(id, schoolyear, pname, pstart, pend, datecreated, status)
{
PageComponent.periodList.innerHTML = PageComponent.periodList.innerHTML +
'<thead>'+
'<tr id = "period_'+ id +'">'+
' <td scope = "col" id = "period_NAME_' + id +'">' + pname + '</td>'+
' <td scope = "col" id = "period_START_' + id +'">' + pstart + '</td>'+
' <td scope = "col" id = "period_END_' + id +'">' + pend + '</td>'+
' <td scope = "col" id = "period_STATUS_' + id + '">' + status + '</td>'+
' <td scope = "col" id = "period_SCHOOLYEAR_' + id + '" hidden>' + schoolyear + '</td>'+
' <td scope = "col" id = "period_DATECREATED_' + id + '" hidden>' + datecreated + '</td>'+
' <td><div class = "btn-group" role = "group"><button id="period_BTNDELETE_' + id + '" value="' + id + '" class="btn btn-warning ml-1" role = "button" onclick="openDeletePeriodModal(' + id + ')"><i class="far fa-trash-alt"></i></button></div></td>'+
// ' <td><div class = "btn-group" role = "group"><button id="period_BTNUPDATE_' + id + '" value="' + id + '" data-target = "#updatePeriodForm_MODAL" data-toggle = "modal" onclick = "updatePeriodFill(\'' + id + '\')"class="btn btn-primary"><i class="far fa-edit"></i></button><button id="period_BTNDELETE_' + id + '" value="' + id + '" class="btn btn-warning ml-1" role = "button" onclick="openDeletePeriodModal(' + id + ')"><i class="far fa-trash-alt"></i></button></div></td>'+
'</tr>'+
'</thead>';
}
<?php
$list_sql = '
WITH OrderedList AS
(
SELECT
Period.idPeriod,
Period.idSchoolYear,
SchoolYear.SYYear,
Period.PName,
Period.PStart,
Period.PEnd,
Period.PStatus,
Period.PDateCreated,
ROW_NUMBER() OVER (ORDER BY Period.idPeriod) AS "RowNumber"
FROM Period
INNER JOIN SchoolYear
On SchoolYear.idSchoolYear = Period.idSchoolYear
WHERE Period.PName LIKE ? AND Period.idSchoolYear = ?
)
SELECT *
FROM OrderedList
WHERE RowNumber BETWEEN ? AND ?';
$list_getResult = $db->connection->prepare($list_sql);
$list_getResult->bindparam(1, $search);
$list_getResult->bindparam(2, $getschoolyear);
$list_getResult->bindparam(3, $limit);
$list_getResult->bindparam(4, $offset);
$list_getResult->execute();
$list_count = $list_getResult->RowCount();
if($list_count > 0){
?>
var content = '<tr>'+
'<tr>'+
'<td id = "period_TITLE_">No Period Found</td>'+
'<tr>';
$("#periodList").append(content);
<?php
}
else
{
foreach($list_getResult as $list_row)
{
$result_ID = htmlspecialchars($list_row['idPeriod']);
$result_SCHOOLYEAR = htmlspecialchars($list_row['SYYear']);
$result_PERIODNAME = htmlspecialchars($list_row['PName']);
$result_PERIODSTART = htmlspecialchars($list_row['PStart']);
$result_PERIODEND = htmlspecialchars($list_row['PEnd']);
$result_DATECREATED = htmlspecialchars($list_row['PDateCreated']);
$result_STATUS = htmlspecialchars($list_row['PStatus']);
if($result_STATUS == True)
{
$result_STATUS = 'Active';
}
else
{
$result_STATUS = 'Inactive';
}
?>
addPeriodList("<?php echo $result_ID ?>","<?php echo $result_SCHOOLYEAR ?>","<?php echo $result_PERIODNAME ?>","<?php echo $result_PERIODSTART ?>","<?php echo $result_PERIODEND?>","<?php echo $result_DATECREATED ?>","<?php echo $result_STATUS ?>");
<?php
}
}
?>
</script>