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 // ################## Start construct_option_select ##################
23 // creates a <select> menu from an array
24 // key vars are used when you need to get data out of the $label array
25 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false
)
29 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
30 if ($includenil !== false
)
32 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ?
' selected="selected"' : '') . '>' . $bugsys->lang
->string('Not Selected') . '</option>';
34 foreach ($array AS $value => $label)
36 $opts[] = '<option value="' . (($valuekey) ?
$label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ?
$label["$valuekey"] : $value)) ?
' selected="selected"' : '') . '>' . (($labelkey) ?
$label["$labelkey"] : $label) . '</option>';
38 return '<select class="input" name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
41 // ################### Start construct_user_display ##################
42 // $userinfo needs userid, email, displayname, and showemail
43 function construct_user_display($userinfo, $html = true
)
47 if (!$userinfo['userid'])
49 $userinfo['displayname'] = $bugsys->lang
->string('Guest');
50 $userinfo['showemail'] = false
;
55 eval('$username = "' . $bugsys->template
->fetch('username_display') . '";');
59 if ($userinfo['showemail'])
61 $username = sprintf($bugsys->lang
->string('%1$s <%2$s>'), $userinfo['displayname'], $userinfo['email']);
65 $username = $userinfo['displayname'];
72 // ######################## Start can_perform ########################
73 // short-hand for bitwise &
74 function can_perform($bitmask, $productid = 0, $userinfo = null
)
78 if ($userinfo == null
)
80 $userinfo =& $bugsys->userinfo
;
83 if (!isset($bugsys->permissions
["$bitmask"]))
85 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING
);
88 if ($productid AND isset($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"]))
90 $inspecific = array('cansearch', 'canbeassignedto', 'canadminpanel', 'canadminbugs', 'canadminfields', 'canadminversions', 'canadminusers', 'canadmingroups', 'canadmintools');
92 if (!in_array($bitmask, $inspecific))
94 return ($bugsys->datastore
['permission']["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions
["$bitmask"]);
98 return ($userinfo['permissions'] & $bugsys->permissions
["$bitmask"]);
101 // ################# Start construct_datastore_select ################
102 // loops through the specified datastore to create <select>s
103 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
, $adminmode = false
)
118 $admin->list_item('', '', ((!$selectedvalue) ? true
: false
));
124 $selected = ((!$selectedvalue) ? true
: false
);
125 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
129 foreach ($bugsys->datastore
["$datastore"] AS $item)
131 $label = $item["$labelname"];
132 $value = $item["$valuename"];
133 $selected = (($value == $selectedvalue) ? true
: false
);
137 $admin->list_item($label, $value, $selected);
141 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
151 // ################## Start construct_custom_fields ##################
152 function construct_custom_fields($bug = array(), $ignore21mask = false
, $nodefault = false
)
157 if (!is_array($fields))
160 $fields_fetch = $bugsys->db
->query("
161 SELECT bugfield.*, permission.mask
162 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
163 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
164 ON (bugfield.fieldid = permission.fieldid)
165 WHERE (permission.mask = 2 OR permission.mask = 1)
166 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
168 while ($field = $bugsys->db
->fetch_array($fields_fetch))
170 $fields["$field[fieldid]"] = $field;
174 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . $bugsys->clean($bug['bugid'], TYPE_UINT
));
176 $fieldbits = array();
178 foreach ($fields AS $field)
182 $field['defaultvalue'] = '';
185 if (!is_null($bug["field$field[fieldid]"]))
187 $bugsys->debug("not null: $field[fieldid]");
188 $value = $bug["field$field[fieldid]"];
192 $value = $field['defaultvalue'];
195 if ($ignore21mask AND $field['mask'] != 0)
200 if ($field['mask'] == 2)
202 switch ($field['type'])
205 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
208 case 'input_checkbox':
209 $selected = (($value) ?
' checked="checked"' : '');
210 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
213 case 'select_single':
214 $selects = unserialize($field['selects']);
215 $value = trim($value);
221 if (!$field['usedefault'] AND !trim($value))
223 $selected = ' selected="selected"';
229 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
231 foreach ($selects AS $id => $select)
234 $select = stripslashes(trim($select));
235 if ($select == $value)
237 $selected = ' selected="selected"';
239 else if ($field['usedefault'] AND $id == 0)
241 $selected = ' selected="selected"';
243 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
245 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
251 $bugsys->debug('mask 1 processing');
252 if (is_null($fieldvalues["field$field[fieldid]"]))
254 $bugsys->debug("is null: $field[fieldid]");
255 if ($field['type'] == 'select_single')
257 if ($field['usedefault'])
259 $temp = unserialize($field['selects']);
260 $value = trim($temp[0]);
264 $value = $fieldvalues["field$field[fieldid]"];
269 $value = $field['defaultvalue'];
274 $value = $fieldvalues["field$field[fieldid]"];
277 if ($field['type'] == 'input_checkbox')
279 $value = (($value) ?
'True' : 'False');
281 $field['value'] = $value;
282 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
284 $fieldbits[] = $tempfield;
290 // ################### Start process_custom_fields ###################
291 function process_custom_fields($bugid, $inputdata = array())
297 $inputdata =& $bugsys->in
;
300 $fields = $bugsys->db
->query("
302 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
303 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
304 ON (bugfield.fieldid = permission.fieldid)
305 WHERE permission.mask = 2
306 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
308 while ($field = $bugsys->db
->fetch_array($fields))
310 if ($field['type'] == 'input_checkbox')
312 $fieldbuild[] = 'field' . $field['fieldid'];
313 if (isset($inputdata["field$field[fieldid]"]))
324 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
326 $errorlist[] = sprintf($bugsys->lang
->string('The "%1$s" field is a required field.'), $field['name']);
330 if (isset($inputdata["field$field[fieldid]"]))
332 $fieldbuild[] = 'field' . $field['fieldid'];
334 if ($field['type'] == 'input_text')
336 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
340 if ($inputdata["field$field[fieldid]"] == -1)
342 $fieldvalue[] = "''";
346 $temp = unserialize($field['selects']);
347 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
357 if (sizeof($fieldbuild) < 1)
362 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
365 // ####################### Start fetch_on_bits #######################
366 function fetch_on_bits($mask, $userinfo = null
)
370 if ($userinfo == null
)
372 $userinfo =& $bugsys->userinfo
;
377 $usergroupid = $userinfo['usergroupid'];
379 if ($bugsys->datastore
['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions
["$mask"])
381 foreach ($bugsys->datastore
['product'] AS $id => $product)
383 if (!$product['componentmother'])
385 $onbits["$id"] = $id;
390 if (is_array($bugsys->datastore
['permission']["$usergroupid"]))
392 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
394 if ($bit & $bugsys->permissions
["$mask"])
396 $onbits["$productid"] = $productid;
400 if ($onbits["$productid"])
402 unset($onbits["$productid"]);
408 if (sizeof($onbits) < 1)
413 return implode(',', $onbits);
416 // #################### Start isso_pre_parse_hook ####################
417 // the pre-parse hook for ISSO's template engine
418 function isso_pre_parse_hook($template)
420 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
424 // ###################### Start fetch_help_link ######################
425 // returns a prepared link to insert into templates that opens up a
426 // help popup in the user-end
427 function fetch_help_link($topic)
431 if (isset($bugsys->datastore
['help']["$topic"]))
433 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
440 return "[[INVALID TOPIC: $topic]]";
445 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
450 // ###################################################################
452 * Returns a user array of information that is specific to all visiting
453 * users (guests). This can then be passed to any function that requires
458 * @return array User information array
460 function fetch_guest_user()
470 'permissions' => $bugsys->datastore
['usergroup'][1]['permissions'],
471 'displaytitle' => $bugsys->datastore
['usergroup'][1]['displaytitle'],
475 /*=====================================================================*\
476 || ###################################################################
479 || ###################################################################
480 \*=====================================================================*/