<?php
	include('globals/error-reporting.php');

	$admin = 'client';
	$type = $_REQUEST['type'];
	$page = (isset($_POST['page']) ? $_POST['page'] : '');
	$variables = getVariables($admin,$page);
	
	$adminBtns .= '<a href="#" class="admin btn btn-default" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admin .'" data-adminact="new" data-page="'. $admin .'" data-section="" data-editid=""><i class="fa fa-user-plus"></i> Add a NEW Client</a>';
	
	include('pages/inc/page-header.php');
	
	$parentClients = getPclientArray($con);
	
	if (!empty($_REQUEST['parentClient']))
		$pclientID = $_REQUEST['parentClient'];
	else
		$pclientID =  '';	 				
	$pClients = getPclientOptions($pclientID,$con);				
					
	$query = 'SELECT c.*, sc.clientName AS subName, sc.clientAbbr AS subAbbr FROM clients AS c LEFT JOIN clients AS sc ON (c.subClientOf = sc.clientID) WHERE c.clientType='. $clientType .' ORDER BY c.clientName';
	$result = $con->query($query);
	if ($result) {
		
		// Define Tables
		foreach ($parentClients as $key => $value) {
			$tableName = cleanClientName($value);
			$$tableName = ''; 
		} 
		
		$clientsInactive = '';
		
		$tableFieldNames = '<th>Name</th>
							<th>Sub-Client Of</th>
							<th>Contact</th>
							<th>Address</th>
							<th>Client Since</th>
							<th>&nbsp;</th>'; 
							
		include('inc/data-tables/table-top.php');
		include('inc/data-tables/table-bottom.php');
		
		$sortColumns = 6;
		$noSortColumns = 5; // Column Number from left (column 1=0) 
		$scrollHeight = '500px';
		$tabTable = true;
		
		while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
			foreach ($variables['displayArray'] as $field) 
				$$field = $row[$field];
			include('list-item/client.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 .'</div>';
			else 
				$tables .= '<div id="tabs-'. $key .'"><p class="center">There are currently no Active Clients Listed</p></div>';
		}
		$reporttabs .= '</ul>';
		
		$content .= '<div class="row"><div class="col-lg-12">';
		
		$content .= '<div id="tabs">' . $reporttabs . $tables . '</div>';

		$content .= '</div></div>';
	}
	include('inc/data-tables/dataTables.php');
?>