JezK
Edit File: edit_academicyear.php
<?php if (session_id() == '') { session_start(); } include("session_check.php"); include('adm_operations.php'); include("header.php"); $operations = new adm_operations(); include('school_timeout.php'); if (isset($_POST['dateupdate'])) { if (date('y-m-d', strtotime(str_replace('/', '-', $_POST['startdate']))) > date('y-m-d', strtotime(str_replace('/', '-', $_POST['startdate'])))) { echo "<script>alert('End Date should be greater than Start Date');</script>"; } else { $result = $operations->getEditAcadamicYear($_SESSION['child']['log_school_id'], $_POST['acdid'], $_SESSION['child']['auth_id'], $_POST['startdate'], $_POST['enddate']); if ($result == 'not2change') echo "<script>alert('You can not change the Start date of the Current Academic year as there is some data associated with it');</script>"; else if ($result == 'past_not_allow') echo "<script>alert('You can not change the Start and End dates of the past Academic Years as there is some data associated with it');</script>"; else if ($result == 'end_not_allow') echo "<script>alert('End date of Current Academic Year can not be less than current date');</script>"; else if ($result == 'year1exist') echo "<script>alert('An Academic Year with the overlapping date already exists');</script>"; else if ($result == 'year2exist') echo "<script>alert('An Academic Year with the overlapping date already exists');</script>"; else { include('yearmanager.php'); $srt = str_replace('/', '-', $_POST['startdate']); $end = str_replace('/', '-', $_POST['enddate']); $startdate = date('Y-m-d', strtotime($srt)); $enddate = date('Y-m-d', strtotime($end)); if ($_SESSION['child']['choosen_academic_id'] == $_POST['acdid']) { if (date('Y', strtotime($startdate)) == date('Y', strtotime($enddate))) $_SESSION['child']['choosen_year_name'] = date('Y', strtotime($startdate)); else $_SESSION['child']['choosen_year_name'] = date('Y', strtotime($srt)) . '-' . date('y', strtotime($end)); } echo "<script>location.replace('academicyear_management.php');</script>"; } } } $result = $operations->getAcadamicYearwithId($_GET['ac_id']); //include("header.php"); ?> <script> function checkacademicdates() { $("#err_start").text(""); $("#err_end").text(""); var date1 = document.getElementById('startdate').value; var date2 = document.getElementById('enddate').value; var arrStartDate = date1.split("/"); var arrEndDate = date2.split("/"); var sDate = new Date(arrStartDate[2], arrStartDate[1], arrStartDate[0]); var eDate = new Date(arrEndDate[2], arrEndDate[1], arrEndDate[0]); // regular expression to match required date format re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; if (date1 == '') { $("#err_start").text('Please select Start Date'); $("#err_start").show(); return false; } else if (!date1.match(re)) { $("#err_start").text("Invalid date format: " + date1); $("#err_start").show(); return false; } else if (date2 == '') { $("#err_end").text('Please select End Date'); $("#err_end").show(); return false; } else if (!date2.match(re)) { $("#err_end").text("Invalid date format: " + date2); $("#err_end").show(); return false; } else if (sDate >= eDate) { alert("End Date should be greater than Start Date"); return false; } } function backtoprevious() { window.location.href = "academicyear_management.php"; } </script> <body style="overflow-x: hidden;"> <div class="row" style="margin-top:30px;"> <div class="col-md-4 text-center" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:14px; color:#000000; font-size:1.4em;"> <i class=" fa-solid fa-pencil" title="Edit Academic Year" style="font-size: 16px;"></i> Edit Academic Year </div> </div> <form method="post"> <div class="row" style="margin-top:50px;"> <div class="col-md-2 text-md-end" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"> Start Date<span style="color:#FF0000; margin:2px;">*</span> </div> <input type="hidden" name="acdid" value="<?php echo $_GET['ac_id']; ?>"> <div class="col-md-4 "> <div id="datepicker" class="input-group date"> <input type="text " class="form-control" style="font-size:13px;" name="startdate" id="startdate" value="<?php if (isset($_POST['startdate'])) echo $_POST['startdate']; else echo $result['academic_startdate']; ?>"> <span class="input-group-append"> <span class="input-group-text bg-light d-block add-on"> <i class="fa fa-calendar-days"></i> <!-- <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> --> </span> </span> </div> <!-- if there is an error--> <div class="col-md-10" id="err_start" style="color:#990000;"></div> <!--- end error--> </div> </div> <div class="row" style="margin-top:20px;"> <div class="col-md-2 text-md-end" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"> End Date<span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-4 "> <div id="datepicker1" class="input-group date"> <input type="text" class="form-control" style=" font-size:13px;" name="enddate" id="enddate" value="<?php if (isset($_POST['enddate'])) echo $_POST['enddate']; else echo $result['academic_enddate']; ?>"> <span class="input-group-append"> <span class="input-group-text bg-light d-block add-on"> <!-- <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> --> <i class="fa fa-calendar-days"></i> </span> </span> </div> <!-- if there is an error--> <div class="col-md-10" id="err_end" style="color:#990000;"></div> <!--- end error--> </div> </div> <div class="form-group"> <div class="col-md-6" align="center"> <button type="submit" name="dateupdate" class="btn btn-outline-secondary btnclr" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;margin-top:20px;" id="aybtn" onclick="return checkacademicdates();">Update</button> <button type="button" class="btn btn-outline-secondary btnclr" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;margin-top:20px;" onclick="backtoprevious()">Cancel</button> </div> </div> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-datepicker@1.9.0/dist/css/bootstrap-datepicker.min.css"> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script type="text/javascript" src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"> </script> <script type="text/javascript" src="https://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 src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script type="text/javascript"> // $('#datetimepicker').datetimepicker({ // format: 'dd/MM/yyyy', // pickTime: false // }).on('changeDate', function() { // $(this).datetimepicker('hide'); // }); $(function() { $('#datepicker').datepicker({ format: 'dd/mm/yyyy', minView: 2, pickTime: false }).on('changeDate', function() { $(this).datepicker('hide'); }); }); </script> <script type="text/javascript"> // $('#datetimepicker1').datetimepicker({ // format: 'dd/MM/yyyy', // pickTime: false // }).on('changeDate', function() { // $(this).datetimepicker('hide'); // }); $(function() { $('#datepicker1').datepicker({ format: 'dd/mm/yyyy', minView: 2, pickTime: false }).on('changeDate', function() { $(this).datepicker('hide'); }); }); </script> <script> $(document).ready(function() { $("#aybtn").prop("disabled", false); }); </script> </body> </html>