<?
if (!defined('IN_BANDTOPIA'))
{
	exit;
}

	if(ADMIN_FULL == "admin" || ADMIN_STAFF == "staff") 
	{
		$nav .= '&nbsp;&gt;&nbsp;<a href="index.php?action=staff&function=stafflist">Staff List</a>';
		/******************************************************/
		/*  Staff List Page
		/******************************************************/
		if($_GET['function'] == 'stafflist' || $_GET['function'] == '') 
		{
			$staffObj = new StaffObj();
			$staffList = $staffObj -> listStaff();
			$template -> assign_block_vars("staff_list",array());
			if(count($staffList) > 0)
			{
				foreach($staffList as $key => $value)
				{
					$template -> assign_block_vars("staff_list.staff", array(
						"STAFF_ID" => $value->get_staff_id(),
						"STAFF_NAME" => $value->get_staff_name(),
						"STAFF_CITY" => $value->get_staff_city(),
						"STAFF_STATE" => $value->get_staff_state(),
						"STAFF_EMAIL" => $value->get_staff_email(),
						"STAFF_PHONE" => $value->get_staff_phone(),
						"STAFF_POSITION" => $value->get_staff_position()));
				}
			}
			$template -> assign_var_from_handle('STAFF_ADMIN_PAGE', 'staffadminpage');
		}
		/******************************************************/
		/*  Staff View/Edit Page
		/******************************************************/
		elseif($_GET['function'] == 'staffview' || $_GET['function'] == 'staffedit' || $_GET['function'] == 'staffadd')
		{
			if($_POST['post_form'] == 'true' && ($_POST['staffadd'] == 'true' || $_POST['staff_id'] != ''))
			{
				$staffObj = new StaffObj();
				$staffObj->set_staff_id($_POST['staff_id']);
				$staffObj->set_staff_name($_POST['staff_name']);
				$staffObj->set_staff_address($_POST['staff_address']);
				$staffObj->set_staff_city($_POST['staff_city']);
				$staffObj->set_staff_state($_POST['staff_state']);
				$staffObj->set_staff_zip($_POST['staff_zip']);
				$staffObj->set_staff_phone($_POST['staff_phone']);
				$staffObj->set_staff_phone2($_POST['staff_phone2']);
				$staffObj->set_staff_email($_POST['staff_email']);
				$staffObj->set_staff_position($_POST['staff_position']);
				$staffMsg = $staffObj->updateStaff();
				
				$template -> assign_block_vars("staff_msg", array(
					"STAFF_MSG" => $staffMsg));
			}
			else
			{
				if($_GET['function'] == 'staffadd')
				{
					$template -> assign_block_vars("staff_view", array(
						"DISABLED" => " DISABLED"));
					$template -> assign_block_vars("staff_view.edit", array());
					$template -> assign_block_vars("staff_view.add", array());
				}
				elseif($_GET['staff_id'] == '' && $_POST['staff_id'] == '')
				{
					header("Location: index.php?action=staff&function=stafflist");
				}
				else
				{	
					$staffObj = new StaffObj();
					$staffObj->set_staff_id($_GET['staff_id']);
					$staffObj->getStaff();
					if($staffObj->get_staff_name() == '')
					{
						$template -> assign_block_vars("page_error",array());
						$template -> assign_block_vars("page_error.error_msg", array(
							"ERROR_MSG" => "No staff found with the provided id.  Please try again."));
					}
					else
					{
						$template -> assign_block_vars("staff_view", array(
							"STAFF_ID" => $staffObj->get_staff_id(),
							"STAFF_NAME" => $staffObj->get_staff_name(),
							"STAFF_ADDRESS" => $staffObj->get_staff_address(),
							"STAFF_CITY" => $staffObj->get_staff_city(),
							"STAFF_STATE" => $staffObj->get_staff_state(),
							"STAFF_ZIP" => $staffObj->get_staff_zip(),
							"STAFF_PHONE" => $staffObj->get_staff_phone(),
							"STAFF_PHONE2" => $staffObj->get_staff_phone2(),
							"STAFF_EMAIL" => $staffObj->get_staff_email(),
							"STAFF_POSITION" => $staffObj->get_staff_position()));
							
						if($_GET['function'] == 'staffedit') 
						{
							$template -> assign_block_vars("staff_view.edit", array());
							$nav .= '&nbsp;&gt;&nbsp;<a href="index.php?action=staff&function=staffview&staff_id='.$_GET['staff_id'].'">Staff View</a>';
						}
						else
						{
							$template -> assign_block_vars("staff_view.view", array());
						}
					}
				}
			}
			$template -> assign_var_from_handle('STAFF_ADMIN_PAGE', 'staffadminpage');
		}
		/******************************************************/
		/*  User Del(Deactivate)
		/******************************************************/
		elseif($_GET['function'] == 'staffdel')
		{
			if($_GET['staff_id'] == '')
			{
				$template -> assign_block_vars("page_error",array());
				$template -> assign_block_vars("page_error.error_msg", array(
					"ERROR_MSG" => "No staff provided.  Please try again."));
			}
			else
			{
				$staffObj = new StaffObj();
				$staffObj->set_staff_id($_GET['staff_id']);
				$staffMsg = $staffObj->delStaff();
				$template -> assign_block_vars("staff_msg", array(
					"STAFF_MSG" => $staffMsg));
			}
			$template -> assign_var_from_handle('STAFF_ADMIN_PAGE', 'staffadminpage');
		}
	} 
	else
	{
		$template -> assign_block_vars("page_error",array());
		$template -> assign_block_vars("page_error.permission", array());
	}
?>