<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone ="#tableZone".$pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
//echo $currentBaseDir ;
include($_SESSION['basedir']."core.php"); 
$res = $dba->getSCCAgencies(0); 


?>

<div id="<?php echo $toDiv; ?>" class="tab-content"  > 

    <table width="100%" border="0" >

        <tr>

            <td> 



                <div id="<?php echo $resultZoneDiv; ?>">  </div></td>

        </tr>



    </table>



    <table width="100%"  >



        <td align="center">

          

                <table width="94%" border="0" cellspacing="1" cellpadding="1">



              <tr>

                        <td align="center" valign="top" ></td>







                    <tr>

                        <td colspan="2" align="center" valign="top"><b style="color:red">

                            </b></td>

                    </tr>

                    <tr height="40">

                        <td height="19" colspan="2" class="connection" valign="top" align="left">

       

                                <div id="routeType1" >

                                    <fieldset >

                                      <legend><em>Liste des agences</em></legend>
                                       <form id="sbmt<?php echo $pageSequence ;?>" action="<?php echo $currentBaseDir ?>/exec_delete_agencies.php" method="post" onsubmit="return false;" >


                                        <table width="100%" border="0">

                            <!--                    <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" tabindex="10">
    Launch demo modal
</button>   -->

                                            <tr>

                                                <td align="left"><table width="100%" border="0">
                                                <tr>
                                                  <td align="center"> 
                                                  <div class="containerIcons"> 
                                                  <div>
                                                    <button id="refreshPage" class="btn" onclick="getPage('<?php echo $_SERVER['PHP_SELF']; ?>','<?php echo $toDiv; ?>')"   title="Rafraichir"><i class="cus-page-refresh"></i>Rafraichir</button>
	  <button id="addBtnAgency" class="btn" data-href="<?php echo $currentBaseDir; ?>/add_agency.php?toDiv=<?php echo $toDiv; ?>&rpage=<?php echo $_SERVER['PHP_SELF']; ?>"  title="Ajouter une agence"><i class="cus-add"></i>Ajouter</button>
	  <button class="btn" id="agency-delete" disabled="disabled" type="submit"><i class="cus-delete"></i> Supprimer</button>
	</div> </div></td>
                                                </tr>
                                              </table></td>
                                            </tr>
                                            <tr>
                                              <td align="left">
                                              
                                              <table id="tblAgency" class="table table-striped table-bordered" width="100%" cellspacing="0">
        <thead>
            <tr>
                <th width="1%" align="left"></th>
                <th width="1%" align="left"></th>
                <th width="38%" align="left">Nom de l'agence</th>
                <th width="55%" align="left">Description</th>
                </tr>
        </thead>
        <tbody>
        
        <?php

$cmpt = 1;

for ($i = 0; $i < count($res); $i++) {

?>




            <tr>
                <td align="left"><input type="checkbox" name="agencies[]" value="<?php echo $res[$i]['agency_id_n']; ?>" class="delete-agency" /></td>
                <td><a href="#" data-href="<?php echo $currentBaseDir; ?>/edit_agency.php?item=<?php echo $res[$i]['agency_id_n']; ?>&toDiv=<?php echo $toDiv; ?>&rpage=<?php echo $_SERVER['PHP_SELF']; ?>"  title="Modifier" class="cus-application-form-edit" ></a></td>
                <td align="left"><?php echo $res[$i]['agency_name_v']; ?></td>
                <td align="left"><?php echo $res[$i]['agency_desc_v']; ?></td>
                </tr>
            
         <?php }   ?>
        </tbody>
    </table></td>
                                            </tr>
                                        </table>



                                      </form>





                                  </fieldset>

                                </div> 

                         









                        </td>

                    </tr>



                </table>


        </td>

        </tr>





    </table>



</div>
<div id="loader" ></div>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="plugins/datatables/dataTables.buttons.min.js"></script>
<script src="plugins/datatables/buttons.html5.min.js"></script>
<script type="text/javascript" src="js/jquery.loading.min.js"></script>

  <script type="text/javascript" >   
    
