Cleanup make_bugzilla_version_list(). Use standard naming convention, add some documentation.

Add a work around so a selected version, if not present, is added to the list and selected.
This fixes the issue where editing an older test result leaves us in an unattainable position,
we can't select the version since it was pruned from the list and we don't want to pick the
wrong version for the results.
This commit is contained in:
Chris Morgan
2007-06-17 22:44:47 +00:00
committed by WineHQ
parent a8df90b23d
commit 6221e9b921

View File

@@ -154,11 +154,14 @@ function get_xml_tag ($file, $mode = null)
} }
/* bugzilla functions */ /* bugzilla functions */
function make_bugzilla_version_list($varname, $cvalue) // $sVarname - name of the selection array that this function will output
// this is the name to use to retrieve the selection on the form postback
// $sSelectedValue - the currently selected entry
function make_bugzilla_version_list($sVarname, $sSelectedValue)
{ {
$table = BUGZILLA_DB.".versions"; $sTable = BUGZILLA_DB.".versions";
$where = "WHERE product_id=".BUGZILLA_PRODUCT_ID; $sWhere = "WHERE product_id=".BUGZILLA_PRODUCT_ID;
$sQuery = "SELECT value FROM $table $where"; $sQuery = "SELECT value FROM $sTable $sWhere";
$hResult = query_bugzilladb($sQuery); $hResult = query_bugzilladb($sQuery);
if(!$hResult) return; if(!$hResult) return;
@@ -195,15 +198,29 @@ function make_bugzilla_version_list($varname, $cvalue)
// build the selection array // build the selection array
echo "<select name='$varname'>\n"; echo "<select name='$sVarname'>\n";
echo "<option value=\"\">Choose ...</option>\n"; echo "<option value=\"\">Choose ...</option>\n";
$bFoundSelectedValue = false;
foreach($aVersions as $sKey => $sValue) foreach($aVersions as $sKey => $sValue)
{ {
if($sValue == $cvalue) if($sValue == $sSelectedValue)
{
echo "<option value=$sValue selected>$sValue\n"; echo "<option value=$sValue selected>$sValue\n";
else $bFoundSelectedValue = true;
} else
{
echo "<option value=$sValue>$sValue\n"; echo "<option value=$sValue>$sValue\n";
}
} }
// if we didn't find the selected value and the selected value isn't empty
// then we should add the selected value to the list because we could have pruned
// the version that is to be selected
if(!$bFoundSelectedValue && $sSelectedValue)
{
echo "<option value=$sSelectedValue selected>$sSelectedValue\n";
}
echo "</select>\n"; echo "</select>\n";
} }