<?php
     session_start();

     require('connect.php');
     require('functions.php');
     //echo '<script> alert("DRIVER ID IS "+ $driverID); </script>';
     $log=loggedin();

     if($log!==true)
     {
          header('Refresh:0 url=index.php');
     }
     else if($_SESSION['type']==="1")
     {
          header('Refresh:0 url=main.php');
     }
     else if($_SESSION['type']==="3")
     {
          header('Refresh:0 url=admin.php');
     }
?>

<?php
     require('connect.php');

     if(isset($_POST['create_btn']))
     {
           
          $from=$_POST['from'];
          $from=test_input($from);
          $to=$_POST['to'];
          $to=test_input($to);
          $pnumber=$_POST['pnumber'];
          $pnumber=test_input($pnumber);
          $bnumber=$_POST['bnumber'];
          $bnumber=test_input($bnumber);
          $date=$_POST['ldate'];
          $date=test_input($date);
          $time=$_POST['ltime'];
          $time=test_input($time);
          $rate=$_POST['rate'];
          $rate=test_input($rate);
          $did = $_SESSION["DID"];

          $query="INSERT INTO logs (lfrom, lto, passenger, bags, ldate, rate, LID, DID ) VALUES ('$from', '$to', '$pnumber', '$bnumber', '$date', '$rate',NULL, '$did')";
          $query=mysqli_query($con,$query);
          if($query)
          {
               echo '<script> alert("log added");</script>';
          }
          else{
               echo '<script> alert("log not added" + $to);</script>';
          }
          
     }
?>
<!DOCKTYPE html>
<html>
<head>
     <title>Driver</title>
     <meta charset="utf-8" />
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

     <style>
          @import "http://fonts.googleapis.com/css?family=Raleway";
          #driver {
               width:100%;
               height:100%;
               opacity:.95;
               top:70;
               left:0;
               display:none;
               position:fixed;
               background-color:#313131;
          }
          #htable{
               display:none;
          }
          #ftable{
               display:none;
          }
          #display{
               display:block;
               background-color:blue;
          }
          #fdisplay{
               display:block;
               background-color:blue;
          }

          img#close {
               position:absolute;
               left: 100%;
               top: -5%;
               cursor:pointer
          }
          div#popupContact {
               position:absolute;
               margin-top:20%;


               
               font-family:'Raleway',sans-serif;
          }
          form 
          {
               max-width:100%;
               min-width:70%;
               padding:1% 5%;
               border:2px solid gray;
               border-radius:10px;
               font-family:raleway;
               background-color:#fff;
          }

          .footer 
          {
               color: white;
               background-color: black;
               margin-left: 0px;
               text-align: center;
               position:fixed;
               bottom: 0;
               height: 50px;
               width: 100%;
          }
          .container 
          {
               width:100%;
               padding: 16px;
               margin-top:30px;
               margin-bottom:60px;
               opacity:0.5;
               background-color:#ffffff;
          }
          .container1 
          {
               width:100%;
               padding: 16px;
               margin-top:50px;
               margin-bottom:60px;
               opacity:0.5;
               background-color:#ffffff;
          }
          button 
          {
               background-color: #4CAF50;
               color: white;
               padding: 14px 20px;
               margin: 8px 0;
               border: none;
               cursor: pointer;
               width: 100%;
          }
          #hide
          {
               background-color:blue;
               display:none;
          }
          #fhide
          {
               background-color:blue;
               display:none;
          }
          #Password 
          {
               background-repeat:no-repeat;
               background-position:5px 7px
               margin-bottom:30px
          }


     </style>
     <script>
          //Function To Display Popup
          function div_show_form() {
               document.getElementById('driver').style.display = "block";
          }
          //Function to Hide Popup
          function div_hide() {
               document.getElementById('driver').style.display = "none";
          }
          function div_show_history() {
               document.getElementById('htable').style.display = "block";
               document.getElementById('display').style.display = "none";
               document.getElementById('Hide').style.display = "block";
          }
          //Function to Hide Popup
          function div_hide_display_his() {
               document.getElementById('htable').style.display = "none";
               document.getElementById('Hide').style.display = "none";
               document.getElementById('display').style.display = "block";
          }
          function div_show_future() {
               document.getElementById('ftable').style.display = "block";
               document.getElementById('fdisplay').style.display = "none";
               document.getElementById('fHide').style.display = "block";
          }
          //Function to Hide Popup
          function div_hide_display_fut() {
               document.getElementById('ftable').style.display = "none";
               document.getElementById('fHide').style.display = "none";
               document.getElementById('fdisplay').style.display = "block";
          }
          function TDate() 
          {
               var UserDate = document.getElementById("date").value;
               var ToDate = new Date();

               if (new Date(UserDate).getTime() <= ToDate.getTime()) 
               {
                    alert("The Date must be Bigger or Equal to today date");
                    return false;
               }
               return true;
          }
     </script>
