<?php
/**
 * The browse view file of leave 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     leave
 * @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->leave->confirmReview);?>
<div id='menuActions'>
  <?php commonModel::printLink('oa.leave', 'export', "mode=all", $lang->exportIcon . $lang->export, "class='btn btn-secondary iframe' data-width='700'");?>
  <?php commonModel::printLink('oa.leave', 'create', '', "<i class='icon icon-plus'></i> {$lang->leave->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.leave', $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.leave', $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 = ($leaveList && $type == 'browseReview' && commonModel::hasPriv('leave', '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='leaveTable'>
          <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 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->leave->id);?>
              </th>
              <th class='w-100px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->leave->createdBy);?></th>
              <th><?php echo $lang->user->dept;?></th>
              <th class='w-60px'><?php commonModel::printOrderLink('type', $orderBy, $vars, $lang->leave->type);?></th>
              <th class='w-140px'><?php commonModel::printOrderLink('begin', $orderBy, $vars, $lang->leave->start);?></th>
              <th class='w-140px'><?php commonModel::printOrderLink('end', $orderBy, $vars, $lang->leave->finish);?></th>
              <th class='w-140px'><?php commonModel::printOrderLink('backDate', $orderBy, $vars, $lang->leave->backDate);?></th>
              <th class='w-70px'><?php commonModel::printOrderLink('hours', $orderBy, $vars, $lang->leave->hours);?></th>
              <th class='text-left c-desc'><?php echo $lang->leave->desc;?></th>
              <th class='w-100px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->leave->status);?></th>
              <?php if($type == 'personal'):?>
              <th class='w-<?php echo $lang->leave->personalActionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php else:?>
              <th class='w-<?php echo $lang->leave->actionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php endif;?>
            </tr>
          </thead>
          <?php foreach($leaveList as $leave):?>
          <?php $viewUrl = commonModel::hasPriv('oa.leave', 'view') ? $this->createLink('oa.leave', 'view', "id={$leave->id}&type=$type") : '';?>
          <tr class='text-center' id='leave<?php echo $leave->id;?>' url='<?php echo $viewUrl;?>'>
            <td class='idTD text-left'>
              <?php if($canBatchReview):?>
              <div class='checkbox-primary'><input type='checkbox' name='leaveIDList[]' value="<?php echo $leave->id;?>" id="leaveIDList<?php echo $leave->id;?>">
                <label for="leaveIDList<?php echo $leave->id;?>"></label>
              </div>
              <?php endif;?>
              <?php echo $leave->id;?>
            </td>
            <td><?php echo zget($users, $leave->createdBy);?></td>
            <td><?php echo zget($deptList, $leave->dept);?></td>
            <td><?php echo zget($lang->leave->typeList, $leave->type);?></td>
            <td><?php echo formatTime($leave->begin . ' ' . $leave->start, $leave->type == 'annual' ? DT_DATE1 : DT_DATETIME2);?></td>
            <td><?php echo formatTime($leave->end . ' ' . $leave->finish, $leave->type == 'annual' ? DT_DATE1 : DT_DATETIME2);?></td>
            <td><?php echo formatTime($leave->backDate, DT_DATETIME2);?></td>
            <td><?php echo $leave->hours == 0 ? '' : $leave->hours . ($leave->type == 'annual' ? $lang->leave->daysTip : $lang->leave->hoursTip);?></td>
            <td class='text-left c-desc' title='<?php echo $leave->desc;?>'><?php echo $leave->desc;?></td>
            <td class='leave-<?php echo $leave->status?>' title='<?php echo $leave->statusLabel;?>'><?php echo $leave->statusLabel;?></td>
            <td class='actionTD text-left'>
              <?php
              if($viewUrl) echo html::a($viewUrl, $lang->detail, "data-toggle='modal'");

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

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

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

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

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

                  if($canReview)
                  {
                      $params = $leave->status == 'back' ? '&mode=back' : '';
                      echo html::a(inlink('review', "id={$leave->id}&status=pass$params"),   $lang->leave->reviewStatusList['pass'],   "class='reviewPass'");
                      echo html::a(inlink('review', "id={$leave->id}&status=reject$params"), $lang->leave->reviewStatusList['reject'], "data-toggle='modal'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->leave->reviewStatusList['pass'],   "class='disabled'");
                      echo html::a('javascript:;', $lang->leave->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->leave->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';?>
