<?php
/**
 * The browse view file of trip 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      chujilu <chujilu@cnezsoft.com>
 * @package     trip
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/treeview.html.php';?>
<?php js::set('type', $type)?>
<?php js::set('confirmReview', $lang->trip->confirmReview)?>
<div id='menuActions'>
  <?php commonModel::printLink($type, 'create', '', "<i class='icon icon-plus'></i> {$lang->$type->create}", "data-toggle='modal' class='btn btn-primary'")?>
</div>
<?php if($mode != 'browseReview'):?>
<div class='main-row'>
  <div class='side-col'>
    <div class='panel'>
      <div class='panel-body'>
        <ul class='tree' data-collapsed='true'>
          <?php foreach($yearList as $year):?>
          <li class='<?php echo $year == $currentYear ? 'active' : ''?>'>
            <?php commonModel::printLink($type, $mode, "date=$year", $year);?>
            <ul>
              <?php foreach($monthList[$year] as $month):?>
              <li class='<?php echo ($year == $currentYear and $month == $currentMonth) ? 'active' : ''?>'>
                <?php commonModel::printLink($type, $mode, "date=$year$month", $year . $month);?>
              </li>
              <?php endforeach;?>
            </ul>
          </li>
          <?php endforeach;?>
        </ul>
      </div>
    </div>
  </div>
  <div class='main-col'>
<?php endif;?>
    <div class='panel main-table' data-ride='table'>
      <table class='table has-sort-head' id='tripTable'>
        <thead>
          <tr class='text-center'>
            <?php $vars = "date=$date&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
            <th class='w-70px text-left'> <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->$type->id);?></th>
            <th class='w-70px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->$type->createdBy);?></th>
            <th class='w-80px'><?php commonModel::printOrderLink('begin', $orderBy, $vars, $lang->$type->begin);?></th>
            <th class='w-80px'><?php commonModel::printOrderLink('end', $orderBy, $vars, $lang->$type->end);?></th>
            <?php if($type == 'trip'):?>
            <th class='w-100px'><?php commonModel::printOrderLink('from', $orderBy, $vars, $lang->$type->from);?></th>
            <?php endif;?>
            <th class='w-100px'><?php commonModel::printOrderLink('to', $orderBy, $vars, $lang->$type->to);?></th>
            <th class='w-150px'><?php commonModel::printOrderLink('customers', $orderBy, $vars, $lang->$type->customer);?></th>
            <th><?php echo $lang->$type->desc;?></th>
            <th class='w-100px'><?php echo $lang->trip->status;?></th>
            <th class='w-160px'><?php echo $lang->actions;?></th>
          </tr>
        </thead>
        <?php foreach($tripList as $trip):?>
        <?php $viewUrl = commonModel::hasPriv('oa.trip', 'view') ? $this->createLink("oa.$type", 'view', "id=$trip->id&type=$mode") : '';?>
        <tr>
          <td><?php echo $trip->id;?></td>
          <td><?php echo zget($users, $trip->createdBy);?></td>
          <td class='text-center'><?php echo formatTime($trip->begin . ' ' . $trip->start, $trip->type == 'trip' ? DT_DATE1 : DT_DATETIME2);?></td>
          <td class='text-center'><?php echo formatTime($trip->end . ' ' . $trip->finish, $trip->type == 'trip' ? DT_DATE1 : DT_DATETIME2);?></td>
          <?php if($type == 'trip'):?>
          <td class='c-name' title='<?php echo $trip->from?>'><?php echo $trip->from;?></td>
          <?php endif;?>
          <td class='c-name' title='<?php echo $trip->to?>'>  <?php echo $trip->to;?></td>
          <?php $tripCustomer = '';?>
          <?php foreach(explode(',', $trip->customers) as $customer) $tripCustomer .= zget($customers, $customer, '') . '/';?>
          <?php $tripCustomer = trim($tripCustomer, '/');?>
          <td class='c-name' title='<?php echo $tripCustomer;?>'><?php echo $tripCustomer;?></td>
          <td title='<?php echo $trip->desc?>'><?php echo $trip->desc;?></td>
          <td class='text-center trip-<?php echo $trip->status;?>'><?php echo $trip->statusLabel;?></td>
          <td class='text-center'>
            <?php 
            if($viewUrl) echo html::a($viewUrl, $lang->detail, "data-toggle='modal'");

            if($mode == 'personal')
            {
                $canEdit   = $this->trip->isClickable($trip, 'edit');
                $canDelete = $this->trip->isClickable($trip, 'delete');
                $canSwitch = $this->trip->isClickable($trip, 'switchStatus');

                $switchLabel = $trip->status == 'wait' ? $lang->trip->cancel : $lang->trip->submit;
                if($canSwitch)
                {
                    commonModel::printLink('oa.trip', 'switchstatus', "id=$trip->id", $switchLabel, "class='reload'");
                }
                else
                {
                    echo html::a('javascript:;', $switchLabel,  "class='disabled'");
                }

                if($canEdit)
                {
                    echo html::a(inlink('edit', "id=$trip->id"), $lang->edit, "data-toggle='modal'");
                }
                else
                {
                    echo html::a('javascript:;', $lang->edit, "class='disabled'");
                }

                if($canDelete)
                {
                    echo html::a(inlink('delete', "id=$trip->id"), $lang->delete, "class='deleter'");
                }
                else
                {
                    echo html::a('javascript:;', $lang->delete, "class='disabled'");
                }
            }
            else
            {
                $canReview = $this->trip->isClickable($trip, 'review');

                if($canReview)
                {
                    echo html::a(inlink('review', "id=$trip->id&status=pass"),   $lang->trip->reviewStatusList['pass'],   "class='reviewPass'");
                    echo html::a(inlink('review', "id=$trip->id&status=reject"), $lang->trip->reviewStatusList['reject'], "data-toggle='modal'");
                }
                else
                {
                    echo html::a('javascript:;', $lang->trip->reviewStatusList['pass'],   "class='disabled'");
                    echo html::a('javascript:;', $lang->trip->reviewStatusList['reject'], "class='disabled'");
                }
            }
            ?>
          </td>
        </tr>
        <?php endforeach;?>
      </table>
      <div class='table-footer'>
        <?php $pager->show();?>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
