<?php
/**
 * The browse view file of lieu 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      Tingting Dai <daitingting@xirangit.com>
 * @package     lieu
 * @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('confirmReview', $lang->lieu->confirmReview)?>
<div id='menuActions'>
  <?php commonModel::printLink('oa.lieu', 'create', "", "<i class='icon icon-plus'></i> {$lang->lieu->create}", "data-toggle='modal' class='btn btn-primary'")?>
</div>
<?php if($type != '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('oa.lieu', $type, "date=$year", $year);?>
            <ul>
              <?php foreach($monthList[$year] as $month):?>
              <li class='<?php echo ($year == $currentYear and $month == $currentMonth) ? 'active' : ''?>'>
                <?php commonModel::printLink('oa.lieu', $type, "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'>
      <?php $canBatchReview = ($lieuList && $type == 'browseReview' && commonModel::hasPriv('lieu', 'batchReview'));?>
      <?php if($canBatchReview):?>
      <form id='batchReviewForm' method='post' action='<?php echo inlink('batchReview', 'status=pass');?>'>
      <?php endif;?>
        <table class='table has-sort-head' id='lieuTable'>
          <thead>
            <tr>
              <?php $vars = "&date={$date}&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
              <th class='w-100px text-left'>
                <?php if($canBatchReview):?>
                <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
                <?php endif;?>
                <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->lieu->id);?>
              </th>
              <th class='w-100px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->lieu->createdBy);?></th>
              <th class='w-100px'><?php echo $lang->user->dept;?></th>
              <th class='w-130px'><?php commonModel::printOrderLink('begin', $orderBy, $vars, $lang->lieu->begin);?></th>
              <th class='w-130px'><?php commonModel::printOrderLink('end', $orderBy, $vars, $lang->lieu->end);?></th>
              <th class='w-70px'><?php commonModel::printOrderLink('hours', $orderBy, $vars, $lang->lieu->hours);?></th>
              <th class='text-left c-desc'><?php echo $lang->lieu->desc;?></th>
              <th class='w-100px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->lieu->status);?></th>
              <?php if($type == 'personal'):?>
              <th class='w-<?php echo $lang->lieu->personalActionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php else:?>
              <th class='w-<?php echo $lang->lieu->actionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php endif;?>
            </tr>
          </thead>
          <?php foreach($lieuList as $lieu):?>
          <?php $viewUrl = commonModel::hasPriv('oa.lieu', 'view') ? $this->createLink('oa.lieu', 'view', "id={$lieu->id}&type=$type") : '';?>
          <tr id='lieu<?php echo $lieu->id;?>' url='<?php echo $viewUrl;?>'>
            <td class='idTD text-left'>
              <?php if($canBatchReview):?>
              <div class='checkbox-primary'><input type='checkbox' name='lieuIDList[]' value="<?php echo $lieu->id;?>" id="lieuIDList<?php echo $lieu->id;?>">
                <label for="lieuIDList<?php echo $lieu->id;?>"></label>
              </div>
              <?php endif;?>
              <?php echo $lieu->id;?>
            </td>
            <td><?php echo zget($users, $lieu->createdBy);?></td>
            <td><?php echo zget($deptList, $lieu->dept, '');?></td>
            <td><?php echo formatTime($lieu->begin . ' ' . $lieu->start, DT_DATETIME2);?></td>
            <td><?php echo formatTime($lieu->end . ' ' . $lieu->finish, DT_DATETIME2);?></td>
            <td><?php echo $lieu->hours;?></td>
            <td class='text-left c-desc' title='<?php echo $lieu->desc;?>'><?php echo $lieu->desc;?></td>
            <td class='lieu-<?php echo $lieu->status;?>'><?php echo $lieu->statusLabel;?></td>
            <td class='actionTD text-left'>
              <?php
              if($viewUrl) echo html::a($viewUrl, $lang->detail, "data-toggle='modal'");

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

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

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

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

                  if($canReview)
                  {
                      echo html::a(inlink('review', "id={$lieu->id}&status=pass"),   $lang->lieu->reviewStatusList['pass'],   "class='reviewPass'");
                      echo html::a(inlink('review', "id={$lieu->id}&status=reject"), $lang->lieu->reviewStatusList['reject'], "data-toggle='modal'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->lieu->reviewStatusList['pass'],   "class='disabled'");
                      echo html::a('javascript:;', $lang->lieu->reviewStatusList['reject'], "class='disabled'");
                  }
              }
              ?>
            </td>
          </tr>
          <?php endforeach;?>
        </table>
        <div class='table-footer'>
          <?php if($canBatchReview):?>
          <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
          <div class='table-actions btn-toolbar'><?php echo html::a('javascript:;', $lang->lieu->reviewStatusList['pass'], "class='btn batchPass'");?></div>
          <?php endif;?>
          <div class='table-statistic'></div>
          <?php $pager->show();?>
        </div>
      <?php if($canBatchReview):?>
      </form>
      <?php endif;?>
    </div>
<?php if($type != 'browseReview'):?>
  </div>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
