<?php

// If this script is being called via Ajax
if (!isset($parentClients)) {
	$parentClients = getPclientArray($con);
	$variables = getVariables('loginfo',$page);
	$sql = '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.infoID='. $editID;
	$res = $con->query($sql);
	$r = $res->fetch_array(MYSQLI_ASSOC);
	foreach($variables['displayArray'] as $value) {
		$$value =  $r[$value];
	}
}

$adminLinks = ''; 
			 
foreach ($parentClients as $key => $value) {
	if (($subClientOf == $key) || ($clientID == $key)) 
		$tableName = cleanClientName($value);
}
if(empty($tableName))
	$tableName = 'other';

$section = ((isset($op)) ? (($op == 'add') ? $tableName : $section) : (isset($section) ? $section : ''));
		
$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="loginfo" data-adminact="edit" data-page="loginfo" data-section="'. $tableName .'" data-editid="' . $infoID . '" title="Edit Login Info"><i class="fa fa-pencil-square-o"></i></a> ';
$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="loginfo" data-adminact="delete" data-page="loginfo" data-section="'. $tableName .'" data-editid="' . $infoID . '" title="Delete Login Info"><i class="fa fa-trash"></i></a> ';
				
// Format Website
if (!empty($website))
	$website = '<p><a href="http://' . $website . '" target="_blank">' . $website . '</a></p>';
else
	$website = '';	
			
// Client Abbreviation
if (!empty($clientAbbr))
	$abbr = ' ('. $clientAbbr .')';
else
	$abbr = '';
			
$listitem = '<tr id="record-'. $infoID .'">
				<td>' . $clientName . $abbr . '</td>
				<td><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="loginfo" data-adminact="edit" data-page="loginfo" data-section="'. $tableName .'" data-editid="' . $infoID . '">' . $infoDesc .'</td>
				<td>'. $website .'</td>
				<td>' . $projectName . '</td>
				<td class="adminActions">'. $adminLinks .'</td>
			</tr>';
 
?>