<?php
include VIEWPATH.'includes/new_header.php';
?>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/sweetalert2@10.10.1/dist/sweetalert2.min.css'>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10.10.1/dist/sweetalert2.all.min.js"></script>
<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_demande_doc.php';
  ?> -->

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

    <!-- Default box -->
    <div class="card">
    
    <div class="card card-defaut">
            <div class="card-header">
             <div class="col-12">
              <div style="" class="card">
                <div class="card-header">
                 <form>

                        <?php
               
                        if((!empty($actions) && !empty($statuts)) && $this->session->userdata('SOCAR_ID_USER')==$derniertraitement['USER_ID'])
                        {
 
                          ?>
                        
                            <div class="dropdown">
                              <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Traiter la demande</button>
                              <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                <?php
                                foreach($actions as $key)
                                {
                                  ?>
                                  <a class="dropdown-item" href="#" onclick="action_comment(<?=$key['ACTION_DOC_ID']?>)">
                                    <?=$key['DESC_ACTION']?></a>
                                  <?php
                                }
                                ?>
                              <a class="dropdown-item" href="#" onclick="action_comment(0)">Réaffecter</a>
                              </div>
                            </div>
                        
                          <?php
                        }

                        if((!empty($actions) && !empty($statuts)) && $this->session->userdata('SOCAR_ID_USER')!=$derniertraitement['USER_ID'])
                        {

                          ?>
                        
                            <div class="dropdown">
                              <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Traiter la demande</button>
                              <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                <?php
                                foreach($actions as $key)
                                {
                                  ?>
                                  <a class="dropdown-item" href="#" onclick="action_comment(<?=$key['ACTION_DOC_ID']?>)">
                                    <?=$key['DESC_ACTION']?></a>
                                  <?php
                                }
                                ?>
                             
                              </div>
                            </div>
                        
                          <?php
                        }

                       if((empty($actions) || empty($statuts)) && $this->session->userdata('SOCAR_ID_USER')==$derniertraitement['USER_ID'])
                        {

                          ?>
                        
                            <div class="dropdown">
                              <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Traiter la demande</button>
                              <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                              <a class="dropdown-item" href="#" onclick="action_comment(0)">Réaffecter</a>
                              </div>
                            </div>
                        
                          <?php
                        }
                        ?>
                      </form>
                 
                </div>
  
              </div>
            </div>
            <!-- /.card-header -->
            <!-- form start -->




          <div class="row" style="">
<!--             <div class="col-md-2">
              <?php
              $url_image='https://jagsolution.mooo.com/document_system_management/uploads/images/av.JPG';
              ?>
              <img src="<?=$url_image?>" style="width:100%; height: 100%;">
            </div> -->
            <div class="col-md-12">
              <?php
              $identification=$requerant['NOM'].' '.$requerant['PRENOM'];
              ?>
              <table class="table table-striped table-responsive" style="margin-top: 0px">
                <thead class="thead-dark"><th>POLICE</th><th>MATRICULE</th><th>IDENTIFICATION</th><th>TELEPHONE</th><th>EMAIL</th><th>ETAPE</th><th>NIVEAU</th><th>DATE</th></thead>
                <tbody><td><?=$requerant['NUM_POLICE']?></td><td><?=$requerant['MATRICULE']?></td><td><?=$identification?></td><td><?=$requerant['TEL']?></td><td><?=$requerant['EMAIL']?></td><td><?=$requerant['DESC_STATUT']?></td><td><?=$profiles['DESCRIPTION']?></td><td><?=date('d-m-Y',strtotime($requerant['DATE_DEMANDE']))?></td></tbody>
              </table>
            </div>

            <div class="col-12">
              <div style="box-shadow: rgba(100, 100, 111, 0.25) 0px 7px 29px 0px" class="card">
                <!-- <div class="card-header">
                  <div class="col-12" style="float:right;">
                    <input type="hidden" name="ID_DEMANDE" id="ID_DEMANDE" value="<?=$requerant['DEMANDE_ID']?>">
                    <h6 style=""><?=$requerant['DESC_TYPE']?> => <?=$requerant['DESC_STATUT']?></h6>
                  </div>
                </div> -->

                <div class="row">
                  <div class="col-12">
                    <ul class="nav nav-tabs" role="tablist">

                    <li class="nav-item">
                      <a class="nav-link active" href="#" id="dossiercomplet" data-toggle="tab" data-bs-target="#dossiercomplet-pane" role="tab" aria-controls="dossiercomplet-pane" onclick="getdossiercomplet();">
                        Dossier complet</a>
                      </li>


                      <!--<li class="nav-item">
                        <a class="nav-link active" href="#" id="detaildemande" data-toggle="tab" data-bs-target="#detaildemande-pane" role="tab" aria-controls="detaildemande-pane" onclick="getdetaildemande();">
                        Dossier</a>
                      </li> -->

                      <li class="nav-item">
                        <a class="nav-link" href="#" id="historiquedemande" data-toggle="tab" data-bs-target="#historiquedemande-pane" role="tab" aria-controls="historiquedemande-pane" onclick="gethistoriquedemande();">
                        Historique</a>
                      </li>
                    </ul>

                    <div class="container tab-pane">
                     
