{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!-- $Id$ -->
{$xajax}
{include file="rt/rtticketshared.html"}

<h1>{$layout.pagetitle}</h1>
<form method="POST" name="note" id="note-form" action="?m=rtnoteadd">
	<input type="hidden" name="note[inreplyto]" value ="{$note.inreplyto|default:"0"}">
	<input type="hidden" name="note[references]" value ="{$note.references|escape|default:""}">
	<input type="hidden" name="note[ticketid]" value="{$note.ticketid}">
	<input type="submit" class="hiddenbtn">
</form>

<table class="lmsbox">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 99%;">
	</colgroup>
	<thead>
		<tr>
			<td colspan="2" class="bold nobr">
				{icon name="helpdesk"}
				{t a=$note.ticketid|string_format:"%06d"}Ticket No. $a{/t}
			</td>
		</tr>
	</thead>
	<tbody>
		<tr id="note-template-row"{if empty($notetemplates)} style="display: none;"{/if}>
			<td class="bold nobr">
				{icon name="document"}
				{trans("Note template")}
			</td>
			<td id="note-templates">
				{include file="rt/rtmessagetemplates.html" templates=$notetemplates tip="Select note template"}
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="note"}
				{trans("Note content")}
			</td>
			<td>
				<div class="valign-middle">
					<textarea name="note[body]" id="note-body" cols="50" rows="5" form="note-form"
						{tip text="Enter note content" trigger="body"}
						>{$note.body}</textarea>
					{speech_recognition target="#note-body"}
				</div>
			</td>
		</tr>
		<tr>
			<td class="bold nobr valign-top">
				{icon name="attachment"}
				{trans("Attachments")}
			</td>
			<td>
				{fileupload id="files" fileupload=$fileupload form="note-form"}
			</td>
		</tr>
		<tr>
			<td colspan="2" class="lms-ui-box-buttons">
				{button type="submit" class="lms-ui-submit-button" accesskey="s" icon="save" label="Submit" form="note-form"}
				{button type="link-button" href="?m=rtticketview&id={$note.ticketid}" icon="cancel" label="Cancel"}
			</td>
		</tr>
	</tbody>
</table>

<br>

