";
// var_dump($_REQUEST);
// echo "
";
// ******** 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 "
| Note ID | Date/Time | Shift | Tech | Subject | Note | References |
|---|---|---|---|---|---|---|
| %s | %s / %s | %s | %s | %s | %s | %s |
| ID | Date | Tech | $uidtext | Part Number | Serial Number | Part Name | Logbook Note ID |
|---|---|---|---|---|---|---|---|
| %s | %s | %s | %s | %s | %s | %s | $mfnotetag |