<?php

	$admin = 'project';  
	$projPage = 'projList';
	$admintype = $_REQUEST['type'];
	$admTypeTitle = ucfirst($_REQUEST['type']);
	
	$page = (isset($_POST['page']) ? $_POST['page'] : $admin);
	$variables = getVariables($admin,$page);
	
	$adminBtns .= '<a href="#" class="admin btn btn-default" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admintype .'" data-adminact="new" data-page="project" data-section="" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW '. $admTypeTitle .'</a>';
	
	include('admin/pieces-parts/projectFilters.php'); 
	include('pages/inc/page-header.php');
	
	$parentClients = getPclientArray($con);
	
	$query = "SELECT * FROM projects AS p LEFT JOIN clients AS c ON (p.clientID = c.clientID) LEFT JOIN projectStatus AS ps on (p.projectStatus = ps.pstatID) LEFT JOIN projectType AS pt ON (p.projectType = pt.ptypeID)"; 
	if (!empty($statID))
		$query .= ' WHERE p.projectStatus='. $statID; 
	if (!empty($pclientID))
		$query .= ' AND c.subClientOf='. $pclientID;
	if (!empty($pCurrentStat))
		$query .= ' AND p.projectCurrent='. $pCurrentStat; 
	
	$query .= ' ORDER BY c.clientName ASC, p.projectTargetComp DESC';
	$result = $con->query($query);
	
	if ($result) {
		
		// Define Tables
		foreach ($parentClients as $key => $value) {
			$tableName = cleanClientName($value);
			$$tableName = ''; 
		}
		
		$projectsActive = ''; 
		$projectsInactive = '';
		
		$tableFieldNames = '<th class="col-sm-3">Client</th>
							<th class="col-sm-3">Project Name</th>
							<th class="col-sm-1">Rate</th>
							<th class="col-sm-1">Target</th>
							<th class="col-sm-1">Amt</th>
							<th class="col-sm-1">Inv</th>
							<th class="col-sm-1">Rec</th>
							<th class="col-sm-12"></th>'; 
		
		include('inc/data-tables/table-top.php');
		include('inc/data-tables/table-bottom.php');
		
		$sortColumns = 10;
		$noSortColumns = 7; // Column Number from left (column 1=0)
		$scrollHeight = '500px';
		$tabTable = true;

		while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
			$adminLinks = ''; 
			$listItem = '';	
			include('list-item/project.php');	
			$$tableName .= $listItem;
		}
		
		// Assemble Client Tables and Tabs
		$tables = ''; 
		$reporttabs = '<ul>';
		foreach ($parentClients as $key => $value) {
			$reporttabs .= '<li><a href="#tabs-'. $key .'">'. $value .'</a></li>';
			$tableName = cleanClientName($value);
			if (!empty($tableName))  
				$tables .= '<div id="tabs-'. $key .'">'. $tableHeader . '<tbody id="'. $tableName .'">' . $$tableName . '</tbody>'. $tableFooter .'</table></div>';
			else 
				$tables .= '<div id="tabs-'. $key .'"><p class="center">There are currently no Active Clients Listed</p></div>';
		}
		$reporttabs .= '</ul>';
		
		$content .= '<div id="tabs">' . $reporttabs . $tables . '</div>';

	}
	include('inc/data-tables/dataTables.php');
	
	/*$footerScripts .= '<script>
function fillDate(thisValue,nextField) {
	var thisValue = thisValue;
	var nextField = nextField;
	document.getElementById(nextField).value=thisValue;
}
</script>';*/

?>