<?php

include ($PATH .'globals/globals.php');

$admin = 'task';
$adminAct = $_REQUEST['adminAct']; 

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

if ($adminAct == 'new') {
	$op = 'add';
	$editInpID = '<input type="hidden" name="op" value="'. $op .'" />'; 
	foreach($variables['fieldArray'] as $value) { 
		if ($value == 'display')
			$$value = 1;
		else 	
			$$value = '';
	}
	$client = ''; 
	$subBtn = 'Add Task'; 
	$modalTitle = 'Create New Task';
} else {
	$op = '';
	$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="editID" value="'. $editID .'" />';
	
	$query = 'SELECT t.*, p.clientID AS client FROM tasks t LEFT JOIN projects p ON (t.projectID = p.projectID) WHERE taskID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		foreach($variables['fieldArray'] as $value) {
			$$value = $row[''. $value .''];
		}
		$client = $row['client'];
		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = ""; 
			$subBtn = 'Reactivate Task';
			$modalTitle = 'Reactivate Task: '. $taskName;
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit Task: '. $taskName;
		} elseif ($adminAct == 'delete') {
			$op = 'delete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Delete Task';
			$modalTitle = 'Delete Task: '. $taskName . '?';
		}
	}
}

$projFilter = (($op=='add') ? '1,4' : ''); 	
$taskProject = getProjectLists($projectID,$projFilter,$con);

if (!empty($client))
	$taskClient = getClientName($client,$con);
else
	$taskClient = ''; 

$taskStatus = getTaskStatus($taskStatus,$con);
$taskPriority = getProjPriority($priority,$con);
	
if ($TaskCurrent == 1)
	$currentCheck = ' checked';
else
  	$currentCheck = '';
	
include('form/task.php');

?>