r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / includes / functions_product.php
1 <?php
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 \*=====================================================================*/
12
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 = '--')
17 {
18 global $bugsys;
19 static $HTML;
20
21 if ($HTML)
22 {
23 return $HTML;
24 }
25
26
27 foreach ($bugsys->datastore['product'] AS $product)
28 {
29 if ($product['componentmother'])
30 {
31 $components["$product[componentmother]"]["$product[productid]"] = $product;
32 }
33 else
34 {
35 $products["$product[productid]"] = $product;
36 }
37 }
38
39 foreach ($bugsys->datastore['version'] AS $version)
40 {
41 $versions["$version[productid]"]["$version[versionid]"] = $version;
42 }
43
44 foreach ($products AS $product)
45 {
46 if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid']))
47 {
48 continue;
49 }
50
51 // prefix
52 $valuepfx = "p$product[productid]";
53
54 // construct global options
55 $OPTIONS .= construct_pcv_select_global_version($product['productid'], 0, $versions, 0, $prefix, $select);
56
57 // any immediate versions
58 if (is_array($versions["$product[productid]"]))
59 {
60 foreach ($versions["$product[productid]"] AS $version)
61 {
62 $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix);
63 }
64 }
65
66 // add it as an optgroup
67 $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix);
68 $OPTIONS = '';
69
70 // components (can't be a nested <optgroup> - it's not valid)
71 if (is_array($components["$product[productid]"]))
72 {
73 foreach ($components["$product[productid]"] AS $component)
74 {
75 // prefix
76 $valuepfx .= "c$component[productid]";
77
78 // construct global options
79 $OPTIONS .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select);
80
81 // product versions
82 if (is_array($versions["$component[componentmother]"]))
83 {
84 foreach ($versions["$component[componentmother]"] AS $version)
85 {
86 $OPTIONS .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
87 }
88 }
89
90 // versions
91 if (is_array($versions["$component[productid]"]))
92 {
93 foreach ($versions["$component[productid]"] AS $version)
94 {
95 $OPTIONS .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix);
96 }
97 }
98
99 // add optgroup
100 $HTML .= construct_optgroup($component['title'], 1, $OPTIONS, $prefix);
101 $OPTIONS = '';
102 }
103 }
104 }
105
106 return $HTML;
107 }
108
109 // ############ Start construct_pcv_select_global_version ############
110 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $depth, $prefix = '', $select = '')
111 {
112 global $bugsys;
113 if (is_array($versions['0']))
114 {
115 foreach ($versions['0'] AS $version)
116 {
117 $global_versions_html .= construct_option($version['version'], "p{$product}c{$component}v$version[versionid]", $select, $depth, $prefix);
118 }
119 }
120 return $global_versions_html;
121 }
122
123 // ###################### Start construct_option #####################
124 function construct_option($title, $value, $selectmatch, $depth, $prefix)
125 {
126 global $bugsys;
127
128 $selected = ($selectmatch == $value);
129
130 $label = fetch_depth_mark($depth, $prefix) . ' ' . $title;
131
132 eval('$OPTIONS = "' . $bugsys->template->fetch('selectoption') . '";');
133 return $OPTIONS;
134 }
135
136 // ##################### Start construct_optgroup ####################
137 function construct_optgroup($label, $depth, $optbits, $prefix)
138 {
139 global $bugsys;
140
141 $glabel = fetch_depth_mark($depth, $prefix) . ' ' . $label;
142
143 eval('$HTML = "' . $bugsys->template->fetch('selectoptgroup') . '";');
144 return $HTML;
145 }
146
147 // ###################### Start fetch_depth_mark #####################
148 function fetch_depth_mark($depth, $mark)
149 {
150 $string = '';
151
152 for ($i = 0; $i <= $depth; $i++)
153 {
154 $string .= $mark;
155 }
156
157 return $string;
158 }
159
160 // ###################### Start parse_pcv_select #####################
161 function parse_pcv_select($input, $validate = false)
162 {
163 global $bugsys;
164
165 $input = trim($input);
166
167 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
168 {
169 return false;
170 }
171
172 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY);
173 if (count($trio) != 3)
174 {
175 return false;
176 }
177
178 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
179
180 if (!$validate)
181 {
182 return $return;
183 }
184 else
185 {
186 // -------------------------------------------------------------------
187 // pcv validation
188 $product = $bugsys->datastore['product'][ $pcv['product'] ];
189 if (!$product)
190 {
191 return false;
192 }
193 $version = $bugsys->datastore['version'][ $pcv['version'] ];
194 if (!$version)
195 {
196 return false;
197 }
198 // no component
199 if ($pcv['component'] == 0)
200 {
201 // not global version and version.productid != product.productid
202 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
203 {
204 return false;
205 }
206 }
207 // using a component
208 else
209 {
210 $component = $bugsys->datastore['product'][ $pcv['component'] ];
211 // component has the right mother
212 if ($component['componentmother'] == $product['productid'])
213 {
214 // version.productid != {component.productid | product.productid}
215 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
216 {
217 return false;
218 }
219 }
220 else
221 {
222 return false;
223 }
224 }
225
226 if (!can_perform('canviewbugs', $product['productid']))
227 {
228 return false;
229 }
230
231 return $pcv;
232 }
233 }
234
235
236 /*=====================================================================*\
237 || ###################################################################
238 || # $HeadURL$
239 || # $Id$
240 || ###################################################################
241 \*=====================================================================*/
242 ?>