<?php
require '../conn/codeblocs.php';
accessCheck();

// preprint($_SESSION);
// echo $STAFF_ID;

// doLogin('ifedi', 'emelum_4DMC');
$get = $_GET;

if($PRIVILEGE == 'techno'){
	$sid = $get['sid'] ?? '';
	$vid = $get['vid'] ?? '';
}else{
	$vid = array_keys($V_ARR_TRIM)[0];
}



$survey_instances = SAW('survey_id, survey_name', 'survey_instance', 1, 1, 1);
$survey_vendees = SAW('vendee_id, vendee_name', 'survey_vendee', 1, 1, 1);

?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>View Page :: Survey Submission Batches</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="shortcut icon" href="../assets/img/swiftpractice_favicon.png" />

		<link rel="stylesheet" type="text/css" href="../assets/styles/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="../assets/styles/font-awesome.min.css">
		<link rel="stylesheet" type="text/css" href="../assets/styles/animate.css">
		<link rel="stylesheet" type="text/css" href="../assets/styles/perfect-scrollbar.css">
		<link rel="stylesheet" type="text/css" href="../assets/styles/util.css">
		<link rel="stylesheet" type="text/css" href="../assets/styles/view.css">

		<meta name="robots" content="noindex, nofollow">
	</head>
	<body>
        			
		
		<div id="" style="clear:both;background:#36304a;padding:.5em; font-size:smaller">
            <form method="get" id="vid-form" style="display:inline-block">
				<?php if($PRIVILEGE == 'techno'|| count($V_ARR_TRIM)>1 ):?>
				<?php doDirectFormSelect('vid', $V_ARR_TRIM, $vid??'', [''=>'...'])?>
				<?php endif?>
				
				
				<?php if($PRIVILEGE == 'techno'):?>
				<?php endif?>

            </form>
			<span style="float:right;color:#ccc"><?=$USER?></span>
			<a href="?doLogout">Sign Out</a>
        </div>
		
		<div id="page-wrap" class="limiter"></div>
		<?php if( ($_SERVER['SYSTEMROOT']??'') == 'C:\WINDOWS'):?>
		<script src="http://localhost/doc/javascripts/NEW/jquery-2.2.4.min.js" integrity="" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<?php else:?>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
		<?php endif?>


		<script src="../assets/js/FileSaver/xlsx.core.min.js"></script>
		<script src="../assets/js/FileSaver/filesaver.min.js"></script>
		<script src="../assets/js/FileSaver/tableexport.min.js"></script>
		<script src="../assets/js/script.js"></script>
		<script>
			$(function(){
				let $wr = $('#page-wrap');

				post_page(QUERY_STRING);
				
				$wr.on('click', 'a.d-anchor', function(e){
					e.preventDefault();
					// console.log(this.href);
					$wr.load(this.href)
				});

				$('#vid-form')
					.on('change', 'select', function(){
						$(this).closest('form').submit();
				})
				.on('submit', function(e){
					e.preventDefault();
					let d = $(this).serialize();
					console.log(d);
					post_page(d);
				});

				$('#page-wrap')
					.on('change', '#sid-form select', function(){
						$(this).closest('form').submit();
				})
				.on('submit', '#sid-form', function(e){
					e.preventDefault();
					let d = $(this).serialize();
					console.log(d);
					post_page(d);
				});




			


			});

			function post_page(qstr){
				let q = qstr || '';
				$.get('pages/summary.inc.php', q, function(o){
					// console.log('OUTPOUT:', o);
					$('#page-wrap').html(o);

					configure_page();
				});
			}

			function configure_page(){
				let $t = $('#main-summary-table');
				if( $t.find('tbody').find('tr').length ){
					$t.tableExport({ 
						filename: ($t.data('te-filename') || 'id')
					});	
				}
				

			}
		</script>
	</body>
</html>
