]>
src.bluestatic.org Git - bugdar.git/blob - includes/functions.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 return ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions["$bitmask"]);
119 return ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]);
122 // ###################################################################
124 * Runs through a given datastore item and creates a series of <select>
129 * @param string Datastore name
130 * @param string Array index for the label
131 * @param string Array index for the value
132 * @param mixed The selected value(s)
133 * @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
134 * @param bool Generate it using admin printers?
136 * @return string Unelss in admin mode, returns the constructed options
138 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
149 if ($includeblank === true OR $includeblank !== false)
151 $newval = ($inclueblank === true ? '' : $includeblank);
154 $admin->list_item('', '', ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true : false));
160 $selected = ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true : false);
161 eval('$select .= "' . $bugsys->template->fetch('selectoption
') . '";');
165 foreach ($bugsys->datastore["$datastore"] AS $item)
167 $label = $item["$labelname"];
168 $value = $item["$valuename"];
169 $selected = (($value == $selectedvalue OR (is_array($selectedvalue) AND in_array($value, $selectedvalue))) ? true : false);
173 $admin->list_item($label, $value, $selected);
177 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
187 // ################## Start construct_custom_fields ##################
188 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
193 if (!is_array($fields))
196 $fields_fetch = $bugsys->db
->query("
197 SELECT bugfield.*, permission.mask
198 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
199 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
200 ON (bugfield.fieldid = permission.fieldid)
201 WHERE (permission.mask = 2 OR permission.mask = 1)
202 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
204 while ($field = $bugsys->db
->fetch_array($fields_fetch))
206 $fields["$field[fieldid]"] = $field;
210 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT
));
212 $fieldbits = array();
214 foreach ($fields AS $field)
218 $field['defaultvalue'] = '';
221 if (!is_null($bug["field$field[fieldid]"]))
223 $bugsys->debug("not null: $field[fieldid]");
224 $value = $bug["field$field[fieldid]"];
228 $value = $field['defaultvalue'];
231 if ($ignore21mask AND $field['mask'] != 0)
236 if ($field['mask'] == 2)
238 switch ($field['type'])
241 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
244 case 'input_checkbox':
245 $selected = (($value) ? ' checked="checked"' : '');
246 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
249 case 'select_single':
250 $selects = unserialize($field['selects']);
251 $value = trim($value);
257 if (!$field['usedefault'] AND !trim($value))
259 $selected = ' selected="selected"';
265 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
267 foreach ($selects AS $id => $select)
270 $select = stripslashes(trim($select));
271 if ($select == $value)
273 $selected = ' selected="selected"';
275 else if ($field['usedefault'] AND $id == 0)
277 $selected = ' selected="selected"';
279 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
281 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
287 $bugsys->debug('mask 1 processing');
288 if (is_null($fieldvalues["field$field[fieldid]"]))
290 $bugsys->debug("is null: $field[fieldid]");
291 if ($field['type'] == 'select_single')
293 if ($field['usedefault'])
295 $temp = unserialize($field['selects']);
296 $value = trim($temp[0]);
300 $value = $fieldvalues["field$field[fieldid]"];
305 $value = $field['defaultvalue'];
310 $value = $fieldvalues["field$field[fieldid]"];
313 if ($field['type'] == 'input_checkbox')
315 $value = (($value) ? 'True' : 'False');
317 $field['value'] = $value;
318 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
320 $fieldbits[] = $tempfield;
326 // ################### Start process_custom_fields ###################
327 function process_custom_fields($bugid, $inputdata = array())
333 $inputdata =& $bugsys->in
;
336 $fields = $bugsys->db
->query("
338 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
339 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
340 ON (bugfield.fieldid = permission.fieldid)
341 WHERE permission.mask = 2
342 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
344 while ($field = $bugsys->db
->fetch_array($fields))
346 if ($field['type'] == 'input_checkbox')
348 $fieldbuild[] = 'field' . $field['fieldid'];
349 if (isset($inputdata["field$field[fieldid]"]))
360 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
362 $errorlist[] = sprintf($bugsys->lang
->string('The "%1$s" field is a required field.'), $field['name']);
366 if (isset($inputdata["field$field[fieldid]"]))
368 $fieldbuild[] = 'field' . $field['fieldid'];
370 if ($field['type'] == 'input_text')
372 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
376 if ($inputdata["field$field[fieldid]"] == -1)
378 $fieldvalue[] = "''";
382 $temp = unserialize($field['selects']);
383 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
393 if (sizeof($fieldbuild) < 1)
398 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
401 // ####################### Start fetch_on_bits #######################
402 function fetch_on_bits($mask, $userinfo = null)
406 if ($userinfo == null)
408 $userinfo =& $bugsys->userinfo
;
413 $usergroupid = $userinfo['usergroupid'];
415 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions["$mask"])
417 foreach ($bugsys->datastore
['product'] AS $id => $product)
419 if (!$product['componentmother'])
421 $onbits["$id"] = $id;
426 if (is_array($bugsys->datastore['permission']["$usergroupid"]))
428 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
430 if ($bit & $bugsys->permissions["$mask"])
432 $onbits["$productid"] = $productid;
436 if ($onbits["$productid"])
438 unset($onbits["$productid"]);
444 if (sizeof($onbits) < 1)
449 return implode(',', $onbits);
452 // #################### Start isso_pre_parse_hook ####################
453 // the pre-parse hook for ISSO's template engine
454 function isso_pre_parse_hook($template)
456 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
460 // ###################### Start fetch_help_link ######################
461 // returns a prepared link to insert into templates that opens up a
462 // help popup in the user-end
463 function fetch_help_link($topic)
467 if (isset($bugsys->datastore['help']["$topic"]))
469 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
476 return "[[INVALID TOPIC: $topic]]";
481 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
486 // ###################################################################
488 * Returns a user array of information that is specific to all visiting
489 * users (guests). This can then be passed to any function that requires
494 * @return array User information array
496 function fetch_guest_user()
506 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
507 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
511 /*=====================================================================*\
512 || ###################################################################
515 || ###################################################################
516 \*=====================================================================*/