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

if(!isset($_GET['id'])){
  include("pages/404.php");
 }
 else
 {

$id=mysqli_real_escape_string($con,htmlspecialchars(trim($_GET['id']))) ;
$req_get="SELECT * FROM parcours,destinations,unite  where parcours.id='$id' and  
parcours.pardest=destinations.id and  parcours.parunite=unite.id
";

$query_get=mysqli_query($con,$req_get);

$data= mysqli_fetch_array($query_get); 

 ?>
<h4 class="title" ><i class="fa fa-road"></i> détails  "<?php echo $data['parnom']; ?> "
<a href="index.php?p=add_dparcours&idpr=<?php echo $id; ?>"  class="btn btn-sm btn-success pull-right">Ajouter</a>
 </h4>
        <div class="row">
          <div class="col-lg-12">
                  <div class="form-panel">
<div class="parcours">
  <h3>  <?php echo $data["uninom"]; ?> <img src="assets/img/arr.png" S> <?php echo $data['dstnom']; ?> </h3>  
                   

</div>
 <table id="dataTables" class="table table-striped table-bordered table-hover">
                      <thead>
                          <tr>
                         
                            <th >Ordre</th>
                            <th >Point d'arrivé</th>
                            <th >Heure</th>
                            <th >Prix</th>
                            <th >Distance</th>
                            <th style="width:15%;"> Actions</th>
                          </tr>
                      </thead>

      <tbody>
<?php
 $req_sql="SELECT *,dparcours.id as iddparcours from dparcours,destinations where 
dparcours.dprponint=destinations.id and 
 dprpar='$id' ORDER BY dprord";

$query_s=mysqli_query($con,$req_sql);
while ($row_par = mysqli_fetch_array($query_s) ) {  ?>
         <tr>
         <td > <?php echo $row_par["dprord"]; ?> </td>
          <td > <?php echo $row_par["dstnom"]; ?> </td>
          <td > <?php echo $row_par['dprheur']; ?> </td>
          <td > <?php echo $row_par['dprprix']; ?> DA </td>
          <td > <?php echo $row_par['dprkm']; ?> KM</td>
          
      
          <td>
         
           <a href="index.php?p=edit_dparcours&id=<?php echo $row_par['iddparcours'];?>" class="btn btn-success btn-xs"> Modifier</a>
    
 <button type="button" class="btn btn-danger btn-xs sup_en"  data="<?php echo $row_par['iddparcours'];?>" >Supprimer</button>

 </td>

          </tr>
          <?php  } ?>
     </tbody>
     </table>
                  </div>
          </div>
          </div>
<script type="text/javascript">
 $(document).ready(function() {
  $("#g_parcours").addClass("active");
 document.title = ' détails <?php echo $data['parnom']; ?> ';
$(".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_dparcous&id="+id,function()
    {   
       setTimeout(function() {
              location.reload();
               }, 2000);
    });

    swal(

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


  }
})

});




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

 ?>