JezK
Edit File: update_homework.php
<?php session_start(); include("session_check.php"); include("menuheader.php"); include_once("school_admin_access_file.php"); $fun = new adminaccess(); if (!(in_array(2, $access) && in_array(2, $allow))) echo "<script>location.replace('dashboard.php');</script>"; /*************************** checking school existance in system*****************/ $timeout = $fun->check_my_status($_SESSION['child']['log_school_id']); if ($timeout == 0) echo "<script>location.replace('logout.php');</script>"; /***************************end*********************************************/ $school_id = $_SESSION['child']['log_school_id']; //school_id $academic_id = $_SESSION['child']['choosen_academic_id']; $user_id = $_SESSION['child']['auth_id']; // academic_year_id $details = $fun->get_classes($school_id, $academic_id); $chosen_date = $fun->get_current_academicyear_id($academic_id, $school_id); if (isset($_POST['asubmit'])) { if ($_POST['hw'] != '') { if ($_FILES["attachment"]["name"]) { $t = $_FILES["attachment"]["tmp_name"]; $n = $_FILES["attachment"]["name"]; $p = strtotime(date('d-m-Y H:i:s')); $k = substr(str_shuffle($p), 0, 5); $tfname = $k . $n; if (move_uploaded_file($t, "uploads/homework/" . $tfname)) { $attachment_file = $tfname; } } $update = $fun->update_homework($_POST['hw'], $_POST['des'], $_POST['classes'], $_POST['sections'], $_POST['subject_id'], $_POST['datepicker'], $academic_id, $school_id, $user_id, $attachment_file); if ($update == 1) echo "<script>location.replace('diary_management.php?classid=" . $_POST[classes] . "&sec_id=" . $_POST[sections] . "&date=" . $_POST['datepicker'] . "');</script>"; else echo "<script>alert('could not update the diary at this moment');</script>"; } else if (($_POST['hw'] == '') && $_POST['classes'] != '' && $_POST['sections'] != '' && $_POST['subject_id'] != '' && $_POST['datepicker'] != '' && $_POST['des'] != '') { if ($_FILES["attachment"]["name"]) { $t = $_FILES["attachment"]["tmp_name"]; $n = $_FILES["attachment"]["name"]; $p = strtotime(date('d-m-Y H:i:s')); $k = substr(str_shuffle($p), 0, 5); $tfname = $k . $n; if (move_uploaded_file($t, "uploads/homework/" . $tfname)) { $attachment_file = $tfname; } } $add = $fun->addhomework($_POST['classes'], $_POST['sections'], $_POST['subject_id'], $_POST['datepicker'], $_POST['des'], $user_id, $school_id, $academic_id, $attachment_file); if ($add == 1) echo "<script>location.replace('diary_management.php?classid=" . $_POST[classes] . "&sec_id=" . $_POST[sections] . "&date=" . $_POST['datepicker'] . "');</script>"; else echo "<script>alert('could not add the diary at this moment');</script>"; } } ?> <style> #nav { margin: auto; width: 427px !important; padding-left: 0; padding-right: 0; list-style: none; background: rgb(51, 93, 220) none repeat scroll 0% 0%; } #nav li { display: inline-block; margin: 0 auto; text-align: center; } #nav li a { display: inline-block; padding: 7px 0; text-align: center; text-decoration: none; color: #FFFFFF; margin: auto; } #nav li:hover, li:active { background-color: rgb(54, 120, 102); width: 90px; } #nav li.selected { background: rgb(54, 120, 102); } select { width: 62px !important; background-color: #FFF; border: 1px solid #CCC; } .multiselect { width: 290px; } .selectBox { position: relative; } .selectBox select { width: 100%; font-weight: bold; } .overSelect { position: absolute; left: 0; right: 0; top: 0; bottom: 0; } #checkboxes { display: none; border: 1px #dadada solid; } #checkboxes label { display: block; } #checkboxes label:hover { background-color: #1e90ff; } </style> <body style="overflow-x: hidden;"> <div class="row" style="margin-top: 30px;margin-top:30px;"> <div class="col-md-9 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:24px; margin-left:20px;"><i class=" fa-solid fa-plus" title="Update Homework" style="font-size: 20px;"></i> Add/Update Home Work </div> </div> <br> <div class="menuu"> <ul id="nav" class="margn_auto text-center"> <li class="selected" style="border-right:1px solid #FFFFFF;width:214px; text-align:center;margin-left:-3px;font-family:Arial, Helvetica, sans-serif;font-style:normal; font-size:14px;"> <a href="diary_management.php"><img src="images/hom-work_white.png" title="Home Work" style="margin-right:5px;" />Home Work</a> </li> <li style="width:215px; text-align:center; margin-left:-3px; font-family:Arial, Helvetica, sans-serif;font-style:normal; font-size:14px;"> <a href="general_comments.php"><img src="images/general-comments_white.png" title="General Comments" style="margin-right:5px;" />General Comments</a> </li> </ul> </div> <form class="form-horizontal" style="margin-top:30px;" method="post" enctype="multipart/form-data"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px; "> <div class="clearfix"> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 text-md-end"> <b style="color:#666666; ">Class</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="classes" name="classes" style="height:29px; width:295px!important;font-size:12px;" tabindex="1" onchange="onchangeClass_Sbj(this.value)"> <option value='0'>--Select Class--</option> <?php foreach ($details as $row) { echo "<option value='{$row['class_id']}' >{$row['class_name']}</option>"; } ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_class" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <div class="clearfix"> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 text-md-end"> <b style="color:#666666; ">Section</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="sections" name="sections" style="height:29px; width:295px!important;font-size:12px;" tabindex="2" onchange="section_change(this.value)"> <option value='0'>--Select Section--</option> </select> <!-- if there is an error--> <div class="col-md-10" id="err_section" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end"> <b style="color:#666666;">Date</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7 mb-3"> <div class="input-group date" id="datetimepicker"> <input type="text" class="form-control" tabindex="3" id="datepicker" name="datepicker" value="<?= date('d/m/Y') ?>"> <span class="input-group-append"> <span class="input-group-text bg-light d-block "> <i class="fa fa-calendar-days"></i> </span> </span> </div> <!-- <div id="datetimepicker" class="input-append date d-flex"> <input type="text" class="form-control" style="height:30px; width:268px;font-size:13px;" tabindex="3" id="datepicker" name="datepicker" value="<?= date('d/m/Y') ?>"> <span class="add-on" style="height:30px;font-size:20px "> <i class="fa-solid fa-calendar"></i> </span> </div> --> <!-- if there is an error--> <div class="col-md-10" id="err_diarydate" style="color:#990000;"></div> <!--- end error--> </div> </div> <div class="clearfix"> <div class="form-group row col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 text-md-end"> <b style="color:#666666; ">Subject</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-7"> <select class="form-select" id="subjects" style="height:29px; width:295px!important;font-size:12px;" tabindex="1" name="subject_id" onchange="onSubjectChange(this.value)"> <option value='0'>--Select Subject--</option> <!--< echo $subject_name;?>---> </select> <!-- if there is an error--> <div class="col-md-10" id="err_subject" style="color:#990000;"></div> <!--- end error--> </div> </div> </div> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end"> <b style="color:#666666;">Description</b><span style="color:#FF0000; margin:2px; ">*</span> </div> <div class="col-md-7"> <textarea class="form-control" rows="3" style="font-size:13px; width:295px!important;" tabindex="2" id="des" name="des" value="<?php echo $homework['description']; ?>"></textarea> <!-- if there is an error--> <div class="col-md-10" id="err_desc" style="color:#990000;"></div> <!--- end error--> </div> </div> <div class="class"> <div class="form-group row col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-md-end"> <b style="color:#666666;">Attachment</b> </div> <div class="col-md-7"> <input type="file" class="form-control " id="attachment" name="attachment" style="height:40px;font-size:13px;" tabindex="2" value=""> <p><i>(Please upload DOC, XLS, PPT, PDF, GIF, PNG, JPG, JPEG files only. The size of the file should not be greater than 5 MB)</i></p> <!-- if there is an error--> <div class="col-md-10" id="err_desc11" style="color:#990000;"></div> <!--- end error--> </div> </div> <input type="hidden" id="hw" name="hw" value=""> <input type="hidden" id="start_dated" name="start_dates" value="<?php echo $chosen_date['start_date']; ?>"> <input type="hidden" id="end_dated" name="end_dates" value="<?php echo $chosen_date['end_date']; ?>"> <input type="hidden" id="now_dated" name="now_dates" value="<?= date('Y-m-d'); ?>"> <input type="hidden" name="student_ids_data" id="student_ids_data" value=""> <input type="hidden" name="student_allids_data" id="student_allids_data" value=""> <input type="hidden" name="student_allnames_data" id="student_allnames_data" value=""> <input type="hidden" name="student_names_data" id="student_names_data" value=""> <input type="hidden" name="student_names" id="student_names" value=""> <input type="hidden" name="student_ids" id="student_ids" value=""> </div> </div> <div class="form-group"> <div class="col-md-8" align="center"> <input type="submit" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="16" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; " value="Add/Update" name="asubmit" onclick="return validateAllfields();"> <button type="button" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" onClick="location.href='diary_management.php'" tabindex="17" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; ">Cancel</button> </div> </div> </form> <!--<script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"> </script> <script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"> </script>--> <script type="text/javascript" src="js/bootstrap-datetimepicker.js" charset="UTF-8"></script> <script type="text/javascript" src="js/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-datepicker@1.9.0/dist/css/bootstrap-datepicker.min.css"> <!-- JavaScript --> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script> <script type="text/javascript"> //////////////////////////////////////////////////////////////// $('#datetimepicker').datepicker({ format: 'dd/mm/yyyy', minView: 2, pickTime: false, autoclose: true, todayBtn: true, todayHighlight: true }).on('changeDate', function() { $(this).datepicker('hide'); if ($('#datepicker').val() == '') { $('#subjects').val(0); $('#des').val(''); } else { var nwdate = $("#now_dated").val(); var cudate = nwdate.split("-"); var done = $("#start_dated").val(); var dtwo = $("#end_dated").val(); var dayone = done.split('-'); var daytwo = dtwo.split('-'); var cmp = $("#datepicker").val(); var dcmp = cmp.split('/'); var mone = dayone[1] - 1; var mtwos = daytwo[1] - 1; var mcdate = dcmp[1] - 1; var mcheck = cudate[1] - 1; var dones = new Date(dayone[0], mone, dayone[2]); var dtwos = new Date(daytwo[0], mtwos, daytwo[2]); var cdate = new Date(dcmp[2], mcdate, dcmp[0]); var checkd = new Date(cudate[0], mcheck, cudate[2]); if (cdate >= dones && cdate <= dtwos) { if (cdate <= checkd) { common_for_all(); } else { alert("You can not choose a Future date"); } } else { alert("Please choose the date within Chosen Academic Year"); } } }); ////////////////////////////////////////////////////////////////////// function onchangeClass_Sbj(x) { if (x == 0) { section_option = '<option value="0">--Select Section--</option>'; $("#sections").html(section_option); //$('#datepicker').val(''); subject_option = '<option value="0">--Select Subject--</option>'; $("#subjects").html(subject_option); //$('#subjects').val(0); $('#des').val(''); return false; } else { $.ajax({ url: "ajaxcalls_attn.php", type: "POST", data: "mode=" + "choose_class" + "&data=" + x, success: function(result) { var result2 = eval("(" + result + ")"); var section_option = '<option value="0">--Select Section--</option>'; for (var i = 0; i < result2.length; i++) { section_option += '<option value="' + result2[i].section_id + '">' + result2[i].section_name + '</option>'; } $("#sections").html(section_option); }, error: function(e) { alert(e); } }); getthisclasssubjects(x); //$('#datepicker').val(''); $('#desc').val(''); } } function validateAllfields() { $('#err_class').text(''); $('#err_section').text(''); $('#err_diarydate').text(''); $('#err_subject').text(''); $('#err_desc').text(''); var cls = $('#classes').val(); var dt = $('#datepicker').val().trim(); var sec = $('#sections').val(); var subj = $('#subjects').val(); var desc = $('#des').val().trim(); if (cls == 0) { $('#err_class').text("Please select Class"); $('#err_class').show(); return false; } else if (sec == 0) { $('#err_section').text("Please select Section"); $('#err_section').show(); return false; } else if (dt == '') { $('#err_diarydate').text("Please select Date"); $('#err_diarydate').show(); return false; } else if (subj == 0) { $('#err_subject').text("Please select Subject"); $('#err_subject').show(); return false; } else if (desc == '') { $('#err_desc').text("Please enter Home Work Description"); $('#err_desc').show(); return false; } else { var nwdate = $("#now_dated").val(); var cudate = nwdate.split("-"); var done = $("#start_dated").val(); var dtwo = $("#end_dated").val(); var dayone = done.split('-'); var daytwo = dtwo.split('-'); var cmp = $("#datepicker").val(); var dcmp = cmp.split('/'); var mone = dayone[1] - 1; var mtwos = daytwo[1] - 1; var mcdate = dcmp[1] - 1; var mcheck = cudate[1] - 1; var dones = new Date(dayone[0], mone, dayone[2]); var dtwos = new Date(daytwo[0], mtwos, daytwo[2]); var cdate = new Date(dcmp[2], mcdate, dcmp[0]); var checkd = new Date(cudate[0], mcheck, cudate[2]); if (cdate >= dones && cdate <= dtwos) { if (cdate <= checkd) { } else { alert("You can not choose a Future date"); return false; } } else { alert("Please choose the date within Chosen Academic Year"); return false; } } } //////////////////////////////////////////////////////////////////// function section_change(m) { if (m == 0) { //$('#err_section').text("Please select Class"); //$('#err_section').show(); //$('#datepicker').val(''); $('#subjects').val(0); $('#des').val(''); } else { common_for_all(); } } //////////////////////////////////////////////////////////////////// function onSubjectChange(s) { if (s == 0) { $('#des').val(''); } else { common_for_all(); } } ///////////////////////////////////////////////////////////////////// function common_for_all() { var cls = $('#classes').val(); var dt = $('#datepicker').val(); var sec = $('#sections').val(); var subj = $('#subjects').val(); var stud = $('#student_ids_data').val(); if (cls == 0 || sec == 0 || dt == '' || subj == 0 || stud == '') { } else { $.ajax({ url: "ajaxcalls_attn.php", type: "POST", data: "mode=" + "get_homework" + "&cls=" + cls + "&sec=" + sec + "&dt=" + dt + "&subj=" + subj, success: function(res1) { var res2 = eval("(" + res1 + ")"); if (res2 != 0) { $('#des').val(res2[1]); $('#hw').val(res2[0]); } else { $('#des').val(''); $('#hw').val(''); } }, error: function(e) { alert(e); } }); } } /////////////////////////////////////////////////////////////////////// function getthisclasssubjects(z) { $.ajax({ url: "ajaxcalls_attn.php", type: "POST", data: "mode=" + "all_subjects" + "&data=" + z, success: function(result) { var result1 = eval("(" + result + ")"); var subject_option = '<option value="0">--Select Subject--</option>'; for (i = 0; i < result1.length; i++) { subject_option += '<option value="' + result1[i].subject_id + '">' + result1[i].subject_name + '</option>'; } $("#subjects").html(subject_option); }, error: function(e) { alert(e); } }); } </script> </body> </html>