<?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');

if ($_GET['page'] == 'my_tickets' && !rst_is_logged()) rst_redirect('index.php?option=com_rstickets&page=add_ticket');
if ($_GET['page'] == 'tickets' && !rst_is_staff_logged()) rst_redirect('index.php?option=com_rstickets&page=my_tickets');

$End = !rst_is_staff_logged() ? 'Frontend' : 'Backend';
if ($_GET['page'] == 'my_tickets') $search = 'search_my_tickets';
if ($_GET['page'] == 'tickets')	$search = 'search_tickets';

$status_array = array('open','on-hold','closed');
$priority_array = array('low','normal','high');

if (!isset($_SESSION['search_tickets']['Unassigned'])) $_SESSION['search_tickets']['Unassigned'] = 1;
if (isset($_GET['order'])) $_SESSION[$search]['order'] = $_GET['order'];
if (isset($_GET['direction'])) $_SESSION[$search]['direction'] = $_GET['direction'];

if (isset($_POST) && count($_POST) > 0)
{
	if ($search == 'search_tickets') $_SESSION['search_tickets']['Unassigned'] = 0;
	$_SESSION[$search]['TicketCode'] = isset($_POST['TicketCode']) ? htmlentities($_POST['TicketCode']) : '';
	$_SESSION[$search]['TicketSubject'] = isset($_POST['TicketSubject']) ? htmlentities($_POST['TicketSubject']) : '';
	$_SESSION[$search]['TicketMessage'] = isset($_POST['TicketMessage']) ? htmlentities($_POST['TicketMessage']) : '';
	$_SESSION[$search]['TicketTime'] = isset($_POST['TicketTime']) ? htmlentities($_POST['TicketTime']) : '';
	$_SESSION[$search]['from'] = isset($_POST['from']) ? htmlentities($_POST['from']) : '';
	$_SESSION[$search]['to'] = isset($_POST['to']) ? htmlentities($_POST['to']) : '';
	$departments = array();
	if (!isset($_SESSION['RST_User']['Group']['GroupId']) || $_GET['page'] == 'my_tickets')
	{
		$departments_array = rst_get_departments();
			foreach ($departments_array as $department)
				$departments[] = $department['DepartmentId'];
	}
	else
	{
		if (isset($_SESSION['RST_User']['Department']) && count($_SESSION['RST_User']['Department']) > 0)
			foreach ($_SESSION['RST_User']['Department'] as $department)
				$departments[] = $department['DepartmentId'];
	}
	$_SESSION[$search]['DepartmentId'] = isset($_POST['DepartmentId']) ? $_POST['DepartmentId'] : $departments;
	if (isset($_POST['TicketStatus']) && count($_POST['TicketStatus']) > 0)
		foreach ($_POST['TicketStatus'] as $key => $poststatus)
			if (!in_array($poststatus,$status_array)) unset($_POST['TicketStatus'][$key]);
	$_SESSION[$search]['TicketStatus'] = isset($_POST['TicketStatus']) ? $_POST['TicketStatus'] : array('open','on-hold');
	
	if (isset($_POST['TicketPriority']) && count($_POST['TicketPriority']) > 0)
	foreach ($_POST['TicketPriority'] as $key => $postpriority)
		if (!in_array($postpriority,$priority_array)) unset($_POST['TicketPriority'][$key]);
	$_SESSION[$search]['TicketPriority'] = isset($_POST['TicketPriority']) ? $_POST['TicketPriority'] : $priority_array;
	
	// CUSTOMER
	$_SESSION[$search]['CustomerUsername'] = isset($_POST['CustomerUsername']) ? htmlentities($_POST['CustomerUsername']) : '';
	$_SESSION[$search]['CustomerFullname'] = isset($_POST['CustomerFullname']) ? htmlentities($_POST['CustomerFullname']) : '';
	$_SESSION[$search]['CustomerEmail'] = isset($_POST['CustomerEmail']) ? htmlentities($_POST['CustomerEmail']) : '';
	// STAFF
	$_SESSION[$search]['StaffUsername'] = isset($_POST['StaffUsername']) ? htmlentities($_POST['StaffUsername']) : '';
	$_SESSION[$search]['StaffFullname'] = isset($_POST['StaffFullname']) ? htmlentities($_POST['StaffFullname']) : '';
	$_SESSION[$search]['StaffEmail'] = isset($_POST['StaffEmail']) ? htmlentities($_POST['StaffEmail']) : '';	
}
else
{
	$_SESSION[$search]['TicketCode'] = isset($_SESSION[$search]['TicketCode']) ? $_SESSION[$search]['TicketCode'] : '';
	$_SESSION[$search]['TicketSubject'] = isset($_SESSION[$search]['TicketSubject']) ? $_SESSION[$search]['TicketSubject'] : '';
	$_SESSION[$search]['TicketMessage'] = isset($_SESSION[$search]['TicketMessage']) ? $_SESSION[$search]['TicketMessage'] : '';
	$_SESSION[$search]['TicketTime'] = isset($_SESSION[$search]['TicketTime']) ? $_SESSION[$search]['TicketTime'] : '';
	$_SESSION[$search]['from'] = isset($_SESSION[$search]['from']) ? $_SESSION[$search]['from'] : '';
	$_SESSION[$search]['to'] = isset($_SESSION[$search]['to']) ? $_SESSION[$search]['to'] : '';
	$departments = array();
	if (!isset($_SESSION['RST_User']['Group']['GroupId']) || $_GET['page'] == 'my_tickets')
	{
		$departments_array = rst_get_departments();
			foreach ($departments_array as $department)
				$departments[] = $department['DepartmentId'];
	}
	else
	{
		if (isset($_SESSION['RST_User']['Department']) && count($_SESSION['RST_User']['Department']) > 0)
			foreach ($_SESSION['RST_User']['Department'] as $department)
				$departments[] = $department['DepartmentId'];
	}
	$_SESSION[$search]['DepartmentId'] = isset($_SESSION[$search]['DepartmentId']) ? $_SESSION[$search]['DepartmentId'] : $departments;
	$_SESSION[$search]['TicketStatus'] = isset($_SESSION[$search]['TicketStatus']) ? $_SESSION[$search]['TicketStatus'] : array('open','on-hold');
	$_SESSION[$search]['TicketPriority'] = isset($_SESSION[$search]['TicketPriority']) ? $_SESSION[$search]['TicketPriority'] : $priority_array;
	// CUSTOMER
	$_SESSION[$search]['CustomerUsername'] = isset($_SESSION[$search]['CustomerUsername']) ? $_SESSION[$search]['CustomerUsername'] : '';
	$_SESSION[$search]['CustomerFullname'] = isset($_SESSION[$search]['CustomerFullname']) ? $_SESSION[$search]['CustomerFullname'] : '';
	$_SESSION[$search]['CustomerEmail'] = isset($_SESSION[$search]['CustomerEmail']) ? $_SESSION[$search]['CustomerEmail'] : '';
	// STAFF
	$_SESSION[$search]['StaffUsername'] = isset($_SESSION[$search]['StaffUsername']) ? $_SESSION[$search]['StaffUsername'] : '';
	$_SESSION[$search]['StaffFullname'] = isset($_SESSION[$search]['StaffFullname']) ? $_SESSION[$search]['StaffFullname'] : '';
	$_SESSION[$search]['StaffEmail'] = isset($_SESSION[$search]['StaffEmail']) ? $_SESSION[$search]['StaffEmail'] : '';
}
?>
<h4 class="rst_h4"><?php echo $_GET['page'] == 'my_tickets' ? LBL_MY_TICKETS : LBL_TICKETS; ?></h4>

