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";
236 <div id="tabber" class="tabber">
237 <div class="tabbertab" title="'._('Advanced queries').'">';
239 if (session_loggedin()) {
240 $res = db_query_params ('SELECT artifact_query_id,query_name, CASE WHEN query_type>0 THEN 1 ELSE 0 END as type
242 WHERE group_artifact_id=$1 AND (user_id=$2 OR query_type>0)
243 ORDER BY type ASC, query_name ASC',
244 array ($ath->getID(),
247 $res = db_query_params ('SELECT artifact_query_id,query_name, CASE WHEN query_type>0 THEN 1 ELSE 0 END as type
249 WHERE group_artifact_id=$1 AND query_type>0
250 ORDER BY type ASC, query_name ASC',
251 array ($ath->getID()));
255 if (db_numrows($res)>0) {
256 echo '<form action="'. getStringFromServer('PHP_SELF') .'" method="get">';
257 echo ' <table width="100%" cellspacing="0">
261 echo '<input type="hidden" name="group_id" value="'.$group_id.'" />';
262 echo '<input type="hidden" name="atid" value="'.$ath->getID().'" />';
263 echo '<input type="hidden" name="power_query" value="1" />';
264 $optgroup['key'] = 'type';
265 $optgroup['values'][0] = 'Private queries';
266 $optgroup['values'][1] = 'Project queries';
267 echo '<span style="font-size:smaller">';
268 echo '<select name="query_id">';
269 echo '<option value="100">Select One</option>';
271 $selected = $af->getDefaultQuery();
272 while ($row = db_fetch_array($res)) {
273 if ($current != $row['type']) {
276 $label = $row['type'] ? 'Project' : 'Private';
277 echo '<optgroup label="'.$label.'">';
278 $current = $row['type'];
280 echo '<option value="'.$row['artifact_query_id'].'"';
281 if ($row['artifact_query_id'] == $selected)
282 echo ' selected="selected"';
283 echo '>'. $row['query_name'] .'</option>'."\n";
289 <input type="submit" name="run" value="'._('Power Query').'" />
290 <a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'.
291 _('Build Query').'</a>
296 <a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'._('Build Query').'</a></strong>';
300 <div class="tabbertab'.($af->query_type == 'custom' ? ' tabbertabdefault' : '').'" title="'._('Simple Filtering and Sorting').'">
301 <form action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">
302 <table width="100%" cellspacing="0">
305 <input type="hidden" name="query_id" value="-1" />
306 <input type="hidden" name="set" value="custom" />
307 '._('Assignee').': '. $tech_box .'
310 '._('State').': '. $status_box .'
315 ': <a href="javascript:help_window(\'/help/tracker.php?helpname=sort_by\')">' .
316 '<strong>(?)</strong></a>'.
317 html_build_select_box_from_arrays($order_arr,$order_name_arr,'_sort_col',$_sort_col,false) .
318 html_build_select_box_from_arrays($sort_arr,$sort_name_arr,'_sort_ord',$_sort_ord,false) .
319 '<input type="submit" name="submit" value="'._('Quick Browse').'" />';
327 if ($af->query_type == 'default') {
328 echo '<div class="tabbertab tabbertabdefault" title="'._('Default').'">';
329 echo '<strong>'._('Viewing only opened records by default, use \'Advanced queries\' or \'Simple Filtering and Sorting\' to change.').'</strong>';
335 if ($art_arr && count($art_arr) > 0) {
337 if ($set=='custom') {
338 $set .= '&_assigned_to='.$_assigned_to.'&_status='.$_status.'&_sort_col='.$_sort_col.'&_sort_ord='.$_sort_ord;
339 if (array_key_exists($ath->getCustomStatusField(),$_extra_fields)) {
340 $set .= '&extra_fields['.$ath->getCustomStatusField().']='.$_extra_fields[$ath->getCustomStatusField()];
345 $IS_ADMIN=$ath->userIsAdmin();
349 <form name="artifactList" action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">
350 <input type="hidden" name="form_key" value="'.form_generate_key().'" />
351 <input type="hidden" name="func" value="massupdate" />';
354 $browse_fields = explode(',', "id,".$ath->getBrowseList());
356 foreach ($browse_fields as $f) {
358 if (intval($f) > 0) {
359 $title = $ath->getExtraFieldName($f);
366 $title=_('Description');
367 if ($f == 'open_date')
368 $title=_('Open Date');
369 if ($f == 'close_date')
370 $title=_('Close Date');
371 if ($f == 'status_id')
373 if ($f == 'priority')
374 $title=_('Priority');
375 if ($f == 'assigned_to')
376 $title=_('Assigned to');
377 if ($f == 'submitted_by')
378 $title=_('Submitted by');
380 $title_arr[] = $title;
383 echo $GLOBALS['HTML']->listTableTop ($title_arr);
385 $then=(time()-$ath->getDuePeriod());
387 $max = ((count($art_arr) > ($start + $pagelength)) ? ($start+$pagelength) : count($art_arr) );
389 for ($i=$start; $i<$max; $i++) {
390 $extra_data = $art_arr[$i]->getExtraFieldDataText();
392 <tr '. $HTML->boxGetAltRowStyle($i) . '>';
393 foreach ($browse_fields as $f) {
395 echo '<td style="white-space: nowrap;">'.
396 ($IS_ADMIN?'<input type="checkbox" name="artifact_id_list[]" value="'.
397 $art_arr[$i]->getID() .'" /> ':'').
398 '<a href="'.getStringFromServer('PHP_SELF').'?func=detail&aid='.
399 $art_arr[$i]->getID() .
400 '&group_id='. $group_id .'&atid='.
401 $ath->getID().'">'.$art_arr[$i]->getID() .
403 } else if ($f == 'summary') {
404 echo '<td><a href="'.getStringFromServer('PHP_SELF').'?func=detail&aid='.
405 $art_arr[$i]->getID() .
406 '&group_id='. $group_id .'&atid='.
408 $art_arr[$i]->getSummary().
410 } else if ($f == 'open_date') {
411 echo '<td>'. (($set != 'closed' && $art_arr[$i]->getOpenDate() < $then)?'* ':' ') .
412 date(_('Y-m-d H:i'),$art_arr[$i]->getOpenDate()) .'</td>';
413 } else if ($f == 'status_id') {
414 echo '<td>'. $art_arr[$i]->getStatusName() .'</td>';
415 } else if ($f == 'priority') {
416 echo '<td class="priority'.$art_arr[$i]->getPriority() .'">'. $art_arr[$i]->getPriority() .'</td>';
417 } else if ($f == 'assigned_to') {
418 echo '<td>'. $art_arr[$i]->getAssignedRealName() .'</td>';
419 } else if ($f == 'submitted_by') {
420 echo '<td>'. $art_arr[$i]->getSubmittedRealName() .'</td>';
421 } else if ($f == 'close_date') {
422 echo '<td>'. ($art_arr[$i]->getCloseDate() ?
423 date(_('Y-m-d H:i'),$art_arr[$i]->getCloseDate()) :' ') .'</td>';
424 } else if ($f == 'details') {
425 echo '<td>'. $art_arr[$i]->getDetails() .'</td>';
426 } else if (intval($f) > 0) {
427 // Now display extra-fields (fields are numbers).
428 $value = $extra_data[$f]['value'];
429 if ($extra_data[$f]['type'] == 9) {
430 $value = preg_replace('/\b(\d+)\b/e', "_artifactid2url('\\1')", $value);
432 echo '<td>' . $value .'</td>';
434 // Display ? for unknown values.
442 Show extra rows for <-- Prev / Next -->
444 //only show this if we're not using a power query
445 if ($af->max_rows > 0) {
446 if (($offset > 0) || ($rows >= 50)) {
448 <tr><td colspan="2">';
450 echo '<a href="'.getStringFromServer('PHP_SELF').'?func=browse&group_id='.$group_id.'&atid='.$ath->getID().'&set='.
451 $set.'&offset='.($offset-50).'"><strong><-- '._('Previous 50').'</strong></a>';
455 echo '</td><td> </td><td colspan="2">';
457 echo '<a href="'.getStringFromServer('PHP_SELF').'?func=browse&group_id='.$group_id.'&atid='.$ath->getID().'&set='.
458 $set.'&offset='.($offset+50).'"><strong>'._('Next 50').' --></strong></a>';
466 echo $GLOBALS['HTML']->listTableBottom();
467 $pages = count($art_arr) / $pagelength;
468 $currentpage = intval($start / $pagelength);
469 //echo "Item Count: ".count($arr)."Pages: $pages";
471 $skipped_pages=false;
472 for ($j=0; $j<$pages; $j++) {
474 if ((($j > 4) && ($j < ($currentpage-5))) || (($j > ($currentpage+5)) && ($j < ($pages-5)))) {
475 if (!$skipped_pages) {
481 $skipped_pages=false;
484 if ($j == $currentpage) {
485 echo '<strong>'.($j+1).'</strong> ';
487 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> ';
496 echo '<script type="text/javascript">
498 function checkAll(val) {
499 al=document.artifactList;
500 len = al.elements.length;
502 for( i=0 ; i<len ; i++) {
503 if (al.elements[i].name==\'artifact_id_list[]\') {
504 al.elements[i].checked=val;
511 <table width="100%" border="0" id="admin_mass_update">
514 <a href="javascript:checkAll(1)">'._('Check all').'</a>
516 <a href="javascript:checkAll(0)">'._('Clear all').'</a>
519 <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>
524 // build custom fields
526 $ef =& $ath->getExtraFields(ARTIFACT_EXTRAFIELD_FILTER_INT);
527 $keys=array_keys($ef);
530 for ($i=0; $i<count($keys); $i++) {
531 if (($ef[$keys[$i]]['field_type']==ARTIFACT_EXTRAFIELDTYPE_CHECKBOX) || ($ef[$keys[$i]]['field_type']==ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)) {
532 $sel[$keys[$i]]=array('100');
534 $sel[$keys[$i]]='100';
537 $ath->renderExtraFields($sel,true,_('No Change'),false,'',ARTIFACT_EXTRAFIELD_FILTER_INT,true);
539 <td><strong>'._('Priority').': <a href="javascript:help_window(\'/help/tracker.php?helpname=priority\')"><strong>(?)</strong></a>
541 echo build_priority_select_box ('priority', '100', true);
548 <td><strong>'._('Assigned to').': <a href="javascript:help_window(\'/help/tracker.php?helpname=assignee\')"><strong>(?)</strong></a>
549 </strong><br />'. $ath->technicianBox ('assigned_to','100.1',true,_('Nobody'),'100.1',_('No Change')) .'</td>
551 if (!$ath->usesCustomStatuses()) {
552 echo '<strong>'._('State').': <a href="javascript:help_window(\'/help/tracker.php?helpname=status\')"><strong>(?)</strong></a></strong>
553 <br />'. $ath->statusBox ('status_id','xzxz',true,_('No Change'));
558 <tr><td colspan="2"><strong>'._('Canned Response').':
559 <a href="javascript:help_window(\'/help/tracker.php?helpname=canned_response\')"><strong>(?)</strong></a>
560 </strong><br />'. $ath->cannedResponseBox ('canned_response') .'</td></tr>
562 <tr><td colspan="3" align="center"><input type="submit" name="submit" value="'._('Mass update').'" /></td></tr>
567 printf(_('* Denotes requests > %1$s Days Old'), ($ath->getDuePeriod()/86400));
569 if (in_array('priority', $browse_fields)) {
570 show_priority_colors_key();
576 <h1>'._('No items found').'</h1>';
578 //echo "<!-- $sql -->";
582 $ath->footer(array());
586 // c-file-style: "bsd"