</head>
<body style="overflow-x:hidden;background-size:100% 100%;background-repeat: no-repeat;bottom: 0;background-attachment: fixed;" background="images/driver.png">

     <div>
          <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="padding: 0px margin:0px">
               <div class="main" >
                    <div class="col-sm-6" >
                         <h1 align="left" style="margin-left:10px;" ><font color="white" size="15">   ABHI CAB</font>
                              <img src="images/logo.png" alt="google.com" width="100" height="50" align="left" style="margin-left:10px;">
                         </h1>
                    </div>
                    <div class="col-sm-6" style="margin-top:40px;">
                         <ul class="nav navbar-nav navbar-right" style="margin-right:10px;">

                              <li >
                                   <a href="index.php"> Home   <span class="glyphicon glyphicon-home"></span></a>
                              </li>

                              <!--<li class="dropdown" ><a class="dropdown-toggle" data-toggle="dropdown" href="#">Login <span class="caret"></span></a>
                                   <ul class="dropdown-menu" >
                                        <li align="right"><a href="index.php">Customer  <span class="glyphicon glyphicon-user"></span></a></li>
                                        <li align="right"><a href="index.php">Admin  <span class="glyphicon glyphicon-user"></span></a></li>
                                        <li align="right"><a href="index.php">Driver  <span class="glyphicon glyphicon-user"></span></a></li>
                                   </ul>
                              </li>

                              <li><a href="main.php">Book Now  <span class="glyphicon glyphicon-shopping-cart"></span></a></li>-->
                              <li ><a href="about_us.html">About Us</a></li>
                              <li><a href="contact.html">Contact Us <span class="glyphicon glyphicon-earphone"></span></a></li>
                              <li><a href="logout.php">Log Out <span class="glyphicon glyphicon-log-out"></span></a></li>

                         </ul>
                    </div>
               </div>
          </nav>
     </div>

     <?php echo '<h2 style="margin-top:150px" align="center"><font size="8" color="red" ><b>DRIVER ('.$_SESSION['DID'].')</b></font></h2>';?>


     
     <!--<div class="col-sm-1"></div>
                         <div class="col-sm-4">
                              <div class="container">
                                   <h3 align="center"><b>HISTORY OF RIDES</b></h3>
                                   <button id="display" onclick="div_show_history()">Display</button>-->

                                   <!--HIDDEN TABLE -->
                                   <!--<div id="htable">
                                        <table style="width:100%; "><font text-color="white">
                                             <thead>
                                                  <tr>
                                                       <th>FROM</th>
                                                       <th>TO</th>
                                                       <th>DATE</th>
                                                       <th>BOOKED BY</th>
                                                       <th>RATE</th>
                                                  </tr>

                                                  <?php
                                                       //execute the SQL query and return records   SSELECT * FROM transaction as t INNER JOIN logs as l ON t.LID = l.LID INNER JOIN customer as c ON t.CID = c.CID WHERE l.DID = '5' and l.ldate > (SELECT CURDATE()) SELECT  lfrom,lto,rate,LID,DID,CID FROM transaction, logs (SELECT LID FROM logs WHERE DID = '".$_SESSION["DID"]."' and ldate < (SELECT CURDATE()))
                                                       $result = "SELECT * FROM transaction as t INNER JOIN logs as l ON t.LID = l.LID INNER JOIN customer as c ON t.CID = c.CID WHERE l.DID = ".$_SESSION["DID"]." and l.ldate > (SELECT CURDATE())";
                                                       $result = mysqli_query($con,$result);
                                                       /*$row = mysqli_fetch_assoc( $result );
                                                       if($row)
                                                       {
                                                       echo $row["rate"];
                                                       }*/

                                                  ?>
                                             </thead>
                                             <tbody>-->
                                                  <!--Use a while loop to make a table row for every DB row

                                                  <?php while( $row = mysqli_fetch_assoc( $result )) :?>

                                                  <tr>
                                                       Each table column is echoed in to a td cell
                                                       <td><?php echo $row["lfrom"]; ?></td>
                                                       <td><?php echo $row["lto"]; ?></td>
                                                       <td><?php echo $row["TDATE"]; ?></td>
                                                       <td><?php echo $row["CNAME"]; ?></td>
                                                       <td><?php echo $row["rate"]; ?></td>
                                                       <?php 
                                                       //$driverID = $_SESSION["DID"];
                                                       //echo '<script> alert("DRIVER ID IS " + $driverID); </script>';?>
                                                  </tr>
                                                  <?php endwhile?>
                                             </tbody>
                                             </font>
                                        </table>


                                   </div>
                              </div>
                         </div>
                         <div class="col-sm-2"></div>
                         <div class="col-sm-4">
                              <div class="container">
                                   <h3 align="center"><b>FUTURE RIDES</b></h3>
                                   <button id="display">Display</button>
                              </div>
                         </div>-->
                         
     <?php
          $logs_driver = "SELECT * FROM logs WHERE DID = '".$_SESSION["DID"]."'";
          $outpput = mysqli_query($con,$logs_driver);
          if(mysqli_num_rows($outpput) > 0)
          {
               echo '   
                         <div class="col-sm-1"></div>
                         <div class="col-sm-4">
                              <div class="container">
                                   <h3 align="center"><b>HISTORY OF RIDES</b></h3>
                                   <button id="display" onclick="div_show_history()" ><font size="3"><b>Display</button>
                                   <button id="Hide" onclick="div_hide_display_his()">Hide</button></font></b>

                                   <!--HIDDEN TABLE -->';
                                   
                                   echo '
                                   <div id="htable">';
                                        $result = "SELECT * FROM transaction as t INNER JOIN logs as l ON t.LID = l.LID INNER JOIN customer as c ON t.CID = c.CID WHERE l.DID = ".$_SESSION["DID"]." and l.ldate < (SELECT CURDATE())";
                                        $result = mysqli_query($con,$result);
                                        if(mysqli_num_rows($result) > 0)
                                        {
                                             echo '
                                        <table style="width:100%; "><font text-color="white">
                                             <thead>
                                                  <tr>
                                                       <th>FROM</th>
                                                       <th>TO</th>
                                                       <th>DATE</th>
                                                       <th>BOOKED BY</th>
                                                       <th>RATE</th>
                                                  </tr>';

                                                  
                                                       
                                                       /*$row = mysqli_fetch_assoc( $result );
                                                       if($row)
                                                       {
                                                       echo $row["rate"];
                                                       }*/

                                             echo '
                                             </thead>
                                             <tbody>
                                                  <!--Use a while loop to make a table row for every DB row-->';
                                                  
                                                  while( $row = mysqli_fetch_assoc( $result ) ) :
                                                  echo '
                                                  <tr>
                                                       <!--Each table column is echoed in to a td cell-->
                                                       <td>';echo $row["lfrom"]; echo '</td>
                                                       <td>';echo $row["lto"]; echo '</td>
                                                       <td>';echo $row["TDATE"]; echo '</td>
                                                       <td>';echo $row["CNAME"]; echo '</td>
                                                      <td>';echo $row["rate"]; echo '</td>
                                                       
                                                  </tr>';
                                                  endwhile;
                                                  echo '
                                             </tbody>
                                             </font>
                                        </table>';
                                        ;}
                                   else{
                                        echo '<h2 align = "center"> no history </h2>';
                                   }echo '


                                   </div>
                                   ';
                                   echo '
                              </div>
                         </div>
                         <div class="col-sm-2"></div>
                         <div class="col-sm-4">
                              <div class="container">
                                   <h3 align="center"><b>FUTURE RIDES</b></h3>
                                   <button id="fdisplay" onclick="div_show_future()"> <font size="3"><b>Display</button>
                                   <button id="fHide" onclick="div_hide_display_fut()">Hide</button></font></b>


                                   <!--HIDDEN TABLE -->';
                                   
                                   echo '
                                   <div id="ftable">';
                                        $result = "SELECT * FROM transaction as t INNER JOIN logs as l ON t.LID = l.LID INNER JOIN customer as c ON t.CID = c.CID WHERE l.DID = ".$_SESSION["DID"]." and l.ldate > (SELECT CURDATE())";
                                        $result = mysqli_query($con,$result);
                                        $extra = "SELECT * FROM logs as l WHERE l.DID = ".$_SESSION["DID"]." and l.ldate > (SELECT CURDATE())";
                                        $extra = mysqli_query($con,$extra);
                                        if(mysqli_num_rows($result) > 0 || mysqli_num_rows($extra) > 0)
                                        {
                                             echo '
                                        <table style="width:100%; "><font text-color="white">
                                             <thead>
                                                  <tr>
                                                       <th>FROM</th>
                                                       <th>TO</th>
                                                       <th>DATE</th>
                                                       <th>BOOKED BY</th>
                                                       <th>RATE</th>
                                                  </tr>';

                                                  
                                                       
                                                       /*$row = mysqli_fetch_assoc( $result );
                                                       if($row)
                                                       {
                                                       echo $row["rate"];
                                                       }*/

                                             echo '
                                             </thead>
                                             <tbody>
                                                  <!--Use a while loop to make a table row for every DB row-->';
                                                  
                                                  while( $row = mysqli_fetch_assoc( $result ) ) :
                                                  echo '
                                                  <tr>
                                                       <!--Each table column is echoed in to a td cell-->
                                                       <td>';echo $row["lfrom"]; echo '</td>
                                                       <td>';echo $row["lto"]; echo '</td>
                                                       <td>';echo $row["TDATE"]; echo '</td>
                                                       <td>';echo $row["CNAME"]; echo '</td>
                                                       <td>';echo $row["rate"]; echo '</td>
                                                       
                                                  </tr>';
                                                  endwhile;
                                                  if(mysqli_num_rows($extra) > 0)
                                                  {
                                                       // echo "<script> alert('hiiiii mad') </script>";
                                                       while( $row1 = mysqli_fetch_assoc( $extra ) ) :
                                                            if(mysqli_num_rows($result) > 0)
                                                            {
                                                                 while( $row = mysqli_fetch_assoc( $result ) ) :
                                                                 if($row1['LID']!= $row['LID'])
                                                                 {
                                                                      echo '
                                                                      <tr>
                                                                           <!--Each table column is echoed in to a td cell-->
                                                                           <td>';echo $row1["lfrom"]; echo '</td>
                                                                           <td>';echo $row1["lto"]; echo '</td>
                                                                           <td>';echo $row1["ldate"]; echo '</td>
                                                                           <td>';echo $row1["CNAME"]; echo '</td>
                                                                           <td>';echo $row1["rate"]; echo '</td>
                                                                           
                                                                      </tr>';
                                                                 }
                                                            endwhile;
                                                            }
                                                            else{
                                                            echo '
                                                            <tr>
                                                                 <!--Each table column is echoed in to a td cell-->
                                                                 <td>';echo $row1["lfrom"]; echo '</td>
                                                                 <td>';echo $row1["lto"]; echo '</td>
                                                                 <td>';echo $row1["ldate"]; echo '</td>
                                                                 <td>';echo $row1["CNAME"]; echo '</td>
                                                                 <td>';echo $row1["rate"]; echo '</td>
                                                                 
                                                            </tr>';
                                                            }
                                                       endwhile;
                                                  }
                                                  echo '
                                             </tbody>
                                             </font>
                                        </table>';
                                        ;}
                                   else{
                                        echo '<h2 align = "center"> no history </h2>';
                                   }echo '


                                   </div>
                                   ';
                                   echo '
                              </div>
                         </div>
                         <div class="col-sm-1">.</div>
                              ';
          }
          else
          {
               // echo '<script> alert("it has no  log");</script>';
               echo '
               <div class="container">
                    <h3 align ="center">Welcome to the site for the 1st time.
                    Click Create Ride to Create a Ride.</h3>
               </div>';
          }
     ?>
