<?php
error_reporting(1);
set_time_limit(0);
session_start();
if(!$_SESSION['USER_NAME'])
{
	header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
	exit;
}
include '../Basic.php';

$time = time();
DisplayHeader(".:".ProgramTitle().":.");
$width = 'width=40%';
$tab='ADD USERS';
PopTable('header',$tab,$width);
?>
<form  name="mass_create_usr" action="action.php" method="post" enctype="multipart/form-data" id="mass_create_usr">
	Choose Csv File
<input type="file" name="csvUpload" value="" id='file_type' accept=".csv">
</br></br>
 <input type="submit" value="Upload">
</form>
<div class="csv_result"></div>
<div class="btn btn-info reset_btn" style="text-align: end;"><button id='reset_form' class='btn btn-info pull-right '>Reset</button></div>
<script>
jQuery(document).ready(function(){
	var url =  window.location.href;
	var ais_pos =  url.indexOf("ais")
	var csvurl = url.substring(0, ais_pos);
	//alert(csvurl+'ais/modules/mod_users/userCSVUpload.php');return false;
	//alert('hhhh');
	jQuery("form[name='mass_create_usr']").submit(function(e){
    	e.preventDefault();
    	//alert('helllo');
    	var formdata = new FormData(jQuery(this)[0]);
    	jQuery.ajax({
        	//url: 'https://arrupe.ac.zw/acis/ais/modules/mod_users/userCSVUpload.php',
        	url: csvurl+'ais/modules/mod_users/userCSVUpload.php',
        	type: "POST",
        	data: formdata,
        	//dataType: 'JSON',
        	error: function(xhr, textStatus) {
           		console.log(textStatus);
        	},
        	success:function(data){//alert('helllo');
            	jQuery('.csv_result').html(data);
            
            },
            processData: false,
            contentType: false,
            cache: false,
        });
    });
		/*********** rest page *****************/
	document.getElementById("reset_form").addEventListener("click", function() {
    		document.getElementById("mass_create_usr").reset();
         	jQuery(".csv_result").html('');
                		
	});

	/**************************************/
});
</script>
<?php
echo PopTable('footer');

?>