]>
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)
37 fetch_user_display_name($userinfo);
41 eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
45 if ($userinfo['showemail
'])
47 $username = sprintf($bugsys->lang->string('%
1$s <
;%
2$s>
;'), $userinfo['displayname
'], $userinfo['email
']);
51 $username = $userinfo['displayname
'];
58 // ######################## Start can_perform ########################
59 // short-hand for bitwise &
60 function can_perform($bitmask, $productid = 0)
62 global $bugsys, $_PERMISSION;
64 $userinfo = $bugsys->userinfo;
66 if (!isset($_PERMISSION["$bitmask"]))
68 trigger_error('Invalid bitmask
"' . $bitmask . '" specified
for can_perform() [includes
/functions
.php
]', E_USER_WARNING);
71 if ($productid AND isset($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"]))
73 $inspecific = array('cansearch
', 'canbeassignedto
', 'canadminpanel
', 'canadminbugs
', 'canadminfields
', 'canadminversions
', 'canadminusers
', 'canadmingroups
', 'canadmintools
');
75 if (!in_array($bitmask, $inspecific))
77 return ($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
81 return ($userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
84 // ################# Start construct_datastore_select ################
85 // loops through the specified datastore to create <select>s
86 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
101 $admin->list_item('', '', ((!$selectedvalue) ? true : false));
107 $selected = ((!$selectedvalue) ? true : false);
108 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
112 foreach ($bugsys->datastore["$datastore"] AS $item)
114 $label = $item["$labelname"];
115 $value = $item["$valuename"];
116 $selected = (($value == $selectedvalue) ? true : false);
120 $admin->list_item($label, $value, $selected);
124 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
134 // ################## Start construct_custom_fields ##################
135 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
140 if (!is_array($fields))
143 $fields_fetch = $bugsys->db->query("
144 SELECT bugfield.*, permission.mask
145 FROM " . TABLE_PREFIX . "bugfield AS bugfield
146 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
147 ON (bugfield.fieldid = permission.fieldid)
148 WHERE (permission.mask = 2 OR permission.mask = 1)
149 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
151 while ($field = $bugsys->db->fetch_array($fields_fetch))
153 $fields["$field[fieldid]"] = $field;
157 $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid
']));
161 foreach ($fields AS $field)
165 $field['defaultvalue
'] = '';
168 if (!is_null($bug["field$field[fieldid]"]))
170 $bugsys->debug("not null: $field[fieldid]");
171 $value = $bug["field$field[fieldid]"];
175 $value = $field['defaultvalue
'];
183 if ($field['mask
'] == 2)
185 switch ($field['type
'])
188 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
191 case 'input_checkbox
':
192 $selected = (($value) ? ' checked
="checked"' : '');
193 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
196 case 'select_single
':
197 $selects = unserialize($field['selects
']);
198 $value = trim($value);
204 if (!$field['usedefault
'] AND !trim($value))
206 $selected = ' selected
="selected"';
212 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
214 foreach ($selects AS $id => $select)
217 $select = stripslashes(trim($select));
218 if ($select == $value)
220 $selected = ' selected
="selected"';
222 else if ($field['usedefault
'] AND $id == 0)
224 $selected = ' selected
="selected"';
226 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
228 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
234 $bugsys->debug('mask
1 processing
');
235 if (is_null($fieldvalues["field$field[fieldid]"]))
237 $bugsys->debug("is null: $field[fieldid]");
238 if ($field['type
'] == 'select_single
')
240 if ($field['usedefault
'])
242 $temp = unserialize($field['selects
']);
243 $value = trim($temp[0]);
247 $value = $fieldvalues["field$field[fieldid]"];
252 $value = $field['defaultvalue
'];
257 $value = $fieldvalues["field$field[fieldid]"];
260 if ($field['type
'] == 'input_checkbox
')
262 $value = (($value) ? 'True' : 'False');
264 $field['value
'] = $value;
265 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
267 $fieldbits[] = $tempfield;
273 // ################### Start process_custom_fields ###################
274 function process_custom_fields($bugid, $inputdata = array())
280 $inputdata =& $bugsys->in;
283 $fields = $bugsys->db->query("
285 FROM " . TABLE_PREFIX . "bugfield AS bugfield
286 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
287 ON (bugfield.fieldid = permission.fieldid)
288 WHERE permission.mask = 2
289 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
291 while ($field = $bugsys->db->fetch_array($fields))
293 if ($field['type
'] == 'input_checkbox
')
295 $fieldbuild[] = 'field
' . $field['fieldid
'];
296 if (isset($inputdata["field$field[fieldid]"]))
307 if ($field['required
'] AND empty($inputdata["field$field[fieldid]"]))
309 $errorlist[] = sprintf($bugsys->lang->string('The
"%1$s" field is a required field.'), $field['name']);
313 if (isset($inputdata["field
$field[fieldid
]"]))
315 $fieldbuild[] = 'field' . $field['fieldid'];
317 if ($field['type'] == 'input_text')
319 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
323 if ($inputdata["field
$field[fieldid
]"] == -1)
325 $fieldvalue[] = "''";
329 $temp = unserialize($field['selects']);
330 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
340 if (count($fieldbuild) < 1)
345 $bugsys->db->query("REPLACE INTO
" . TABLE_PREFIX . "bugvaluefill (bugid
, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
348 // ####################### Start fetch_on_bits #######################
349 function fetch_on_bits($mask)
351 global $bugsys, $_PERMISSION;
355 $usergroupid = $bugsys->userinfo['usergroupid'];
357 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
359 foreach ($bugsys->datastore['product'] AS $id => $product)
361 if (!$product['componentmother'])
363 $onbits["$id"] = $id;
368 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
370 if ($bit & $_PERMISSION["$mask"])
372 $onbits["$productid"] = $productid;
376 if ($onbits["$productid"])
378 unset($onbits["$productid"]);
383 if (count($onbits) < 1)
388 return implode(',', $onbits);
391 // #################### Start isso_pre_parse_hook ####################
392 // the pre-parse hook for ISSO's template engine
393 function isso_pre_parse_hook($template)
395 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
399 // ###################### Start fetch_help_link ######################
400 // returns a prepared link to insert into templates that opens up a
401 // help popup in the user-end
402 function fetch_help_link($topic)
406 if (isset($bugsys->datastore['help']["$topic"]))
408 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
415 return "[[INVALID TOPIC: $topic]]";
420 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
425 /*=====================================================================*\
426 || ###################################################################
429 || ###################################################################
430 \*=====================================================================*/