]> src.bluestatic.org Git - bugdar.git/blob - functions.php
dc30d3d51567f4b8d429c1443dc0cfd3c0e64802
[bugdar.git] / functions.php
1 <?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 \*=====================================================================*/
12
13 // ########################### Start phrase ##########################
14 function phrase()
15 {
16 global $bugsys;
17
18 $args = func_get_args();
19 $numargs = sizeof($args);
20
21 if ($numargs < 1)
22 {
23 return false;
24 }
25
26 if ($phrasetext = $bugsys->language["$args[0]"])
27 {
28 if ($numargs < 2)
29 {
30 $phrase = $phrasetext;
31 }
32 else
33 {
34 $args[0] = $phrasetext;
35 if (($phrase = @call_user_func_array('sprintf', $args)) === false)
36 {
37 for ($i = 1; $i < $numargs; $i++)
38 {
39 $phrase = str_replace("%{$i}\$s", $args["$i"], $args[0]);
40 }
41 }
42 }
43 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \\1: UNDEFINED]</strong>', $phrase);
44 }
45 else
46 {
47 return "<strong>[UNDEFINED PHRASE: $args[0]]</strong>";
48 }
49 }
50
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)
55 {
56 if (!$userinfo['displayname'])
57 {
58 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
59 }
60 }
61
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)
66 {
67 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
68 if ($includenil !== false)
69 {
70 $opts[] = '<option value="' . $includenil . '"' . ((!$selected) ? ' selected="selected"' : '') . '>Not Selected</option>';
71 }
72 foreach ($array AS $value => $label)
73 {
74 $opts[] = '<option value="' . (($valuekey) ? $label["$valuekey"] : $value) . '"' . (($selected == (($valuekey) ? $label["$valuekey"] : $value)) ? ' selected="selected"' : '') . '>' . (($labelkey) ? $label["$labelkey"] : $label) . '</option>';
75 }
76 return '<select name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
77 }
78
79 // ########################## Start datelike #########################
80 function datelike($format, $timestamp)
81 {
82 global $bugsys;
83
84 if (!$format OR $format == 'standard')
85 {
86 $format = $bugsys->options['dateformat'];
87 }
88
89 return date($format, ($timestamp + (60 * $bugsys->userinfo['timezone'])));
90 }
91
92 // ################### Start construct_user_display ##################
93 // $userinfo needs userid, email, displayname, and showemail
94 function construct_user_display($userinfo, $userid = true)
95 {
96 fetch_user_display_name($userinfo);
97 return "$userinfo[displayname]" . (($userinfo['showemail']) ? " &lt;$userinfo[email]&gt;" : '') . (($userid) ? " (userid: $userinfo[userid])" : '');
98 }
99
100 // ######################## Start can_perform ########################
101 // short-hand for bitwise &
102 function can_perform($bitmask, $userinfo = null)
103 {
104 global $_PERMISSION;
105
106 if (!isset($_PERMISSION["$bitmask"]))
107 {
108 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING);
109 }
110
111 if (!$userinfo)
112 {
113 global $bugsys;
114 return ($bugsys->userinfo['permissions'] & $_PERMISSION["$bitmask"]);
115 }
116 return ($userinfo['permissions'] & $_PERMISSION["bitmask"]);
117 }
118
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 = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')
123 {
124 global $bugsys;
125 static $HTML;
126
127 if ($HTML)
128 {
129 return $HTML;
130 }
131
132
133 $selected = ' checked="checked"';
134
135 $products_fetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
136 while ($product = $bugsys->db->fetch_array($products_fetch))
137 {
138 if ($product['componentmother'])
139 {
140 $components["$product[componentmother]"]["$product[productid]"] = $product;
141 }
142 else
143 {
144 $products["$product[productid]"] = $product;
145 }
146 }
147
148 $versions_fetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder");
149 while ($version = $bugsys->db->fetch_array($versions_fetch))
150 {
151 $versions["$version[productid]"]["$version[versionid]"] = $version;
152 }
153
154 foreach ($products AS $product)
155 {
156 $row['prefix'] = '';
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]"]))
165 {
166 foreach ($versions["$product[productid]"] AS $version)
167 {
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') . '";');
175 }
176 }
177
178 if (is_array($components["$product[productid]"]))
179 {
180 foreach ($components["$product[productid]"] AS $component)
181 {
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]"]))
192 {
193 foreach ($versions["$component[productid]"] AS $version)
194 {
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') . '";');
202 }
203 }
204 }
205 }
206 }
207
208 return $HTML;
209 }
210
211 // ############ Start construct_pcv_select_global_version ############
212 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
213 {
214 global $bugsys;
215 if (is_array($versions['0']))
216 {
217 foreach ($versions['0'] AS $version)
218 {
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') . '";');
227 }
228 }
229 return $global_versions_html;
230 }
231
232 // ###################### Start parse_pcv_select #####################
233 function parse_pcv_select($input, $validate = false)
234 {
235 global $bugsys;
236
237 $input = trim($input);
238
239 /*
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));
245 */
246
247 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
248 {
249 return false;
250 }
251
252 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY);
253 if (count($trio) != 3)
254 {
255 return false;
256 }
257
258 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
259
260 if (!$validate)
261 {
262 return $return;
263 }
264 else
265 {
266 // -------------------------------------------------------------------
267 // pcv validation
268 $product = $bugsys->datastore['product'][ $pcv['product'] ];
269 if (!$product)
270 {
271 return false;
272 }
273 $version = $bugsys->datastore['version'][ $pcv['version'] ];
274 if (!$version)
275 {
276 return false;
277 }
278 // no component
279 if ($pcv['component'] == 0)
280 {
281 // not global version and version.productid != product.productid
282 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
283 {
284 return false;
285 }
286 }
287 // using a component
288 else
289 {
290 $component = $bugsys->datastore['product'][ $pcv['component'] ];
291 // component has the right mother
292 if ($component['componentmother'] == $product['productid'])
293 {
294 // version.productid != {component.productid | product.productid}
295 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
296 {
297 return false;
298 }
299 }
300 else
301 {
302 return false;
303 }
304 }
305
306 return $pcv;
307 }
308 }
309
310 /*=====================================================================*\
311 || ###################################################################
312 || # $HeadURL$
313 || # $Id$
314 || ###################################################################
315 \*=====================================================================*/
316 ?>