2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 // ###################################################################
24 * Constructs a massive <select> form element to create non-valid XHTML
25 * for product selection. We have to use nested <optgroup>s (invalid)
26 * because certain browsers (Safari) do not support <option disabled>,
27 * which is how I want to implement components.
29 * @param string Selection
31 * @return string A large blob of <select> HTML
33 function ConstructProductSelect($select = null
)
40 // index all of the products by parent and ID
42 foreach ($bugsys->datastore
['product'] AS $id => $prod)
44 $products["$prod[componentmother]"]["$id"] = $prod;
48 foreach ($products['0'] AS $productid => $product)
50 $build .= ConstructVersionSelect($productid, $select);
52 // these are components
53 foreach ($products["$productid"] AS $componentid => $component)
55 $build .= ConstructOptionGroup($component['title'], ConstructVersionSelect($componentid, $select));
58 $output .= ConstructOptionGroup($product['title'], $build);
65 // ###################################################################
67 * Constructs a string of HTML <option>s for a given product ID. This
68 * will always include global versions and inherited versions (if the
69 * passed ID is that of a component).
71 * @param integer Product ID
72 * @param string Selection
74 * @return string Constructed <option> HTML
76 function ConstructVersionSelect($productid, $select)
80 $product = $bugsys->datastore
['product']["$productid"];
85 // this is a component
86 if ($product['componentmother'])
88 $component = $bugsys->datastore
['product']["$productid"];
89 $product = $bugsys->datastore
['product']["$component[componentmother]"];
92 foreach ($bugsys->datastore
['version'] AS $versionid => $version)
94 if (!$version['productid'] OR $version['productid'] == $component['productid'] OR $version['productid'] == $product['productid'])
96 $value = intval($product['productid']) . ',' . intval($component['productid']) . ',' . intval($versionid);
97 $label = $version['version'];
98 $selected = ($value == $select);
99 eval('$build .= "' . $bugsys->template
->fetch('selectoption') . '";');
106 // ###################################################################
108 * Constructs an <optgroup> block from a label and a string of
109 * HTML <option> elements.
111 * @param string Label for this <optgroup>
112 * @param string HTML bits
114 * @return string Composed HTML
116 function ConstructOptionGroup($glabel, $optbits)
119 eval('$HTML = "' . $bugsys->template
->fetch('selectoptgroup') . '";');
123 // #################### Start construct_pcv_select ###################
124 // constructs a product/component/version select with one go :-)
125 // NB: need to make sure we have the option to turn off just p/c selection without v
126 function construct_pcv_select($action = 'canviewbugs', $select = '', $prefix = '--')
136 foreach ($bugsys->datastore
['product'] AS $product)
138 if ($product['componentmother'])
140 $components["$product[componentmother]"]["$product[productid]"] = $product;
144 $products["$product[productid]"] = $product;
148 foreach ($bugsys->datastore
['version'] AS $version)
150 $versions["$version[productid]"]["$version[versionid]"] = $version;
153 foreach ($products AS $product)
155 if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid']))
164 $valuepfx = "p$product[productid]";
166 // construct global options
167 $OPTIONS .= construct_pcv_select_global_version($product['productid'], 0, $versions, 0, $prefix, $select);
169 // any immediate versions
170 if (is_array($versions["$product[productid]"]))
172 foreach ($versions["$product[productid]"] AS $version)
174 $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix);
179 $OPTIONS = '<option disabled="disabled"></option>';
182 // components (can't be a nested <optgroup> - it's not valid)
183 if (is_array($components["$product[productid]"]))
185 foreach ($components["$product[productid]"] AS $component)
191 $valuepfx = "p$product[productid]c$component[productid]";
193 // construct global options
194 $OPTIONS2 .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select);
197 if (is_array($versions["$component[componentmother]"]))
199 foreach ($versions["$component[componentmother]"] AS $version)
201 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
206 if (is_array($versions["$component[productid]"]))
208 foreach ($versions["$component[productid]"] AS $version)
210 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
215 $OPTIONS .= construct_optgroup($component['title'], 1, $OPTIONS2, $prefix);
219 // add it as an optgroup
220 $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix);
226 // ############ Start construct_pcv_select_global_version ############
227 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $depth, $prefix = '', $select = '')
230 if (is_array($versions['0']))
232 foreach ($versions['0'] AS $version)
234 $global_versions_html .= construct_option($version['version'], "p{$product}c{$component}v$version[versionid]", $select, $depth, $prefix);
237 return $global_versions_html;
240 // ###################### Start construct_option #####################
241 function construct_option($title, $value, $selectmatch, $depth, $prefix)
245 $selected = ($selectmatch == $value);
247 $label = fetch_depth_mark($depth, $prefix) . ' ' . $title;
249 eval('$OPTIONS = "' . $bugsys->template
->fetch('selectoption') . '";');
253 // ##################### Start construct_optgroup ####################
254 function construct_optgroup($label, $depth, $optbits, $prefix)
258 $glabel = fetch_depth_mark($depth, $prefix) . ' ' . $label;
260 eval('$HTML = "' . $bugsys->template
->fetch('selectoptgroup') . '";');
264 // ###################### Start fetch_depth_mark #####################
265 function fetch_depth_mark($depth, $mark)
269 for ($i = 0; $i <= $depth; $i++
)
277 // ###################### Start parse_pcv_select #####################
278 function parse_pcv_select($input, $validate = false
)
282 $input = trim($input);
284 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
289 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
290 if (sizeof($trio) != 3)
295 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
303 // -------------------------------------------------------------------
305 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
310 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
316 if ($pcv['component'] == 0)
318 // not global version and version.productid != product.productid
319 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
327 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
328 // component has the right mother
329 if ($component['componentmother'] == $product['productid'])
331 // version.productid != {component.productid | product.productid}
332 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
343 if (!can_perform('canviewbugs', $product['productid']))
353 /*=====================================================================*\
354 || ###################################################################
357 || ###################################################################
358 \*=====================================================================*/