<?php
if (isset($_SESSION['RST_User']['Group']['GroupId']))
{
	$searches = rst_get_searches($_GET['page'],$_SESSION['RST_User']['UserId']);
	if (count($searches) > 0)
	{
		echo '<div style="clear: both; width: 100%; margin-bottom: 10px;">
		<select name="SearchId" onchange="rst_predefined_search(this'.(isset($_GET['Itemid']) && is_numeric($_GET['Itemid']) ? ",'".intval($_GET['Itemid'])."'" : '').');">
		<option value="">'.LBL_PREDEFINED_SEARCHES.'</option>';
		foreach ($searches as $searching)
			echo '<option '.(isset($_SESSION[$search]['predefined']) && $_SESSION[$search]['predefined']==$searching['SearchId'] ? 'selected="selected"' : '').' value="'.$searching['SearchId'].'">'.$searching['SearchName'].'</option>';
		echo '</select> <a class="editButton" href="'.JRoute::_('index.php?option=com_rstickets&page='.($_GET['page'] == 'tickets' ? 'searches' : 'my_searches')).'">'.LBL_MANAGE_SEARCHES.'</a></div>';
	}
}
?>

<a href="<?php echo JRoute::_('index.php?option=com_rstickets&page=search_'.$_GET['page']); ?>" class="searchButton"><?php echo LBL_ADVANCED_SEARCH; ?></a>
<?php
// CHECK IF CLOSED TICKETS ARE HIDDEN
if (rst_show_closed_tickets($search))
	echo ' <a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=hide_closed_'.$_GET['page']).'" class="hiddenButton">'.LBL_HIDE_CLOSED_TICKETS.'</a>';
