//1st pass) parent tasks and its children foreach ($p['tasks'] as $i => $t1) { if ($t1['task_parent'] == $t1['task_id'] && !$task_id) { //Here we are NOT on a task view context, like the tasks module list or the project view tasks list. //check for child $no_children = empty($children_of[$t1['task_id']]); showtask($t1, 0, true, false, $no_children); $shown_tasks[$t1['task_id']] = $t1['task_id']; findchild($p['tasks'], $t1['task_id']); } elseif ($t1['task_parent'] == $task_id && $task_id) { //Here we are on a task view context //check for child $no_children = empty($children_of[$t1['task_id']]); showtask($t1, 0, true, false, $no_children); $shown_tasks[$t1['task_id']] = $t1['task_id']; findchild($p['tasks'], $t1['task_id']); } } reset($p); //2nd pass parentless tasks foreach ($p['tasks'] as $i => $t1) { if (!isset($shown_tasks[$t1['task_id']])) { //Here we are on a parentless task context, this can happen because we are: //1) displaying filtered tasks that could be showing only child tasks and not its parents due to filtering. //2) in a situation where child tasks are active and parent tasks are inactive or vice-versa. // //The IF condition makes sure: //1) The parent task has been displayed and passed through the findchild first, so child tasks are not erroneously displayed as orphan (parentless) //2) Only not displayed yet tasks are shown so we don't show duplicates due to findchild that may cause duplicate showtasks for level 1 (and higher) tasks. showtask($t1, -1, true, false, true); $shown_tasks[] = $t1['task_id'];
function findchild(&$tarr, $parent, $level = 0) { global $tasks_opened, $tasks_closed, $tasks_filtered, $children_of; $tasks_closed = $tasks_closed ? $tasks_closed : array(); $tasks_opened = $tasks_opened ? $tasks_opened : array(); $level = $level + 1; foreach ($tarr as $x => $task) { if ($task['task_parent'] == $parent && $task['task_parent'] != $task['task_id']) { $is_opened = !in_array($task['task_id'], $tasks_closed); //check for child $no_children = empty($children_of[$task['task_id']]); showtask($task, $level, $is_opened, false, $no_children); if ($is_opened && !$no_children) { /* * Yes, this is stupid, but there was previously a bug where if you had * two dynamic tasks at the same level and the child of a dynamic task, * they would only both display if the first one was closed. The moment * you opened the first one, the second would disappear. * * There is something screwy happening in this function in the pass by * reference. I suspect it's a PHP4 vs PHP5 oddity. */ $tmp = $tarr; findchild($tmp, $task['task_id'], $level); } } } }
function findchild(&$tarr, $parent, $level = 0) { global $shown_tasks; $level = $level + 1; $n = count($tarr); for ($x = 0; $x < $n; $x++) { if ($tarr[$x]['task_parent'] == $parent && $tarr[$x]['task_parent'] != $tarr[$x]['task_id']) { showtask($tarr[$x], $level, true); $shown_tasks[$tarr[$x]['task_id']] = $tarr[$x]['task_id']; findchild($tarr, $tarr[$x]['task_id'], $level); } } }
* don't "mess with" display when showing certain views * (or similiar filters that don't involve "breaking apart" a task tree * even though they might not use this page ever) */ if (!$task_id && in_array($f, $never_show_with_dots)) { showtaskToOrganize($t1, 1, true, false, true); } else { //display as close to "tree-like" as possible $is_opened = !$t1['task_dynamic'] || !in_array($t1['task_id'], $tasks_closed); //check for child $no_children = empty($children_of[$t1['task_id']]); $my_level = $task_id && $t1['task_parent'] == $task_id ? 0 : -1; showtaskToOrganize($t1, $my_level, $is_opened, false, $no_children); // indeterminate depth for child task if ($is_opened && !$no_children) { findchild($p['tasks'], $t1['task_id'], 0, false, true); } } } } } echo '</div>'; if (isset($project_id)) { echo '</div>'; } ?> <form name="taskOrder" action="?m=tasks&a=do_task_order" method="post"> <input id="taskList" name="taskList" type="hidden" /> <input id="projectId" name="projectId" type="hidden" value="<?php echo $project_id; ?>
} else { $p['tasks'] = array_csort($p['tasks'], $task_sort_item1, $task_sort_order1, $task_sort_type1); } } //print_r($p['tasks']); for ($i = 0; $i < $tnums; $i++) { $t = $p['tasks'][$i]; /* 20041118 gregorerhardt bug #311: ** added the following task status condition to the if clause in order to make sure inactive children ** are shown in the 'inactive view'; their parents are for instance not listed with them. */ if ($t["task_parent"] == $t["task_id"] || $p['tasks'][$i]["task_status"] != 0) { $is_opened = in_array($t["task_id"], $tasks_opened); showtask($t, 0, $is_opened, '', $_GET["impr"]); if ($is_opened || !$t["task_dynamic"]) { findchild($p['tasks'], $t["task_id"]); } } // else showtask( $t, 0, $is_opened ); } // check that any 'orphaned' user tasks are also display for ($i = 0; $i < $tnums; $i++) { if (!in_array($p['tasks'][$i]["task_id"], $done)) { if ($p['tasks'][$i]["task_dynamic"] && in_array($p['tasks'][$i]["task_parent"], $tasks_closed)) { closeOpenedTask($p['tasks'][$i]["task_id"]); } if (in_array($p['tasks'][$i]["task_parent"], $tasks_opened)) { showtask($p['tasks'][$i], 1, false, '', $_GET["impr"]); } } }
function findchild(&$tarr, $parent, $level = 0) { global $projects; global $tasks_opened; $level = $level + 1; $n = count($tarr); for ($x = 0; $x < $n; $x++) { if ($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"]) { $is_opened = in_array($tarr[$x]["task_id"], $tasks_opened); showtask($tarr[$x], $level, $is_opened); if ($is_opened || !$tarr[$x]["task_dynamic"]) { findchild($tarr, $tarr[$x]["task_id"], $level); } } } }