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)
18 if (!$userinfo['displayname'])
20 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
24 // ################## Start construct_option_select ##################
25 // creates a <select> menu from an array
26 // key vars are used when you need to get data out of the $label array
27 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"' : '') . '>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 name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
41 // ########################## Start datelike #########################
42 function datelike($format, $timestamp)
46 if (!$format OR $format == 'standard')
48 $format = $bugsys->options
['dateformat'];
51 return date($format, ($timestamp +
(60 * $bugsys->userinfo
['timezone'])));
54 // ################### Start construct_user_display ##################
55 // $userinfo needs userid, email, displayname, and showemail
56 function construct_user_display($userinfo, $userid = true
)
58 fetch_user_display_name($userinfo);
59 return "$userinfo[displayname]" . (($userinfo['showemail']) ?
" <$userinfo[email]>" : '') . (($userid) ?
" (userid: $userinfo[userid])" : '');
62 // ######################## Start can_perform ########################
63 // short-hand for bitwise &
64 function can_perform($bitmask, $userinfo = null
)
68 if (!isset($_PERMISSION["$bitmask"]))
70 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING
);
76 return ($bugsys->userinfo
['permissions'] & $_PERMISSION["$bitmask"]);
78 return ($userinfo['permissions'] & $_PERMISSION["bitmask"]);
81 // #################### Start construct_pcv_select ###################
82 // constructs a product/component/version select with one go :-)
83 // NB: need to make sure we have the option to turn off just p/c selection without v
84 function construct_pcv_select($select = '', $prefix = ' ')
95 $selected = ' checked="checked"';
97 $products_fetch = $bugsys->db
->query("SELECT * FROM " . TABLE_PREFIX
. "product ORDER BY displayorder ASC");
98 while ($product = $bugsys->db
->fetch_array($products_fetch))
100 if ($product['componentmother'])
102 $components["$product[componentmother]"]["$product[productid]"] = $product;
106 $products["$product[productid]"] = $product;
110 $versions_fetch = $bugsys->db
->query("SELECT * FROM " . TABLE_PREFIX
. "version ORDER BY displayorder");
111 while ($version = $bugsys->db
->fetch_array($versions_fetch))
113 $versions["$version[productid]"]["$version[versionid]"] = $version;
116 foreach ($products AS $product)
119 $valuepfx = "p$product[productid]";
120 $row['value'] = "{$valuepfx}c0v0";
121 $row['title'] = "<strong style=\"text-decoration: underline\">$product[title]</strong>";
122 $row['description'] = $product['description'];
123 $show['input'] = false
;
124 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
125 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select);
126 if (is_array($versions["$product[productid]"]))
128 foreach ($versions["$product[productid]"] AS $version)
130 $row['prefix'] = $prefix . $prefix;
131 $row['value'] = "{$valuepfx}c0v$version[versionid]";
132 $row['title'] = $version['version'];
133 $row['selected'] = (($select == $row['value']) ?
$selected : '');
134 $row['description'] = '';
135 $show['input'] = true
;
136 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
140 if (is_array($components["$product[productid]"]))
142 foreach ($components["$product[productid]"] AS $component)
144 $row['prefix'] = $prefix;
145 $valuepfx .= "c$component[productid]";
146 $row['value'] = "{$valuepfx}v0";
147 $row['selected'] = (($select == $row['value']) ?
$selected : '');
148 $row['title'] = "<span style=\"text-decoration: underline\">$component[title]</span>";
149 $row['description'] = $component['description'];
150 $show['input'] = false
;
151 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
152 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select);
153 if (is_array($versions["$component[productid]"]))
155 foreach ($versions["$component[productid]"] AS $version)
157 $show['input'] = true
;
158 $row['prefix'] = $prefix . $prefix;
159 $row['value'] = "{$valuepfx}v$version[versionid]";
160 $row['selected'] = (($select == $row['value']) ?
$selected : '');
161 $row['title'] = $version['version'];
162 $row['description'] = '';
163 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
173 // ############ Start construct_pcv_select_global_version ############
174 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
177 if (is_array($versions['0']))
179 foreach ($versions['0'] AS $version)
181 $row['prefix'] = $prefix . $prefix;
182 $row['typeselect'] = $type;
183 $row['value'] = "p{$product}c{$component}v$version[versionid]";
184 $row['selected'] = (($select == $row['value']) ?
' checked="checked"' : '');
185 $row['title'] = $version['version'];
186 $row['description'] = '';
187 $show['input'] = true
;
188 eval('$global_versions_html .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
191 return $global_versions_html;
194 // ###################### Start parse_pcv_select #####################
195 function parse_pcv_select($input, $validate = false
)
199 $input = trim($input);
202 yummy regex tests....
203 var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input));
204 var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input));
205 var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input));
206 var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input));
209 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
214 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
215 if (count($trio) != 3)
220 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
228 // -------------------------------------------------------------------
230 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
235 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
241 if ($pcv['component'] == 0)
243 // not global version and version.productid != product.productid
244 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
252 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
253 // component has the right mother
254 if ($component['componentmother'] == $product['productid'])
256 // version.productid != {component.productid | product.productid}
257 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
272 // ################# Start construct_datastore_select ################
273 // loops through the specified datastore to create <select>s
274 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
)
284 $selected = ((!$selectedvalue) ? true
: false
);
285 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
288 foreach ($bugsys->datastore
["$datastore"] AS $item)
290 $label = $item["$labelname"];
291 $value = $item["$valuename"];
292 $selected = (($value == $selectedvalue) ? true
: false
);
293 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
298 // ################## Start construct_custom_fields ##################
299 function construct_custom_fields($bug = array())
304 if (!is_array($fields))
307 $fields_fetch = $bugsys->db
->query("
309 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
310 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
311 ON (bugfield.fieldid = permission.fieldid)
312 WHERE permission.mask = 2
313 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
315 while ($field = $bugsys->db
->fetch_array($fields_fetch))
317 $fields["$field[fieldid]"] = $field;
323 foreach ($fields AS $field)
325 if (!is_null($bug["field$field[fieldid]"]))
327 $value = $bug["field$field[fieldid]"];
331 $value = $field['defaultvalue'];
334 switch ($field['type'])
337 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
340 case 'input_checkbox':
341 $selected = (($value) ?
' checked="checked"' : '');
342 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
345 case 'select_single':
346 $selects = unserialize($field['selects']);
347 $value = trim($value);
353 if (!$field['usedefault'] AND !trim($value))
355 $selected = ' selected="selected"';
361 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
363 foreach ($selects AS $id => $select)
366 $select = stripslashes(trim($select));
367 if ($select == $value)
369 $selected = ' selected="selected"';
371 else if ($field['usedefault'] AND $id == 0)
373 $selected = ' selected="selected"';
375 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
377 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
380 $fieldbits .= $tempfield;
386 // ################### Start process_custom_fields ###################
387 function process_custom_fields($bugid, $inputdata = array())
393 $inputdata =& $bugsys->in
;
396 $fields = $bugsys->db
->query("
398 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
399 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
400 ON (bugfield.fieldid = permission.fieldid)
401 WHERE permission.mask = 2
402 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
404 while ($field = $bugsys->db
->fetch_array($fields))
406 if ($field['type'] == 'input_checkbox')
408 $fieldbuild[] = 'field' . $field['fieldid'];
409 if (isset($inputdata["field$field[fieldid]"]))
420 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
422 $errorlist[] = lang
::p('field_x_is_required', $field['name']);
426 if (isset($inputdata["field$field[fieldid]"]))
428 $fieldbuild[] = 'field' . $field['fieldid'];
430 if ($field['type'] == 'input_text')
432 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
436 if ($inputdata["field$field[fieldid]"] == -1)
438 $fieldvalue[] = "''";
442 $temp = unserialize($field['selects']);
443 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
453 if (count($fieldbuild) < 1)
458 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
461 /*=====================================================================*\
462 || ###################################################################
465 || ###################################################################
466 \*=====================================================================*/