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

$row= mysqli_fetch_array($query_get); 

?>

 
 	<div class="row">
          		<div class="col-lg-12">
                  <div class="form-panel">
                   	<form id="add-form" method="" class="form-horizontal" action=""  enctype="multipart/form-data">  
                  <div class="col-sm-12 col-xs-12 part_div"> 
                 

              	   <div  id="titre_glob1" class="col-sm-4 col-xs-12 titre_glob"> 
                     <div class="col-sm-12 col-xs-12 part_div">
                    <h4 id="sous_title1" class="sous_title"> Informations patient</h4>

                    
                    

                     <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Nom(*) </label>
                      <input type="text" required="required"  class="form-control"  id="nom" name="nom" value="<?php echo $row['nom'] ?>">
                      </div>
                      </div> 
                      
                       <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Prénom(*) </label>
                      <input type="text" required="required"  class="form-control"  id="prenom" name="prenom" value="<?php echo $row['prenom'] ?>">
                      </div>
                      </div> 
                     
                       <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label for="date">Date de naissance(*)</label> 
                      
                       <input class="form-control" type="date" id="date_naissance" name="date_naissance" value="<?php echo $row['date_naissance'] ?>">
                      </div>
                     
                     
                      </div>
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Sexe</label>
        
                      <select name="sexe" class="form-control" >
                         
                        <option value="<?php echo $row['sexe'] ?>"><?php echo $row['sexe'] ?></option>
                        <option value="F" >F</option>
                        <option value="M" >M</option>
                        
                      </select>
                      </div>
                      </div>
                       

                       <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Groupe Sanguin</label>
        
                      <select name="groupe_sanguin" class="form-control" >
                         
                        <option value="<?php echo $row['groupe_sanguin'] ?>"><?php echo $row['groupe_sanguin'] ?></option>
                        <option value="O-" >O-</option>
                        <option value="O+" >O+</option>
                        <option value="B-" >B-</option>
                         <option value="B+" >B+</option>
                        <option value="A-" >A-</option>
                        <option value="A+" >A+</option>
                        <option value="AB-" >AB-</option>
                        <option value="AB+" >AB+</option>
                      </select>
                      </div>
                      </div>

                       <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Situation familiale</label>
        
                      <select name="situation_familiale" class="form-control" >
                         
                        <option value="<?php echo $row['situation_familiale'] ?>"><?php echo $row['situation_familiale'] ?></option>
                        <option value="Célibataire" >Célibataire</option>
                        <option value="Marié(e)" >Marié(e)</option>
                        <option value="Divorcé(e)" >Divorcé(e)</option>
                      </select>
                      </div>
                      </div>

                
                      </div> 
                      </div> 
                      
                      <div id="titre_glob2" class="col-sm-4 col-xs-12 titre_glob">
                           <div class="col-sm-12 col-xs-12 part_div"> 
                         <h4 id="sous_title2" class="sous_title">Coordonnées</h4>
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Email</label>
                      <input type="mail"  class="form-control"  id="mail" name="mail" value="<?php echo $row['mail'] ?>">
                      </div>
                      </div> 

                      <div class="form-group">
                      <div class="col-sm-10 col-xs-12">
                      <label>Tel</label>
                      <input type="text"  class="form-control"  id="tel" name="tel" value="<?php echo $row['tel'] ?>">
                      </div>
                      </div> 
                      
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Adresse</label>
                      <textarea  class="form-control"  id="adresse" name="adresse" rows="4" >
                        <?php echo $row['adresse'] ?>
                      </textarea> 
                      </div>
                      </div> 
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Note</label>
                      <textarea  class="form-control"  id="note" name="note" rows="4" >   <?php echo $row['note'] ?>     
                      </textarea> 
                      </div>
                      </div> 
                      </div>
                      </div>
                     
                      <div  id="titre_glob3" class="col-sm-4 col-xs-12 titre_glob">
                       <div class="col-sm-12 col-xs-12 part_div"> 
                       <h4  id="sous_title3" class="sous_title"> Antécédents</h4>
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Antécédents médicaux</label>
                      <textarea  class="form-control"  id="antecedents_med" name="antecedents_med" rows="3">  <?php echo $row['antecedents_med'] ?>      
                      </textarea> 
                      </div>
                      </div> 
                       <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Antécédents chirurgicaux</label>
                      <textarea  class="form-control"  id="antecedents_chirur" name="antecedents_chirur" rows="3">  <?php echo $row['antecedents_chirur'] ?>      
                      </textarea> 
                      </div>
                      </div>                       
                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Antécédents Familiales</label>
                      <textarea  class="form-control"  id="antecedents_famil" name="antecedents_famil" rows="3">  <?php echo $row['antecedents_famil'] ?>      
                      </textarea> 
                      </div>
                      </div> 

                      <div class="form-group">
                      <div class="col-sm-12 col-xs-12">
                      <label>Autres antécédents</label>
                      <textarea  class="form-control"  id="antecedents_autres" name="antecedents_autres" rows="3"><?php echo $row['antecedents_autres'] ?>
                        
                      </textarea> 
                      </div>
                      </div> 
                      </div> 
                      </div> 
 </div> 

              <div class="form-group">
                         <div class="col-sm-2 col-xs-12">
                          <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
              <input type="submit" id="modifier" class="btn btn-primary btn-block" value="Modifier"></input>
                     </div>
                     <div class="input-group message col-sm-6" id="mess">
                     </div>
                

              </div>
              	</form>

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


<script type="text/javascript" src="assets/js/jquery.validate.js"></script>



 





<script type="text/javascript">
$(document).ready( function () {
$("#g_patient").addClass("active");
document.title = 'Modifier Patient';

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

    }, "type required");
$("#add-form").validate({
submitHandler: function(form) {
$.ajax({
 url: 'actions/patient/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>Insertion avec succès </strong> </div>')  ;
              $("#add-form")[0].reset();
               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",
               unite: "selectcheck"


                               },
                messages: {
                        nom: "Entrez le nom ",
                        nomar: "Entrez le nom en arab",
                       unite: "sélectionnez l'unité",                           },
                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");  } ?>