<?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_demande_conge.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">Liste de demande des conges d&eacute;j&agrave; enregistr&eacute;</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">

                               <!-- FILTRE -->

             <!-- <form method="POST" action="<?=base_url('conge/Demande_Conge/listing')?>" id="myform">
                <div class="form-row">
                  <div class="form-group col-md-6">
                    <label for="inputEmail4">Statut congé</label>
                       <select class="custom-select" name="STATUS_CONGE" id="STATUS_CONGE" onchange="get_info()">
                          <option>-- Select --</option>
                          <?php
                          foreach ($typeconge as $typeconge) { ?>

                           <option value="<?php echo $typeconge['STATUS_CONGE'] ?>" <?php echo  set_select('STATUS_CONGE', $typeconge['STATUS_CONGE']); ?> <?= ($STATUS_CONGE == $typeconge['STATUS_CONGE'])?"selected":"" ?> ><?php echo $typeconge['DESCRIPTION']?></option>
                         <?php }
                          ?>
                        </select>
                  </div>
                </div>
              </form> -->


                <table id="example1" class="table table-bordered table-striped table-hover">


                  <thead>
                  <tr>
                    <th>Nom</th>
                    <th>Exercice</th>
                    <th>Date demande</th>
                    <th>Type</th>
                    <!-- <th>Niveau</th> -->
                    <th>Status</th>
                    <th>Aff.</th>
                    <th>Nb Jours</th>
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

                  <?php
                  // $status_accorde = array(12,14);
                  // $status_demande = array(1,4,7);
                  // $status_a_verifier = array(2,5,8);
                  $status_accorde = array(11);
                  $status_demande = array(1,4,7,2,5,8,13);
                  $status_a_verifier = array();
                  $status_refu = array(0,3,6,9,12,14);
                  
                  $type_message = $this->Model->getRequete('SELECT * FROM `conge_type_message`');
                  $tmessages ='<option value=""> Selectionner </option>';
                  foreach ($type_message as $tmessage) {
                    $tmessages .='<option value="'.$tmessage['ID_TYPE_MESSAGE'].'">'.$tmessage['DESCRIPTION'].'</option>';
                  }
                  
                  $type_dest = $this->Model->getRequete('SELECT * FROM `conge_type_destinataire`');
                  $tdestinataire ='<option value=""> Selectionner </option>';
                  foreach ($type_dest as $typedest) {
                    $tdestinataire .='<option value="'.$typedest['ID_TYPE_DESTINATAIRE'].'">'.$typedest['DESCRIPTION'].'</option>';
                  }
                    foreach ($resultat as $key) 
                    {


                      $conge = $this->Model->getRequeteOne('SELECT config_exercice.DESCRIPTION AS EXERCICE, conge_demande_conge.DATE_DEMANDE, conge_demande_conge.DATE_SYSTEME_DEMANDE, conge_status_conge.DESCRIPTION AS STATUS_CONGE, conge_demande_conge.STATUS_CONGE AS STATUS_CONGES, conge_demande_conge.NB_JOURS_DEMANDE, conge_demande_conge.NB_JOURS_ACCORDE, conge_demande_conge.DATE_DERNIER_REPOSE, config_type_conge.NOM_CONGE, conge_demande_conge.DATE_DEBUT_CONGE_DEMANDE, conge_demande_conge.DATE_FIN_CONGE_DEMANDE, conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, conge_demande_conge.DATE_FIN_CONGE_ACCORDE FROM conge_demande_conge JOIN config_exercice ON config_exercice.ID_EXERCICE = conge_demande_conge.ID_EXERCICE JOIN conge_status_conge ON conge_status_conge.STATUS_CONGE = conge_demande_conge.STATUS_CONGE JOIN config_type_conge ON config_type_conge.ID_TYPE_CONGE = conge_demande_conge.ID_TYPE_CONGE WHERE 1 AND conge_demande_conge.ID_DEMANDE_CONGE = '.$key['ID_DEMANDE_CONGE'].'');
                     
                                             if ($key['STATUS_CONGES'] == 0 && $key['ID_EMPLOYE'] == $this->session->userdata('SOCAR_ID_USER')) {
                                                $buttons = "<button type='submit' class='btn btn-primary'>Reaccepter le conger par rapport au modification</button>";
                                                $fxct ="conge/Demande_Conge/reaccepter_conge";
                                                $inputs="<input type='hidden' name='ID_DEMANDE_CONGE' value='".$key['ID_DEMANDE_CONGE']."'>
                                                <div class='form-group col-lg-12'>
                                                      <label for='exampleInputPassword1'>Commentaire</label>
                                                      <textarea class='form-control' name='COMMENTAIRE' id='COMMENTAIRE' rows='3'></textarea>
                                                </div>"; 
                                              }
                                              elseif ($key['STATUS_CONGES'] != 0 && $key['ID_EMPLOYE'] == $this->session->userdata('SOCAR_ID_USER')) {
                                                $buttons = "<button type='submit' class='btn btn-danger'>Refuser le conger par rapport au modification </button>";
                                                $fxct ="conge/Demande_Conge/refuser_conge";    
                                                $inputs="<input type='hidden' name='ID_DEMANDE_CONGE' value='".$key['ID_DEMANDE_CONGE']."'>
                                                <div class='form-group col-lg-12'>
                                                      <label for='exampleInputPassword1'>Commentaire</label>
                                                      <textarea class='form-control' name='COMMENTAIRE' id='COMMENTAIRE' rows='3'></textarea>
                                                </div>";                    
                                              }
                                              else{
                                                $buttons = "";
                                                $fxct ="";  
                                                $inputs="";
                                              }
                                              if (in_array($key['STATUS_CONGES'], $status_accorde)) {
                                                $back_collors="bg-primary";                   
                                              }
                                              elseif (in_array($key['STATUS_CONGES'], $status_demande)) {
                                                $back_collors="bg-info";                   
                                              }
                                              elseif (in_array($key['STATUS_CONGES'], $status_a_verifier)) {
                                                $back_collors="bg-info";   
                                              }
                                              // elseif ($key['STATUS_CONGES'] == 8) {
                                              // $back_collors="bg-primary";
                                              // }
                                              // elseif ($key['STATUS_CONGES'] == 10) {
                                              // $back_collors="bg-primary"; 
                                              // }
                                              // elseif ($key['STATUS_CONGES'] == 11) {
                                              // $back_collors="bg-primary"; 
                                              // }
                                              // elseif ($key['STATUS_CONGES'] == 13) {
                                              // $back_collors="bg-primary"; 
                                              // }
                                              // elseif ($key['STATUS_CONGES'] == 14) {
                                              // $back_collors="bg-primary";
                                              // }
                                              else{
                                                $back_collors="bg-danger";
                                              }
                      // echo "The ".$key['STATUS_CONGES']." - ".$back_collors." element is in the array<br>";
                      // <td>".$key['NIVEAU']."</td>
                     echo "<tr>
                     <td>".$key['NOM']." ".$key['PRENOM']."</td>
                     <td>".$key['EXERCICE']."</td>
                     <td>".$key['DATE_DEMANDE']."</td>
                     <td>".$key['TYPE_CONGE']."</td>
                     
                     <td><div class='".$back_collors." color-palette'> ".$key['STATUS_CONGE']."</div>
                      
            <div class='modal fade' id='modaldetails0_".$key['ID_DEMANDE_CONGE']."'>
        <div class='modal-dialog modal-lg'>
          <div class='modal-content'>
            <div class='modal-header'>
              <h4 class='modal-title'>Details</h4>
              <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
              </button>
            </div>
            <form id='FormData' action='".base_url()."".$fxct."' method='POST' enctype='multipart/form-data'>
            <div class='modal-body'>
            
            <div class='form-group col-lg-12'>
              <table class='table'>
                <tr>
                  <td>Exercice</td>
                  <td><b>".$conge['EXERCICE']."</td>
                  <td>Type Conge</td>
                  <td><b>".$conge['NOM_CONGE']."</td>
                </tr>
                <tr>
                  <td>Date de demande</td>
                  <td><b>".$conge['DATE_SYSTEME_DEMANDE']."</td>
                  <td>Dernier reponse</td>
                  <td><b>".$conge['DATE_DERNIER_REPOSE']."</td>
                </tr>
                <tr>
                  <td>Date demandée</td>
                  <td><b>".$conge['DATE_DEBUT_CONGE_DEMANDE']." - ".$conge['DATE_FIN_CONGE_DEMANDE']."</td>
                  <td>Nb Jours</td>
                  <td><b>".$conge['NB_JOURS_DEMANDE']."</td>
                </tr>
                <tr>
                  <td>Date accordée</td>
                  <td><b>".$conge['DATE_DEBUT_CONGE_ACCORDE']." - ".$conge['DATE_FIN_CONGE_ACCORDE']."</td>
                  <td>Nb Jours</td>
                  <td><b>".$conge['NB_JOURS_ACCORDE']."</td>
                </tr>
                <tr>
                  <td>Status</td>
                  <td colspan='3'><b>".$conge['STATUS_CONGE']."</td>
                </tr>
              </table>
              </div>
              ".$inputs."
              
            </div>
            
            <div class='modal-footer justify-content-between'>
              <button type='button' class='btn btn-default' data-dismiss='modal'>Fermer</button>

              ".$buttons."

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

      <div class='modal fade' id='modalmessage_".$key['ID_DEMANDE_CONGE']."'>
        <div class='modal-dialog modal-lg'>
          <div class='modal-content'>
            <div class='modal-header'>
              <h4 class='modal-title'>Details</h4>
              <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
              </button>
            </div>
            <form id='FormData' action='".base_url()."conge/Demande_Conge/message_conge' method='POST' enctype='multipart/form-data'>
            <div class='modal-body row'>
            
            <div class='form-group col-lg-12'>
              <table class='table'>
                <tr>
                  <td>Type Conge</td>
                  <td><b>".$conge['NOM_CONGE']."</td>
                  <td>Status</td>
                  <td><b>".$conge['STATUS_CONGE']."</td>
                </tr>
                <tr>
                  <td>Date de demande</td>
                  <td><b>".$conge['DATE_SYSTEME_DEMANDE']."</td>
                  <td>Dernier réponse</td>
                  <td><b>".$conge['DATE_DERNIER_REPOSE']."</td>
                </tr>
                <tr>
                  <td>Date demandée</td>
                  <td><b>".$conge['DATE_DEBUT_CONGE_DEMANDE']." - ".$conge['DATE_FIN_CONGE_DEMANDE']."</td>
                  <td>Nb Jours</td>
                  <td><b>".$conge['NB_JOURS_DEMANDE']."</td>
                </tr>
                <tr>
                  <td>Date accordée</td>
                  <td><b>".$conge['DATE_DEBUT_CONGE_ACCORDE']." - ".$conge['DATE_FIN_CONGE_ACCORDE']."</td>
                  <td>Nb Jours</td>
                  <td><b>".$conge['NB_JOURS_ACCORDE']."</td>
                </tr>
              </table>
              </div>
              
              <input type='hidden' name='ID_DEMANDE_CONGE' value='".$key['ID_DEMANDE_CONGE']."'>

              <div class='form-group col-lg-6'>
                   <label for='exampleInputPassword1'>Type message</label>
                    <select class='form-control' name='ID_TYPE_MESSAGE' id='ID_TYPE_MESSAGE'>
                     ".$tmessages."
                    </select>
              </div>
              <div class='form-group col-lg-6'>
                   <label for='exampleInputPassword1'>Destinataire</label>
                   <select class='form-control' name='ID_TYPE_DESTINATAIRE' id='ID_TYPE_DESTINATAIRE'>
                     ".$tdestinataire."
                    </select>
              </div>

              <div class='form-group col-lg-12'>
                   <label for='exampleInputPassword1'>Message</label>
                   <textarea class='form-control' name='CORPS_MESSAGE' id='CORPS_MESSAGE' rows='3'></textarea>
              </div>
              
            </div>
            
            <div class='modal-footer justify-content-between'>
              <button type='button' class='btn btn-default' data-dismiss='modal'>Fermer</button>

              <button type='submit' class='btn btn-primary'>Envoyer</button>

            </div>
            </form>
          </div>
        </div>
      </div>
                     </td>
                     <td>
                     <div class='modal fade' id='affectation".$key['ID_DEMANDE_CONGE']."'>
        <div class='modal-dialog'>
          <div class='modal-content'>
            <div class='modal-header'>
              <h4 class='modal-title'>Affectation de ".$key['NOM']." ".$key['PRENOM']."</h4>
              <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
              </button>
            </div>
            <div class='modal-body'>
              <table class='table'>
                     <tr>
                      <td>Direction</td>
                      <td>".$key['DIRECTION']."</td>
                     </tr>
                     <tr>
                      <td>Service</td>
                      <td>".$key['SERVICE']."</td>
                     </tr>
                     <tr>
                      <td>Section</td>
                      <td>".$key['DEPARTEMENT']."</td>
                     </tr>
                     
              </table>
            </div>
            <div class='modal-footer justify-content-between'>
              <button type='button' class='btn btn-primary' data-dismiss='modal'>Fermer</button>
            </div>
          </div>
        </div>
      </div>
                    <button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#affectation".$key['ID_DEMANDE_CONGE']."'>
                  <i class='fas fa-building'></i>
                </button>
                     </td>
                     <td>".$key['NB_JOURS_DEMANDE']."</td>
                     <td><div class='dropdown '>
                                       <a class='btn btn-primary btn-sm dropdown-toggle' data-toggle='dropdown'>Actions
                                       <span class='caret'></span></a>
                                       <ul class='dropdown-menu dropdown-menu-right'>";

                                       echo'<li><a class="dropdown-item" data-toggle="modal" data-target="#modaldetails0_'.$key['ID_DEMANDE_CONGE'].'" href="#"> Details </a> </li>';

                                       

                                       
                                      

                                       // if ($this->session->userdata('SOCAR_ID_USER') == 0) {
                                        // $employe= $this->Model->getRequeteOne(" SELECT rh_employe_affectation.ID_DIRECTION, organigramme_direction.DESCRIPTION AS DIRECTION, rh_employe_affectation.ID_RESPONSABILITE, rh_employe_affectation.ID_SERVICE, organigramme_service.DESCRIPTION AS DEPARTEMENT, rh_employe_affectation.ID_SECTION, organigramme_section.DESCRIPTION AS SERVICE, rh_employe.NOM, rh_employe.PRENOM , rh_employe.ID_EMPLOYE FROM rh_employe_affectation JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = rh_employe_affectation.ID_DIRECTION LEFT JOIN organigramme_service ON organigramme_service.ID_SERVICE = rh_employe_affectation.ID_SERVICE LEFT JOIN organigramme_section ON organigramme_section.ID_SECTION = rh_employe_affectation.ID_SECTION JOIN rh_employe ON rh_employe.ID_EMPLOYE = rh_employe_affectation.ID_EMPLOYE WHERE rh_employe_affectation.STATUS_AFFECTATION = 1 AND rh_employe_affectation.ID_EMPLOYE = ".$this->session->userdata('SOCAR_ID_USER')." ");
                                        // if ($employe['ID_RESPONSABILITE']!= 3 && $key['STATUS_CONGES']!= 14) {
                                          echo "<li><a class='dropdown-item' href='".base_url("conge/Demande_Conge/traitement/".$key['ID_DEMANDE_CONGE'])."'> Traiter </a> </li>";

                                          if ($key['STATUS_CONGES']== 11 || $key['REFUS'] == 1 ) {
                                          echo "<li><a class='dropdown-item' href='".base_url("pdf/Pdf_Conge/index/".$key['ID_DEMANDE_CONGE'])."' target='_blank'> PDF de la demande </a> </li>";
                                        }
                                        // }

                                        if ($key['STATUS_CONGES'] == 1 || $key['STATUS_CONGES'] == 4 || $key['STATUS_CONGES'] == 7 && $key['ID_EMPLOYE'] == $employe['ID_EMPLOYE']) {
                                        echo" <li><a class='dropdown-item' href='".base_url("conge/Demande_Conge/index_update/".$key['ID_DEMANDE_CONGE'])."'> Modifier </a> </li>";
                                       }

                                       // if ($key['ID_EMPLOYE'] == $this->session->userdata('SOCAR_ID_USER')) {
                                                
                                                // echo'<li><a class="dropdown-item" data-toggle="modal" data-target="#modalmessage_'.$key['ID_DEMANDE_CONGE'].'" href="#"> Message </a> </li>';
                                                
                                              // }

                                            

                                     // }

                                     
                                       
                                       echo "</ul>
                                     </div></td>
                   </tr>";
           
                     
                                     
                  // $tabledata[]=$chambr;
                }
                  ?>
                  
                  </tfoot>
                </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,"ordering": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper  .col-md-6:eq(0)');
   
  });
</script>
</body>
</html>

<script>


         function get_info() {
       
       myform.action= myform.action;
        myform.submit();
      } 
  

</script>


<script>

 
  function excels() {
  // window.open(''+base_url('Traitement/excels')+'', '_blank');
  // var dateUne = $('#dateUne').val();
  // alert(dateUne);
  // var dateDeux = $('#dateDeux').val();
  // alert(dateDeux);
  // var IS_SEND = $('#IS_SEND').val();
  var previewpdf = window.open('<?php echo base_url(); ?>conge/Demande_Conge/excels/', '_blank', '');
    pageImp.print(); 
}
     </script>