var table = $('#tblAgency').DataTable( {
	 dom: 'Bfrtip',
								buttons: [
							            {
										extend: 'csv',
										title: "export<?php echo date('YmdHis'); ?>" 
									   }
								],
  "language": {
    "search": "Filtrer:",
	"emptyTable" : "Table vide",
	"zeroRecords":    "Table vide",
	"lengthMenu":     "Nombre de lignes  _MENU_ ",
	"info":           "Affichage de  _START_ &aacute; _END_ sur  _TOTAL_ entr&eacute;es",
	"paginate": {
        "first":      "D&eacute;but",
        "last":       "Fin",
        "next":       "Suivant",
        "previous":   "Pr&eacute;c&eacute;dent"
    },
	"infoEmpty":      "Affichage de  0 &agrave; 0 sur  0 entr&eacute;es"
  }
});

var $modal = $('#myModal');

$('#addBtnAgency').on('click', function(){
  // create the backdrop and wait for next modal to be triggered
 // $('body').modalmanager('loading');
   $('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
    var dataURL = $(this).attr('data-href');
	 var modalTitle = $(this).attr('title'); 
	 $('.modal-title').html(modalTitle) ;
	  $('#loader').loading('stop'); 
	 $('.modal-body').load(dataURL ,function(){
        $modal.modal({
		 backdrop:'static',
		 keyboard: false
		});
    }); 

 
});
/**********************************/

$("#tblAgency").on('click', '.cus-application-form-edit',  function(){
  // create the backdrop and wait for next modal to be triggered
 // $('body').modalmanager('loading');
   $('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
    var dataURL = $(this).attr('data-href');
	 var modalTitle = $(this).attr('title'); 
	 $('.modal-title').html(modalTitle) ;
	  $('#loader').loading('stop'); 
	 $('.modal-body').load(dataURL ,function(){
        $modal.modal({
		 backdrop:'static',
		 keyboard: false
		});
    }); 

 
});

/********** Next Function *********/
var checkBoxes = $('tbody .delete-agency');
var counterChecked = 0;

$('body').on('change', 'input[type="checkbox"]', function() {

    this.checked ? counterChecked++ : counterChecked--;
    counterChecked > 0 ? $('#agency-delete').prop("disabled", false): $('#agency-delete').prop("disabled", true);

});



$('#agency-delete').on("click", function(e){
	
	e.preventDefault();
	
$.confirm({
    title: 'Attention!',
    content: 'Voulez-vous supprimer les éléments selectionnés?',
    buttons: {
        confirm: {
		  text : 'Confirmer',
		  btnClass: 'btn-blue',
		  action: function () {
			  
	
	 $.ajax({
            url: $('#sbmt<?php echo $pageSequence ;?>').attr('action'),
            type: 'post',
            dataType: 'json',
            data: table.$('input[type="checkbox"]').serialize(),
            success: function(obj) {
                //alert(data);
                if(obj.errorCode == 0 ) {
					$("#<?php echo $toDiv; ?>").load('<?php echo $_SERVER['PHP_SELF']; ?>');
					$('#loader').hide();
								 $.alert({
									 icon: 'glyphicon glyphicon-ok',
									 title: 'RESULTAT',
									 content: obj.errorMessage,
									 type: 'green',
									 typeAnimated: true
					
									});
									//  alert(data);
								
			   
							   }
							   else {
								   
								   $.alert({
									     icon: 'glyphicon glyphicon-warning-sign',
										 title: 'RESULTAT',
							     content: obj.errorMessage,
							     type: 'red',
							     typeAnimated: true
									});


							   }
            }
        });

  } },
        cancel: {
		  text: 'Annuler', 
		  action:  function () {
          
        
        }
	  }
      }
}); 
	
	//$('#sbmt01').submit() ;
	
});



</script>


 



<script type="text/javascript" src="js/jquery.loading.min.js"></script>
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js"></script>