<?php
/**
* @version 1.0.0
* @package RStickets! 1.0.0
* @copyright (C) 2007-2008 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

// DIE()
defined('_JEXEC') or die('Restricted access');

// MUST BE LOGGED IN & ADMIN PERMISSIONS
if (!isset($_SESSION['RST_User']['UserId']) || (isset($_SESSION['RST_User']['Admin']) && $_SESSION['RST_User']['Admin'] == 0)) rst_admin_redirect('?option=com_rstickets');
?>
<h4 class="rst_h4"><?php echo LBL_DEPARTMENTS; ?></h4>

<table cellpadding="4" cellspacing="0" class="tableGrey">
	<thead>
	<tr class="tableHead">
		<td class="tdGrey"><?php echo LBL_ORDERING; ?></td>
		<td class="tdGrey"><?php echo LBL_NAME; ?></td>
		<td class="tdGrey"><?php echo LBL_PREFIX; ?></td>
		<td class="tdGrey"><?php echo LBL_TICKET_ASSIGNMENT_TYPE; ?></td>
		<td class="tdGrey"><?php echo LBL_TICKET_GENERATION_RULE; ?></td>
		<td class="tdGrey"><?php echo LBL_PRIORITY; ?></td>
		<td class="tdGrey"><?php echo LBL_CUSTOMER_RECEIVES; ?></td>
		<td class="tdGrey"><?php echo LBL_STAFF_RECEIVES; ?></td>
		<td class="tdGrey"><?php echo LBL_FILE_UPLOAD; ?></td>
		<td class="tdGrey"><?php echo LBL_ACTIONS; ?></td>
	</tr>
	</thead>
	<tbody>
		<?php
		$departments = rst_get_departments();
		if (count($departments) > 0)
			foreach ($departments as $key => $department)
			{
				?>
				<tr class="<?php echo $key % 2 == 0 ? 'trEven' : 'trOdd'; ?>">
				<td class="tdGrey"><?php echo $key + 1; ?> <?php echo $key > 0 ? '<a href="'.RST_BACKEND_SCRIPT_PATH.'?option=com_rstickets&&task=departments&action=order_department&id='.$department['DepartmentId'].'&direction=up" class="upIcon"></a>' : ''; ?> <?php echo $key < (count($departments) - 1)  ? '<a href="'.RST_BACKEND_SCRIPT_PATH.'?option=com_rstickets&task=departments&action=order_department&id='.$department['DepartmentId'].'&direction=down" class="downIcon"></a>' : ''; ?></td>
				<td class="tdGrey"><a href="<?php echo RST_BACKEND_SCRIPT_PATH; ?>?option=com_rstickets&task=add_department&amp;id=<?php echo $department['DepartmentId']; ?>"><?php echo $department['DepartmentName']; ?></a></td>
				<td class="tdGrey"><?php echo $department['DepartmentPrefix']; ?></td>
				<td class="tdGrey"><?php echo $department['TicketAssignmentType']; ?></td>
				<td class="tdGrey"><?php echo $department['TicketGenerationRule']; ?></td>
				<td class="tdGrey"><?php echo $priority_array_lang[$department['DepartmentPriority']]; ?></td>
				<td class="tdGrey"><?php echo $department['UserEmailTicket'] == 1 ? LBL_YES : LBL_NO; ?></td>
				<td class="tdGrey"><?php echo $department['StaffEmailTicket'] == 1 ? LBL_YES : LBL_NO; ?></td>
				<td class="tdGrey"><?php echo $department['FileUpload'] == 'yes' ? LBL_EVERYONE : ($department['FileUpload'] == 'users' ? LBL_REGISTERED : ($department['FileUpload'] == 'no' ? LBL_NOBODY : '')); ?></td>
				<td><a href="<?php echo RST_BACKEND_SCRIPT_PATH; ?>?option=com_rstickets&amp;task=add_department&amp;id=<?php echo $department['DepartmentId']; ?>" class="editButton"><?php echo BTN_EDIT; ?></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="return confirm('<?php echo LBL_SURE; ?>')" href="<?php echo RST_BACKEND_SCRIPT_PATH; ?>?option=com_rstickets&amp;task=departments&amp;action=delete_department&amp;id=<?php echo $department['DepartmentId']; ?>" class="deleteButton"><?php echo BTN_DELETE; ?></a></td>
				</tr>
				<?php
			}
		else
			{
			?>
			<tr><td colspan="6"><strong><?php echo LBL_NO_DEPARTMENTS; ?></strong></td></tr>
			<?php
			}
		?>
	</tbody>
</table>