<?php

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

  $_SESSION['raison_sociale']="";
  $_SESSION['adresse']="";
  $_SESSION['tel']="";
  $_SESSION['format']="";


$sel=$pdo->prepare('SELECT * FROM param');
$sel->execute(array());
while ($sels=$sel->fetch()) {
  $_SESSION['raison_sociale']=$sels['raison_sociale'];
  $_SESSION['adresse']=$sels['adresse'];
  $_SESSION['tel']=$sels['tel'];
  $_SESSION['format']=$sels['format'];
}


if(isset($_POST["btnSave"])){
    
    $up=$pdo->prepare('UPDATE param SET raison_sociale=?, adresse=?, tel=?, format=?');
    $up->execute(array($_POST['raison_sociale'],$_POST['adresse'],$_POST['tel'], $_POST['format']));
    if ($up) {
      $_SESSION['raison_sociale']=$_POST['raison_sociale'];
      $_SESSION['adresse']=$_POST['adresse'];
      $_SESSION['tel']=$_POST['tel'];
      $_SESSION['format']=$_POST['format'];

       echo 
            
                "<script type='text/javascript'>
        
        jQuery(function validation(){
        
        Swal.fire({
  position: 'center',
  icon: 'success',
  title: 'Succès',
  text: 'Confifigartion effectuée',
  showConfirmButton: false,
  timer: 3000
})
        
        });
        
        </script>";
    }

  }
    
    
   







?>

 <!-- 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">Configuration</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 -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Configuration</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form  method="post">
               
                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1">Rasion sociale</label>
                    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="raison_sociale" required value="<?php echo $_SESSION['raison_sociale']; ?>">
                  </div>
                  
                </div>

                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1"> Adresse</label>
                    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="adresse" required value="<?php echo $_SESSION['adresse']; ?>">
                  </div>
                  
                </div>

                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1">Téléphone</label>
                    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="tel" required value="<?php echo $_SESSION['tel']; ?>">
                  </div>
                  
                </div>
                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1">Format d'impression par défaut</label>
                    <select class="form-control" name="format" required>
                      <option value="<?php echo $_SESSION['format']; ?>"><?php echo $_SESSION['format']; ?></option>
                      <option value="A4">A4</option>
                      <option value="Thermique">Thermique</option>
                    </select>
                    
                  </div>
                  
                </div>


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

                <div class="card-footer">
                  <button type="submit" class="btn btn-primary" name="btnSave">Enregistrer</button>
                </div>
              </form>
            </div>
            <!-- /.card -->

           
                
              
            </div>
            

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


      
        
        
        <!-- /.right column -->
        
          </div> 

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












<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>






  <!-- 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";


?>