r518: Splitting out the pcv functions to be in their own file
[bugdar.git] / includes / functions_product.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 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($select = '', $prefix = '--')
17 {
18 global $bugsys;
19 static $HTML;
20
21 if ($HTML)
22 {
23 return $HTML;
24 }
25
26
27 $selected = ' selected="selected"';
28
29 foreach ($bugsys->datastore['product'] AS $product)
30 {
31 if ($product['componentmother'])
32 {
33 $components["$product[componentmother]"]["$product[productid]"] = $product;
34 }
35 else
36 {
37 $products["$product[productid]"] = $product;
38 }
39 }
40
41 foreach ($bugsys->datastore['version'] AS $version)
42 {
43 $versions["$version[productid]"]["$version[versionid]"] = $version;
44 }
45
46 foreach ($products AS $product)
47 {
48 $row['prefix'] = '';
49 $valuepfx = "p$product[productid]";
50 $row['value'] = "{$valuepfx}c0v0";
51 $row['title'] = $product['title'];
52 $row['optgroup'] = true;
53 $row['description'] = $product['description'];
54 $show['input'] = false;
55 $begin = true;
56 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
57 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select);
58 if (is_array($versions["$product[productid]"]))
59 {
60 foreach ($versions["$product[productid]"] AS $version)
61 {
62 $row['prefix'] = $prefix . $prefix . ' ';
63 $row['value'] = "{$valuepfx}c0v$version[versionid]";
64 $row['title'] = $version['version'];
65 $row['optgroup'] = false;
66 $row['selected'] = (($select == $row['value']) ? $selected : '');
67 $row['description'] = '';
68 $show['input'] = true;
69 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
70 }
71 }
72
73 if (is_array($components["$product[productid]"]))
74 {
75 foreach ($components["$product[productid]"] AS $component)
76 {
77 $row['prefix'] = $prefix . ' ';
78 $valuepfx .= "c$component[productid]";
79 $row['value'] = "{$valuepfx}v0";
80 $row['selected'] = (($select == $row['value']) ? $selected : '');
81 $row['title'] = $component['title'];
82 $row['depth'] = 1;
83 $row['optgroup'] = true;
84 $begin = true;
85 $row['description'] = $component['description'];
86 $show['input'] = false;
87 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
88 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select);
89 if (is_array($versions["$component[productid]"]))
90 {
91 foreach ($versions["$component[productid]"] AS $version)
92 {
93 $show['input'] = true;
94 $row['prefix'] = $prefix . $prefix . ' ';
95 $row['value'] = "{$valuepfx}v$version[versionid]";
96 $row['selected'] = (($select == $row['value']) ? $selected : '');
97 $row['title'] = $version['version'];
98 $row['optgroup'] = false;
99 $row['description'] = '';
100 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
101 }
102 }
103 }
104 $row['optgroup'] = true;
105 $begin = false;
106 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
107 }
108 $row['optgroup'] = true;
109 $begin = false;
110 eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
111 }
112
113 return $HTML;
114 }
115
116 // ############ Start construct_pcv_select_global_version ############
117 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '')
118 {
119 global $bugsys;
120 if (is_array($versions['0']))
121 {
122 foreach ($versions['0'] AS $version)
123 {
124 $row['prefix'] = $prefix . $prefix. ' ';
125 $row['typeselect'] = $type;
126 $row['value'] = "p{$product}c{$component}v$version[versionid]";
127 $row['selected'] = (($select == $row['value']) ? ' selected="selected"' : '');
128 $row['title'] = $version['version'];
129 $row['optgroup'] = false;
130 $row['description'] = '';
131 $show['input'] = true;
132 eval('$global_versions_html .= "' . $bugsys->template->fetch('pcv_select_row') . '";');
133 }
134 }
135 return $global_versions_html;
136 }
137
138 // ###################### Start parse_pcv_select #####################
139 function parse_pcv_select($input, $validate = false)
140 {
141 global $bugsys;
142
143 $input = trim($input);
144
145 /*
146 yummy regex tests....
147 var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input));
148 var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input));
149 var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input));
150 var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input));
151 */
152
153 if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0)
154 {
155 return false;
156 }
157
158 $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY);
159 if (count($trio) != 3)
160 {
161 return false;
162 }
163
164 $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2]));
165
166 if (!$validate)
167 {
168 return $return;
169 }
170 else
171 {
172 // -------------------------------------------------------------------
173 // pcv validation
174 $product = $bugsys->datastore['product'][ $pcv['product'] ];
175 if (!$product)
176 {
177 return false;
178 }
179 $version = $bugsys->datastore['version'][ $pcv['version'] ];
180 if (!$version)
181 {
182 return false;
183 }
184 // no component
185 if ($pcv['component'] == 0)
186 {
187 // not global version and version.productid != product.productid
188 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
189 {
190 return false;
191 }
192 }
193 // using a component
194 else
195 {
196 $component = $bugsys->datastore['product'][ $pcv['component'] ];
197 // component has the right mother
198 if ($component['componentmother'] == $product['productid'])
199 {
200 // version.productid != {component.productid | product.productid}
201 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
202 {
203 return false;
204 }
205 }
206 else
207 {
208 return false;
209 }
210 }
211
212 return $pcv;
213 }
214 }
215
216
217 /*=====================================================================*\
218 || ###################################################################
219 || # $HeadURL$
220 || # $Id$
221 || ###################################################################
222 \*=====================================================================*/
223 ?>