<br></br>
<div class="col-sm-12">
     <div class="col-sm-5"></div>
     <div class="col-sm-2">
          <button onclick="div_show_form()" ><font size="5"><b>Create Ride</b></font></button>
     </div>
     <div class="col-sm-5"></div>
</div>    


     <!-- Footer -->
     <footer class="footer">
          <h5>Copyright &copy; 2019 AbhiCab.com</h5>
     </footer>


     
     

     <!-- hiddwn pop ups -->
     <div id="driver" >
          <!-- Popup Div Starts Here -->
          <div class="col-sm-4"></div>
          <dir class="col-sm-4">
               <div id="popupContact" >

                    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  id="form" method="post" name="form">
                         <img id="close" src="images/3.png" onclick ="div_hide()">
                         <h2>Create Ride</h2>
                         <hr>
                         <div class="col-sm-6">
                              <lable><b>From</b></lable>
                              <input style="width:100%;" type="text" placeholder="Starting Point" name="from" required>
                         </div>
                         <div class="col-sm-6">
                              <lable><b>To</b></lable>
                              <input style="width:100%;" type="text" placeholder="Ending Point" name="to" required>
                         </div>
                         
                        <br>.</br>
                         
                         <div class="col-sm-6">
                              <lable><b>Passengers</b></lable>
                              
                              <input  style="width:100%;"type="number" placeholder="Number of Passengers" name="pnumber" required>
                         </div>

                         <div class="col-sm-6">
                              <lable><b>Bags</b></lable>
                              
                              <input  style="width:100%;"type="number" placeholder="Number of Bags" name="bnumber" required>
                         </div>
                         
                         <br>.</br>
                         
                         <div class="col-sm-6">
                              <lable><b>Date</b></lable>
                              <br>
                              <input  style="width:100%;"type="date" onchange="TDate()" id="date" placeholder="Trip Date" name="ldate" required>
                         </div>

                         <!--<div class="col-sm-6">
                              <lable><b>Time</b></lable>
                              <br>
                              <input  style="width:100%;"type="time" placeholder="Leaving time" name="ltime" required>
                         </div>-->
                         
                        
                         <div class="col-sm-6">
                              <lable><b>Rate</b></lable>
                              <br>
                              <input  style="width:100%;"type="number" placeholder="Cost per KM" name="rate" required>
                         </div>
                         
                         
                         <!--<lable><b>Password</b></lable>
                         <input style="width:100%;" id="Password" name="dpassword" placeholder="Password" type="password" text-type="password">
                         <br></br>-->
                         <button style="width:100%;" align="center" name="create_btn" type="submit">Create</button>
                    </form>
               </div>
          </dir>
          <div class="col-sm-4"></div>
          <!-- Popup Div Ends Here -->
     </div>



     </div>
