5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010 Roland Mas
9 require_once $gfcommon.'tracker/ArtifactFactory.class.php';
10 require_once $gfcommon.'tracker/ArtifactQuery.class.php';
12 // make sure this person has permission to view artifacts
14 if (!$ath->userCanView()) {
15 exit_permission_denied();
18 $query_id = getIntFromRequest('query_id');
19 $start = getIntFromRequest('start');
24 // The browse page can be powered by a pre-saved query
25 // or by select boxes chosen by the user
27 // If there is a $query_id coming from the request OR the pref
28 // was already saved, use the artifact factory that way.
30 // If the query_id = -1, unset the pref and use regular browse boxes
32 if (session_loggedin()) {
34 if ($query_id == '-1') {
35 $u =& session_get_user();
36 $u->setPreference('art_query'.$ath->getID(),'');
38 $aq = new ArtifactQuery($ath,$query_id);
39 if (!$aq || !is_object($aq)) {
40 exit_error('Error',$aq->getErrorMessage());
45 $u =& session_get_user();
46 $query_id=$u->getPreference('art_query'.$ath->getID(),'');
48 } elseif ($query_id) {
49 // If user is not logged, then use a cookie to store the current query.
50 if (isset($_COOKIE["GFTrackerQuery"])) {
51 $gf_tracker = unserialize($_COOKIE["GFTrackerQuery"]);
53 $gf_tracker = array();
55 $gf_tracker[$ath->getID()] = $query_id;
56 // Send the query_id as a cookie to save it.
57 setcookie("GFTrackerQuery", serialize($gf_tracker));
58 $_COOKIE["GFTrackerQuery"] = serialize($gf_tracker);
59 } elseif (isset($_COOKIE["GFTrackerQuery"])) {
60 $gf_tracker = unserialize($_COOKIE["GFTrackerQuery"]);
61 $query_id = (int)$gf_tracker[$ath->getID()];
64 $af = new ArtifactFactory($ath);
66 if (!$af || !is_object($af)) {
67 exit_error('Error','Could Not Get Factory');
68 } elseif ($af->isError()) {
69 exit_error('Error',$af->getErrorMessage());
72 if (!isset($_sort_col)) {
73 /* default sort order: highest priority first */
74 $_sort_col = 'priority';
77 $offset = getStringFromRequest('offset');
78 $_sort_col = getStringFromRequest('_sort_col',$_sort_col);
79 $_sort_ord = getStringFromRequest('_sort_ord',$_sort_ord);
80 $max_rows = getStringFromRequest('max_rows');
81 $set = getStringFromRequest('set');
82 $_assigned_to = getIntFromRequest('_assigned_to');
83 $_status = getIntFromRequest('_status');
84 $_extra_fields = array() ;
85 $aux_extra_fields = array() ;
86 if ($set == 'custom') {
88 //may be past in next/prev url
90 if (isset($_GET['extra_fields'][$ath->getCustomStatusField()])) {
91 $_extra_fields[$ath->getCustomStatusField()] = $_GET['extra_fields'][$ath->getCustomStatusField()];
92 } elseif (isset($_POST['extra_fields'][$ath->getCustomStatusField()])) {
93 $_extra_fields[$ath->getCustomStatusField()] = $_POST['extra_fields'][$ath->getCustomStatusField()];
97 if (is_array($_extra_fields)){
98 $keys=array_keys($_extra_fields);
99 foreach ($keys as $key) {
100 if ($_extra_fields[$key] != 'Array') {
101 $aux_extra_fields[$key] = $_extra_fields[$key];
105 if (isset($_extra_fields)){
106 $aux_extra_fields = $_extra_fields;
108 $aux_extra_fields = '';
112 $af->setup($offset,$_sort_col,$_sort_ord,$pagelength,$set,$_assigned_to,$_status,$aux_extra_fields);
114 // These vals are sanitized and/or retrieved from ArtifactFactory stored settings
116 $_sort_col=$af->order_col;
117 $_sort_ord=$af->sort;
118 $_status=$af->status;
119 $_assigned_to=$af->assigned_to;
120 $_extra_fields=$af->extra_fields;
122 $art_arr =& $af->getArtifacts();
124 if (!$art_arr && $af->isError()) {
125 exit_error('Error',$af->getErrorMessage());
128 //build page title to make bookmarking easier
129 //if a user was selected, add the user_name to the title
131 $ath->header(array('atid'=>$ath->getID()));
135 * Build the powerful browsing options pop-up boxes
140 // creating a custom technician box which includes "any" and "unassigned"
142 $res_tech= $ath->getTechnicians();
144 $tech_id_arr=util_result_column_to_array($res_tech,0);
145 $tech_id_arr[]='0'; //this will be the 'any' row
147 $tech_name_arr=util_result_column_to_array($res_tech,1);
148 $tech_name_arr[]=_('Any');
150 if (is_array($_assigned_to)) {
153 $tech_box=html_build_select_box_from_arrays ($tech_id_arr,$tech_name_arr,'_assigned_to',$_assigned_to,true,_('Unassigned'));
157 // custom order by arrays to build a pop-up box
159 $order_name_arr=array();
160 $order_name_arr[]=_('ID');
161 $order_name_arr[]=_('Priority');
162 $order_name_arr[]=_('Summary');
163 $order_name_arr[]=_('Open Date');
164 $order_name_arr[]=_('Close Date');
165 $order_name_arr[]=_('Submitter');
166 $order_name_arr[]=_('Assignee');
170 $order_arr[]='artifact_id';
171 $order_arr[]='priority';
172 $order_arr[]='summary';
173 $order_arr[]='open_date';
174 $order_arr[]='close_date';
175 $order_arr[]='submitted_by';
176 $order_arr[]='assigned_to';
179 // custom sort arrays to build pop-up box
181 $sort_name_arr=array();
182 $sort_name_arr[]=_('Ascending');
183 $sort_name_arr[]=_('Descending');
190 // custom changed arrays to build pop-up box
192 $changed_name_arr=array();
193 $changed_name_arr[]=_('Any changes');
194 $changed_name_arr[]=_('Last 24H');
195 $changed_name_arr[]=_('Last 7days');
196 $changed_name_arr[]=_('Last 2weeks');
197 $changed_name_arr[]=_('Last 1month');
199 $changed_arr=array();
200 $changed_arr[]= 0x7fffffff; // Any
201 $changed_arr[]= 3600 * 24; // 24 hour
202 $changed_arr[]= 3600 * 24 * 7; // 1 week
203 $changed_arr[]= 3600 * 24 * 14;// 2 week
204 $changed_arr[]= 3600 * 24 * 30;// 1 month
208 * Show the free-form text submitted by the project admin
210 echo $ath->renderBrowseInstructions();
213 // statuses can be custom in GForge 4.5+
215 if ($ath->usesCustomStatuses()) {
216 $aux_extra_fields = array();
217 if (is_array($_extra_fields)){
218 $keys=array_keys($_extra_fields);
219 foreach ($keys as $key) {
220 if (!is_array($_extra_fields[$key])) {
221 $aux_extra_fields[$key] = $_extra_fields[$key];
225 $aux_extra_fields = $_extra_fields;
227 $status_box=$ath->renderSelect ($ath->getCustomStatusField(),$aux_extra_fields[$ath->getCustomStatusField()],false,'',true,_('Any'));
229 if (is_array($_status)) {
232 $status_box = $ath->statusBox('_status',$_status,true,_('Any'));
234 echo '<script type="text/javascript" src="/tabber/tabber.js"></script>'."\n";
237 $proj_name = $group->getUnixName();
238 $proj_url = util_make_url_g($group->getUnixName(),$group_id);
239 // the tracker's URIs are constructed in order to support addition of an OSLC-CM REST server
240 // inside /tracker/cm/. There each tracker has a URL in the form .../project/PROJ_NAME/atid/ATID
241 $tracker_stdzd_uri = util_make_url('/tracker/cm/project/'. $proj_name .'/atid/'. $ath->getID());
242 print '<div about="'. $tracker_stdzd_uri
243 .'" typeof="sioc:Container" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:doap="http://usefulinc.com/ns/doap#">'."\n";
244 print '<span rel="http://www.w3.org/2002/07/owl#sameAs" resource="" />'."\n";
245 print '<span rev="doap:bug-database sioc:space_of" resource="'. $proj_url .'" />'."\n";
246 print "</div>\n"; // end of about
249 <div id="tabber" class="tabber">
250 <div class="tabbertab" title="'._('Advanced queries').'">';
252 if (session_loggedin()) {
253 $res = db_query_params ('SELECT artifact_query_id,query_name, CASE WHEN query_type>0 THEN 1 ELSE 0 END as type
255 WHERE group_artifact_id=$1 AND (user_id=$2 OR query_type>0)
256 ORDER BY type ASC, query_name ASC',
257 array ($ath->getID(),
260 $res = db_query_params ('SELECT artifact_query_id,query_name, CASE WHEN query_type>0 THEN 1 ELSE 0 END as type
262 WHERE group_artifact_id=$1 AND query_type>0
263 ORDER BY type ASC, query_name ASC',
264 array ($ath->getID()));
268 if (db_numrows($res)>0) {
269 echo '<form action="'. getStringFromServer('PHP_SELF') .'" method="get">';
270 echo '<input type="hidden" name="group_id" value="'.$group_id.'" />';
271 echo '<input type="hidden" name="atid" value="'.$ath->getID().'" />';
272 echo '<input type="hidden" name="power_query" value="1" />';
273 echo ' <table width="100%" cellspacing="0">
277 $optgroup['key'] = 'type';
278 $optgroup['values'][0] = 'Private queries';
279 $optgroup['values'][1] = 'Project queries';
280 echo '<span style="font-size:smaller">';
281 echo '<select name="query_id">';
282 echo '<option value="100">Select One</option>';
284 $selected = $af->getDefaultQuery();
285 while ($row = db_fetch_array($res)) {
286 if ($current != $row['type']) {
289 $label = $row['type'] ? 'Project' : 'Private';
290 echo '<optgroup label="'.$label.'">';
291 $current = $row['type'];
293 echo '<option value="'.$row['artifact_query_id'].'"';
294 if ($row['artifact_query_id'] == $selected)
295 echo ' selected="selected"';
296 echo '>'. $row['query_name'] .'</option>'."\n";
302 <input type="submit" name="run" value="'._('Power Query').'" />
303 <a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'.
304 _('Build Query').'</a>
309 <a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'._('Build Query').'</a></strong>';
313 <div class="tabbertab'.($af->query_type == 'custom' ? ' tabbertabdefault' : '').'" title="'._('Simple Filtering and Sorting').'">
314 <form action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">
315 <input type="hidden" name="query_id" value="-1" />
316 <input type="hidden" name="set" value="custom" />
317 <table width="100%" cellspacing="0">
320 '._('Assignee').': '. $tech_box .'
323 '._('State').': '. $status_box .'
328 ': <a href="javascript:help_window(\'/help/tracker.php?helpname=sort_by\')">' .
329 '<strong>(?)</strong></a>'.
330 html_build_select_box_from_arrays($order_arr,$order_name_arr,'_sort_col',$_sort_col,false) .
331 html_build_select_box_from_arrays($sort_arr,$sort_name_arr,'_sort_ord',$_sort_ord,false) .
332 '<input type="submit" name="submit" value="'._('Quick Browse').'" />';
340 if ($af->query_type == 'default') {
341 echo '<div class="tabbertab tabbertabdefault" title="'._('Default').'">';
342 echo '<strong>'._('Viewing only opened records by default, use \'Advanced queries\' or \'Simple Filtering and Sorting\' to change.').'</strong>';
348 if ($art_arr && count($art_arr) > 0) {
351 $aq = new ArtifactQuery($ath,$query_id);
352 $has_bargraph = (in_array('bargraph', $aq->getQueryOptions()));
354 $has_bargraph = false;
358 // Display the roadmap block based on the values of the Status field.
359 $colors = array('#a71d16', '#ffa0a0', '#f5f5b5', '#bae0ba', '#16a716');
362 foreach($art_arr as $art) {
363 if ($ath->usesCustomStatuses()) {
364 $custom_id = $ath->getCustomStatusField();
365 $extra_data = $art->getExtraFieldDataText();
366 $count[ $extra_data[$custom_id]['value'] ]++;
368 $count[ $art->getStatusName()]++;
371 foreach($count as $n => $c) {
372 $percent[$n] = round(100*$c/count($art_arr));
376 $efarr =& $ath->getExtraFields(ARTIFACT_EXTRAFIELDTYPE_STATUS);
377 $keys=array_keys($efarr);
378 $field_id = $keys[0];
379 $states = $ath->getExtraFieldElements($field_id);
382 if (is_array($states)) {
383 foreach($states as $state) {
384 $name = $state['element_name'];
386 $graph .= '<td style="background: '.$colors[$i].'; width: '.$percent[$name].'%;"> </td>';
387 $legend .= '<td style="white-space: nowrap; width: '.$percent[$name].'%;">'."<i>$name: $count[$name] ($percent[$name]%)</i></td>";
395 <table class="progress">
397 <tr><?php echo $graph; ?></tr>
400 <table class="progress_legend">
401 <tr><?php echo $legend ?></tr>
407 if ($set=='custom') {
408 $set .= '&_assigned_to='.$_assigned_to.'&_status='.$_status.'&_sort_col='.$_sort_col.'&_sort_ord='.$_sort_ord;
409 if (array_key_exists($ath->getCustomStatusField(),$_extra_fields)) {
410 $set .= '&extra_fields['.$ath->getCustomStatusField().']='.$_extra_fields[$ath->getCustomStatusField()];
415 $IS_ADMIN=$ath->userIsAdmin();
419 <form name="artifactList" action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">
420 <input type="hidden" name="form_key" value="'.form_generate_key().'" />
421 <input type="hidden" name="func" value="massupdate" />';
424 $browse_fields = explode(',', "id,".$ath->getBrowseList());
426 foreach ($browse_fields as $f) {
428 if (intval($f) > 0) {
429 $title = $ath->getExtraFieldName($f);
436 $title=_('Description');
437 if ($f == 'open_date')
438 $title=_('Open Date');
439 if ($f == 'close_date')
440 $title=_('Close Date');
441 if ($f == 'status_id')
443 if ($f == 'priority')
444 $title=_('Priority');
445 if ($f == 'assigned_to')
446 $title=_('Assigned to');
447 if ($f == 'submitted_by')
448 $title=_('Submitted by');
449 if ($f == 'related_tasks')
450 $title=_('Related tasks');
452 $title_arr[] = $title;
455 echo $GLOBALS['HTML']->listTableTop ($title_arr);
457 $then=(time()-$ath->getDuePeriod());
459 $max = ((count($art_arr) > ($start + $pagelength)) ? ($start+$pagelength) : count($art_arr) );
461 for ($i=$start; $i<$max; $i++) {
462 $extra_data = $art_arr[$i]->getExtraFieldDataText();
464 <tr '. $HTML->boxGetAltRowStyle($i) . '>';
465 foreach ($browse_fields as $f) {
467 echo '<td style="white-space: nowrap;">'.
468 ($IS_ADMIN?'<input type="checkbox" name="artifact_id_list[]" value="'.
469 $art_arr[$i]->getID() .'" /> ':'').
470 '<a href="'.getStringFromServer('PHP_SELF').'?func=detail&aid='.
471 $art_arr[$i]->getID() .
472 '&group_id='. $group_id .'&atid='.
473 $ath->getID().'">'.$art_arr[$i]->getID() .
475 } else if ($f == 'summary') {
476 echo '<td><a href="'.getStringFromServer('PHP_SELF').'?func=detail&aid='.
477 $art_arr[$i]->getID() .
478 '&group_id='. $group_id .'&atid='.
480 $art_arr[$i]->getSummary().
482 } else if ($f == 'open_date') {
483 echo '<td>'. (($set != 'closed' && $art_arr[$i]->getOpenDate() < $then)?'* ':' ') .
484 date(_('Y-m-d H:i'),$art_arr[$i]->getOpenDate()) .'</td>';
485 } else if ($f == 'status_id') {
486 echo '<td>'. $art_arr[$i]->getStatusName() .'</td>';
487 } else if ($f == 'priority') {
488 echo '<td class="priority'.$art_arr[$i]->getPriority() .'">'. $art_arr[$i]->getPriority() .'</td>';
489 } else if ($f == 'assigned_to') {
490 echo '<td>'. $art_arr[$i]->getAssignedRealName() .'</td>';
491 } else if ($f == 'submitted_by') {
492 echo '<td>'. $art_arr[$i]->getSubmittedRealName() .'</td>';
493 } else if ($f == 'close_date') {
494 echo '<td>'. ($art_arr[$i]->getCloseDate() ?
495 date(_('Y-m-d H:i'),$art_arr[$i]->getCloseDate()) :' ') .'</td>';
496 } else if ($f == 'details') {
497 echo '<td>'. $art_arr[$i]->getDetails() .'</td>';
498 } else if ($f == 'related_tasks') {
500 $tasks_res = $art_arr[$i]->getRelatedTasks();
502 while ($rest = db_fetch_array($tasks_res)) {
503 $link = '/pm/task.php?func=detailtask&project_task_id='.$rest['project_task_id'].
504 '&group_id='.$group_id.'&group_project_id='.$rest['group_project_id'];
505 $title = '[T'.$rest['project_task_id'].']';
506 if ($rest['status_id'] == 2) {
507 $title = '<strike>'.$title.'</strike>';
509 print $s.'<a href="'.$link.'" title="'.$rest['summary'].'">'.$title.'</a>';
513 } else if (intval($f) > 0) {
514 // Now display extra-fields (fields are numbers).
515 $value = $extra_data[$f]['value'];
516 if ($extra_data[$f]['type'] == 9) {
517 $value = preg_replace('/\b(\d+)\b/e', "_artifactid2url('\\1')", $value);
518 } else if ($extra_data[$f]['type'] == 7) {
519 if ($art_arr[$i]->getStatusID() == 2) {
520 $value = '<strike>'.$value.'</strike>';
524 echo '<td>' . $value .'</td>';
526 // Display ? for unknown values.
534 Show extra rows for <-- Prev / Next -->
536 //only show this if we're not using a power query
537 if ($af->max_rows > 0) {
538 if (($offset > 0) || ($rows >= 50)) {
540 <tr><td colspan="2">';
542 echo '<a href="'.getStringFromServer('PHP_SELF').'?func=browse&group_id='.$group_id.'&atid='.$ath->getID().'&set='.
543 $set.'&offset='.($offset-50).'"><strong><-- '._('Previous 50').'</strong></a>';
547 echo '</td><td> </td><td colspan="2">';
549 echo '<a href="'.getStringFromServer('PHP_SELF').'?func=browse&group_id='.$group_id.'&atid='.$ath->getID().'&set='.
550 $set.'&offset='.($offset+50).'"><strong>'._('Next 50').' --></strong></a>';
558 echo $GLOBALS['HTML']->listTableBottom();
559 $pages = count($art_arr) / $pagelength;
560 $currentpage = intval($start / $pagelength);
561 //echo "Item Count: ".count($arr)."Pages: $pages";
563 $skipped_pages=false;
564 for ($j=0; $j<$pages; $j++) {
566 if ((($j > 4) && ($j < ($currentpage-5))) || (($j > ($currentpage+5)) && ($j < ($pages-5)))) {
567 if (!$skipped_pages) {
573 $skipped_pages=false;
576 if ($j == $currentpage) {
577 echo '<strong>'.($j+1).'</strong> ';
579 echo '<a href="'.getStringFromServer('PHP_SELF')."?func=browse&group_id=".$group_id.'&atid='.$ath->getID().'&set='. $set.'&start='.($j*$pagelength).'"><strong>'.($j+1).'</strong></a> ';
588 echo '<script type="text/javascript">
590 function checkAll(val) {
591 al=document.artifactList;
592 len = al.elements.length;
594 for( i=0 ; i<len ; i++) {
595 if (al.elements[i].name==\'artifact_id_list[]\') {
596 al.elements[i].checked=val;
603 <table width="100%" border="0" id="admin_mass_update">
606 <a href="javascript:checkAll(1)">'._('Check all').'</a>
608 <a href="javascript:checkAll(0)">'._('Clear all').'</a>
611 <span class="important">'._('<strong>Admin:</strong> If you wish to apply changes to all items selected above, use these controls to change their properties and click once on "Mass Update".').'</span></p>
616 // build custom fields
618 $ef =& $ath->getExtraFields(ARTIFACT_EXTRAFIELD_FILTER_INT);
619 $keys=array_keys($ef);
622 for ($i=0; $i<count($keys); $i++) {
623 if (($ef[$keys[$i]]['field_type']==ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($ef[$keys[$i]]['field_type']==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
624 $sel[$keys[$i]]=array('100');
626 $sel[$keys[$i]]='100';
629 $ath->renderExtraFields($sel,true,_('No Change'),false,'',ARTIFACT_EXTRAFIELD_FILTER_INT,true);
631 <td><strong>'._('Priority').': <a href="javascript:help_window(\'/help/tracker.php?helpname=priority\')"><strong>(?)</strong></a>
633 echo build_priority_select_box ('priority', '100', true);
640 <td><strong>'._('Assigned to').': <a href="javascript:help_window(\'/help/tracker.php?helpname=assignee\')"><strong>(?)</strong></a>
641 </strong><br />'. $ath->technicianBox ('assigned_to','100.1',true,_('Nobody'),'100.1',_('No Change')) .'</td>
643 if (!$ath->usesCustomStatuses()) {
644 echo '<strong>'._('State').': <a href="javascript:help_window(\'/help/tracker.php?helpname=status\')"><strong>(?)</strong></a></strong>
645 <br />'. $ath->statusBox ('status_id','xzxz',true,_('No Change'));
650 <tr><td colspan="2"><strong>'._('Canned Response').':
651 <a href="javascript:help_window(\'/help/tracker.php?helpname=canned_response\')"><strong>(?)</strong></a>
652 </strong><br />'. $ath->cannedResponseBox ('canned_response') .'</td></tr>
654 <tr><td colspan="3" align="center"><input type="submit" name="submit" value="'._('Mass update').'" /></td></tr>
659 printf(_('* Denotes requests > %1$s Days Old'), ($ath->getDuePeriod()/86400));
661 if (in_array('priority', $browse_fields)) {
662 show_priority_colors_key();
668 <h1>'._('No items found').'</h1>';
670 //echo "<!-- $sql -->";
674 $ath->footer(array());
678 // c-file-style: "bsd"