else
	echo ' <a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=show_closed_'.$_GET['page']).'" class="hiddenButton">'.LBL_SHOW_CLOSED_TICKETS.'</a>';
	
if (rst_can_see_all())
	echo ' <a href="'.JRoute::_('index.php?option=com_rstickets&page=tickets&action=show_all_tickets').'" class="unassignedButton">'.($_SESSION['search_tickets']['Unassigned'] == 1 ? LBL_SHOW_ALL_TICKETS : LBL_SHOW_UNASSIGNED_TICKETS).'</a>';

if (rst_is_searching($search))
{
	echo ' <a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=reset_search_'.$_GET['page']).'" class="deleteButton">'.BTN_RESET_SEARCH_FILTERS.'</a>';
	if (isset($_SESSION['RST_User']['Group']['GroupId']))
		echo ' <a href="'.JRoute::_('index.php?option=com_rstickets&page=save_search_'.$_GET['page']).'" class="addButton">'.BTN_SAVE_SEARCH.'</a>';
}

$pag = (isset($_GET['pag']) ? intval($_GET['pag']) : 1);

$mystafftickets = ($_GET['page'] == 'tickets' ? 0 : (rst_is_staff_logged() ? 1 : 0));
$mycustomertickets = ($_GET['page'] == 'tickets' ? 0 : (!rst_is_staff_logged() ? 1 : 0));

$tickets = rst_get_tickets($_SESSION[$search]['TicketCode'],$_SESSION[$search]['TicketSubject'],$_SESSION[$search]['TicketMessage'],$_SESSION[$search]['TicketTime'],$_SESSION[$search]['from'],$_SESSION[$search]['to'],$_SESSION[$search]['DepartmentId'],$_SESSION[$search]['TicketStatus'],$_SESSION[$search]['TicketPriority'],$pag,(isset($_SESSION[$search]['order']) ? $_SESSION[$search]['order'] : 'TicketTime'),(isset($_SESSION[$search]['direction']) ? $_SESSION[$search]['direction'] : 'DESC'),$_SESSION[$search]['StaffUsername'],$_SESSION[$search]['StaffFullname'],$_SESSION[$search]['StaffEmail'],$_SESSION[$search]['CustomerUsername'],$_SESSION[$search]['CustomerFullname'],$_SESSION[$search]['CustomerEmail'],$mystafftickets,$mycustomertickets);
?>