</body>
</html>
<!--
     <div class="col-sm-1"></div>
     <div class="col-sm-4">
          <div class="container">
               <h3 align="center"><b>HISTORY</b></h3>
               <?php
                    //execute the SQL query and return records
                    //$result = "SELECT DID,DNAME FROM driver ";
                    //$result = mysqli_query($con,$result);
               ?>
               <table style="width:100%; "><font text-color="white">
                    <thead>
                         <tr>
                              <th>driver_id</th>
                              <th>driver_Name</th>
                         </tr>
                    </thead>
                    
                    <tbody>-->
                         <!--Use a while loop to make a table row for every DB row-->
                         <!--
                         <?php //while( $row = mysqli_fetch_assoc( $result )) : ?>
                         <tr>
                              Each table column is echoed in to a td cell
                              <td><?php //echo $_SESSION["DID"]; ?></td>
                              <td><?php //echo $_SESSION["DID"]; ?></td>
                              <?php 
                              //$driverID = $_SESSION["DID"];
                              //echo '<script> alert("DRIVER ID IS " + $driverID); </script>';?>
                         </tr>
                         <?php //endwhile ?>
                    </tbody>-->
                    
                    
                    
                    
                    <!--
                    <tbody>
                         <?php
                              //while( $row = mysql_fetch_assoc( $result ) ){
                                   //echo
                                        //"<tr>
                                             //<td>{$row\['DID']\}</td>
                                             //<td>{$row\['DNAME'\]}</td>
                                        //</tr>\n";
                              //}
                         ?>
                    </tbody>
                    -->
                    <!--
               </font>
               </table>
          </div>
     </div>
     <div class="row">
     <div class="col-sm-2"></div>

     <div class="col-sm-4">
          <div class="container">
               <h3 align="center"><b>FUTURE</b></h3>
               <table style="width:100%; "><font text-color="white">
                    <tr>
                    <th>Cust ID</th>
                    <th>Cust Name</th> 
                    <th>Process ID</th>
                    </tr>
                    <tr>
                    <td>213</td>
                    <td>lavish</td>
                    <td>923</td>
                    </tr>
                    <tr>
                    <td>377</td>
                    <td>Krushna</td>
                    <td>924</td>
                    </tr>
                    
               </font></table>
          </div>
     </div>

     <div class="col-sm-1"></div>
     </div>

     <div class="col-sm-4"></div>

     <div class="col-sm-4">
          <div class="container1">      
               <h3 align="center"><b>ON GOING</b></h3>
               <table style="width:100%; "><font text-color="white">
                    <tr>
                    <th>Cust ID</th>
                    <th>Cust Name</th> 
                    <th>Process ID</th>
                    </tr>
                    <tr>
                    <td>117</td>
                    <td>Suresh</td>
                    <td>921</td>
                    </tr>
                    
               </font></table>
          </div>
     </div>

     <div class="col-sm-4"></div>-->