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 // ################# Start construct_datastore_select ################
123 // loops through the specified datastore to create <select>s
124 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
, $adminmode = false
)
139 $admin->list_item('', '', ((!$selectedvalue) ? true
: false
));
145 $selected = ((!$selectedvalue) ? true
: false
);
146 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
150 foreach ($bugsys->datastore
["$datastore"] AS $item)
152 $label = $item["$labelname"];
153 $value = $item["$valuename"];
154 $selected = (($value == $selectedvalue) ? true
: false
);
158 $admin->list_item($label, $value, $selected);
162 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
172 // ################## Start construct_custom_fields ##################
173 function construct_custom_fields($bug = array(), $ignore21mask = false
, $nodefault = false
)
178 if (!is_array($fields))
181 $fields_fetch = $bugsys->db
->query("
182 SELECT bugfield.*, permission.mask
183 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
184 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
185 ON (bugfield.fieldid = permission.fieldid)
186 WHERE (permission.mask = 2 OR permission.mask = 1)
187 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
189 while ($field = $bugsys->db
->fetch_array($fields_fetch))
191 $fields["$field[fieldid]"] = $field;
195 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT
));
197 $fieldbits = array();
199 foreach ($fields AS $field)
203 $field['defaultvalue'] = '';
206 if (!is_null($bug["field$field[fieldid]"]))
208 $bugsys->debug("not null: $field[fieldid]");
209 $value = $bug["field$field[fieldid]"];
213 $value = $field['defaultvalue'];
216 if ($ignore21mask AND $field['mask'] != 0)
221 if ($field['mask'] == 2)
223 switch ($field['type'])
226 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
229 case 'input_checkbox':
230 $selected = (($value) ?
' checked="checked"' : '');
231 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
234 case 'select_single':
235 $selects = unserialize($field['selects']);
236 $value = trim($value);
242 if (!$field['usedefault'] AND !trim($value))
244 $selected = ' selected="selected"';
250 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
252 foreach ($selects AS $id => $select)
255 $select = stripslashes(trim($select));
256 if ($select == $value)
258 $selected = ' selected="selected"';
260 else if ($field['usedefault'] AND $id == 0)
262 $selected = ' selected="selected"';
264 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
266 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
272 $bugsys->debug('mask 1 processing');
273 if (is_null($fieldvalues["field$field[fieldid]"]))
275 $bugsys->debug("is null: $field[fieldid]");
276 if ($field['type'] == 'select_single')
278 if ($field['usedefault'])
280 $temp = unserialize($field['selects']);
281 $value = trim($temp[0]);
285 $value = $fieldvalues["field$field[fieldid]"];
290 $value = $field['defaultvalue'];
295 $value = $fieldvalues["field$field[fieldid]"];
298 if ($field['type'] == 'input_checkbox')
300 $value = (($value) ?
'True' : 'False');
302 $field['value'] = $value;
303 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
305 $fieldbits[] = $tempfield;
311 // ################### Start process_custom_fields ###################
312 function process_custom_fields($bugid, $inputdata = array())
318 $inputdata =& $bugsys->in
;
321 $fields = $bugsys->db
->query("
323 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
324 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
325 ON (bugfield.fieldid = permission.fieldid)
326 WHERE permission.mask = 2
327 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
329 while ($field = $bugsys->db
->fetch_array($fields))
331 if ($field['type'] == 'input_checkbox')
333 $fieldbuild[] = 'field' . $field['fieldid'];
334 if (isset($inputdata["field$field[fieldid]"]))
345 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
347 $errorlist[] = sprintf($bugsys->lang
->string('The "%1$s" field is a required field.'), $field['name']);
351 if (isset($inputdata["field$field[fieldid]"]))
353 $fieldbuild[] = 'field' . $field['fieldid'];
355 if ($field['type'] == 'input_text')
357 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
361 if ($inputdata["field$field[fieldid]"] == -1)
363 $fieldvalue[] = "''";
367 $temp = unserialize($field['selects']);
368 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
378 if (sizeof($fieldbuild) < 1)
383 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
386 // ####################### Start fetch_on_bits #######################
387 function fetch_on_bits($mask, $userinfo = null
)
391 if ($userinfo == null
)
393 $userinfo =& $bugsys->userinfo
;
398 $usergroupid = $userinfo['usergroupid'];
400 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions
["$mask"])
402 foreach ($bugsys->datastore
['product'] AS $id => $product)
404 if (!$product['componentmother'])
406 $onbits["$id"] = $id;
411 if (is_array($bugsys->datastore
['permission']["$usergroupid"]))
413 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
415 if ($bit & $bugsys->permissions
["$mask"])
417 $onbits["$productid"] = $productid;
421 if ($onbits["$productid"])
423 unset($onbits["$productid"]);
429 if (sizeof($onbits) < 1)
434 return implode(',', $onbits);
437 // #################### Start isso_pre_parse_hook ####################
438 // the pre-parse hook for ISSO's template engine
439 function isso_pre_parse_hook($template)
441 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
445 // ###################### Start fetch_help_link ######################
446 // returns a prepared link to insert into templates that opens up a
447 // help popup in the user-end
448 function fetch_help_link($topic)
452 if (isset($bugsys->datastore
['help']["$topic"]))
454 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
461 return "[[INVALID TOPIC: $topic]]";
466 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
471 // ###################################################################
473 * Returns a user array of information that is specific to all visiting
474 * users (guests). This can then be passed to any function that requires
479 * @return array User information array
481 function fetch_guest_user()
491 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
492 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
496 /*=====================================================================*\
497 || ###################################################################
500 || ###################################################################
501 \*=====================================================================*/