<?php
/**
 * The view file of task 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      Yidong Wang <yidong@cnezsoft.com>
 * @package     task
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php if($mode) js::set('mode', $mode);?>
<?php js::set('projectID', $projectID);?>
<?php if($projectID):?>
<?php js::set('backLink', $backLink);?>
<?php endif;?>
<li id='bysearchTab'><?php echo html::a('javascript:;', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div class='main-row'>
  <div class='panel main-table' data-ride='table'>
    <?php $canBatchClose = ($tasks && commonModel::hasPriv('task', 'batchClose'));?>
    <?php if($canBatchClose):?>
    <form id='ajaxForm' method='post' action="<?php echo $this->createLink('proj.task', 'batchClose');?>">
    <?php endif;?>
      <table class='table has-sort-head' id='taskList'>
        <thead>
          <tr class='text-center'>
            <?php $vars = "projectID=$projectID&mode={$mode}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
            <th class='text-left w-100px'>
              <?php if($canBatchClose):?>
              <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
              <?php endif;?>
              <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->task->id);?>
            </th>
            <th class='w-40px'> <?php commonModel::printOrderLink('pri',        $orderBy, $vars, $lang->task->lblPri);?></th>
            <th>                <?php commonModel::printOrderLink('name',       $orderBy, $vars, $lang->task->name);?></th>
            <th class='w-100px'><?php commonModel::printOrderLink('deadline',   $orderBy, $vars, $lang->task->deadline);?></th>
            <th class='w-80px'> <?php commonModel::printOrderLink('assignedTo', $orderBy, $vars, $lang->task->assignedTo);?></th>
            <th class='w-90px'> <?php commonModel::printOrderLink('status',     $orderBy, $vars, $lang->task->status);?></th>
            <th class='w-90px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->task->createdDate);?></th>
            <th class='w-80px'><?php commonModel::printOrderLink('consumed',    $orderBy, $vars, $lang->task->consumedAB . $lang->task->lblHour);?></th>
            <th class='w-100px'><?php commonModel::printOrderLink('left',       $orderBy, $vars, $lang->task->leftAB . $lang->task->lblHour);?></th>
            <?php $class = $this->app->clientLang == 'en' ? 'w-280px' : 'w-240px';?>
            <th class='<?php echo $class;?>'><?php echo $lang->actions;?></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($tasks as $task):?>
          <tr class='text-center'>
            <td class='text-left'>
              <?php if($canBatchClose):?>
              <div class='checkbox-primary'><input type='checkbox' name='taskIDList[]' value="<?php echo $task->id;?>" id="taskIDList<?php echo $task->id;?>">
                <label for="taskIDList<?php echo $task->id;?>"></label>
              </div>
              <?php endif;?>
              <?php echo $task->id;?>
            </td>
            <td><span class='active label-pri label-pri-<?php echo $task->pri; ?>'><?php echo $lang->task->priList[$task->pri];?></span></td>
            <td class='text-left <?php if(!empty($task->children)) echo 'has-child';?>' title="<?php echo $task->name;?>">
              <?php if($task->parent != 0) echo "<span class='label label-info'>{$lang->task->childrenAB}</span>"?>
              <?php if(!empty($task->team)) echo "<span class='label label-info'>{$lang->task->multipleAB}</span>"?>
              <?php echo html::a($this->createLink('task', 'view', "taskID=$task->id&from=$from"), $task->name);?>
              <?php if(!empty($task->children)) echo '<a class="task-toggle" data-id="' . $task->id . '"><i class="icon icon-angle-right"></i></a>';?>
            </td>
            <td><?php echo formatTime($task->deadline, DT_DATE1);?></td>
            <td><?php if(isset($users[$task->assignedTo])) echo $users[$task->assignedTo];?></td>
            <td class="<?php echo $task->status;?>"><?php echo zget($lang->task->statusList, $task->status);?></td>
            <td><?php echo formatTime($task->createdDate, DT_DATE1);?></td>
            <td><?php echo $task->consumed;?></td>
            <td><?php echo $task->left;?></td>
            <td class='text-left'><?php $this->task->buildOperateMenu($task, '', 'browse', true, $from);?></td>
          </tr>
          <?php if(!empty($task->children)):?>
          <?php $i = 0;?>
          <?php foreach($task->children as $key => $child):?>
          <?php $class  = $i == 0 ? ' table-child-top' : '';?>
          <?php $class .= ($i + 1 == count($task->children)) ? ' table-child-bottom' : '';?>
          <tr class='text-center table-children<?php echo $class;?> parent-<?php echo $task->id;?>' data-id='<?php echo $child->id?>' data-status='<?php echo $child->status?>' data-estimate='<?php echo $child->estimate?>' data-consumed='<?php echo $child->consumed?>' data-left='<?php echo $child->left?>'>
            <td class='text-left'>
              <?php if($canBatchClose):?>
              <div class='checkbox-primary'><input type='checkbox' name='taskIDList[]' value="<?php echo $child->id;?>" id="taskIDList<?php echo $child->id;?>">
                <label for="taskIDList<?php echo $child->id;?>"></label>
              </div>
              <?php endif;?>
              <?php echo $child->id;?>
            </td>
            <td><span class='active label-pri label-pri-<?php echo $child->pri; ?>'><?php echo $lang->task->priList[$child->pri];?></span></td>
            <td class='text-left' title='<?php echo $child->name;?>'>
              <span class='label label-info'><?php echo $lang->task->childrenAB?></span>
              <?php echo html::a($this->createLink('task', 'view', "taskID=$child->id"), $child->name);?>
            </td>
            <td><?php echo formatTime($child->deadline, DT_DATE1);?></td>
            <td><?php if(isset($users[$child->assignedTo])) echo $users[$child->assignedTo];?></td>
            <td class="<?php echo $task->status;?>"><?php echo zget($lang->task->statusList, $task->status);?></td>
            <td><?php echo formatTime($child->createdDate, DT_DATE1);?></td>
            <td> <?php echo $child->consumed;?></td>
            <td><?php echo $child->left;?></td>
            <td class='text-left'><?php $this->task->buildOperateMenu($child, '', 'browse', true, $from);?></td>
          </tr>
          <?php $i ++;?>
          <?php endforeach;?>
          <?php endif;?>
          <?php endforeach;?>
        </tbody>
      </table>
      <div class='table-footer'>
        <?php if($canBatchClose):?>
        <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
        <div class='table-actions btn-toolbar'><?php echo html::submitButton($lang->close, 'btn');?></div>
        <div class='table-statistic'></div>
        <?php endif;?>
        <?php $pager->show();?>
      </div>
    <?php if($canBatchClose):?>
    </form>
    <?php endif;?>
  </div>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
