<?php
include VIEWPATH.'includes/new_header.php';
?>
<body class="hold-transition sidebar-mini">
  <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">
        <div class="container-fluid">
          <div class="row">
            <div class="col-12">
              
              <!-- /.card -->

              <div class="card card-primary">
                <div class="card-header">
                  <h3 class="card-title">Client</h3>
                </div>
                <!-- /.card-header -->
                <div class="card-body">
                
                  <table id="example1" class="table table-responsive table-bordered table-hover table-striped" style="width:100%">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Nom</th>
                        <th>Type</th>
                        <th>Telephone</th>
                        <th>Mail</th>
                        <th>RC</th>
                        <th>NIF</th>
                        <th>Adresse</th>
                        <th>Localisation</th>
                        <th>Type</th>
                        <th>Status</th>
                        <th></th>
                      </tr>   
                    </thead>
                    <tbody>
                      <?php

                      $resultat=$this->Model->getRequete('SELECT ID_CLIENT, NUMERO_CLIENT, client_type.DESCRIPTION TYPE_CLIENT,standard_status.DESCRIPTION,provinces.PROVINCE_NAME,communes.commune_name,zones.ZONE_NAME, NOM, PRENOM, TELEPHONE, MAIL, client_client.ID_STATUS, syst_status.DESCRIPTION AS STATUS_SYST, RC, NIF, ADRESSE FROM `client_client` JOIN client_type ON client_type.ID_CLIENT_TYPE = client_client.ID_CLIENT_TYPE JOIN syst_status ON syst_status.ID_STATUS = client_client.ID_STATUS JOIN provinces ON provinces.PROVINCE_ID=client_client.PROVINCE_ID JOIN communes ON communes.commune_id=client_client.COMMUNE_ID JOIN zones ON zones.ZONE_ID = client_client.ZONE_ID  JOIN collines ON collines.colline_id=client_client.COLLINE_ID JOIN standard_status ON standard_status.ID_STANDARD=client_client.ID_STANDARD');

                      foreach ($resultat as $key) 
                      {
                        
                        if ($key['ID_STATUS']==1) {
                          $links = '<li><a class="nav-link" href="'.base_url('donnee/Client/desactiver/'.$key['ID_CLIENT']).'">Desactiver</a></li>';
                        }
                        else{
                          $links = '<li><a class="nav-link" href="'.base_url('donnee/Client/reactiver/'.$key['ID_CLIENT']).'">Reactiver</a></li>';
                        }
                        
                        
                        echo "<tr>
                        <td>".$key['NUMERO_CLIENT']."</td>
                        <td>".$key['NOM']." ".$key['PRENOM']."</td>
                        <td>".$key['TYPE_CLIENT']."</td>
                        <td>".$key['TELEPHONE']."</td>
                        <td>".$key['MAIL']."</td>
                        <td>".$key['RC']."</td>
                        <td>".$key['NIF']."</td>
                        <td>".$key['ADRESSE']."</td>
                        <td>".$key['commune_name']."-".$key['ZONE_NAME']."</td>
                        <td>".$key['DESCRIPTION']."</td>
                        <td>".$key['STATUS_SYST']."</td>
                        ";

                        $modadcontent ='<div class="dropdown">
                        <button id="dLabel" class="btn btn-primary btn-xs" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Action
                        <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dLabel">
                        <li><a class="nav-link" href="'.base_url('donnee/Client/index_update/'.$key['ID_CLIENT']).'">Modification</a></li>
                        '.$links.'
                        </ul>
                        </div>';
                        echo "<td>".$modadcontent."</td></tr>";
                      }
                      ?>
                      
                    </tbody>
                    
                  </table>
                </div>
                <!-- /.card-body -->
              </div>
              <!-- /.card -->
            </div>
            <!-- /.col -->
          </div>
          <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

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

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
      <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->
  </div>

  <!-- ./wrapper -->
  <?php
  include VIEWPATH.'includes/new_script.php';
  ?>

  <!-- Page specific script -->
  <script>
    $(function () {
      $("#example1").DataTable({
        "responsive": true, "lengthChange": false, "autoWidth": false,
        "buttons": ["excel", "pdf", "print", "colvis"]
      }).buttons().container().appendTo('#example1_wrapper  .col-md-6:eq(0)');
      
    });
  </script>

  <script type="text/javascript">
    function changelist() {
      document.getElementById("myForm").submit();
    }

    $('#reservation').daterangepicker({

      locale: {
        format: 'DD/MM/YYYY'
      }
    })
    $('.select').select2();

  </script>
</body>
</html>
