moved the flags part of the constraints generation for log and maintform search to the end to avoid mysql unknown column error

This commit is contained in:
2026-02-23 13:36:30 -05:00
parent ec8efec61e
commit 962bd7b504

View File

@@ -35,7 +35,7 @@ $srchploc = $_REQUEST['srchploc'] ?? NULL;
$srchnha = $_REQUEST['srchnha'] ?? NULL; $srchnha = $_REQUEST['srchnha'] ?? NULL;
$srchrepord = $_REQUEST['srchrepord'] ?? NULL; $srchrepord = $_REQUEST['srchrepord'] ?? NULL;
$srchflags = $_POST['srchflags'] ?? []; $srchflags = $_POST['srchflags'] ?? [];
$target = $_REQUEST['target'] ?? NULL; $target = $_REQUEST['target'] ?? ["log","maintform","part"];
$doparts = PARTS_FUNCTIONS; $doparts = PARTS_FUNCTIONS;
$logname = LOG_NAME; $logname = LOG_NAME;
@@ -56,7 +56,7 @@ framework("begin", "$logname Search", "Search", $print);
// echo "REQUEST variables: <br>"; // echo "REQUEST variables: <br>";
// var_dump($_REQUEST); // var_dump($_REQUEST);
// echo "<br>";
// ******** begin database manipulation ******** // ******** begin database manipulation ********
@@ -92,7 +92,6 @@ if ($search) {
$srchpname = trim($srchpname); $srchpname = trim($srchpname);
$srchploc = trim($srchploc); $srchploc = trim($srchploc);
$srchnha = trim($srchnha); $srchnha = trim($srchnha);
if ($target[0] == "") $target = [];
if (in_array("log", $target)) { if (in_array("log", $target)) {
// define the query constraints // define the query constraints
// log note id // log note id
@@ -131,23 +130,6 @@ if ($search) {
$logfromtables[] = "lognotes"; $logfromtables[] = "lognotes";
$logconstraints[] = "lognotes.lognote like \"%$srchtext%\""; $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 // uid
if ($srchuid != "any" && $srchuid != "") { if ($srchuid != "any" && $srchuid != "") {
$logfromtables[] = "lognotes"; $logfromtables[] = "lognotes";
@@ -200,12 +182,28 @@ if ($search) {
$logfromtables[] = "maintforms"; $logfromtables[] = "maintforms";
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; $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 // build the clauses and run the query
$logfromclause = implode(",", array_unique($logfromtables)); $logfromclause = implode(",", array_unique($logfromtables));
$logwhereclause = implode(" and ", $logconstraints); $logwhereclause = implode(" and ", $logconstraints);
$logrowqry = mysqli_query($db, "select lognotes.* from $logfromclause where $logwhereclause order by lognotes.date asc, lognotes.time asc"); $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)) { if (in_array("maintform", $target)) {
// maintforms search // maintforms search
// define the query constraints // define the query constraints
@@ -248,23 +246,6 @@ if ($search) {
$mffromtables[] = "maintactions"; $mffromtables[] = "maintactions";
$mfconstraints[] = "maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)"; $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 // uid
if ($srchuid != "any" && $srchuid != "") { if ($srchuid != "any" && $srchuid != "") {
$mffromtables[] = "maintforms"; $mffromtables[] = "maintforms";
@@ -307,12 +288,28 @@ if ($search) {
$mffromtables[] = "maintforms"; $mffromtables[] = "maintforms";
$mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; $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 // build the clauses and run the query
$mffromclause = implode(",", array_unique($mffromtables)); $mffromclause = implode(",", array_unique($mffromtables));
$mfwhereclause = implode(" and ", $mfconstraints); $mfwhereclause = implode(" and ", $mfconstraints);
$mfrowqry = mysqli_query($db, "select maintforms.* from $mffromclause where $mfwhereclause order by maintforms.mfdate asc, maintforms.mftime asc"); $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)) { if (in_array("part", $target)) {
// parts search // parts search
// define the query constraints // define the query constraints
@@ -334,7 +331,6 @@ if ($search) {
// tech doesn't apply to parts // tech doesn't apply to parts
// subject doesn't apply to parts // subject doesn't apply to parts
// search text doesn't apply to parts // search text doesn't apply to parts
// flags doesn't apply to parts
// uid // uid
if ($srchuid != "any" && $srchuid != "") { if ($srchuid != "any" && $srchuid != "") {
$pfromtables[] = "parts"; $pfromtables[] = "parts";
@@ -373,6 +369,7 @@ if ($search) {
$pfromtables[] = "maintforms"; $pfromtables[] = "maintforms";
$pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\""; $pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.repord=\"{$srchrepord}\"";
} }
// flags doesn't apply to parts
// build the clauses and run the query // build the clauses and run the query
$pfromclause = implode(",", array_unique($pfromtables)); $pfromclause = implode(",", array_unique($pfromtables));
$pwhereclause = implode(" and ", $pconstraints); $pwhereclause = implode(" and ", $pconstraints);