]>
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 fetch_user_display_name ##################
14 // preps a dispaly name if one isn't set
15 // should be able to be removed by the final version as registration should set this
16 function fetch_user_display_name(&$userinfo)
20 if (!$userinfo['displayname'])
22 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
25 if (!$userinfo['userid'])
27 $userinfo['displayname'] = $bugsys->lang
->string('Guest');
31 // ################## Start construct_option_select ##################
32 // creates a <select> menu from an array
33 // key vars are used when you need to get data out of the $label array
34 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false)
38 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
39 if ($includenil !== false)
41 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ? ' selected="selected"' : '') . '>' . $bugsys->lang
->string('Not Selected') . '</option>';
43 foreach ($array AS $value => $label)
45 $opts[] = '<option value="' . (($valuekey) ? $label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ? $label["$valuekey"] : $value)) ? ' selected
="selected"' : '') . '>' . (($labelkey) ? $label["$labelkey"] : $label) . '</option
>';
47 return '<select
class="input" name
="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
50 // ################### Start construct_user_display ##################
51 // $userinfo needs userid, email, displayname, and showemail
52 function construct_user_display($userinfo, $html = true)
55 fetch_user_display_name($userinfo);
59 eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
63 if ($userinfo['showemail
'])
65 $username = sprintf($bugsys->lang->string('%
1$s <
;%
2$s>
;'), $userinfo['displayname
'], $userinfo['email
']);
69 $username = $userinfo['displayname
'];
76 // ######################## Start can_perform ########################
77 // short-hand for bitwise &
78 function can_perform($bitmask, $productid = 0)
80 global $bugsys, $_PERMISSION;
82 $userinfo = $bugsys->userinfo;
84 if (!isset($_PERMISSION["$bitmask"]))
86 trigger_error('Invalid bitmask
"' . $bitmask . '" specified
for can_perform() [includes
/functions
.php
]', E_USER_WARNING);
89 if ($productid AND isset($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"]))
91 $inspecific = array('cansearch
', 'canbeassignedto
', 'canadminpanel
', 'canadminbugs
', 'canadminfields
', 'canadminversions
', 'canadminusers
', 'canadmingroups
', 'canadmintools
');
93 if (!in_array($bitmask, $inspecific))
95 return ($bugsys->datastore['permission
']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
99 return ($userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
102 // ################# Start construct_datastore_select ################
103 // loops through the specified datastore to create <select>s
104 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
119 $admin->list_item('', '', ((!$selectedvalue) ? true : false));
125 $selected = ((!$selectedvalue) ? true : false);
126 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
130 foreach ($bugsys->datastore["$datastore"] AS $item)
132 $label = $item["$labelname"];
133 $value = $item["$valuename"];
134 $selected = (($value == $selectedvalue) ? true : false);
138 $admin->list_item($label, $value, $selected);
142 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
152 // ################## Start construct_custom_fields ##################
153 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
158 if (!is_array($fields))
161 $fields_fetch = $bugsys->db->query("
162 SELECT bugfield.*, permission.mask
163 FROM " . TABLE_PREFIX . "bugfield AS bugfield
164 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
165 ON (bugfield.fieldid = permission.fieldid)
166 WHERE (permission.mask = 2 OR permission.mask = 1)
167 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
169 while ($field = $bugsys->db->fetch_array($fields_fetch))
171 $fields["$field[fieldid]"] = $field;
175 $fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid
']));
179 foreach ($fields AS $field)
183 $field['defaultvalue
'] = '';
186 if (!is_null($bug["field$field[fieldid]"]))
188 $bugsys->debug("not null: $field[fieldid]");
189 $value = $bug["field$field[fieldid]"];
193 $value = $field['defaultvalue
'];
201 if ($field['mask
'] == 2)
203 switch ($field['type
'])
206 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
209 case 'input_checkbox
':
210 $selected = (($value) ? ' checked
="checked"' : '');
211 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
214 case 'select_single
':
215 $selects = unserialize($field['selects
']);
216 $value = trim($value);
222 if (!$field['usedefault
'] AND !trim($value))
224 $selected = ' selected
="selected"';
230 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
232 foreach ($selects AS $id => $select)
235 $select = stripslashes(trim($select));
236 if ($select == $value)
238 $selected = ' selected
="selected"';
240 else if ($field['usedefault
'] AND $id == 0)
242 $selected = ' selected
="selected"';
244 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
246 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
252 $bugsys->debug('mask
1 processing
');
253 if (is_null($fieldvalues["field$field[fieldid]"]))
255 $bugsys->debug("is null: $field[fieldid]");
256 if ($field['type
'] == 'select_single
')
258 if ($field['usedefault
'])
260 $temp = unserialize($field['selects
']);
261 $value = trim($temp[0]);
265 $value = $fieldvalues["field$field[fieldid]"];
270 $value = $field['defaultvalue
'];
275 $value = $fieldvalues["field$field[fieldid]"];
278 if ($field['type
'] == 'input_checkbox
')
280 $value = (($value) ? 'True' : 'False');
282 $field['value
'] = $value;
283 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
285 $fieldbits[] = $tempfield;
291 // ################### Start process_custom_fields ###################
292 function process_custom_fields($bugid, $inputdata = array())
298 $inputdata =& $bugsys->in;
301 $fields = $bugsys->db->query("
303 FROM " . TABLE_PREFIX . "bugfield AS bugfield
304 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
305 ON (bugfield.fieldid = permission.fieldid)
306 WHERE permission.mask = 2
307 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
309 while ($field = $bugsys->db->fetch_array($fields))
311 if ($field['type
'] == 'input_checkbox
')
313 $fieldbuild[] = 'field
' . $field['fieldid
'];
314 if (isset($inputdata["field$field[fieldid]"]))
325 if ($field['required
'] AND empty($inputdata["field$field[fieldid]"]))
327 $errorlist[] = sprintf($bugsys->lang->string('The field titled
"%1$s" is a required field.'), $field['name']);
331 if (isset($inputdata["field
$field[fieldid
]"]))
333 $fieldbuild[] = 'field' . $field['fieldid'];
335 if ($field['type'] == 'input_text')
337 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
341 if ($inputdata["field
$field[fieldid
]"] == -1)
343 $fieldvalue[] = "''";
347 $temp = unserialize($field['selects']);
348 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
358 if (count($fieldbuild) < 1)
363 $bugsys->db->query("REPLACE INTO
" . TABLE_PREFIX . "bugvaluefill (bugid
, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
366 // ####################### Start fetch_on_bits #######################
367 function fetch_on_bits($mask)
369 global $bugsys, $_PERMISSION;
373 $usergroupid = $bugsys->userinfo['usergroupid'];
375 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
377 foreach ($bugsys->datastore['product'] AS $id => $product)
379 if (!$product['componentmother'])
381 $onbits["$id"] = $id;
386 foreach ($bugsys->datastore
['permission']["$usergroupid"] AS $productid => $bit)
388 if ($bit & $_PERMISSION["$mask"])
390 $onbits["$productid"] = $productid;
394 if ($onbits["$productid"])
396 unset($onbits["$productid"]);
401 if (count($onbits) < 1)
406 return implode(',', $onbits);
409 /*=====================================================================*\
410 || ###################################################################
413 || ###################################################################
414 \*=====================================================================*/