<?php

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

//$fieldArray = array('feeID','feeDescID','clientID','feeAmt','feeDesc','feeStartDate','feeRecID','feeLastRec','feeNextRec','projectID','feeActive','display');
//$excludeArray = array('submit','feeActive','display','adminType','activateFee');
$variables = getVariables('ongoing',$page);

$adminAct = $_REQUEST['adminAct']; 

if ($adminAct == 'new') {
	$op = 'add';
	$editInpID = '<input type="hidden" name="op" value="'. $op .'" />'; 
	foreach($variables['fieldArray'] as $value) { 
		if ($value == 'feeAmt')
			$$value = 0;
		elseif (($value == 'feeActive') || ($value == 'display'))
			$$value = 1; 
		elseif ($value == 'clientID')
			$feeClientID = ''; 
		else 	
			$$value = '';
	}
	$feeNext = ''; 
	$feeLast = ''; 
	$subBtn = 'Add Ongoing Fee'; 
	$modalTitle = 'Create New Ongoing Fee';
	$feeActivated = false;
} else {
	$op = '';
	$editID = $_REQUEST['editID']; 
	$editInpID = '<input type="hidden" name="editID" value="'. $editID .'" />';
	
	$query = 'SELECT * FROM ongoingFees WHERE feeID=' . $editID; 
	$result = $con->query($query);
		
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		foreach($variables['fieldArray'] as $value) { 
			if ($value == 'clientID') {
				$feeClientID = $row[''. $value .''];
			} else {
			 	$$value = $row[''. $value .''];
			}
		}
		
		if ($adminAct == 'react') {
			$op = 'react';
			$delConfirm = ""; 
			$subBtn = 'Reactivate Fee';
			$modalTitle = 'Reactivate Fee';
		} elseif ($adminAct == 'edit') {
			$op = 'edit';
			$delConfirm = ""; 
			$subBtn = 'Save Changes';
			$modalTitle = 'Edit Fee';
		} elseif ($adminAct == 'deact') {
			$op = 'deact';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Deactivate Fee';
			$modalTitle = 'Deactivate Fee?';
		} elseif ($adminAct == 'delete') {
			$op = 'delete';
			$delConfirm = ' onSubmit="return sure()"';
			$subBtn = 'Delete Fee';
			$modalTitle = 'Delete Fee?';
		}
	}
	if ($feeNextRec != "0000-00-00")
		$feeNext = Date::convert($feeNext, 'Y-m-d', 'm/d/Y');
	else 
		$feeNext = '';
	
	if ($feeLastRec != "0000-00-00")
		$feeLast = Date::convert($feeLast, 'Y-m-d', 'm/d/Y');
	else 
		$feeLast = '';
	$feeActivated = checkOGF($feeID,$con);
}
$projType = ''; 	
$feeType = getFeeType($feeDescID,$con);
$feeClient = getCompany($feeClientID,$con);
$feeRec = getFeeRec($feeRecID,$con);
$feeProject = getProject($projID,$projType,$con);
$billRate = getRates($currentRateID,$con);

include('form/ongoing.php'); 
	
?>