892 lines
36 KiB
PHP
892 lines
36 KiB
PHP
<?php
|
|
/*
|
|
search.php
|
|
OpenLog Online Logbook
|
|
Copyright (C) 2026 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("functions.php");
|
|
|
|
$noprint = TRUE;
|
|
|
|
if (isset($_SESSION['login'])) {
|
|
$loggedin = TRUE;
|
|
} else {
|
|
$loggedin = FALSE;
|
|
}
|
|
|
|
$print = $_REQUEST['print'] ?? NULL;
|
|
$search = $_REQUEST['search'] ?? NULL;
|
|
$srchnoteid = $_REQUEST['srchnoteid'] ?? NULL;
|
|
$srchmfid = $_REQUEST['srchmfid'] ?? NULL;
|
|
$srchbdate = $_REQUEST['srchbdate'] ?? NULL;
|
|
$srchedate = $_REQUEST['srchedate'] ?? NULL;
|
|
$srchshift = $_REQUEST['srchshift'] ?? NULL;
|
|
$srchtech = $_REQUEST['srchtech'] ?? NULL;
|
|
$srchsubj = $_REQUEST['srchsubj'] ?? NULL;
|
|
$srchtext = $_REQUEST['srchtext'] ?? NULL;
|
|
$srchuid = $_REQUEST['srchuid'] ?? NULL;
|
|
$srchpn = $_REQUEST['srchpn'] ?? NULL;
|
|
$srchsn = $_REQUEST['srchsn'] ?? NULL;
|
|
$srchpname = $_REQUEST['srchpname'] ?? NULL;
|
|
$srchploc = $_REQUEST['srchploc'] ?? NULL;
|
|
$srchnha = $_REQUEST['srchnha'] ?? NULL;
|
|
$srchrepord = $_REQUEST['srchrepord'] ?? NULL;
|
|
$srchflags = $_REQUEST['srchflags'] ?? [];
|
|
$target = $_REQUEST['target'] ?? ["log", "maintform", "part"];
|
|
|
|
$doparts = PARTS_FUNCTIONS;
|
|
$logname = LOG_NAME;
|
|
$techalpha = TECH_ALPHA;
|
|
$subjalpha = SUBJ_ALPHA;
|
|
$uidtext = UID_TEXT;
|
|
|
|
if ($print) {
|
|
$sbcolor = P_SIDEBAR_COLOR;
|
|
$mbgcolor = P_MENUBG_COLOR;
|
|
} else {
|
|
$sbcolor = SIDEBAR_COLOR;
|
|
$mbgcolor = MENUBG_COLOR;
|
|
}
|
|
|
|
|
|
framework("begin", "$logname Search", "Search", $print);
|
|
|
|
// echo "REQUEST variables: <br>";
|
|
// var_dump($_REQUEST);
|
|
// echo "<br>";
|
|
|
|
// ******** begin database manipulation ********
|
|
|
|
// define the arrays
|
|
$logfromtables = [];
|
|
$mffromtables = [];
|
|
$pfromtables = [];
|
|
$logconstraints = [];
|
|
$mfconstraints = [];
|
|
$pconstraints = [];
|
|
|
|
// get the date range of lognotes
|
|
$logdateqry = mysqli_query($db, "select min(date), max(date) from lognotes");
|
|
$logdateresults = mysqli_fetch_row($logdateqry);
|
|
$logmindate = $logdateresults[0];
|
|
if ($logmindate == "") $logmindate = $today;
|
|
$logmaxdate = $logdateresults[1];
|
|
if ($logmaxdate == "") $logmaxdate = $today;
|
|
// get the date range of maintenance forms
|
|
$mfdateqry = mysqli_query($db, "select min(mfdate), max(mfdate) from maintforms");
|
|
$mfdateresults = mysqli_fetch_row($mfdateqry);
|
|
$mfmindate = $mfdateresults[0];
|
|
if ($mfmindate == "") $mfmindate = $today;
|
|
$mfmaxdate = $mfdateresults[1];
|
|
if ($mfmaxdate == "") $mfmaxdate = $today;
|
|
// determine entire date range
|
|
$mindate = min($logmindate, $mfmindate);
|
|
$maxdate = max($logmaxdate, $mfmaxdate);
|
|
|
|
if ($search) {
|
|
// strip whitespace from beginning and end of text fields
|
|
$srchtext = trim($srchtext);
|
|
$srchpname = trim($srchpname);
|
|
$srchploc = trim($srchploc);
|
|
$srchnha = trim($srchnha);
|
|
if (in_array("log", $target)) {
|
|
// define the query constraints
|
|
// log note id
|
|
if ($srchnoteid != "any" && $srchnoteid != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.lognoteid=\"$srchnoteid\"";
|
|
}
|
|
// maint form id
|
|
if ($srchmfid != "any" && $srchmfid != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "maintforms";
|
|
$logconstraints[] = "lognotes.lognoteid=maintforms.lognoteid and maintforms.maintformid=\"$srchmfid\"";
|
|
}
|
|
// date range
|
|
if ($srchbdate != "" && $srchedate != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.date between \"$srchbdate\" and \"$srchedate\"";
|
|
}
|
|
// shift
|
|
if ($srchshift != "0") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.shift=\"$srchshift\"";
|
|
}
|
|
// tech
|
|
if ($srchtech != "0") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.tech=\"$srchtech\"";
|
|
}
|
|
// subject
|
|
if ($srchsubj != "0") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.subject=\"$srchsubj\"";
|
|
}
|
|
// search text
|
|
if ($srchtext != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logconstraints[] = "lognotes.lognote like \"%$srchtext%\"";
|
|
}
|
|
// uid
|
|
if ($srchuid != "any" && $srchuid != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.uid=\"{$srchuid}\"";
|
|
}
|
|
// part number
|
|
if ($srchpn != "any" && $srchpn != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partnum=\"{$srchpn}\"";
|
|
}
|
|
// serial number
|
|
if ($srchsn != "any" && $srchsn != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.sernum=\"{$srchsn}\"";
|
|
}
|
|
// part name
|
|
if ($srchpname != "any" && $srchpname != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and parts.partname like \"%{$srchpname}%\"";
|
|
}
|
|
// part location
|
|
if ($srchploc != "any" && $srchploc != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logfromtables[] = "maintforms";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\"";
|
|
}
|
|
// next higher assembly
|
|
if ($srchnha != "any" && $srchnha != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$logfromtables[] = "maintforms";
|
|
$logconstraints[] = "lognotes.lognoteid=logparts.lognoteid and logparts.partid=parts.partid and maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\"";
|
|
}
|
|
// repair order
|
|
if ($srchrepord != "any" && $srchrepord != "") {
|
|
$logfromtables[] = "lognotes";
|
|
$logfromtables[] = "logparts";
|
|
$logfromtables[] = "parts";
|
|
$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 (in_array("maintform", $target)) {
|
|
// maintforms search
|
|
// define the query constraints
|
|
// log note id
|
|
if ($srchnoteid != "any" && $srchnoteid != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "lognotes";
|
|
$mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\"";
|
|
}
|
|
// maint form id
|
|
if ($srchmfid != "any" && $srchmfid != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mfconstraints[] = "maintforms.maintformid=\"$srchmfid\"";
|
|
}
|
|
// date range
|
|
if ($srchbdate != "" && $srchedate != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mfconstraints[] = "maintforms.mfdate between \"$srchbdate\" and \"$srchedate\"";
|
|
}
|
|
// shift
|
|
if ($srchshift != "0") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "lognotes";
|
|
$mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.shift=\"$srchshift\"";
|
|
}
|
|
// tech
|
|
if ($srchtech != "0") {
|
|
$mffromtables[] = "maintforms";
|
|
$mfconstraints[] = "maintforms.mftech=\"$srchtech\"";
|
|
}
|
|
// subject
|
|
if ($srchsubj != "0") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "lognotes";
|
|
$mfconstraints[] = "maintforms.lognoteid=lognotes.lognoteid and lognotes.subject=\"$srchsubj\"";
|
|
}
|
|
// search text
|
|
if ($srchtext != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "maintactions";
|
|
$mfconstraints[] = "maintforms.mfmalfunction like \"%$srchtext%\" or (maintactions.action like \"%$srchtext%\" and maintforms.maintformid=maintactions.maintformnum)";
|
|
}
|
|
// uid
|
|
if ($srchuid != "any" && $srchuid != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "parts";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and parts.uid=\"{$srchuid}\"";
|
|
}
|
|
// part number
|
|
if ($srchpn != "any" && $srchpn != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "parts";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and parts.partnum=\"{$srchpn}\"";
|
|
}
|
|
// serial number
|
|
if ($srchsn != "any" && $srchsn != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "parts";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and parts.sernum=\"{$srchsn}\"";
|
|
}
|
|
// part name
|
|
if ($srchpname != "any" && $srchpname != "") {
|
|
$mffromtables[] = "maintforms";
|
|
$mffromtables[] = "parts";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and parts.partname like \"%{$srchpname}%\"";
|
|
}
|
|
// part location
|
|
if ($srchploc != "any" && $srchploc != "") {
|
|
$mffromtables[] = "parts";
|
|
$mffromtables[] = "maintforms";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\"";
|
|
}
|
|
// next higher assembly
|
|
if ($srchnha != "any" && $srchnha != "") {
|
|
$mffromtables[] = "parts";
|
|
$mffromtables[] = "maintforms";
|
|
$mfconstraints[] = "maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\"";
|
|
}
|
|
// repair order
|
|
if ($srchrepord != "any" && $srchrepord != "") {
|
|
$mffromtables[] = "parts";
|
|
$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 (in_array("part", $target)) {
|
|
// parts search
|
|
// define the query constraints
|
|
// log note id
|
|
if ($srchnoteid != "any" && $srchnoteid != "") {
|
|
$pfromtables[] = "parts";
|
|
$pfromtables[] = "logparts";
|
|
$pfromtables[] = "lognotes";
|
|
$pconstraints[] = "parts.partid=logparts.partid and logparts.lognoteid=lognotes.lognoteid and lognotes.lognoteid=\"$srchnoteid\"";
|
|
}
|
|
// maint form id
|
|
if ($srchmfid != "any" && $srchmfid != "") {
|
|
$pfromtables[] = "parts";
|
|
$pfromtables[] = "maintforms";
|
|
$pconstraints[] = "parts.partid=maintforms.mfpart and maintforms.maintformid=\"$srchmfid\"";
|
|
}
|
|
// date range doesn't apply to parts
|
|
// shift doesn't apply to parts
|
|
// tech doesn't apply to parts
|
|
// subject doesn't apply to parts
|
|
// search text doesn't apply to parts
|
|
// uid
|
|
if ($srchuid != "any" && $srchuid != "") {
|
|
$pfromtables[] = "parts";
|
|
$pconstraints[] = "parts.uid=\"{$srchuid}\"";
|
|
}
|
|
// part number
|
|
if ($srchpn != "any" && $srchpn != "") {
|
|
$pfromtables[] = "parts";
|
|
$pconstraints[] = "parts.partnum=\"{$srchpn}\"";
|
|
}
|
|
// serial number
|
|
if ($srchsn != "any" && $srchsn != "") {
|
|
$pfromtables[] = "parts";
|
|
$pconstraints[] = "parts.sernum=\"{$srchsn}\"";
|
|
}
|
|
// part name
|
|
if ($srchpname != "any" && $srchpname != "") {
|
|
$pfromtables[] = "parts";
|
|
$pconstraints[] = "parts.partname like \"%{$srchpname}%\"";
|
|
}
|
|
// part location
|
|
if ($srchploc != "any" && $srchploc != "") {
|
|
$pfromtables[] = "parts";
|
|
$pfromtables[] = "maintforms";
|
|
$pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.mfpartloc like \"%{$srchploc}%\"";
|
|
}
|
|
// next higher assembly
|
|
if ($srchnha != "any" && $srchnha != "") {
|
|
$pfromtables[] = "parts";
|
|
$pfromtables[] = "maintforms";
|
|
$pconstraints[] = "maintforms.mfpart=parts.partid and maintforms.nha like \"%{$srchnha}%\"";
|
|
}
|
|
// repair order
|
|
if ($srchrepord != "any" && $srchrepord != "") {
|
|
$pfromtables[] = "parts";
|
|
$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);
|
|
$prowqry = mysqli_query($db, "select parts.* from $pfromclause where $pwhereclause order by parts.uid asc");
|
|
}
|
|
}
|
|
// ******** end database manipulation ********
|
|
|
|
pagetable("begin");
|
|
if (!$print) {
|
|
pageblock("left", "begin");
|
|
sidemenu();
|
|
pageblock("left", "end");
|
|
}
|
|
pageblock("right", "begin");
|
|
banner($print);
|
|
// display the form
|
|
if ($srchnoteid) $noteidval = $srchnoteid;
|
|
else $noteidval = "any";
|
|
if ($srchmfid) $mfidval = $srchmfid;
|
|
else $mfidval = "any";
|
|
if ($srchbdate) $bdateval = $srchbdate;
|
|
else $bdateval = $mindate;
|
|
if ($srchedate) $edateval = $srchedate;
|
|
else $edateval = $maxdate;
|
|
if ($srchshift) $shiftval = $srchshift;
|
|
else $shiftval = 0;
|
|
if ($srchtech) $techval = $srchtech;
|
|
else $techval = 0;
|
|
if ($srchsubj) $subjval = $srchsubj;
|
|
else $subjval = 0;
|
|
if ($srchtext) $textval = $srchtext;
|
|
else $textval = "";
|
|
if ($srchuid) $uidval = $srchuid;
|
|
else $uidval = "any";
|
|
if ($srchpn) $pnval = $srchpn;
|
|
else $pnval = "any";
|
|
if ($srchsn) $snval = $srchsn;
|
|
else $snval = "any";
|
|
if ($srchpname) $pnameval = $srchpname;
|
|
else $pnameval = "any";
|
|
if ($srchploc) $plocval = $srchploc;
|
|
else $plocval = "any";
|
|
if ($srchnha) $nhaval = $srchnha;
|
|
else $nhaval = "any";
|
|
if ($srchrepord) $repordval = $srchrepord;
|
|
else $repordval = "any";
|
|
|
|
if (!$print) {
|
|
echo "
|
|
<form method=post action=\"search.php\">
|
|
<b>Log Note ID:</b> <input type=\"text\" name=\"srchnoteid\" size=\"7\" value=\"$noteidval\" title=\"Only show results with this Logbook Note ID number\">
|
|
<b>Maintenance Form ID:</b> <input type=\"text\" name=\"srchmfid\" size=\"7\" value=\"$mfidval\" title=\"Only show results with this Maintenance Form ID number\">
|
|
<br><br>
|
|
<b>Start Date:</b> <input type=\"text\" name=\"srchbdate\" size=\"10\" value=\"$bdateval\" id=\"startdatepicker\" title=\"Format: YYYY-MM-DD\">
|
|
<b>End Date:</b> <input type=\"text\" name=\"srchedate\" size=\"10\" value=\"$edateval\" id=\"enddatepicker\" title=\"Format: YYYY-MM-DD\">
|
|
<br><br>
|
|
<b>Shift:</b> <select name=\"srchshift\" title=\"Only show results with this shift\">
|
|
";
|
|
if ($shiftval == 0) {
|
|
echo "<option value=\"0\" selected>any</option>";
|
|
} else {
|
|
echo "<option value=\"0\">any</option>";
|
|
}
|
|
$shiftrow = mysqli_query($db, "select * from shifts");
|
|
while ($shiftitem = mysqli_fetch_assoc($shiftrow)) {
|
|
if ($shiftitem['shiftid'] == $shiftval) {
|
|
printf("<option value=\"%s\" selected>%s</option>", $shiftitem['shiftid'], $shiftitem['shiftname']);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>", $shiftitem['shiftid'], $shiftitem['shiftname']);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
<b>Tech:</b> <select name=\"srchtech\" title=\"Only show results with this tech\">
|
|
";
|
|
if ($techval == 0) {
|
|
echo "<option value=\"0\" selected>any</option>";
|
|
} else {
|
|
echo "<option value=\"0\">any</option>";
|
|
}
|
|
if ($techalpha) $torder = "techname";
|
|
else $torder = "techid";
|
|
$techrow = mysqli_query($db, "select * from techs order by $torder asc");
|
|
while ($techitem = mysqli_fetch_assoc($techrow)) {
|
|
if ($techitem['techid'] == $techval) {
|
|
printf("<option value=\"%s\" selected>%s</option>", $techitem['techid'], $techitem['techname']);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>", $techitem['techid'], $techitem['techname']);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
<b>Subject:</b> <select name=\"srchsubj\" title=\"Only show results with this subject\">
|
|
";
|
|
if ($subjval == 0) {
|
|
echo "<option value=\"0\" selected>any</option>";
|
|
} else {
|
|
echo "<option value=\"0\">any</option>";
|
|
}
|
|
if ($subjalpha) $sorder = "subjectname";
|
|
else $sorder = "subjectid";
|
|
$subjrow = mysqli_query($db, "select * from subjects order by $sorder asc");
|
|
while ($subjitem = mysqli_fetch_assoc($subjrow)) {
|
|
if ($subjitem['subjectid'] == $subjval) {
|
|
printf("<option value=\"%s\" selected>%s</option>", $subjitem['subjectid'], $subjitem['subjectname']);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>", $subjitem['subjectid'], $subjitem['subjectname']);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
<br><br>
|
|
";
|
|
if ($doparts) {
|
|
echo "
|
|
<b>$uidtext:</b> <input type=\"text\" name=\"srchuid\" size=\"8\" value=\"$uidval\" title=\"Only show results associated with this $uidtext\">
|
|
<b>Part Number:</b> <input type=\"text\" name=\"srchpn\" size=\"20\" value=\"$pnval\" title=\"Only show results associated with this part number\">
|
|
<b>Serial Number:</b> <input type=\"text\" name=\"srchsn\" size=\"20\" value=\"$snval\" title=\"Only show results associated with this serial number\">
|
|
<br><br>
|
|
<b>Part Name:</b> <input type=\"text\" name=\"srchpname\" size=\"40\" value=\"$pnameval\" title=\"Only show results associated with this part name\">
|
|
<b>Part Location:</b> <input type=\"text\" name=\"srchploc\" size=\"20\" value=\"$plocval\" title=\"Only show results associated with this part location\">
|
|
<br><br>
|
|
<b>Next Higher Assembly:</b> <input type=\"text\" name=\"srchnha\" size=\"20\" value=\"$nhaval\" title=\"Only show results associated with this next higher assembly\">
|
|
<b>Repair Order:</b> <input type=\"text\" name=\"srchrepord\" size=\"12\" value=\"$repordval\" title=\"Only show results associated with this repair order number\">
|
|
<br><br>
|
|
";
|
|
}
|
|
echo "
|
|
<b>Text in Log Note, Discrepancy, or Maintenance Action:</b><br>
|
|
<textarea rows=\"3\" cols=\"70\" name=\"srchtext\" wrap=\"soft\" title=\"Only show results containing text similar to this\">$textval</textarea>
|
|
<br><br>
|
|
<b>Flags:</b>
|
|
";
|
|
$flagslist = mysqli_query($db, "select * from flags");
|
|
$flagsperline = 8;
|
|
$flagcount = 1;
|
|
while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) {
|
|
//if ($srchflags[0] == "") $srchflags = [];
|
|
if (in_array($flagcheckbox["flagid"], $srchflags)) {
|
|
printf(
|
|
"<input type=\"checkbox\" name=\"srchflags[]\" value=\"%s\" checked title=\"When checked, only results with this flag set will be shown\"><font color=\"%s\" title=\"%s\">%s</font>",
|
|
$flagcheckbox["flagid"],
|
|
$flagcheckbox["flagcolor"],
|
|
$flagcheckbox["flagname"],
|
|
$flagcheckbox["flagsym"]
|
|
);
|
|
} else {
|
|
$flagid = $flagcheckbox["flagid"];
|
|
if (mysqli_num_rows(mysqli_query($db, "select flagid from flags where flagid=\"$flagid\" and status=1"))) {
|
|
printf(
|
|
"<input type=\"checkbox\" name=\"srchflags[]\" value=\"%s\" title=\"When checked, only results with this flag set will be shown\"><font color=\"%s\" title=\"%s\">%s</font>",
|
|
$flagcheckbox["flagid"],
|
|
$flagcheckbox["flagcolor"],
|
|
$flagcheckbox["flagname"],
|
|
$flagcheckbox["flagsym"]
|
|
);
|
|
}
|
|
}
|
|
if ($flagcount < $flagsperline) {
|
|
echo " ";
|
|
$flagcount++;
|
|
} else {
|
|
echo "<br>";
|
|
$flagcount = 1;
|
|
}
|
|
}
|
|
echo "
|
|
<br><br>
|
|
";
|
|
if ($doparts) {
|
|
echo "
|
|
<b>Search in:</b>
|
|
";
|
|
if ($target[0] == "") $target = [];
|
|
if (in_array("log", $target)) {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"log\" title=\"Search in Logbook\" checked>Logbook ";
|
|
} else {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"log\" title=\"Search in Logbook\">Logbook ";
|
|
}
|
|
if (in_array("maintform", $target)) {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"maintform\" title=\"Search in Maintenance Forms\" checked>Maintenance Forms ";
|
|
} else {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"maintform\" title=\"Search in Maintenance Forms\">Maintenance Forms ";
|
|
}
|
|
if (in_array("part", $target)) {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"part\" title=\"Search in Parts\" checked>Parts ";
|
|
} else {
|
|
echo "<input type=\"checkbox\" name=\"target[]\" value=\"part\" title=\"Search in Parts\">Parts ";
|
|
}
|
|
echo "
|
|
|
|
";
|
|
} else {
|
|
echo "<input type=\"hidden\" name=\"target[]\" value=\"log\">";
|
|
}
|
|
echo "
|
|
<input type=\"submit\" name=\"search\" value=\"Search\">
|
|
";
|
|
if ($search) {
|
|
$allvars = http_build_query($_REQUEST);
|
|
echo "
|
|
<a href=\"search.php?print=1&$allvars\" target=\"_blank\">Print Search Results</a>
|
|
";
|
|
}
|
|
echo "
|
|
</form>
|
|
<hr>
|
|
";
|
|
} else {
|
|
echo "
|
|
<b>Log Note ID:</b> $noteidval
|
|
<b>Maintenance Form ID:</b> $mfidval
|
|
<br><br>
|
|
<b>Start Date:</b> $bdateval
|
|
<b>End Date:</b> $edateval
|
|
<br><br>
|
|
<b>Shift:</b>
|
|
";
|
|
if ($shiftval == 0) {
|
|
echo "any";
|
|
} else {
|
|
$shiftname = dblookup($db, "shifts", "shiftid", "shiftname", $shiftval);
|
|
echo "$shiftname";
|
|
}
|
|
echo "
|
|
|
|
<b>Tech:</b>
|
|
";
|
|
if ($techval == 0) {
|
|
echo "any";
|
|
} else {
|
|
$techname = dblookup($db, "techs", "techid", "techname", $techval);
|
|
echo "$techname";
|
|
}
|
|
echo "
|
|
|
|
<b>Subject:</b>
|
|
";
|
|
if ($subjval == 0) {
|
|
echo "any";
|
|
} else {
|
|
$subjname = dblookup($db, "subjects", "subjectid", "subjectname", $subjval);
|
|
echo "$subjname";
|
|
}
|
|
echo "
|
|
|
|
<br><br>
|
|
";
|
|
if ($doparts) {
|
|
echo "
|
|
<b>$uidtext:</b> $uidval
|
|
<b>Part Number:</b> $pnval
|
|
<b>Serial Number:</b> $snval
|
|
<br><br>
|
|
<b>Part Name:</b> $pnameval
|
|
<b>Part Location:</b> $plocval
|
|
<br><br>
|
|
<b>Next Higher Assembly:</b> $nhaval
|
|
<b>Repair Order:</b> $repordval
|
|
<br><br>
|
|
";
|
|
}
|
|
echo "
|
|
<b>Text in Log Note, Discrepancy, or Maintenance Action:</b><br>
|
|
$textval
|
|
<br><br>
|
|
<b>Flags:</b>
|
|
";
|
|
$flagslist = mysqli_query($db, "select * from flags");
|
|
$flagsperline = 8;
|
|
$flagcount = 1;
|
|
while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) {
|
|
if ($srchflags) {
|
|
if ($srchflags[0] == "") $srchflags = [];
|
|
if (in_array($flagcheckbox["flagid"], $srchflags)) {
|
|
printf(
|
|
"<font color=\"%s\">%s</font>",
|
|
$flagcheckbox["flagcolor"],
|
|
$flagcheckbox["flagsym"]
|
|
);
|
|
}
|
|
}
|
|
if ($flagcount < $flagsperline) {
|
|
echo " ";
|
|
$flagcount++;
|
|
} else {
|
|
echo "<br>";
|
|
$flagcount = 1;
|
|
}
|
|
}
|
|
echo "
|
|
<br><br>
|
|
";
|
|
if ($doparts) {
|
|
if ($target[0] == "") $target = [];
|
|
echo "
|
|
<b>Search in:</b>
|
|
";
|
|
if (in_array("log", $target)) {
|
|
echo "Logbook ";
|
|
}
|
|
if (in_array("maintform", $target)) {
|
|
echo "Maintenance Forms ";
|
|
}
|
|
if (in_array("part", $target)) {
|
|
echo "Parts ";
|
|
}
|
|
echo "
|
|
|
|
";
|
|
}
|
|
echo "
|
|
<hr>
|
|
";
|
|
}
|
|
|
|
if ($search) {
|
|
if ($target[0] == "") $target = [];
|
|
if (in_array("log", $target)) {
|
|
// run lognotes query and show results
|
|
$log_num_results = mysqli_num_rows($logrowqry);
|
|
if ($log_num_results) {
|
|
echo "
|
|
<b>Results from Logbook: $log_num_results</b><br><br>
|
|
<table border=\"1\" width=\"100%\">
|
|
<tr><th>Note ID</th><th>Date/Time</th><th>Shift</th><th>Tech</th><th>Subject</th><th>Note</th><th>References</th></tr>
|
|
";
|
|
while ($logtablerow = mysqli_fetch_assoc($logrowqry)) {
|
|
$logrefs = " <a href=\"logentry.php?refto=$logtablerow[lognoteid]\"><img src=\"icons/plus.png\" border=\"0\" title=\"Add referring note\" alt=\"Add referring note\"></a>";
|
|
if (islink($logtablerow['lognoteid'])) {
|
|
$logrefs = $logrefs . " <a href=\"refchain.php?chainnote=$logtablerow[lognoteid]\"><img src=\"icons/magnifier--arrow.png\" border=\"0\" title=\"View ref chain\" alt=\"View ref chain\"></a>";
|
|
}
|
|
// convert the shift number to a name
|
|
$logshname = dblookup($db, "shifts", "shiftid", "shiftname", $logtablerow['shift']);
|
|
// convert tech number to name
|
|
$logtname = dblookup($db, "techs", "techid", "techname", $logtablerow['tech']);
|
|
//convert subject number to name
|
|
$logsubjname = dblookup($db, "subjects", "subjectid", "subjectname", $logtablerow['subject']);
|
|
// create links of urls in note
|
|
$logfmtnote = convertweblinks($logtablerow['lognote']);
|
|
|
|
// generate the flags string
|
|
$flagstring = "";
|
|
$flagqry = mysqli_query($db, "select flagid from flagmap where lognoteid=$logtablerow[lognoteid]");
|
|
while ($flagid = mysqli_fetch_row($flagqry)) {
|
|
$flagparams = mysqli_fetch_assoc(mysqli_query($db, "select * from flags where flagid=\"$flagid[0]\""));
|
|
$flagcolor = $flagparams["flagcolor"];
|
|
$flagsym = $flagparams["flagsym"];
|
|
$flagname = $flagparams["flagname"];
|
|
$flagstring = $flagstring . "<font color=\"$flagcolor\" title=\"$flagname\">$flagsym</font> ";
|
|
}
|
|
if ($flagstring) {
|
|
$logfmtnote = $logfmtnote . "<br>" . $flagstring . " ";
|
|
} else {
|
|
$logfmtnote = $logfmtnote . "<br>";
|
|
}
|
|
|
|
printf(
|
|
"<tr>
|
|
<td valign=\"top\"><a href=logentry.php?edit=1¬eid=%s>%s</a></td>
|
|
<td valign=\"top\">%s / %s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
</tr>",
|
|
$logtablerow['lognoteid'],
|
|
$logtablerow['lognoteid'],
|
|
$logtablerow['date'],
|
|
$logtablerow['time'],
|
|
$logshname,
|
|
$logtname,
|
|
$logsubjname,
|
|
$logfmtnote,
|
|
$logrefs
|
|
);
|
|
}
|
|
echo "</table><br><hr>";
|
|
} else {
|
|
echo "<font size=\"+1\">No Logbook notes match your search criteria.</font><br><hr>";
|
|
}
|
|
}
|
|
if ($target[0] == "") $target = [];
|
|
if (in_array("maintform", $target)) {
|
|
// run maintforms query and show results
|
|
$mf_num_results = mysqli_num_rows($mfrowqry);
|
|
if ($mf_num_results) {
|
|
echo "
|
|
<b>Results from Maintenance Forms: $mf_num_results</b><br><br>
|
|
<br><table border=\"1\" width=\"100%\">
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Date</th>
|
|
<th>Tech</th>
|
|
<th>$uidtext</th>
|
|
<th>Part Number</th>
|
|
<th>Serial Number</th>
|
|
<th>Part Name</th>
|
|
<th>Logbook<br>Note ID</th>
|
|
</tr>
|
|
";
|
|
while ($mfrow = mysqli_fetch_assoc($mfrowqry)) {
|
|
// look up part data
|
|
$mfuid = dblookup($db, "parts", "partid", "uid", $mfrow["mfpart"]);
|
|
if ($mfuid == "") $mfuid = " ";
|
|
$mfpartno = dblookup($db, "parts", "partid", "partnum", $mfrow["mfpart"]);
|
|
if ($mfpartno == "") $mfpartno = " ";
|
|
$mfserno = dblookup($db, "parts", "partid", "sernum", $mfrow["mfpart"]);
|
|
if ($mfserno == "") $mfserno = " ";
|
|
$mfpartname = dblookup($db, "parts", "partid", "partname", $mfrow["mfpart"]);
|
|
if ($mfpartname == "") $mfpartname = " ";
|
|
// look up tech name
|
|
$mftname = dblookup($db, "techs", "techid", "techname", $mfrow["mftech"]);
|
|
if ($mfrow["lognoteid"] == 0) {
|
|
$mfnoteidval = " ";
|
|
$mfnotetag = "%s%s";
|
|
} else {
|
|
$mfnoteidval = $mfrow["lognoteid"];
|
|
$mfnotetag = "<a href=\"logentry.php?edit=1¬eid=%s\">%s</a>";
|
|
}
|
|
printf(
|
|
"<tr>
|
|
<td align=\"center\" valign=\"top\"><a href=\"maintformentry.php?mfedit=1&maintformid=%s\">%s</a></td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td align=\"center\" valign=\"top\">$mfnotetag</td>
|
|
</tr>",
|
|
$mfrow["maintformid"],
|
|
$mfrow["maintformid"],
|
|
$mfrow["mfdate"],
|
|
$mftname,
|
|
$mfuid,
|
|
$mfpartno,
|
|
$mfserno,
|
|
$mfpartname,
|
|
$mfnoteidval,
|
|
$mfnoteidval
|
|
);
|
|
}
|
|
echo "</table><br><hr>";
|
|
} else {
|
|
echo "<font size=\"+1\">No Maintenance Forms match your search criteria.</font><br><hr>";
|
|
}
|
|
}
|
|
if ($target[0] == "") $target = [];
|
|
if (in_array("part", $target)) {
|
|
// run parts query and show results
|
|
$p_num_results = mysqli_num_rows($prowqry);
|
|
if ($p_num_results) {
|
|
echo "
|
|
<b>Results from Parts: $p_num_results</b><br><br>
|
|
<table width=\"100%\" border=\"1\" cellpadding=\"5\">
|
|
<tr>
|
|
<th>Action</th>
|
|
<th>$uidtext</th>
|
|
<th>Part Number</th>
|
|
<th>Serial Number</th>
|
|
<th>Part Name</th>
|
|
</tr>
|
|
";
|
|
while ($partrow = mysqli_fetch_assoc($prowqry)) {
|
|
if ($loggedin) {
|
|
printf(
|
|
"
|
|
<tr>
|
|
<td>
|
|
<a href=\"partentry.php?edit=1&partid=%s\"><img src=\"icons/notebook--pencil.png\" border=\"0\" title=\"Edit this part\" alt=\"Edit this part\"></a>
|
|
</td>
|
|
<td>%s</td>
|
|
<td>%s</td>
|
|
<td>%s</td>
|
|
<td>%s</td>",
|
|
$partrow['partid'],
|
|
$partrow['uid'],
|
|
$partrow['partnum'],
|
|
$partrow['sernum'],
|
|
$partrow['partname']
|
|
);
|
|
} else {
|
|
printf(
|
|
"
|
|
<tr>
|
|
<td>
|
|
<img src=\"icons/notebook--pencil.png\" border=\"0\" title=\"You must be logged in to edit a part\" alt=\"You must be logged in to edit a part\">
|
|
</td>
|
|
<td>%s</td>
|
|
<td>%s</td>
|
|
<td>%s</td>
|
|
<td>%s</td>",
|
|
$partrow['uid'],
|
|
$partrow['partnum'],
|
|
$partrow['sernum'],
|
|
$partrow['partname']
|
|
);
|
|
}
|
|
echo "
|
|
</tr>
|
|
";
|
|
}
|
|
echo "</table><br><hr>";
|
|
} else {
|
|
echo "<font size=\"+1\">No Parts match your search criteria.</font><br><hr>";
|
|
}
|
|
}
|
|
} else {
|
|
echo "<font size=\"+1\">Use fields above to define your search.</font>";
|
|
}
|
|
|
|
banner($print);
|
|
pageblock("right", "end");
|
|
pagetable("end");
|
|
|
|
framework("end", "", "", $print);
|