<?php
/**
 * The detail 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      Gang Liu <liugang@cnezsoft.com>
 * @package     leave 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../../sys/common/view/header.modal.html.php';?>
<table class='table table-bordered leaveTable'>
  <tr>
    <th class='w-90px'><?php echo $lang->leave->createdBy;?></th>
    <td><?php echo zget($users, $leave->createdBy) . $lang->at . $leave->createdDate;?></th>
  </tr>
  <tr>
    <th><?php echo $lang->leave->dateRange;?></th>
    <td>
      <?php echo formatTime($leave->begin . ' ' . $leave->start, DT_DATETIME2) . '~' . formatTime($leave->end . ' ' . $leave->finish, DT_DATETIME2);?>
      <?php echo $lang->leave->hours . $leave->hours . $lang->leave->hoursTip;?>
    </td>
  </tr>
  <tr>
    <th><?php echo $lang->leave->desc;?></th>
    <td>
      <span class='label label-info'><?php echo zget($lang->leave->typeList, $leave->type);?></span>
      <?php echo $leave->desc;?>
    </td>
  </tr>
  <tr>
    <th><?php echo $lang->leave->backDate;?></th>
    <td>
      <?php echo formatTime($leave->backDate, DT_DATETIME2);?>
    </td>
  </tr>
  <tr>
    <th><?php echo $lang->leave->status;?></th>
    <td class='status'>
      <?php
      $class = 'text-warning';
      if($reviewer && strpos('wait,doing', $leave->status) !== false)
      {
          echo zget($users, $reviewer);
          echo "<span class='{$class}'>{$lang->leave->statusList['doing']}</span>";
      }
      else
      {
          if($leave->status == 'pass')   $class = 'text-success';
          if($leave->status == 'reject') $class = 'text-danger';
          echo "<span class='{$class}'>{$lang->leave->statusList[$leave->status]}</span>";
      }
      ?>
    </td>
  </tr>
  <tr>
    <th><?php echo $lang->leave->reviewedBy;?></th>
    <td id='reviewedBy'>
      <?php
      if($leave->reviewedBy)
      {
          if($leave->status == 'reject')
          {
              $reviewStatus = "<span class='text-danger'> " . $lang->leave->review . $lang->leave->statusList['reject'] . '</span>';
          }
          else
          {
              $reviewStatus = "<span class='text-success'> " . $lang->leave->review . $lang->leave->statusList['pass'] . '</span>';
          }

          echo zget($users, $leave->reviewedBy) . $reviewStatus . $lang->at . formatTime($leave->reviewedDate, DT_DATETIME1);
      }
      ?>
    </td>
  </tr>
</table>
<?php echo $this->fetch('action', 'history', "objectType=leave&objectID=$leave->id");?>
<div class='main-actions text-center'>
  <div class='btn-toolbar'>
    <?php 
    echo html::a('javascript:;', $lang->goback, "class='btn' data-dismiss='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 "<div class='divider'></div>";
            echo html::a(inlink('back', "id={$leave->id}"), $lang->leave->back, "class='btn loadInModal'");
        }
        if($canSwitch or $canEdit or $canDelete)
        {
            echo "<div class='divider'></div>";
            if($canSwitch)
            {
                $switchLabel = $leave->status == 'wait' ? $lang->leave->cancel : $lang->leave->submit;
                echo html::a(inlink('switchStatus', "id={$leave->id}"), $switchLabel, "class='btn'");
            }
            if($canEdit) echo html::a(inlink('edit', "id={$leave->id}"), $lang->edit, "class='btn loadInModal'");
            if($canDelete) echo html::a(inlink('delete', "id={$leave->id}"), $lang->delete, "class='btn deleteLeave'");
        }
    }
    else
    {
        $canReview = $this->leave->isClickable($leave, 'review');

        if($canReview)
        {
            $params = $leave->status == 'back' ? '&mode=back' : '';

            echo "<div class='divider'></div>";
            echo html::a(inlink('review', "id={$leave->id}&status=pass$params"),   $lang->leave->statusList['pass'],   "class='btn reviewPass'");
            echo html::a(inlink('review', "id={$leave->id}&status=reject$params"), $lang->leave->statusList['reject'], "class='btn loadInModal'");
        }
    }
    ?>
  </div>
</div>
<?php include '../../../sys/common/view/footer.modal.html.php';?>
