<!-- BEGIN site/messages.tt -->
    [% IF admin_messages.size %]
      <h4 class="warning">Admin messages:</h4>
      <ul>
        [% FOREACH msg IN admin_messages;
            # PROCESS dumper.tt dump = msg.as_tree %]
          <li>[% msg.message %]</li>
        [% END %]
      </ul>            
    [% END %]
    
    [% IF user_messages.inbound.size || user_messages.outbound.size;
            # PROCESS dumper.tt dump = user_messages %]
        <h4>User messages:</h4>
      [% IF user_messages.inbound.size;
            unacknowledged_msg_count = 0 # counter for 'submit' button %]
        <p class="indent">
            <i>received messages [acknowledge to keep, 'x' to delete]</i>:
        </p>
        <form method="post" action="[% app_url %]/user/acknowledge_messages">
        <table class="indent">
          <tr>
            <th scope="col">From</th>
            <th scope="col">Date/Time</th>
            <th scope="col">Message</th>
            <th scope="col">OK</th>
            <td class="borderless"></td>
          </tr>
          [% FOREACH msg IN user_messages.inbound;
              # PROCESS dumper.tt dump = msg.as_tree %]
            <tr>
              <td>
                [% msg.sender.first_name | ucfirst %]
                [% msg.sender.last_name  | ucfirst %]
              </td>
              <td>[% msg.received.strftime('%a %d.%b.%Y @ %H:%M') %]</td>
              <td>[% msg.message | html %]</td>
              <td>
                [% IF msg.acknowledged %]
                    <img src="/images/tick.gif" />
                [% ELSE; unacknowledged_msg_count = 1# only need 1 %]
                    <input type="checkbox" name="msg_id" value="[% msg.id %]" />
                [% END %]
              </td>
              <td class="borderless">
                [ <a href="[% app_url %]/resources/user_messages/[% msg.sender.id %]">
                  reply</a> ]
                [ <a href="[% app_url %]/user/delete_message/[% msg.id %]"
                      alt="delete" title="delete msg">
                    <span class="red">x</span>
                  </a> ]                            
             </td>
          </tr>
          [% END %]
          [% IF unacknowledged_msg_count %]
          <tr class="borderless">
            <td colspan="4" align="right">
                <span class="info">acknowledge selected messages &#187;</span>
                [% site.html.submit %]
            </td>
          </tr>
          [% END %]
        </table>
        </fom>
      [% END %]
      [% IF user_messages.outbound.size %]
        <p class="indent"><i>copies of sent messages still in recipient inbox</i>:</p>
        <table class="indent">
          <tr>
            <th scope="col">To</th>
            <th scope="col">Date/Time</th>
            <th scope="col">Message</th>
            <td class="borderless"></td>
          </tr>
          [% FOREACH msg IN user_messages.outbound;
              # PROCESS dumper.tt dump = msg.as_tree %]
            <tr>
              <td>
                [% msg.recipient.first_name | ucfirst %]
                [% msg.recipient.last_name  | ucfirst %]
              </td>
              <td>[% msg.received.strftime('%a %d.%b.%Y @ %H:%M') %]</td>
              <td>[% msg.message | html %]</td>
              <td class="borderless">
                [ <a href="[% app_url %]/user/delete_message/[% msg.id %]"
                      alt="delete" title="delete msg">
                    <span class="red">x</span>
                  </a> ]                            
             </td>
          </tr>
          [% END %]                
        </table>
      [% END %]
        
    [% ELSE %]
        <p class="info">No new user messages today</p>
    [% END %]

<!-- END site/messages.tt -->
