00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: general.php 5442 2006-02-19 15:14:12Z yeupou $
00006 #
00007 # Copyright 2001-2002 (c) Laurent Julliard, CodeX Team, Xerox
00008 #
00009 # Copyright 2003-2006 (c) Mathieu Roy <yeupou--gnu.org>
00010 #
00011 # The Savane project is free software; you can redistribute it and/or
00012 # modify it under the terms of the GNU General Public License
00013 # as published by the Free Software Foundation; either version 2
00014 # of the License, or (at your option) any later version.
00015 #
00016 # The Savane project is distributed in the hope that it will be useful,
00017 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 # GNU General Public License for more details.
00020 #
00021 # You should have received a copy of the GNU General Public License
00022 # along with the Savane project; if not, write to the Free Software
00023 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024
00025
00026 function my_hide_url ($svc, $db_item_id, $item_id, $count, $hide, $link="")
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 global $PHP_SELF;
00049
00050 $pref_name = 'my_hide_'.$svc.$db_item_id;
00051 $old_pref_value = user_get_preference($pref_name);
00052 list($old_hide,$old_count) = explode('|', $old_pref_value);
00053
00054 # Make sure they are both 0 if never set before
00055 if ($old_count == false) { $old_count = 0; }
00056 if ($old_hide == false) { $old_hide = 0; }
00057
00058 if ($item_id == $db_item_id)
00059 {
00060 if (isset($hide))
00061 {
00062 $pref_value = "$hide|$count";
00063 }
00064 else
00065 {
00066 $pref_value = "$old_hide|$count";
00067 $hide = $old_hide;
00068 }
00069 }
00070 else
00071 {
00072 if ($old_hide)
00073 {
00074 # if items are hidden keep the old count and keep pref as is
00075 $pref_value = $old_pref_value;
00076 }
00077 else
00078 {
00079 # only update the item count if the items are visible
00080 # if they are hidden keep reporting the old count
00081 $pref_value = "$old_hide|$count";
00082 }
00083 $hide = $old_hide;
00084 }
00085
00086 # Update pref value if needed
00087 if ($old_pref_value != $pref_value)
00088 {
00089 user_set_preference($pref_name, $pref_value);
00090 }
00091
00092 if ($hide)
00093 {
00094 $hide_url= '<a name="'.$svc.$db_item_id.'" href="'.$PHP_SELF.'?hide_'.$svc.'=0&hide_group_id='.$db_item_id.'#'.$svc.$db_item_id.'"><span class="minusorplus">(+)</span>'.$link.'</a>';
00095 $hide_now = true;
00096 }
00097 else
00098 {
00099 $hide_url= '<a name="'.$svc.$db_item_id.'" href="'.$PHP_SELF.'?hide_'.$svc.'=1&hide_group_id='.$db_item_id.'#'.$svc.$db_item_id.'"><span class="minusorplus">(-)</span>'.$link.'</a>';
00100 $hide_now = false;
00101 }
00102
00103 return array($hide_now, $count-$old_count, $hide_url);
00104 }
00105
00106 function my_format_as_flag($assigned_to, $submitted_by)
00107 {
00108 $AS_flag = '';
00109 if ($assigned_to == user_getid())
00110 {
00111 $AS_flag = 'A';
00112 }
00113 if ($submitted_by == user_getid())
00114 {
00115 $AS_flag .= 'S';
00116 }
00117 if ($AS_flag) { $AS_flag = '[<strong>'.$AS_flag.'</strong>]'; }
00118
00119 return $AS_flag;
00120 }
00121
00122 function my_item_count($total, $new)
00123 {
00124 $ret = '(';
00125 $ret .= sprintf(ngettext("%s item", "%s items", $total), $total);
00126 if ($new)
00127 {
00128 $ret .= ", <strong>".sprintf(ngettext("%s new", "%s new", $new), $new)."</strong>";
00129 }
00130 $ret .= ')';
00131 return $ret;
00132 }
00133
00134
00135 function my_item_list ($role="assignee", $threshold="5", $status="open", $uid=0, $condensed=0) {
00136 # status: 1 = open, 3 = closed
00137 if ($status == "open") { $status = 1; }
00138 if ($status == "closed") { $status = 3; }
00139
00140 # threshold: based on priority
00141
00142 # by defaut, consider we are printing items of the current users
00143 # if not, we want to ignore private items
00144 $showprivate = '';
00145 if (!$uid)
00146 { $uid = user_getid(); }
00147 else
00148 {
00149 $showprivate = ' AND privacy<>2 ';
00150 }
00151
00152 $items_per_groups = array();
00153 $groups = array();
00154
00155 $item_date = array();
00156 $item_priority = array();
00157 $item_resolution_id = array();
00158 $item_summary = array();
00159
00160 $trackers = array("support", "bugs", "task", "cookbook", "patch");
00161 $results = 0;
00162
00163
00164 # Get a timestamp to get new items (15 days)
00165 $new_date_limit = mktime(date("H"),
00166 date("i"),
00167 0,
00168 date("m"),
00169 date("d")-15,
00170 date("Y"));
00171
00172
00173 while (list(, $tracker) = each($trackers))
00174 {
00175 $sql = 'SELECT '.$tracker.'.bug_id,'.$tracker.'.date,'.$tracker.'.priority,'.$tracker.'.resolution_id,'.$tracker.'.summary,groups.group_id,groups.group_name,groups.unix_group_name FROM '.$tracker.',groups '.
00176 'WHERE groups.group_id='.$tracker.'.group_id '.
00177 'AND '.$tracker.'.status_id='.$status.' '.
00178 'AND ('.$tracker.'.priority >= '.$threshold.' OR '.$tracker.'.date > '.$new_date_limit.') '.$showprivate;
00179 if ($role == "assignee")
00180 { $sql .= 'AND '.$tracker.'.assigned_to='.$uid.' '; }
00181 else
00182 {
00183 # If the submitter is also the owner, we ll show it in the assigned
00184 # list, which matters more than the fact he is submitter
00185 $sql .= 'AND '.$tracker.'.assigned_to<>'.$uid.' AND '.$tracker.'.submitted_by='.$uid.' ';
00186 }
00187 $sql .= 'ORDER BY '.$tracker.'.date DESC ';
00188
00189 $result=db_query($sql);
00190 $rows=db_numrows($result);
00191 if ($result && $rows > 0)
00192 {
00193 $results = 1;
00194 for ($j=0; $j<$rows; $j++)
00195 {
00196 # Create item unique name
00197 $thisitem = $tracker.'#'.db_result($result,$j,'bug_id');
00198
00199 # Store data
00200 $item_date[$thisitem] = db_result($result,$j,'date');
00201 $item_priority[$thisitem] = db_result($result,$j,'priority');
00202 $item_status[$thisitem] = db_result($result,$j,'resolution_id');
00203 $item_summary[$thisitem] = db_result($result,$j,'summary');
00204
00205 # Associate with the relevant group
00206 $thisgroup = db_result($result,$j,'unix_group_name');
00207 if (array_key_exists($thisgroup, $items_per_groups))
00208 { $items_per_groups[$thisgroup] = $items_per_groups[$thisgroup].','.$thisitem; }
00209 else
00210 { $items_per_groups[$thisgroup] = $thisitem; }
00211 if (!array_key_exists($thisgroup, $groups))
00212 { $groups[$thisgroup] = db_result($result,$j,'group_name'); }
00213
00214 }
00215 }
00216 }
00217
00218 # Break here if we have no results
00219 if (!$results)
00220 {
00221 print _("None found");
00222 return false;
00223 }
00224
00225 # Go thru the group list and list items
00226 asort($groups);
00227 while (list($thisgroup,$thisgroupfullname) = each($groups))
00228 {
00229 $thisgroupid = group_getid($thisgroup);
00230
00231 $theseitems = array();
00232 $theseitems = explode(",", $items_per_groups[$thisgroup]);
00233
00234 # Put the content in an array well sort later according to the
00235 # date
00236 $thisgroupcontent = array();
00237 while (list(,$thisitem) = each($theseitems))
00238 {
00239 list($tracker, $item_id) = explode("#", $thisitem);
00240 $prefix = utils_get_tracker_prefix($tracker);
00241 $icon = utils_get_tracker_icon($tracker);
00242
00243 $dstatus = db_result(db_query("SELECT value FROM ".$tracker."_field_value WHERE bug_field_id='108' AND (group_id='".$thisgroupid."' OR group_id='100') AND value_id='".$item_status[$thisitem]."' ORDER BY bug_fv_id DESC LIMIT 1"), 0, 'value');
00244
00245 $thisgroupcontent[$item_date[$thisitem].$thisitem] = '<div class="'.utils_get_priority_color($item_priority[$thisitem], $status).'">'.
00246 '<a href="'.$GLOBALS['sys_home'].$tracker.'/?'.$item_id.'" class="block">'.
00247 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/'.$icon.'.png" class="icon" alt="'.$tracker.'" /> '.
00248 stripslashes($item_summary[$thisitem]).
00249 ' <span class="xsmall">('.$prefix .' #'.$item_id.', '.$dstatus.')</span></a></div>';
00250
00251 }
00252 krsort($thisgroupcontent);
00253
00254 if (!$condensed)
00255 {
00256 $count = count($thisgroupcontent);
00257 list($hide_now,$count_diff,$hide_url) = my_hide_url($role,$thisgroupid,sane_get("hide_group_id"),$count,sane_get("hide_$role"), '<strong>'.$thisgroupfullname.'</strong>');
00258
00259 print '<div class="'.utils_altrow(1).'"> '.$hide_url.' <span class="smaller">'.my_item_count($count,max(0, $count_diff)).'</span></div>';
00260 }
00261 else
00262 {
00263 # In condensed mode, there is no hide url
00264 print '<div class="'.utils_altrow(1).'"> '.sprintf(_("%s: "), group_getname($thisgroupid)).'</div>';
00265
00266 }
00267
00268 if (!$hide_now)
00269 {
00270 while (list(,$line) = each($thisgroupcontent))
00271 {
00272 print $line;
00273 }
00274 }
00275
00276 # Add extra space to make the page easier to read
00277 if (!$condensed)
00278 { print '<br />'; }
00279 }
00280
00281
00282 }
00283
00284
00285 function my_incoming_unassigned_item_list ($groups) {
00286 $uid = user_getid();
00287
00288 $items_per_groups = array();
00289 $groups_with_items = array();
00290
00291 $item_date = array();
00292 $item_priority = array();
00293 $item_resolution_id = array();
00294 $item_summary = array();
00295
00296 $trackers = array("support", "bugs", "task", "cookbook", "patch");
00297 $results = 0;
00298
00299
00300 # Get a timestamp to get new items (15 days)
00301 $new_date_limit = mktime(date("H"),
00302 date("i"),
00303 0,
00304 date("m"),
00305 date("d")-15,
00306 date("Y"));
00307
00308
00309 while (list(, $tracker) = each($trackers))
00310 {
00311 $sql = 'SELECT '.$tracker.'.bug_id,'.$tracker.'.date,'.$tracker.'.priority,'.$tracker.'.resolution_id,'.$tracker.'.summary,groups.group_id,groups.group_name,groups.unix_group_name FROM '.$tracker.',groups '.
00312 'WHERE groups.group_id='.$tracker.'.group_id '.
00313 'AND '.$tracker.'.status_id=1 '.
00314 'AND '.$tracker.'.date > '.$new_date_limit.' '.
00315 'AND '.$tracker.'.assigned_to=100 AND (';
00316
00317 # Go thru the list of groups to find out if any is relevant
00318 $previous = 0;
00319 reset($groups);
00320 while (list($group, $groupname) = each ($groups))
00321 {
00322 # Interesting only if the user got manager rights
00323 $id = group_getid($group);
00324 if (member_check(0, $id, member_create_tracker_flag($tracker).'3'))
00325 {
00326 if ($previous) { $sql .= "OR "; }
00327 $sql .= "$tracker.group_id='".$id."' ";
00328 $previous = 1;
00329 }
00330 }
00331
00332 $sql .= ') ORDER BY '.$tracker.'.date DESC ';
00333
00334 # Go to the next tracker if the user have no manager right on any
00335 # projects of this tracker
00336 if (!$previous)
00337 { continue; }
00338
00339 $result=db_query($sql);
00340 $rows=db_numrows($result);
00341
00342 if ($result && $rows > 0)
00343 {
00344 $results = 1;
00345 for ($j=0; $j<$rows; $j++)
00346 {
00347 # Create item unique name
00348 $thisitem = $tracker.'#'.db_result($result,$j,'bug_id');
00349
00350 # Store data
00351 $item_date[$thisitem] = db_result($result,$j,'date');
00352 $item_priority[$thisitem] = db_result($result,$j,'priority');
00353 $item_status[$thisitem] = db_result($result,$j,'resolution_id');
00354 $item_summary[$thisitem] = db_result($result,$j,'summary');
00355
00356 # Associate with the relevant group
00357 $thisgroup = db_result($result,$j,'unix_group_name');
00358 if (array_key_exists($thisgroup, $items_per_groups))
00359 { $items_per_groups[$thisgroup] = $items_per_groups[$thisgroup].','.$thisitem; }
00360 else
00361 { $items_per_groups[$thisgroup] = $thisitem; }
00362 if (!array_key_exists($thisgroup, $groups_with_items))
00363 { $groups_with_items[$thisgroup] = db_result($result,$j,'group_name'); }
00364
00365 }
00366 }
00367 }
00368
00369 # Break here if we have no results
00370 if (!$results)
00371 { return false; }
00372
00373 # Print the title (here in the function because we do not want to show
00374 # this table to people that are not even project member).
00375 print '<br /><div class="box"><div class="boxtitle">'._("New and Unassigned Items").'</div>';
00376
00377 # Go thru the group list and list items
00378 asort($groups_with_items);
00379 while (list($thisgroup,$thisgroupfullname) = each($groups_with_items))
00380 {
00381 $thisgroupid = group_getid($thisgroup);
00382
00383 $theseitems = array();
00384 $theseitems = explode(",", $items_per_groups[$thisgroup]);
00385
00386 # Put the content in an array we ll sort later according to the
00387 # date
00388 $thisgroupcontent = array();
00389 while (list(,$thisitem) = each($theseitems))
00390 {
00391 list($tracker, $item_id) = explode("#", $thisitem);
00392 $prefix = utils_get_tracker_prefix($tracker);
00393 $icon = utils_get_tracker_icon($tracker);
00394
00395 $dstatus = db_result(db_query("SELECT value FROM ".$tracker."_field_value WHERE bug_field_id='108' AND (group_id='".$thisgroupid."' OR group_id='100') AND value_id='".$item_status[$thisitem]."' ORDER BY bug_fv_id DESC LIMIT 1"), 0, 'value');
00396
00397 $thisgroupcontent[$item_date[$thisitem].$thisitem] = '<div class="'.utils_get_priority_color($item_priority[$thisitem], $status).'">'.
00398 '<a href="'.$GLOBALS['sys_home'].$tracker.'/?'.$item_id.'" class="block">'.
00399 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/'.$icon.'.png" class="icon" alt="'.$tracker.'" /> '.
00400 stripslashes($item_summary[$thisitem]).
00401 ' <span class="xsmall">('.$prefix .' #'.$item_id.', '.$dstatus.')</span></a></div>';
00402
00403 }
00404 krsort($thisgroupcontent);
00405 $count = count($thisgroupcontent);
00406
00407 list($hide_now,$count_diff,$hide_url) = my_hide_url("unassigned",$thisgroupid,sane_get("hide_group_id"),$count,sane_get("hide_unassigned"), '<strong>'.$thisgroupfullname.'</strong>');
00408
00409 print '<div class="'.utils_altrow(1).'">'.$hide_url.' <span class="smaller">'.my_item_count($count,max(0, $count_diff)).'</span></div>';
00410
00411 if (!$hide_now)
00412 {
00413 while (list(,$line) = each($thisgroupcontent))
00414 {
00415 print $line;
00416 }
00417 }
00418 print '<br />';
00419
00420 }
00421 print '</div>';
00422
00423 }
00424
00425
00426 function my_incoming_assigned_item_list ($groups) {
00427 $uid = user_getid();
00428
00429 $items_per_groups = array();
00430 $groups_with_items = array();
00431
00432 $item_date = array();
00433 $item_priority = array();
00434 $item_resolution_id = array();
00435 $item_summary = array();
00436
00437 $trackers = array("support", "bugs", "task", "patch", "cookbook");
00438 $results = 0;
00439
00440
00441 # Get a timestamp to get new items (15 days)
00442 $new_date_limit = mktime(date("H"),
00443 date("i"),
00444 0,
00445 date("m"),
00446 date("d")-15,
00447 date("Y"));
00448
00449
00450 while (list(, $tracker) = each($trackers))
00451 {
00452 # We need two different SQL commands to find newly assigned item
00453 # that are in fact completely new items, with no history, and assigned
00454 # item that may be very very old but that were assigned recently to the
00455 # user
00456
00457 # We'll ignore item self-assigned.
00458 $cases = array("assignedonsubmission", "assignedafterwards");
00459 while (list(, $case) = each($cases))
00460 {
00461 if ($case == "assignedafterwards")
00462 {
00463 $sql = 'SELECT '.$tracker.'.bug_id,'.$tracker.'_history.date,'.$tracker.'.priority,'.$tracker.'.resolution_id,'.$tracker.'.summary,groups.group_id,groups.group_name,groups.unix_group_name FROM '.$tracker.','.$tracker.'_history,groups '.
00464 'WHERE groups.group_id='.$tracker.'.group_id '.
00465 'AND '.$tracker.'_history.bug_id='.$tracker.'.bug_id '.
00466 'AND '.$tracker.'_history.new_value='.$uid.' '.
00467 'AND '.$tracker.'_history.old_value<>'.$uid.' '.
00468 'AND '.$tracker.'_history.mod_by<>'.$uid.' '.
00469 'AND '.$tracker.'_history.field_name="assigned_to" '.
00470 'AND '.$tracker.'.status_id=1 '.
00471 'AND '.$tracker.'_history.date > '.$new_date_limit.' '.
00472 'AND '.$tracker.'.assigned_to='.$uid.' AND (';
00473
00474 # Go thru the list of groups to find out if any is relevant
00475 $previous = 0;
00476 reset($groups);
00477 while (list($group, $groupname) = each ($groups))
00478 {
00479 $id = group_getid($group);
00480 # Interesting only if the user got technician rights
00481 if (member_check(0, $id, member_create_tracker_flag($tracker).'1'))
00482 {
00483 if ($previous) { $sql .= "OR "; }
00484 $sql .= "$tracker.group_id='".$id."' ";
00485 $previous = 1;
00486 }
00487 }
00488
00489 $sql .= ') ORDER BY '.$tracker.'_history.date DESC ';
00490 }
00491 else
00492 {
00493 $sql = 'SELECT '.$tracker.'.bug_id,'.$tracker.'.date,'.$tracker.'.priority,'.$tracker.'.resolution_id,'.$tracker.'.summary,groups.group_id,groups.group_name,groups.unix_group_name FROM '.$tracker.',groups '.
00494 'WHERE groups.group_id='.$tracker.'.group_id '.
00495 'AND '.$tracker.'.status_id='.$status.' '.
00496 'AND '.$tracker.'.date > '.$new_date_limit.' '.
00497 'AND '.$tracker.'.submitted_by<>'.$uid.' '.
00498 'AND '.$tracker.'.assigned_to='.$uid.' AND (';
00499
00500 # Go thru the list of groups to find out if any is relevant
00501 $previous = 0;
00502 reset($groups);
00503 while (list($group, $groupname) = each ($groups))
00504 {
00505 $id = group_getid($group);
00506 # Interesting only if the user got technician rights
00507 if (member_check(0, $id, member_create_tracker_flag($tracker).'1'))
00508 {
00509 if ($previous) { $sql .= "OR "; }
00510 $sql .= "$tracker.group_id='".$id."' ";
00511 $previous = 1;
00512 }
00513 }
00514
00515 ') ORDER BY '.$tracker.'.date DESC ';
00516
00517 }
00518
00519 # Go to the next tracker if the user have no manager right on any
00520 # projects of this tracker
00521 if (!$previous)
00522 { continue; }
00523
00524 $result=db_query($sql);
00525 $rows=db_numrows($result);
00526
00527 if ($result && $rows > 0)
00528 {
00529 $results = 1;
00530 for ($j=0; $j<$rows; $j++)
00531 {
00532 # Create item unique name
00533 $thisitem = $tracker.'#'.db_result($result,$j,'bug_id');
00534
00535 # Items can be found in both cases (assigned on submission
00536 # and assigned afterwards)
00537 if (array_key_exists($thisitem, $item_date))
00538 { continue; }
00539
00540 # Store data
00541 $item_date[$thisitem] = db_result($result,$j,'date');
00542 $item_priority[$thisitem] = db_result($result,$j,'priority');
00543 $item_status[$thisitem] = db_result($result,$j,'resolution_id');
00544 $item_summary[$thisitem] = db_result($result,$j,'summary');
00545
00546 # Associate with the relevant group
00547 $thisgroup = db_result($result,$j,'unix_group_name');
00548 if (array_key_exists($thisgroup, $items_per_groups))
00549 { $items_per_groups[$thisgroup] = $items_per_groups[$thisgroup].','.$thisitem; }
00550 else
00551 { $items_per_groups[$thisgroup] = $thisitem; }
00552 if (!array_key_exists($thisgroup, $groups_with_items))
00553 { $groups_with_items[$thisgroup] = db_result($result,$j,'group_name'); }
00554
00555 }
00556 }
00557 }
00558 }
00559
00560 # Break here if we have no results
00561 if (!$results)
00562 {
00563 print _("None found");
00564 return false;
00565 }
00566
00567 # Go thru the group list and list items
00568 asort($groups_with_items);
00569 while (list($thisgroup,$thisgroupfullname) = each($groups_with_items))
00570 {
00571 $thisgroupid = group_getid($thisgroup);
00572
00573 $theseitems = array();
00574 $theseitems = explode(",", $items_per_groups[$thisgroup]);
00575
00576 # Put the content in an array we'll sort later according to the
00577 # date
00578 $thisgroupcontent = array();
00579 while (list(,$thisitem) = each($theseitems))
00580 {
00581 list($tracker, $item_id) = explode("#", $thisitem);
00582 $prefix = utils_get_tracker_prefix($tracker);
00583 $icon = utils_get_tracker_icon($tracker);
00584
00585 $dstatus = db_result(db_query("SELECT value FROM ".$tracker."_field_value WHERE bug_field_id='108' AND (group_id='".$thisgroupid."' OR group_id='100') AND value_id='".$item_status[$thisitem]."' ORDER BY bug_fv_id DESC LIMIT 1"), 0, 'value');
00586
00587 $thisgroupcontent[$item_date[$thisitem].$thisitem] = '<div class="'.utils_get_priority_color($item_priority[$thisitem], $status).'">'.
00588 '<a href="'.$GLOBALS['sys_home'].$tracker.'/?'.$item_id.'" class="block">'.
00589 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/'.$icon.'.png" class="icon" alt="'.$tracker.'" /> '.
00590 stripslashes($item_summary[$thisitem]).
00591 ' <span class="xsmall">('.$prefix .' #'.$item_id.', '.$dstatus.')</span></a></div>';
00592
00593 }
00594 krsort($thisgroupcontent);
00595 $count = count($thisgroupcontent);
00596
00597 list($hide_now,$count_diff,$hide_url) = my_hide_url("newlyassigned",$thisgroupid,sane_get("hide_group_id"),$count,sane_get("hide_newlyassigned"), '<strong>'.$thisgroupfullname.'</strong>');
00598
00599 print '<div class="'.utils_altrow(1).'">'.$hide_url.' <span class="smaller">'.my_item_count($count,max(0, $count_diff)).'</span></div>';
00600
00601 if (!$hide_now)
00602 {
00603 while (list(,$line) = each($thisgroupcontent))
00604 {
00605 print $line;
00606 }
00607 }
00608 print '<br />';
00609
00610 }
00611
00612
00613 }
00614
00615
00616 ?>