From 8e2ae437fdaa4ec24d55731e292cb25e29bd2281 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 9 Oct 2005 19:29:31 +0000 Subject: [PATCH] r518: Splitting out the pcv functions to be in their own file --- includes/functions.php | 203 ------------------------------ includes/functions_product.php | 223 +++++++++++++++++++++++++++++++++ newreport.php | 1 + search.php | 1 + showreport.php | 1 + 5 files changed, 226 insertions(+), 203 deletions(-) create mode 100644 includes/functions_product.php diff --git a/includes/functions.php b/includes/functions.php index b5c9d44..3ce84e5 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -90,209 +90,6 @@ function can_perform($bitmask, $userinfo = null) return ($userinfo['permissions'] & $_PERMISSION["bitmask"]); } -// #################### 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($select = '', $prefix = '--') -{ - global $bugsys; - static $HTML; - - if ($HTML) - { - return $HTML; - } - - - $selected = ' selected="selected"'; - - foreach ($bugsys->datastore['product'] AS $product) - { - if ($product['componentmother']) - { - $components["$product[componentmother]"]["$product[productid]"] = $product; - } - else - { - $products["$product[productid]"] = $product; - } - } - - foreach ($bugsys->datastore['version'] AS $version) - { - $versions["$version[productid]"]["$version[versionid]"] = $version; - } - - foreach ($products AS $product) - { - $row['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); - 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') . '";'); - } - } - - if (is_array($components["$product[productid]"])) - { - foreach ($components["$product[productid]"] AS $component) - { - $row['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); - 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') . '";'); - } - } - } - $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 = '') -{ - 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') . '";'); - } - } - return $global_versions_html; -} - -// ###################### Start parse_pcv_select ##################### -function parse_pcv_select($input, $validate = false) -{ - global $bugsys; - - $input = trim($input); - - /* - yummy regex tests.... - var_dump(preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input)); - var_dump(preg_match('#^p(\d.+?)c(\d.+?)v(\d.+?)$#', $input)); - var_dump(preg_match('#^p([0-9]+?)c([0-9]+?)v([0-9]+?)$#', $input)); - var_dump(preg_match('#^p([0-9].+?)c([0-9].+?)v([0-9].+?)$#', $input)); - */ - - if (preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) == 0) - { - return false; - } - - $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY); - if (count($trio) != 3) - { - return false; - } - - $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; - } -} - // ################# Start construct_datastore_select ################ // loops through the specified datastore to create