<?php
include VIEWPATH.'includes/new_header.php';
?>

<body class="hold-transition sidebar-mini">
  <!-- Site wrapper -->
  <div class="wrapper">
    <?php
    include VIEWPATH.'includes/new_top_menu.php';
    include VIEWPATH.'includes/new_menu_principal.php';
    ?>

    

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <?php 
      include 'includes/menu_client.php';
      ?>

      <!-- Main content -->
      <section class="content">

        <!-- Default box -->
        <div class="card">







          



          <?php 
          if(!empty($this->session->flashdata('message')))
           echo $this->session->flashdata('message');
         ?>



         
         <div class="card card-primary">
          <div class="card-header">
            <h3 class="card-title">Enregistrement du client</h3>
          </div>
          <!-- /.card-header -->
          <!-- form start -->
          <form role="form" action="<?=base_url('donnee/Client/update')?>" enctype="multipart/form-data" method="POST">
            <div class="card-body row">
              
              
              
              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Numero Client <spam class="text-danger">*</spam></label>
                <input type="text" class="form-control" id="NUMERO_CLIENT" name="NUMERO_CLIENT" readonly="readonly" value="<?php echo $NUMERO_CLIENT;?>">
                <input type="hidden" class="form-control" id="ID_CLIENT" name="ID_CLIENT" value="<?php echo $dataclient['ID_CLIENT'];?>">
                <?php echo form_error('NUMERO_CLIENT', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Type client<spam class="text-danger">*</spam> </label>
                <select class="custom-select" name="ID_CLIENT_TYPE" id="ID_CLIENT_TYPE">
                  <option value="">-- Select --</option>
                  
                  <?php
                  foreach ($typeclient as $tclient) {
                    if ($dataclient['ID_CLIENT_TYPE'] == $tclient['ID_CLIENT_TYPE']) {
                      echo"<option value='".$tclient['ID_CLIENT_TYPE']."' selected>".$tclient['DESCRIPTION']."</option>";
                    }
                    else{
                      echo"<option value='".$tclient['ID_CLIENT_TYPE']."'>".$tclient['DESCRIPTION']."</option>";
                    }
                    
                    
                  }
                  ?>
                </select>
                
                <?php echo form_error('ID_CLIENT_TYPE', '<div class="text-danger">', '</div>'); ?>
              </div>

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Nom <spam class="text-danger">*</spam></label>
                <input type="text" class="form-control" id="NOM" name="NOM" value="<?php echo $dataclient['NOM']?>">
                <?php echo form_error('NOM', '<div class="text-danger">', '</div>'); ?>
              </div> 


              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Pr&eacute;nom </label>
                <input type="text" class="form-control" id="PRENOM" name="PRENOM" value="<?php echo $dataclient['PRENOM']?>">
                <?php echo form_error('PRENOM', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">T&eacute;l&eacute;phone <spam class="text-danger">*</spam></label>
                <input type="text" class="form-control" id="TELEPHONE" name="TELEPHONE" value="<?php echo $dataclient['TELEPHONE']?>">
                <?php echo form_error('TELEPHONE', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Mail </label>
                <input type="text" class="form-control" id="MAIL" name="MAIL" value="<?php echo $dataclient['MAIL']?>">
                <?php echo form_error('MAIL', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">RC </label>
                <input type="text" class="form-control" id="RC" name="RC" value="<?php echo $dataclient['RC']?>">
                <?php echo form_error('RC', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">NIF </label>
                <input type="text" class="form-control" id="NIF" name="NIF" value="<?php echo $dataclient['NIF']?>">
                <?php echo form_error('NIF', '<div class="text-danger">', '</div>'); ?>
              </div> 

              <div class="form-group col-lg-6">
                <label for="exampleInputEmail1">Provinces<spam class="text-danger">*</spam> </label>
                <select class="form-control" onchange="get_commune(this.value)"
                name="province_perso_ref" id="province_perso_ref">
                <option value="">-</option>

                <?php

                foreach ($provinces as $value) {

                  if ($value['PROVINCE_ID'] == set_value('province_perso_ref',$dataclient['PROVINCE_ID'])) {

                    echo "<option value='" . $value['PROVINCE_ID'] . "' selected='selected'>" .  strtoupper($value['PROVINCE_NAME'] ). "</option>";
                  } else {
                    echo "<option value='" . $value['PROVINCE_ID'] . "'>" . strtoupper( $value['PROVINCE_NAME']) . "</option>";
                  }
                }
                ?>
              </select>
              
              <?php echo form_error('province_perso_ref', '<div class="text-danger">', '</div>'); ?>
            </div>
            <div class="form-group col-lg-6">
              <label for="exampleInputEmail1">Communes <spam class="text-danger">*</spam> </label>
              <select class="form-control" onchange="get_zones(this.value)"
              name="commune_perso_ref" id="commune_perso_ref">
              <option value="">-</option>
              <?php

              foreach ($communes as $value) {

                if ($value['commune_id'] == set_value('commune_perso_ref',$dataclient['COMMUNE_ID'])) {

                  echo "<option value='" . $value['commune_id'] . "' selected='selected'>" .  strtoupper($value['commune_name'] ). "</option>";
                } else {
                  echo "<option value='" . $value['commune_id'] . "'>" . strtoupper( $value['commune_name']) . "</option>";
                }
              }
              ?>
            </select>
            
            <?php echo form_error('commune_perso_ref', '<div class="text-danger">', '</div>'); ?>
          </div>
          <div class="form-group col-lg-6">
            <label for="exampleInputEmail1">Zones <spam class="text-danger">*</spam> </label>
            <select class="form-control" onchange="get_collines(this.value)"
            name="zone_perso_ref" id="zone_perso_ref">
            <option value="">-</option>
            <?php

            foreach ($zones as $value) {

              if ($value['ZONE_ID'] == set_value('zone_perso_ref',$dataclient['ZONE_ID'])) {

                echo "<option value='" . $value['ZONE_ID'] . "' selected='selected'>" .  strtoupper($value['ZONE_NAME'] ). "</option>";
              } else {
                echo "<option value='" . $value['ZONE_ID'] . "'>" . strtoupper( $value['ZONE_NAME']) . "</option>";
              }
            }
            ?>
          </select>
          <?php echo form_error('zone_perso_ref', '<div class="text-danger">', '</div>'); ?>
        </div>
        <div class="form-group col-lg-6">
          <label for="exampleInputEmail1">Collines <spam class="text-danger">*</spam> </label>
          <select class="form-control" name="colline_perso_ref"
          id="colline_perso_ref">
          <option value="">-</option>
          <?php

          foreach ($collines as $value) {

            if ($value['colline_id'] == set_value('colline_perso_ref',$dataclient['COLLINE_ID'])) {

              echo "<option value='" . $value['colline_id'] . "' selected='selected'>" .  strtoupper($value['colline'] ). "</option>";
            } else {
              echo "<option value='" . $value['colline_id'] . "'>" . strtoupper( $value['colline']) . "</option>";
            }
          }
          ?>
        </select>
        <?php echo form_error('colline_perso_ref', '<div class="text-danger">', '</div>'); ?>
      </div>
      <div class="form-group col-lg-6">
        <label for="exampleInputEmail1">Type de prix <spam class="text-danger">*</spam> </label>
        <select class="custom-select" name="ID_STANDARD" id="ID_STANDARD">
          <option value="">-- Select --</option>
          
          <?php
          $verif = $this->Model->getRequete('SELECT * FROM `standard_status`');
          
          foreach ($verif as $value) {
            if ($value['ID_STANDARD'] == set_value('ID_STANDARD',$dataclient['ID_STANDARD'])) {

              echo "<option value='" . $value['ID_STANDARD'] . "' selected='selected'>" .  strtoupper($value['DESCRIPTION'] ). "</option>";
            } else {
              echo "<option value='" . $value['ID_STANDARD'] . "'>" . strtoupper( $value['DESCRIPTION']) . "</option>";
            }
          }
          ?>
        </select>
        
      </div>
      <div class="form-group col-lg-6">
        <label for="exampleInputEmail1">Adresse <spam class="text-danger">*</spam></label>
        <textarea class="form-control" name="ADRESSE" id="ADRESSE" rows="3"><?php echo $dataclient['ADRESSE']?></textarea>

        <?php echo form_error('ADRESSE', '<div class="text-danger">', '</div>'); ?>
      </div> 

      

      
      
      
      
      
      
      

      

      

      
      
    </div>
    <!-- /.card-body -->

    <div class="card-footer">
      <button type="submit" class="btn btn-primary btn-block">Enregistrer</button>
    </div>
  </form>
</div>


<!-- /.card-body -->
        <!-- <div class="card-footer">
          Footer
        </div> -->
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
  include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<?php
include VIEWPATH.'includes/new_script.php';
?>

<script>
  $(document).ready(function(){ 
    $('#message').delay(5000).hide('slow');
  });



  function get_commune(prov){
    var form= new FormData();
    form.append("prov",prov);
    $.ajax({
      url: "<?php echo base_url('voiture/Garage/get_commune/');?>"+prov,
      type: "POST",
      data: form,
      processData: false,  
      contentType: false,
      success: function(data){
        $('#COMMUNE_ID').html(data);
        
      }
    }); 

  }

  $('#sandbox-container input').datepicker({
  });
</script>





<script>
// la fonction pour affiche le commune selon la province selectionnee
function get_commune() {
  var province_perso_ref = $('#province_perso_ref').val();

  $.post("<?= base_url('donnee/Client/get_commune') ?>", {
    province_perso_ref: province_perso_ref
  }, function(data) {
    commune_perso_ref.innerhtml = data;
    $('#commune_perso_ref').html(data);
  })
}


// la fonction pour affiche les zones selon le commune selectionnee

function get_zones() {
  var commune_perso_ref = $('#commune_perso_ref').val();
  $.post("<?= base_url('donnee/Client/get_zones') ?>", {
    commune_perso_ref: commune_perso_ref
  }, function(data) {
    zone_perso_ref.innerhtml = data;
    $('#zone_perso_ref').html(data);
  })
}


// la fonction pour affiche les collines selon le zone selectionnee
function get_collines() {
  var zone_perso_ref = $('#zone_perso_ref').val();
  $.post("<?= base_url('donnee/Client/get_collines') ?>", {
    zone_perso_ref: zone_perso_ref
  }, function(data) {
    colline_perso_ref.innerhtml = data;
    $('#colline_perso_ref').html(data);
  })
}

</script>

</body>
</html>
