{include file="header.html"}
{$allow_reopen_tickets_newer_than = intval(ConfigHelper::getConfig('userpanel.allow_reopen_tickets_newer_than', 0))}
{$allow_message_add_to_closed_tickets = intval(ConfigHelper::getConfig('userpanel.allow_message_add_to_closed_tickets', 1))}

<style>

	.card > .card-block {
		margin: 0.4em;
	}

</style>
<h3>{button class="btn btn-secondary mb-2" href="?m=helpdesk" icon="cancel" label="Back"}</h3>
<h5><span class="badge" style="color: white; background-color:{$_RT_STATES[$ticket.state].color};">{$_RT_STATES[$ticket.state].label}</span><strong> {trans($title)}</strong></h5>

{foreach $ticket.messages as $message}
<div class="card">
	<div class="card-header">
		{trans("Subject:")} <strong>{$message.subject|escape}</strong>
	</div>
	<div class="card-block">
		<div class="card-block">
			<blockquote class="blockquote">
				<p class="mb-0 p-2">
					{if $message.contenttype == 'text/plain'}
						{$message.body|trim|escape|regex_replace:"/\r?\n/":'<br>'}
					{else}
						{$message.body}
					{/if}
				</p>
			</blockquote>
			<small class="p-2 text-muted">{trans("From")}:
				{if $message.customerid}
					{$message.customername}{elseif $message.userid}{$message.username}
				{elseif $message.mailfrom}
					{$message.mailfrom|escape}
				{else}
					{$ticket.requestor|escape}
					{if $ticket.requestoremail}
						&lt;{$ticket.requestoremail|escape}&gt;
					{/if}
				{/if}, {trans("Time:")} {$message.createtime|date_format:"Y-m-d H:i"}
			</small>
				{if $message.attachments}
					<strong>{trans("Attachments:")}</strong>
					<ul class="list-inline">
						{foreach $message.attachments as $attachment}
							{if !$attachment@first}
							{/if}
							<li class="list-inline-item">
								{button class="btn btn-secondary btn-sm" href="?m=helpdesk&f=attachment&msgid={$message.id}&file={$attachment.filename}" icon="file" label="{$attachment.filename}"}
							</li>
						{/foreach}
					</ul>
				{/if}

				{if ($ticket.state != $smarty.const.RT_RESOLVED || $allow_message_add_to_closed_tickets)
					&& (!$allow_reopen_tickets_newer_than || $smarty.now - $allow_reopen_tickets_newer_than <= $ticket.lastmod)}
					{button class="btn btn-success float-right" href="?m=helpdesk&op=message&id={$ticket.id}&msgid={$message.id}" icon="message" label="Reply"}
				{/if}
			</div>
		</div>
	</div>
{/foreach}

{include file="footer.html"}

