<!DOCTYPE html>
<html lang="en">
<head>
    <title>Wasah</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8">

             
    <!-- External CSS libraries -->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-submenu.css">
    <link rel="stylesheet" type="text/css" href="css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="css/slider.css">
    <link rel="stylesheet" type="text/css" href="css/style_form.css">
    <link rel="stylesheet" type="text/css" href="fonts/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="fonts/linearicons/style.css">
    <link rel="stylesheet" type="text/css" href="fonts/flaticon/font/flaticon.css">
    
    

    <link href="css/bootstrap-select.min.css" type="text/css" rel="stylesheet">

    <!-- Custom stylesheet -->
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" type="text/css" id="style_sheet" href="css/colors/default.css">

    <!-- Favicon icon -->
    <link rel="shortcut icon" href="img/favicon.gif" type="image/x-icon" >

    <!-- Google fonts -->
    <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800%7CPlayfair+Display:400,700%7CRoboto:100,300,400,400i,500,700">
    <link href="https://fonts.googleapis.com/css?family=Oswald:400,600,700" rel="stylesheet">
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script type="text/javascript" src="js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script type="text/javascript" src="js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script type="text/javascript" src="js/html5shiv.min.js"></script>
    <script type="text/javascript" src="js/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<div class="page_loader"><img src="img/loader.gif" alt="Loader"></div>

<!-- Top Header start -->
 <?php include_once ("styl/vrchni_panel.php");?>
<!-- Top Header end -->

<!-- Main header start -->
<?php include_once ("styl/panel.php");?>
<!-- Main header end -->

<!-- Sub banner start -->
<div class="sub-banner">
    <div class="overlay">  
    </div>
</div>
<!-- Sub banner end -->

<!-- Car list start-->
<?php
include_once ("databaze/pripojit.php");
  



$dotaz_auta="SELECT * FROM auta WHERE stav = 'vraceno'";


 $vysledek_auta = mysqli_query($link, $dotaz_auta);
if(!$vysledek) {
    echo "error udalost_list";
    exit();
  }    
    $pocet_auta = mysqli_num_rows($vysledek_auta);
    $datum = date("Y-m-d");
    
$dotaz_event="SELECT * FROM event WHERE odhlaseni_datum>=$datum";
  //date("Y-m-d")

 $vysledek_event = mysqli_query($link, $dotaz_event);
if(!$vysledek) {
    echo "error udalost_list";
    exit();
  }    
    $pocet_event = mysqli_num_rows($vysledek_event);    
//***************************************************************************************************************************************
 if ($_GET["zmena_vratit_km"])  {
     
  $s_vratit = htmlspecialchars($_GET['zmena_vratit_auto']);
  $s_km = htmlspecialchars($_GET['zmena_vratit_km']);
  $s_datum = date("Y-m-d");
  $s_kdo = $_SESSION["uzivatel"]->email;
 
 
 
  $dotaz3 = "INSERT INTO auta_historie (VIN, datum_od, kdo, stav_km) VALUES ('$s_vratit','$s_datum','$s_kdo','$s_km')";
  $vysledek3 = mysqli_query($link, $dotaz3);
  if(!$vysledek3) {
    echo "error registrace udalost.php";
    exit();
  }
   $dotaz_stav="UPDATE auta SET stav ='vraceno', najeto_km='$s_km'  WHERE vin='".$s_vratit."'";  
      $vysledek_stav = mysqli_query($link, $dotaz_stav);
  if(!$vysledek_stav) {
    echo "error registrace udalost.php";
    exit();
  } 
  header('Location: car_sprava.php?auto_vraceno_garaz');
   
 }



 else if ($_GET["kdo"])  {
 
 
   
  $t_vin = htmlspecialchars($_GET['vin']);
  $t_datum = htmlspecialchars($_GET['datum']);
  $t_komu = htmlspecialchars($_GET['komu']);
  $t_udalost = htmlspecialchars($_GET['udalost']);
  $t_kdo = htmlspecialchars($_GET['kdo']); 

  
  $dotaz_auta8="SELECT * FROM auta WHERE vin='$t_vin'";
   

 $vysledek_auta8 = mysqli_query($link, $dotaz_auta8);
if(!$vysledek) {
    echo "error udalost_list";
    exit();
  }    
    $radek_auta8=mysqli_fetch_object($vysledek_auta8);
    $t_stav_km = $radek_auta8->najeto_km;

 
   include_once ("databaze/pripojit.php");
   $dotaz3 = "INSERT INTO auta_historie (VIN, datum_od, kdo, komu, stav_km, udalost) VALUES ('$t_vin','$t_datum','$t_kdo','$t_komu','$t_stav_km','$t_udalost')";
  $vysledek3 = mysqli_query($link, $dotaz3);
  if(!$vysledek3) {
    echo "error registrace udalost.php";
    exit();
  }
   $dotaz_stav="UPDATE auta SET stav ='vypujceno'  WHERE vin='".$t_vin."'";  
      $vysledek_stav = mysqli_query($link, $dotaz_stav);
  if(!$vysledek_stav) {
    echo "error registrace udalost.php";
    exit();
  }  
  header('Location: car_sprava.php?auto_pujceno_garaz');

   }
    else {} 
//******************************************************************************************************************************************

    
?>

<!-- TABULKA!!! -->


    
 <div class="container">
 <table class='table table-bordered table-striped'>   
