From 962bd7b5045b7954c44ff37e4b72918ed1afe111 Mon Sep 17 00:00:00 2001 From: Rod Wright Date: Mon, 23 Feb 2026 13:36:30 -0500 Subject: [PATCH] moved the flags part of the constraints generation for log and maintform search to the end to avoid mysql unknown column error --- distfiles/search.php | 77 +++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/distfiles/search.php b/distfiles/search.php index 2c63907..980c6a4 100644 --- a/distfiles/search.php +++ b/distfiles/search.php @@ -35,7 +35,7 @@ $srchploc = $_REQUEST['srchploc'] ?? NULL; $srchnha = $_REQUEST['srchnha'] ?? NULL; $srchrepord = $_REQUEST['srchrepord'] ?? NULL; $srchflags = $_POST['srchflags'] ?? []; -$target = $_REQUEST['target'] ?? NULL; +$target = $_REQUEST['target'] ?? ["log","maintform","part"]; $doparts = PARTS_FUNCTIONS; $logname = LOG_NAME; @@ -56,7 +56,7 @@ framework("begin", "$logname Search", "Search", $print); // echo "REQUEST variables:
"; // var_dump($_REQUEST); - +// echo "
"; // ******** begin database manipulation ******** @@ -92,7 +92,6 @@ if ($search) { $srchpname = trim($srchpname); $srchploc = trim($srchploc); $srchnha = trim($srchnha); - if ($target[0] == "") $target = []; if (in_array("log", $target)) { // define the query constraints // log note id @@ -131,23 +130,6 @@ if ($search) { $logfromtables[] = "lognotes"; $logconstraints[] = "lognotes.lognote like \"%$srchtext%\""; } - // flags - if (!empty($srchflags)) { - unset($flagconstraints); - $flagcount = count($srchflags); - $logfromtables[] = "lognotes"; - $logfromtables[] = "flagmap"; - $flagconstraints[] = "flagmap.lognoteid=lognotes.lognoteid and flagmap.flagid in ("; - foreach ($srchflags as $flagid) { - $flagconstraints[] = "\"$flagid\""; - $flagconstraints[] = ","; - } - // remove final comma - array_splice($flagconstraints, -1, 1); - $flagconstraints[] = ") group by flagmap.lognoteid having count(distinct flagmap.flagid)=$flagcount"; - // make flagconstraints a single string so that the final implode doesn't split it - $logconstraints[] = join('', $flagconstraints); - } // uid if ($srchuid != "any" && $srchuid != "") { $logfromtables[] = "lognotes"; @@ -200,12 +182,28 @@ if ($search) { $logfromtables[] = "maintforms"; $logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; } + // flags + if (!empty($srchflags)) { + unset($flagconstraints); + $flagcount = count($srchflags); + $logfromtables[] = "lognotes"; + $logfromtables[] = "flagmap"; + $flagconstraints[] = "flagmap.lognoteid=lognotes.lognoteid and flagmap.flagid in ("; + foreach ($srchflags as $flagid) { + $flagconstraints[] = "\"$flagid\""; + $flagconstraints[] = ","; + } + // remove final comma + array_splice($flagconstraints, -1, 1); + $flagconstraints[] = ") group by flagmap.lognoteid having count(distinct flagmap.flagid)=$flagcount"; + // make flagconstraints a single string so that the final implode doesn't split it + $logconstraints[] = join('', $flagconstraints); + } // build the clauses and run the query $logfromclause = implode(",", array_unique($logfromtables)); $logwhereclause = implode(" and ", $logconstraints); $logrowqry = mysqli_query($db, "select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc"); } - if ($target[0] == "") $target = []; if (in_array("maintform", $target)) { // maintforms search // define the query constraints @@ -248,23 +246,6 @@ if ($search) { $mffromtables[] = "maintactions"; $mfconstraints[] = "maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)"; } - // flags - if (!empty($srchflags)) { - unset($flagconstraints); - $flagcount = count($srchflags); - $mffromtables[] = "maintforms"; - $mffromtables[] = "flagmap"; - $flagconstraints[] = "flagmap.maintformid=maintforms.maintformid and flagmap.flagid in ("; - foreach ($srchflags as $thisflagid) { - $flagconstraints[] = "\"$thisflagid\""; - $flagconstraints[] = ","; - } - // remove final comma - array_splice($flagconstraints, -1, 1); - $flagconstraints[] = ") group by flagmap.maintformid having count(distinct flagmap.flagid)=$flagcount"; - // make flagconstraints a single string so that the final implode doesn't split it - $mfconstraints[] = join('', $flagconstraints); - } // uid if ($srchuid != "any" && $srchuid != "") { $mffromtables[] = "maintforms"; @@ -307,12 +288,28 @@ if ($search) { $mffromtables[] = "maintforms"; $mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; } + // flags + if (!empty($srchflags)) { + unset($flagconstraints); + $flagcount = count($srchflags); + $mffromtables[] = "maintforms"; + $mffromtables[] = "flagmap"; + $flagconstraints[] = "flagmap.maintformid=maintforms.maintformid and flagmap.flagid in ("; + foreach ($srchflags as $thisflagid) { + $flagconstraints[] = "\"$thisflagid\""; + $flagconstraints[] = ","; + } + // remove final comma + array_splice($flagconstraints, -1, 1); + $flagconstraints[] = ") group by flagmap.maintformid having count(distinct flagmap.flagid)=$flagcount"; + // make flagconstraints a single string so that the final implode doesn't split it + $mfconstraints[] = join('', $flagconstraints); + } // build the clauses and run the query $mffromclause = implode(",", array_unique($mffromtables)); $mfwhereclause = implode(" and ", $mfconstraints); $mfrowqry = mysqli_query($db, "select maintforms.* from $mffromclause where $mfwhereclause order by maintforms.mfdate asc, maintforms.mftime asc"); } - if ($target[0] == "") $target = []; if (in_array("part", $target)) { // parts search // define the query constraints @@ -334,7 +331,6 @@ if ($search) { // tech doesn't apply to parts // subject doesn't apply to parts // search text doesn't apply to parts - // flags doesn't apply to parts // uid if ($srchuid != "any" && $srchuid != "") { $pfromtables[] = "parts"; @@ -373,6 +369,7 @@ if ($search) { $pfromtables[] = "maintforms"; $pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; } + // flags doesn't apply to parts // build the clauses and run the query $pfromclause = implode(",", array_unique($pfromtables)); $pwhereclause = implode(" and ", $pconstraints);