<%!
    from baruwa.lib.dates import SHTFMT
%>

<div class="space-6"></div>
${functions.search(c.action, c.page['q'])}
<div class="space-6"></div>
${self.pager('sresultstop')}
<div class="space-6"></div>
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span10">
		<table class="table table-bordered">
			<thead>
			<tr>
				<th class="hidden-phone">${_('Date/Time')}</th>
				<th class="hidden-phone">${_('From')}</th>
				<th class="hidden-phone">${_('To')}</th>
				<th>${_('Subject')}</th>
				<th class="hidden-phone">${_('Size')}</th>
				<th class="hidden-phone">${_('Score')}</th>
				<th class="hidden-phone">${_('Status')}</th>
			</tr>
			</thead>
		<tbody>
% if c.messages:
% for index, msg in enumerate(c.messages):
<%
value = 'white'
if (msg.spam and not msg.highspam and not msg.blacklisted
	and not msg.nameinfected and not msg.otherinfected 
	and not msg.virusinfected):
	value = 'spam'
if msg.highspam and (not msg.blacklisted):
	value = 'highspam'
if msg.whitelisted:
	value = 'whitelisted'
if msg.blacklisted:
	value = 'blacklisted'
if msg.nameinfected or msg.virusinfected:
    value = 'infected'
if not msg.scaned:
       value = 'notscanned'
#view_url = url(route, messageid=msg.id)
if c.action == 'archive':
	view_url = url('message-archive', msgid=msg.id)
else:
	view_url = url('message-detail', msgid=msg.id)

if (msg.spam and (not msg.blacklisted) 
	and (not msg.virusinfected) 
	and (not msg.nameinfected) 
	and (not msg.otherinfected)):
       status = _('Spam')
if msg.blacklisted:
       status = _('BL')
if (msg.virusinfected or 
       msg.nameinfected or 
       msg.otherinfected):
       status = _('Infected')
if ((not msg.spam) and (not msg.virusinfected) 
       and (not msg.nameinfected) 
       and (not msg.otherinfected) 
       and (not msg.whitelisted)):
       status = _('Clean')
if msg.whitelisted:
       status = _('WL')
if not msg.scaned:
       status = _('NS')
if msg.from_address == '':
	from_addr = '---'
else:
	from_addr =  msg.from_address
%>
		<tr class="${value}">
			<td class="hidden-phone">${h.link_to(h.datetimeformat(h.format_date(msg.timestamp, c.tzinfo), format='%Y-%m-%d %H:%M:%S'), view_url)}</td>
			<td class="hidden-phone">${h.link_to(h.wrap_paragraphs(from_addr,32), view_url)}</td>
			<td class="hidden-phone">${h.link_to(h.truncate(h.do_breaks(msg.to_address), 50), view_url)}</td>
			<td>${h.link_to(h.truncate((msg.subject and msg.subject.strip()) or '---', 50), view_url)}</td>
			<td class="hidden-phone">${h.link_to(h.format_byte_size(msg.size), view_url)}</td>
			<td class="hidden-phone">${h.link_to(msg.sascore, view_url)}</td>
			<td class="hidden-phone">${h.link_to(status, view_url)}</td>                        
		</tr>
		% endfor
		% else:
		<tr>
			<td colspan="7"><strong>${_('No messages found matching search query: %(q)s !') % dict(q=c.page['q'])}</strong></td>
		</tr>
		% endif
		</tbody>
		</table>
	</div>
	<div class="span1 hidden-phone"></div>
</div>
${self.pager('sresultsbottom')}
<div class="space-6"></div>

<%def name="pager(name)">
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span10 toolbar">
		% if c.page['total'] != 0:
		<p>${_('Showing items %(i)d to %(l)d of %(count)d') % dict(i=c.page['first'], l=c.page['last'], count=c.page['total'])}.</p>
		<div class="limiter">
		${_('Show items:')}
		${h.pager_select(name, str(c.page['results_per_page']))}
		${_('per page')}
		</div>
		<div class="pages">
		% if not c.page['page_numbers']:
		-
		% endif
		% else:
		<p>${_('No items found')}</p>
		% endif
		% if c.page['total'] and c.page['show_first']:
		<span>${h.link_to(h.literal('<i class="icon-double-angle-left"></i>'), url.current(q=c.page['q'], page=c.page['first_page'], a=c.action))}</span>
		<span>...</span>
		% endif
		% if c.page['total'] and c.page['has_previous']:
		<span>
		  ${h.link_to(h.literal('<i class="icon-angle-left"></i>'), url.current(q=c.page['q'], page=c.page['previous'], a=c.action))}
		</span>
		% endif
		% for linkpage in c.page['page_numbers']:
		% 	if linkpage == c.page['page']:
		<span class="curpage">${linkpage}</span>
		% 	else:
		<span>
		  ${h.link_to(h.literal(linkpage), url.current(q=c.page['q'], page=linkpage, a=c.action))}
		</span>
		% 	endif
		% endfor
		% if c.page['total'] and c.page['has_next']:
		<span>
		  ${h.link_to(h.literal('<i class="icon-angle-right"></i>'), url.current(q=c.page['q'], page=c.page['next'], a=c.action))}
		% endif
		</span>
		% if c.page['total'] and c.page['show_last']:
		<span>...</span>
		<span>
		  ${h.link_to(h.literal('<i class="icon-double-angle-right"></i>'), url.current(q=c.page['q'], page=c.page['last_page'], a=c.action))}
		% endif
		</span>
		% if c.page['total'] != 0:
		</div>
		% else:
		<div class="pages">-</div>
		% endif
	</div>
	<div class="span1 hidden-phone"></div>
</div>
</%def>

<%def name="heading()">\
${_('Messages :: Search results :: %(q)s') % dict(q=c.page['q'])}
</%def>

<%def name="title()">\
${_('Messages :: Search results :: %(q)s') % dict(q=c.page['q'])}\
</%def>

<%def name="submenu()">\
<div class="navbar navbar-static-top">
    <div class="navbar-inner">
        <div class="nav-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="nav_item">${h.link_to(_('Full message list'), url(controller='messages', action='listing'))}</li>
				<li class="nav_item">${h.link_to(_('Quarantine'), url(controller='messages', action='quarantine'))}</li>
				<li class="nav_item">${h.link_to(_('Archive'), url(controller='messages', action='archive'))}</li>
            </ul>
        </div>
    </div>
</div>
</%def>

<%def name="status()">\
</%def>

<%def name="headers()">\
</%def>

<%def name="localscripts()">\
<script type="text/javascript">
var setitems_url = "${url(controller='messages', action='setnum')}";
var search_url = "${url(controller='messages', action='search')}";
var user_timezone = "${c.user.timezone}";
</script>
${h.javascript_link(h.media_url() + 'js/vendor/jquery.address-1.4.min.js',
h.media_url() + 'js/vendor/moment.min.js',
h.media_url() + 'js/vendor/moment-timezone-with-data.min.js',
h.media_url() + 'js/baruwa/dates.min.js',
h.media_url() + 'js/baruwa/messages.search.min.js')}
</%def>
<%namespace name="functions" file="functions.html"/>
<%inherit file="../base.html"/>

