<?php 
/**
 * The browse view file of exchange module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Yuting Wang <wangyuting@cnezsoft.com>
 * @package     exchange
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php if($source == 'my'):?>
<?php include '../../my/view/header.html.php';?>
<?php else:?>
<?php include '../../common/view/header.html.php';?>
<?php endif;?>

<?php include '../../common/view/confirmer.html.php';?>

<?php js::set('source', $source);?>
<?php if($source != 'my'):?>
<?php js::set('mode', $mode);?>
<li id='bysearchTab'><?php echo html::a('#', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<?php endif;?>

<div class='panel main-table' data-ride='table'>
  <table class='table has-sort-head' id='exchageList'>
    <thead>
      <tr class='text-center'>
        <?php $vars = "mode=$mode&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
        <th class='w-70px'><?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->exchange->id);?></th>
        <th class='text-left'><?php commonModel::printOrderLink('gift', $orderBy, $vars, $lang->exchange->gift);?></th>
        <th class='text-left'><?php echo $lang->gift->desc;?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('amount', $orderBy, $vars, $lang->exchange->amount);?></th>
        <th class='w-120px'><?php commonModel::printOrderLink('score', $orderBy, $vars, $lang->exchange->score);?></th>
        <?php if($type != 'my'):?>
        <th class='w-100px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->exchange->createdBy);?> </th>
        <?php endif;?>
        <th class='w-140px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->exchange->createdDate);?></th>
        <?php if($type != 'toGrant'):?>
        <th class='w-140px'><?php commonModel::printOrderLink('grantedDate', $orderBy, $vars, $lang->exchange->grantedDate);?></th>
        <?php endif;?>
        <th class='w-80px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->exchange->status);?></th>
        <?php if($type != 'all'):?>
        <th class='w-80px'><?php echo $lang->actions;?></th>
        <?php endif;?>
      </tr>
    </thead>
    <tbody>
      <?php $canViewGift = commonModel::hasPriv('gift', 'view');?>
      <?php foreach($exchangeList as $exchange):?>
      <tr class='text-center'>
        <td><?php echo $exchange->id;?></td>
        <?php $gift = zget($gifts, $exchange->gift);?>
        <?php $name = zget($gift, 'name', $exchange->gift);?>
        <?php $desc = zget($gift, 'name', $exchange->gift);?>
        <td class='text-left'><?php echo $canViewGift ? html::a($this->createLink('gift', 'view', "giftID={$exchange->gift}"), $name) : $name;?></td>
        <td class='text-left' title='<?php echo $desc;?>'><?php echo $desc;?></td>
        <td><?php echo $exchange->amount;?></td>
        <td><?php echo $exchange->score;?></td>
        <?php if($type != 'my'):?>
        <td><?php echo zget($users, $exchange->createdBy);?></td>
        <?php endif;?>
        <td><?php echo formatTime($exchange->createdDate);?></td>
        <?php if($type != 'toGrant'):?>
        <td><?php echo formatTime($exchange->grantedDate);?></td>
        <?php endif;?>
        <td><?php echo zget($lang->exchange->statusList, $exchange->status);?></td>
        <?php if($type != 'all'):?>
        <td>
          <?php
          if($type == 'toGrant')
          {
              if(!commonModel::printLink('exchange', 'grant', "exchangeID={$exchange->id}", $lang->exchange->grant, "class='confirmer' data-confirmTitle='{$lang->exchange->tip->confirmGrantTitle}' data-confirmDetail='{$lang->exchange->tip->confirmGrantDetail}' data-confirmButton='{$lang->confirm}' data-confirming='{$lang->exchange->granting}'")) echo html::a('javascript:;', $lang->exchange->grant, "class='disabled'");

              $clear               = $lastClearTime > $exchange->createdDate;
              $confirmCancelDetail = $clear ? $lang->exchange->tip->confirmCancelDetailb : $lang->exchange->tip->confirmCancelDetaila;
              if(!commonModel::printLink('exchange', 'cancel', "exchangeID={$exchange->id}&clear={$clear}", $lang->cancel, "class='confirmer' data-confirmTitle='{$lang->exchange->tip->confirmCancelTitle}' data-confirmDetail='{$confirmCancelDetail}' data-confirmButton='{$lang->confirm}' data-confirming='{$lang->exchange->canceling}'")) echo html::a('javascript:;', $lang->cancel, "class='disabled'");
          }

          if($type == 'my')
          {
              if($exchange->status == 'granted' && commonModel::hasPriv('exchange', 'finish'))
              {
                  echo html::a($this->createLink('exchange', 'finish', "exchangeID=$exchange->id"), $lang->exchange->finish, "class='reload'");
              }
              else
              {
                  echo html::a('javascript:;', $lang->exchange->finish, "class='disabled'");
              }
          }
          ?>
        </td>
        <?php endif;?>
      </tr>
      <?php endforeach;?>
    </tbody>
  </table>
  <div class='table-footer'><?php $pager->show();?></div>
</div>
<?php include '../../common/view/footer.html.php';?>
