]>
src.bluestatic.org Git - bugdar.git/blob - includes/functions.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]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['displayname
'] = $bugsys->lang->string('Guest
');
41 $userinfo['showemail
'] = false;
46 eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
50 if ($userinfo['showemail
'])
52 $username = sprintf($bugsys->lang->string('%
1$s <
;%
2$s>
;'), $userinfo['displayname
'], $userinfo['email
']);
56 $username = $userinfo['displayname
'];
63 // ######################## Start can_perform ########################
64 // short-hand for bitwise &
65 function can_perform($bitmask, $productid = 0)
67 global $bugsys, $_PERMISSION;
69 $userinfo = $bugsys->userinfo;
71 if (!isset($_PERMISSION["$bitmask"]))
73 trigger_error('Invalid bitmask
"' . $bitmask . '" specified
for can_perform() [includes
/functions
.php
]', E_USER_WARNING);
76 if ($productid AND isset($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"]))
78 $inspecific = array('cansearch
', 'canbeassignedto
', 'canadminpanel
', 'canadminbugs
', 'canadminfields
', 'canadminversions
', 'canadminusers
', 'canadmingroups
', 'canadmintools
');
80 if (!in_array($bitmask, $inspecific))
82 return ($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
86 return ($userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
89 // ################# Start construct_datastore_select ################
90 // loops through the specified datastore to create <select>s
91 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
106 $admin->list_item('', '', ((!$selectedvalue) ? true : false));
112 $selected = ((!$selectedvalue) ? true : false);
113 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
117 foreach ($bugsys->datastore["$datastore"] AS $item)
119 $label = $item["$labelname"];
120 $value = $item["$valuename"];
121 $selected = (($value == $selectedvalue) ? true : false);
125 $admin->list_item($label, $value, $selected);
129 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
139 // ################## Start construct_custom_fields ##################
140 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
145 if (!is_array($fields))
148 $fields_fetch = $bugsys->db->query("
149 SELECT bugfield.*, permission.mask
150 FROM " . TABLE_PREFIX . "bugfield AS bugfield
151 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
152 ON (bugfield.fieldid = permission.fieldid)
153 WHERE (permission.mask = 2 OR permission.mask = 1)
154 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
156 while ($field = $bugsys->db->fetch_array($fields_fetch))
158 $fields["$field[fieldid]"] = $field;
162 $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid
']));
166 foreach ($fields AS $field)
170 $field['defaultvalue
'] = '';
173 if (!is_null($bug["field$field[fieldid]"]))
175 $bugsys->debug("not null: $field[fieldid]");
176 $value = $bug["field$field[fieldid]"];
180 $value = $field['defaultvalue
'];
183 if ($ignore21mask AND $field['mask
'] != 0)
188 if ($field['mask
'] == 2)
190 switch ($field['type
'])
193 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
196 case 'input_checkbox
':
197 $selected = (($value) ? ' checked
="checked"' : '');
198 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
201 case 'select_single
':
202 $selects = unserialize($field['selects
']);
203 $value = trim($value);
209 if (!$field['usedefault
'] AND !trim($value))
211 $selected = ' selected
="selected"';
217 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
219 foreach ($selects AS $id => $select)
222 $select = stripslashes(trim($select));
223 if ($select == $value)
225 $selected = ' selected
="selected"';
227 else if ($field['usedefault
'] AND $id == 0)
229 $selected = ' selected
="selected"';
231 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
233 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
239 $bugsys->debug('mask
1 processing
');
240 if (is_null($fieldvalues["field$field[fieldid]"]))
242 $bugsys->debug("is null: $field[fieldid]");
243 if ($field['type
'] == 'select_single
')
245 if ($field['usedefault
'])
247 $temp = unserialize($field['selects
']);
248 $value = trim($temp[0]);
252 $value = $fieldvalues["field$field[fieldid]"];
257 $value = $field['defaultvalue
'];
262 $value = $fieldvalues["field$field[fieldid]"];
265 if ($field['type
'] == 'input_checkbox
')
267 $value = (($value) ? 'True' : 'False');
269 $field['value
'] = $value;
270 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
272 $fieldbits[] = $tempfield;
278 // ################### Start process_custom_fields ###################
279 function process_custom_fields($bugid, $inputdata = array())
285 $inputdata =& $bugsys->in;
288 $fields = $bugsys->db->query("
290 FROM " . TABLE_PREFIX . "bugfield AS bugfield
291 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
292 ON (bugfield.fieldid = permission.fieldid)
293 WHERE permission.mask = 2
294 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
296 while ($field = $bugsys->db->fetch_array($fields))
298 if ($field['type
'] == 'input_checkbox
')
300 $fieldbuild[] = 'field
' . $field['fieldid
'];
301 if (isset($inputdata["field$field[fieldid]"]))
312 if ($field['required
'] AND empty($inputdata["field$field[fieldid]"]))
314 $errorlist[] = sprintf($bugsys->lang->string('The
"%1$s" field is a required field.'), $field['name']);
318 if (isset($inputdata["field
$field[fieldid
]"]))
320 $fieldbuild[] = 'field' . $field['fieldid'];
322 if ($field['type'] == 'input_text')
324 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
328 if ($inputdata["field
$field[fieldid
]"] == -1)
330 $fieldvalue[] = "''";
334 $temp = unserialize($field['selects']);
335 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
345 if (count($fieldbuild) < 1)
350 $bugsys->db->query("REPLACE INTO
" . TABLE_PREFIX . "bugvaluefill (bugid
, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
353 // ####################### Start fetch_on_bits #######################
354 function fetch_on_bits($mask)
356 global $bugsys, $_PERMISSION;
360 $usergroupid = $bugsys->userinfo['usergroupid'];
362 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
364 foreach ($bugsys->datastore['product'] AS $id => $product)
366 if (!$product['componentmother'])
368 $onbits["$id"] = $id;
373 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
375 if ($bit & $_PERMISSION["$mask"])
377 $onbits["$productid"] = $productid;
381 if ($onbits["$productid"])
383 unset($onbits["$productid"]);
388 if (count($onbits) < 1)
393 return implode(',', $onbits);
396 // #################### Start isso_pre_parse_hook ####################
397 // the pre-parse hook for ISSO's template engine
398 function isso_pre_parse_hook($template)
400 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
404 // ###################### Start fetch_help_link ######################
405 // returns a prepared link to insert into templates that opens up a
406 // help popup in the user-end
407 function fetch_help_link($topic)
411 if (isset($bugsys->datastore['help']["$topic"]))
413 eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
420 return "[[INVALID TOPIC: $topic]]";
425 return eval('$temp = "' . $bugsys->template
->fetch('help_link') . '";');
430 /*=====================================================================*\
431 || ###################################################################
434 || ###################################################################
435 \*=====================================================================*/