<div id="bulkChangeDiv">
<?php
if (isset($_SESSION['RST_User']['Group']['GroupId']) && ($_SESSION['RST_User']['Group']['CanAssignTickets'] == 1 || $_SESSION['RST_User']['Group']['CanChangeTicketStatus'] == 1 || $_SESSION['RST_User']['Group']['CanUpdateTicket'] == 1 || $_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1))
{
?>
<form method="post" action="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=update_tickets'.(!empty($pag) ? '&pag='.$pag : '')); ?>">
<table cellpadding="4" cellspacing="0" class="tableTickets">
	<thead>
	<tr class="tableHead"><td colspan="9"><?php echo LBL_BULK_CHANGE; ?></td></tr>
	</thead>
	<tbody>
	<tr>
	<?php
	if ($_SESSION['RST_User']['Group']['CanAssignTickets'] == 1)
	{
	?>
		<td class="tdGrey"><?php echo LBL_ASSIGN; ?>
		<br />
		<select name="UserId">
			<option value=""><?php echo LBL_UNCHANGED; ?></option>
			<option value="0"><?php echo LBL_UNASSIGNED; ?></option>
			<?php
			$departments = $_SESSION['RST_User']['Department'];
			$optdepartments = array();
			foreach ($departments as $department)
				if (in_array($department['DepartmentId'],$_SESSION[$search]['DepartmentId']))
					$optdepartments[] = array('DepartmentId' => $department['DepartmentId'],'DepartmentName' => $department['DepartmentName']);
			
			foreach ($optdepartments as $optdepartment)
			{
				echo '<optgroup label="'.$optdepartment['DepartmentName'].'">';
				$users = rst_get_staff(0,array($optdepartment['DepartmentId']),array('CanAnswerTicket'));
				if (count($users) > 0)
					foreach ($users as $user)
						echo '<option value="'.$user['UserId'].'">('.$user['Username'].') ('.$user['OpenTickets'].')</option>';
						//															   ')'.$user['Fullname'].'('
				echo '</optgroup>';
			}
			?>
		</select>
		</td>
	<?php
	}
	if ($_SESSION['RST_User']['Group']['CanUpdateTicket'] == 1)
	{
	?>
		<td class="tdGrey"><?php echo LBL_PRIORITY; ?>
		<br />
		<select name="TicketPriority">
			<option value=""><?php echo LBL_UNCHANGED; ?></option>
			<?php
			$priority_array = array('low','normal','high');
			foreach ($priority_array as $priority)
				echo '<option value="'.$priority.'">'.$priority_array_lang[$priority].'</option>';
			?>
		</select>
		</td>
	<?php
	}
	if ($_SESSION['RST_User']['Group']['CanChangeTicketStatus'] == 1)
	{
	?>
		<td class="tdGrey"><?php echo LBL_STATUS; ?>
		<br />
		<select name="TicketStatus">
			<option value=""><?php echo LBL_UNCHANGED; ?></option>
			<?php
			$status_array = array('open','on-hold','closed');
			foreach ($status_array as $status)
				echo '<option value="'.$status.'">'.$status_array_lang[$status].'</option>';
		?>
		</select>
		</td>
	<?php
	}
	if ($_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1)
	{
	?>
		<td class="tdGrey"><?php echo LBL_BULK_DELETE; ?>
		<br />
		<select name="TicketDelete">
			<option value=""><?php echo LBL_UNCHANGED; ?></option>
			<option value="selected"><?php echo LBL_DELETE_SELECTED; ?></option>
		</select>
		</td>
	<?php
	}
	?>
	<td><button type="submit"><?php echo BTN_UPDATE; ?></button></td>
	</tr>
	</tbody>
</table>
<?php
}
?>
</div>

<div class="rst_pag">
<?php
echo LBL_PAGE;
if ($pag > 1)
	echo '<a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&pag='.($pag-1)).'">&lt;</a>';

$totalpages = $tickets['totalpages'];
if ($pag > 2 && $pag + 2 < $totalpages) $totalpages = $pag + 2;
if ($pag < 3 && $totalpages > 5) $totalpages = 5;

if ($pag - 2 > 0) $start = $pag - 2;
if ($pag < 3) $start = 1;
if ($pag + 2 > $totalpages && $totalpages - 4 > 0) $start = $totalpages - 4;


for ($page=$start;$page<=$totalpages;$page++)
	echo '<a '.((!empty($pag) && $pag == $page) || (empty($pag) && $page == 1) ? 'id="rst_here"' : '').' href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&pag='.$page).'">'.$page.'</a>';
	
if (($page-1) < $tickets['totalpages'])
	echo '<a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&pag='.($pag+1)).'">&gt;</a>';
?>
</div>

