<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php");

$pageName = basename($_SERVER['PHP_SELF']);

 $m->where("page_name", $pageName);
 $pageNameAccess=$m->get("eduportal_modules_pages_detail");


$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $pageNameAccess[0]['page_id']);
$access = $m->get("users_privilege_detail");


 ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Add/View vehicle route | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
  

  </head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

 
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">

             <a href="dashboard.php">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
                Manage Vehicle Route
          <br><br>

          <div class="row" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
   
      

                                    <!-- page content -->
        
  <div class="">
    
      <h3 style="margin-left: 15px;">Add New vehicle Route</h3>
            <div class="row">
          
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
            
                  <div class="x_content">
          
     
                    <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data" class="form-horizontal form-label-left" >
  <?php
  
  $month;
   if(!isset($_GET['vehrouteup'])){?>
        <input type="hidden" name="action" value="assign_vehicle_route" />

  <?php } else {

          $query="select * from eduportal_assign_vehicle_route where vehrote_id =".$_GET['vehrouteup'];
          $vehroutedata = $m->query($query);

         
?>
              <input type="hidden" name="action" value="update_vehicle_route" />
              <input type="hidden" name="vehrote_id"  value="<?php echo $_GET['vehrouteup'];?>">

  <?php } ?>        
          
        <div class="item form-group">
                        
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                         Route Title <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">
                           <select name="route_id" class="form-control" >
                     <option value="">Select Route</option> 
                    <?php
                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("eduportal_route_details");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($vehroutedata[0]['route_id']==$WorkAssignListVal['route_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['route_id']; ?>"><?php echo $WorkAssignListVal['route_title']; ?></option>


                            <?php
                    } ?>

                    </select>
                        </div>

<br><br>
                          
                         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="email">

                          Vehicle <span class="required">*</span>
                        </label>
                        
                        <div class="col-md-6 col-sm-6 col-xs-12">

                          <select name="vehicle_id" class="form-control" >
                     <option value="">Select Vehicle</option> 
                    <?php
                    $m->where("branch_id", $_SESSION['branch']);
                    $WorkAssignList = $m->get("eduportal_vehicles_detail");
                    foreach($WorkAssignList as $WorkAssignListVal)
                    { ?>

                       <option <?php if($vehroutedata[0]['vehicle_id']==$WorkAssignListVal['vehicle_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['vehicle_id']; ?>"><?php echo $WorkAssignListVal['vehicle_model']; ?></option>


                            <?php
                    } ?>

                    </select>
                        </div>

                      </div>              
                   
                     

                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-7">
                          
                          <button id="send" type="submit" class="btn btn-primary" >Save Record</button>
                         
                        </div>
                      </div>

                    </form>
              
          </div>
                </div>
              </div>
            </div>
          </div>
       
        

        <!-- /page content -->



  </div>
  <div class="clearfix"></div>
</section>           

<?php
$branch=$_SESSION['branch'];

$sql = "SELECT * FROM eduportal_assign_vehicle_route where branch_id='$branch' ";


$vehiclesRoutes = $m->query($sql);
 //print_r($categories);
 
     ?>




     <div class="t col-md-12 col-sm-12 col-xs-12">
                <h3>Vehicle Route List<small> (<?php echo count($vehiclesRoutes);?> records)</small></h3>
              </div>

            
          
          
    

<?php  if(isset($_SESSION['addsuccessexp'])){?>

<div id="snackbar"><script> toastFunction();</script> Your Recored is Sucessfully Added</div>

<?php  unset($_SESSION['addsuccessexp']); }?>


          
          <?php  if(isset($_SESSION['upsuccessexp'])){?>


            <div class="alert alert-success" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Record is updated successfully...
            </div>


          <?php  unset($_SESSION['upsuccessexp']); }?>
          

          <?php  if(isset($_SESSION['deleteexp'])){?>


            <div class="alert alert-danger" id="msg">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Danger!</strong> Record is deleted successfully...
            </div>


          <?php  unset($_SESSION['deleteexp']); }
          ?>

<table id="datatable" class="table table-striped table-bordered"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                           <th width="10%">Route Title</th>
                          <th width="10%">Assign Vehicle</th>                          
                          <th width="8%">Action</th>
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  $count=1;
$date= date("Y-m-d");

foreach($vehiclesRoutes as $vehiclesRoute){

        $m->where("route_id", $vehiclesRoute['route_id']);
        $route=$m->get("eduportal_route_details");

         $m->where("vehicle_id", $vehiclesRoute['vehicle_id']);
        $vehicle=$m->get("eduportal_vehicles_detail");

 
?>
                        <tr>
                          <td style="text-align:center;"><?php echo $count; $count++;?></td>                        

                          <td><?php echo $route[0]['route_title'];?></td>
                          <td><?php echo $vehicle[0]['vehicle_model'];?></td>

                          <td>        
            

              <a style="padding: 0px 5px; font-size:14px;"  href="vehicle_route.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&vehrouteup=<?php echo $vehiclesRoute['vehrote_id'];?>" style="cursor:pointer;"  class="btn btn-success"> <i class="fa fa-pencil" aria-hidden="true"></i></a>

              

        <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?vehicle_routeID=<?php echo $vehiclesRoute['vehrote_id'];?>&action=DeleteVehicleRoute" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

 
        
                          </td>

                        </tr>
<?php } ?>
                      

                      </tbody>
                    </table>
           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
<script>
function toastFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>