<!--                       <div class="col-12" id="div_detaildemande">
                        <table class="table table-striped">
                          <tbody>
                          <tr><td>Code</td><td>  <?=$requerant['DEMANDE_ID']?></td></tr>

                            <tr><td>Type document</td><td>  <?=$requerant['DESC_TYPE']?></td></tr>
                            
                            <tr><td>Document</td><td>  <i style="font-size: 80px" class="fa fa-file" aria-hidden="true" data-toggle="modal" data-target="#exampleModal4"></i></td></tr>
                          </tbody>
                        </table>
                      </div> -->

                      <div class="col-12" id="div_historiquedemande" style="display:none;">
                        <table id="historique" class="table table-striped" style="margin-top:-80px">
                          <thead>
                            <tr>
                              <th>#</th>
                              <th>DATE</th>
                              <th>ACTION</th> 
                              <th>COMMENTAIRE</th> 
                              <th>ETAPE</th>
                              <th>SERVICE</th>
                              <th>UTILISATEUR</th>
                              <th>DOCUMENT</th>
                            </tr>
                          </thead>
                          <tbody>
                          </tbody>
                        </table>
                      </div>


      <?php 
      $urlpass = base_url();
      $elementspas = explode("/", $urlpass);
      $nouveau_urlpass = null ;
        $indicepass = sizeof($elementspas);
        for ($i = 0; $i < ($indicepass - 2); $i++) {
            $nouveau_urlpass .=$elementspas[$i] . '/';
          }
      ?>

                      
                      <div class="col-12" id="div_dossiercomplet">

                       <button type="button" style="" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModalalldoc">
                        Voir tout les documents
                      </button>

                      <!-- Modal -->
                      <div class="modal fade" id="myModalalldoc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog modal-lg" role="document" style="max-width: 80%;">
                          <div class="modal-content">
                         
                            <div class="modal-body">
                              <?php
                        $ACTE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=1 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($ACTE) { ?>
                          <div class="text-center"><h6>Demande d'avance et Acte d'engagement</h6></div>

                        <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/acte/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">

                         <?php }

                         $ORDRE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=2 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($ORDRE) {

                          ?>
                          <div class="text-center"><h6>Ordre de reglément</h6></div>

                           <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/index/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">

                       <?php }

                       $QUITANCE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=4 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($QUITANCE) {

                          ?>
                          <div class="text-center"><h6>Quitance avance</h6></div>

                            <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/quitance/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">
                          <?php }



                          $FICHIER=$this->Model->getRequete('SELECT DEMANDE_HIST_FILE,doc_type_etape.DESCRIPTION,doc_type_etape.`FICHIER_ID`,FILE_PATH FROM `doc_demande_historique_fichier` JOIN doc_type_etape ON doc_type_etape.FICHIER_ID=doc_demande_historique_fichier.FICHIER_ID WHERE doc_type_etape.`FICHIER_ID` NOT IN (1,2,4) AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($FICHIER) {

                          foreach ($FICHIER as $key => $value) {
                         

                          ?>
                          <div class="text-center"><h6><?=$value['DESCRIPTION']?></h6></div>
                          <embed src="<?=$nouveau_urlpass?>/uploads/document_rapport/<?=$value['FILE_PATH']?>" type="application/pdf" scrolling="auto" height="500px" width="100%" >

                          <?php } } ?>
                              

                            </div>
                            <div class="modal-footer">
                              <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                            </div>
                          </div>
                        </div>
                      </div>
                        <table class="table table-striped table-condensed" style="">
                          <tbody>

                         <?php
                        $ACTE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=1 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($ACTE) { ?>

                        <tr><td>Demande d'avance et Acte d'engagement</td><td> <i style="font-size: 20px;margin-right: 80px" class="fa fa-file" aria-hidden="true" data-toggle="modal" data-target="#exampleModal4"></i></td></tr>

                         <?php }

                         $ORDRE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=2 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($ORDRE) {

                          ?>



                          <tr><td>Ordre de reglément</td><td>  
                           <i style="font-size: 20px" class="fa fa-file" aria-hidden="true" data-toggle="modal" data-target="#exampleModaldemandeavance"></i>
                         </td></tr>

                       <?php }

                       $QUITANCE=$this->Model->getRequeteOne('SELECT `FICHIER_ID` FROM `doc_demande_historique_fichier` WHERE `FICHIER_ID`=4 AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($QUITANCE) {

                          ?>

                            <tr><td>Quitance avance</td><td>  <i style="font-size: 20px" class="fa fa-file" aria-hidden="true" data-toggle="modal" data-target="#exampleModalquitance"></i></td></tr>
                          <?php }



                          $FICHIER=$this->Model->getRequete('SELECT DEMANDE_HIST_FILE,doc_type_etape.DESCRIPTION,doc_type_etape.`FICHIER_ID`,FILE_PATH FROM `doc_demande_historique_fichier` JOIN doc_type_etape ON doc_type_etape.FICHIER_ID=doc_demande_historique_fichier.FICHIER_ID WHERE doc_type_etape.`FICHIER_ID` NOT IN (1,2,4) AND `DEMANDE_ID`='.$requerant['DEMANDE_ID']);

                         if ($FICHIER) {

                          foreach ($FICHIER as $key => $value) {
                         

                          ?>

                            <tr><td><?=$value['DESCRIPTION']?></td><td>  <i style="font-size: 20px" class="fa fa-file" aria-hidden="true" data-toggle="modal" data-target="#exampleModale<?=$value['DEMANDE_HIST_FILE']?>"></i></td></tr>

                   <div id='exampleModale<?=$value['DEMANDE_HIST_FILE']?>' class='modal fade'>
                     <div class='modal-dialog modal-lg'>
                       <div class='modal-content'>
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                      <div class='modal-body'> 
                        
                        <embed src="<?=$nouveau_urlpass?>/uploads/document_rapport/<?=$value['FILE_PATH']?>" type="application/pdf" scrolling="auto" height="500px" width="100%" >
                          <!-- #toolbar=0&scrollbar=0 -->
                      </div>
                    </div>
                  </div>
                </div>

            <?php } } ?>





                          </tbody>
                        </table>
                       
                      </div>


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



  <div class="modal fade" id="addCommentaire">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h3 class="modal-title">Traitement de la demande</h3>
        </div>
        <form id="CommentaireForm" method="post" enctype="multipart/form-data">
          <div class="modal-body">
            <div class="row">
              <div class="col-md-12">
                <div class="col-md-12">
                  <input type="hidden" name="ID_DEMANDE" id="ID_DEMANDE" value="<?=$requerant['DEMANDE_ID']?>">
                  <input type="hidden" name="url_data" id="url_data">

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



            <div class="form-group col-md-4">
                          <label for="USER">
                           Voulez-vous faire une affectation manuelle ?
                             
                          </label>
                         <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input" id="switch1" onclick="showprofil()" <?php echo (!empty($AFFECTATION))? 'checked':'' ?>>
                        <label class="custom-control-label" for="switch1"></label>
                         </div>
            </div>

        <div class="form-row" id="affectation" <?php echo (!empty($AFFECTATION))? "style='display: block'":"style='display: none'" ?>>

