<?php
if(!empty($_SESSION['user_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 consultations where id='$id'";
$query_get=mysqli_query($con,$req_get);

$row= mysqli_fetch_array($query_get); 
$id_patient= $row['id_patient'];


$req_get_patient="SELECT * FROM patients where id='$id_patient'";
$query_get_patient=mysqli_query($con,$req_get_patient);
$row_patient= mysqli_fetch_array($query_get_patient);
?>
<h4 class="title"><i class="fa fa-building"></i> Modifier La Consultation du patient " <?php echo $row_patient['nom']." ".$row_patient['prenom']; ?> "</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 $row['id']; ?>">
                    
                       <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Nom et prénom du patient</label>
        
                       <input type="text" class="form-control" name="patient" value="<?php echo $row_patient['nom']." ".$row_patient['prenom'] ?>" disabled>  
                       
                      </div>
                      </div> 
                      <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Motif </label>
                      <select name="motif" class="form-control" >
                           <option value="<?php echo $row['motif'] ?>"><?php echo $row['motif']; ?></option>
                        <option value="Consultation">Consultation</option>
                         <option value="Controle">Controle</option>
                      </select>
                      </div>
                      </div> 
                    

                     <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Poids</label>
                      <input  type="number" step="any" required="required"  class="form-control"  id="poids" name="poids" value="<?php echo $row['poids'] ?>">


                      </div>
                      </div> 
                       <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Taille</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="taille" name="taille" value="<?php echo $row['taille'] ?>">
                      </div>
                      </div> 


                        <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Temperature</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="temperature" name="temperature" value="<?php echo $row['temperature'] ?>" ?>
                      </div>
                      </div> 

                        <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Frequence Cardiaque</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="frequence_cardiaque" name="frequence_cardiaque" value="<?php echo $row['frequence_cardiaque'] ?>">
                      </div>
                      </div> 
                        <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Glycemie</label>
                      <input type="number" step="any" required="required"  class="form-control"  id="glycemie" name="glycemie" value="<?php echo $row['glycemie'] ?>">
                      </div>
                      </div> 
                       <div class="form-group">
                      <div class="col-sm-3 col-xs-12">
                      <label>Diagnostic Medical</label>
                      <textarea class="form-control"  id="diagnostic_medical" name="diagnostic_medical"><?php echo $row['diagnostic_medical'] ?></textarea>
                     
                      </div>
                      </div>
              <div class="form-group">
                         <div class="col-sm-3 col-xs-12">
              <input type="submit" id="modifier" class="btn btn-primary btn-block" value="modifier">
              </div>
               <div class="col-sm-3 col-xs-12">
              <button class="btn btn-success btn-block" onclick="rtn()">Retour</button>

                     </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_consultation").addClass("active");
document.title = 'Modifier Consultation ';

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

    }, "type required");
$("#form").validate({
submitHandler: function(form) {
$.ajax({
 url: 'actions/consultation/modifier.php',
 type: "POST",
 data: new FormData(form),
 contentType: false,
 cache: false,
 processData: false,
 success: function(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();
               }, 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: {
               nom: "required",
               nomar: "required",
                               },
                messages: {
                        nom: "Entrez le nom ",
                            nomar: "Entrez le nom en arab"
                           },
                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>
<script>
function rtn() {
   window.history.back();
}
</script>
<?php } 

}else{  

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