<?php

// If this script is being called via Ajax
if ($ajaxUpdate) {
	$admin = 'task';
	$page = (isset($_POST['page']) ? $_POST['page'] : $admin);
	$parentClients = getPclientArray($con);
	$variables = getVariables($admin,$page);
	$sql = "SELECT * FROM tasks t LEFT JOIN projects p ON (t.projectID = p.projectID) LEFT JOIN clients c ON (p.clientID = c.clientID) LEFT JOIN taskStatus ts ON (t.taskStatus = ts.taskStatID) LEFT JOIN projectStatus AS ps on (p.projectStatus = ps.pstatID) WHERE t.taskID=". $editID;
	$res = $con->query($sql);
	$r = $res->fetch_array(MYSQLI_ASSOC);
	
	foreach($variables['displayArray'] as $value) {
		$$value =  $r[$value];
	}
}

// Company Name or Abbreviation
$client = $clientName;
if (!empty($clientAbbr)) 
	$client .= ' ('. $clientAbbr . ')';

// Due Date
if ($dueDate == "0000-00-00")
	$dueDate = "N/A";
else
	$dueDate = Date::convert($dueDate, 'Y-m-d', 'm/d/Y');
			
$adminLinks = '';  
			
if ($display == 1) {
	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="task-time" data-adminact="" data-page="'. $page .'" data-section="'. $tableName .'" data-editid="' . $taskID . '" title="Hours"><i class="fa fa-clock-o"></i></a> ';
					
	$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admin .'" data-adminact="edit" data-page="'. $page .'" data-section="'. $tableName .'" data-editid="'. $taskID .'"><i class="fa fa-pencil-square-o"></i></a> ';	
					
	$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admin .'" data-adminact="delete" data-page="'. $page .'" data-section="'. $tableName .'" data-editid="' . $taskID . '" title="Delete Task"><i class="fa fa-trash"></i></a>';
} else {
	$adminLinks .= ' <a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admin .'" data-adminact="react" data-page="'. $page .'" data-section="'. $tableName .'" data-editid="' . $taskID . '" title="Reactivate Task"><i class="fa fa-refresh"></i></a>';
}
	
$listItem = '<tr id="record-'. $taskID .'">
				<td><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="'. $admin .'" data-adminact="edit" data-page="'. $page .'" data-section="'. $tableName .'" data-editid="' . $taskID . '">' . $taskName . '</a></td>
				<td>' . $projectName . '</td>
				<td>' .$client . '</td>
				<td>' . $taskEstimate . '</td>
				<td>' . $dueDate . '</td>
				<td class="adminActions">'. $adminLinks .'</td>
			</tr>';

?>