<?php
$user = auth()->user();
?>
<script src="assets/js/king-table.js"></script>
<div class="content">
	<div class="main-content">
		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-envelope"></i> <?php echo e(__('letter.annual_meet_invite')); ?></h3>
			</div>
			<div class="widget-content">
						<div class="widget">
							<div class="widget-header">
							<h3><i class="fa fa-edit"></i> <?php echo e(__('letter.file_uploader')); ?></h3></div>
							<div class="widget-content">
		<div class="row">

			<div class="col-md-6 form-horizontal">
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li><?php echo e(__('grade.enter_details')); ?>...</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>
<form id="frmmain" name="frmmain" data-parsley-validate novalidate enctype="multipart/form-data" >
			<input type="hidden" name="_token" id="_token" value="<?php echo e(csrf_token()); ?>">
			<div class="form-group">
				<label for="cst_gender" class="col-sm-4 control-label"><?php echo e(__('letter.upload_file')); ?></label>
				<span id="errupload_file" style='color: red;'></span>
				<div class="col-sm-8">					
					<input type="file" class="form-control" id="upload_file" name="upload_file" >
				</div>
			</div>
			<div class="form-group">
				<center><button type="submit" id="submitfile" name="submitfile" class="btn btn-default submitfile">Submit</button></center>
			</div>
</form>
			</div>
			<div class="col-md-6 form-horizontal">
				<div class="form-group">
				<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
					<thead>
						<tr>
							<th colspan="3"><b ><?php echo e(__('letter.file_short_code')); ?>:</b></th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td><?php echo e(__('mylanguage.member_id')); ?> - </td>
							<th>###MEMBERID###</th>
						</tr>
						<tr>
							<td>2</td>
							<td><?php echo e(__('mylanguage.name')); ?> -  </td>
							<th>###NAME###</th>
						</tr>
						<?php
						/*
						<tr>
							<td>3</td>
							<td>{{ __('letter.next_page') }} -</td>
							<th>###NEXTPAGE###</th>
						</tr>
						<tr>
							<td>4</td>
							<td>{{ __('letter.balance_report') }} -</td>
							<th>###BALANCEREPORT###</th>
						</tr>
						*/
						?>
					</tbody>
				</div>										
			</div>
								</div>
							</div>
						</div>				
			</div>
		</div>
		<!-- END DATA EXPORT -->
	</div>
</div>
<!-- /main -->

<style>
.modal-dialog.modal-100 {
    width: 90%;
    /*margin: 30px auto;*/
}
</style>

<script>
	$('.createMod').click(function(e)
	{   
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
</script>
<script type="application/javascript">
i=0;
	$('.submitfile').click(function()
	{
		var _token = $("input[name='_token']").val();
		var upload_file =  $('#upload_file').val();
		var formData = new FormData($("#frmmain")[0]);
		if(upload_file == "")
		{
			document.getElementById("errupload_file").innerHTML = "Kindly Upload the file...";
			$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');	
		}
		else
		{
				if(i==0)
				{
					$.ajax({
						url: 'uploadannualmeetfile',
						type: 'POST',
						data: formData,
						processData: false,
						contentType: false,
						beforeSend: function() {
							$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
						},
						error: function(xhr, ajaxOptions, thrownError) {
						   console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
						},
						success: function(data) 
						{
							printSuccessMsg(data.message);
							$('#upload_file').val('');
							fileupdater(data.filename);
						}	
					});
				}
		}
		return false;
	});
	function printErrorMsg (msg) {			
		$(".alert-info").css('display','none');
		$(".print-success-msg").css('display','none');
		$(".print-error-msg").find("ul").html('');
		$(".print-error-msg").css('display','block');
		$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
	}	
	function printSuccessMsg (msg) {
		$(".alert-info").css('display','none');
		$(".print-error-msg").css('display','none');
		$(".print-success-msg").find("ul").html('');
		$(".print-success-msg").css('display','block');
		$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
	}
	function fileupdater(filename)
	{
		window.open('http://localhost/MosqueDesk/filegenerator/?filename=' + filename ,'_blank');
		/*
		$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Generating Files...');
		$.ajax({
			url: "/fileeditor",
			type:'get',
			data: { 'filename': filename},
			success: function(data) {											
				if(data.status == 1)
				{
					printSuccessMsg(data.message);
				}
				else
				{
					printErrorMsg(data.message)
				}
			}
		});
		*/
	}
</script>