<?php
include('../globals/error-reporting.php');
$admin = 'todo'; 
include ($PATH .'globals/globals.php');
$adminAct = $_REQUEST['adminAct']; 
$page = ($_POST['page'] ? $_POST['page'] : '');
$variables = getVariables('todo',$page);	

if ($adminAct == 'new') {
	$op = 'add';
	$editID = ''; 
	$editInpID = ''; 
	$tdDoneINp = '<input type="hidden" name="todoDone" value="0" />';
	foreach($variables['fieldArray'] as $value) { 
		if ($value == 'clientID')
			$client = $defaultCompany;
		elseif ($value == 'addDate')
			$$value = $today;
		else 	
			$$value = '';
	}
	$subBtn = 'Add To-Do Item'; 
	$modalTitle = 'Create New To-Do';
} else {
	$op = '';
	$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="editID" value="'. $editID .'" />';
	
	$query = 'SELECT * FROM todo_list WHERE todoID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		foreach($variables['fieldArray'] as $value) { 
			if ($value == 'clientID')
				$client = $row['clientID'];
			else 	
				$$value = $row[''. $value .''];
		}
		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = ""; 
			$subBtn = 'Reactivate To-Do';
			$modalTitle = 'Reactivate To-Do: '. $todoName;
			$tdDoneINp = '<input type="hidden" name="todoDone" value="'. $todoDone .'" />'; 
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit To-Do: '. $todoName;
			$tdDoneINp = '<input type="hidden" name="todoDone" value="'. $todoDone .'" />'; 
		} elseif ($adminAct == 'complete') {
			$op = 'complete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Complete To-Do';
			$modalTitle = 'Complete To-Do: '. $todoName . '?';
			$tdDoneINp = '<input type="hidden" name="todoDone" value="1" />'; 
		} 
	}
}
$projType = '';
$todoClient = getCompany($client,$con);
$todoProject = getProject($projectID,$projType,$con);

include('form/todo.php');

?>