<?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 (!rst_is_staff_logged()) rst_redirect('index.php?option=com_rstickets');
if ($_SESSION['RST_User']['Group']['CanMoveTicket'] == 0) rst_redirect('index.php?option=com_rstickets');
if (!isset($_POST['NewDepartmentId'])) rst_redirect('index.php?option=com_rstickets');
// NEW DEPARTMENT OR UNASSIGNED
$department = $_POST['NewDepartmentId'] > 0 ? rst_get_departments($_POST['NewDepartmentId']) : array(0 => array('DepartmentId' => 0));
// DEPARTMENT NOT FOUND ?
if (count($department) == 0)
	rst_redirect('index.php?option=com_rstickets&page=ticket&id='.$ticket['TicketId']);
$ticket = rst_get_ticket_messages($_GET['id']);
// TICKET NOT FOUND ?
if (count($ticket) == 0)
	rst_redirect('index.php?option=com_rstickets');
// SAME DEPARTMENT ?
if ($department[0]['DepartmentId'] == $ticket['DepartmentId']) rst_redirect('index.php?option=com_rstickets&page=ticket&id='.$ticket['TicketId'].'&move_ticket2=1');
?>
	<style type="text/css">.custom_fields { display: table-row !important; _display: block !important; @display: block !important; }</style>
	<h4 class="rst_h4"><?php echo LBL_MOVING_TICKET; ?> <span><?php echo $ticket['TicketCode']; ?></span></h4>
	<a href="<?php echo JRoute::_('index.php?option=com_rstickets&page=ticket&id='.intval($_GET['id'])); ?>" class="backButton"><?php echo BTN_BACK; ?></a>
	<form method="post" action="<?php echo JRoute::_('index.php?option=com_rstickets&page=move_ticket&id='.$ticket['TicketId'].'&action=move_ticket'); ?>">
	<input type="hidden" name="NewDepartmentId" value="<?php echo $department[0]['DepartmentId']; ?>" />
	<input type="hidden" name="TicketId" value="<?php echo $ticket['TicketId']; ?>" />
	<?php
	if (($department[0]['DepartmentId']) > 0)
	{
		$totalfields = rst_get_departments_custom_fields($department[0]['DepartmentId']);
		if (count($totalfields) > 0)
		{
	?>
	<p><?php echo LBL_MOVE_TICKET_DESCRIPTION; ?></p>
	<table cellpadding="4" cellspacing="0" class="tableGrey wide">
	<thead>
	<tr class="tableHead">
		<td colspan="2"><?php echo LBL_CUSTOM_FIELDS; ?></td>
	</tr>
	</thead>
	<tbody>
	<?php
		echo rst_gen_custom_fields($department[0]['DepartmentId']);
	?>
	</tbody>
	</table>
	<?php
		}
	}
	?>
	<p><?php echo LBL_MOVE_TICKET_WARNING; ?></p>
	<button type="submit"><?php echo BTN_MOVE_TICKET; ?></button>
	</form>