From 304f8d1a8160c2987e16cdc06dd634cbde9e4723 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 18 Feb 2005 07:05:53 +0000 Subject: [PATCH] r59: Added PCV select parameter to construct_pcv_select(). Added input validation to parse_pcv_select() so we don't have to do it in multiple files. --- includes/functions.php | 71 ++++++++++++++++++++++++---- templates/default/pcv_select_row.tpl | 2 +- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index c294888..74f9e8a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -276,7 +276,7 @@ function can_perform($bitmask, $userinfo = null) // #################### Start construct_pcv_select ################### // constructs a product/component/version select with one go :-) // NB: need to make sure we have the option to turn off just p/c selection without v -function construct_pcv_select($type = 'radio', $prefix = '     ') +function construct_pcv_select($select = '', $prefix = '     ') { global $bugsys, $DB_sql, $tpl; static $HTML; @@ -286,7 +286,8 @@ function construct_pcv_select($type = 'radio', $prefix = '   &nbs return $HTML; } - $row['typeselect'] = $type; + + $selected = ' checked="checked"'; $products_fetch = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); while ($product = $DB_sql->fetch_array($products_fetch)) @@ -315,15 +316,15 @@ function construct_pcv_select($type = 'radio', $prefix = '   &nbs $row['title'] = "$product[title]"; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); - $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $type); + $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $select); if (is_array($versions["$product[productid]"])) { foreach ($versions["$product[productid]"] AS $version) { $row['prefix'] = $prefix . $prefix; - $row['typeselect'] = $type; $row['value'] = "{$valuepfx}c0v$version[versionid]"; $row['title'] = $version['version']; + $row['selected'] = iff($select == $row['value'], $selected, ''); eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); } } @@ -335,16 +336,18 @@ function construct_pcv_select($type = 'radio', $prefix = '   &nbs $row['prefix'] = $prefix; $valuepfx .= "c$component[productid]"; $row['value'] = "{$valuepfx}v0"; + $row['selected'] = iff($select == $row['value'], $selected, ''); $row['title'] = $component['title']; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); - $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $type);; + $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $select); if (is_array($versions["$component[productid]"])) { foreach ($versions["$component[productid]"] AS $version) { $row['prefix'] = $prefix . $prefix; $row['value'] = "{$valuepfx}v$version[versionid]"; + $row['selected'] = iff($select == $row['value'], $selected, ''); $row['title'] = $version['version']; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); @@ -358,7 +361,7 @@ function construct_pcv_select($type = 'radio', $prefix = '   &nbs } // ############ Start construct_pcv_select_global_version ############ -function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $type) +function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $select = '') { global $tpl; if (is_array($versions['0'])) @@ -368,6 +371,7 @@ function construct_pcv_select_global_version($product = 0, $component = 0, $vers $row['prefix'] = $prefix . $prefix; $row['typeselect'] = $type; $row['value'] = "p{$product}c{$component}v$version[versionid]"; + $row['selected'] = iff($select == $row['value'], ' checked="checked"', ''); $row['title'] = $version['version']; $row['description'] = ''; eval('$global_versions_html .= "' . $tpl->fetch('pcv_select_row') . '";'); @@ -377,8 +381,10 @@ function construct_pcv_select_global_version($product = 0, $component = 0, $vers } // ###################### Start parse_pcv_select ##################### -function parse_pcv_select($input) +function parse_pcv_select($input, $validate = false) { + global $bugsys; + $input = trim($input); /* @@ -400,7 +406,56 @@ function parse_pcv_select($input) return false; } - return array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2])); + $pcv = array('product' => intval($trio[0]), 'component' => intval($trio[1]), 'version' => intval($trio[2])); + + if (!$validate) + { + return $return; + } + else + { + // ------------------------------------------------------------------- + // pcv validation + $product = $bugsys->datastore['product'][ $pcv['product'] ]; + if (!$product) + { + return false; + } + $version = $bugsys->datastore['version'][ $pcv['version'] ]; + if (!$version) + { + return false; + } + // no component + if ($pcv['component'] == 0) + { + // not global version and version.productid != product.productid + if ($version['productid'] != 0 AND $version['productid'] != $product['productid']) + { + return false; + } + } + // using a component + else + { + $component = $bugsys->datastore['product'][ $pcv['component'] ]; + // component has the right mother + if ($component['componentmother'] == $product['productid']) + { + // version.productid != {component.productid | product.productid} + if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0) + { + return false; + } + } + else + { + return false; + } + } + + return $pcv; + } } /*=====================================================================*\ diff --git a/templates/default/pcv_select_row.tpl b/templates/default/pcv_select_row.tpl index b9644fc..c453805 100755 --- a/templates/default/pcv_select_row.tpl +++ b/templates/default/pcv_select_row.tpl @@ -1 +1 @@ -$row[prefix] $row[title]: $row[description]
+$row[prefix] $row[title]: $row[description]
-- 2.22.5