<?php
js::set('objectType', $objectType);
js::set('objectID',   $objectID);
css::internal($pageCSS);
?>
<?php if(isset($comments) and $comments):?>
<div class='panel'>
  <div class='panel-heading'>
    <div class='panel-actions pull-right'><a href='#commentForm' class='btn btn-primary'><i class='icon-comment-alt'></i> <?php echo $lang->message->post; ?></a></div>
    <strong><i class='icon-comments'></i> <?php echo $lang->message->list;?></strong>
  </div>
  <div class='panel-body'>
    <div class='comments-list'>
      <?php foreach($comments as $number => $comment):?>
      <div class='comment' id="comment<?php echo $comment->id?>">
        <div class='content'>
          <div class='text'><span class='author'><strong><?php echo $comment->from . $lang->colon;?></strong></span> &nbsp;<?php echo nl2br($comment->content);?></div>
          <div class='actions text-muted small'>
            <div class='pull-right'></div>
            <?php echo $lang->comment->commentAt . ' ' . formatTime($comment->date, DT_DATETIME1);?>
          </div>
        </div>
        <?php if(!empty($replies[$comment->id])):?>
          <div class='comments-list'>
            <?php foreach($replies[$comment->id] as $reply):?>
            <div class='comment'>
              <div class='content'>
                <div class='text'><span class='author'><strong><?php echo $reply->from . $lang->colon;?></strong></span> &nbsp;<?php echo nl2br($reply->content);?></div>
                <div class='actions text-muted small'><?php echo $lang->comment->replyAt . ' ' . formatTime($reply->date, DT_DATETIME1);?></div>
              </div>
            </div>
            <?php endforeach; ?>
          </div>
        <?php endif;?>
      </div>
      <?php endforeach;?>
    </div>
    <div class='clearfix'><?php $pager->show('right', 'shortest');?></div>
  </div>
</div>
<?php endif;?>

<div class='panel'>
  <div class='panel-heading'><strong><i class='icon-comment-alt'></i> <?php echo $lang->message->post;?></strong></div>
  <div class='panel-body'>
    <form method='post' class='form-horizontal' id='commentForm' action="<?php echo $this->createLink('message', 'post', 'type=comment');?>">
      <table class='table table-form'>
        <tr>
          <th class='w-70px'><?php echo $lang->message->from; ?></th>
          <td>
            <i class='icon-user text-muted'></i> <strong><?php echo $this->session->user->realname ;?></strong>
            <?php echo html::hidden('from', $this->session->user->realname);?>
          </td>
        </tr>
        <tr>
          <th><?php echo $lang->message->content; ?></th>
          <td>
            <?php
            echo html::textarea('content', '', "class='form-control'");
            echo html::hidden('objectType', $objectType);
            echo html::hidden('objectID', $objectID);
            ?>
          </td>
        </tr>
        <tr class='hide'>
          <th></th>
          <td id='captchaBox'></td>
        </tr>
        <tr>
          <th></th>
          <td class='form-actions'><?php echo html::submitButton();?></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<?php js::execute($pageJS);?>
