<?php
/**
 * The browse view file of attend 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     attend
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/treeview.html.php';?>
<?php $lang->attend->abbrStatusList['rest'] = '';?>
<div id='menuActions'>
  <?php commonModel::printLink('attend', 'export', "date=$currentYear$currentMonth&company=$company", "{$lang->attend->export}", "class='iframe btn btn-primary'")?>
</div>
<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('attend', $company ? 'company' : 'department', "date=$year", $year);?>
            <ul>
              <?php foreach($monthList[$year] as $month):?>
              <li class='<?php echo ($year == $currentYear and $month == $currentMonth) ? 'active' : ''?>'>
                <?php commonModel::printLink('attend', $company ? 'company' : 'department', "date=$year$month", $year . $month);?>
              </li>
              <?php endforeach;?>
            </ul>
          </li>
          <?php endforeach;?>
        </ul>
      </div>
    </div>
  </div>
  <div class='main-col'>
    <div class='panel'>
      <div class='panel-heading text-center'>
        <?php $title = $currentYear;?>
        <?php if($this->app->clientLang != 'en') $title .= $lang->year;?>
        <?php $title .= $currentMonth;?>
        <?php if($this->app->clientLang != 'en') $title .= $lang->month;?>
        <strong><?php echo $title . $lang->attend->report;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-bordered table-fixed'>
          <thead>
            <tr class='text-center'>
              <th rowspan='2' class='w-80px text-middle c-dept'><?php echo $lang->user->dept;?></th>
              <th rowspan='2' class='w-80px text-middle c-name'><?php echo $lang->user->realname;?></th>
              <?php for($day = 1; $day <= $dayNum; $day++):?>
              <th><?php echo $day?></th>
              <?php endfor;?>
            </tr>
            <tr class='text-center'>
              <?php $weekOffset = date('w', strtotime("$currentYear-$currentMonth-01")) - 1;?>
              <?php for($day = 1; $day <= $dayNum; $day++):?>
              <th><?php echo $lang->datepicker->abbrDayNames[($day + $weekOffset) % 7]?></th>
              <?php endfor;?>
            </tr>
          </thead>
          <?php foreach($attends as $dept => $deptAttends):?>
            <?php $isFirst = true;?>
            <?php foreach($deptAttends as $account => $userAttends):?>
            <tr class='text-center'>
              <?php if($isFirst):?>
              <td rowspan='<?php echo count($deptAttends);?>' class='text-middle'>
                <?php echo isset($users[$account]->dept) ? $deptList[$users[$account]->dept] : ''?>
              </td>
              <?php $isFirst = false;?>
              <?php endif;?>
              <td class='text-middle'><?php echo isset($users[$account]->realname) ? $users[$account]->realname : '';?></td>
              <?php for($day = 1; $day <= $dayNum; $day++):?>
                <?php $currentDate = date("Y-m-d", strtotime("{$currentYear}-{$currentMonth}-{$day}"));?>
                <?php if(isset($userAttends[$currentDate])):?>
                <?php 
                $attend = $userAttends[$currentDate];
                $status = $attend->status;
                if($attend->hoursList)
                {
                    $title  = '';
                    $icon   = '';
                    foreach($attend->hoursList as $status => $hours) 
                    {
                        $title .= $lang->attend->statusList[$status] . $hours . 'h ';
                        $icon  .= $lang->attend->markStatusList[$status];
                    }
                }
                else
                {
                    $title = $lang->attend->statusList[$attend->status];
                    $icon  = $lang->attend->markStatusList[$attend->status];
                }
                ?>
                <td class='attend-status attend-<?php echo $status;?>' title='<?php echo $title;?>'>
                  <span><?php echo $icon;?></span>
                </td>
                <?php else:?>
                <td></td>
                <?php endif;?>
              <?php endfor;?>
            </tr>
            <?php endforeach;?>
          <?php endforeach;?>
        </table>
      </div>
      <div class='table-footer legend'>
        <?php foreach($lang->attend->markStatusList as $key => $value):?>
        <span class='legend-item attend-<?php echo $key?>'>
          <i class='legend-i'><?php echo $value?></i>
          <?php echo $lang->attend->statusList[$key]?>
        </span>
        <?php endforeach;?>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