<div class="form-group col-md-4">
<label for="service">Niveau de Service concerné <spam class="text-danger">*</spam></label>
                  <select class="custom-select" name="ID_NIVEAUX_ORGANIGRAMME" id="ID_NIVEAUX_ORGANIGRAMME" onchange="get_services(this)">
                        <option value="">-- Selectionner --</option>
                        <?php
                        foreach ($niveaus as $niveau) {
                         echo"<option value='".$niveau['ID_NIVEAUX_ORGANIGRAMME']."'>".$niveau['DESCRIPTION']."</option>";
                        }
                        ?>
                      </select>
                  <?php echo form_error('ID_NIVEAUX_ORGANIGRAMME', '<div class="text-danger">', '</div>'); ?>
 <!--    </div> -->
  </div>
 

    <div class="form-group col-md-4">
                  <label for="service">Service concerné <spam class="text-danger">*</spam></label>
                  <select class="custom-select" name="SERVICE" id="SERVICE">
      
                    </select>
                  <?php echo form_error('SERVICE', '<div class="text-danger">', '</div>'); ?>
    </div>
<div class="form-group col-md-4">
                  <label for="service">Etape<spam class="text-danger">*</spam></label>
                  <select class="custom-select" name="STATUT_DOC_ID" id="STATUT_DOC_ID">
                        <option>-- Selectionner --</option>
                        <?php
                        foreach ($doc_statut as $doc_statut) {
                         echo"<option value='".$doc_statut['STATUT_DOC_ID']."'>".$doc_statut['DESC_STATUT']."</option>";
                        }
                        ?>
                      </select>
                  <?php echo form_error('STATUT_DOC_ID', '<div class="text-danger">', '</div>'); ?>
    </div>

