<?php
/*
* date last modified 03-10-2017
* Edited by PI-Digi Logical Solutions
* HTML Files - manage_staff.html.php
* Mysql Tables - tbl_admin, tbl_staff, tbl_admin_type
*/
require_once('./classes/class.noseo_pagination.php'); # pagination class
require_once('./includes/functions.php'); # general functions

if(isset($_REQUEST['p']) && $_REQUEST['p']!=''){
	$p = trim($_REQUEST['p']);
} else {
	$p = 1;
}

if(isset($_POST['clear'])) {
	?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>';
			</script>
	<?php
}

//get tech list
$techListRs = mysqli_query($con, "SELECT id, name FROM tbl_technician WHERE status = 'Active' ORDER BY name");

if(isset($_GET['action']) && $_GET['action'] == 'delete') {
	/* Delete Record */
	/*if(isset($_GET['del_id']) && $_GET['del_id']!=''){
		//delete advance return entry if added with salary
		mysqli_query($con, "DELETE FROM tbl_ WHERE salary_id = '".$_GET['del_id']."'");
				
		$delete = mysqli_query($con,'DELETE FROM tbl_ WHERE id='.$_GET['del_id']);
		if($delete) {
			$success = 'Deleted the record';
			?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>&success=<?php echo $success; ?>&p=<?php echo $p;?>';
			</script>
	        <?php
		}
	}*/
}

$pageVars = '';

// Get All User details to list 
$where = ' id>0 ';




if(isset($_POST['search'])) {
	
	if(isset($_POST['date_to']) && strlen($_POST['date_to'])>0) {
		$to_date = trim($_POST['date_to']);
		if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$to_date)) {
		    //ok - yyy-mm-dd
		} else {
		    $dateArr = explode('-', $to_date);
			$to_date = $dateArr[2].'-'.$dateArr[1].'-'.$dateArr[0];
		}		
	} else {
		$to_date = '';
	}

	if(isset($_POST['from_date']) && strlen($_POST['from_date'])>0) {
		$from_date = trim($_POST['from_date']);
		if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$from_date)) {
		    //ok - yyy-mm-dd
		} else {
		    $dateArr = explode('-', $from_date);
			$from_date = $dateArr[2].'-'.$dateArr[1].'-'.$dateArr[0];
		}
	} else {
		$from_date = '';
	}
	
	if(isset($_REQUEST['technician']) && strlen($_REQUEST['technician'])>0) {
		$where .= ' AND technician_id='.$_REQUEST['technician'];
		$pageVars .= '&technician='.$_REQUEST['technician'];
	}
	
	if($from_date!='' && $to_date!=''){
		$where .= " AND `date` BETWEEN '".$from_date."' AND '".$to_date."' ";
		$pageVars .= '&from_date='.$from_date.'&to_date='.$to_date;
	}
			
}

$select = "SELECT * FROM tbl_technician_paid WHERE ".$where." ORDER BY id DESC";
//echo $select;
// Using pagination class
$pagination = new pagination_noseo($select);
$execDetails = $pagination->createPages(30);

$pageLnk = 'index.php?page='.$page.'&'.$pageVars;
$pageNums = $pagination->pageNumber(5, $pageLnk);
?>