<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<script src="restriction/vehicle_restriction.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;

        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:10px;
        padding-right:10px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
.col-sm-3
{
  display:flex;
  }
#menu1 input[type="text"]
{
    height:30px;
    min-width:40%;
    margin-left:3px;
}
#menu1 select
{
    height:35px;
    /* padding-bottom:8px; */
}
.cftTable
{
  width:100%;
  line-height:40px;
  margin-bottom:10px;
  text-align:center;
  border:1px solid lightgrey;
}
.cftTable td,th
{
  text-align:center;
  border:1px solid lightgrey;
}

    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    <div ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>CFT Calculation</h3>
<br>

<!-- table -->
<div>
  <!-- tab for rate -->
  <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='cftdetails'");
while($per=mysqli_fetch_array($usper))
{
          ?>
  <ul class="nav nav-pills" role="tablist">
     <li class="nav-item">
      <a class="nav-link active" data-toggle="pill" href="#home"><span style="color:#000000;">List</span></a>
    </li>
    <li class="nav-item">
    <?php if($per['dataadd'] =='1'){ ?>  <a class="nav-link" data-toggle="pill" href="#menu1"><span style="color:#000000;">Entry</span></a><?php } ?>
    </li>
    
  </ul>

  <!-- Tab panes -->
  <div class="tab-content" style="border:1px solid lightgrey">
    <!--  -->
    <div id="home" class="container tab-pane active"><br>
    <!-- entry list div -->
    <table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protable">
    <thead >
<tr>
    <th>Date</th>
    <th>Vehicle No</th>
    <?php if($per['dataedit'] =='1'){ ?><th>Edit</th><?php } ?>
</tr>

    </thead>
    <tbody>
      <?php 
      $fetch_cft = mysqli_query($connect,"select  distinct vehicleno,date from cftdetails where status!='deleted' order by date desc");
     while($cft_dis=mysqli_fetch_array($fetch_cft))
     {
       $date = $cft_dis['date'];
       $date_format = date_create($date);
       $date_change = date_format($date_format,"d-m-Y");
      ?>
        <tr>
        <td><?php echo $date_change  ?></td>
    <td><?php echo $cft_dis['vehicleno']  ?></td>
    <?php if($per['dataedit'] =='1'){ ?>   <td><a href="edit_cft.php?vehicle=<?php echo $cft_dis['vehicleno'] ?>"><i class="fas fa-edit edit"></i></a></td><?php } ?>
           
        </tr>
        <?php } }?>
    </tbody>



</table>
    <!-- entry div table -->
    </div>
    <!-- entrydiv -->
    <div id="menu1" class="container tab-pane fade"><br>
    <!-- enter the entry list -->
    <form action="insert_cft.php" method="post">
    <!-- enter the entry list -->
    <div class="row">
      <div class="col-sm-1"></div>
      <div class="col-sm-2"><label>Vehicle No:</label></div>
      <div class="col-sm-3"><input type="text"class="vehiclenochk required" placeholder="Vehicle No" id="vehicleNo" autocomplete="off"></input></div>
      <?php 
