<?php session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) . " SELF :" .$_SERVER['PHP_SELF']  ;
$toDiv = $_REQUEST['toDiv'];
$rpage = $_REQUEST['rpage'];
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir']."core.php");

?>

<form action="<?php echo $currentBaseDir; ?>/exec_add_customer.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"> Identifiant :
                        <input name="queueName" type="text" class="form-control" placeholder="Identifiant de la file d'attente" size="20" >
                    </div>
                    <div class="form-group"> Musique d'attente :
                        <select name="musicOnHoldClass">
                         <option value="default" selected="selected">Default</option> 
                        </select>
                    </div>
                    <div class="form-group"> Strategie des appels :
                        <select name="strategy">
                         <option value="ringall" selected="selected">Activer tous les agents</option> 
                        </select>
                    </div>
                    <div class="form-group"> Temps de repos :
                    <input name="wrapTime" type="text" class="form-control" placeholder="Temps de repos post-appel" size="20">
                    </div>
                     <button  type="submit" class="btn addition">Ajouter</button>  <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>
                </form>
                


<script type="text/javascript">

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

				});
			    //  alert(data);
            $("#" + toDiv).load(rpage);
            $('#loader').hide();
			   
		   }
		   else {
			   
			   $.alert({
				     icon: 'glyphicon glyphicon-warning-sign',
					 title: 'RESULTAT',
                     content: obj.errorMessage,
                     type: 'red',
                     typeAnimated: true
				});
			   
			  // $.alert( obj.errorMessage );
		   }
         
        });
       // return false; // prevent normal submit
   
	
  event.preventDefault();
	
	/*
        var postData = $(this).serializeArray();
        var formURL = $(this).attr("action");
		
        $.ajax({
            url: formURL,
            type: "POST",
            data: postData,
            success: function(data, textStatus, jqXHR) {
              
			  alert("Processing the form...");
			
            },
            error: function(jqXHR, status, error) {
                console.log(status + ": " + error);
            }
        });
        event.preventDefault(); */
    });

$(".close-btn").on('click', function(){
  // create the backdrop and wait for next modal to be triggered
 // $('body').modalmanager('loading');
   $('#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>