I have implemented user-specified column based task
ordering in the projects view.
It supports sort by primary column and secondary sort
by scondary column ( like Microsoft Project ).
You simply click on the heading, click again to reverse
the order. (like Microsoft Project )
Children tasks are kept with their parents.
There are three problems:
1. it doesn't work in the "Tasks" view yet (so I disabled
it there), it works in the Project's task listing view.
2. I use the priority graphics low.gif and 1.gif to display
the current ordering so this probably needs new graphics
at some point.
3. I had to hack the background colour for the table
headings so I could see hyperlinked text. The "A" CSS
colours need to be changed for table headers really.
(but I wanted to limit my changed files to one for this
patch so I left this for the time-being)
Ok, here's the patch:
----- File: modules/tasks/tasks.php
----- near similar code at top of file, ADD
$task_sort_item1 = dPgetParam(
$_GET, 'task_sort_item1', '' );
$task_sort_type1 = dPgetParam(
$_GET, 'task_sort_type1', '' );
$task_sort_item2 = dPgetParam(
$_GET, 'task_sort_item2', '' );
$task_sort_type2 = dPgetParam(
$_GET, 'task_sort_type2', '' );
$task_sort_order1 = intval( dPgetParam(
$_GET, 'task_sort_order1', 0 ) );
$task_sort_order2 = intval( dPgetParam(
$_GET, 'task_sort_order2', 0 ) );
----- AFTER this:
function findchild( &$tarr, $parent, $level=0 ){
GLOBAL $projects;
$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 );
findchild( $tarr, $tarr[$x]
["task_id"], $level);
}
}
}
----- ADD this:
/* please throw this in an include file somewhere, its
very useful */
function array_csort() { //coded by Ichier2003
$args = func_get_args();
$marray = array_shift($args);
$msortline = "return(array_multisort(";
foreach ($args as $arg) {
$i++;
if (is_string($arg)) {
foreach ($marray as $row) {
$sortarr[$i][] = $row[$arg];
}
} else {
$sortarr[$i] = $arg;
}
$msortline .= "\$sortarr[".$i."],";
}
$msortline .= "\$marray));";
eval($msortline);
return $marray;
}
function sort_by_item_title( $title, $item_name,
$item_type )
{
global $AppUI,$project_id,$min_view;
global
$task_sort_item1,$task_sort_type1,$task_sort_order1;
global
$task_sort_item2,$task_sort_type2,$task_sort_order2;
if \( $min\_view \) \{ if \( $task\_sort\_item2 ==
$item_name ) $item_order = $task_sort_order2;
if ( $task_sort_item1 ==
$item_name ) $item_order = $task_sort_order1;
if \( isset\( $item\_order \) \) \{ if \( $item\_order ==
SORT_ASC ) echo '<img src="./images/icons/low.gif"
width=13 height=16>';
else echo '<img
src="./images/icons/1.gif" width=13 height=16>';
}
else $item_order = SORT_DESC;
/\* flip the sort order for the link \*/ $item\_order = \( $item\_order ==
SORT_ASC ) ? SORT_DESC : SORT_ASC;
echo '&lt;a href=&quot;./index.php?
m=projects&a=view&project_id='.$project_id;
echo '&task_sort_item1='.$item_name;
echo '&task_sort_type1='.$item_type;
echo '&amp;task\_sort\_order1='.$item\_order; if \( $task\_sort\_item1 == $item\_name \) \{ echo '&amp;task\_sort\_item2='.$task\_sort\_item2; echo '&amp;task\_sort\_type2='.$task\_sort\_type2; echo '&amp;task\_sort\_order2='.$task\_sort\_order2; \} else \{ echo '&amp;task\_sort\_item2='.$task\_sort\_item1; echo '&amp;task\_sort\_type2='.$task\_sort\_type1; echo '&amp;task\_sort\_order2='.$task\_sort\_order1; \} echo '&quot;&gt;'; \} echo $AppUI-&gt;\_\($title\); if \( $min\_view \) \{ echo '&lt;/a&gt;'; \}
}
----- REPLACE this:
&lt;th width=&quot;10&quot; STYLE=&quot;background:
#4aa">&nbsp;</th>
<th width="20"><?php echo $AppUI->_
('Work');?></th>
<th width="15" align="center">&nbsp;</th>
<th width="200"><?php echo $AppUI->_('Task
Name');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_
('Task Creator');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_
('Start Date');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_
('Duration');?>&nbsp;&nbsp;</th>
<th nowrap="nowrap"><?php echo $AppUI->_
('Finish Date');?></th>
----- WITH this:
&lt;th width=&quot;10&quot; STYLE=&quot;background:
#4aa">&nbsp;</th>
<th width="20" STYLE="background: #4aa"><?
php echo $AppUI->_('Work');?></th>
<th width="15" align="center"
STYLE="background: #4aa">&nbsp;</th>
<th width="200" STYLE="background: #4aa"><?
php sort_by_item_title( 'Task Name', 'task_name',
SORT_STRING );?></th>
<th nowrap="nowrap" STYLE="background:
#4aa"><?php sort_by_item_title( 'Task
Creator', 'user_username', SORT_STRING );?></th>
<th nowrap="nowrap" STYLE="background:
#4aa"><?php sort_by_item_title( 'Start
Date', 'task_start_date', SORT_NUMERIC );?></th>
<th nowrap="nowrap" STYLE="background:
#4aa"><?php sort_by_item_title
( 'Duration', 'task_duration', SORT_NUMERIC );?
>&nbsp;&nbsp;</th>
<th nowrap="nowrap" STYLE="background:
#4aa"><?php sort_by_item_title( 'Finish
Date', 'task_end_date', SORT_NUMERIC );?></th>
----- BEFORE this:
for \($i=0; $i &lt; $tnums; $i++\) \{ $t = $p\['tasks'\]\[$i\]; if \($t\[&quot;task\_parent&quot;\] == $t
["task_id"]) {
showtask( $t );
findchild( $p
['tasks'], $t["task_id"] );
}
}
----- ADD this:
if \( $min\_view &amp;&amp; $task\_sort\_item1 \!
= "" )
{
if ( $task_sort_item2 != ""
&& $task_sort_item1 != $task_sort_item2 )
$p['tasks'] =
array_csort($p['tasks'], $task_sort_item1,
$task_sort_order1, $task_sort_type1
,
$task_sort_item2, $task_sort_order2,
$task_sort_type2 );
else $p['tasks'] =
array_csort($p['tasks'], $task_sort_item1,
$task_sort_order1, $task_sort_type1 );
}
----- FINISH
Logged In: YES
user_id=929981
Thank you, this works sooo nicely, it really saves a lot of time
on large projects with many tasks.
Can this be done on the ToDo page as well:
index.php?m=tasks&a=todo
What's the glitch the Tasks page?
with index.php?m=tasks