public function addSelectionFormVariablesToTable($v)
 {
     $t1 = nuRunQuery("SELECT * FROM {$this->TT}");
     $fieldArray = tableFieldNamesToArray($t1);
     $s = "SELECT NOW() as timestamp ";
     while (list($key, $value) = each($v)) {
         //            if($key!=''){
         if ($key != '' and !in_array($key, $fieldArray) and $key != 'timestamp') {
             //--stop duplicate field names
             $value = str_replace('\\"', '"', $value);
             $s = $s . ' , "' . $value . '" AS ' . $key . ' ';
         }
     }
     $t = nuRunQuery("SELECT COUNT(*) FROM {$this->TT}");
     $r = db_fetch_row($t);
     if ($r[0] == 0) {
         nuRunQuery("DROP TABLE {$this->TT}");
         nuRunQuery("CREATE TABLE {$this->TT} {$s}");
         $this->noData = true;
     } else {
         nuRunQuery("CREATE TABLE a{$this->TT} {$s}, {$this->TT}.* FROM {$this->TT}");
         nuRunQuery("DROP TABLE {$this->TT}");
         nuRunQuery("CREATE TABLE {$this->TT} SELECT * FROM a{$this->TT}");
         nuRunQuery("DROP TABLE a{$this->TT}");
     }
 }
