]>
src.bluestatic.org Git - bugdar.git/blob - includes/functions_product.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 // #################### Start construct_pcv_select ###################
23 // constructs a product/component/version select with one go :-)
24 // NB: need to make sure we have the option to turn off just p/c selection without v
25 function construct_pcv_select($action = 'canviewbugs', $select = '', $prefix = '--')
35 foreach ($bugsys->datastore
['product'] AS $product)
37 if ($product['componentmother'])
39 $components["$product[componentmother]"]["$product[productid]"] = $product;
43 $products["$product[productid]"] = $product;
47 foreach ($bugsys->datastore
['version'] AS $version)
49 $versions["$version[productid]"]["$version[versionid]"] = $version;
52 foreach ($products AS $product)
54 if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid']))
63 $valuepfx = "p$product[productid]";
65 // construct global options
66 $OPTIONS .= construct_pcv_select_global_version($product['productid'], 0, $versions, 0, $prefix, $select);
68 // any immediate versions
69 if (is_array($versions["$product[productid]"]))
71 foreach ($versions["$product[productid]"] AS $version)
73 $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix);
78 $OPTIONS = '<option disabled="disabled"></option>';
81 // components (can't be a nested <optgroup> - it's not valid)
82 if (is_array($components["$product[productid]"]))
84 foreach ($components["$product[productid]"] AS $component)
90 $valuepfx = "p$product[productid]c$component[productid]";
92 // construct global options
93 $OPTIONS2 .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select);
96 if (is_array($versions["$component[componentmother]"]))
98 foreach ($versions["$component[componentmother]"] AS $version)
100 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
105 if (is_array($versions["$component[productid]"]))
107 foreach ($versions["$component[productid]"] AS $version)
109 $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
114 $OPTIONS .= construct_optgroup($component['title'], 1, $OPTIONS2, $prefix);
118 // add it as an optgroup
119 $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix);
125 // ############ Start construct_pcv_select_global_version ############
126 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $depth, $prefix = '', $select = '')
129 if (is_array($versions['0']))
131 foreach ($versions['0'] AS $version)
133 $global_versions_html .= construct_option($version['version'], "p{$product}c{$component}v$version[versionid]", $select, $depth, $prefix);
136 return $global_versions_html;
139 // ###################### Start construct_option #####################
140 function construct_option($title, $value, $selectmatch, $depth, $prefix)
144 $selected = ($selectmatch == $value);
146 $label = fetch_depth_mark($depth, $prefix) . ' ' . $title;
148 eval('$OPTIONS = "' . $bugsys->template
->fetch('selectoption') . '";');
152 // ##################### Start construct_optgroup ####################
153 function construct_optgroup($label, $depth, $optbits, $prefix)
157 $glabel = fetch_depth_mark($depth, $prefix) . ' ' . $label;
159 eval('$HTML = "' . $bugsys->template
->fetch('selectoptgroup') . '";');
163 // ###################### Start fetch_depth_mark #####################
164 function fetch_depth_mark($depth, $mark)
168 for ($i = 0; $i <= $depth; $i++
)
176 // ###################### Start parse_pcv_select #####################
177 function parse_pcv_select($input, $validate = false)
181 $input = trim($input);
183 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
188 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY
);
189 if (sizeof($trio) != 3)
194 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
202 // -------------------------------------------------------------------
204 $product = $bugsys->datastore
['product'][ $pcv['product'] ];
209 $version = $bugsys->datastore
['version'][ $pcv['version'] ];
215 if ($pcv['component'] == 0)
217 // not global version and version.productid != product.productid
218 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
226 $component = $bugsys->datastore
['product'][ $pcv['component'] ];
227 // component has the right mother
228 if ($component['componentmother'] == $product['productid'])
230 // version.productid != {component.productid | product.productid}
231 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
242 if (!can_perform('canviewbugs', $product['productid']))
252 /*=====================================================================*\
253 || ###################################################################
256 || ###################################################################
257 \*=====================================================================*/