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 Permission action to verify against for a product
30 * @param string Selection
32 * @return string A large blob of <select> HTML
34 function ConstructProductSelect($action = 'canviewbugs', $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 if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid']))
55 $output .= ConstructOptionGroup($product['title'], ConstructVersionSelect($productid, $select));
57 // these are components
58 foreach ($products["$productid"] AS $componentid => $component)
60 $output .= ConstructOptionGroup($product['title'] . '/' . $component['title'], ConstructVersionSelect($componentid, $select));
67 // ###################################################################
69 * Constructs a string of HTML <option>s for a given product ID. This
70 * will always include global versions and inherited versions (if the
71 * passed ID is that of a component).
73 * @param integer Product ID
74 * @param string Selection
76 * @return string Constructed <option> HTML
78 function ConstructVersionSelect($productid, $select)
82 $product = $bugsys->datastore
['product']["$productid"];
87 // this is a component
88 if ($product['componentmother'])
90 $component = $bugsys->datastore
['product']["$productid"];
91 $product = $bugsys->datastore
['product']["$component[componentmother]"];
94 foreach ($bugsys->datastore
['version'] AS $versionid => $version)
96 if (!$version['productid'] OR $version['productid'] == $component['productid'] OR $version['productid'] == $product['productid'])
98 $value = intval($product['productid']) . ',' . intval($component['productid']) . ',' . intval($versionid);
99 $label = $version['version'];
100 $selected = ($value == $select);
101 eval('$build .= "' . $bugsys->template
->fetch('selectoption') . '";');
108 // ###################################################################
110 * Constructs an <optgroup> block from a label and a string of
111 * HTML <option> elements.
113 * @param string Label for this <optgroup>
114 * @param string HTML bits
116 * @return string Composed HTML
118 function ConstructOptionGroup($glabel, $optbits)
121 eval('$HTML = "' . $bugsys->template
->fetch('selectoptgroup') . '";');
125 /*=====================================================================*\
126 || ###################################################################
129 || ###################################################################
130 \*=====================================================================*/