<?php
/**
 * The yyy view file of score module of ZDOO.
 *
 * @copyright   Copyright 2009-2020 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Gang Liu <liugang@easycorp.ltd>
 * @package     score
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php $this->app->loadLang('search');?>
<?php js::set('type', $type);?>
<div class='main-row'>
  <div class='side-col'>
    <div class='panel'>
      <div class='panel-body'>
        <nav class='menu leftmenu'>
          <ul class='nav nav-primary'>
            <?php foreach($lang->score->report->menus as $menuType => $menu):?>
            <?php list($label, $moduleName, $methodName, $vars) = explode('|', $menu);?>
            <li <?php if($menuType == $type) echo "class='active'";?>><?php echo html::a($this->createLink($moduleName, $methodName, $vars), $label);?></li>
            <?php endforeach;?>
          </ul>
        </nav>
      </div>
    </div>
  </div>
  <div class='main-col'>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <div class='input-group w-500px'>
          <div class='input-group-addon'><?php echo $lang->score->report->year;?></div>
          <?php echo html::select('year', $years, $year, "class='form-control chosen'");?>
          <div class='input-group-addon'><?php echo $lang->score->report->dept;?></div>
          <?php echo html::select('dept', $depts, $dept, "class='form-control chosen'");?>
          <div class='input-group-btn'><?php echo html::a(inlink('report', "type=$type&year=$year&dept=$dept"), $lang->search->common, "class='btn btn-primary btn-search'");?></div>
          <script>$('.chosen').chosen();</script> <!- Init the chosen here to avoid the page flicker. ->
        </div>
      </div>
      <div class='panel-body'>
        <table class='table table-bordered table-hover table-striped'>
          <thead>
            <tr class='text-center'>
              <th><?php echo $lang->score->report->dept;?></th>
              <th><?php echo $lang->score->report->user;?></th>
              <th><?php echo $lang->score->report->item;?></th>
              <?php foreach($lang->datepicker->monthNames as $name):?>
              <th><?php echo $name;?></th>
              <?php endforeach;?>
              <th><?php echo $lang->total;?></th>
            </tr>
          </thead>
          <tbody>
            <?php
            foreach($reportData as $dept => $deptUsers)
            {
                $rowspan  = '_' . $dept;
                $$rowspan = 0;
                foreach($deptUsers as $user => $userData)
                {
                    foreach($userData as $type => $monthData) $$rowspan++;
                }
            }
            
            foreach($reportData as $dept => $deptUsers)
            {
                $rowspan   = '_' . $dept;
                $userIndex = 1;
                foreach($deptUsers as $user => $userData)
                {
                    $typeIndex = 1;
                    foreach($userData as $type => $monthData)
                    {
                        echo "<tr class='text-center text-middle'>";
            
                        if($dept == $lang->total)
                        {
                            if($typeIndex == 1) echo "<th rowspan='2' colspan='2'>{$dept}</th>";
                        }
                        else
                        {
                            if($userIndex == 1) echo "<th rowspan='{$$rowspan}'>{$dept}</th>";
                            if($typeIndex == 1) echo "<th rowspan='2'>{$user}</th>";
                        }
            
                        echo "<th>{$type}</th>";
                        foreach($monthData as $value) echo '<td>' . ($value ? $value : '') . '</td>';
                        echo "</tr>";

                        $userIndex++;
                        $typeIndex++;
                    }
                }
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