$arrayOfHashVariables = joinHashArrays($sysVariables, $sesVariables);
//--join the arrays together
$newFormArray = arrayToHashArray($formValue);
$arrayOfHashVariables = joinHashArrays($arrayOfHashVariables, $newFormArray);
//--join the arrays together
eval(replaceHashVariablesWithValues($arrayOfHashVariables, $A->sat_export_data_code));
//eval($A->sat_export_data_code);
$ascii = $A->sat_export_delimiter;
if ($A->sat_export_use_quotes == '0') {
    $dq = '';
} else {
    $dq = '"';
}
$t = nuRunQuery("SELECT * FROM {$dataTable}");
$Field = array();
$Field = tableFieldNamesToArray($t);
if ($A->sat_export_header != '0') {
    for ($i = 0; $i < count($Field); $i++) {
        if ($i > 0) {
            print chr($ascii);
        }
        print $Field[$i];
    }
    print "\r\n";
}
$t = nuRunQuery("SELECT * FROM {$dataTable}");
while ($r = db_fetch_array($t)) {
    for ($f = 0; $f < count($Field); $f++) {
        if ($f > 0) {
            print chr($ascii);
        }
function addVariablesToTT($TT, $v)
{
    //--join variables to the temp table and return true if the temp table had no data
    $t1 = nuRunQuery("SELECT * FrOM {$TT}");
    $fieldArray = tableFieldNamesToArray($t1);
    $s = "SELECT NOW() as timestamp ";
    while (list($key, $value) = each($v)) {
        if ($key != '' and !in_array($key, $fieldArray) and $key != '') {
            //--stop duplicate field names
            $value = str_replace('\\"', '"', $value);
            $s .= ' , "' . $value . '" AS ' . $key . ' ';
        }
    }
    $t = nuRunQuery("SELECT COUNT(*) FROM {$TT}");
    $r = db_fetch_row($t);
    if ($r[0] == 0) {
        nuRunQuery("DROp TABLE {$TT}");
        nuRunQuery("CREATE TABLE {$TT} {$s}");
        $noData = true;
    } else {
        nuRunQuery("CREATE TABLE a{$TT} {$s}, {$TT}.* FROM {$TT}");
        nuRunQuery("DRoP TABLE {$TT}");
        nuRunQuery("CREATE TABLE {$TT} SELECT * FROM a{$TT}");
        nuRunQuery("DrOP TABLE a{$TT}");
        $noData = false;
    }
    return $noData;
}
    $SQL->setWhere(" {$SQL->where} AND ({$object->sob_lookup_id_field} = '{$rID}')");
}
$SQL->removeAllFields();
$SQL->addField($object->sob_lookup_id_field);
$fieldNames[] = $object->sob_all_name;
$SQL->addField($object->sob_lookup_code_field);
$fieldNames[] = 'code' . $object->sob_all_name;
$SQL->addField($object->sob_lookup_description_field);
$fieldNames[] = 'description' . $object->sob_all_name;
$t = nuRunQuery("SELECT * FROM zzsys_lookup WHERE slo_zzsys_object_id = '{$object->zzsys_object_id}'");
while ($r = db_fetch_object($t)) {
    $SQL->addField($r->zzsys_slo_table_field_name);
    $fieldNames[] = $r->zzsys_slo_page_field_name;
}
$t = nuRunQuery($SQL->SQL);
$fieldArray = tableFieldNamesToArray($t);
$T = nuRunQuery($SQL->SQL);
$R = db_fetch_row($T);
for ($i = 0; $i < count($fieldArray); $i++) {
    tofile("UPDATE zzsys_small_form_value SET sfv_value = '" . $R[$i] . "'  WHERE sfv_form_record = '{$f}{$fr}{$ses}' AND sfv_name = '" . $fieldNames[$i] . "'");
    nuRunQuery("UPDATE zzsys_small_form_value SET sfv_value = '" . $R[$i] . "'  WHERE sfv_form_record = '{$f}{$fr}{$ses}' AND sfv_name = '" . $fieldNames[$i] . "'");
}
$url = "formsmall.php?x=11&f={$f}&fr={$fr}&r={$rID}&dir={$dir}&ses={$ses}";
print "<html>\n<body onload=\"document.forms.lookup.submit()\">\n";
print "<form name='lookup' method='POST' action='{$url}'>\n</form>\n";
print "</body>\n</html>\n";
return;
?>


 public function addSelectionFormVariablesToTable($v)
 {
     $t1 = nuRunQuery("SELECT * FROM {$this->TT}");
     $fieldArray = tableFieldNamesToArray($t1);
     $s = "SELECT NOW() as timestamp ";
     $columnCount = 0;
     while (list($key, $value) = each($v)) {
         $columnCount = $columnCount + 1;
         if ($key != '' and !in_array($key, $fieldArray) and $key != '') {
             //--stop duplicate field names
             //changed by SG 29/Jan/2009
             //$value                      = str_replace('\"', '"', $value);
             //$s                              = $s . ' , "' . $value . '" AS ' . $key . ' ';
             $value = addslashes($value);
             $s = "{$s} , '{$value}' AS `{$key}` ";
         }
         if ($columnCount > 200) {
             break;
         }
     }
     $t = nuRunQuery("SELECT COUNT(*) FROM {$this->TT}");
     $r = db_fetch_row($t);
     if ($r[0] == 0) {
         nuRunQuery("DROP TABLE {$this->TT}");
         nuRunQuery("CREATE TABLE {$this->TT} {$s}");
         $this->noData = true;
     } else {
         nuRunQuery("CREATE TABLE a{$this->TT} {$s}, {$this->TT}.* FROM {$this->TT}");
         nuRunQuery("DROP TABLE {$this->TT}");
         nuRunQuery("CREATE TABLE {$this->TT} SELECT * FROM a{$this->TT}");
         nuRunQuery("DROP TABLE a{$this->TT}");
     }
 }
 function __construct($parameters, $ACTIVITY)
 {
     $this->resize = 0.0679;
     $this->reportID = $ACTIVITY->zzsys_activity_id;
     $this->report = new Reporting();
     $this->hasReportHeader = $this->validSection($this->reportHeader);
     $this->hasReportFooter = $this->validSection($this->reportFooter);
     $this->hasPageHeader = $this->validSection($this->pageHeader);
     $this->hasPageFooter = $this->validSection($this->pageFooter);
     $this->fixControlNames();
     $this->buildBreakOnArray();
     $this->headerNumbers = array(5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31);
     $this->footerNumbers = array(6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32);
     $this->alignment = array('left', 'left', 'center', 'right');
     $this->selectionFormVariables = getSelectionFormVariables($parameters);
     $this->tablesUsed = getSelectionFormTempTableNames($parameters, $this->selectionFormVariables);
     $this->TT = TT();
     $this->sumTT = TT();
     $this->tablesUsed[] = $this->TT;
     $dataTable = $this->TT;
     $formValue = $this->selectionFormVariables;
     eval($ACTIVITY->sat_report_data_code);
     $this->TT = $dataTable;
     //		BuildTable($this->selectionFormVariables, $this->TT);
     $this->addSelectionFormVariablesToTable($this->selectionFormVariables);
     $t = nuRunQuery("SELECT * FROM {$this->TT} LIMIT 0 , 1");
     $this->fields = tableFieldNamesToArray($t);
     if ($_GET['tt'] != '') {
         //--- create a temp table to debug
         nuRunQuery("CREATE TABLE " . $_GET['tt'] . " SELECT * FROM {$this->TT}");
     }
     $this->sumTotals();
     $this->orderBy = $this->orderByClause();
     $this->styleSheet = $this->buildStyleSheet();
 }