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


 ?>
<h4 class="title" ><i class="fa fa-users"></i> Liste des patients
<a href="index.php?p=add_patient"  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 >N°</th>
                            <th >Nom et prénom</th>
                            <th >Sexe</th>
                            <th >Age</th>
                            <th> Actions</th>
                          </tr>
                      </thead>
                          <tbody>

       <?php

       $req_sql="SELECT * FROM patients";
      $query=mysqli_query($con,$req_sql);

         while ($row = mysqli_fetch_array($query) ) {  ?>
         <tr>
         <td > <?php echo $row['id'] ?> </td>
          <td > <?php echo $row['nom']." ". $row['prenom']; ?> </td>
          <td > <?php echo $row['sexe']; ?> </td>
          <td > <?php echo $row['age']; ?> </td>

          <td>
           <button type="button" class="btn btn-info btn-xs" data-toggle="modal"  data-target="#affiche<?php echo $row['id'];?>">Afficher</button>
           <a href="index.php?p=infos_patient&id=<?php echo $row['id'];?>" class="btn btn-success btn-xs"> Détails</a>
           <a href="index.php?p=edit_patient&id=<?php echo $row['id'];?>" class="btn btn-warning btn-xs"> Modifier</a>
    
            <button type="button" class="btn btn-danger btn-xs sup_patient"  data="<?php echo $row['id'];?>" >Supprimer</button>
            <div class="modal fade" id="affiche<?php echo $row['id'];?>" 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">Patient  "<?php echo $row["nom"].$row["prenom"]; ?> "</h4>
      </div>
      <div class="modal-body">
      <table class="table table-striped table-bordered table-hover" >
             <tr><th>Nom </th> <td > <?php echo $row["nom"]; ?></td></tr>
             <tr><th>Prenom </th> <td > <?php echo $row["prenom"]; ?></td></tr>
             <tr><th>Date de naissance</th> <td > <?php echo $row["date_naissance"]; ?></td></tr>
             <tr><th>Age</th> <td > <?php echo $row["age"]; ?></td></tr>
             <tr><th>Groupe sanguin</th> <td > <?php echo $row["groupe_sanguin"]; ?></td></tr>
             <tr><th>Situation familiale</th> <td > <?php echo $row["situation_familiale"]; ?></td></tr>
             <tr><th>Adresse</th> <td > <?php echo $row["adresse"]; ?></td></tr>
             <tr><th>Tel</th> <td > <?php echo $row["tel"]; ?></td></tr>
            
  
             <tr><th>Date d'ajout </th> <td > <?php $date=date_create($row['date_creation']);  echo date_format($date,"d/m/Y H:i"); ?></td></tr>
     <tr><th> Date de modification </th> <td > <?php $date=date_create($row['date_modification']);  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_patients").addClass("active");
 document.title = 'Liste des patients ';
$(".sup_patient").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_patient&id="+id,function()
    {   
       setTimeout(function() {
              location.reload();
               }, 2000);
    });

    swal(

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


  }
})

});

 $(".desact_user").click(function ()
{   var id = $(this).attr('id');
$.get("actions/fonctions.php?type=desact_user&id="+id,function()
    {    location.reload();
    });
});

$(".act_user").click(function ()
{   var id = $(this).attr('id');
$.get("actions/fonctions.php?type=act_user&id="+id,function()
    {    location.reload();
    });
});


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