<?php
/**
 * The edit 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      Tingting Dai <daitingting@xirangit.com>
 * @package     task
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php if(helper::isAjaxRequest()):?>
<?php include '../../../sys/common/view/header.modal.html.php';?>
<?php else:?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php endif;?>
<?php include '../../common/view/editor.html.php';?>
<?php $readonly = empty($task->children) ? '' : "readonly='readonly'";?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a('javascript:history.go(-1);', '<i class="icon icon-back icon-sm"></i> ' . $lang->goback, "class='btn btn-back'");?>
    <div class="divider"></div>
    <?php endif;?>
    <div class="page-title">
      <span class="text" title='<?php echo $task->name;?>'><?php echo $lang->task->edit . $lang->minus . $task->name;?></span>
    </div>
  </div>
</div>
<form method='post' id='ajaxForm' enctype='multipart/form-data' action="<?php echo $this->createLink('task', 'edit', "taskID=$task->id&from=$from")?>">
  <div class='main-row'>
    <div class='main-col col-8'>
      <div class='panel'>
        <div class='panel-body'>
          <table class='table table-form table-data'>
            <tr>
              <th class='w-80px'><?php echo $lang->task->name?></th>
              <td>
                <?php if(empty($task->children) and empty($task->parent)){}?>
                <?php echo html::input("name", $task->name, "class='form-control'");?>
              </td>
            </tr>
            <tr>
              <th><?php echo $lang->task->assignedTo;?></th>
              <td>
                <div class='input-group'>
                  <?php echo html::select('assignedTo', !empty($members) ? $members : $projectMembers, $task->assignedTo, "class='form-control'");?>
                  <?php echo html::input('teamMember', '', "class='form-control team-group hidden' readonly");?>
                  <span class='input-group-addon'>
                    <label class='checkbox-inline'>
                      <input type='checkBox' name='multiple' value='1' <?php echo empty($task->team) ? '' : 'checked'?> />
                      <?php echo $lang->task->multipleAB;?>
                    </label>
                  </span>
                </div>
              </td>
            </tr>
            <tr class='team hidden'>
              <th class='w-80px'><?php echo $lang->task->team;?></th>
              <td>
                <table class='table table-detail table-condensed table-borderless'>
                  <?php foreach($task->team as $member):?>
                  <tr>
                    <td class='w-120px'><?php echo html::select("team[]", $projectMembers, $member->account, "class='form-control chosen'")?></td>
                    <td class='w-80px'><?php echo html::input("role[]", $member->role, "class='form-control' placeholder='{$lang->project->role}'")?></td>
                    <td class=''>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->task->estimate?></span>
                        <?php echo html::input("teamEstimate[]", $member->estimate, "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                        <span class='input-group-addon '><?php echo $lang->task->consumed?></span>
                        <?php echo html::input("teamConsumed[]", $member->consumed, "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                        <span class='input-group-addon '><?php echo $lang->task->left?></span>
                        <?php echo html::input("teamLeft[]", $member->left, "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                      </div>
                    </td>
                  </tr>
                  <?php endforeach;?>
                  <?php for($i = 0; $i < 3; $i++):?>
                  <tr>
                    <td class='w-120px'><?php echo html::select("team[]", $projectMembers, '', "class='form-control chosen'")?></td>
                    <td class='w-80px'><?php echo html::input("role[]", '', "class='form-control' placeholder='{$lang->project->role}'")?></td>
                    <td class=''>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->task->estimate?></span>
                        <?php echo html::input("teamEstimate[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                        <span class='input-group-addon '><?php echo $lang->task->consumed?></span>
                        <?php echo html::input("teamConsumed[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                        <span class='input-group-addon '><?php echo $lang->task->left?></span>
                        <?php echo html::input("teamLeft[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                      </div>
                    </td>
                  </tr>
                  <?php endfor;?>
                </table>
              </td>
            </tr>
            <tr>
              <th><?php echo $lang->task->desc?></th>
              <td><?php echo html::textarea('desc', $task->desc, "class='form-control'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->comment;?></th>
              <td><?php echo html::textarea('remark', '', "class='form-control'");?></td>
            </tr>
            <?php if(commonModel::hasPriv('file', 'upload')):?>
            <tr>
              <th><?php echo $lang->files;?></th>
              <td><?php echo $this->fetch('file', 'buildForm')?></td>
            </tr>
            <?php endif;?>
          </table>
        </div>
      </div>
      <?php echo $this->fetch('action', 'history', "objectType=task&objectID={$task->id}");?>
      <?php echo html::hidden('referer', $this->server->http_referer);?>
      <div class='main-actions'>
        <?php
        if($readonly) echo html::hidden('status', $task->status);
        $browseLink = $this->session->taskList ? $this->session->taskList : inlink('browse', "project=$task->project");
        echo html::submitButton() . ' ' . html::a($browseLink, $lang->goback, "class='btn btn-back'");
        ?>
      </div>
    </div>
    <div class='side-col col-4'>
      <div class='panel'>
        <div class='panel-heading'><strong><?php echo $lang->task->basicInfo;?></strong></div>
        <div class='panel-body'>
          <table class='table table-data'>
            <?php if($project->taskStatus):?>
            <tr>
              <th class='w-80px'><?php echo $lang->task->project;?></th>
              <td><?php echo html::select('project', $projects, $task->project, "class='form-control chosen'");?></td>
            </tr>
            <?php endif;?>
            <tr>
              <th><?php echo $lang->task->parent;?></th>
              <td><?php echo html::select('parent', $tasks, $task->parent, "class='form-control chosen'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->status;?></th>
              <td>
                <?php $disabled = $readonly ? "disabled='disabled'" : '';?>
                <?php echo html::select('status', $lang->task->statusList, $task->status, "class='form-control' $disabled");?>
              </td>
            </tr>
            <tr>
              <th><?php echo $lang->task->pri;?></th>
              <td><?php echo html::select('pri', $lang->task->priList, $task->pri, "class='form-control'")?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->deadline;?></th>
              <td><?php echo html::input('deadline', formatTime($task->deadline), "class='form-control form-date'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->estimate;?></th>
              <td><?php echo html::input('estimate', $task->estimate, "class='form-control'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->consumed;?></th>
              <td><?php echo html::input('consumed', $task->consumed, "class='form-control' $readonly");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->left;?></th>
              <td><?php echo html::input('left', $task->left, "class='form-control' $readonly");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->mailto;?></th>
              <td><?php echo html::select('mailto[]', $users, $task->mailto, "class='form-control chosen' multiple data-placeholder='{$lang->task->mailtoPlaceholder}'");?></td>
            </tr>
          </table>
        </div>
      </div>
      <div class='panel'>
        <div class='panel-heading'><strong><?php echo $lang->task->life?></strong></div>
        <div class='panel-body'>
          <table class='table table-data'>
            <tr>
              <th class='w-80px'><?php echo $lang->task->createdBy;?></th>
              <td><?php echo zget($users, $task->createdBy, $task->createdBy)?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->finishedBy;?></th>
              <td><?php echo html::select('finishedBy', $users, $task->finishedBy, "class='form-control chosen'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->finishedDate;?></th>
              <td><?php echo html::input('finishedDate', formatTime($task->finishedDate), "class='form-control form-date'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->canceledBy;?></th>
              <td><?php echo html::select('canceledBy', $users, $task->canceledBy, "class='form-control chosen'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->canceledDate;?></th>
              <td><?php echo html::input('canceledDate', formatTime($task->canceledDate), "class='form-control form-date'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->closedBy;?></th>
              <td><?php echo html::select('closedBy', $users, $task->closedBy, "class='form-control chosen'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->closedDate;?></th>
              <td><?php echo html::input('closedDate', formatTime($task->closedDate), "class='form-control form-date'");?></td>
            </tr>
            <tr>
              <th><?php echo $lang->task->closedReason;?></th>
              <td><?php echo html::select('closedReason', $lang->task->reasonList, $task->closedReason, "class='form-control'");?></td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade modal-team" id="modalTeam">
    <div class="modal-dialog" style='width: 850px'>
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
        <h4 class="modal-title"><?php echo $lang->task->team?></h4>
      </div>
      <div class='modal-body'>
        <table class='table table-condensed table-borderless'>
          <thead>
            <tr class='text-center'>
              <th><?php echo $lang->task->team;?></th>
              <th class='w-120px'><?php echo $lang->project->role;?></th>
              <th class='w-400px'><?php echo $lang->task->recordEstimate;?></th>
              <th class='w-90px'></th>
            </tr>
          </thead>
          
          <?php for($i = 0; $i < 3; $i++):?>
          <tr>
            <td><?php echo html::select("team[]", $projectMembers, '', "class='form-control chosen'")?></td>
            <td><?php echo html::input("role[]", '', "class='form-control'")?></td>
            <td>
              <div class='input-group'>
                <span class='input-group-addon'><?php echo $lang->task->estimate?></span>
                <?php echo html::input("teamEstimate[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                <span class='input-group-addon '><?php echo $lang->task->consumed?></span>
                <?php echo html::input("teamConsumed[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
                <span class='input-group-addon '><?php echo $lang->task->left?></span>
                <?php echo html::input("teamLeft[]", '', "class='form-control text-center' placeholder='{$lang->task->hour}'")?>
              </div>
            </td>
            <td>
              <a href='javascript:;' class='btn btn-move-up btn-sm'><i class='icon-arrow-up'></i></a>
              <a href='javascript:;' class='btn btn-move-down btn-sm'><i class='icon-arrow-down'></i></a>
            </td>
          </tr>
          <?php endfor;?>
          <tr>
            <td colspan='4' class='text-center'><?php echo html::a('javascript:void(0)', $lang->confirm, "class='btn btn-primary' data-dismiss='modal'")?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</form>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