<table class="lmsbox">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 99%;">
	</colgroup>
	<tbody>
		<tr>
			<td class="bold nobr">
				{icon name="mail"}
				<label for="notify">
					{trans("Notify users")}
				</label>
			</td>
			<td>
				<input type="checkbox" name="note[notify]" id="notify" form="note-form"
					value="1"{if $note.notify} checked{/if}>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="status"}
				{trans("Status")}
			</td>
			<td>
				<select size="1" name="note[state]" id="state" form="note-form"
					{tip text="Select status" trigger="state"}>
					{foreach $_RT_STATES as $stateidx => $state}
						<option value="{$stateidx}"{if $note.state == $stateidx} selected{/if}>{$state.label}</option>
					{/foreach}
				</select>
				&nbsp;
				<label>
					<input type="checkbox" name="note[resolve]" id="resolve" form="note-form"
						value="{$smarty.const.RT_RESOLVED}"
						{if isset($note.resolve) || $note.state == $smarty.const.RT_RESOLVED} checked{/if}
						{tip trigger="resolve"}>
					{trans("resolve ticket")}
				</label>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="cause"}
				{trans("Cause")}
			</td>
			<td>
				<select size="1" name="note[cause]" form="note-form"
					{tip text="Select ticket cause" trigger="cause"}>
					<option value="0"{if !$note.cause} selected{/if}>{trans("unknown/other")}</option>
					<option value="1"{if $note.cause == 1} selected{/if}>{trans("customer's side")}</option>
					<option value="2"{if $note.cause == 2} selected{/if}>{trans("company's side")}</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="source"}
				{trans("Ticket source")}
			</td>
			<td>
				<select size="1" name="note[source]" form="note-form"
					{tip text="Select ticket source" trigger="source"}>
					{foreach Localisation::arraySort($_RT_SOURCES) as $sourceidx => $status}
						<option value="{$sourceidx}"{if $note.source == $sourceidx} selected{/if}>{$status}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="priority"}
				{trans("Priority")}
			</td>
			<TD>
				<select size="1" name="note[priority]" form="note-form"
					{tip text="Set ticket priority" trigger="priority"}>
					{foreach $_RT_PRIORITIES as $priorityidx => $priority}
						<option value="{$priorityidx}"{if $note.priority == $priorityidx} selected{/if}>{$priority}</option>
					{/foreach}
					<option value=""{if !isset($note.priority)} selected{/if}>{trans("undefined")}</option>
				</select>
			</TD>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="queue"}
				{trans("Queue")}
			</td>
			<td>
				<select size="1" name="note[queueid]" form="note-form" id="queue-selection"
					{tip text="Select queue" trigger="queue" class="lms-ui-advanced-select-test"}>
					{foreach $queuelist as $item}
					<option value="{$item.id}"
						{if $item.id == $note.queueid} selected{/if}>{$item.name}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="owner"}
				{trans("Owner")}
			</td>
			<td>
				<select size="1" name="note[owner]" form="note-form" id="owner"
					{tip text="Select user" trigger="owner" class="lms-ui-advanced-select-test"}>
					<option value="0">{trans("— select user —")}</option>
					{foreach $userlist as $user}
						{if $user.id != $note.owner
							&& ($hide_disabled_users && !$user.access
								|| $hide_deleted_users && $user.deleted)}
							{continue}
						{/if}
						<option value="{$user.id}"
							class="{if !$user.access} lms-ui-disabled{/if}{if $user.deleted} lms-ui-crossed{/if}"
							{if $user.id == $note.owner}selected{/if}
						>{strip}
							{$user.name|trunescape:40} ({$user.login})
						{/strip}</option>
					{/foreach}
				</select>
				&nbsp;
				<label>
					<input type="checkbox" id="assign-to-me" data-userid="{$layout.logid}" form="note-form">
					{trans("assign to me")}
				</label>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="verifier"}
				{trans("Verifier")}
			</td>
			<td id="rtverifiers">
				{if !$ticket.verifierid || $ticket.verifierid == $layout.logid}
					<select size="1" name="note[verifierid]" form="note-form"
						{tip text="Select user" trigger="verifierid" class="lms-ui-advanced-select-test"}>
						<option value="0">{trans("— select user —")}</option>
						{foreach $userlist as $user}
							{if $user.id != $note.verifierid
								&& ($hide_disabled_users && !$user.access
									|| $hide_deleted_users && $user.deleted)}
								{continue}
							{/if}
							<option value="{$user.id}"
								class="{if !$user.access} lms-ui-disabled{/if}{if $user.deleted} lms-ui-crossed{/if}"
								{if $user.id == $note.verifierid} selected{/if}
							>{strip}
								{$user.name|trunescape:40} ({$user.login})
							{/strip}</option>
						{/foreach}
					</select>
				{else}
					<input type="hidden" name="note[verifierid]" value="{$ticket.verifierid}" form="note-form">
					<span title="{trans("Only verifier can change this")}">{$ticket.verifier_username}</span>
				{/if}
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="deadline"}
				{trans("<!rt>Deadline")}
			</td>
			<td>
				{if ConfigHelper::checkConfig('rt.allow_all_users_modify_deadline', ConfigHelper::checkConfig('phpui.helpdesk_allow_all_users_modify_deadline'))
					|| !$ticket.verifierid || $ticket.verifierid == $layout.logid}
					<input type="text" name="note[deadline]" value="{if $note.deadline}{$note.deadline|date_format:"Y/m/d H:i"}{/if}"
						form="note-form" size="20"
						{tip text="Enter deadline in YYYY/MM/DD HH:MM format or click to select it from applet" class="lms-ui-datetime" trigger="deadline"}>
				{else}
					<input type="hidden" name="note[deadline]" value="{if $note.deadline}{$note.deadline|date_format:"Y/m/d H:i"}{/if}"
						form="note-form">
					<span title="{trans("Only verifier can change this")}">{if $note.deadline}{$note.deadline|date_format:"Y-m-d H:i"}{else}{trans("<!rt>— none —")}{/if}</span>
				{/if}
			</td>
		</tr>

		<tr>
			<td class="bold nobr">
				{icon name="queue"}
				{trans("Category changes")}
			</td>
			<td>
				<select name="note[category_change]" form="note-form"
					{tip text="Select category change type" trigger="category_change"}>
					<option value="0"{if $note.category_change == 0} selected{/if}>{trans("— no changes —")}</option>
					<option value="1"{if $note.category_change == 1} selected{/if}>{trans("— replace —")}</option>
					<option value="2"{if $note.category_change == 2} selected{/if}>{trans("— append —")}</option>
					<option value="3"{if $note.category_change == 3} selected{/if}>{trans("— remove —")}</option>
				</select>
			</td>
		</tr>

		<tr id="categories">
			<td class="bold nobr">
				{icon name="categories"}
				{trans("Categories")}
			</td>
			<td>
				{include file="rt/rtcategoryselection.html" name_prefix="note[categories]" categories=$categories form="note-form"}
			</td>
		</tr>
	</tbody>
</table>

{include file="rt/rtticketmessagesbox.html"}

<script>

	$(function() {
		$('[name="note[body]"]').focus();

		$('[name="note[category_change]"]').change(function() {
			if (parseInt($(this).val())) {
				$('#categories').show();
			} else {
				$('#categories').hide();
			}
		}).change();

		$('body').on('change', '.template-selector', function() {
			var selected = $('option:selected', this);
			if (parseInt(selected.val()) == 0) {
				return;
			}
			$('[name="note[body]"]').val(Base64.decode(selected.attr('data-message')));
		});
	});

</script>

{/block}
