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

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

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

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

                  if($canReview)
                  {
                      echo html::a(inlink('review', "id=$makeup->id&status=pass"),   $lang->makeup->statusList['pass'],   "class='reviewPass'");
                      echo html::a(inlink('review', "id=$makeup->id&status=reject"), $lang->makeup->statusList['reject'], "data-toggle='modal'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->makeup->statusList['pass'],   "class='disabled'");
                      echo html::a('javascript:;', $lang->makeup->statusList['reject'], "class='disabled'");
                  }
              }
              ?>
            </td>
          </tr>
          <?php endforeach;?>
        </table>
        <?php if(!$makeupList):?>
        <div class='table-footer'>
          <div class='pager' style='float: right; clear: none'><?php echo $lang->pager->noRecord;?></div>
        </div>
        <?php endif;?>
        <?php if($canBatchReview):?>
        <div class='table-footer'>
          <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->makeup->statusList['pass'], "class='btn batchPass'");?>
          <div class='table-statistic'></div>
        </div>
      </form>
      <?php endif;?>
    </div>
<?php if($type != 'browseReview'):?>
  </div>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
