"; // 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 "
Log Note ID:         Maintenance Form ID:  

Start Date:         End Date:  

Shift:         Tech:         Subject:        

"; if ($doparts) { echo " $uidtext:         Part Number:         Serial Number:        

Part Name:         Part Location:  

Next Higher Assembly:         Repair Order:  

"; } echo " Text in Log Note, Discrepancy, or Maintenance Action:


Flags: "; $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( "%s", $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( "%s", $flagcheckbox["flagid"], $flagcheckbox["flagcolor"], $flagcheckbox["flagname"], $flagcheckbox["flagsym"] ); } } if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; $flagcount = 1; } } echo "

"; if ($doparts) { echo " Search in:   "; if ($target[0] == "") $target = []; if (in_array("log", $target)) { echo "Logbook  "; } else { echo "Logbook  "; } if (in_array("maintform", $target)) { echo "Maintenance Forms  "; } else { echo "Maintenance Forms  "; } if (in_array("part", $target)) { echo "Parts  "; } else { echo "Parts  "; } echo "        "; } else { echo ""; } echo " "; if ($search) { $allvars = http_build_query($_REQUEST); echo "       Print Search Results "; } echo "

"; } else { echo " Log Note ID:   $noteidval        Maintenance Form ID:   $mfidval

Start Date:   $bdateval        End Date:   $edateval

Shift:   "; if ($shiftval == 0) { echo "any"; } else { $shiftname = dblookup($db, "shifts", "shiftid", "shiftname", $shiftval); echo "$shiftname"; } echo "        Tech:   "; if ($techval == 0) { echo "any"; } else { $techname = dblookup($db, "techs", "techid", "techname", $techval); echo "$techname"; } echo "        Subject:   "; if ($subjval == 0) { echo "any"; } else { $subjname = dblookup($db, "subjects", "subjectid", "subjectname", $subjval); echo "$subjname"; } echo "       

"; if ($doparts) { echo " $uidtext:   $uidval        Part Number:   $pnval        Serial Number:   $snval       

Part Name:   $pnameval        Part Location:   $plocval

Next Higher Assembly:   $nhaval        Repair Order:   $repordval

"; } echo " Text in Log Note, Discrepancy, or Maintenance Action:
$textval

Flags: "; $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( "%s", $flagcheckbox["flagcolor"], $flagcheckbox["flagsym"] ); } } if ($flagcount < $flagsperline) { echo "   "; $flagcount++; } else { echo "
"; $flagcount = 1; } } echo "

"; if ($doparts) { if ($target[0] == "") $target = []; echo " Search in:   "; if (in_array("log", $target)) { echo "Logbook  "; } if (in_array("maintform", $target)) { echo "Maintenance Forms  "; } if (in_array("part", $target)) { echo "Parts  "; } echo "        "; } echo "
"; } 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 " Results from Logbook: $log_num_results

"; while ($logtablerow = mysqli_fetch_assoc($logrowqry)) { $logrefs = "    \"Add"; if (islink($logtablerow['lognoteid'])) { $logrefs = $logrefs . "      \"View"; } // 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 . "$flagsym  "; } if ($flagstring) { $logfmtnote = $logfmtnote . "
" . $flagstring . "     "; } else { $logfmtnote = $logfmtnote . "
"; } printf( "", $logtablerow['lognoteid'], $logtablerow['lognoteid'], $logtablerow['date'], $logtablerow['time'], $logshname, $logtname, $logsubjname, $logfmtnote, $logrefs ); } echo "
Note IDDate/TimeShiftTechSubjectNoteReferences
%s %s / %s %s %s %s %s %s


"; } else { echo "No Logbook notes match your search criteria.

"; } } 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 " Results from Maintenance Forms: $mf_num_results


"; 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 = "%s"; } printf( "", $mfrow["maintformid"], $mfrow["maintformid"], $mfrow["mfdate"], $mftname, $mfuid, $mfpartno, $mfserno, $mfpartname, $mfnoteidval, $mfnoteidval ); } echo "
ID Date Tech $uidtext Part Number Serial Number Part Name Logbook
Note ID
%s %s %s %s %s %s %s $mfnotetag


"; } else { echo "No Maintenance Forms match your search criteria.

"; } } 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 " Results from Parts: $p_num_results

"; while ($partrow = mysqli_fetch_assoc($prowqry)) { if ($loggedin) { printf( " ", $partrow['partid'], $partrow['uid'], $partrow['partnum'], $partrow['sernum'], $partrow['partname'] ); } else { printf( " ", $partrow['uid'], $partrow['partnum'], $partrow['sernum'], $partrow['partname'] ); } echo " "; } echo "
Action $uidtext Part Number Serial Number Part Name
\"Edit %s %s %s %s
\"You %s %s %s %s


"; } else { echo "No Parts match your search criteria.

"; } } } else { echo "Use fields above to define your search."; } banner($print); pageblock("right", "end"); pagetable("end"); framework("end", "", "", $print);