0) { $strSelection = urldecode($strSelection); $strFileData = file_get_contents("{$strQueryDir}/{$strSelection}"); // Translate occurrences of {{ Date: next monday }} into yyyy-MM-dd format: // Can be used in string literals or default values in comments! preg_match_all( "/\{\{\s*?Date\:\s*?(.*)\s*?\}\}/i", $strFileData, $varDateReplacements); for ($i = 0; $i < count($varDateReplacements[0]); $i++) { try { $strMatch = $varDateReplacements[0][$i]; $strMatchSafe = preg_quote($strMatch); $strDateString = $varDateReplacements[1][$i]; $strFileData = preg_replace( "/{$strMatchSafe}/i", date_create($strDateString)->format("Y-m-d"), $strFileData); } catch (Exception $x) {} } //foreach ($varReplacements as $k => $v) // $strFileData = preg_replace("/\{\{{$k}\}\}/i", $v, $strFileData); // Get the inputs: preg_match_all( "/declare\s+\@([A-Za-z0-9]{1,})\s+(.+)\s+=\s+\?;(\s+-- Default\:\s(.*))?/i", $strFileData, $varInputs); //Respond::json($varInputs); // Get the options defined in comments: preg_match_all( "/--\s+([A-Za-z0-9]{1,})\:\s+(.+)/i", $strFileData, $varOptionMatches); if (count($varOptionMatches[0]) > 0) { for ($i = 0; $i < count($varOptionMatches[0]); $i++) { $strKey = strtolower($varOptionMatches[1][$i]); $strValue = $varOptionMatches[2][$i]; $varOptions[$strKey] = $strValue; } } if (array_key_exists("allow", $varOptions)) { $intAllowed = 0; $strAllowedObjects = strtolower($varOptions["allow"]); $varAllowedObjects = explode(",", $strAllowedObjects); $varUserObjects = []; if (class_exists("UserAuth")) { $varUser = UserAuth::getUser(); if ($varUser !== null) { foreach (UserAuth::getUserGroups() as $strGroup) $varUserObjects[] = strtolower($strGroup); $varUserObjects[] = strtolower($varUser["cn"]); } } foreach ($varAllowedObjects as $strObject) if (in_array($strObject, $varUserObjects)) $intAllowed = 1; } $intRun = Request::getParam("run"); //if (Request::posts("run_query")) if ($intRun !== null && $intRun == 1 && $intAllowed == 1) { $varPosted = Request::getParams(); unset($varPosted["run"]); try { $varRows = $c->query("{$strQueryDir}/{$strSelection}", $varPosted); $strView = "files/views/{$strSelection}.php"; // Load a custom view if there is one: if (file_exists($strView)) { ob_clean(); require $strView; ob_end_flush(); exit; } } catch (Exception $x) { $strMessage = $x->getMessage(); $strError = $strMessage; $strError .= "\n\n"; $strFile = $x->getFile(); $intLine = $x->getLine(); $strError .= "#-1 {$strFile}({$intLine}): {$strMessage}\n"; $strError .= $x->getTraceAsString(); } } } // Fancier title processing: $strTitle = null; if (array_key_exists("title", $varOptions)) $strTitle = $varOptions["title"]; $strTitle = $strTitle ?? $strSelection ?? "Report"; ?>
= $strError; ?>
= $varOptions[$strClass]; ?>
= $col; ?> |
---|
= $r[$col]; ?> |