<?php
/**
 * The control file of project module of ZenTaoPMS.
 *
 * @copyright   Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com)
 * @license     business(商业软件) 
 * @author      Yangyang Shi <shiyangyang@cnezsoft.com>
 * @package     project 
 * @version     $Id$
 * @link        http://www.zentao.net
 */
?>
<?php include '../../../common/view/header.html.php';?>
<?php include '../../view/taskheader.html.php';?>
<?php include "featurebar.html.php";?>
<style>
  .table > caption {border: 1px solid #ddd; border-bottom: none;}
</style>
<form method='post' class='form-condensed' target='hiddenwin'>
  <table class='table table-fixed mgb-20 active-disabled'>
    <thead>
    <tr class='colhead'>
      <th class='w-id'><?php echo $lang->project->gantt->id;?></th>
      <th><?php echo $lang->project->gantt->pretask;?></th>
      <th class='w-100px'><?php echo $lang->project->gantt->condition;?></th>
      <th><?php echo $lang->project->gantt->task;?></th>
      <th class='w-110px'><?php echo $lang->project->gantt->action;?></th>
    </tr>
    </thead>
    <tbody>
    <?php foreach($relations as $id => $relation):?>
    <?php
    $tasksClone = $tasks;
    unset($tasksClone[$relation->pretask]);
    ?>
    <tr>
      <td><?php echo $id . html::hidden("id[$id]", "$id");?></td>
      <td style='overflow:visible'><?php echo html::select("pretask[$id]", $tasks, $relation->pretask, "class='form-control chosen' onchange='deleteself(this, $id, \"\")'");?></td> 
      <td><?php echo html::select("condition[$id]", $lang->project->gantt->preTaskStatus, $relation->condition, 'class=form-control');?> </td>
      <td style='overflow:visible'><?php echo html::select("task[$id]", $tasksClone, $relation->task, "class='form-control chosen'");?> </td>
      <td><?php echo html::select("action[$id]", $lang->project->gantt->taskActions, $relation->action, 'class=form-control');?> </td>
    </tr>
    <?php endforeach;?>
    </tbody>
  </table>
  <table class='table table-fixed active-disabled'>
    <caption class='text-left'><strong><?php echo $lang->project->gantt->newCreateRelationOfTasks;?></strong></caption>
    <thead>
    <tr class='colhead'>
      <th class='w-id'><?php echo $lang->project->gantt->id;?></th>
      <th><?php echo $lang->project->gantt->pretask;?></th>
      <th class='w-100px'><?php echo $lang->project->gantt->condition;?></th>
      <th><?php echo $lang->project->gantt->task;?></th>
      <th class='w-110px'><?php echo $lang->project->gantt->action;?></th>
    </tr>
    </thead>
    <tbody>
    <?php for($i = 1 ; $i <= 5 ; $i++):?>
    <tr>
      <td class='text-center'><?php echo $i . html::hidden("newid[$i]", $i);?></td>
      <td style='overflow:visible'><?php echo html::select("newpretask[$i]", $tasks, '', "class='form-control chosen' onchange='deleteself(this, $i, \"new\")'");?> </td>
      <td><?php echo html::select("newcondition[$i]", $lang->project->gantt->preTaskStatus, '', 'class=form-control');?> </td>
      <td style='overflow:visible'><?php echo html::select("newtask[$i]", $tasks, '', "class='form-control chosen'");?> </td>
      <td><?php echo html::select("newaction[$i]", $lang->project->gantt->taskActions, '', 'class=form-control');?> </td>
    </tr>
    <?php endfor;?>
    </tbody>
    <tfoot>
    <tr>
      <td colspan='5' class='text-center'>
        <?php echo html::submitButton() . html::backButton();?>
      </td>
    </tr>
    </tfoot>
  </table>
</form>
<script language='Javascript'>
$('#ganttTab').addClass('active');
$('#maintainRelation').addClass('active');
function deleteself(obj, i, isnew)
{
    var value = $(obj).val();
    var options = '';
    $(obj).find('option').each(function(){
        var optionValue = $(this).attr('value');
        if(optionValue != value || optionValue == '') options = options + "<option value='" + optionValue + "'>" + $(this).html() + "</option>";
    });
    $('select').each(function()
    {
        if($(this).attr('name') == isnew + "task[" + i + "]")
        {
            $(this).html(options);
            $(this).trigger("chosen:updated");
        }
    });
}
</script>
<?php include '../../../common/view/footer.html.php';?>
