2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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 2 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 \*=====================================================================*/
23 * Constructs a massive <select> form element to create non-valid XHTML
24 * for product selection. We have to use nested <optgroup>s (invalid)
25 * because certain browsers (Safari) do not support <option disabled>,
26 * which is how I want to implement components.
28 * @param string Permission action to verify against for a product
29 * @param string Selection
30 * @param bool Include obsolete versions?
32 * @return string A large blob of <select> HTML
34 function construct_product_select($action = 'canviewbugs', $select = null
, $obsolete = true
)
38 // index all of the components by parent and ID
39 $components = array();
40 if (is_array(bugdar
::$datastore['component']))
42 foreach (bugdar
::$datastore['component'] as $id => $prod)
44 $components["$prod[parentid]"]["$id"] = $prod;
49 foreach (bugdar
::$datastore['product'] as $productid => $product)
51 if (!can_perform($action, $product['productid']) ||
!can_perform('canviewbugs', $product['productid']))
56 if ($versions = construct_version_select($productid, $select, $obsolete))
58 $output .= construct_option_group($product['title'], $versions);
61 // these are components
62 if ($components["$productid"])
64 foreach ($components["$productid"] as $componentid => $component)
66 $output .= construct_option_group($product['title'] . '/' . $component['title'], construct_version_select($componentid, $select, $obsolete));
75 * Constructs a string of HTML <option>s for a given product ID. This
76 * will always include global versions and inherited versions (if the
77 * passed ID is that of a component).
79 * @param integer Product ID
80 * @param string Selection
81 * @param bool Include obsolete versions?
83 * @return string Constructed <option> HTML
85 function construct_version_select($productid, $select, $obsolete)
87 $product = bugdar
::$datastore['product']["$productid"];
92 // this is a component
95 $component = bugdar
::$datastore['component']["$productid"];
96 $product = bugdar
::$datastore['product']["$component[parentid]"];
99 foreach (bugdar
::$datastore['version'] as $versionid => $version)
101 if ((!$version['productid'] ||
$version['productid'] == $component['productid'] ||
$version['productid'] == $product['productid']) && (!$version['obsolete'] ||
($version['obsolete'] && $obsolete)))
103 $tpl = new BSTemplate('selectoption');
105 'value' => intval($product['productid']) . ',' . intval($component['productid']) . ',' . intval($versionid),
106 'label' => $version['version']
108 $tpl->vars
['selected'] = ($tpl->vars
['value'] == $select);
109 $build .= $tpl->evaluate()->getTemplate();
117 * Constructs an <optgroup> block from a label and a string of
118 * HTML <option> elements.
120 * @param string Label for this <optgroup>
121 * @param string HTML bits
123 * @return string Composed HTML
125 function construct_option_group($glabel, $optbits)
127 $tpl = new BSTemplate('selectoptgroup');
130 'optbits' => $optbits
132 return $tpl->evaluate()->getTemplate();