</div>




            <div class="row">
              <div class="col-md-12">
                <div class="col-md-12">
                 
                  <label style="font-weight: 900; color:#454545">Commentaire <font color="red">*</font></label>
                  <textarea name="COMMENTAIRE" id="COMMENTAIRE" class="form-control"></textarea>
                  <font id="errorCOMMENTAIRE" color="red"></font>
                </div>

              <?php if (!empty($check)) { ?>

                <div class="col-md-12">


            
          <!-- DEBUT CART -->
          <br>
        <table class="table table-bordered">
          <thead>
            <th> 
                <label for="exampleInputEmail1" class="col-lg-6 col-md-6 col-sm-6">Nom</label>
              </th>

              <th> 
                <label for="exampleInputEmail1" class="col-lg-6 col-md-6 col-sm-6">Fichier</label>
              </th>

          </thead>
          <tbody> 
           <td>
           <select class="form-control input-sm" name="FICHIER_ID" id="FICHIER_ID">
                                 <option value='0'>-- Selectionner --</option>
                                <?php

                                foreach ($doc_type as $doc_type)
                                 {
                                  echo"<option value='".$doc_type['FICHIER_ID']."'>".$doc_type['DESCRIPTION']."</option>";
                                 }
                                ?>
                             </select>
            <font color='red' id="errordescriptiondoc"></font> 
             
           </td>

          <td>   
          <input type="file" name="FILE_NAME" id="FILE_NAME" class="form-control">
          <font color='red' id="errorfile"></font>
         </td>

          <td>
            <button type="button" name="btnadd" class="btn btn-primary" id="btnadd">Ajouter</button>
           </td>
          </tbody>

          </table>


          <div id="divdata" style="margin-left: 0px;width: auto;"></div>


          <!-- FIN CART -->
                 

            <?php } ?>

              </div>
            </div>

          </div>

          
          <div class="modal-footer">
            <button type="button" class="btn btn-dark" data-dismiss="modal">Annuler</button>
            <a href="#" class="btn btn-primary" id="btnSaveCom" onclick="save_commentaire();">Traiter</a>
          </div>
        

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

  <?php 
      $urlpass = base_url();
      $elementspas = explode("/", $urlpass);
      $nouveau_urlpass = null ;
        $indicepass = sizeof($elementspas);
        for ($i = 0; $i < ($indicepass - 2); $i++) {
            $nouveau_urlpass .=$elementspas[$i] . '/';
          }
  ?>




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


              <div id='exampleModaldemandeavance' class='modal fade'>
                  <div class='modal-dialog modal-lg'>
                    <div class='modal-content'>
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                      <div class='modal-body'> 
                        
                        <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/index/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">
                          <!-- #toolbar=0&scrollbar=0 -->
                      </div>
                    </div>
                  </div>
      </div>


       <div id='exampleModal4' class='modal fade'>
                  <div class='modal-dialog modal-lg'>
                    <div class='modal-content'>
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                      <div class='modal-body'> 
                        
                       <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/acte/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">
                          <!-- #toolbar=0&scrollbar=0 -->
                      </div>
                    </div>
                  </div>
      </div>



        <div id='exampleModalquitance' class='modal fade'>
                  <div class='modal-dialog modal-lg'>
                    <div class='modal-content'>
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                      <div class='modal-body'> 
                        
                        <embed src="<?=$nouveau_urlpass?>/pdf/Pdf_Avance_Pension/quitance/<?=$requerant['DEMANDE_ID']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">
                          <!-- #toolbar=0&scrollbar=0 -->
                      </div>
                    </div>
                  </div>
      </div>




    
          </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(){

      $('#btnadd').click(function(){

        var FICHIER_ID=$('#FICHIER_ID').val();
        var file= document.getElementById("FILE_NAME").files[0];
        var form= new FormData();
      
     form.append("FICHIER_ID", FICHIER_ID);
     form.append("file",file);

         if (Number(FICHIER_ID)==0)
         {
         $('#errordescriptiondoc').html('Le nom du document est obligatoire');
         }
         else if (Number(FICHIER_ID)>0)
         {
         $('#errordescriptiondoc').html('');
         }

         if(file != "")
         { 
      
      $('#errorfile').html('');

     }

     else if(file == ""){
      $('#errorfile').html('Le fichier est obligatoire');

     }


        if(Number(FICHIER_ID)>0 && file != "") 
        {

          $.ajax({
                       url: "<?php echo base_url('gestion_document/Demande_Document/addcart/');?>",
                       type: "POST",
                       data: form,
                       processData: false,  
                       contentType: false, 
                       success: function(data){
                      $('#divdata').html(data);
      $('#FILE_NAME').val('');
      $('#FICHIER_ID').val('');
                         }  
                      });


      
      }

      });
     });

  function remove_ct(id_row){

  var rowid=$('#rowid'+id_row).val();
    $.post('<?php echo base_url();?>gestion_document/Demande_Document/remove_cart',
  {
    rowid:rowid

    },
    function(data)
    {
    $('#divdata').html(data);
    });

}

