{include file="header.html"}
{$xajax}

<style>

	.notice-attachments {
		margin-top: 0.5em;
		margin-bottom: 0.5em;
	}

	.notice-attachments ul {
		margin-block-start: 0;
		margin-block-end: 0;
		list-style-type: none;
		padding-inline-start: 0;
	}

	.notice-confirm {
		margin-top: 0.5em;
	}

</style>

{if $warning}
	{box title="Warning to you"}
	<div class="alert alert-warning" role="alert">
		{$warning}
		<a class="alert-link" href="?m=notices&amp;confirm_old=1">{trans("<!userpanel>Confirm")}</a>
	</div>
	{/box}
{/if}

{box title="Notice to you"}
{if $notices}
	<div class="table-responsive">
		<table class="table table-bordered table-condensed table-striped">
			<tr class="bg-primary text-white">
				<th>{trans("Date")}</th>
				<th>{trans("Type")}</th>
				<th>{trans("Subject")}</th>
				<th>{trans("Read")}</th>
			</tr>
			{foreach $notices as $items}
				<tr class="{if $items.status==$smarty.const.MSG_ERROR}text-danger{elseif $items.status==$smarty.const.MSG_SENT}text-muted{/if}" onCLick="ReadNotice('{$items.id}');">
					<td>{$items.cdate|date_format:"Y-m-d H:i"}</td>
					<td>{if $items.type == $smarty.const.MSG_USERPANEL_URGENT}<strong>{trans("Urgent")}</strong>{else}{trans("Casual")}{/if}</td>
					<td>{$items.subject}</td>
					<td>
						{if $items.type == $smarty.const.MSG_USERPANEL_URGENT || $items.type == $smarty.const.MSG_USERPANEL}
							{if $items.status == $smarty.const.MSG_SENT && !$items.lastreaddate}
								{trans("Unread")}
							{elseif $items.status == $smarty.const.MSG_SENT || $items.status == $smarty.const.MSG_DELIVERED}
								{$items.lastreaddate|date_format:"Y-m-d H:i"}
							{/if}
						{/if}
					</td>
				</tr>
				<tr id="{$items.id}" style="display:none;">
					<td colspan="4" >
						<h3>{trans("Body")}</h3>
						<div class="notice-body">
							{if $items.mibody}
								{if $items.contenttype == 'text/plain'}
									{nl2br(htmlspecialchars($items.mibody), false)}
								{elseif $items.contenttype == 'text/html'}
									{$items.mibody}
								{else}
									{nl2br($items.mibody, false)}
								{/if}
							{else}
								{if $items.contenttype == 'text/plain'}
									{nl2br(htmlspecialchars($items.body), false)}
								{elseif $items.contenttype == 'text/html'}
									{$items.body}
								{else}
									{nl2br($items.body, false)}
								{/if}
							{/if}
						</div>
						{if !empty($items.attachments)}
							<div class="notice-attachments">
								{icon name="attachment"}
								<strong>{trans("Attachments")}</strong>
								<ul>
									{foreach $items.attachments as $attachmentid => $attachment}
										<li>
											<a href="?m=notices&f=attachmentview&id={$attachmentid}">
												{$attachment.filename|escape}
												{if preg_match('/pdf/', $attachment.contenttype)}
													{$icon = "pdf"}
												{elseif preg_match('/csv|excel|spreadsheet/', $attachment.contenttype)}
													{$icon = "xls"}
												{/if}
												{icon name="lms-ui-icon-view" class=$icon}
											</a>
										</li>
									{/foreach}
								</ul>
							</div>
						{/if}
						{if $items.status != $smarty.const.MSG_DELIVERED}
							<div class="notice-confirm">
								{button class="btn btn-primary" href="?m=notices&confirm={$items.id}" icon="confirm" label="<!userpanel>Confirm"}
							</div>
						{/if}
					</td>
				</tr>
				<SCRIPT type="text/javascript">
					<!--
					function ReadNotice(elem) {
						xajax_setNoticeRead(elem);
						showOrHide(elem);
					}
					if (getCookie('{$items.id}') == '1')
						document.getElementById('{$items.id}').style.display = '';
					//-->
				</SCRIPT>
			{/foreach}
		</table>
	</div>
{else}
	<div class="alert alert-info" role="alert">{trans("We don't have any notices to you.")}</div>
{/if}
{/box}
{include file="footer.html"}
