<?php
if(!empty($_SESSION['admin_connect_id']))
{


 ?>
<h4 class="title" ><i class="fa fa-calendar-alt"></i> Liste des planning  
<a href="index.php?p=add_planning"  class="btn btn-sm btn-success pull-right">Ajouter</a>
 </h4>
        <div class="row">
          <div class="col-lg-12">
                  <div class="form-panel">
                    <table id="dataTables" class="table table-striped table-bordered table-hover">
                      <thead>
                          <tr>
                            <th >Parcours </th>
                            <th >unité </th>
                            <th >Destination </th>
                            <th >Heure</th>
                            <th >Clients</th>
                            <th style="width:20%;"> Actions</th>
                          </tr>
                      </thead>

      <tbody>

       <?php



       $req_sql="SELECT *,planning.id as idplanning  FROM planning
LEFT JOIN parcours ON ( planning.plnpar=parcours.id)
LEFT JOIN destinations ON (planning.plndest=destinations.id)
LEFT JOIN unite ON (planning.plnunite=unite.id)
LEFT JOIN clients ON (planning.plnclient=clients.id)
LEFT JOIN users ON ( planning.plnadded_by=users.id)";
       $query_s=mysqli_query($con,$req_sql);

         while ($row_par = mysqli_fetch_array($query_s) ) {  ?>
         <tr>
         
          <td > <?php echo $row_par['parnom'];?> </td>
          <td > <?php echo $row_par['uninom'];?> </td>
          <td > <?php echo $row_par['dstnom'];?> </td>
          <td > <?php echo $row_par["plnheure"]; ?> </td>
          <td > <?php echo $row_par['clinom']; ?> </td>
         <td>
           <button type="button" class="btn btn-info btn-xs" data-toggle="modal"  data-target="#affiche<?php echo $row_par['idplanning'];?>">Afficher</button>
           <a href="index.php?p=edit_planning&id=<?php echo $row_par['idplanning'];?>" class="btn btn-success btn-xs"> Modifier</a>
    
 <button type="button" class="btn btn-danger btn-xs sup_en"  data="<?php echo $row_par['idplanning'];?>" >Supprimer</button>
 <div class="modal fade" id="affiche<?php echo $row_par['idplanning'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">planning  " <?php echo $row_par["parnom"]; ?> "</h4>
      </div>
      <div class="modal-body">
      <table class="table table-striped table-bordered table-hover" >
             <tr><th>Nom </th> <td > <?php echo $row_par["parnom"]; ?></td></tr>
             <tr><th>Nom en arabe </th> <td > <?php echo $row_par["parnomar"]; ?></td></tr>
             <tr><th>Unité</th> <td > <?php echo $row_par["uninom"]; ?></td></tr>
             <tr><th>Destination </th> <td > <?php echo $row_par["dstnom"]; ?></td></tr>
             <tr><th>Ajouté par</th> <td > <?php echo $row_par["nom"]; ?></td></tr>
             <tr><th>Date d'ajout </th> <td > <?php $date=date_create($row_par['parcreated_at']);  echo date_format($date,"d/m/Y H:i"); ?></td></tr>
     <tr><th> Date de modification </th> <td > <?php $date=date_create($row_par['parupdated_at']);  echo date_format($date,"d/m/Y H:i"); ?></td></tr>


          


      </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
      </div>
    </div>
  </div>
</div>
 </td>

          </tr>
          <?php  } ?>
     </tbody>
     </table>
                  </div>
          </div>
          </div>
<script type="text/javascript">
 $(document).ready(function() {
  $("#g_planning").addClass("active");
 document.title = 'Liste des planning ';
$(".sup_en").click(function ()
{   var id = $(this).attr('data');

swal({
  title: ' Voulez vous vraiment supprimer cet enregistrement ?',
  text: "Vous ne serez pas capable de revenir à cela!",
  type: 'warning',
  width: 600,
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Oui, supprimez-le !',
  cancelButtonText:  'Non'
}).then((result) => {
  if (result.value) {
//if click oui
$.get("actions/fonctions.php?type=sup_planning&id="+id,function()
    {   
       setTimeout(function() {
              location.reload();
               }, 2000);
    });

    swal(

      'Supprimé !',
      'L\'enregistrement a été supprimé.',
      'success'
    ).then(function(){ 
   location.reload();
   })
  


  }
})

});




} );
      </script>
<?php } ?>