]>
src.bluestatic.org Git - bugdar.git/blob - includes/functions.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 // ################## Start construct_option_select ##################
14 // creates a <select> menu from an array
15 // key vars are used when you need to get data out of the $label array
16 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false)
20 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
21 if ($includenil !== false)
23 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ? ' selected="selected"' : '') . '>' . $bugsys->lang
->string('Not Selected') . '</option>';
25 foreach ($array AS $value => $label)
27 $opts[] = '<option value="' . (($valuekey) ? $label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ? $label["$valuekey"] : $value)) ? ' selected
="selected"' : '') . '>' . (($labelkey) ? $label["$labelkey"] : $label) . '</option
>';
29 return '<select
class="input" name
="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
32 // ################### Start construct_user_display ##################
33 // $userinfo needs userid, email, displayname, and showemail
34 function construct_user_display($userinfo, $html = true)
38 if (!$userinfo['userid
'])
40 $userinfo['username
'] = $bugsys->lang->string('Guest
');
45 eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
49 if ($userinfo['showemail
'])
51 $username = sprintf($bugsys->lang->string('%
1$s <
;%
2$s>
;'), $userinfo['displayname
'], $userinfo['email
']);
55 $username = $userinfo['displayname
'];
62 // ######################## Start can_perform ########################
63 // short-hand for bitwise &
64 function can_perform($bitmask, $productid = 0)
66 global $bugsys, $_PERMISSION;
68 $userinfo = $bugsys->userinfo;
70 if (!isset($_PERMISSION["$bitmask"]))
72 trigger_error('Invalid bitmask
"' . $bitmask . '" specified
for can_perform() [includes
/functions
.php
]', E_USER_WARNING);
75 if ($productid AND isset($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"]))
77 $inspecific = array('cansearch
', 'canbeassignedto
', 'canadminpanel
', 'canadminbugs
', 'canadminfields
', 'canadminversions
', 'canadminusers
', 'canadmingroups
', 'canadmintools
');
79 if (!in_array($bitmask, $inspecific))
81 return ($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
85 return ($userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
88 // ################# Start construct_datastore_select ################
89 // loops through the specified datastore to create <select>s
90 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
105 $admin->list_item('', '', ((!$selectedvalue) ? true : false));
111 $selected = ((!$selectedvalue) ? true : false);
112 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
116 foreach ($bugsys->datastore["$datastore"] AS $item)
118 $label = $item["$labelname"];
119 $value = $item["$valuename"];
120 $selected = (($value == $selectedvalue) ? true : false);
124 $admin->list_item($label, $value, $selected);
128 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
138 // ################## Start construct_custom_fields ##################
139 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
144 if (!is_array($fields))
147 $fields_fetch = $bugsys->db->query("
148 SELECT bugfield.*, permission.mask
149 FROM " . TABLE_PREFIX . "bugfield AS bugfield
150 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
151 ON (bugfield.fieldid = permission.fieldid)
152 WHERE (permission.mask = 2 OR permission.mask = 1)
153 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
155 while ($field = $bugsys->db->fetch_array($fields_fetch))
157 $fields["$field[fieldid]"] = $field;
161 $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid
']));
165 foreach ($fields AS $field)
169 $field['defaultvalue
'] = '';
172 if (!is_null($bug["field$field[fieldid]"]))
174 $bugsys->debug("not null: $field[fieldid]");
175 $value = $bug["field$field[fieldid]"];
179 $value = $field['defaultvalue
'];
187 if ($field['mask
'] == 2)
189 switch ($field['type
'])
192 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
195 case 'input_checkbox
':
196 $selected = (($value) ? ' checked
="checked"' : '');
197 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
200 case 'select_single
':
201 $selects = unserialize($field['selects
']);
202 $value = trim($value);
208 if (!$field['usedefault
'] AND !trim($value))
210 $selected = ' selected
="selected"';
216 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
218 foreach ($selects AS $id => $select)
221 $select = stripslashes(trim($select));
222 if ($select == $value)
224 $selected = ' selected
="selected"';
226 else if ($field['usedefault
'] AND $id == 0)
228 $selected = ' selected
="selected"';
230 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
232 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
238 $bugsys->debug('mask
1 processing
');
239 if (is_null($fieldvalues["field$field[fieldid]"]))
241 $bugsys->debug("is null: $field[fieldid]");
242 if ($field['type
'] == 'select_single
')
244 if ($field['usedefault
'])
246 $temp = unserialize($field['selects
']);
247 $value = trim($temp[0]);
251 $value = $fieldvalues["field$field[fieldid]"];
256 $value = $field['defaultvalue
'];
261 $value = $fieldvalues["field$field[fieldid]"];
264 if ($field['type
'] == 'input_checkbox
')
266 $value = (($value) ? 'True' : 'False');
268 $field['value
'] = $value;
269 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
271 $fieldbits[] = $tempfield;
277 // ################### Start process_custom_fields ###################
278 function process_custom_fields($bugid, $inputdata = array())
284 $inputdata =& $bugsys->in;
287 $fields = $bugsys->db->query("
289 FROM " . TABLE_PREFIX . "bugfield AS bugfield
290 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
291 ON (bugfield.fieldid = permission.fieldid)
292 WHERE permission.mask = 2
293 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
295 while ($field = $bugsys->db->fetch_array($fields))
297 if ($field['type
'] == 'input_checkbox
')
299 $fieldbuild[] = 'field
' . $field['fieldid
'];
300 if (isset($inputdata["field$field[fieldid]"]))
311 if ($field['required
'] AND empty($inputdata["field$field[fieldid]"]))
313 $errorlist[] = sprintf($bugsys->lang->string('The
"%1$s" field is a required field.'), $field['name']);
317 if (isset($inputdata["field
$field[fieldid
]"]))
319 $fieldbuild[] = 'field' . $field['fieldid'];
321 if ($field['type'] == 'input_text')
323 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
327 if ($inputdata["field
$field[fieldid
]"] == -1)
329 $fieldvalue[] = "''";
333 $temp = unserialize($field['selects']);
334 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
344 if (count($fieldbuild) < 1)
349 $bugsys->db->query("REPLACE INTO
" . TABLE_PREFIX . "bugvaluefill (bugid
, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
352 // ####################### Start fetch_on_bits #######################
353 function fetch_on_bits($mask)
355 global $bugsys, $_PERMISSION;
359 $usergroupid = $bugsys->userinfo['usergroupid'];
361 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
363 foreach ($bugsys->datastore['product'] AS $id => $product)
365 if (!$product['componentmother'])
367 $onbits["$id"] = $id;
372 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
374 if ($bit & $_PERMISSION["$mask"])
376 $onbits["$productid"] = $productid;
380 if ($onbits["$productid"])
382 unset($onbits["$productid"]);
387 if (count($onbits) < 1)
392 return implode(',', $onbits);
395 // #################### Start isso_pre_parse_hook ####################
396 // the pre-parse hook for ISSO's template engine
397 function isso_pre_parse_hook($template)
399 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
403 // ###################### Start fetch_help_link ######################
404 // returns a prepared link to insert into templates that opens up a
405 // help popup in the user-end
406 function fetch_help_link($topic)
410 if (isset($bugsys->datastore['help']["$topic"]))
412 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
419 return "[[INVALID TOPIC: $topic]]";
424 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
429 /*=====================================================================*\
430 || ###################################################################
433 || ###################################################################
434 \*=====================================================================*/