menu from an array // key vars are used when you need to get data out of the $label array function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false) { // if we're not working on a boolean false, we use it for the value (allows -1 and 0) if ($includenil !== false) { $opts[] = ''; } foreach ($array AS $value => $label) { $opts[] = ''; } return '"; } // ########################## Start datelike ######################### function datelike($format, $timestamp) { global $bugsys; if (!$format OR $format == 'standard') { $format = $bugsys->options['dateformat']; } return date($format, ($timestamp + (60 * $bugsys->userinfo['timezone']))); } // ################### Start construct_user_display ################## // $userinfo needs userid, email, displayname, and showemail function construct_user_display($userinfo, $userid = true) { fetch_user_display_name($userinfo); return "$userinfo[displayname]" . (($userinfo['showemail']) ? " <$userinfo[email]>" : '') . (($userid) ? " (userid: $userinfo[userid])" : ''); } // ######################## Start can_perform ######################## // short-hand for bitwise & function can_perform($bitmask, $userinfo = null) { global $_PERMISSION; if (!isset($_PERMISSION["$bitmask"])) { trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING); } if (!$userinfo) { global $bugsys; return ($bugsys->userinfo['permissions'] & $_PERMISSION["$bitmask"]); } 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 = ' checked="checked"'; $products_fetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); while ($product = $bugsys->db->fetch_array($products_fetch)) { if ($product['componentmother']) { $components["$product[componentmother]"]["$product[productid]"] = $product; } else { $products["$product[productid]"] = $product; } } $versions_fetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder"); while ($version = $bugsys->db->fetch_array($versions_fetch)) { $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['description'] = $product['description']; $show['input'] = false; 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['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['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['description'] = ''; 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']) ? ' checked="checked"' : ''); $row['title'] = $version['version']; $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