From c64dff6923b914eba8d82401f8131767b99962ba Mon Sep 17 00:00:00 2001 From: Conner Harkness Date: Tue, 9 Sep 2025 14:49:13 -0600 Subject: [PATCH] Refactor to change some verbiage, added ability to POST data (both via FormMethod option or as an API) --- pages/run.php | 126 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 39 deletions(-) diff --git a/pages/run.php b/pages/run.php index 5443b2f..226c9c9 100644 --- a/pages/run.php +++ b/pages/run.php @@ -29,8 +29,9 @@ $strError = null; $varOptions = []; - $intAllowed = 1; - $intSortable = 1; + $intAllowed = 1; // Default to allowing the user to run the query + $intSortable = 1; // By default, make the tables Datatables sortable + $intSectioned = 0; // By default, the data is unsectioned if ($strSelection !== null && strlen($strSelection) > 0) { @@ -144,25 +145,46 @@ if (in_array($strObject, $varUserObjects)) $intAllowed = 1; } - - $intRun = Request::getParam("run"); - $strFormat = Request::getParam("format"); - //if (Request::posts("run_query")) + $varPosted = Request::getParams(); + $intRun = 0; + + // Merge POST with the GET params: + // POSTing implies running the query, too. + foreach (Request::getPosted() as $k => $v) + { + $varPosted[$k] = $v; + $intRun = 1; + } + + $intRun = $varPosted["run"] ?? $intRun; + $strFormat = $varPosted["format"] ?? null; + + // Auto-format the output to be JSON when the POSTed Content-Type is JSON: + if (Request::getHeader("Content-Type") == "application/json") + $strFormat = "json"; + + // Remove these keys from submitted fields: + foreach (["run", "format"] as $k) + if (array_key_exists($k, $varPosted)) + unset($varPosted[$k]); + if ($intRun !== null && $intRun == 1 && $intAllowed == 1) { - $varPosted = Request::getParams(); - - // Remove these keys from submitted fields: - foreach (["run", "format"] as $k) - if (array_key_exists($k, $varPosted)) - unset($varPosted[$k]); - try { $varRows = $c->query($strQueryPath, $varPosted); $strQueryView = "{$strQueryPath}.php"; + if (count($varRows) > 0) + { + if (array_key_exists("_section", $varRows[0])) + { + $intSectioned = 1; + $intSortable = 0; + } + } + // Allow returning the data as JSON for APIs, maybe: if (strtolower($strFormat) == "json") Respond::json($varRows); @@ -223,9 +245,10 @@ .csv Print +
- -
+ + @@ -271,7 +294,7 @@
- +
@@ -306,7 +329,13 @@ -
+ + + 0): ?> :
  • Printed:
  • -
  • Search:
  • +
  • Filter:
  • @@ -521,7 +550,7 @@ $strNextCellClass = ""; ?> -
    +
    @@ -581,11 +610,14 @@
    + @@ -593,6 +625,13 @@ + - + + + + + + + + + $(function() { - var fileSearch = $("#file-search").first(); - var tableSearch = $("#table-search").first(); + var fileSearchInput = $("#file-search-input").first(); + var tableFilterInput = $("#table-filter-input").first(); - fileSearch.on("focus", function() { - fileSearch.trigger("input"); - fileSearch.select(); + fileSearchInput.on("focus", function() { + fileSearchInput.trigger("input"); + fileSearchInput.select(); }); - fileSearch.on("input", function() { - var q = fileSearch.val(); + fileSearchInput.on("input", function() { + var q = fileSearchInput.val(); $(".file-search-results div").each(function(i, x) { x = $(x); @@ -662,41 +711,40 @@ }); }); - if (tableSearch) + if (tableFilterInput) { - var searchText = $("#search-text").first(); + var filterText = $("#table-filter-text").first(); - tableSearch.on("input", function() { - var q = tableSearch.val(); + tableFilterInput.on("input", function() { + var q = tableFilterInput.val(); - searchText.html(q); + filterText.html(q); - searchText + filterText .parents("li") .first() .addClass("d-none"); if (q.length > 0) { - searchText + filterText .parents("li") .first() .removeClass("d-none"); } - $(".searchable").each(function(i, x) { + $(".filterable").each(function(i, x) { x = $(x); x.addClass("d-none"); - var searchableText = x.text(); + var filterableText = x.text(); - if (searchableText.includesAll(q)) + if (filterableText.includesAll(q)) x.removeClass("d-none"); }); }); } - fnShowPage = function(id) { $("div.page").addClass("d-none"); @@ -773,7 +821,7 @@ 0): ?>