<?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 dparcours where id='$id'";
$query_get=mysqli_query($con,$req_get);

$data= mysqli_fetch_array($query_get); 

?>


<h4 class="title"><i class="fa fa-road"></i> Modifier les détails </h4>
  <div class="row">
              <div class="col-lg-12">
                  <div class="form-panel">
                    <form id="form" method="" class="form-horizontal" action=""  enctype="multipart/form-data">
                     <input type="hidden" name="id" value="<?php echo $data['id']; ?>">
                    
                 
                      <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Ordre </label>
                      <input type="number" required="required"  class="form-control"  id="ordre" name="ordre" value="<?php echo $data['dprord'];  ?>">
                      </div>
                      </div> 
                    

                     <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Prix (DA)</label>
                      <input type="text" required="required"  class="form-control"  id="prix" name="prix" value="<?php echo $data['dprprix'];  ?>">
                      </div>
                      </div> 
                       <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Distance</label>
                      <input type="text" required="required"  class="form-control"  id="km" name="km" value="<?php echo $data['dprkm'];  ?>">
                      </div>
                      </div>  

                         <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Heure </label> 
                      <input type="time"required="required"  class="form-control"  id="heure" name="heure" value="<?php echo $data['dprheur'];  ?>">
                      </div>
                      </div> 
                   
 
                       <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Point d'arrivé  </label>
        
                      <select name="destinations" class="form-control" >
                         
                        <option value="0">sélectionnez le Point d'arrivé </option>
                        <?php
                       $reqq= "SELECT * FROM destinations";
                        $q_destinations  = mysqli_query($con,$reqq);
                         while ($destinations = mysqli_fetch_array($q_destinations)) {
                        ?>
                         <option value="<?php echo $destinations['id'] ?>" 
 <?php if($data['dprponint']==$destinations['id']){ echo "selected";} ?>

                          ><?php echo $destinations['dstnom'] ?></option>
                      <?php  }  ?>
                                          
                        
                      </select>
                      </div>
                      </div> 



              <div class="form-group">
                         <div class="col-sm-6 col-xs-12">
              <input type="submit" id="modifier" class="btn btn-primary btn-block" value="modifier">
                     </div>
                     </div>
                <div class="input-group message col-sm-6" id="mess">

              </div>
                </form>

                  </div>
        </div>
  </div>


<script type="text/javascript" src="assets/js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready( function () {
$("#g_parcours").addClass("active");
document.title = 'Modifier parcours ';

   jQuery.validator.addMethod('selectcheck', function (value) {
    return (value != '0');

    }, "type required");
$("#form").validate({
submitHandler: function(form) {
$.ajax({
 url: 'actions/dparcours/modifier.php',
 type: "POST",
 data: new FormData(form),
 contentType: false,
 cache: false,
 processData: false,
 success: function(data){
  alert(data);
  if(data == 1){
        $("#mess").html('<div class="alert alert-success">  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>   <strong>Modification avec succès </strong> </div>')  ;
               setTimeout(function() {
              /* location.reload();*/
  window.location.href ="index.php?p=dt_parcours&id=<?php echo $data['dprpar']; ?>";
               }, 2000);
    } else  {
     $("#mess").html('<div class="alert alert-danger">  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>   <strong>Erreur.</strong> </div>')  ;

     }
},
 error: function(){}
 });
  } ,
             rules: {  
               ordre: "required",
               prix: "required",
               km: "required",
               heure: "required",
               destinations: "selectcheck"


                               },
                messages: {
                        ordre: "Entrez l'ordre ",
                        prix: "Entrez le prix", 
                        km: "Entrez le Kilométrage", 
                        heure: "Entrez l'heure", 
                       destinations: "sélectionnez le point d'arrivé",  

                                                },
                errorElement: "em",
                errorPlacement: function ( error, element ) {

                    error.addClass( "help-block" );

                    element.parents( ".col-sm-6" ).addClass( "has-feedback" );

                    if ( element.prop( "type" ) === "checkbox" ) {
                        error.insertAfter( element.parent( "label" ) );
                    } else {
                        error.insertAfter( element );
                    }

                },

                highlight: function ( element, errorClass, validClass ) {
                    $( element ).parents( ".col-sm-6" ).addClass( "has-error" ).removeClass( "has-success" );
                    $( element ).next( "span" ).addClass( "glyphicon-remove" ).removeClass( "glyphicon-ok" );
                },
                unhighlight: function ( element, errorClass, validClass ) {
                    $( element ).parents( ".col-sm-6" ).addClass( "has-success" ).removeClass( "has-error" );
                    $( element ).next( "span" ).addClass( "glyphicon-ok" ).removeClass( "glyphicon-remove" );
                }
            } );
        } );


</script>
<?php } 

}else{  

 include("../404.php");  } ?>