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
)
36 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
37 if ($includenil !== false
)
39 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ?
' selected="selected"' : '') . '>' . $lang->string('Not Selected') . '</option>';
41 foreach ($array AS $value => $label)
43 $opts[] = '<option value="' . (($valuekey) ?
$label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ?
$label["$valuekey"] : $value)) ?
' selected="selected"' : '') . '>' . (($labelkey) ?
$label["$labelkey"] : $label) . '</option>';
45 return '<select name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
48 // ################### Start construct_user_display ##################
49 // $userinfo needs userid, email, displayname, and showemail
50 function construct_user_display($userinfo, $html = true
)
53 fetch_user_display_name($userinfo);
57 eval('$username = "' . $bugsys->template
->fetch('username_display') . '";');
61 if ($userinfo['showemail'])
63 $username = sprintf($bugsys->lang
->string('%1$s <%2$s>'), $userinfo['displayname'], $userinfo['email']);
67 $username = $userinfo['displayname'];
74 // ######################## Start can_perform ########################
75 // short-hand for bitwise &
76 function can_perform($bitmask, $userinfo = null
)
80 if (!isset($_PERMISSION["$bitmask"]))
82 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING
);
88 return ($bugsys->userinfo
['permissions'] & $_PERMISSION["$bitmask"]);
90 return ($userinfo['permissions'] & $_PERMISSION["bitmask"]);
93 // #################### Start construct_pcv_select ###################
94 // constructs a product/component/version select with one go :-)
95 // NB: need to make sure we have the option to turn off just p/c selection without v
96 function construct_pcv_select($select = '', $prefix = '--')
107 $selected = ' selected="selected"';
109 foreach ($bugsys->datastore
['product'] AS $product)
111 if ($product['componentmother'])
113 $components["$product[componentmother]"]["$product[productid]"] = $product;
117 $products["$product[productid]"] = $product;
121 foreach ($bugsys->datastore
['version'] AS $version)
123 $versions["$version[productid]"]["$version[versionid]"] = $version;
126 foreach ($products AS $product)
129 $valuepfx = "p$product[productid]";
130 $row['value'] = "{$valuepfx}c0v0";
131 $row['title'] = $product['title'];
132 $row['optgroup'] = true
;
133 $row['description'] = $product['description'];
134 $show['input'] = false
;
136 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
137 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select);
138 if (is_array($versions["$product[productid]"]))
140 foreach ($versions["$product[productid]"] AS $version)
142 $row['prefix'] = $prefix . $prefix . ' ';
143 $row['value'] = "{$valuepfx}c0v$version[versionid]";
144 $row['title'] = $version['version'];
145 $row['optgroup'] = false
;
146 $row['selected'] = (($select == $row['value']) ?
$selected : '');
147 $row['description'] = '';
148 $show['input'] = true
;
149 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
153 if (is_array($components["$product[productid]"]))
155 foreach ($components["$product[productid]"] AS $component)
157 $row['prefix'] = $prefix . ' ';
158 $valuepfx .= "c$component[productid]";
159 $row['value'] = "{$valuepfx}v0";
160 $row['selected'] = (($select == $row['value']) ?
$selected : '');
161 $row['title'] = $component['title'];
163 $row['optgroup'] = true
;
165 $row['description'] = $component['description'];
166 $show['input'] = false
;
167 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
168 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select);
169 if (is_array($versions["$component[productid]"]))
171 foreach ($versions["$component[productid]"] AS $version)
173 $show['input'] = true
;
174 $row['prefix'] = $prefix . $prefix . ' ';
175 $row['value'] = "{$valuepfx}v$version[versionid]";
176 $row['selected'] = (($select == $row['value']) ?
$selected : '');
177 $row['title'] = $version['version'];
178 $row['optgroup'] = false
;
179 $row['description'] = '';
180 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
184 $row['optgroup'] = true
;
186 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
188 $row['optgroup'] = true
;
190 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
196 // ############ Start construct_pcv_select_global_version ############
197 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
200 if (is_array($versions['0']))
202 foreach ($versions['0'] AS $version)
204 $row['prefix'] = $prefix . $prefix. ' ';
205 $row['typeselect'] = $type;
206 $row['value'] = "p{$product}c{$component}v$version[versionid]";
207 $row['selected'] = (($select == $row['value']) ?
' selected="selected"' : '');
208 $row['title'] = $version['version'];
209 $row['optgroup'] = false
;
210 $row['description'] = '';
211 $show['input'] = true
;
212 eval('$global_versions_html .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
215 return $global_versions_html;
218 // ###################### Start parse_pcv_select #####################
219 function parse_pcv_select($input, $validate = false
)
223 $input = trim($input);
226 yummy regex tests....
227 var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input));
228 var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input));
229 var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input));
230 var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input));
233 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
238 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
239 if (count($trio) != 3)
244 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
252 // -------------------------------------------------------------------
254 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
259 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
265 if ($pcv['component'] == 0)
267 // not global version and version.productid != product.productid
268 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
276 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
277 // component has the right mother
278 if ($component['componentmother'] == $product['productid'])
280 // version.productid != {component.productid | product.productid}
281 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
296 // ################# Start construct_datastore_select ################
297 // loops through the specified datastore to create <select>s
298 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false
, $adminmode = false
)
313 $admin->list_item('', '', ((!$selectedvalue) ? true
: false
));
319 $selected = ((!$selectedvalue) ? true
: false
);
320 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
324 foreach ($bugsys->datastore
["$datastore"] AS $item)
326 $label = $item["$labelname"];
327 $value = $item["$valuename"];
328 $selected = (($value == $selectedvalue) ? true
: false
);
332 $admin->list_item($label, $value, $selected);
336 eval('$select .= "' . $bugsys->template
->fetch('selectoption') . '";');
346 // ################## Start construct_custom_fields ##################
347 function construct_custom_fields($bug = array(), $ignore21mask = false
, $nodefault = false
)
352 if (!is_array($fields))
355 $fields_fetch = $bugsys->db
->query("
356 SELECT bugfield.*, permission.mask
357 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
358 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
359 ON (bugfield.fieldid = permission.fieldid)
360 WHERE (permission.mask = 2 OR permission.mask = 1)
361 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
363 while ($field = $bugsys->db
->fetch_array($fields_fetch))
365 $fields["$field[fieldid]"] = $field;
369 $fieldvalues = $bugsys->db
->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugvaluefill WHERE bugid = " . intval($bug['bugid']));
373 foreach ($fields AS $field)
377 $field['defaultvalue'] = '';
380 if (!is_null($bug["field$field[fieldid]"]))
382 $bugsys->debug("not null: $field[fieldid]");
383 $value = $bug["field$field[fieldid]"];
387 $value = $field['defaultvalue'];
395 if ($field['mask'] == 2)
397 switch ($field['type'])
400 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_text') . '";');
403 case 'input_checkbox':
404 $selected = (($value) ?
' checked="checked"' : '');
405 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_input_checkbox') . '";');
408 case 'select_single':
409 $selects = unserialize($field['selects']);
410 $value = trim($value);
416 if (!$field['usedefault'] AND !trim($value))
418 $selected = ' selected="selected"';
424 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
426 foreach ($selects AS $id => $select)
429 $select = stripslashes(trim($select));
430 if ($select == $value)
432 $selected = ' selected="selected"';
434 else if ($field['usedefault'] AND $id == 0)
436 $selected = ' selected="selected"';
438 eval('$options .= "' . $bugsys->template
->fetch('bugfield_select_single_option') . '";');
440 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_select_single') . '";');
446 $bugsys->debug('mask 1 processing');
447 if (is_null($fieldvalues["field$field[fieldid]"]))
449 $bugsys->debug("is null: $field[fieldid]");
450 if ($field['type'] == 'select_single')
452 if ($field['usedefault'])
454 $temp = unserialize($field['selects']);
455 $value = trim($temp[0]);
459 $value = $fieldvalues["field$field[fieldid]"];
464 $value = $field['defaultvalue'];
469 $value = $fieldvalues["field$field[fieldid]"];
472 if ($field['type'] == 'input_checkbox')
474 $value = (($value) ?
'True' : 'False');
476 $field['value'] = $value;
477 eval('$tempfield = "' . $bugsys->template
->fetch('bugfield_static_text') . '";');
479 $fieldbits[] = $tempfield;
485 // ################### Start process_custom_fields ###################
486 function process_custom_fields($bugid, $inputdata = array())
492 $inputdata =& $bugsys->in
;
495 $fields = $bugsys->db
->query("
497 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
498 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
499 ON (bugfield.fieldid = permission.fieldid)
500 WHERE permission.mask = 2
501 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
503 while ($field = $bugsys->db
->fetch_array($fields))
505 if ($field['type'] == 'input_checkbox')
507 $fieldbuild[] = 'field' . $field['fieldid'];
508 if (isset($inputdata["field$field[fieldid]"]))
519 if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
521 $errorlist[] = sprintf($bugsys->lang
->string('The field titled "%1$s" is a required field.'), $field['name']);
525 if (isset($inputdata["field$field[fieldid]"]))
527 $fieldbuild[] = 'field' . $field['fieldid'];
529 if ($field['type'] == 'input_text')
531 $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
535 if ($inputdata["field$field[fieldid]"] == -1)
537 $fieldvalue[] = "''";
541 $temp = unserialize($field['selects']);
542 $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
552 if (count($fieldbuild) < 1)
557 $bugsys->db
->query("REPLACE INTO " . TABLE_PREFIX
. "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
560 /*=====================================================================*\
561 || ###################################################################
564 || ###################################################################
565 \*=====================================================================*/