<!DOCTYPE html >
<%~if in.mode and in.mode eq sent%><%set sent_mode = 1%><%endif%>
<html lang="en">
<head>
  <title><%cat_full_name%>: <%if search%> Search <%endif%>Messages</title>
<%include include_common_head.html%>
</head>

<%~set content_header_title = 'Private Messages'%>

<%~if sent_mode and not $search%>
  <%~GForum::Message::sent_messages%>
<%~endif%>

<%~set hidden_sort = ''%><%set hidden_page = ''%>
<%~if in.sb%><%set hidden_sort .= ";sb=$sb"%><%endif%>
<%~if in.so%><%set hidden_sort .= ";so=$so"%><%endif%>
<%~if in.sent_sb%><%set hidden_sort .= ";sent_sb=$sent_sb"%><%endif%>
<%~if in.sent_so%><%set hidden_sort .= ";sent_so=$sent_so"%><%endif%>
<%~if sent_mode%><%set hidden_page .= ";mode=sent"%><%endif%>
<%~if in.mh%><%set hidden_page .= ";mh=$mh"%><%endif%>

<%~if sent_mode%>
  <%~set sb = $sent_sb%>
  <%~set so = $sent_so%>
<%~endif%>

<body class="page-<%page_id%> message-list-page<%if sent_mode%> sent-message-list-page<%endif%>">
  <div class="container-b">
    <%include include_header.html%>

    <div class="main">
      <div class="contentwrapper clearfix">
        <div class="sidebar">
            <%include include_sidebar.html%>
        </div>
        <%~set content_header_title = "Private Messages"%>
        <%~init array breadcrumbs%><%init hash breadcrumbs.0%>
        <%~set breadcrumbs.0.name = $content_header_title%>

        <%~if sent_mode%>
        <%~set content_header_title .= ': Sent'%>
        <%~set breadcrumbs.0.url = GForum::SEO::url(params => "do=message_list")%>
        <%~init hash breadcrumbs.1%>
        <%~set breadcrumbs.1.name = 'Private Messages: Sent'%>
        <%~else%>
        <%~set content_header_title .= ': Inbox'%>
        <%~endif%>


        <%~set url_param_mh = ""%>
        <%~if in.mh%><%set url_param_mh = ";mh=$mh"%><%endif%>

        <%~if sent_num_deleted or $num_deleted%><%set success = "Selected messages were deleted"%><%endif%>

        <%include include_breadcrumb.html%>
        <div class="content"><%-- start content--%>
          <%include include_content_header.html%>
          <p>
            <%if sent_mode%>
            You have <span class="number"><%sent_num_messages || 0%></span> sent message<%if sent_num_messages != 1%>s<%endunless%>.
            <%else%>
            You have <span class="number"><%num_messages%></span> message<%if num_messages != 1%>s<%endif%> &mdash;
            <span class="new"><span class="number"><%num_new%></span> new</span>,
            <span class="read"><span class="number"><%num_read + $num_replied%></span> read</span>,
            <span class="replied"><span class="number"><%num_replied%></span> replied</span>.
            <%endif%>
          </p>

          <form action="<%GForum::SEO::url()%>" method="post">
            <%hidden_form%>
            <%~if in.mh%>
            <input type="hidden" name="mh" value="<%mh%>" />
            <%~endif%>
            <%~if sent_mode%>
            <input type="hidden" name="mode" value="sent" />
            <%~if in.sent_so%>
            <input type="hidden" name="sent_so" value="<%sent_so%>" />
            <%~endif%>
            <%~if in.sent_sb%>
            <input type="hidden" name="sent_sb" value="<%sent_sb%>" />
            <%~endif%>
            <%~else%>
            <%~if in.so%>
            <input type="hidden" name="so" value="<%so%>" />
            <%~endif%>
            <%~if in.sb%>
            <input type="hidden" name="sb" value="<%sb%>" />
            <%~endif%>
            <%~endif%>

            <%~set url_param_sent_mode = ""%>
            <%~if sent_mode%><%set url_param_sent_mode = "sent_"%><%endif%>

            <div class="row">
                <label class="name">Search Message</label>
                <div class="value">
                    <select class="button" name="search">
                        <option value="body"<%if search eq 'body'%> selected<%endif%>>Body</option>
                        <option value="username"<%if search eq 'username'%> selected<%endif%>>Sender</option>
                        <option value="subject"<%if search eq 'subject'%> selected<%endif%>>Subject</option>
                    </select>
                    for
                    <input type="text" name="search_value" value="<%search_value || ''%>" class="txt textmid" />
                    <input type="submit" value="Search" name="do=message_list;action=search" class="btn"/>
                    <%if search%><input class="submit" type="submit" value="Clear Search" name="do=message_list;"/><%endif%>
                </div>
            </div>
                   
            <div class="dtable">
              <div class="dhead">
                <div class="drow">
                  <div class="dcell icon">&nbsp;</div>
                  <div class="dcell status">
                    <%~unless sent_mode%>
                    <%~if sb eq msg_status and so ieq asc%><%set url_param_so = "desc"%><%else%><%set url_param_so = "asc"%><%endif%>
                    <a href="<%GForum::SEO::url(params => "do=$this_do;sb=msg_status;so=$url_param_so$hidden_page")%>" title="Sort by New/Read/Replied"><%~%>
                      Status
                      <%~if sb eq msg_status%> <span class="<%if so ieq asc%>ascending<%else%>descending<%endif%>"></span><%endif~%>
                    </a>
                    <%endunless~%>
                  </div>
                  <div class="dcell subject">
                    <%~if sb eq msg_subject and so ieq asc%><%set url_param_so = "desc"%><%else%><%set url_param_so = "asc"%><%endif%>
                    <a href="<%GForum::SEO::url(params => "do=$this_do;${url_param_sent_mode}sb=msg_subject;${url_param_sent_mode}so=$url_param_so$hidden_page")%>" title="Sort by Subject"><%~%>
                      Subject
                      <%~if sb eq msg_subject%> <span class="<%if so ieq asc%>ascending<%else%>descending<%endif%>"></span><%endif~%>
                    </a>
                  </div>
                  <div class="dcell author">
                    <%~if sb eq msg_username and so ieq asc%><%set url_param_so = "desc"%><%else%><%set url_param_so = "asc"%><%endif%>
                    <a href="<%GForum::SEO::url(params => "do=$this_do;${url_param_sent_mode}sb=msg_username;${url_param_sent_mode}so=$url_param_so$hidden_page")%>" title="Sort by Author"><%~%>
                      <%if sent_mode%>To<%else%>From<%endif%>
                      <%~if sb eq msg_username%> <span class="<%if so ieq asc%>ascending<%else%>descending<%endif%>"></span><%endif~%>
                    </a>
                  </div>
                  <div class="dcell date">
                    <%~if sb eq msg_time and so ieq desc%><%set url_param_so = "asc"%><%else%><%set url_param_so = "desc"%><%endif%>
                    <a href="<%GForum::SEO::url(params => "do=$this_do;${url_param_sent_mode}sb=msg_time;${url_param_sent_mode}so=$url_param_so$hidden_page")%>" title="Sort by date sent"><%~%>
                      Sent
                      <%~if sb eq msg_time%> <span class="<%if so ieq asc%>ascending<%else%>descending<%endif%>"></span><%endif~%>
                    </a>
                  </div>
                </div>
              </div><%-- end dhead --%>

              <%~if sent_mode%>
              <%include include_message_list_sent.html%>
              <%~else%>
              <%include include_message_list.html%>
              <%~endif%>
            </div> <%-- end dtable --%>

            <%~set pagination_options.params = "do=$this_do$hidden_sort$hidden_page"%>
            <%if sent_mode%>
            <%~set pagination_options.page_items = $sent_num_messages%>
            <%~set pagination_options.param_page = 'sent_page'%>
            <%else%>
            <%~set pagination_options.page_items = $num_messages%>
            <%endif%>

            <%~if $pagination_options.page_items%>
            <div class="toolbar clearfix">
              <hr class="line" />
              <%include include_paging.html%>
              <div class="btn-wrapper clearfix">
                <input type="submit" name="do=message_delete" value="Delete Messages" class="btn default" title="Delete the selected messages" />
              </div>
            </div>
            <%~endif%>

          </form>

        </div><%-- end content --%>
      </div><%-- end contentwrapper --%>
    </div><%-- end main --%>

    <%include include_footer.html%>
  </div>

</body>
<%~include include_global_js.html%>
<script type="text/javascript">
  $(document).ready(function () {
    GForum.init_check_all('<%if sent_mode%>sent_<%endif%>delete', '#delete_checkall');
  });
</script>
</html>