From dfea9c013975d63599470aa6f752c668ce352fa7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 9 Oct 2005 21:33:23 +0000 Subject: [PATCH] r519: Make the PCV selector XHTML-compliant --- includes/functions_product.php | 116 ++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/includes/functions_product.php b/includes/functions_product.php index 0315f8c..1badb44 100644 --- a/includes/functions_product.php +++ b/includes/functions_product.php @@ -24,8 +24,6 @@ function construct_pcv_select($select = '', $prefix = '--') } - $selected = ' selected="selected"'; - foreach ($bugsys->datastore['product'] AS $product) { if ($product['componentmother']) @@ -45,96 +43,106 @@ function construct_pcv_select($select = '', $prefix = '--') foreach ($products AS $product) { - $row['prefix'] = ''; + // prefix $valuepfx = "p$product[productid]"; - $row['value'] = "{$valuepfx}c0v0"; - $row['title'] = $product['title']; - $row['optgroup'] = true; - $row['description'] = $product['description']; - $show['input'] = false; - $begin = true; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); - $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select); + + // construct global options + $OPTIONS .= construct_pcv_select_global_version($product['productid'], 0, $versions, 0, $prefix, $select); + + // any immediate versions if (is_array($versions["$product[productid]"])) { foreach ($versions["$product[productid]"] AS $version) { - $row['prefix'] = $prefix . $prefix . ' '; - $row['value'] = "{$valuepfx}c0v$version[versionid]"; - $row['title'] = $version['version']; - $row['optgroup'] = false; - $row['selected'] = (($select == $row['value']) ? $selected : ''); - $row['description'] = ''; - $show['input'] = true; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); + $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix); } } + // add it as an optgroup + $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix); + $OPTIONS = ''; + + // components (can't be a nested - it's not valid) if (is_array($components["$product[productid]"])) { foreach ($components["$product[productid]"] AS $component) { - $row['prefix'] = $prefix . ' '; + // prefix $valuepfx .= "c$component[productid]"; - $row['value'] = "{$valuepfx}v0"; - $row['selected'] = (($select == $row['value']) ? $selected : ''); - $row['title'] = $component['title']; - $row['depth'] = 1; - $row['optgroup'] = true; - $begin = true; - $row['description'] = $component['description']; - $show['input'] = false; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); - $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select); + + // construct global options + $OPTIONS .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select); + + // versions if (is_array($versions["$component[productid]"])) { foreach ($versions["$component[productid]"] AS $version) { - $show['input'] = true; - $row['prefix'] = $prefix . $prefix . ' '; - $row['value'] = "{$valuepfx}v$version[versionid]"; - $row['selected'] = (($select == $row['value']) ? $selected : ''); - $row['title'] = $version['version']; - $row['optgroup'] = false; - $row['description'] = ''; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); + $OPTIONS .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix); } } + + // add optgroup + $HTML .= construct_optgroup($component['title'], 1, $OPTIONS, $prefix); + $OPTIONS = ''; } - $row['optgroup'] = true; - $begin = false; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); } - $row['optgroup'] = true; - $begin = false; - eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); } return $HTML; } // ############ Start construct_pcv_select_global_version ############ -function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '') +function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $depth, $prefix = '', $select = '') { global $bugsys; if (is_array($versions['0'])) { foreach ($versions['0'] AS $version) { - $row['prefix'] = $prefix . $prefix. ' '; - $row['typeselect'] = $type; - $row['value'] = "p{$product}c{$component}v$version[versionid]"; - $row['selected'] = (($select == $row['value']) ? ' selected="selected"' : ''); - $row['title'] = $version['version']; - $row['optgroup'] = false; - $row['description'] = ''; - $show['input'] = true; - eval('$global_versions_html .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); + $global_versions_html .= construct_option($version['version'], "p{$product}c{$component}v$version[versionid]", $select, $depth, $prefix); } } return $global_versions_html; } +// ###################### Start construct_option ##################### +function construct_option($title, $value, $selectmatch, $depth, $prefix) +{ + global $bugsys; + + $selected = ($selectmatch == $value); + + $label = fetch_depth_mark($depth, $prefix) . ' ' . $title; + + eval('$OPTIONS = "' . $bugsys->template->fetch('selectoption') . '";'); + return $OPTIONS; +} + +// ##################### Start construct_optgroup #################### +function construct_optgroup($label, $depth, $optbits, $prefix) +{ + global $bugsys; + + $glabel = fetch_depth_mark($depth, $prefix) . ' ' . $label; + + eval('$HTML = "' . $bugsys->template->fetch('selectoptgroup') . '";'); + return $HTML; +} + +// ###################### Start fetch_depth_mark ##################### +function fetch_depth_mark($depth, $mark) +{ + $string = ''; + + for ($i = 0; $i <= $depth; $i++) + { + $string .= $mark; + } + + return $string; +} + // ###################### Start parse_pcv_select ##################### function parse_pcv_select($input, $validate = false) { -- 2.22.5