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


 ?>
 <h4 class="title"><i class="fa fa-arrow-right"></i> Ajouter destination</h4>
 	<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="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>destination </label>
                      <input type="text" required="required"  class="form-control"  id="nom" name="nom">
                      </div>
                      </div> 
                    

                     <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>destination AR</label>
                      <input type="text" required="required"  class="form-control"  id="nomar" name="nomar">
                      </div>
                      </div> 
                      
                       <div class="form-group">
                      <div class="col-sm-6 col-xs-12">
                      <label>Wilaya</label>
        
                      <select name="wialya" class="form-control" >
                         
                        <option value="0">Wilaya</option>
                        <?php
                       $reqq= "SELECT * FROM wilayas";
                        $q_wialya  = mysqli_query($con,$reqq);
                         while ($wialya = mysqli_fetch_array($q_wialya)) {
                        ?>
                         <option value="<?php echo $wialya['C_WILAYA'] ?>" ><?php echo $wialya['L_WILAYA_F'] ?></option>
                      <?php  }  ?>
                                          
                        
                      </select>
                      </div>
                      </div> 

              <div class="form-group">
                         <div class="col-sm-6 col-xs-12">
              <input type="submit" id="Ajouter" class="btn btn-primary btn-block" value="Ajouter">
                     </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_destination").addClass("active");
document.title = 'Ajouter destination';

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

    }, "type required");
$("#add-form").validate({
submitHandler: function(form) {
$.ajax({
 url: 'actions/destination/ajouter.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",
               wialya: "selectcheck"


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