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'] = $bugsys->lang
->string('Guest');
71 $userinfo['showemail'] = false
;
76 eval('$username = "' . $bugsys->template
->fetch('username_display') . '";');
80 if ($userinfo['showemail'])
82 $username = sprintf($bugsys->lang
->string('%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 ($productid AND isset($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"]))
111 $inspecific = array('cansearch', 'canbeassignedto', 'canadminpanel', 'canadminbugs', 'canadminfields', 'canadminversions', 'canadminusers', 'canadmingroups', 'canadmintools');
113 if (!in_array($bitmask, $inspecific))
115 $bugsys->debug("verdict on can_perform($bitmask, $productid, $userinfo[userid]) = " . ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions
["$bitmask"]));
116 return ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions
["$bitmask"]);
120 $bugsys->debug("verdict on can_perform($bitmask, $productid, $userinfo[userid]) = " . ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]));
121 return ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]);
124 // ###################################################################
126 * Runs through a given datastore item and creates a series of <select>
131 * @param string Datastore name
132 * @param string Array index for the label
133 * @param string Array index for the value
134 * @param mixed The selected value(s)
135 * @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
136 * @param bool Generate it using admin printers?
138 * @return string Unelss in admin mode, returns the constructed options
140 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
, $adminmode = false
)
151 if ($includeblank === true
OR $includeblank !== false
)
153 $newval = ($inclueblank === true ?
'' : $includeblank);
156 $admin->list_item('', '', ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true
: false
));
162 $selected = ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true
: false
);
163 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
167 foreach ($bugsys->datastore
["$datastore"] AS $item)
169 $label = $item["$labelname"];
170 $value = $item["$valuename"];
171 $selected = (($value == $selectedvalue OR (is_array($selectedvalue) AND in_array($value, $selectedvalue))) ? true
: false
);
175 $admin->list_item($label, $value, $selected);
179 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
189 // ################## Start construct_custom_fields ##################
190 function construct_custom_fields($bug = array(), $ignore21mask = false
, $nodefault = false
)
195 if (!is_array($fields))
198 $fields_fetch = $bugsys->db
->query("
199 SELECT bugfield.*, permission.mask
200 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
201 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
202 ON (bugfield.fieldid = permission.fieldid)
203 WHERE (permission.mask = 2 OR permission.mask = 1)
204 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
206 while ($field = $bugsys->db
->fetch_array($fields_fetch))
208 $fields["$field[fieldid]"] = $field;
212 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT
));
214 $fieldbits = array();
216 foreach ($fields AS $field)
220 $field['defaultvalue'] = '';
223 if (!is_null($bug["field$field[fieldid]"]))
225 $bugsys->debug("not null: $field[fieldid]");
226 $value = $bug["field$field[fieldid]"];
230 $value = $field['defaultvalue'];
233 if ($ignore21mask AND $field['mask'] != 0)
238 if ($field['mask'] == 2)
240 switch ($field['type'])
243 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
246 case 'input_checkbox':
247 $selected = (($value) ?
' checked="checked"' : '');
248 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
251 case 'select_single':
252 $selects = unserialize($field['selects']);
253 $value = trim($value);
259 if (!$field['usedefault'] AND !trim($value))
261 $selected = ' selected="selected"';
267 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
269 foreach ($selects AS $id => $select)
272 $select = stripslashes(trim($select));
273 if ($select == $value)
275 $selected = ' selected="selected"';
277 else if ($field['usedefault'] AND $id == 0)
279 $selected = ' selected="selected"';
281 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
283 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
289 $bugsys->debug('mask 1 processing');
290 if (is_null($fieldvalues["field$field[fieldid]"]))
292 $bugsys->debug("is null: $field[fieldid]");
293 if ($field['type'] == 'select_single')
295 if ($field['usedefault'])
297 $temp = unserialize($field['selects']);
298 $value = trim($temp[0]);
302 $value = $fieldvalues["field$field[fieldid]"];
307 $value = $field['defaultvalue'];
312 $value = $fieldvalues["field$field[fieldid]"];
315 if ($field['type'] == 'input_checkbox')
317 $value = (($value) ?
'True' : 'False');
319 $field['value'] = $value;
320 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
322 $fieldbits[] = $tempfield;
328 // ################### Start process_custom_fields ###################
329 function process_custom_fields($bugid, $inputdata = array())
335 $inputdata =& $bugsys->in
;
338 $fields = $bugsys->db
->query("
340 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
341 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
342 ON (bugfield.fieldid = permission.fieldid)
343 WHERE permission.mask = 2
344 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
346 while ($field = $bugsys->db
->fetch_array($fields))
348 if ($field['type'] == 'input_checkbox')
350 $fieldbuild[] = 'field' . $field['fieldid'];
351 if (isset($inputdata["field$field[fieldid]"]))
362 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
364 $errorlist[] = sprintf($bugsys->lang
->string('The "%1$s" field is a required field.'), $field['name']);
368 if (isset($inputdata["field$field[fieldid]"]))
370 $fieldbuild[] = 'field' . $field['fieldid'];
372 if ($field['type'] == 'input_text')
374 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
378 if ($inputdata["field$field[fieldid]"] == -1)
380 $fieldvalue[] = "''";
384 $temp = unserialize($field['selects']);
385 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
395 if (sizeof($fieldbuild) < 1)
400 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
403 // ####################### Start fetch_on_bits #######################
404 function fetch_on_bits($mask, $userinfo = null
)
408 if ($userinfo == null
)
410 $userinfo =& $bugsys->userinfo
;
415 $usergroupid = $userinfo['usergroupid'];
417 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions
["$mask"] AND is_array($bugsys->datastore
['product']))
419 foreach ($bugsys->datastore
['product'] AS $id => $product)
421 if (!$product['componentmother'])
423 $onbits["$id"] = $id;
428 if (is_array($bugsys->datastore
['permission']["$usergroupid"]))
430 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
432 if ($bit & $bugsys->permissions
["$mask"])
434 $onbits["$productid"] = $productid;
438 if ($onbits["$productid"])
440 unset($onbits["$productid"]);
446 if (sizeof($onbits) < 1)
451 return implode(',', $onbits);
454 // #################### Start isso_pre_parse_hook ####################
455 // the pre-parse hook for ISSO's template engine
456 function isso_pre_parse_hook($template)
458 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
462 // ###################### Start fetch_help_link ######################
463 // returns a prepared link to insert into templates that opens up a
464 // help popup in the user-end
465 function fetch_help_link($topic)
469 if (isset($bugsys->datastore
['help']["$topic"]))
471 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
478 return "[[INVALID TOPIC: $topic]]";
483 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
488 // ###################################################################
490 * Returns a user array of information that is specific to all visiting
491 * users (guests). This can then be passed to any function that requires
496 * @return array User information array
498 function fetch_guest_user()
508 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
509 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
513 // ###################################################################
515 * Does an exhaustive permissions check on the bug. It checks for hidden
516 * bug status and ability to view hidden bugs. This normally was done
517 * at the top of each page, but it got so big, it was moved to a function.
521 * @param array Bug array
522 * @param array Alternate user array
524 * @return bool Does the user have permission
526 function check_bug_permissions($bug, $userinfo = null
)
529 if ($userinfo == null
)
531 $userinfo = $bugsys->userinfo
;
534 $bugsys->debug("checking permissions for $userinfo[userid] on bug $bug[bugid]");
538 !can_perform('canviewbugs', $bug['product'], $userinfo)
545 ($userinfo['userid'] == $bug['userid'] AND can_perform('canviewownhidden', $bug['productid'], $userinfo))
547 can_perform('canviewhidden', $bug['productid'], $userinfo)
561 /*=====================================================================*\
562 || ###################################################################
565 || ###################################################################
566 \*=====================================================================*/