$proname_val=mysqli_query($connect,"select distinct vehicleno from cftdetails where status!='deleted'");
while($proname_val_show = mysqli_fetch_array($proname_val))
{
?>
<input type="hidden" class="vehicleNoValue" value="<?php echo $proname_val_show['vehicleno'] ?>">
<?php
}
?>
<script>
  var vehNo = document.querySelectorAll(".vehicleNoValue");
  var vehAdd = document.getElementById("vehicleNo");
  vehAdd.addEventListener("keyup",function(e){
    //console.log("a");
   var vehicle = e.target.value.toLowerCase();
   vehNo.forEach((list)=>{
    if(vehicle.replace(/ /g,"") == list.value.toLowerCase().replace(/ /g,"")){
      document.getElementById("alertUser").click();
      vehAdd.value="";
   }
   });
     
  });
  //console.log(userName);
  </script>
      <div class="col-sm-2"><label>Chakka Type:</label></div>
      <div class="col-sm-3"><input type="text" class="required" placeholder="Chakka Type" id="chakka" autocomplete="off"></input></div>
    </div>
    <br>
    <div class="row">
      <div class="col-sm-1"></div>
      <div class="col-sm-2"><label>Length:</label></div>
      <div class="col-sm-3"><input type="text" class="required" placeholder="Length" id="length" autocomplete="off"></input> <input type="text" class="required" placeholder="Length" id="lengthTwo" autocomplete="off"></input></div>
      <div class="col-sm-2"><label>Width:</label></div>
      <div class="col-sm-3"><input type="text" class="required" placeholder="Width" id="width" autocomplete="off"></input><input type="text" class="required" placeholder="Width" id="widthTwo" autocomplete="off"></input></div>
    </div>
    <br>
    <div class="row">
      <div class="col-sm-1"></div>
      <div class="col-sm-2"><label>Height:</label></div>
      <div class="col-sm-3"><input type="text" class="required" placeholder="Height" id="height" autocomplete="off"></input><input type="text"class="required" placeholder="Height" id="heightTwo" autocomplete="off"></input></div>
      <div class="col-sm-2"><label>CFT:</label></div>
      <div class="col-sm-3"><input type="text" class="required" placeholder="CFT" id="cft" readonly autocomplete="off"></input></div>
      <div class="col-sm-1"><label>In FT<sup>3</sup></label></div>
    </div>
        <br>
    <div class="row">
      <div class="col-sm-1"></div>
      <div class="col-sm-2"><label>In Unit:</label></div>
      <div class="col-sm-3" autocomplete="off"><input type="text" class="required" placeholder="unit" id="unit" ></input></div>
      <div class="col-sm-2"><input  type="button" class="btn btn-primary"  style="float:left;margin-left:10px;height:40px;" id="addCft" value="Add"></div>
     
    </div>
    <br>
    <table class="cftTable">
      <thead>
        <tr>
          <th>Vehicle</th>
          <th>Chakka</th>
          <th>Lgt</th>
          <th>wdt</th>
          <th>hgt</th>
          <th>CFT</th>
          <th>Unit</th>
          <th>Delete</th>
        </tr>
      </thead>
      <tbody id="cftTbody">
        
      </tbody>
    </table>
    <input type="button" class="btn btn-success" data-toggle="modal" data-target="#addpro" style="float:left;margin-left:10px;height:40px;" value="Submit">
<br><br>
            <!-- entry div over  -->
        </div>
                <!-- modal for add confirm -->
<div class="modal fade" id="addpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> CFT Have Been Generated Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning" >Ok</button>
        </div>

      </div>
    </div>
  </div>
</form>
<!-- modal for add confirm -->
        <!--overall entry div over  -->
        
        
    </div>
   <!--  -->
  </div>
</div>

  <!-- tab for rate -->
</div>
<!-- tab for entry area-->
<!-- modal for edit -->
<div class="modal fade" id="edittkt">
    <div class="modal-dialog modal-dialog-centered modal-lg">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Edit Ticket</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <!-- entry for edit  -->
            
    <!-- entry for edit  -->           

        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button  class="btn btn-success"data-toggle="modal" data-target="#editpro" >Update</button>
        </div>
        <!-- modal for add -->
<div class="modal fade" id="editpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> Ticket Have Been Updated Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning" >Ok</button>
        </div>
        
      </div>
    </div>
  </div>
  
<!-- modal for add -->
      </div>
    </div>
  </div>
<!-- modal for edit -->
      
<!-- modal for delete -->
<!-- The Modal -->
<div class="modal fade" id="prd-1">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(247, 2, 80,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body" >
         Are You Sure Want To Delete !.
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
        <a href="#?dele=1"><button type="button" class="btn btn-success" data-dismiss="modal">Yes</button></a>
          <button type="button" class="btn btn-warning" data-dismiss="modal">No</button>
        </div>
        
      </div>
    </div>
  </div>
<!-- ,odal for delete -->
<!-- table -->


<!-- main-content-div -->
</div>
<!-- main-content-div -->
</div>
<!-- modal to blockdate -->
<button type="button" class="btn btn-primary" id="alertUser" data-toggle="modal" data-target="#advanceLimit" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="advanceLimit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close"  data-dismiss="alert">&times;</button>
    <strong>Vehicle No Already Exist</strong>
  </div>
  </div>
  </div>
        
<!-- alert -->
<!-- alert5 -->
<button type="button" class="btn btn-primary alertalpha" id="blockButton" data-toggle="modal" data-target="#textmodal" style="display:none">
      </button> 

  <!-- The Modal -->
  <div class="modal fade" id="textmodal">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Special Characters Are Not Allowed</strong>
  </div>
  </div>
        </div>
    

 <!--  alert -->
 <!-- modal to blockdate -->
<button type="button" class="btn btn-primary" id="alertUser" data-toggle="modal" data-target="#advanceLimit" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="advanceLimit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close"  data-dismiss="alert">&times;</button>
    <strong>Vehicle No Already Exist</strong>
  </div>
  </div>
  </div>
        
<!-- alert -->
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="restriction/cft.js"></script>
</body>