//===================================================================================
//This section constructs and runs the preselect query if necessary.
//do this before building the detail query, so that query string
//variables get inserted into this as well
if (queryHasParams($preSelect)) {
    $preSelect = buildSQLQuery($preSelect);
    traceHide("preSelect=" . $preSelect);
    $udbResult = pdoQuery($preSelect, $conn_udb);
    $row = pdoFirstRow($udbResult);
    $subQuery = pdoData($row, "sub_query");
    traceHide("sub_query=" . $subQuery);
    $detailSelect = mergeSQLQuery($detailSelect, $subQuery);
}
//===================================================================================
//This section constructs the detail query if necessary
if (queryHasParams($detailSelect)) {
    $paramStr = buildParamTitle($detailSelect);
    traceHide("queryParamTitle=" . $paramStr);
    traceHide("before builtSQLQuery=" . $detailSelect);
    $detailSelect = buildSQLQuery($detailSelect);
    traceHide("after builtSQLQuery=" . $detailSelect);
} else {
    traceHide("query has no parameters");
}
//===================================================================================
//This section runs the constructed detail query
//Different handling for stored procedures and conventional SQL
if ($isStoredProcedure) {
    //**FIX**
    // $aCmd is of type "ADODB.Command"
    //$aCmd_ActiveConnection=;
    ?>
<TABLE>
<TR>
  <TD class="ddheader"><B>Function</B></TD>
  <TD class="ddheader"><B>Action</B></TD>
</TR>
<?php 
}
foreach ($adHocRows as $row) {
    ?>
<TR>
<?php 
    if ($row['sub_menu_num'] == "0") {
        //This is a query request
        //Check to see if adHocParam page required
        if (queryHasParams(pdoData($row, "select_stmt"))) {
            //Query with arguments
            if (cMenuFormatGet) {
                ?>
<TD class="ahMenu1">
<LI><A HREF="adHocParam.php?menunum=<?php 
                echo pdoData($row, "menu_num");
                ?>
&linenum=<?php 
                echo pdoData($row, "line_num");
                ?>
"><?php 
                echo pdoData($row, "title");
                ?>
</A>&nbsp;&nbsp;<BR>
</TD>
<CENTER>
<IMG SRC="<?php 
echo cHeaderImagePath;
?>
" ALT="" BORDER="0" WIDTH="299" HEIGHT="95"></A>
<BR><BR>
<span class="header18"><?php 
echo pdoData($row, "title");
?>
</span>
</CENTER>
<?php 
traceHide($sql);
traceHide("menunum/linenum=" . $thisMenu . "/" . $thisLine);
$selectStmt = pdoData($row, "select_stmt");
if (queryHasParams($selectStmt)) {
    $paramStr = explode(cParamDelimiter, $selectStmt);
    //step through the parameters and create corresponding form inputs
    //these are called '_n', where n is their index within array
    //splitParamStrArray
    $formInputsStr = "";
    for ($i = 1; $i < count($paramStr); $i += 2) {
        traceHide("requestName=" . $paramStr[$i]);
        $formInputsStr = $formInputsStr . "<TR><TD class=\"ahParam\">" . $paramStr[$i] . "</TD>" . "<TD class=\"ahParam\"><INPUT TYPE=\"text\" NAME=\"" . $paramStr[$i] . "\" VALUE=\"" . requestValue($paramStr[$i]) . "\" class=\"text\"></TD><TD>&nbsp;</TD></TR>";
    }
}
pdoDisconnect($connAdHoc);
?>
<FORM ACTION="adHocQuery.php" NAME="InputForm" METHOD="POST">
<CENTER>
<TABLE cellpadding="2">