<?php use_helper('ModalBox'); ?>
<table class="table-content" style="width: 100%" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th width="5%"><?php echo checkbox_tag('supporter', '', false, array('onclick'=>'checkAll(supporter);')) ?></th>
    <th width="25%">Họ tên</th>
    <th width="25%">Nick yahoo</th>
    <th width="20%">Vị trí</th>
    <th width="25%">Trạng thái</th>
  </tr>
  <?php foreach($listSupport as $key => $item):?>
  <tr class="row<?php echo $key%2;?>">
    <td><?php echo checkbox_tag('supporter', $item['nick'], false) ?></td>
    <?php foreach(array('name', 'nick') as $field):?>
    <td><?php echo m_link_to($item[$field], '/admin/editsupport?key='.$key, array('title'=>'Đổi thông tin hỗ trợ trực tuyến'))?></td>
    <?php endforeach;?>
    <td>
      <?php echo form_tag('/admin/updateordersupport', array('id'=>'orderform'.$key)) ?>
      <?php echo input_hidden_tag('key', $key)?>
      <select name="order" onchange="<?php echo m_submit_element() ?>">
        <?php for($i = 0; $i < count($listSupport); $i++):?>
        <option<?php if($i == $key) echo ' selected';?>><?php echo $i + 1 ?></option>
        <?php endfor;?>
      </select>
      </form>
    </td>
    <td><?php echo content_tag('a', image_tag('http://opi.yahoo.com/online?u='.$item['nick'].'&amp;m=g&amp;t=2&amp;l=us'), array('href'=>'ymsgr:sendIM?'.$item['nick'])) ?></td>
  </tr>
  <?php endforeach ?>
</table>

<div style="margin-top:10px;">
  <?php echo input_hidden_tag('del_supporters', '') ?>
  <?php echo m_link_to('Xóa', '/admin/delsupport', array('onclick'=>'if(!getDelLink(supporter)) return false;'), array(), array('id'=>"$('del_supporters').value")) ?> |
  <?php echo m_link_to('Tạo mới','/admin/editsupport', array('title'=>'Thêm người hỗ trợ trực tuyến')) ?>
  <div style="float:right"><?php echo m_finish('Thoát') ?></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_supporters").value = ids.join("|");
  return true;
}
') ?>
