<?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'] == 'search_my_tickets' && !rst_is_logged()) rst_redirect('index.php?option=com_rstickets');
if ($_GET['page'] == 'search_tickets' && !rst_is_staff_logged()) rst_redirect('index.php?option=com_rstickets');

if ($_GET['page'] == 'search_my_tickets') { $search = 'search_my_tickets'; $redirect = 'my_tickets'; }
if ($_GET['page'] == 'search_tickets')	{ $search = 'search_tickets'; $redirect = 'tickets'; }
?>
<h4 class="rst_h4"><?php echo $_GET['page'] == 'search_tickets' ? LBL_ADVANCED_SEARCH_IN_TICKETS : LBL_ADVANCED_SEARCH_IN_MY_TICKETS; ?></h4>
<a href="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$redirect); ?>" class="backButton"><?php echo BTN_BACK; ?></a>
<form action="<?php echo JRoute::_('index.php?option=com_rstickets&page='.$redirect); ?>" method="post" id="searchcontent">
<table cellpadding="4" cellspacing="0" class="tableGrey">
	<thead>
	<tr class="tableHead">
		<td colspan="4"><?php echo LBL_SEARCH_BY_USERS; ?></td>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td class="tdGrey"><?php echo LBL_CUSTOMER_USERNAME; ?></td>
		<td><input type="text" name="CustomerUsername" value="<?php echo isset($_SESSION[$search]['CustomerUsername']) ? $_SESSION[$search]['CustomerUsername'] : '' ?>" /></td>
		<td class="tdGrey"><?php echo LBL_STAFF_USERNAME; ?></td>
		<td><input type="text" name="StaffUsername" value="<?php echo isset($_SESSION[$search]['StaffUsername']) ? $_SESSION[$search]['StaffUsername'] : '' ?>" /></td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_CUSTOMER_FULLNAME; ?></td>
		<td><input type="text" name="CustomerFullname" value="<?php echo isset($_SESSION[$search]['CustomerFullname']) ? $_SESSION[$search]['CustomerFullname'] : '' ?>" /></td>
		<td class="tdGrey"><?php echo LBL_STAFF_FULLNAME; ?></td>
		<td><input type="text" name="StaffFullname" value="<?php echo isset($_SESSION[$search]['StaffFullname']) ? $_SESSION[$search]['StaffFullname'] : '' ?>" /></td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_CUSTOMER_EMAIL; ?></td>
		<td><input type="text" name="CustomerEmail" value="<?php echo isset($_SESSION[$search]['CustomerEmail']) ? $_SESSION[$search]['CustomerEmail'] : '' ?>" /></td>
		<td class="tdGrey"><?php echo LBL_STAFF_EMAIL; ?></td>
		<td><input type="text" name="StaffEmail" value="<?php echo isset($_SESSION[$search]['StaffEmail']) ? $_SESSION[$search]['StaffEmail'] : '' ?>" /></td>
	</tr>
	<tr class="tableHead">
	<td colspan="4"><?php echo LBL_SEARCH_BY_TICKET_PROPERTIES; ?></td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_SUBJECT; ?></td>
		<td><input type="text" name="TicketSubject" value="<?php echo isset($_SESSION[$search]['TicketSubject']) ? $_SESSION[$search]['TicketSubject'] : '' ?>" /></td>
		<td class="tdGrey"><?php echo LBL_TICKET_CODE; ?></td>
		<td><input type="text" name="TicketCode" value="<?php echo isset($_SESSION[$search]['TicketCode']) ? $_SESSION[$search]['TicketCode'] : '' ?>" /></td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_MESSAGE; ?></td>
		<td><textarea name="TicketMessage" rows="5" cols="20"><?php echo isset($_SESSION[$search]['TicketMessage']) ? $_SESSION[$search]['TicketMessage'] : '' ?></textarea></td>
		<td class="tdGrey"><?php echo LBL_DEPARTMENT; ?></td>
		<td>
		<?php
		$departments = rst_is_staff_logged() && $_GET['page'] == 'search_tickets' ? $_SESSION['RST_User']['Department'] : rst_get_departments();
		if (count($departments) > 0)
		{
			echo '<select name="DepartmentId[]" size="5" multiple="multiple">';
			$departments[] = array('DepartmentId' => 0, 'DepartmentName' => LBL_UNASSIGNED_DEPARTMENT, 'DepartmentPrefix' => 'UNASSIGNED');
			foreach ($departments as $department)
				echo '<option '.(isset($_SESSION[$search]['DepartmentId']) && count($_SESSION[$search]['DepartmentId']) > 0 && in_array($department['DepartmentId'],$_SESSION[$search]['DepartmentId']) ? 'selected="selected"' : (count($_SESSION[$search]['DepartmentId']) == 0 ? 'selected="selected"' : '')).' value="'.$department['DepartmentId'].'">'.$department['DepartmentName'].'</option>';
			echo '</select>';
		}
		else echo '<strong>'.LBL_NO_DEPARTMENTS.'</strong><br/>';
		?>
		</td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_STATUS; ?></td>
		<td>
		<select name="TicketStatus[]" size="4" multiple="multiple">
			<?php
			$status_array = array('open','on-hold','closed');
			foreach ($status_array as $status)
				echo '<option '.(isset($_SESSION[$search]['TicketStatus']) && in_array($status,$_SESSION[$search]['TicketStatus']) ? 'selected="selected"' : '').' value="'.$status.'">'.$status_array_lang[$status].'</option>';
			?>
		</select>
		</td>
		<td class="tdGrey"><?php echo LBL_PRIORITY; ?></td>
		<td>
		<select name="TicketPriority[]" size="4" multiple="multiple">
			<?php
			$priority_array = array('low','normal','high');
			foreach ($priority_array as $priority)
				echo '<option '.(isset($_SESSION[$search]['TicketPriority']) && in_array($priority,$_SESSION[$search]['TicketPriority']) ? 'selected="selected"' : '').' value="'.$priority.'">'.$priority_array_lang[$priority].'</option>';
			?>
		</select>
		</td>
	</tr>
	<tr class="tableHead">
	<td colspan="4"><?php echo LBL_SEARCH_BY_DATE_RANGE; ?></td>
	</tr>
	<tr>
		<td class="tdGrey"><?php echo LBL_FROM; ?></td>
		<td>
		<input type="text" name="from" onclick="displayCalendar(this,'<?php echo $T_SETTINGS['Date_Format_JS']; ?>',this)" value="<?php echo isset($_SESSION[$search]['from']) && $_SESSION[$search]['from'] != '' ? $_SESSION[$search]['from'] : /*date($T_SETTINGS['Date_Format'],$date_start)*/ '' ?>" />
		</td>
		<td class="tdGrey"><?php echo LBL_TO; ?></td>
		<td>
		<input type="text" name="to" onclick="displayCalendar(this,'<?php echo $T_SETTINGS['Date_Format_JS']; ?>',this)" value="<?php echo isset($_SESSION[$search]['to']) && $_SESSION[$search]['to'] != '' ? $_SESSION[$search]['to'] : /*date($T_SETTINGS['Date_Format'],$date_stop)*/ '' ?>" />
		</td>
	</tr>
	</tbody>
</table>
<p><button type="submit" name="Search"><?php echo BTN_SEARCH; ?></button></p>
</form>
