diff --git a/init.php b/init.php index b00eabe..bfa6885 100644 --- a/init.php +++ b/init.php @@ -7,6 +7,10 @@ if (!file_exists($strDBCSFile)) file_put_contents($strDBCSFile, $strDBCS); - $strDBCS = trim(file_get_contents($strDBCSFile)); - $c = new DatabaseConnection($strDBCS); + $strDBCS = trim(file_get_contents($strDBCSFile)); + $varDBCSParts = explode("\n", $strDBCS); + $strUsername = $varDBCSParts[1]; + $strPassword = $varDBCSParts[2]; + + $c = new DatabaseConnection($varDBCSParts[0], $strUsername, $strPassword); ?> diff --git a/pages/run.php b/pages/run.php index caf4244..30c0c81 100644 --- a/pages/run.php +++ b/pages/run.php @@ -1,7 +1,9 @@ 0) { $strFileData = file_get_contents("{$strQueryDir}/{$strSelection}"); - preg_match_all("/declare\s+\@([A-Za-z0-9]{1,})\s+(.+)\s+=\s+\?/i", $strFileData, $varInputs); + // Get the inputs: + preg_match_all( + "/declare\s+\@([A-Za-z0-9]{1,})\s+(.+)\s+=\s+\?/i", + $strFileData, + $varInputs); - //Respond::json($varMatces); + // 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) + if ($intRun !== null && $intRun == 1 && $intAllowed == 1) { $varPosted = Request::getParams(); unset($varPosted["run"]); @@ -31,6 +78,16 @@ 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) { @@ -46,12 +103,21 @@ } } } + + // Fancier title processing: + $strTitle = null; + if (array_key_exists("title", $varOptions)) + $strTitle = $varOptions["title"]; + + $strTitle = $strTitle ?? $strSelection ?? "Report"; ?> +