<?php

include_once("connectdb.php");
session_start();
if ($_SESSION["useremail"]=="" OR $_SESSION["role"]=="user" ){
    
    header("location:index.php");
    
}



include_once"header.php";







        if (isset($_POST['save'])) {
            if (!empty($_POST['deb'])) {
                $deb=htmlspecialchars($_POST['deb']);
            } else {
                $error_deb="Date à renseigner obligatoirement";
            }

            if (!empty($_POST['fin'])) {
                if ($_POST['fin'] < $_POST['deb']) {
                    $error_fin="La date de début ne peut pas excéder celle de fin";
                } else {
                    $fin=htmlspecialchars($_POST['fin']);
                }
                
            } else {
                $error_fin="Date à renseigner obligatoirement";
            }

            
            
            
            if (isset($deb) && isset($fin)) {
                $_SESSION['deb']=$deb;
                $_SESSION['fin']=$fin;
               
                echo '<script>window.location.href="apercu_bilan.php"</script>';
                 //header('refresh:3;apercu_bilan.php');
            }
            






        }







?>

 <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Etat des ventes</h1>
        
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
             <li class="breadcrumb-item"><a href="logout.php">Déconnexion</a></li>
              <li class="breadcrumb-item active"><a href="changepassword.php">Modifier mon mot de passe</a></li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>

   
   
   
   
   
   
    <!-- Main content -->
    <section class="content container-fluid">
          <!--    <div class="row">-->
              
               <!-- left column -->
          
            <!-- general form elements -->
            <div class="card card-warning">
              <div class="card-header">
                <h3 class="card-title">Etat</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              
               
                <div class="card-body">
                <form role="form" action="" method="post">
                <div class="row">
                 <div class="col-md-6">
                 
                 
                  <div class="form-group">
                  <label>Date de début</label>
                      <div class="input-group date"   data-target-input="nearest">
                        <input type="date"  class="form-control" name="deb" required>
                    </div>
                    <?php
                         if(!empty($error_deb)){
                            echo '<h5 style="color:red;">'.$error_deb.'</h5>';
                         }
                    ?>
                </div>
                  
                
                  </div>

                 
                 <div class="col-md-6">
                  <div class="form-group">
                  <label>Date de fin</label>
                      <div class="input-group date"   data-target-input="nearest">
                        <input type="date"  class="form-control" name="fin" required>
                    </div>
                    <?php
                         if(!empty($error_fin)){
                            echo '<h5 style="color:red;">'.$error_fin.'</h5>';
                         }
                    ?>
                </div>
                  
                </div>

                 <hr>
                  <div align="center">
                      
                      <input type="submit" name="save" value="Voir l'apercu" class="btn btn-info" >
                      
                      
                  <br><br><br></div>

                   
 
                  
                 
                
                   
                   
                   
                   
                    </div>
                  
                  
                <!-- /.card-body -->

                
              </form>
              </div>
            
            <!-- /.card -->

           
                
              
            
            

          <!--/.col (left) -->
          <!-- right column -->


       
            
            
              
                
                <!-- /.form group -->
                
                
                <!-- /.form group -->
              
                
              <!-- /.card-body -->
            
                
                
              </div>
           
      
        
        <!-- /.right column -->
        
        <!--   </div> -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->






  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
    <div class="p-3">
      <h5>Title</h5>
      <p>Sidebar content</p>
    </div>
  </aside>
  <!-- /.control-sidebar -->

 <?php
include_once"footer.php";


?>