JezK
Edit File: add_studenttoroute.php
<?php session_start(); include("menuheader.php"); if (!(in_array(5, $access) && in_array(5, $allow))) echo "<script>location.replace('dashboard.php');</script>"; include_once("school_admin_access_app.php"); $fun = new adminaccess(); $school_id = $_SESSION['child']['log_school_id']; //school_id $academic_id = $_SESSION['child']['choosen_academic_id']; // academic_year_id $user_id = $_SESSION['child']['auth_id']; //user_id $details = $fun->get_classes($school_id, $academic_id); $sections = $fun->get_sections($_GET['classid'], $academic_id); $routes = $fun->school_students_routes($school_id, $academic_id); // print_r($routes);exit; if ($details) { foreach ($details as $row) { if ($_GET['classid'] == $row['class_id']) { $classes_list .= "<option value='{$row['class_id']}' selected>{$row['class_name']}</option>"; } else { $classes_list .= "<option value='{$row['class_id']}' >{$row['class_name']}</option>"; } } } if ($sections) { foreach ($sections as $row) { if ($_GET['sec_id'] == $row['section_id']) { $secs .= "<option value='{$row['section_id']}' selected>{$row['section_name']}</option>"; } else { $secs .= "<option value='{$row['section_id']}' >{$row['section_name']}</option>"; } } } if ($routes) { foreach ($routes as $row) { if ($_GET['route_id'] == $row['route_id']) { $route_info .= "<option value='{$row['route_id']}' selected>{$row['route_name']}</option>"; } else { $route_info .= "<option value='{$row['route_id']}' >{$row['route_name']}</option>"; } } } if (isset($_GET['route_id'])) { $stops = $fun->route_stops($_GET['route_id'], $academic_id); } if (isset($_GET['classid']) && isset($_GET['sec_id']) && isset($_GET['route_id'])) { $getstudents = $fun->get_students_for_routes($_GET['classid'], $_GET['sec_id'], $_GET['route_id'], $school_id, $academic_id); } if (isset($_POST['route_submit'])) { $data = $_POST['check_list']; $route_id = $_POST['routes']; foreach ($data as $std) { $stop_id[$std] = $_POST['pickup' . $std]; } $details = $fun->addstudents_route($data, $route_id, $stop_id, $academic_id); if ($details == "success") { echo "<script>location.replace('transport_management.php?route_id=" . $route_id . "');</script>"; } } ?> <style> select { width: 62px !important; background-color: #FFF; border: 1px solid #CCC; } .table-condensed>thead>tr>th, .table-condensed>tbody>tr>th, .table-condensed>tfoot>tr>th, .table-condensed>thead>tr>td, .table-condensed>tbody>tr>td, .table-condensed>tfoot>tr>td { padding: 3px; } .checkbox input[type=checkbox], .checkbox-inline input[type=checkbox], .radio input[type=radio], .radio-inline input[type=radio] { position: absolute; margin-left: -15px; margin-top: 4px; } </style> <body style="overflow-x: hidden;"> <div class="row" style="margin-top:20px;"> <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-plus " title="Add Student to Route" style="font-size: 20px;margin:0px 0px 0px -48px;"></i> Add Student to Route </div> </div> <form class="form-horizontal" method="post"> <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-6 col-md-offset-1 text-md-end"> <b style="color:#666666; ">Select Route</b> <span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <select class="form-select" id="routes" name="routes" style="height:29px; font-size:12px; width:300px !important;" tabindex="1"> <option value='0' selected>--Select Route--</option> <?php echo $route_info; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_route" style="color:#990000;margin-left:-12px; display:none; width:200px;"></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-6 col-md-offset-1 text-md-end"> <b style="color:#666666; ">Choose Class</b> <span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <select class="form-select" id="classes" name="classes" style="height:29px; font-size:13px; width:300px!important; " tabindex="2"> <option value='0' selected>--Select Class--</option> <?php echo $classes_list; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_class" style="color:#990000;margin-left:-12px; display:none; width:200px;"></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-6 col-md-offset-1 text-md-end"> <b style="color:#666666; ">Choose Section</b> <span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <select class="form-select" id="sections" name="sections" style="height:29px; font-size:13px; width:300px!important;" tabindex="3"> <option value='0' selected>--Select Section--</option> <?php echo $secs; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_section" style="color:#990000;margin-left:-12px; display:none; width:200px;"></div> <!--- end error--> </div> </div> </div> </div> <div class="row" style="margin-left:10px;margin-right:10px;"> <div class="col-md-12 centered" style="font-family: Arial, Helvetica, sans-serif;margin-top:10px;"> <table id="myTable" class="table table-condensed table-hover" style=" font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"> <thead> <tr class="info"> <th class="col-md-2 text-center" style="width:20%">Student Roll No</th> <th style="width:20%">Student Name</th> <th style="width:20%">Address</th> <!--<th>Section</th>--> <th style="width:40%">Pickup/Drop</th> </tr> </thead> <tbody> <?php if ($getstudents) { $i = 1; foreach ($getstudents as $value) { if ($stops) { $stops_info = ''; $chec = ""; foreach ($stops as $row) { if ($value['route_stop'] == $row['route_stop_id'] && $_GET['route_id'] == $value['route_id']) { $stops_info .= "<option value='{$row['route_stop_id']}' selected>{$row['route_stop_name']}</option>"; $chec = "checked"; } else { $stops_info .= "<option value='{$row['route_stop_id']}' >{$row['route_stop_name']}</option>"; } } } ?> <tr> <td class="col-sm-1 text-center" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;width:20% ;padding-top:10px;"> <label class="checkbox-inline"> <input type="checkbox" class="selectchk" name="check_list[]" id="ck<?php echo $i; ?>" value="<?php echo $value['student_id'] ?>" <?php echo $chec; ?> /> <?php echo $value['student_rollno'] ?> </label> </td> <td class=" text-center" style=" font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;padding-top:9px;width:20%"><?php echo $value['student_name'] ?></td> <td style=" font-size:14px;font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;padding-top:9px;width:20%"><?php echo $value['student_address'] ?></td> <!--<td style="font-size:14px;font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:9px;"></td>--> <td style="font-size:14px;font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;width:40%"> <div class="col-md-6"> <select class="form-control" name="pickup<?php echo $value['student_id'] ?>" id="picup<?php echo $value['student_id'] ?>" style="height:29px; font-size:13px; width:300px!important;margin-left: -16px;"> <option value='0'>--Select Pickup/Drop--</option> <?php echo $stops_info; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_pickup<?php echo $i ?>" style="color:#990000;margin-left:-29px; display:none; width:200px;"></div> <!--- end error--> </div> </td> </tr> <?php $i++; } } ?> </tbody> </table> </div> </div> <div class="col-md-10" id="errprevilage" style="color:#990000;margin-left:250px;"></div> <div class="form-group"> <div class="col-md-12" align="center"> <input type="submit" onclick=" return validation()" name="route_submit" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="19" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:20px; " value="Add"> <button type="button" class="btn btn-outline-secondary custom-button-width .navbar-right btnclr" tabindex="20" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:20px; " onclick="location.href='transport_management.php'">Cancel</button> </div> </div> </form> <script type="text/javascript" language="javascript" src="Excel/media/js/jquery.js"></script> <script type="text/javascript" language="javascript" src="Excel/media/js/jquery.dataTables.js"></script> <script type="text/javascript" language="javascript" src="Excel/js/dataTables.tableTools.js"></script> <script type="text/javascript" language="javascript" src="Excel/examples/resources/syntax/shCore.js"></script> <script type="text/javascript" language="javascript" src="Excel/examples/resources/demo.js"></script> <script type="text/javascript" language="javascript" class="init"> $(document).ready(function() { $('#errprevilage').hide(); $('#myTable').DataTable({ dom: 'T<"clear">lfrtip', "oLanguage": { "sSearch": "" }, tableTools: { "aButtons": [ "xls", { "sExtends": "pdf", "sPdfOrientation": "landscape", "sPdfMessage": "Your custom message would go here." }, "print" ] }, "bSort": false }); $('div.dataTables_filter input').attr('placeholder', 'Search'); $("#classes").change(function() { $("#err_class").text(""); if ($(this).val() == 0) { var section_option = '<option value="0">--Select Section--</option>'; $("#sections").html(section_option); $("#err_class").text("Please select Class"); $("#err_class").show(); return false; } else { var x = $(this).val(); $.ajax({ url: "ajaxcalls_app.php", type: "POST", data: "mode=" + "choose_class" + "&data=" + x, success: function(result) { //alert(result); //alert("success : "+result); var result2 = eval("(" + result + ")"); //alert(result2[0]); 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) { } }); } }); $("#pickup").change(function() { $("#err_pickup").text(""); if ($("#pickup").val() == 0) { $("#err_pickup").text("Please select Pickup/Drop"); $("#err_pickup").show(); return false; } }); $("#sections").change(function() { $("#err_section").text(""); $("#err_route").text(""); $("#err_pickup").text(""); if ($("#sections").val() == 0) { $("#err_section").text("Please select Section"); $("#err_section").show(); return false; } else if ($("#routes").val() == 0) { var section_option = '<option value="0">--Select Stop--</option>'; $("#pickup").html(section_option); $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if ($("#pickup").val() == 0) { $("#err_pickup").text("Please select Pickup/Drop"); $("#err_pickup").show(); return false; } else { var cls = $("#classes").val(); var sec_id = $("#sections").val(); var route_num = $("#routes").val(); var route_stop_id = $("#pickup").val(); window.location.href = "add_studenttoroute.php?classid=" + cls + "&route_id=" + route_num + "&sec_id=" + sec_id; } }); $("#routes").change(function() { $("#err_route").text(""); var cln = $("#classes").val(); var scn = $("#sections").val(); var rtn = $("#routes").val(); if (rtn == 0) { $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if (cln != 0 && scn != 0 && rtn != 0) { window.location.href = "add_studenttoroute.php?classid=" + cln + "&route_id=" + rtn + "&sec_id=" + scn; } }); }); </script> <script> function validation() { var cnt = 0; var j = 1; $("#err_route").text(""); $("#err_class").text(""); $("#err_section").text(""); if ($("#routes").val() == 0) { $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if ($("#classes").val() == 0) { $("#err_class").text("Please select Class"); $("#err_class").show(); return false; } else if ($("#sections").val() == 0) { $("#err_section").text("Please select Section"); $("#err_section").show(); return false; } var checkb = document.getElementsByName("check_list[]"); for (var ctr = 1; ctr <= checkb.length; ctr++) { $("#err_pickup" + ctr).text(""); } for (var i = 0; i < checkb.length; i++) { $("#err_pickup" + j).text(""); var per = checkb[i].value; var stp = $('#picup' + per).val(); if (checkb[i].checked) { if (stp == 0) { $("#err_pickup" + j).text("Please select Stop"); $("#err_pickup" + j).show(); return false; } cnt = 1; } j++; } if (cnt == 0) { alert('Please add atleast one Student to Route'); return false; } for (var i = 0, j = 1; i < checkb.length; i++) { var per = checkb[i].value; var stp = $('#picup' + per).val(); if (stp != 0) { if (checkb[i].checked == false) { alert("Please select the student also if the stop has been selected"); $('#ck' + j).focus(); return false; } } j++; } } </script> </body> </html>