</script>


<script>
  function action_comment(ACTION_DOC_ID)
  {
    Swal.fire(
    {
      title: 'Confirmation d\'une action',
      text: "Souhaitez-vous confirmer cet action ?",
      icon: 'question',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Confirmer',
      cancelButtonText: "Annuler",
    }).then((result) =>
    {
      if(result.isConfirmed)
      {
          var url_data=ACTION_DOC_ID;
          $('#url_data').val(url_data);
          $('#addCommentaire').modal('show');
  
      }
    });
  }

  function save_commentaire()
  {
    var statut=1;

    // $('#errorID_NIVEAUX_ORGANIGRAMME').text("");
    // if($('#ID_NIVEAUX_ORGANIGRAMME').val()==0)
    // {
    //   $('#errorID_NIVEAUX_ORGANIGRAMME').text("Le champ est obligatoire");
    //   statut=2;

    // }

    // $('#errorSERVICE').text("");
    // if($('#SERVICE').val()==0)
    // {
    //   $('#errorSERVICE').text("Le champ est obligatoire");
    //   statut=2;
    // }

    $('#errorCOMMENTAIRE').text("");
    if($('#COMMENTAIRE').val()=='')
    {
      $('#errorCOMMENTAIRE').text("Le champ est obligatoire");
      statut=2;
    }


    if(statut<2)
    {
      // var values = $("input[name='langue_parle[]']").map(function(){return $(this).val();}).get();
      // var newval = values.length + 1;
      // var i;
      // for (i = 1; i < newval; i++) 
      // {        
      // $('#result6').val('');
      // if(!$('#langue_parle'+i).val())
      // {
      // alert("Le champs de langue parle sur la ligne "+i+" est vides ");
      // $('#result6').val('societe');
      //  }
      //  else if(!$('#FILE_NAME'+i).val())
      //   {
      //  alert("Le niveau de langue sur la ligne "+i+" est vides ");
      //  $('#result6').val('description');
      //   }
      //}//fin foreach
      // var file = document.getElementById('FILE_NAME');
      var form_data = new FormData($("#CommentaireForm")[0]);
      url = "<?= base_url('gestion_document/Demande_Document/addcommentaire') ?>";
      $.ajax(
      {
        url: url,
        type: 'POST',
        dataType:'JSON',
        data: form_data ,
        contentType: false,
        cache: false,
        processData: false,
        success: function(data)
        {
          if(data==true)
          {
            Swal.fire(
            {
              icon: 'success',
              title: 'Success',
              text: 'Le traitement est fait avec succès',
              timer: 1500,
            }).then(() =>
            {
              window.location.reload('<?=base_url('gestion_document/Demande_Document/demande_list')?>');
            });
          }
          else
          {
            Swal.fire(
            {
              icon: 'success',
              title: 'Success',
              text: 'Le traitement est echoué',
              timer: 1500,
            }).then(() =>
            {
              window.location.reload('<?=base_url('gestion_document/Demande_Document/demande_list')?>');
              $("#ID_NIVEAUX_ORGANIGRAMME").val('');

            });
          }
        }
      });
    }
  }

  function getdetaildemande()
  {
    $('#div_detaildemande').prop('style','');
    $('#div_historiquedemande').prop('style','display:none;');
    $('#div_dossiercomplet').prop('style','display:none;');

  }

    function getdossiercomplet()
  {
    $('#div_detaildemande').prop('style','display:none;');
    $('#div_historiquedemande').prop('style','display:none;');
    $('#div_dossiercomplet').prop('style','');

  }


  function gethistoriquedemande()
  {
    $('#div_historiquedemande').prop('style','');
    $('#div_detaildemande').prop('style','display:none;');
    $('#div_dossiercomplet').prop('style','display:none;');
    historique_list($('#ID_DEMANDE').val());
  }

