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
)
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 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT
));
219 $fieldbits = array();
221 foreach ($fields AS $field)
225 $field['defaultvalue'] = '';
228 if (!is_null($bug["field$field[fieldid]"]))
230 $bugsys->debug("not null: $field[fieldid]");
231 $value = $bug["field$field[fieldid]"];
235 $value = $field['defaultvalue'];
238 if ($ignore21mask AND $field['mask'] != 0)
243 if ($field['mask'] == 2)
245 switch ($field['type'])
248 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
251 case 'input_checkbox':
252 $selected = (($value) ?
' checked="checked"' : '');
253 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
256 case 'select_single':
257 $selects = unserialize($field['selects']);
258 $value = trim($value);
264 if (!$field['usedefault'] AND !trim($value))
266 $selected = ' selected="selected"';
272 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
274 foreach ($selects AS $id => $select)
277 $select = stripslashes(trim($select));
278 if ($select == $value)
280 $selected = ' selected="selected"';
282 else if ($field['usedefault'] AND $id == 0)
284 $selected = ' selected="selected"';
286 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
288 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
294 $bugsys->debug('mask 1 processing');
295 if (is_null($fieldvalues["field$field[fieldid]"]))
297 $bugsys->debug("is null: $field[fieldid]");
298 if ($field['type'] == 'select_single')
300 if ($field['usedefault'])
302 $temp = unserialize($field['selects']);
303 $value = trim($temp[0]);
307 $value = $fieldvalues["field$field[fieldid]"];
312 $value = $field['defaultvalue'];
317 $value = $fieldvalues["field$field[fieldid]"];
320 if ($field['type'] == 'input_checkbox')
322 $value = (($value) ?
'True' : 'False');
324 $field['value'] = $value;
325 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
327 $fieldbits[] = $tempfield;
333 // ###################################################################
335 * This takes the bug ID and input data and then sanitizes, verifies,
336 * and processes the data for custom fields. If there are any errors,
337 * they are passed to the message reporter.
339 * @param integer The bug ID; if NULL, then it returns a query that needs to have %1$s replaced with the bug ID, otherwise it executes the query itself
340 * @param object MessageReporter object
341 * @param bool If there are errors, add them to an errorbox format? If not, then display-on-encounter
342 * @param array If you don't want to get the data from $bugsys->in[], then an optional input source
344 * @return mixed NULL if an ID is passed, string if bugid is NULL
346 function process_custom_fields($bugid, $msg, $errorbox = false
, $inputdata = array())
352 $inputdata =& $bugsys->in
;
355 $fields = $bugsys->db
->query("
357 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
358 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
359 ON (bugfield.fieldid = permission.fieldid)
360 WHERE permission.mask = 2
361 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
363 while ($field = $bugsys->db
->fetch_array($fields))
365 if ($field['type'] == 'input_checkbox')
367 $fieldbuild[] = 'field' . $field['fieldid'];
368 if (isset($inputdata["field$field[fieldid]"]))
379 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
381 $errorlist[] = sprintf(_('The "%1$s" field is a required field.'), $field['name']);
385 if (!empty($field['regexmatch']))
387 if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["field$field[fieldid]"]))
389 $errorlist[] = sprintf(_('%1$s does not match the specified format'), $field['name']);
394 if (isset($inputdata["field$field[fieldid]"]))
396 $fieldbuild[] = 'field' . $field['fieldid'];
398 if ($field['type'] == 'input_text')
400 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
404 if ($inputdata["field$field[fieldid]"] == -1)
406 $fieldvalue[] = "''";
410 $temp = unserialize($field['selects']);
411 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
420 foreach ($errorlist AS $err)
422 $msg->add_error($err);
427 $msg->error($errorlist[0]);
431 if (sizeof($fieldbuild) < 1)
436 $query = "REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES (%1\$s, " . implode(', ', $fieldvalue) . ")";
442 $bugsys->db
->query(sprintf($query, $bugid));
445 // ####################### Start fetch_on_bits #######################
446 function fetch_on_bits($mask, $userinfo = null
)
450 if ($userinfo == null
)
452 $userinfo =& $bugsys->userinfo
;
457 $usergroupid = $userinfo['usergroupid'];
459 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions
["$mask"] AND is_array($bugsys->datastore
['product']))
461 foreach ($bugsys->datastore
['product'] AS $id => $product)
463 if (!$product['componentmother'])
465 $onbits["$id"] = $id;
470 if (is_array($bugsys->datastore
['permission']["$usergroupid"]))
472 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
474 if ($bit & $bugsys->permissions
["$mask"])
476 $onbits["$productid"] = $productid;
480 if ($onbits["$productid"])
482 unset($onbits["$productid"]);
488 if (sizeof($onbits) < 1)
493 return implode(',', $onbits);
496 // #################### Start isso_pre_parse_hook ####################
497 // the pre-parse hook for ISSO's template engine
498 function isso_pre_parse_hook($template)
500 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
504 // ###################### Start fetch_help_link ######################
505 // returns a prepared link to insert into templates that opens up a
506 // help popup in the user-end
507 function fetch_help_link($topic)
511 if (isset($bugsys->datastore
['help']["$topic"]))
513 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
520 return "[[INVALID TOPIC: $topic]]";
525 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
530 // ###################################################################
532 * Returns a user array of information that is specific to all visiting
533 * users (guests). This can then be passed to any function that requires
538 * @return array User information array
540 function fetch_guest_user()
550 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
551 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
555 // ###################################################################
557 * Does an exhaustive permissions check on the bug. It checks for hidden
558 * bug status and ability to view hidden bugs. This normally was done
559 * at the top of each page, but it got so big, it was moved to a function.
563 * @param array Bug array
564 * @param array Alternate user array
566 * @return bool Does the user have permission
568 function check_bug_permissions($bug, $userinfo = null
)
571 if ($userinfo == null
)
573 $userinfo = $bugsys->userinfo
;
576 $bugsys->debug("checking permissions for $userinfo[userid] on bug $bug[bugid]");
578 $bugsys->debug('*** START VERBOSE CHECK ***');
580 $bugsys->debug('* !can_perform(canviewbugs, $bug[product], $userinfo) = ' . (int)(!can_perform('canviewbugs', $bug['product'], $userinfo)));
581 $bugsys->debug('* $bug[hidden] = ' . (int)$bug['hidden']);
582 $bugsys->debug('* $userinfo[userid] (' . $userinfo['userid'] . ') == $bug[userid] (' . $bug['userid'] . ') = ' . (int)($userinfo['userid'] == $bug['userid']));
583 $bugsys->debug('* can_perform(canviewownhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewownhidden', $bug['product'], $userinfo)));
584 $bugsys->debug('* can_perform(canviewhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewhidden', $bug['product'], $userinfo)));
585 $bugsys->debug('* !$bug[hidden] = ' . (int)(!$bug['hidden']));
587 $bugsys->debug('*** END PERMISSIONS CHECK ***');
591 !can_perform('canviewbugs', $bug['product'], $userinfo)
598 ($userinfo['userid'] == $bug['userid'] AND can_perform('canviewownhidden', $bug['product'], $userinfo))
600 can_perform('canviewhidden', $bug['product'], $userinfo)
608 $bugsys->debug('*** DONE WITH REAL CALLS ***');
612 $bugsys->debug('*** DONE WITH REAL CALLS ***');
617 /*=====================================================================*\
618 || ###################################################################
621 || ###################################################################
622 \*=====================================================================*/