<form action="#">
 <br>
 <label for="vins">Vyber Vin auta k zapůjčení:</label>
  <select id="vin" name="vin">
  
  <?php 
  if ($_GET["vin"]) { 
  
  $win2 = $_GET["vin"];
   echo "<option value='$win2'>$win2</option>";}
   else {
  for ($i = 1; $i <= $pocet_auta; $i++) {
   // echo "<option value='$radek_auta'>'$radek_auta'</option>";
   $radek_auta=mysqli_fetch_object($vysledek_auta);
   echo "<option value='$radek_auta->vin'>$radek_auta->vin</option>";
 }}
  
  
  ?>
   
  </select>
   <br>
  <?php if ($_GET["vin"]) { ?>
 Komu chcete auto půjčit: <input type="text" name="komu" > 
 <input type="hidden" name="kdo" value="<?php echo $_SESSION["uzivatel"]->email;?>">
 <br>
 Datum vypůjčení od:  <input type="date" name="datum" > 
 <br>
 <label for="udalost">K jaké události</label>
  <select id="udalost" name="udalost">
  
  <?php 
  
  for ($i = 1; $i <= $pocet_event; $i++) {
   // echo "<option value='$radek_auta'>'$radek_auta'</option>";
   $radek_event=mysqli_fetch_object($vysledek_event);
   echo "<option value='$radek_event->nazev'>$radek_event->nazev</option>";
}
  
  
  ?>
   
  </select>
   <br>
   <?php } ?>
  
 <button  name="tlacitko" type="submit" > <?php if ($_GET["vin"]) { ?> Pujč auto <?php } else { ?>  Pokračovat  <?php }?> </button> 
</form>
 </form>
</table>
<br>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!START: Historie auta !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<H3>Historie:</H3>
 <br>
 <?php 
 
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!START: HISTORIE PDF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if ($_GET["vypis_historie"])  {
          $a_historie = htmlspecialchars($_GET['vypis_historie']);
         echo "Výpis historie VIN: ";
         echo   $a_historie;
         echo " ke stažení zde:";
         ?> <a href="pdf_historie.php?karta=<?php echo $a_historie; ?>" target="_blank">Historie.pdf</a> <?php
         
          }
 
 
 
 
 
 
 
 
 
 
 
 
  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!KONEC: HISTORIE PDF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   echo "<br>";
  $dotaz_vypis_historie="SELECT * FROM auta";
   

 $vysledek_vypis_historie = mysqli_query($link, $dotaz_vypis_historie);
if(!$vysledek_vypis_historie) {
    echo "error udalost_list";
    exit();
  }    
    $pocet_vypis_historie = mysqli_num_rows($vysledek_vypis_historie);
   ?>


 <form action="car_sprava.php" method="GET" id="form3"> Aktuální stav tachometru: 
    
    <select id="vypis_historie" name="vypis_historie">
  
  <?php 

  for ($i = 1; $i <= $pocet_vypis_historie; $i++) {
   // echo "<option value='$radek_auta'>'$radek_auta'</option>";
   $radek_vypis_historie=mysqli_fetch_object($vysledek_vypis_historie);
   echo "<option value='$radek_vypis_historie->vin'>$radek_vypis_historie->vin</option>";
}
  
  
  ?>
   
  </select>
    
    
    
    
    <input type="submit" name="button_historie" value="Vypiš historii" form="form3">  </form> 


<br>
<br>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!KONEC: Historie auta !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!START: Zapůjčená auta !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<H3>Zapůjčená auta:</H3> 
<br>
 <?php  $dotaz_vypis_pujcky="SELECT * FROM auta WHERE stav='vypujceno'";
   

 $vysledek_vypis_pujcky = mysqli_query($link, $dotaz_vypis_pujcky);
if(!$vysledek_vypis_pujcky) {
    echo "error udalost_list";
    exit();
  }    
    $pocet_vypis_pujcky = mysqli_num_rows($vysledek_vypis_pujcky);
   ?>


 <form action="car_sprava.php" method="GET" id="form2"> Aktuální stav tachometru: 
    <input type="text" name="zmena_vratit_km" > 
    
    <select id="zmena_vratit_auto" name="zmena_vratit_auto">
  
  <?php 

  for ($i = 1; $i <= $pocet_vypis_pujcky; $i++) {
   // echo "<option value='$radek_auta'>'$radek_auta'</option>";
   $radek_vypis_pujcky=mysqli_fetch_object($vysledek_vypis_pujcky);
   echo "<option value='$radek_vypis_pujcky->vin'>$radek_vypis_pujcky->vin</option>";
}
  
  
  ?>
   
  </select>
    
    
    
    
    <input type="submit" name="s_vratit" value="Vrátit auto" form="form2">  </form> 


    
 <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!KONEC: Zapůjčená auta!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->  


  <br><br>
<br>
</div>




<!-- Footer start-->
<?php include_once ("styl/spodek.php");?>
<!-- Footer end-->




<script type="text/javascript" src="js/jquery-2.2.0.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-slider.js"></script>
<script type="text/javascript" src="js/wow.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollUp.js"></script>
<script type="text/javascript" src="js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="js/bootstrap-submenu.js"></script>

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script type="text/javascript" src="js/ie10-viewport-bug-workaround.js"></script>

<!-- Custom javascript -->
<script type="text/javascript" src="js/app.js"></script>

</body>
</html>