2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 // ###################################################################
24 * Constructs HTML code <select>s from an array. You use they keys when
25 * you need to access a multi-dimensional array of data.
29 * @param string HTML name of the select
30 * @param array Array of <option>s
31 * @param integer ID of the selected item, 0 for none
32 * @param string Name of the index where values are stored in the $array
33 * @param string Name of the iddex where the labels are stored in $array
34 * @param bool Value of the blank option, FALSE turns it off
35 * @param bool Construct a multiple-selection <select> menu and append "[]" to the end of the name
37 * @return string Constructed HTML output
39 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false
, $multiple = false
)
45 $selected = explode(',', $selected);
48 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
49 if ($includenil !== false
)
51 $opts[] = '<option value="' . $includenil . '"' . ((!$selected OR (is_array($selected) AND in_array($includenil, $selected))) ?
' selected="selected"' : '') . '> ---------</option>';
53 foreach ($array AS $value => $label)
55 $newval = ($valuekey ?
$label["$valuekey"] : $value);
56 $newlab = ($labelkey ?
$label["$labelkey"] : $label);
57 $opts[] = '<option value="' . $newval . '"' . (($selected == $newval OR (is_array($selected) AND in_array($newval, $selected))) ?
' selected="selected"' : '') . '>' . $newlab . '</option>';
59 return '<select class="input" name="' . $name . ($multiple ?
'[]' : '') . '"' . ($multiple ?
' multiple="multiple" size="' . (sizeof($array) < 8 ?
sizeof($array) +
1 : 8) . '"' : '') . '>' . implode("\n\t", $opts) . "\r</select>";
62 // ################### Start construct_user_display ##################
63 // $userinfo needs userid, email, displayname, and showemail
64 function construct_user_display($userinfo, $html = true
)
68 if (!$userinfo['userid'])
70 $userinfo['displayname'] = _('Guest');
71 $userinfo['showemail'] = false
;
76 eval('$username = "' . $bugsys->template
->fetch('username_display') . '";');
80 if ($userinfo['showemail'])
82 $username = sprintf(_('%1$s <%2$s>'), $userinfo['displayname'], $userinfo['email']);
86 $username = $userinfo['displayname'];
93 // ######################## Start can_perform ########################
94 // short-hand for bitwise &
95 function can_perform($bitmask, $productid = 0, $userinfo = null
)
99 if ($userinfo == null
)
101 $userinfo =& $bugsys->userinfo
;
104 if (!isset($bugsys->permissions
["$bitmask"]))
106 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING
);
109 if (!$userinfo['permissions'])
111 $userinfo['permissions'] = (int)$bugsys->datastore
['usergroup']["$userinfo[usergroupid]"]['permissions'];
114 if ($productid AND isset($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"]))
116 $inspecific = array('cansearch', 'canbeassignedto', 'canadminpanel', 'canadminbugs', 'canadminfields', 'canadminversions', 'canadminusers', 'canadmingroups', 'canadmintools');
118 if (!in_array($bitmask, $inspecific))
120 $bugsys->debug("verdict* on can_perform($bitmask, $productid, $userinfo[userid]) = " . ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions
["$bitmask"]));
121 return ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions
["$bitmask"]);
125 $bugsys->debug("verdict on can_perform($bitmask, $productid, $userinfo[userid]) = " . ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]));
126 return ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]);
129 // ###################################################################
131 * Runs through a given datastore item and creates a series of <select>
136 * @param string Datastore name
137 * @param string Array index for the label
138 * @param string Array index for the value
139 * @param mixed The selected value(s)
140 * @param bool Include a blank option? TRUE will set a null value, FALSE turns it off, anything else is used as the value for the blank option
141 * @param bool Generate it using admin printers?
143 * @return string Unelss in admin mode, returns the constructed options
145 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
, $adminmode = false
)
156 if ($includeblank === true
OR $includeblank !== false
)
158 $newval = ($inclueblank === true ?
'' : $includeblank);
161 $admin->list_item('', '', ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true
: false
));
167 $selected = ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true
: false
);
168 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
172 foreach ($bugsys->datastore
["$datastore"] AS $item)
174 $label = $item["$labelname"];
175 $value = $item["$valuename"];
176 $selected = (($value == $selectedvalue OR (is_array($selectedvalue) AND in_array($value, $selectedvalue))) ? true
: false
);
180 $admin->list_item($label, $value, $selected);
184 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
194 // ################## Start construct_custom_fields ##################
195 function construct_custom_fields($bug = array(), $ignore21mask = false
, $nodefault = false
, $searchMode = false
)
200 if (!is_array($fields))
203 $fields_fetch = $bugsys->db
->query("
204 SELECT bugfield.*, permission.mask
205 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
206 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
207 ON (bugfield.fieldid = permission.fieldid)
208 WHERE (permission.mask = 2 OR permission.mask = 1)
209 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
211 while ($field = $bugsys->db
->fetch_array($fields_fetch))
213 $fields["$field[fieldid]"] = $field;
217 $fieldbits = array();
219 foreach ($fields AS $field)
223 $field['defaultvalue'] = '';
226 if (!is_null($bug["custom$field[fieldid]"]))
228 $bugsys->debug("not null: $field[fieldid]");
229 $value = $bug["custom$field[fieldid]"];
233 $value = $field['defaultvalue'];
236 if ($ignore21mask AND $field['mask'] != 0)
241 if ($field['mask'] == 2)
243 switch ($field['type'])
246 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
249 case 'input_checkbox':
250 $selected = ($value ?
' checked="checked"' : '');
251 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
254 case 'select_single':
255 $selects = unserialize($field['selects']);
256 $value = trim($value);
262 if (!$field['usedefault'] AND !trim($value))
264 $selected = ' selected="selected"';
270 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
272 foreach ($selects AS $id => $select)
275 $select = stripslashes(trim($select));
276 if ($select == $value)
278 $selected = ' selected="selected"';
280 else if ($field['usedefault'] AND $id == 0)
282 $selected = ' selected="selected"';
284 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
286 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
292 $bugsys->debug('mask 1 processing');
293 if (is_null($bug["custom$field[fieldid]"]))
295 $bugsys->debug("is null: $field[fieldid]");
296 if ($field['type'] == 'select_single')
298 if ($field['usedefault'])
300 $temp = unserialize($field['selects']);
301 $value = trim($temp[0]);
305 $value = $bug["custom$field[fieldid]"];
310 $value = $field['defaultvalue'];
315 $value = $bug["custom$field[fieldid]"];
318 if ($field['type'] == 'input_checkbox')
320 $value = ($value ?
'True' : 'False');
322 $field['value'] = $value;
323 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
325 $fieldbits[] = $tempfield;
331 // ###################################################################
333 * This takes the bug API object and input data and then sanitizes, verifies,
334 * and processes the data for custom fields. If there are any errors,
335 * they are passed to the message reporter.
337 * @param object A BugAPI object
338 * @param object MessageReporter object
339 * @param bool If there are errors, add them to an errorbox format? If not, then display-on-encounter
340 * @param bool Search mode: don't change certain fields when they're 0 or empty
342 * @return mixed NULL if an ID is passed, string if bugid is NULL
344 function process_custom_fields(&$bugapi, &$msg, $errorbox = false
, $searchMode = false
)
350 $inputdata =& $bugsys->in
;
353 $fields = $bugsys->db
->query("
355 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
356 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
357 ON (bugfield.fieldid = permission.fieldid)
358 WHERE permission.mask = 2
359 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
361 while ($field = $bugsys->db
->fetch_array($fields))
363 $fieldname = "custom$field[fieldid]";
364 if ($field['type'] == 'input_checkbox')
366 if ($searchMode AND intval($inputdata["$fieldname"]) == 0)
370 $bugapi->set($fieldname, intval(isset($inputdata["$fieldname"])));
374 if ($field['required'] AND empty($inputdata["$fieldname"]) AND !$searchMode)
376 $errorlist[] = sprintf(_('The "%1$s" field is a required field.'), $field['name']);
380 if (!empty($field['regexmatch']))
382 if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["$fieldname"]))
384 $errorlist[] = sprintf(_('%1$s does not match the specified format'), $field['name']);
389 if (isset($inputdata["$fieldname"]))
391 if ($field['type'] == 'input_text')
393 if (empty($inputdata["$fieldname"]) AND $searchMode)
397 $bugapi->set($fieldname, $inputdata["$fieldname"]);
401 if ($inputdata["$fieldname"] == -1)
405 $bugapi->set($fieldname, '');
410 $temp = unserialize($field['selects']);
411 $bugapi->set($fieldname, trim($temp[ intval($inputdata["$fieldname"]) ]));;
420 foreach ($errorlist AS $err)
422 $msg->addError($err);
427 $msg->error($errorlist[0]);
432 // ####################### Start fetch_on_bits #######################
433 function fetch_on_bits($mask, $userinfo = null
)
437 if ($userinfo == null
)
439 $userinfo =& $bugsys->userinfo
;
444 $usergroupid = $userinfo['usergroupid'];
446 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions
["$mask"] AND is_array($bugsys->datastore
['product']))
448 foreach ($bugsys->datastore
['product'] AS $id => $product)
450 $onbits["$id"] = $id;
454 if (is_array($bugsys->datastore
['permission']["$usergroupid"]))
456 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
458 if ($bit & $bugsys->permissions
["$mask"])
460 $onbits["$productid"] = $productid;
464 if ($onbits["$productid"])
466 unset($onbits["$productid"]);
472 if (sizeof($onbits) < 1)
477 return implode(',', $onbits);
480 // #################### Start isso_pre_parse_hook ####################
481 // the pre-parse hook for ISSO's template engine
482 function isso_pre_parse_hook($template)
484 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
488 // ###################### Start fetch_help_link ######################
489 // returns a prepared link to insert into templates that opens up a
490 // help popup in the user-end
491 function fetch_help_link($topic)
495 if (isset($bugsys->datastore
['help']["$topic"]))
497 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
504 return "[[INVALID TOPIC: $topic]]";
509 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
514 // ###################################################################
516 * Returns a user array of information that is specific to all visiting
517 * users (guests). This can then be passed to any function that requires
522 * @return array User information array
524 function fetch_guest_user()
534 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
535 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
536 'timezone' => $bugsys->options
['defaulttimezone']
540 // ###################################################################
542 * Does an exhaustive permissions check on the bug. It checks for hidden
543 * bug status and ability to view hidden bugs. This normally was done
544 * at the top of each page, but it got so big, it was moved to a function.
548 * @param array Bug array
549 * @param array Alternate user array
551 * @return bool Does the user have permission
553 function check_bug_permissions($bug, $userinfo = null
)
556 if ($userinfo == null
)
558 $userinfo = $bugsys->userinfo
;
561 $bugsys->debug("checking permissions for $userinfo[userid] on bug $bug[bugid]");
563 $bugsys->debug('*** START VERBOSE CHECK ***');
565 $bugsys->debug('* !can_perform(canviewbugs, $bug[product], $userinfo) = ' . (int)(!can_perform('canviewbugs', $bug['product'], $userinfo)));
566 $bugsys->debug('* $bug[hidden] = ' . (int)$bug['hidden']);
567 $bugsys->debug('* $userinfo[userid] (' . $userinfo['userid'] . ') == $bug[userid] (' . $bug['userid'] . ') = ' . (int)($userinfo['userid'] == $bug['userid']));
568 $bugsys->debug('* can_perform(canviewownhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewownhidden', $bug['product'], $userinfo)));
569 $bugsys->debug('* can_perform(canviewhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewhidden', $bug['product'], $userinfo)));
570 $bugsys->debug('* !$bug[hidden] = ' . (int)(!$bug['hidden']));
572 $bugsys->debug('*** END PERMISSIONS CHECK ***');
576 !can_perform('canviewbugs', $bug['product'], $userinfo)
583 ($userinfo['userid'] == $bug['userid'] AND can_perform('canviewownhidden', $bug['product'], $userinfo))
585 can_perform('canviewhidden', $bug['product'], $userinfo)
593 $bugsys->debug('*** DONE WITH REAL CALLS ***');
597 $bugsys->debug('*** DONE WITH REAL CALLS ***');
602 // ###################################################################
604 * Takes an array of bug information and returns another array with
605 * information that is suitable for display as all the IDs have been
606 * replaced by their string equivalents
608 * @param array Unprocessed bug data
609 * @param string Color to display if the user has opted to not show status colours
611 * @param array Bug array with data fit for display
613 function ProcessBugDataForDisplay($bug, $color = '')
617 $bug['hiddendisplay'] = (can_perform('canviewhidden', $bug['product']) OR (can_perform('canviewownhidden') AND $bug['userid'] == $bugsys->userinfo
['userid']));
619 $bug['bgcolor'] = ($bugsys->userinfo
['showcolors'] ?
$bugsys->datastore
['status']["$bug[status]"]['color'] : $color);
620 $bug['product'] = $bugsys->datastore
['product']["$bug[product]"]['title'];
621 $bug['version'] = $bugsys->datastore
['version']["$bug[version]"]['version'];
622 $bug['component'] = $bugsys->datastore
['component']["$bug[component]"]['title'];
623 $bug['status'] = $bugsys->datastore
['status']["$bug[status]"]['status'];
624 $bug['resolution'] = $bugsys->datastore
['resolution']["$bug[resolution]"]['resolution'];
625 $bug['priority'] = $bugsys->datastore
['priority']["$bug[priority]"]['priority'];
626 $bug['severity'] = $bugsys->datastore
['severity']["$bug[severity]"]['severity'];
628 $bug['lastposttime'] = ($bug['hiddendisplay'] ?
$bug['hiddenlastposttime'] : $bug['lastposttime']);
629 $bug['lastpost'] = ($bug['hiddendisplay'] ?
$bug['hiddenlastpostbyname'] : $bug['lastpostbyname']);
631 $bug['lastposttime'] = $bugsys->datef
->format($bugsys->options
['dateformat'], $bug['lastposttime']);
636 // ###################################################################
638 * Loads the pagination module and sets all of the appropriate options
643 function LoadPaginationFramework()
647 $bugsys->load('pagination', 'pagination', true
);
648 $bugsys->pagination
->setDefaultPerPage($bugsys->options
['defaultpp']);
649 $bugsys->pagination
->setMaxPerPage($bugsys->options
['maxpp']);
650 $bugsys->pagination
->setPageLinks($bugsys->options
['pagelinks']);
651 $bugsys->pagination
->setPageVar('p');
652 $bugsys->pagination
->setPerPageVar('pp');
653 $bugsys->pagination
->setBitProcessor('PageNavigatorBitCallback');
654 $bugsys->pagination
->setNavigatorProcessor('PageNavigatorCallback');
655 $bugsys->pagination
->processIncomingData();
658 // ###################################################################
660 * Callback function for the Pagination->BitProcessor()
662 * @param string Base link
663 * @param bool Do not show this as a link
664 * @param integer Page number
665 * @param object Page navigator framework
667 * @return string Processed HTML
669 function PageNavigatorBitCallback($baselink, $nolink, $number, $paginator)
672 eval('$return = "' . $bugsys->template
->fetch('pagenav_bit') . '";');
676 // ###################################################################
678 * Callback function for the Pagination->NavigatorProcessor()
680 * @param string Base URL
681 * @param integer Next page number
682 * @param integer Previous page number
683 * @param array Show information
684 * @param string Individual page bits
685 * @param object Page navigator framework
687 * @return string Processed HTML
689 function PageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pagebits, $paginator)
692 eval('$return = "' . $bugsys->template
->fetch('pagenav') . '";');
696 /*=====================================================================*\
697 || ###################################################################
700 || ###################################################################
701 \*=====================================================================*/