<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone ="#tableZone".$pageSequence;
$_SESSION['sequence']++;


$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");
$res = $dba->getSCCMailDetails(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 campagnes mail</em></legend>

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

                                            <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="addBtnCallReason" class="btn" data-href="<?php echo $currentBaseDir; ?>/create_mail_campaign.php?toDiv=<?php echo $toDiv; ?>&rpage=<?php echo $_SERVER['PHP_SELF']; ?>"  title="Cr&eacute;er une campagne."><i class="cus-add"></i>Cr&eacute;er</button>
	  <button class="btn" id="callreason-delete" disabled="disabled"><i class="cus-delete"></i> Supprimer</button>
	</div> </div></td>
                                                </tr>
                                              </table></td>
                                            </tr>
                                            <tr>
                                              <td align="left">
                                              
                                              <table id="tblMailMngt" class="table table-striped table-bordered" width="100%" cellspacing="0">
        <thead>
            <tr>
                <th width="3%" align="left"></th>
                <th width="1%" align="left"></th>
                <th width="15%" align="left">Date de création</th>
                <th width="18%" align="left">Nom de la campagne</th>
                <th width="36%" align="left">Sujet</th>
                <th width="11%" align="left">Progression</th>
                <th width="11%" align="left">Statut</th>
                <th width="5%" align="left">&nbsp;</th>
                </tr>
        </thead>
        <tbody>
        
        <?php

$cmpt = 1;

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

?>

            <tr>
                <td align="left"><input type="checkbox" name="callReason" value="<?php echo $res[$i]['campaign_id_n']; ?>" class="delete-callreason" /></td>
                <td><a href="#" data-href="<?php echo $currentBaseDir; ?>/edit_mail_action.php?item=<?php echo $res[$i]['campaign_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]['creation_date_d']; ?></td>
                <td align="left"><?php echo $res[$i]['campaign_name_v']; ?></td>
                <td align="left"><?php echo $res[$i]['subject']; ?></td>
                <td align="left"><?php echo $res[$i]['char_field_7']; ?></td>
                <td align="left"><?php echo $res[$i]['description_v']; ?></td>
                <td align="left">&nbsp;</td> 
                </tr>
            
         <?php }   ?>
        </tbody>
    </table></td>
                                            </tr>
                                        </table>


                                  </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 type="text/javascript" >   
    
$('#tblMailMngt').DataTable( {
  "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"
  }
});
</script>

<script>
$('#addbtn2345').on('click',function(){
	 var dataURL = $(this).attr('data-href');
	 var modalTitle = $(this).attr('title'); 
	 $('.modal-title').html(modalTitle) ;
    $('.modal-body').load(dataURL ,function(){
        $('#myModalDesc').modal({
		 backdrop:'static',
		 keyboard: false
		});
    });
});
</script>

<script id="ajax" type="text/javascript">
var $modal = $('#myModal');

$('#addBtnCallReason').on('click', function(){
   $('#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
		});
    }); 
 
});
$("a[class='cus-application-form-edit']").on('click', function(){
   $('#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
		});
    }); 
});
var checkBoxes = $('tbody .delete-callreason');
checkBoxes.change(function () {
    $('#callreason-delete').prop('disabled', checkBoxes.filter(':checked').length < 1);	
});
checkBoxes.change(); // or add disabled="true" in the HTML
$("#callreason-delete").on("click",function(){
	var deleteData= "";
    checkBoxes.each(function() {
        if ($(this).is(":checked")) {
			deleteData = deleteData+ "'" +  $(this).get(0).value +  "'," ;
            
        }
    });	
	deleteData = deleteData.substring(0, deleteData.length - 1);	
	$.confirm({
    title: 'Attention!',
    content: 'Voulez-vous supprimer les éléments selectionnés?',
    buttons: {
        confirm: {
		  text : 'Confirmer',
		  btnClass: 'btn-blue',
		  action: function () {			  
			  $.getJSON('<?php echo $currentBaseDir ?>/exec_delete_callreason.php?data=' + deleteData,
						function(obj) {		   
							   if(obj.errorCode == 0 ) {								 
								 $.alert({
									 icon: 'glyphicon glyphicon-ok',
									 title: 'RESULTAT',
									 content: obj.errorMessage,
									 type: 'green',
									 typeAnimated: true
					
									});
								$("#<?php echo $toDiv; ?>").load('<?php echo $_SERVER['PHP_SELF']; ?>');
								$('#loader').hide();			   
		   }
		   else {
			   
			   $.alert({
				     icon: 'glyphicon glyphicon-warning-sign',
					 title: 'RESULTAT',
                     content: obj.errorMessage,
                     type: 'red',
                     typeAnimated: true
				});
		   }
				});            
        } },
        cancel: {
		  text: 'Annuler', 
		  action:  function () {        
        }
	  }
    }
});
	
});
</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>