]>
src.bluestatic.org Git - bugdar.git/blob - includes/functions_product.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2002-2007 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 \*=====================================================================*/
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
31 * @param bool Include obsolete versions?
33 * @return string A large blob of <select> HTML
35 function ConstructProductSelect ( $action = 'canviewbugs' , $select = null , $obsolete = true )
41 // index all of the components by parent and ID
42 $components = array ();
43 if ( is_array ( Bugdar
:: $datastore [ 'component' ]))
45 foreach ( Bugdar
:: $datastore [ 'component' ] AS $id => $prod )
47 $components [ " $prod [parentid]" ][ " $id" ] = $prod ;
52 foreach (Bugdar:: $datastore ['product'] AS $productid => $product )
54 if (!can_perform( $action , $product ['productid']) OR !can_perform('canviewbugs', $product ['productid']))
59 if ( $versions = ConstructVersionSelect( $productid , $select , $obsolete ))
61 $output .= ConstructOptionGroup( $product ['title'], $versions );
64 // these are components
65 if ( $components [" $productid" ])
67 foreach ( $components [ " $productid" ] AS $componentid => $component )
69 $output .= ConstructOptionGroup( $product ['title'] . '/' . $component ['title'], ConstructVersionSelect( $componentid , $select , $obsolete ));
77 // ###################################################################
79 * Constructs a string of HTML <option>s for a given product ID. This
80 * will always include global versions and inherited versions (if the
81 * passed ID is that of a component).
83 * @param integer Product ID
84 * @param string Selection
85 * @param bool Include obsolete versions?
87 * @return string Constructed <option> HTML
89 function ConstructVersionSelect( $productid , $select , $obsolete )
93 $product = Bugdar:: $datastore ['product'][" $productid" ];
98 // this is a component
101 $component = Bugdar
:: $datastore [ 'component' ][ " $productid" ];
102 $product = Bugdar:: $datastore ['product'][" $component [ parentid
] "];
105 foreach (Bugdar:: $datastore ['version'] AS $versionid => $version )
107 if ((! $version ['productid'] OR $version ['productid'] == $component ['productid'] OR $version ['productid'] == $product ['productid']) AND (! $version ['obsolete'] OR ( $version ['obsolete'] AND $obsolete )))
109 $value = intval( $product ['productid']) . ',' . intval( $component ['productid']) . ',' . intval( $versionid );
110 $label = $version ['version'];
111 $selected = ( $value == $select );
112 eval(' $build .= " ' . $bugsys- >template->fetch(' selectoption
') . ' ";');
119 // ###################################################################
121 * Constructs an <optgroup> block from a label and a string of
122 * HTML <option> elements.
124 * @param string Label for this <optgroup>
125 * @param string HTML bits
127 * @return string Composed HTML
129 function ConstructOptionGroup( $glabel , $optbits )
132 eval(' $HTML = " ' . $bugsys- >template->fetch(' selectoptgroup
') . ' ";');