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) { if (!can_perform($action, $product['productid']) OR !can_perform('canviewbugs', $product['productid'])) { continue; } // set options $OPTIONS = ''; // prefix $valuepfx = "p$product[productid]"; // 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) { $OPTIONS .= construct_option($version['version'], "{$valuepfx}c0v$version[versionid]", $select, 0, $prefix); } } else { $OPTIONS = ''; } // components (can't be a nested - it's not valid) if (is_array($components["$product[productid]"])) { foreach ($components["$product[productid]"] AS $component) { // set options2 $OPTIONS2 = ''; // prefix $valuepfx = "p$product[productid]c$component[productid]"; // construct global options $OPTIONS2 .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, 1, $prefix, $select); // product versions if (is_array($versions["$component[componentmother]"])) { foreach ($versions["$component[componentmother]"] AS $version) { $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix); } } // versions if (is_array($versions["$component[productid]"])) { foreach ($versions["$component[productid]"] AS $version) { $OPTIONS2 .= construct_option($version['version'], "{$valuepfx}v$version[versionid]", $select, 1, $prefix); } } // add optgroup $OPTIONS .= construct_optgroup($component['title'], 1, $OPTIONS2, $prefix); } } // add it as an optgroup $HTML .= construct_optgroup($product['title'], 0, $OPTIONS, $prefix); } return $HTML; } // ############ Start construct_pcv_select_global_version ############ 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) { $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) { global $bugsys; $input = trim($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 (sizeof($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; } } if (!can_perform('canviewbugs', $product['productid'])) { return false; } return $pcv; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>