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 phrase ##########################
18 $args = func_get_args();
19 $numargs = sizeof($args);
26 if ($phrasetext = $bugsys->language
["$args[0]"])
30 $phrase = $phrasetext;
34 $args[0] = $phrasetext;
35 if (($phrase = @call_user_func_array('sprintf', $args)) === false
)
37 for ($i = 1; $i < $numargs; $i++
)
39 $phrase = str_replace("%{$i}\$s", $args["$i"], $args[0]);
43 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \\1: UNDEFINED]</strong>', $phrase);
47 return "<strong>[UNDEFINED PHRASE: $args[0]]</strong>";
51 // ################## Start fetch_user_display_name ##################
52 // preps a dispaly name if one isn't set
53 // should be able to be removed by the final version as registration should set this
54 function fetch_user_display_name(&$userinfo)
56 if (!$userinfo['displayname'])
58 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
62 // ################## Start construct_option_select ##################
63 // creates a <select> menu from an array
64 // key vars are used when you need to get data out of the $label array
65 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false
)
67 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
68 if ($includenil !== false
)
70 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ?
' selected="selected"' : '') . '>Not Selected</option>';
72 foreach ($array AS $value => $label)
74 $opts[] = '<option value="' . (($valuekey) ?
$label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ?
$label["$valuekey"] : $value)) ?
' selected="selected"' : '') . '>' . (($labelkey) ?
$label["$labelkey"] : $label) . '</option>';
76 return '<select name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
79 // ########################## Start datelike #########################
80 function datelike($format, $timestamp)
84 if (!$format OR $format == 'standard')
86 $format = $bugsys->options
['dateformat'];
89 return date($format, ($timestamp +
(60 * $bugsys->userinfo
['timezone'])));
92 // ################### Start construct_user_display ##################
93 // $userinfo needs userid, email, displayname, and showemail
94 function construct_user_display($userinfo, $userid = true
)
96 fetch_user_display_name($userinfo);
97 return "$userinfo[displayname]" . (($userinfo['showemail']) ?
" <$userinfo[email]>" : '') . (($userid) ?
" (userid: $userinfo[userid])" : '');
100 // ######################## Start can_perform ########################
101 // short-hand for bitwise &
102 function can_perform($bitmask, $userinfo = null
)
106 if (!isset($_PERMISSION["$bitmask"]))
108 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING
);
114 return ($bugsys->userinfo
['permissions'] & $_PERMISSION["$bitmask"]);
116 return ($userinfo['permissions'] & $_PERMISSION["bitmask"]);
119 // #################### Start construct_pcv_select ###################
120 // constructs a product/component/version select with one go :-)
121 // NB: need to make sure we have the option to turn off just p/c selection without v
122 function construct_pcv_select($select = '', $prefix = ' ')
133 $selected = ' checked="checked"';
135 $products_fetch = $bugsys->db
->query("SELECT * FROM " . TABLE_PREFIX
. "product ORDER BY displayorder ASC");
136 while ($product = $bugsys->db
->fetch_array($products_fetch))
138 if ($product['componentmother'])
140 $components["$product[componentmother]"]["$product[productid]"] = $product;
144 $products["$product[productid]"] = $product;
148 $versions_fetch = $bugsys->db
->query("SELECT * FROM " . TABLE_PREFIX
. "version ORDER BY displayorder");
149 while ($version = $bugsys->db
->fetch_array($versions_fetch))
151 $versions["$version[productid]"]["$version[versionid]"] = $version;
154 foreach ($products AS $product)
157 $valuepfx = "p$product[productid]";
158 $row['value'] = "{$valuepfx}c0v0";
159 $row['title'] = "<strong style=\"text-decoration: underline\">$product[title]</strong>";
160 $row['description'] = $product['description'];
161 $show['input'] = false
;
162 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
163 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select);
164 if (is_array($versions["$product[productid]"]))
166 foreach ($versions["$product[productid]"] AS $version)
168 $row['prefix'] = $prefix . $prefix;
169 $row['value'] = "{$valuepfx}c0v$version[versionid]";
170 $row['title'] = $version['version'];
171 $row['selected'] = (($select == $row['value']) ?
$selected : '');
172 $row['description'] = '';
173 $show['input'] = true
;
174 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
178 if (is_array($components["$product[productid]"]))
180 foreach ($components["$product[productid]"] AS $component)
182 $row['prefix'] = $prefix;
183 $valuepfx .= "c$component[productid]";
184 $row['value'] = "{$valuepfx}v0";
185 $row['selected'] = (($select == $row['value']) ?
$selected : '');
186 $row['title'] = "<span style=\"text-decoration: underline\">$component[title]</span>";
187 $row['description'] = $component['description'];
188 $show['input'] = false
;
189 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
190 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select);
191 if (is_array($versions["$component[productid]"]))
193 foreach ($versions["$component[productid]"] AS $version)
195 $show['input'] = true
;
196 $row['prefix'] = $prefix . $prefix;
197 $row['value'] = "{$valuepfx}v$version[versionid]";
198 $row['selected'] = (($select == $row['value']) ?
$selected : '');
199 $row['title'] = $version['version'];
200 $row['description'] = '';
201 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
211 // ############ Start construct_pcv_select_global_version ############
212 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
215 if (is_array($versions['0']))
217 foreach ($versions['0'] AS $version)
219 $row['prefix'] = $prefix . $prefix;
220 $row['typeselect'] = $type;
221 $row['value'] = "p{$product}c{$component}v$version[versionid]";
222 $row['selected'] = (($select == $row['value']) ?
' checked="checked"' : '');
223 $row['title'] = $version['version'];
224 $row['description'] = '';
225 $show['input'] = true
;
226 eval('$global_versions_html .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
229 return $global_versions_html;
232 // ###################### Start parse_pcv_select #####################
233 function parse_pcv_select($input, $validate = false
)
237 $input = trim($input);
240 yummy regex tests....
241 var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input));
242 var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input));
243 var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input));
244 var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input));
247 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
252 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
253 if (count($trio) != 3)
258 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
266 // -------------------------------------------------------------------
268 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
273 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
279 if ($pcv['component'] == 0)
281 // not global version and version.productid != product.productid
282 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
290 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
291 // component has the right mother
292 if ($component['componentmother'] == $product['productid'])
294 // version.productid != {component.productid | product.productid}
295 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
310 /*=====================================================================*\
311 || ###################################################################
314 || ###################################################################
315 \*=====================================================================*/