JezK
Edit File: add_stafftoroute.php
<?php session_start(); include("session_check.php"); include("menuheader.php"); if(!(in_array(5,$access) && in_array(5,$allow))) echo "<script>location.replace('dashboard.php');</script>"; $operations1=new adm_operations(); $schid=$_SESSION['child']['log_school_id']; $acdid=$_SESSION['child']['choosen_academic_id']; $pdr=0; if(isset($_POST['adroute'])) { $rtid=$_POST['route']; $stff=$_POST['usersdata']; $academic_id=$_SESSION['child']['choosen_academic_id']; $me=$_SESSION['child']['auth_id']; if($_POST['stype']!=2 && !empty($_SESSION['prstf'])) { foreach($_SESSION['prstf'] as $stid) { if(!in_array($stid,$stff)) { $delstfrt=$operations1->removeRoutetostaff($stid,$academic_id,$rtid); } } } for($i=0;$i<count($stff);$i++) { $op=$operations1->addroute2staff($rtid,$stff[$i],$academic_id,$me,$_POST['stype'],$_POST['prevdvr']); if($op=='single') { $ur="transport_management.php?route_id=".$rtid; unset($_SESSION['prstf']); echo '<script>location.replace("'.$ur.'");</script>'; } else echo "<script>alert('One route can not be assigned more than one driver');</script>"; } } $op=$operations1->getroutes2schid($schid,$acdid); if(empty($op)) { $routes.='<option value="0">--Select Route--</option>'; } else { $routes.='<option value="0">--Select Route--</option>'; foreach($op as $opp) { if($_GET['rid']==$opp['route_id']) $routes.='<option value='.$opp['route_id'].' selected>'.$opp['route_number'].' ('.$opp['source_name'].'-'.$opp['destination_name'].')</option>'; else $routes.='<option value='.$opp['route_id'].'>'.$opp['route_number'].' ('.$opp['source_name'].'-'.$opp['destination_name'].')</option>'; } } if($_GET['rid']!='' && $_GET['type']) { $op1=$operations1->getstaff2schid1($schid,$acdid,$_GET['rid'],$_GET['type']); } if(empty($op1)) { $staff.=''; } else { if(isset($_POST['usersdata'])) { $k=1; $f=0; foreach($op1 as $op2) { $tp=""; if($op2['staff_id']==$_POST['usersdata'][$f] && isset($_GET['rid'])) { $sh="checked"; $pdr=$op2['staff_route_id']; } else { $sh=""; } switch($op2['staff_type']) { case 1:$tp="Teacher";break; case 2:$tp="Driver";break; case 3:$tp="Admin Staff";break; case 4:$tp="Maid";break; case 5:$tp="Others";break; } $staff.='<tr> <td class="col-sm-1 text-center" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;padding-top:10px; "><label class="checkbox-inline"><input type="checkbox" '.$sh.' name="usersdata[]" value="'.$op2['staff_id'].'" id="'.$k.'" >'.$k.'</label></td> <td class="col-sm-2 text-center" style=" font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_name'].'</td> <td style=" font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_address'].'</td> <td style="font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_mobile'].'</td> <td style="font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$tp.'</td> </tr>'; $k++; } } else { $k=1; foreach($op1 as $op2) { $tp=""; if($_GET['rid']==$op2['route_id'] && isset($_GET['rid'])) { $sh="checked"; $pdr=$op2['staff_route_id']; $_SESSION['prstf'][$k]=$op2['staff_id']; } else { $sh=""; } switch($op2['staff_type']) { case 1:$tp="Teacher";break; case 2:$tp="Driver";break; case 3:$tp="Admin Staff";break; case 4:$tp="Maid";break; case 5:$tp="Others";break; } $staff.='<tr> <td class="col-sm-1 text-center" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; "><label class="checkbox-inline"><input style="padding-top:10px;" type="checkbox" '.$sh.' name="usersdata[]" value="'.$op2['staff_id'].'" id="'.$k.'" >'.$k.'</label></td> <td class="col-sm-2 text-center" style=" font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_name'].'</td> <td style=" font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_address'].'</td> <td style="font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$op2['staff_mobile'].'</td> <td style="font-size:14px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; padding-top:10px;">'.$tp.'</td> </tr>'; $k++; } } } ?> <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: 1px; } </style> <script> function fetchstops(val) { //$.post("getstops.php",{id:val},function(data){document.getElementById("stop").innerHTML=data;}); var rt=$("#route").val(); var st=$("#stype").val(); $("#err_route").text(""); $("#err_stype").text(""); if(rt==0) { $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if(st!=0 && rt!=0) { window.location.href="add_stafftoroute.php?rid="+rt+"&type="+st; } } function stafftypeload() { var rt=$("#route").val(); var st=$("#stype").val(); $("#err_route").text(""); $("#err_stype").text(""); if(rt==0) { $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if(st==0) { $("#err_stype").text("Please select Staff Type"); $("#err_stype").show(); return false; } else { window.location.href="add_stafftoroute.php?rid="+rt+"&type="+st; } } function formvalid() { $("#err_route").text(""); var st=$("#stype").val(); var staff=document.getElementsByName('usersdata[]'); k=0; if(document.getElementById('route').value==0) { $("#err_route").text("Please select Route"); $("#err_route").show(); return false; } else if(st==0) { $("#err_stype").text("Please select Staff Type"); $("#err_stype").show(); return false; } for(i=0;i<staff.length;i++) { if(staff[i].checked==true) { k=k+1; } } if(k==0) { alert('Please add atleast one Staff Member to Route'); return false; } else if(k>1 && st==2) { alert('One route can not be assigned more than one driver'); return false; } } function getstaffhere(stf) { var r=document.getElementById('route').value; if(r!=0 && stf!=0) { window.location.href="add_stafftoroute.php?rid="+r; } } </script> <body style="overflow-x: hidden;"> <div class="row" style="margin-top:20px;"> <div class="col-md-9 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:14px; color:#000000; font-size:1.4em;margin-left:25px;"> <i class=" glyphicon glyphicon-plus " title =" Add Staff to Route" style="font-size: 16px;"></i> Add Staff to Route </div> <div class="col-md-2 text-center"> <!--<button type="button" onClick="" class="btn btn-default" style="margin-right:20px;font-family: Arial, Helvetica, sans-serif; font-size:14px;padding:4px 10px;"> Add Route </button>--> </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="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-5 text-right"> <b style="color:#666666; margin-left:20%; ">Select Route</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <select class="form-control" id="route" name="route" style="height:29px; font-size:12px; width:300px !important;" tabindex="1" onchange="fetchstops();"> <?php echo $routes;?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_route" style="color:#990000;margin-left:-13px; display:none; width:200px;"></div> <!--- end error--> </div> </div> </div> <div class="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-5 text-right"> <b style="color:#666666; margin-left:20%; ">Select Staff Type</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <select class="form-control" id="stype" name="stype" style="height:29px; font-size:12px; width:300px !important;" tabindex="2" onchange="stafftypeload();"> <? $st=array("Select Staff Type","Teacher","Driver","Admin Staff","Maid","Others"); for($o=0;$o<count($st);$o++) if($o==$_GET['type']) echo '<option value="'.$o.'" selected>'.$st[$o].'</option>'; else echo '<option value="'.$o.'">'.$st[$o].'</option>'; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_stype" style="color:#990000;margin-left:-13px; display:none; width:200px;"></div> <!--- end error--> </div> <input type="hidden" name="prevdvr" value="<?php echo $pdr?>"> </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="margin-top:-40px; font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"> <thead> <tr class="info"> <th class="col-md-1 text-center"> S.No</th> <th>Staff Name</th> <th>Staff Address</th> <th>Staff Phone Number</th> <th>Staff Type</th> </tr> </thead> <tbody> <?php echo $staff;?> </tbody> </table> </div> </div> <div class="form-group" > <div class="col-md-12" align="center"> <button type="submit" class="btn btn-default custom-button-width .navbar-right btnclr" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" name="adroute" onclick="return formvalid();" >Add</button> <button type="button" class="btn btn-default custom-button-width .navbar-right btnclr" onclick="window.location.href='transport_management.php'" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; " >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() { $('#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'); }); /* $(function () { $('th input[type="checkbox"]').click(function(){ if ($(this).is(':checked')) $('td input[type="checkbox"]').prop('checked', true); else $('td input[type="checkbox"]').prop('checked', false); }) }); $(function() { $('td input[type="checkbox"]').click(function() { if ($(this).is(':checked')) {} else $('th input[type="checkbox"]').prop('checked', false); }) });*/ </script> </body> </html>