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

	$type = $_REQUEST['type'];
	$page = (isset($_POST['page']) ? $_POST['page'] : '');
	$variables = getVariables('loginfo',$page);

	$adminBtns .= '<a href="#" class="admin btn btn-default" data-toggle="modal" data-target="#adminModal" data-admintype="loginfo" data-page="loginfo" data-section="" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Login Info</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 l.*, c.clientName, c.clientAbbr, c.clientID, c.subClientOf, p.projectName, p.projectID FROM loginfo l LEFT JOIN clients c ON (c.clientID = l.clientID) LEFT JOIN projects p ON (p.projectID = l.projectID) WHERE l.display=1 ORDER BY c.subClientOf, c.clientName, l.infoDesc';
	$result = $con->query($query);
	if ($result) {
		
		// Define Tables
		foreach ($parentClients as $key => $value) {
			$tableName = cleanClientName($value);
			$$tableName = ''; 
		} 
		$other = ''; 
		$clientsInactive = '';

		$tableFieldNames = '<th class="col-sm-3">Name</th>
							<th class="col-sm-3">Description</th>
							<th class="col-sm-3">Website</th>
							<th class="col-sm-2">Project</th>
							<th class="col-sm-1">&nbsp;</th>'; 
		
		include('inc/data-tables/table-top.php');
		include('inc/data-tables/table-bottom.php');
							
		$sortColumns = 4;
		$noSortColumns = 4; // Column Number from left (column 1=0) 
		$scrollHeight = 500;
		$tabTable = true;
		 
		while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
			foreach ($variables['displayArray'] as $field) 
				$$field = $row[$field];
			include('list-item/loginfo.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');
?>