<?php

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

$adminAct = $_REQUEST['adminAct']; 
$fieldArray = array('expName','expDesc','clientID','projectID','expDate','expAmount','expReimbursable'); 

if ($adminAct == 'new') {
	$op = 'add';
	$editID = ''; 
	$editInpID = '';
	foreach ($fieldArray as $value) {
		if ($value == 'expReimbursable')
			$$value = 0;
		elseif ($value == 'clientStatus')
			$$value = 2;
		else
			$$value = ''; 
	}
	$expClient = getCompany($clientID,$con);
	$projType = ''; 
	$expProject = getProject($projectID,$projType,$con);
	$expDisp = 1;
	$subBtn = 'Add Expense'; 
	$modalTitle = 'Create New Expense';
} else {
	$op = '';
	$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="editID" value="'. $editID .'" />';
	
	$query = 'SELECT * FROM expenses WHERE expID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
			
		foreach($fieldArray as $value) {
			$$value =  $row[''. $value .''];
		}
		$expClient = getCompany($clientID,$con);
		$projType = '';
		$expProject = getProject($projectID,$projType,$con);
		$expReimbCK = (($expReimbursable == 1) ? ' checked' : '');
		$expReimbYes = (($expReimbursable == 1) ? ' selected' : '');
		$expReimbNo = (($expReimbursable == 0) ? ' selected' : '');
		$expDisp = $row['expDisp'];

		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = ""; 
			$subBtn = 'Reactivate Expense';
			$modalTitle = 'Reactivate Expense: '. $expName;
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit Expense: '. $expName;
		} elseif ($adminAct == 'delete') {
			$op = 'delete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Delete Expense';
			$modalTitle = 'Delete Expense: '. $expName . '?';
		}
	}
}
include('form/expense.php'); 

?>