<?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;
}

//get staff list
$staffListRs = mysqli_query($con, "SELECT id, name FROM tbl_staff WHERE status = 'Active'");

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_staff_advance WHERE salary_id = '".$_GET['del_id']."'");
				
		$delete = mysqli_query($con,'DELETE FROM tbl_staff_salary 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($_REQUEST['staff']) && strlen($_REQUEST['staff'])>0) {
	$where .= ' AND staff_id='.$_REQUEST['staff'];
	$pageVars .= '&staff='.$_REQUEST['staff'];
}


if(isset($_POST['search'])) {
	if(isset($_REQUEST['staff']) && strlen($_REQUEST['staff'])>0) {
		$where .= ' AND staff_id='.$_REQUEST['staff'];
		$pageVars .= '&staff='.$_REQUEST['staff'];
	}
			
}

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

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