function executeSingleRecFuncs() { global $g_sqlSingleRecFuncs; global $g_sqlMathOps; debug_printb("[executeSingleRecFuncs] executing singlerec functions...<br>"); for ($i = 0; $i < count($this->colFuncs); ++$i) { if (!$this->colFuncs[$i] || $this->colFuncsExecuted[$i]) { continue; } if (!in_array($this->colFuncs[$i], $g_sqlSingleRecFuncs)) { continue; } debug_print($this->colFuncs[$i] . "(" . $this->colNames[$i] . "): "); // EVAL if ($this->colFuncs[$i] == "EVAL") { $eval_str = $this->colNames[$i]; $out_str = ""; if (has_quotes($eval_str)) { remove_quotes($eval_str); } debug_print("EVAL function, eval String is {$eval_str}!<br>"); $sp = new StringParser(); $sp->specialElements = $g_sqlMathOps; $sp->setString($eval_str); while (!is_empty_str($elem = $sp->parseNextElement())) { debug_print("ELEM: {$elem}\n"); if (is_numeric($elem) || in_array($elem, $g_sqlMathOps)) { $out_str .= $elem . " "; } else { $origColNr = $this->findColNrByAttrs($elem, "", ""); if ($origColNr == NOT_FOUND) { print_error_msg("EVAL: Column '" . $elem . "' not found!"); return false; } $out_str .= "%{$origColNr}%"; } } debug_print("New Eval String: {$out_str}\n"); $val_str = ""; // apply function (use values from the original column as input) $rowCount = count($this->rows); $colCount = count($this->colNames); for ($j = 0; $j < $rowCount; ++$j) { $val_str = $out_str; for ($k = 0; $k < $colCount; ++$k) { if (!is_false(strpos($val_str, "%{$k}%"))) { $val_str = str_replace("%{$k}%", $this->rows[$j]->fields[$k], $val_str); } } debug_print("VAL_STR={$val_str}\n"); $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $val_str); } $this->colFuncsExecuted[$i] = true; // function with paramater, but the parameter is not a column } else { if ($this->colNames[$i] && !is_empty_str($this->colNames[$i]) && (is_numeric($this->colNames[$i]) || has_quotes($this->colNames[$i]))) { $param = $this->colNames[$i]; if (has_quotes($param)) { remove_quotes($param); } $result = execFunc($this->colFuncs[$i], $param); $rowCount = count($this->rows); debug_print("a function with a non-column parameter! (result={$result})<br>"); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; // function with parameter? =>execute function with the values form the original column } else { if ($this->colNames[$i]) { debug_print("a function with a column parameter!<br>"); // find original column (without function) $origColNr = $this->findColNrByAttrs($this->colNames[$i], $this->colTables[$i], ""); if ($origColNr == NOT_FOUND) { print_error_msg("Column '" . $this->colNames[$i] . "' not found!"); return false; } // copy some column header data from the original $this->colTables[$i] = $this->colTables[$origColNr]; $this->colTableAliases[$i] = $this->colTableAliases[$origColNr]; // apply function (use values from the original column as input) $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = execFunc($this->colFuncs[$i], $this->rows[$j]->fields[$origColNr]); } $this->colFuncsExecuted[$i] = true; // function without parameter: just execute! } else { debug_print("a function with no parameters!<br>"); $result = execFunc($this->colFuncs[$i], ""); $rowCount = count($this->rows); for ($j = 0; $j < $rowCount; ++$j) { $this->rows[$j]->fields[$i] = $result; } $this->colFuncsExecuted[$i] = true; } } } } }