<?php echo form_tag('message/delete', array('name'=>'listform')) ?>
  <?php echo input_hidden_tag('type', $box_type) ?>
  <table class="table-content" style="width:100%">
    <tr>
      <th style="width:20px"><?php echo checkbox_tag('items', '', false, array('onclick'=>'check_all();')) ?></th>
      <th>Tiêu đề</th>
      <th style="width:120px;">Người <?php echo ($box_type=='inbox')? 'gửi': 'nhận'?></th>
      <th style="width:30px;">Ngày</th>
    </tr>

    <?php foreach ($pager->getResult() as $key => $message): ?>
      <tr class="row<?php echo $key%2?>">
        <td><?php echo checkbox_tag('items[]', $message->getMsId(), false, array('id'=>'items')) ?></td>
        <td>
          <div<?php echo ($message->getMsStatus()=='0'? ' class="msg-unread"': '') ?>>
            <?php echo link_to($message->getMsSubject(), "/message/mailbox?type=$box_type&ms_id=".$message->getMsId()) ?>
          </div>
        </td>
        <td>
          <?php $name = ($box_type=='inbox')? $message->getMsSenderName(): $message->getMsReceiverName() ?>
          <?php $user = ($box_type=='inbox')? $message->getMsFrom(): $message->getMsTo() ?>
          <?php $done = ($box_type=='inbox')? 'nhận từ': 'gửi cho' ?>
          <?php echo link_to($name, "/message/mailbox?type=$box_type&partner=$user", array('title'=>"Xem tất cả thư đã $done $name")) ?>
        </td>
        <td title="<?php echo $message->getMsTime('H:i:s d-m-Y');?>">
          <?php echo $message->getMsTime('d/m');?>
        </td>
      </tr> 
    <?php endforeach; ?>

    <?php if ($pager->getTotalRecordCount() == 0): ?>
      <tr><td colspan="4">Bạn chưa <?php echo ($box_type=='inbox')? 'nhận': 'gửi'?> tin nhắn nào</td></tr>
    <?php else: ?>
      <tr><th colspan="4"><?php echo link_to('Xóa', '#', array('onclick'=>'delete_all();')) ?></th></tr>
    <?php endif; ?>
  </table>
  <br>
  <?php $baseLink = "/message/mailbox?type=$box_type" . ($partner? '&partner='.$partner: '') ?>
  <center><?php echo showPageNav13($pager, $baseLink); ?></center> 
</form>

<?php $sf_context->getResponse()->addJavascriptCommand('
  check_all = function() {
    for (var i = 1; i < items.length; i++) items[i].checked = items[0].checked;
  }
  delete_all = function() {
    for (var i = 1; i < items.length; i++) if (items[i].checked) break;
    if (i == items.length) {alert ("Vui lòng đánh dấu vào các tin nhắn bạn muốn xóa"); return;}
    if (confirm("Bạn có chắc chắn muốn xóa các tin nhắn đã chọn?")) document.listform.submit();
  }
'); ?>
