JezK
Edit File: edit_route123.php
<?php session_start(); include("header.php"); include_once("school_admin_access.php"); include_once("school_admin_student.php"); include_once("encription_key.php"); $encrypted_id = $_GET['id']; $admin=new adminaccess(); $encry=new Encryption(); $student=new studentacess(); $school_id = $_SESSION['child']['log_school_id']; $acadamic_id = $_SESSION['child']['choosen_academic_id']; $route_id = $encrypted_id; //$route_id = $encry->decode($encrypted_id); //echo $route_id; $route_details = $student->route_data_byid($route_id); $stop_details = $student->stop_data_byrouteid($route_details['route_id']); // print_r($route_details); // echo "<br>"; //print_r($stop_details); $editids = ''; $ids = ''; if($_POST['action'] == "update"){ $i = 0; $j = 1; foreach($_POST['stopname'] as $k=>$v){ if($_POST['stopid'][$k]){ $editids .= ",".$_POST['stopid'][$k]; }else{ $ids .= ",".$k; //$result_stops=$student->insert_route_stops($_POST,$_SESSION); } $i++; $j++; } $editids =ltrim($editids,','); $editids =rtrim($editids,','); $ids =ltrim($ids,','); $ids =rtrim($ids,','); $check_route_edit=$student->check_route_data_edit($_POST,$_SESSION); if(!$check_route_edit) { if($editids != ''){ $result_update=$student->update_routestop_data($_POST,$editids,$_SESSION); } if($ids != ''){ $result_insert=$student->insert_routestop_data($_POST,$ids,$_SESSION); } if($result_update!=ERR204 || $result_insert != ERR204) { echo "<script>location.replace('route_management.php?cresult=ERR203');</script>" ; } }else { echo "<script>alert('Route Number already exists');</script>" ; } } ?> <style> @media screen and (min-width: 1600px) { .media_1600 { margin-left: 149px!important; } .media { width:300px!important; } } </style> <body style="overflow-x: hidden;"> <div class="row" style="margin-top: 30px; margin-left:20px;margin-top:30px;margin-bottom:20px;"> <div class="col-md-9 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:1.4em; margin-left:20px;"> <i class=" glyphicon glyphicon-pencil" title ="Edit Route" style="font-size: 20px;"></i> Edit Route </div> </div> <form class="form-horizontal" method="post"> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size:13px;">Route Number</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-6"> <input type="text" class="form-control media" id="route_number" name="route_number" maxlength="15" value="<?php echo $route_details['route_number']?>" style="height:29px;font-size:13px; margin-left:-20px;width:252px;margin-bottom: 3%;" tabindex="1"> <!-- if there is an error--> <div class="col-md-12" id="err_route_number" style="color:#990000;font-size:12px;display:none;margin-left:-32px;margin-top:-7px;">Please Enter Route Number</div> <!--- end error--> </div> </div> <div class="col-md-6"> <div class="col-md-3"> </div> <div class="col-md-6"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size: 13px;">Vehical Type</b> </div> <div class="col-md-6"> <input type="text" class="form-control media" name="route_vehical_type" maxlength="50" id="route_vehical_type" style="height:29px;font-size:13px; margin-left:-20px;width:252px;margin-bottom: 3%;" tabindex="2" value="<?php echo $route_details['vehicle_type']?>" > <!-- if there is an error--> <div class="col-md-10" id="err_vehicletype" style="color:#990000;margin-left:-34px;font-size:12px;margin-top:-10px;display:none;"></div> <!--- end error--> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size: 13px;">Vehical No</b> </div> <div class="col-md-6"> <input type="text" name="route_vehical_no" id="route_vehical_no" maxlength="50" class="form-control media" style="height:29px;font-size:13px; margin-left:-20px;width:252px;margin-bottom: 3%;" tabindex="3" value="<?php echo $route_details['vehicle_number']?>" > <!-- if there is an error--> <div class="col-md-10" id="err_vehicalno" style="color:#990000;margin-left:-34px;font-size:12px;margin-top:-10px;display:none;"></div> <!--- end error--> </div> </div> </div> <div style="height:25px"></div> <div style="clear:both;"></div> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size: 13px;">Starting Point</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-5"> <input type="text" class="form-control" id="source_name" name="source_name" maxlength="50" style="height:29px;font-size:13px; margin-left:-20px;margin-bottom: 3%;" tabindex="4" value="<?php echo $route_details['source_name']?>"> </div> <!-- if there is an error--> <div class="col-md-12" id="err_sourcename" style="color:#990000;font-size:12px;display:none;margin-left: 261px;margin-top: -9px;">Please Enter correct value</div> <!--- end error--> </div> <div class="col-md-6"> <div class="col-md-3 text-right"> <b style="color:#666666;font-size: 13px;">Time</b> <span style="color:#FF0000;">*</span> </div> <div class="col-md-6"> <div id="datetimepicker1" class="input-append"> <input data-format="hh:mm:ss" name="source_time" id="source_time" type="text" style="height:29px;font-size:13px;margin-bottom: 3%;"tabindex="5" value="<?php echo $route_details['source_time']?>" ></input> <span class="add-on" style=" height:29px;"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> </span> </div> </div> <!-- if there is an error--> <div class="col-md-12 media_1600" id="err_sourcetime" style="color:#990000;font-size:12px;display:none;margin-left:14em;margin-top: -7px;">Please Enter correct value</div> <!--- end error--> </div> </div> <div style="clear:both;"></div> <?php //for($i=0; $i<$stop_details['count']; $i++){ $str = ""; $ids = ''; if($stop_details){ foreach($stop_details as $k=>$sval){ if($sval['route_stop_name'] == $route_details['source_name'] || $sval['route_stop_name'] == $route_details['destination_name'] ){ $sids .= ",".$sval['route_stop_id']; $sids =ltrim($sids,','); $sids =rtrim($sids,','); }else{ $stopids[] = $sval; } } } // $str = $str.",".$i; $i=0; $p=1; //echo "<pre>"; //print_r($stopids); if($stopids){ foreach($stopids as $k=>$val){ ?> <div id="Editdiv<?php echo $p?>"> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size: 13px;">Stop Name</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-5"> <input type="text" class="form-control" name="stopname[]" id="stopname<?php echo $i?>" maxlength="50" style="height:29px;font-size:13px; margin-left:-20px;margin-bottom: 3%;" tabindex="6" value="<?php echo $val['route_stop_name']?>"> <!-- if there is an error--> <div class="col-md-12" id="err_stopname" style="color:#990000;margin-left:-34px;font-size:12px;margin-top:-10px;display:none;"></div> <!--- end error--> </div> </div> <div class="col-md-6"> <div class="col-md-3 text-right"> <b style="color:#666666;font-size: 13px;">Stop Time</b> <span style="color:#FF0000;">*</span> </div> <div class="col-md-6"> <div id="soursedate<?php echo $i?>" class="input-append"> <input data-format="hh:mm:ss" type="text" id="soursedate<?php echo $i?>" name="soursedate[]" style="height:29px;font-size:13px;margin-bottom: 3%;"tabindex="7" value="<?php echo $val['route_stop_time']?>"></input> <span class="add-on" style=" height:29px;"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> </span> </div> </div> <?php if($p == 1){ ?> <div class="col-md-1"> <input type="hidden" value="<?php echo count($stopids)?>" id="theValue" /> <a href="javascript:;" onclick="addElement();"> <i class="glyphicon glyphicon-plus" title ="Add Route" style="font-size: 14px;margin-top:10px;margin-left:-4em;"></i> </a> </div> <?php }else { ?> <div class="col-md-1"> <input type="hidden" value="0" id="theValue" /> <a onclick="delete_route('<?php echo $val['route_stop_id']?>','<?php echo $p?>')" > <i class="glyphicon glyphicon-remove-circle" title ="Remove Route" style="font-size: 14px;margin-top:10px;margin-left:-4em;"></i> </a> </div> <?php } ?> <!-- if there is an error--> <div class="col-md-12 media_1600" id="err_stoptime" style="color:#990000;margin-left:14em;font-size:12px;margin-top:-7px;display:none;"></div> <!--- end error--> <input type="hidden" name="stopid[]" id="stopid<?php echo $i?>" value="<?php echo $val['route_stop_id']?>"> </div> </div> </div> <script> $(function() { $('#soursedate<?php echo $i?>').datetimepicker({ pickDate: false }); }); </script> <?php $i++; $p++; } } ?> </div> <div style="clear:both;"></div> <div class="col-md-12" > <div id="myDiv"> </div> </div> <div class="row"> <div class="col-md-6"> <div class="col-md-3 col-md-offset-2 text-right"> <b style="color:#666666;font-size: 13px;">Destination Name</b><span style="color:#FF0000; margin:2px;">*</span> </div> <div class="col-md-5"> <input type="text" class="form-control" id="destination_name" maxlength="50" name="destination_name" style="height:29px;font-size:13px; margin-left:-20px;margin-bottom: 3%;" tabindex="8" value="<?php echo $route_details['destination_name']?>"> <!-- if there is an error--> <div class="col-md-12" id="err_dest_name" style="color:#990000;margin-left:-32px; font-size:12px;display:none;margin-top:-9px;">Please Enter correct value</div> <!--- end error--> </div> </div> <div class="col-md-6"> <div class="col-md-3 text-right"> <b style="color:#666666;font-size: 13px;">Time</b> <span style="color:#FF0000;">*</span> </div> <div class="col-md-6"> <div id="datetimepicker2" class="input-append"> <input data-format="hh:mm:ss" name="destination_time" id="destination_time" maxlength="50" type="text" style="height:29px;font-size:13px;margin-bottom: 3%;"tabindex="9" value="<?php echo $route_details['destination_time']?>" ></input> <span class="add-on" style=" height:29px;"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i> </span> </div> </div> <!-- if there is an error--> <div class="col-md-12 media_1600" id="err_dest_time" style="color:#990000;margin-left:14em; font-size:12px;display:none;margin-top:-9px;">Please Enter correct value</div> <!--- end error--> </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" tabindex="10" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; " onclick="return inputvalidations()">Update</button> <button type="button" class="btn btn-default custom-button-width .navbar-right" tabindex="11" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px; " onclick="return clearall()" >Cancel</button> </div> </div> <input type="hidden" name="action" id="action" value="update"> <input type="hidden" name="stopids" id="stopids" value="<?php echo $sids?>"> <input type="text" name="stop_no" id="stop_no" value="<?php echo $str?>"> <input type="hidden" name="route_id" id="route_id" value="<?php echo $route_id?>"> <input type="hidden" name="acadamic_id" id="acadamic_id" value="<?php echo $acadamic_id?>"> <input type="hidden" name="school_id" id="school_id" value="<?php echo $school_id?>"> <input type="hidden" name="delete_route_ids" id="delete_route_ids" value=""> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"> </script> <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"> function delete_route_edit(val,me) { alert(me); var delete_route_ids = ''; delete_route_ids = document.getElementById('delete_route_ids').value; document.getElementById('delete_route_ids').value = delete_route_ids+","+val; $('#Editdiv'+me).remove(); } function delete_route(route_id,me){ alert(me); var result = confirm("Do you want to delete the Stop ?"); if(result == true){ var acadamic_id=$("#acadamic_id").val(); var school_id=$("#school_id").val(); $.ajax({ url: "ajaxcalls.php", type:"POST", data:"mode="+"delete_stop"+"&route_id="+route_id+"&acadamic_id="+acadamic_id+"&school_id="+school_id, success: function(result) { //alert(result); if(result == "exist"){ // alert('test123'); alert('You can not delete this stop as there is some data associated with it'); return false; }else{ var delete_route_ids = ''; var stop_ids_data = ''; delete_route_ids = document.getElementById('delete_route_ids').value; document.getElementById('delete_route_ids').value = delete_route_ids+","+route_id; var stop_data = document.getElementById('stop_no').value; var values = stop_data.split(','); for(var i = 0; i < values.length; i++) { if(values[i] != ''){ var correct = values[i]-1; stop_ids_data += ","+correct; } } stop_ids_data = stop_ids_data.replace(/^,/g, ''); stop_ids_data = stop_ids_data.replace(/,$/g, ''); document.getElementById('stop_no').value = stop_ids_data; document.getElementById('theValue').value = (document.getElementById('theValue').value -1); $('#Editdiv'+me).remove(); //window.location = 'route_management.php?cresult=success'; //location.reload(); } } }); } } function clearall() { window.location="route_management.php"; } function inputvalidations() { $('#err_route_number').hide(); $('#err_sourcename').hide(); $('#err_sourcetime').hide(); $('#err_dest_name').hide(); $('#err_stopname').hide(); $('#err_stoptime').hide(); $('#err_vehicalno').hide(); $('#err_vehicletype').hide(); $('#err_sourcetime').hide(); $('#err_dest_time').hide(); var route_number = document.getElementById('route_number').value; var source_name = document.getElementById('source_name').value; var sourcetime = document.getElementById('source_time').value; //var stop_name = document.getElementById('stop_name').value; //var stoptime = document.getElementById('stop_time').value; var destination_name = document.getElementById('destination_name').value; var destinationtime = document.getElementById('destination_time').value; var route_vehical_type = document.getElementById('route_vehical_type').value; var route_vehical_no = document.getElementById('route_vehical_no').value; var regex=/^[a-zA-Z0-9 ]+$/; var regex_vno=/^[a-zA-Z0-9\_ ]+$/; if(route_number == '') { $('#err_route_number').text('Please enter Route Number'); $('#err_route_number').show(); return false; } if(route_number.trim() =='') { $('#err_route_number').text('Please enter a valid Route Number'); $('#err_route_number').show(); return false; } if(isNaN(route_number)) { $('#err_route_number').text('Please enter a valid Route Number'); $('#err_route_number').show(); return false; } if(source_name == '' || source_name.trim() == '') { $('#err_sourcename').text('Please enter Starting Point'); $('#err_sourcename').show(); return false; } if(!regex.test(source_name)) { $('#err_sourcename').text('Please enter a valid Starting Point'); $('#err_sourcename').show(); return false; } if(source_name.length>50) { $('#err_sourcename').text('Please enter a valid Starting Point'); $('#err_sourcename').show(); return false; } if(sourcetime == '' || sourcetime.trim() == "") { $('#err_sourcetime').text('Please enter Starting Time'); $('#err_sourcetime').show(); return false; } // checking stopnames name is empty var stops=document.getElementsByName("stopname[]"); var soursedates=document.getElementsByName("soursedate[]"); var repeat=0; var vr1=0; var xstopnames=[]; var repeattime=0; var vrt1=0; var xstoptimes=[]; for(var l =0,p=0; l < soursedates.length; l++) { if(soursedates[l].value=='') vrt1=1; xstoptimes[p]=soursedates[l]; p++; } for(var l =0,p=0; l < stops.length; l++) { if(stops[l].value=='') vr1=1; xstopnames[p]=stops[l]; p++; } var j =1; for(var i = 0; i < stops.length; i++) { if(stops[i].value=='') // stop name validation { if(i==0) { $("#err_stopname").text('Please enter Stop Name'); $("#err_stopname").show(); return false; } else { $("#err_stopname").text('Please enter missing Stop Name'); $("#err_stopname").show(); return false; } }else if(stops[i].value.trim() =='') // stop name validation { if(i==0) { $("#err_stopname").text('Please enter a valid Stop Name'); $("#err_stopname").show(); return false; } else { $("#err_stopname").text('Please enter a valid Name for each Stop'); $("#err_stopname").show(); return false; } }else if(!regex.test(stops[i].value)){ if(i==0) { $("#err_stopname").text('Please enter a valid Stop Name'); $("#err_stopname").show(); return false; } else { $("#err_stopname").text('Please enter a valid Name for each Stop'); $("#err_stopname").show(); return false; } }else if(stops[i].value == source_name) // stop name validation { if(i==0) { $("#err_stopname").text('Starting Point and Stop name should not be same'); $("#err_stopname").show(); return false; } else { $("#err_stopname").text('Starting Point and Stop name should not be same'); $("#err_stopname").show(); return false; } }else if(stops[i].value == destination_name) // stop name validation { if(i==0) { $("#err_dest_name").text('Destination name and Stop name should not be same'); $("#err_dest_name").show(); return false; } else { $("#err_dest_name").text('Destination Name and Stop name should not be same'); $("#err_dest_name").show(); return false; } } if(soursedates[i].value=='') // stop name validation { if(i==0) { $("#err_stoptime").text('Please enter Stop Time'); $("#err_stoptime").show(); return false; } else { $("#err_stoptime").text('Please enter the missing Stop Time'); $("#err_stoptime").show(); return false; } } if(soursedates[i].value <= sourcetime) { $("#err_stoptime").text('Stop Time for any stop can not be lesser than any previous stop'); $("#err_stoptime").show(); //$("#err_sourcetime").text('Stop Time for any stop can not be lesser than any previous stop'); //$("#err_sourcetime").show(); return false; } if(stops.length == 1){ if(soursedates[i].value >= destinationtime && destinationtime != ''){ $("#err_dest_time").text('Destination time can not be lesser than any previous stop time'); $("#err_dest_time").show(); return false; } }else{ if(soursedates[stops.length-1].value >= destinationtime && destinationtime != '' ){ $("#err_dest_time").text('Destination time can not be lesser than any previous stop time'); $("#err_dest_time").show(); return false; } } } for(var i = 0; i < stops.length; i++) { for(var j=0;j< xstopnames.length; j++) { if(((xstopnames[j].value).trim()).toUpperCase()==((stops[i].value).trim()).toUpperCase()) { repeat++; if(repeat>1) { $("#err_stopname").show(); $('#err_stopname').text('Please enter unique name for each Stop Name'); return false; } } } repeat=0; } if(soursedates.length > 1){ for(var i = 0,n=1; i < soursedates.length; i++) { if( n < soursedates.length) { if((xstoptimes[i].value) >= (soursedates[n].value)) { $("#err_stoptime").show(); $('#err_stoptime').text('Stop Time for any stop can not be lesser than any previous stop'); return false; } } n++; } } if(route_vehical_type != ''){ if(!regex.test(route_vehical_type)) { $('#err_vehicletype').text('Please enter a valid Vehicle Type'); $('#err_vehicletype').show(); return false; }else if(route_vehical_type.length > 50){ $('#err_vehicletype').text('Please enter a valid Vehicle Type'); $('#err_vehicletype').show(); } } if(route_vehical_no != ''){ if(!regex_vno.test(route_vehical_no)) { $('#err_vehicalno').text('Please enter a valid Vehicle No'); $('#err_vehicalno').show(); return false; }else if(route_vehical_no.length > 50){ $('#err_vehicalno').text('Please enter a valid Vehicle No'); $('#err_vehicalno').show(); } } if(destination_name == '' || destination_name.trim() == '') { $('#err_dest_name').text('Please enter Destination Name'); $('#err_dest_name').show(); return false; } if(!regex.test(destination_name)) { $('#err_dest_name').text('Please enter a valid Destination Name'); $('#err_dest_name').show(); return false; } if(destination_name.length>50) { $('#err_dest_name').text('Please enter a valid Destination Name'); $('#err_dest_name').show(); return false; } /*if(destination_name == source_name){ $("#err_dest_name").text('Starting Point and Destination Name should not be same'); $("#err_dest_name").show(); return false; }*/ if(destinationtime == '' || destinationtime.trim() == '') { $('#err_dest_time').text('Please enter Destination Time'); $('#err_dest_time').show(); return false; } } $(function() { $('#datetimepicker1').datetimepicker({ pickDate: false }); }); </script> <script type="text/javascript"> $(function() { $('#datetimepicker2').datetimepicker({ pickDate: false }); }); </script> <script type="text/javascript"> $(function() { $('#datetimepicker3').datetimepicker({ pickDate: false }); }); </script> <script type="text/javascript"> $(function() { $('#datetimepicker4').datetimepicker({ pickDate: false }); }); </script> <script> function addElement() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1)+ 2; numi.value = num; var newdiv = document.createElement('div'); var divIdName = 'my'+num+'Div'; var num_sd = num -1 ; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = '<div class="row"><div class="col-md-6"><div class="col-md-3 col-md-offset-2"><b style="color:#666666;font-size: 13px;margin-left: 47px;">Stop Name </b><span style="color:#FF0000;">*</span></div><div class="col-md-6"><input type="text" name="stopname[]" id="stopname'+num+'" maxlength="50" class="form-control" style="height:29px;font-size:13px;margin-left:-30px;width:252px ;margin-bottom: 3%;" tabindex="1" ><div class="col-md-7" style="color:#990000; display:none;">Please Enter correct value</div></div></div><div class="col-md-6"><div class="col-md-3" style="width:200px;"><b style="color:#666666;font-size: 13px;margin-left: 67px;">Stop Time</b><span style="color:#FF0000; margin:2px;">*</span></div><div class="col-md-6"><div id="soursedate_date'+num+'" class="input-append"><input data-format="hh:mm:ss" type="text" name="soursedate[]" id="soursedate'+num+'" style="height:29px;font-size:13px;margin-bottom: 3%;margin-left: -33px;" tabindex="7" ></input><span class="add-on" style=" height:29px;"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span></div></div><div class="col-md-1"><a onclick="removeElement(\''+divIdName+'\','+num+');"><i class="glyphicon glyphicon-remove-circle" title ="Remove Route" style="font-size: 14px;margin-left:-81px;margin-top: 7px;"></i></a></div></div><input type="hidden" name="stopid'+num+'" id="stopid'+num+'" value=""><div class="col-md-7" id="err_dynamic'+num+'" style="color:#990000;margin-left:-15p; display:none;"></div></div>'; ni.appendChild(newdiv); var totalids = document.getElementById('stop_no').value; document.getElementById('stop_no').value = totalids+','+num_sd; $(function() { $('#soursedate_date'+num).datetimepicker({ pickDate: false }); }); } function removeElement(divNum,num) { var d = document.getElementById('myDiv'); var olddiv = document.getElementById(divNum); d.removeChild(olddiv); var totalids = document.getElementById('stop_no').value; stop_no = totalids.replace(num,''); document.getElementById('theValue').value = (document.getElementById('theValue').value -1); stop_no = stop_no.replace(/^,/g, ''); stop_no = stop_no.replace(/,$/g, ''); // stop_no = stop_no .replace(",,",","); document.getElementById('stop_no').value = stop_no; } </script> </body> </html>