<table cellpadding="4" cellspacing="0" class="tableTickets">
	<thead>
	<tr class="tableHead">
		<td class="tdGrey tdSmallWidth"><input class="smallCheck" type="checkbox" name="all" value="1" onclick="check_all_checkboxes(this,'tickets[]');" /></td>
		<?php if ($T_SETTINGS[$End.'_TicketTime'] == 1) { ?>
		<td class="tdGrey tdSmallWidth"><a <?php echo rst_is_sort('TicketTime',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=TicketTime&direction='.(rst_is_sort('TicketTime',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_DATE_TIME; ?></a></td>
		<?php } if ($T_SETTINGS[$End.'_TicketSubject'] == 1 || $T_SETTINGS[$End.'_TicketCode'] == 1) { ?>
		<td class="tdGrey">
		<?php } if ($T_SETTINGS[$End.'_TicketCode'] == 1) { ?>
		<a <?php echo rst_is_sort('TicketCode',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=TicketCode&direction='.(rst_is_sort('TicketCode',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_TICKET_CODE; ?></a>
		<?php } if ($T_SETTINGS[$End.'_TicketSubject'] == 1) { ?>
		<a <?php echo rst_is_sort('TicketSubject',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=TicketSubject&direction='.(rst_is_sort('TicketSubject',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_SUBJECT; ?></a>
		<?php } if ($T_SETTINGS[$End.'_TicketSubject'] == 1 || $T_SETTINGS[$End.'_TicketCode'] == 1) { ?>
		</td>
		<?php } if ($T_SETTINGS[$End.'_StaffFullname'] == 1) { ?>
		<td class="tdGrey tdMediumWidth"><a <?php echo rst_is_sort('StaffFullname',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=StaffFullname&direction='.(rst_is_sort('StaffFullname',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_STAFF; ?></a></td>
		<?php } if ($T_SETTINGS[$End.'_CustomerFullname'] == 1) { ?>
		<td class="tdGrey tdMediumWidth"><a <?php echo rst_is_sort('CustomerFullname',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=CustomerFullname&direction='.(rst_is_sort('CustomerFullname',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_CUSTOMER; ?></a></td>
		<?php } if ($T_SETTINGS[$End.'_TicketPriority'] == 1) { ?>
		<td class="tdGrey tdSmallWidth"><a <?php echo rst_is_sort('TicketPriority',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=TicketPriority&direction='.(rst_is_sort('TicketPriority',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_PRIORITY; ?></a></td>
		<?php } if ($T_SETTINGS[$End.'_TicketStatus'] == 1) { ?>
		<td class="tdGrey tdSmallWidth"><a <?php echo rst_is_sort('TicketStatus',$search) ? (isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'class="downIcon"' : 'class="upIcon"') : ''; ?> href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&order=TicketStatus&direction='.(rst_is_sort('TicketStatus',$search) && isset($_SESSION[$search]['direction']) && $_SESSION[$search]['direction'] == 'DESC' ? 'ASC' : 'DESC').(!empty($pag) ? '&pag='.$pag : '')); ?>"><?php echo LBL_STATUS; ?></a></td>
		<?php } if (isset($_SESSION['RST_User']['Group']['CanDeleteTicket']) && $_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1 || isset($_SESSION['RST_User']['Group']['GroupId'])) echo '<td class="tdMedium2Width">'.LBL_ACTIONS.'</td>'; ?>
	</tr>
	
	</thead>
	<tbody>
	<?php
	if (isset($tickets['tickets']) && count($tickets['tickets']) > 0)
		foreach ($tickets['tickets'] as $key => $ticket)
		{
			$notified = rst_is_notified($ticket['TicketId']);
			$overdued = rst_is_overdue($ticket['TicketId']);
			echo '<tr class="'.($overdued ? 'trOverdue' : ($key % 2 == 0 ? 'trEven' : 'trOdd')).'"><td class="tdGrey"><input class="smallCheck" type="checkbox" name="tickets[]" value="'.$ticket['TicketId'].'" onclick="show_bulk_change();" /></td>'
				.($T_SETTINGS[$End.'_TicketTime'] == 1 ? '<td class="tdGrey">'.date($T_SETTINGS['Date_Format'],$ticket['TicketTime']).'</td>' : '')
				.'<td class="tdGrey">'
				.($T_SETTINGS[$End.'_TicketCode'] == 1 ? '<a href="'.JRoute::_('index.php?option=com_rstickets&page=ticket&id='.$ticket['TicketId']).'">'.$ticket['TicketCode'].'</a> <span class="rst_smallreplies">('.$ticket['TicketReplies'].' '.LBL_REPLIES.')</span> <br />' : '')
				.($T_SETTINGS[$End.'_TicketSubject'] == 1 ? '<a href="'.JRoute::_('index.php?option=com_rstickets&page=ticket&id='.$ticket['TicketId']).'">'.rst_cut_text($ticket['TicketSubject']).'</a>' : '')
				.'</td>'
				.($T_SETTINGS[$End.'_StaffFullname'] == 1 ? '<td class="tdGrey">'.(!empty($T_SETTINGS['RStickets_Custom_User_Link']) && $ticket['UserId'] > 0 ? '<a href="'.rst_replace_placeholder('{userid}',$ticket['UserId'],$T_SETTINGS['RStickets_Custom_User_Link']).'">'.$ticket['StaffFullname'].'</a>' : $ticket['StaffFullname']).'</td>' : '')
				.($T_SETTINGS[$End.'_CustomerFullname'] == 1 ? '<td class="tdGrey">'.(!empty($T_SETTINGS['RStickets_Custom_User_Link']) ? '<a href="'.rst_replace_placeholder('{userid}',$ticket['CustomerId'],$T_SETTINGS['RStickets_Custom_User_Link']).'">'.$ticket['CustomerFullname'].'</a>' : $ticket['CustomerFullname']).'</td>' : '')
				.($T_SETTINGS[$End.'_TicketPriority'] == 1 ? '<td class="tdGrey">'.$priority_array_lang[$ticket['TicketPriority']].'</td>' : '')
				.($T_SETTINGS[$End.'_TicketStatus'] == 1 ? '<td class="tdGrey">'.$status_array_lang[$ticket['TicketStatus']].'</td>' : '')
				.((isset($_SESSION['RST_User']['Group']['GroupId']) && !$notified) || (isset($_SESSION['RST_User']['Group']['GroupId']) && $_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1) ? '<td>' : '')
				.(isset($_SESSION['RST_User']['Group']['GroupId']) && !$notified && $overdued ? '<a href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=notify_customer&id='.$ticket['TicketId'].(isset($_SESSION[$search]['order']) ? '&order='.$_SESSION[$search]['order'] : '').(isset($_SESSION[$search]['direction']) ? '&order='.$_SESSION[$search]['direction'] : '').(!empty($pag) ? '&pag='.$pag : '')).'" class="notifyButton">'.BTN_NOTIFY.'</a>' : '')
				.(isset($_SESSION['RST_User']['Group']['GroupId']) && $_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1 ? ' <a onclick="return confirm(\''.LBL_SURE.'\')" href="'.JRoute::_('index.php?option=com_rstickets&page='.$_GET['page'].'&action=delete_ticket&id='.$ticket['TicketId']).'" class="deleteButton">'.BTN_DELETE.'</a>' : '')
				.((isset($_SESSION['RST_User']['Group']['GroupId']) && !$notified) || (isset($_SESSION['RST_User']['Group']['GroupId']) && $_SESSION['RST_User']['Group']['CanDeleteTicket'] == 1) ? '</td>' : '').
			'</tr>';
		}
	else echo '<tr><td colspan="8"><em>'.LBL_NO_TICKETS.'</em></td></tr>';
	?>
	</tbody>
</table>
</form>

<form action="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$_GET['page']); ?>" method="post" id="filterContainer">
<input type="hidden" name="TicketTime" value="" />
<input type="hidden" name="TicketCode" value="" />
<input type="hidden" name="TicketSubject" value="" />
<input type="hidden" name="StaffFullname" value="" />
<input type="hidden" name="CustomerFullname" value="" />
<input type="hidden" name="TicketPriority" value="" />
<input type="hidden" name="TicketStatus" value="" />
<input type="hidden" name="Search" value="" />
</form>