2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]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 construct_pcv_select ###################
14 // constructs a product/component/version select with one go :-)
15 // NB: need to make sure we have the option to turn off just p/c selection without v
16 function construct_pcv_select($action = 'canviewbugs', $select = '', $prefix = '--')
26 foreach ($bugsys->datastore
['product'] AS $product)
28 if ($product['componentmother'])
30 $components["$product[componentmother]"]["$product[productid]"] = $product;
34 $products["$product[productid]"] = $product;
38 foreach ($bugsys->datastore
['version'] AS $version)
40 $versions["$version[productid]"]["$version[versionid]"] = $version;
43 foreach ($products AS $product)
45 if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid']))
54 $valuepfx = "p$product[productid]";
56 // construct global options
57 $OPTIONS .= construct_pcv_select_global_version($product['productid'], 0, $versions, 0, $prefix, $select);
59 // any immediate versions
60 if (is_array($versions["$product[productid]"]))
62 foreach ($versions["$product[productid]"] AS $version)
64 $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix);
69 $OPTIONS = '<option disabled="disabled"></option>';
72 // components (can't be a nested <optgroup> - it's not valid)
73 if (is_array($components["$product[productid]"]))
75 foreach ($components["$product[productid]"] AS $component)
81 $valuepfx = "p$product[productid]c$component[productid]";
83 // construct global options
84 $OPTIONS2 .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select);
87 if (is_array($versions["$component[componentmother]"]))
89 foreach ($versions["$component[componentmother]"] AS $version)
91 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
96 if (is_array($versions["$component[productid]"]))
98 foreach ($versions["$component[productid]"] AS $version)
100 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
105 $OPTIONS .= construct_optgroup($component['title'], 1, $OPTIONS2, $prefix);
109 // add it as an optgroup
110 $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix);
116 // ############ Start construct_pcv_select_global_version ############
117 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $depth, $prefix = '', $select = '')
120 if (is_array($versions['0']))
122 foreach ($versions['0'] AS $version)
124 $global_versions_html .= construct_option($version['version'], "p{$product}c{$component}v$version[versionid]", $select, $depth, $prefix);
127 return $global_versions_html;
130 // ###################### Start construct_option #####################
131 function construct_option($title, $value, $selectmatch, $depth, $prefix)
135 $selected = ($selectmatch == $value);
137 $label = fetch_depth_mark($depth, $prefix) . ' ' . $title;
139 eval('$OPTIONS = "' . $bugsys->template
->fetch('selectoption') . '";');
143 // ##################### Start construct_optgroup ####################
144 function construct_optgroup($label, $depth, $optbits, $prefix)
148 $glabel = fetch_depth_mark($depth, $prefix) . ' ' . $label;
150 eval('$HTML = "' . $bugsys->template
->fetch('selectoptgroup') . '";');
154 // ###################### Start fetch_depth_mark #####################
155 function fetch_depth_mark($depth, $mark)
159 for ($i = 0; $i <= $depth; $i++
)
167 // ###################### Start parse_pcv_select #####################
168 function parse_pcv_select($input, $validate = false
)
172 $input = trim($input);
174 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
179 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
180 if (count($trio) != 3)
185 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
193 // -------------------------------------------------------------------
195 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
200 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
206 if ($pcv['component'] == 0)
208 // not global version and version.productid != product.productid
209 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
217 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
218 // component has the right mother
219 if ($component['componentmother'] == $product['productid'])
221 // version.productid != {component.productid | product.productid}
222 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
233 if (!can_perform('canviewbugs', $product['productid']))
243 /*=====================================================================*\
244 || ###################################################################
247 || ###################################################################
248 \*=====================================================================*/