</script>

<script>
  function historique_list(ID_DEMANDE)
  {
    $('#message').delay('slow').fadeOut(3000);
    $("#historique").DataTable(
    {
      "destroy": true,
      "processing": true,
      "serverSide": true,
      "ajax":
      {
        url: "<?php echo base_url('gestion_document/Demande_Document/historique_list'); ?>",
        type: "POST",
        data: {ID_DEMANDE:ID_DEMANDE},
        beforeSend: function() {}
      },
      lengthMenu:
      [
        [10, 50, 100, -1],
        [10, 50, 100, "All"]
      ],
      pageLength: 10,
      "columnDefs": [
      {
        "targets": [],
        "orderable": true
      }],
      order:[1,'desc'],
      dom: 'Bfrtlip',
      buttons: [],
      language:
      {
        "sProcessing": "Traitement en cours...",
        "sSearch": "Rechercher&nbsp;:",
        "sLengthMenu": "Afficher _MENU_ &eacute;l&eacute;ments",
        "sInfo": "Affichage de l'&eacute;l&eacute;ment _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
        "sInfoEmpty": "Affichage de l'&eacute;l&eacute;ment 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
        "sInfoFiltered": "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
        "sInfoPostFix": "",
        "sLoadingRecords": "Chargement en cours...",
        "sZeroRecords": "Aucun &eacute;l&eacute;ment &agrave; afficher",
        "sEmptyTable": "Aucune donn&eacute;e disponible dans le tableau",
        "oPaginate":
        {
          "sFirst": "Premier",
          "sPrevious": "Pr&eacute;c&eacute;dent",
          "sNext": "Suivant",
          "sLast": "Dernier"
        },
        "oAria":
        {
          "sSortAscending": ": activer pour trier la colonne par ordre croissant",
          "sSortDescending": ": activer pour trier la colonne par ordre d&eacute;croissant"
        }
      }
    });
  }
</script>

<script>
function get_services(va){
var ID_NIVEAUX_ORGANIGRAMME= $(va).val();
$.post('<?php echo base_url('gestion_document/Demande_Document/get_services')?>',
   {ID_NIVEAUX_ORGANIGRAMME:ID_NIVEAUX_ORGANIGRAMME},
   function(data){
     $('#SERVICE').html(data);
   });

}
</script>



  <script>

      function showprofil()
      {

        if($('input[type=checkbox]').prop('checked'))
         {

         $("#affectation").show();
         }
         else
         {
         $("#affectation").hide();
         $("#ID_NIVEAUX_ORGANIGRAMME").val('');
         }
         
      }


      
  </script>


</body>
</html>
