<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$_SESSION['sequence']++;
$toDiv = $_REQUEST['toDiv'];
$rpage = $_REQUEST['rpage'];
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");

?>

<form action="<?php echo $currentBaseDir; ?>/exec_mail_campaign.php" method="post" enctype="multipart/form-data"  id="campaignFrm"  toDiv="<?php echo $toDiv; ?>" returnPage="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false;">
                    <div class="form-group"> 
                        <input name="campaignName" type="text" class="form-control" placeholder="Nom de la campagne" title="Nom de la campagne" size="20" >
                    </div>
                    
                    <div class="form-group"> 
                        <input name="subjectName" type="text" class="form-control" placeholder="Entrez le sujet du mail" title="Sujet du mail" size="20" >
                    </div>

     <div class="form-group"> 
                        <input name="toUserList" type="text" class="form-control" placeholder="A" title="Liste des E-mail de la campagne. Veuillez séparer les E-mail par des points-virgules en cas de multiple E-mail. Exemple : info@mail.com;dt@mail.com" size="20" >
                    </div>      
                      <div class="form-group"> 
                        <input name="ccUserList" type="text" class="form-control" placeholder="CC" title="Liste des E-mail de la campagne. Veuillez séparer les E-mail par des points-virgules en cas de multiple E-mail. Exemple : info@mail.com;dt@mail.com" size="20" >
                    </div>            
                    <div class="form-group">
                    <div id="mail">
                    <textarea  name="mailText" class="form-control" title="Composez votre mail." id="mailText" ></textarea>
                    </div>
                    <input type="hidden"  id="actionType" name="actionType"  value="2">
                    </div>
                    
                     <div class="form-group"> 
                        <input name="attachedDoc" type="file" class="form-control"  title="Selectionnez un fichier à envoyer." size="20" >
                    </div>
                    
                     <button  type="submit" class="btn btn-primary">Envoyer</button> <button  type="button" class="btn" id="save">Enregistrer</button>    <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>
                </form>
                


<script type="text/javascript">

$('#save').on('click', function(e){
	document.getElementById('actionType').value = -1;
   $(this).parents('form').submit() ;
});


$('form').on("submit", function(event) { 
	
	
	 $.post($(this).attr("action"), $(this).serialize(), function(data) {
 
		   var obj = jQuery.parseJSON( data);
		   
		   if(obj.errorCode == 0 ) {
			   
			 $.alert({
				 icon: 'glyphicon glyphicon-ok',
				 title: 'RESULTAT',
                 content: obj.errorMessage,
                 type: 'green',
                 typeAnimated: true

				});
            $("#" + toDiv).load(rpage);
            $('#loader').hide();
			   
		   }
		   else {
			   
			   $.alert({
				     icon: 'glyphicon glyphicon-warning-sign',
					 title: 'RESULTAT',
                     content: obj.errorMessage,
                     type: 'red',
                     typeAnimated: true
				});

		   }
         
        });

  event.preventDefault();

    });


$(".close-btn").on('click', function(){
   $('#loader').loading({
		  message : "Chargement...",
		  theme : 'dark'
		  
		});
		
		   $("#<?php echo $toDiv; ?>").load("<?php echo $rpage; ?>");
           $('#loader').loading('stop'); 
		
});

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