<!--// $Id$ //-->

{js}

<form method="post" name="customermessages" id="customermessages-form" action="?m=messagedel&customerid={$customerinfo.id}">
</form>

{tab_container id="customermessages" label="Customer Messages"}

	{tab_header content_id="messagespanel"}
		{tab_header_cell icon="lms-ui-icon-message"}
			<strong>{trans("Customer Messages")}</strong>
			{capture assign="message_hint"}
				<strong>{trans("Message status color markings:")}</strong>
				<br><br>
				<span class="lms-ui-message-new"><strong>{trans("new/waiting")}</strong></span>
				<br>
				<span class='lms-ui-message-sent'><strong>{trans("sent")}</strong></span>
				<br>
				<span class='lms-ui-message-delivered'><strong>{trans("delivered")}</strong></span>
				<br>
				<span class='lms-ui-message-cancelled'><strong>{trans("cancelled")}</strong></span>
				<br>
				<span class='lms-ui-message-error'><strong>{trans("error")}</strong></span>
			{/capture}
			{hint text=$message_hint}
		{/tab_header_cell}
		{tab_header_cell}
			{if ConfigHelper::checkPrivileges('messaging', 'messaging_creation')}
				<a href="?m=messageadd&customerid={$customerinfo.id}">
					{trans("New Message")}
					{icon name="next" class="fa-fw"}
				</a>
			{/if}
			<a href="?m=messagelist&cid={$customerinfo.id}">
				{trans("All Messages")}
				{icon name="next" class="fa-fw"}
			</a>
		{/tab_header_cell}
	{/tab_header}

	{tab_contents id="messagespanel"}

		{tab_table}
			<TABLE id="customermessages-datatable" class="lmsbox-inner lms-ui-datatable"
					{if $limit} data-page-length="{$limit}"
					data-empty-table-message="{trans("There are no messages in database.")}"
					data-order='[[ 0, "desc" ]]' style="display: none;"{/if} width="100%">
				<COLGROUP>
					<COL style="width: 1%;">
					<COL style="width: 93%;">
					<COL style="width: 1%;">
					<COL style="width: 1%;">
					<COL style="width: 1%;">
					<COL style="width: 1%;">
					<COL style="width: 1%;">
					<COL style="width: 1%;">
				</COLGROUP>
				<THEAD>
				<TR>
					<TH class="nobr">
						{trans("Date")}
					</TH>
					<TH class="bold nobr">
						{trans("Subject")}
					</TH>
					<TH class="bold nobr">
						{trans("User")}
					</TH>
					<TH class="nobr">
						{trans("Destination")}
					</TH>
					<th class="nobr">
						{trans("Last change")}
					</th>
					<th class="nobr">
						{trans("Attempts left")}
					</th>
					<TH class="nobr" data-orderable="false" data-searchable="false">
						{trans("Last read")}
					</TH>
					<TH class="nobr" data-orderable="false" data-searchable="false"></TH>
				</TR>
				</THEAD>
				<TBODY>
				{foreach $messagelist as $item}
				<TR class="{$_MESSAGESTATUSES[$item.status].class}">
					<TD class="nobr" onClick="return self.location.href='?m=messageinfo&id={$item.id}'">
						{$item.cdate|date_format:"Y-m-d"}
					</TD>
					<TD class="bold" onClick="return self.location.href='?m=messageinfo&id={$item.id}'">
						{if $item.type == $smarty.const.MSG_MAIL}
							<i class="lms-ui-icon-mail fa-fw"></i>
						{elseif $item.type == $smarty.const.MSG_WWW}
							<i class="lms-ui-icon-web fa-fw"></i>
						{elseif $item.type == $smarty.const.MSG_USERPANEL || $item.type == $smarty.const.MSG_USERPANEL_URGENT}
							<i class="lms-ui-icon-userpanel fa-fw"></i>
						{else}
							<i class="lms-ui-icon-sms fa-fw"></i>
						{/if}
						{$item.subject|escape}
					</TD>
					<TD class="text-center nobr" onClick="return self.location.href='?m=messageinfo&id={$item.id}'">
						{if $item.userid}
							<a href="?m=userinfo&id={$item.userid}">{$item.username|escape}</a>
						{/if}
					</TD>
					<TD class="text-right nobr" onClick="return self.location.href='?m=messageinfo&id={$item.id}'">
						{$item.destination}
					</TD>
					<TD class="text-right nobr">
						{if $item.lastdate}{$item.lastdate|date_format:"Y-m-d H:i"}{else} - {/if}
					</TD>
					<td class="text-right nobr">
						{if !empty($message.startdate)}
							{if !empty($item.attempts)}
								{icon name="reload" class="fa-fw"}
							{/if}
							{$item.attempts}
						{/if}
					</td>
					<TD class="text-right nobr">
						{if $item.lastreaddate}{$item.lastreaddate|date_format:"Y-m-d H:i"}{else} - {/if}
					</TD>
					<TD class="text-right nobr">
						{if $item.files}
							{button class="toggle-file-list" type="link" icon="attachment" tip="Show file list" resourceid={$item.filecontainerid}}
						{/if}
						{if ConfigHelper::checkPrivileges('messaging', 'messaging_removal')}
							{button type="link" icon="delete" class="delete-message" href="?m=messagedel&id={$item.id}&customerid={$customerinfo.id}"
								tip="Delete"}
						{/if}
						{if ConfigHelper::checkPrivileges('messaging', 'messaging_creation')}
							{button type="link" icon="resend" href="?m=messageadd&customerid={$customerinfo.id}&messageid={$item.id}" tip="Resend"}
						{/if}
						<input type="checkbox" class="lms-ui-multi-check" name="marks[{$item.id}]" value="{$item.id}"
							form="customermessages-form">
						<div id="files-{$item.filecontainerid}" style="display: none;" class="files">
							{foreach $item.files as $file}
								{documentview id="{$item.id}-{$file.id}" type=$file.contenttype name=$file.filename
									url="?m=attachments&attachmentaction=viewfile&type=messageid&id={$item.filecontainerid}&fileid={$file.id}" external=true
									text="{$file.filename} <i class=\"lms-ui-icon-view{if preg_match('/pdf/',$file.contenttype)} pdf{elseif preg_match('/csv|excel|spreadsheet/',$file.contenttype)} xls{/if}\"></i>"}
								<br>
							{/foreach}
						</div>
					</TD>
				</TR>
				{/foreach}
				</TBODY>
			</TABLE>
		{/tab_table}

		{tab_button_panel}
			{tab_buttons}
				{if ConfigHelper::checkPrivileges('messaging', 'messaging_removal')}
					{button icon="delete" id="delete-messages" label="Delete"}
				{/if}
			{/tab_buttons}
			{tab_buttons}
				<label>
					{trans("Check All")}
					<input type="checkbox" class="lms-ui-multi-check-all">
				</label>
			{/tab_buttons}
		{/tab_button_panel}

	{/tab_contents}
{/tab_container}
