]>
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 // ################## 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)
76 global $bugsys, $_PERMISSION;
78 $userinfo = $bugsys->userinfo;
80 if (!isset($_PERMISSION["$bitmask"]))
82 trigger_error('Invalid bitmask
"' . $bitmask . '" specified
for can_perform() [includes
/functions
.php
]', E_USER_WARNING);
85 if ($productid AND isset($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"]))
87 $inspecific = array('cansearch
', 'canbeassignedto
', 'canadminpanel
', 'canadminbugs
', 'canadminfields
', 'canadminversions
', 'canadminusers
', 'canadmingroups
', 'canadmintools
');
89 if (!in_array($bitmask, $inspecific))
91 return ($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
95 return ($userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
98 // ################# Start construct_datastore_select ################
99 // loops through the specified datastore to create <select>s
100 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
115 $admin->list_item('', '', ((!$selectedvalue) ? true : false));
121 $selected = ((!$selectedvalue) ? true : false);
122 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
126 foreach ($bugsys->datastore["$datastore"] AS $item)
128 $label = $item["$labelname"];
129 $value = $item["$valuename"];
130 $selected = (($value == $selectedvalue) ? true : false);
134 $admin->list_item($label, $value, $selected);
138 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
148 // ################## Start construct_custom_fields ##################
149 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
154 if (!is_array($fields))
157 $fields_fetch = $bugsys->db->query("
158 SELECT bugfield.*, permission.mask
159 FROM " . TABLE_PREFIX . "bugfield AS bugfield
160 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
161 ON (bugfield.fieldid = permission.fieldid)
162 WHERE (permission.mask = 2 OR permission.mask = 1)
163 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
165 while ($field = $bugsys->db->fetch_array($fields_fetch))
167 $fields["$field[fieldid]"] = $field;
171 $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid
']));
175 foreach ($fields AS $field)
179 $field['defaultvalue
'] = '';
182 if (!is_null($bug["field$field[fieldid]"]))
184 $bugsys->debug("not null: $field[fieldid]");
185 $value = $bug["field$field[fieldid]"];
189 $value = $field['defaultvalue
'];
192 if ($ignore21mask AND $field['mask
'] != 0)
197 if ($field['mask
'] == 2)
199 switch ($field['type
'])
202 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
205 case 'input_checkbox
':
206 $selected = (($value) ? ' checked
="checked"' : '');
207 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
210 case 'select_single
':
211 $selects = unserialize($field['selects
']);
212 $value = trim($value);
218 if (!$field['usedefault
'] AND !trim($value))
220 $selected = ' selected
="selected"';
226 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
228 foreach ($selects AS $id => $select)
231 $select = stripslashes(trim($select));
232 if ($select == $value)
234 $selected = ' selected
="selected"';
236 else if ($field['usedefault
'] AND $id == 0)
238 $selected = ' selected
="selected"';
240 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
242 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
248 $bugsys->debug('mask
1 processing
');
249 if (is_null($fieldvalues["field$field[fieldid]"]))
251 $bugsys->debug("is null: $field[fieldid]");
252 if ($field['type
'] == 'select_single
')
254 if ($field['usedefault
'])
256 $temp = unserialize($field['selects
']);
257 $value = trim($temp[0]);
261 $value = $fieldvalues["field$field[fieldid]"];
266 $value = $field['defaultvalue
'];
271 $value = $fieldvalues["field$field[fieldid]"];
274 if ($field['type
'] == 'input_checkbox
')
276 $value = (($value) ? 'True' : 'False');
278 $field['value
'] = $value;
279 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
281 $fieldbits[] = $tempfield;
287 // ################### Start process_custom_fields ###################
288 function process_custom_fields($bugid, $inputdata = array())
294 $inputdata =& $bugsys->in;
297 $fields = $bugsys->db->query("
299 FROM " . TABLE_PREFIX . "bugfield AS bugfield
300 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
301 ON (bugfield.fieldid = permission.fieldid)
302 WHERE permission.mask = 2
303 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
305 while ($field = $bugsys->db->fetch_array($fields))
307 if ($field['type
'] == 'input_checkbox
')
309 $fieldbuild[] = 'field
' . $field['fieldid
'];
310 if (isset($inputdata["field$field[fieldid]"]))
321 if ($field['required
'] AND empty($inputdata["field$field[fieldid]"]))
323 $errorlist[] = sprintf($bugsys->lang->string('The
"%1$s" field is a required field.'), $field['name']);
327 if (isset($inputdata["field
$field[fieldid
]"]))
329 $fieldbuild[] = 'field' . $field['fieldid'];
331 if ($field['type'] == 'input_text')
333 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
337 if ($inputdata["field
$field[fieldid
]"] == -1)
339 $fieldvalue[] = "''";
343 $temp = unserialize($field['selects']);
344 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
354 if (count($fieldbuild) < 1)
359 $bugsys->db->query("REPLACE INTO
" . TABLE_PREFIX . "bugvaluefill (bugid
, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
362 // ####################### Start fetch_on_bits #######################
363 function fetch_on_bits($mask)
365 global $bugsys, $_PERMISSION;
369 $usergroupid = $bugsys->userinfo['usergroupid'];
371 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
373 foreach ($bugsys->datastore['product'] AS $id => $product)
375 if (!$product['componentmother'])
377 $onbits["$id"] = $id;
382 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
384 if ($bit & $_PERMISSION["$mask"])
386 $onbits["$productid"] = $productid;
390 if ($onbits["$productid"])
392 unset($onbits["$productid"]);
397 if (count($onbits) < 1)
402 return implode(',', $onbits);
405 // #################### Start isso_pre_parse_hook ####################
406 // the pre-parse hook for ISSO's template engine
407 function isso_pre_parse_hook($template)
409 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
413 // ###################### Start fetch_help_link ######################
414 // returns a prepared link to insert into templates that opens up a
415 // help popup in the user-end
416 function fetch_help_link($topic)
420 if (isset($bugsys->datastore['help']["$topic"]))
422 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
429 return "[[INVALID TOPIC: $topic]]";
434 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
439 /*=====================================================================*\
440 || ###################################################################
443 || ###################################################################
444 \*=====================================================================*/