<?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");

//$res = $dba->getSCCTicketDetailById($_REQUEST['item']) ;
//$callreasonres = $dba->getSCCCallReasonDetails(0);

?>

<form action="<?php echo $currentBaseDir; ?>/exec_add_ticket_batch.php" method="post" enctype="multipart/form-data"  id="batchTicketFrm"  toDiv="<?php echo $toDiv; ?>" returnPage="<?php echo $_SERVER['PHP_SELF']; ?>" >

  
  <div class="form-row">
    <div class="form-group col-md-12">
      <label for="importFile">Importer des tickets</label> <br /> <br />
      <input type="file" class="form-control" id="importFile" name="importFile"  title="Importer un fichier" >
      <br />
    </div>
  </div>
  
  
 
  <button type="submit" class="btn btn-primary" id="import">Importer</button> <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>
</form>
                


<script type="text/javascript">

$('#import').on('click', function(e){
	
	//stop submit the form, we will post it manually.
        e.preventDefault();

        // Get form
        var form = $('#batchTicketFrm')[0];

		// Create an FormData object 
        var data = new FormData(form);
		$("#import").prop("disabled", true);
		 $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "<?php echo $currentBaseDir; ?>/exec_add_ticket_batch.php",
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            timeout: 600000,
            success: 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 );
		   }
          
                $("#import").prop("disabled", false);

            },
            error: function (e) {
                $("#import").prop("disabled", false);

            }
        });



	
});




$(".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>