<?php
/*
* date last modified 03-10-2017
* Edited by PI-Digi Logical Solutions
* HTML Files - manage_staff.html.php
* Mysql Tables - tbl_admin, tbl_purchase_order, 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($_GET['action']) && $_GET['action'] == 'complete') {	
	if(isset($_GET['id']) && $_GET['id']!=''){
		$update = mysqli_query($con,"UPDATE tbl_project SET status = 'completed' WHERE id='".$_GET['id']."'");
		if($update) {
			$success = 'Marked the project as completed';
			?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>&p=<?php echo $p; ?>&success=<?php echo $success; ?>';
			</script>
	        <?php
		}
	}
}

if(isset($_GET['action']) && $_GET['action'] == 'inprogress') {	
	if(isset($_GET['id']) && $_GET['id']!=''){
		$update = mysqli_query($con,"UPDATE tbl_project SET status = 'in_progress' WHERE id='".$_GET['id']."'");
		if($update) {
			$success = 'Marked the project as in progress';
			?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>&p=<?php echo $p; ?>&success=<?php echo $success; ?>';
			</script>
	        <?php
		}
	}
}

if(isset($_GET['action']) && $_GET['action'] == 'incomplete') {
	/* Delete User */
	if(isset($_GET['id']) && $_GET['id']!=''){
		$update = mysqli_query($con,"UPDATE tbl_project SET status = 'in_progress' WHERE id='".$_GET['id']."'");
		if($update) {
			$success = 'Marked the project as in progress';
			?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>&p=<?php echo $p; ?>&success=<?php echo $success; ?>';
			</script>
	        <?php
		}
	}
}

if(isset($_GET['action']) && $_GET['action'] == 'delete') {
	/* Delete User */
	if(isset($_GET['id']) && $_GET['id']!=''){
		$delete = mysqli_query($con,'DELETE FROM tbl_project WHERE id='.$_GET['id']);
		if($delete) {
			$success = 'Deleted the project';
			?>
	        <script language="javascript" type="text/javascript">			
				window.location='index.php?page=<?php echo $page;?>&p=<?php echo $p; ?>&success=<?php echo $success; ?>';
			</script>
	        <?php
		}
	}
}

$pageVars = '';

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

/*if(isset($_POST['search'])) {
	if(isset($_POST['user_type']) && strlen($_POST['user_type'])>0) {
		$where .= ' AND role='.$_POST['user_type'];
		$userType = $_POST['user_type'];
	}
	
	if(isset($_POST['keyword']) && strlen($_POST['keyword'])>0) {
		$keyword = trim($_POST['keyword']);
		$where.= " AND (ad_username LIKE '%".$keyword."%' OR first_name LIKE '%".$keyword."%') ";
	}	
}*/

$select = "SELECT * FROM tbl_project 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);
?>