<?php use_helper('tvtl', 'ModalBox'); ?>
<div id="listpoll">
<table class="table-content" style="width:100%">
  <tr>
    <th width="5%"><?php echo checkbox_tag('poll', '', false, array('onclick'=>'checkAll(poll)')) ?></th>
    <th width="40%">Câu hỏi điều tra</th>
    <th width="40%">Các phương án lựa chọn</th>
    <th width="15%" style="text-align:center">Trạng thái</th>
  </tr>
  <?php foreach ($pager->getResult() as $i => $poll): ?>
  <tr class="row<?php echo $i%2;?>">
    <td><?php echo checkbox_tag('poll', $poll->getPollId(), false) ?></td>
    <td><?php echo m_link_to($poll->getPollName(), '/admin/editpoll?page='.$page.'&id='.$poll->getPollId(), array('title'=>"Sửa câu hỏi này"))?></td>
    <td><ul>
      <?php $answers = explode('|', $poll->getPollQuestions());
      $total = $results[$poll->getPollId()]['total'];
      foreach ($answers as $key => $answer) {
        $num = $results[$poll->getPollId()]['answer'][$key];
        $percent = ($total > 0)? round($num * 100 / $total): 0;
        echo "<li>$answer ($percent%)</li>";
      }?>
    </ul></td>
    <td style="text-align:center"><?php
      if ($poll->getPollActive() == 1) echo 'Đang chạy';
      else echo '<u>'.m_link_to('Đang ẩn', '/admin/updatepoll?actId='.$poll->getPollId(), array('title'=>'Chạy câu hỏi điều tra này')).'</u>'
    ?></td>
  </tr>
  <?php endforeach ?>
</table>

<div style="margin-top:10px;">
  <?php echo input_hidden_tag('del_polls', '') ?>
  <?php echo m_link_to('Xóa', '/admin/updatepoll', array('onclick'=>'if(!getDelLink(poll)) return false;'), array(), array('poll'=>"$('del_polls').value")) ?> |
  <?php echo m_link_to('Tạo mới', '/admin/editpoll?page='.$page) ?> |
  <?php echo m_finish('Thoát') ?>
  <div style="float:right"><?php echo showPageNav13($pager, '/admin/listpoll', 'listpoll') ?></div>
</div>
</div>

<?php $sf_context->getResponse()->addJavascriptCommand('
checkAll = function(items) {
  for (var i=1; i<items.length; i++) items[i].checked = items[0].checked;
}
getDelLink = function(items) {
  var ids = new Array();
  for (var i = 1; i < items.length; i++) if (items[i].checked) ids.push(items[i].value);
  if (ids.length == 0) {alert ("Bạn phải chọn ít nhất một thành viên"); return false;}
  if (!confirm("Bạn có chắc chắn không?")) return false;
  $("del_polls").value = ids.join("|");
  return true;
}
$("MB_window").style.height = "auto";
') ?>
