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>$product[title]</strong>";
160 $row['description'] = '';
161 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
162 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select);
163 if (is_array($versions["$product[productid]"]))
165 foreach ($versions["$product[productid]"] AS $version)
167 $row['prefix'] = $prefix . $prefix;
168 $row['value'] = "{$valuepfx}c0v$version[versionid]";
169 $row['title'] = $version['version'];
170 $row['selected'] = (($select == $row['value']) ?
$selected : '');
171 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
175 if (is_array($components["$product[productid]"]))
177 foreach ($components["$product[productid]"] AS $component)
179 $row['prefix'] = $prefix;
180 $valuepfx .= "c$component[productid]";
181 $row['value'] = "{$valuepfx}v0";
182 $row['selected'] = (($select == $row['value']) ?
$selected : '');
183 $row['title'] = $component['title'];
184 $row['description'] = '';
185 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
186 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select);
187 if (is_array($versions["$component[productid]"]))
189 foreach ($versions["$component[productid]"] AS $version)
191 $row['prefix'] = $prefix . $prefix;
192 $row['value'] = "{$valuepfx}v$version[versionid]";
193 $row['selected'] = (($select == $row['value']) ?
$selected : '');
194 $row['title'] = $version['version'];
195 $row['description'] = '';
196 eval('$HTML .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
206 // ############ Start construct_pcv_select_global_version ############
207 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
210 if (is_array($versions['0']))
212 foreach ($versions['0'] AS $version)
214 $row['prefix'] = $prefix . $prefix;
215 $row['typeselect'] = $type;
216 $row['value'] = "p{$product}c{$component}v$version[versionid]";
217 $row['selected'] = (($select == $row['value']) ?
' checked="checked"' : '');
218 $row['title'] = $version['version'];
219 $row['description'] = '';
220 eval('$global_versions_html .= "' . $bugsys->template
->fetch('pcv_select_row') . '";');
223 return $global_versions_html;
226 // ###################### Start parse_pcv_select #####################
227 function parse_pcv_select($input, $validate = false
)
231 $input = trim($input);
234 yummy regex tests....
235 var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input));
236 var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input));
237 var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input));
238 var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input));
241 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
246 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
247 if (count($trio) != 3)
252 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
260 // -------------------------------------------------------------------
262 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
267 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
273 if ($pcv['component'] == 0)
275 // not global version and version.productid != product.productid
276 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
284 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
285 // component has the right mother
286 if ($component['componentmother'] == $product['productid'])
288 // version.productid != {component.productid | product.productid}
289 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
304 // ######################### Start log_action ########################
305 function log_action($bugid, $language, $arguments, $original = array(), $changed = array())
310 INSERT INTO " . TABLE_PREFIX
. "history
311 (bugid, dateline, userid, language, arguments, original, changed)
313 (" . intval($bugid) . ", " . time() . ", " . $bugsys->userinfo
['userid'] . ",
314 '" . $bugsys->escape($language) . "', '" . $bugsys->escape(serialize($arguments)) . "',
315 '" . $bugsys->escape(serialize($original)) . "', '" . $bugsys->escape(serialize($changed)) . "'
320 /*=====================================================================*\
321 || ###################################################################
324 || ###################################################################
325 \*=====================================================================*/