0) { $mftime = "00:00:01:"; } // remove cruft from malfunction text $mfmalfunction = htmlentities($mfmalfunction); $mfmalfunction = addslashes($mfmalfunction); if ($mfauthorized) { $partdatainput = array(); if ($uid) $partdatainput['uid'] = $uid; if ($partnum) $partdatainput['partnum'] = $partnum; if ($sernum) $partdatainput['sernum'] = $sernum; $partinfo = get_part_data($partdatainput); // add to parts table if ($partinfo['result'] == 1) { // if this part has not been seen before, add it to the parts table and get partid mysqli_query($db, "insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")"); $mfpart = mysqli_insert_id($db); } else if ($partinfo['result'] == 2) { $pdatamismatch = TRUE; } else { // if it is in parts table, get partid for this record $pdatamismatch = FALSE; $mfpart = $partinfo['partid']; } if ($uid == "" || $partnum == "" || $sernum == "") { // have the maintenance form stay pending due to incomplete part data $pending = 1; } else { $pending = 0; } // add the record to maintforms if (! $pdatamismatch) { $lognoteid = ($lognoteid == NULL) ? 0 : $lognoteid; mysqli_query($db, "insert into maintforms(mfdate,mftime,mftech,mfpart,mfpartloc,mfmalfunction,nha,repord,lognoteid,pending) values (\"$mfdate\", \"$mftime\",\"$loggedinas\",\"$mfpart\",\"$mfpartloc\",\"$mfmalfunction\",\"$nha\",\"$repord\",\"$lognoteid\",\"$pending\")"); $newmaintformid = mysqli_insert_id($db); $mfidtoprint = $newmaintformid; // update the flagmap table foreach ($flags as $thisflag) { // set flag for this maintenance form mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$newmaintformid\")"); } } } } } } if ($mfedit) { $mfidtoprint = $maintformid; if ($mfsubmit && $mfauthorized) { if ($mfmalfunction && ($uid || ($partnum && $sernum))) { // remove cruft from malfunction text $mfmalfunction = htmlentities($mfmalfunction); $mfmalfunction = addslashes($mfmalfunction); // update parts table if ($uid == "" || $partnum == "" || $sernum == "") { // have the maintenance form stay pending due to incomplete part data $pending = 1; } else { $pending = 0; } if (! $pdatamismatch) { mysqli_query($db, "update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$mfpart\""); } // update the record in maintforms if (! $pdatamismatch) { mysqli_query($db, "update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\", mfmalfunction=\"$mfmalfunction\", nha=\"$nha\", repord=\"$repord\", lognoteid=\"$lognoteid\", pending=\"$pending\" where maintformid=\"$maintformid\""); // update the flagmap table mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\""); foreach ($flags as $thisflag) { // set flag for this maintenance form mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$maintformid\")"); } } } } // refresh the maintenance form in question from the database $mftoedit = getmfdata($maintformid); } if ($mfdelete && $mfauthorized) { // delete from maintforms table mysqli_query($db, "delete from maintforms where maintformid=\"$maintformid\""); // delete occurances from the flagmap table mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\""); } if ($actionadd) { if ($actionaddsubmit) { if ($action) { // sanitize and fix blank date and time $actiondate = fix_date($actiondate); $actiontime = fix_time($actiontime); // determine whether supplied date is future or past $datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$actiondate\",CURRENT_DATE)")); // if future, set time to 00:00:01, if past, set to 23:59:59 if ($datediff[0] < 0) { $actiontime = "23:59:59:"; } if ($datediff[0] > 0) { $actiontime = "00:00:01:"; } // remove cruft from action text $action = htmlentities($action); $action = addslashes($action); // add to maintactions table mysqli_query($db, "insert into maintactions (actiondate,actiontime,maintformnum,actiontech,action) values (\"$actiondate\",\"$actiontime\",\"$maintformid\",\"$loggedinas\",\"$action\")"); echo mysqli_error($db); } } } if ($actionedit) { if ($actioneditsubmit && $actionauthorized) { // update the action // sanitize and fix blank date and time $actiondate = fix_date($actiondate); $actiontime = fix_time($actiontime); // remove cruft from action text $action = htmlentities($action); $action = addslashes($action); // update maintactions table mysqli_query($db, "update maintactions set actiondate=\"$actiondate\", actiontime=\"$actiontime\", action=\"$action\" where maintactionid=\"$maintactionid\""); } // refresh the action in question from the database $actiontoedit = getactiondata($maintactionid); } if ($actiondelete && $actionauthorized) { // delete the action mysqli_query($db, "delete from maintactions where maintactionid=\"$maintactionid\""); } // ******** end database manipulation ******** pagetable("begin"); if (!$print) { pageblock("left", "begin"); sidemenu(); pageblock("left", "end"); } pageblock("right", "begin"); banner($print); // display the form if ($mfadd || $actionadd) { $mfdate = $today; $mftime = $now; $actiondate = $today; $actiontime = $now; } if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) { $mfdate = $mftoedit["mfdate"]; $mftime = $mftoedit["mftime"]; $mfpart = $mftoedit["mfpart"]; $mfpartloc = $mftoedit["mfpartloc"]; $mfmalfunction = $mftoedit["mfmalfunction"]; $nha = $mftoedit["nha"]; $repord = $mftoedit["repord"]; $lognoteid = $mftoedit["lognoteid"]; if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) $mftech = $mftoedit["mftech"]; if (! $mftime) $mftime = $now; } if (($mfedit || $actionadd || $actionedit) && ! ($mfsubmit || $actionaddsubmit || $actioneditsubmit)) { $partinfo = array(); $partinfoinput['partid'] = $mfpart; $partinfo = get_part_data($partinfoinput); $mfpart = $partinfo['partid']; $uid = $partinfo['uid']; $partnum = $partinfo['partnum']; $sernum = $partinfo['sernum']; $partname = $partinfo['partname']; $pluresult = $partinfo['result']; if ($pluresult == 2) $pdatamismatch = TRUE; else $pdatamismatch = FALSE; } $techname = dblookup($db, "techs", "techid", "techname", $mftech); if ($mfsubmit) { if ($mfmalfunction) { if (($uid || ($partnum && $sernum)) || $mfpart) { if ($mfadd) { format_message(0, "Maintenance Form added. You may enter another one or return to Maintenance Forms page."); } if ($mfedit) { format_message(0, "Maintenance Form changed. Return to Maintenance Forms page."); } } else { format_message(1, "You didn't enter any part information. Please try again."); } } else { format_message(1, "You didn't enter any malfunction description. Please try again."); } } if ($mfdelete) { format_message(0, "Maintenance Form Deleted. Return to Maintenance Forms page."); } if ($pdatamismatch) { $advtxt = "   Warning: The $uidtext doesn't match the Part Number/Serial Number associated with it in our database. Please ensure the part information you entered is correct and try again. If you know it to be correct, please use the Parts page to correct the database. "; } else { $advtxt = " You can enter a $uidtext or Part Number/Serial Number or both. "; } if ($printfmt) { // show entire maint form echo "
Maintenance Form

Form ID:
$maintformid
Date:
$mfdate
Time:
$mftime
Tech:
$techname
Log Note ID:
$lognoteid
Repair Order:
$repord

Part Data

$uidtext:
$uid
Part Number:
$partnum
Serial Number:
$sernum
Part Name:
$partname
Part Location:
$mfpartloc
Next Higher Assembly:
$nha

Malfuction Description
$mfmalfunction

Flags
"; // create an array called theseflags of flagids set for this maintformid $allflags = mysqli_query($db, "select flagid from flags"); unset($theseflags); $theseflags = []; while ($thisflag = mysqli_fetch_row($allflags)) { if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) { $theseflags[] = $thisflag[0]; } } // display flag symbols for set flags $flagslist = mysqli_query($db, "select * from flags"); while ($flagsymbol = mysqli_fetch_assoc($flagslist)) { if ($theseflags[0] == "") $theseflags = []; if (!empty($theseflags) && in_array($flagsymbol["flagid"], $theseflags)) { echo $flagsymbol['flagsym'] . "  "; } } echo "

Maintenance Actions
"; $maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); while ($actiontable = mysqli_fetch_assoc($maintactionqry)) { $actiondate = $actiontable["actiondate"]; $actiontime = $actiontable["actiontime"]; $tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]); $actiontext = convertweblinks($actiontable["action"]); // print the actions echo "
Tech:  $tname Date:  $actiondate Time:  $actiontime
$actiontext

"; } } else { echo "
Date
(YYYY-MM-DD):

Time:
Tech:
$techname
Log Note ID:
$advtxt
$uidtext:
Part Number:
Serial Number:
Part Name:
Part Location:
Next Higher Assembly:
Repair Order:

"; } if ($mfsubmit) { echo " "; } echo "
Malfunction Description:
"; // create an array called theseflags of flagids set for this maintformid $allflags = mysqli_query($db, "select flagid from flags"); unset($theseflags); $theseflags = []; while ($thisflag = mysqli_fetch_row($allflags)) { if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) { $theseflags[] = $thisflag[0]; } } if ($mfadd) { $flagslist = mysqli_query($db, "select * from flags where status=1"); } else { $flagslist = mysqli_query($db, "select * from flags"); } $flagsperline = 8; $flagcount = 1; while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) { //if ($theseflags[0]=="") $theseflags=[]; if (in_array($flagcheckbox["flagid"], $theseflags)) { 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 ($mfadd) { if ($mfauthorized) { echo "
Print This Maintenance Form

"; } else { if ($mfauthorized) { echo "

Deleted maintenance forms are irretrievable!
Print This Maintenance Form
"; } else { echo "
Only the owner of a maintenance form or an administrator can delete it.

Print This Maintenance Form "; } echo " "; } echo "

"; if ($actionadd || $actionedit) { // show the action form if ($actionadd) { $matime = $now; $actiontext = ""; $actiontech = $loggedinas; } else if ($actionedit) { $actiontext = $actiontoedit['action']; $actiontech = $actiontoedit['actiontech']; $actiondate = $actiontoedit['actiondate']; $actiontime = $actiontoedit['actiontime']; } $tname = dblookup($db, "techs", "techid", "techname", $actiontech); echo "
Tech:  $tname (YYYY-MM-DD):   Time:  
Action Taken:

"; if ($actionadd) { echo "
"; } else if ($actionedit) { echo " "; } echo "

"; } echo "Maintenance Actions    "; if ($_SESSION['login'] && $maintformid) echo ""; echo "

"; $maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc"); while ($actiontable = mysqli_fetch_assoc($maintactionqry)) { $maintactionid = $actiontable["maintactionid"]; $actiondate = $actiontable["actiondate"]; $actiontime = $actiontable["actiontime"]; $maintformnum = $actiontable["maintformnum"]; $tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]); $actiontext = convertweblinks($actiontable["action"]); // print the table echo "
"; if (($loggedinas == $actiontable["actiontech"]) || $isadmin) { echo " \"Edit   \"Delete "; } else { echo " \"Only \"Only "; } echo " Tech:  $tname Date:  $actiondate Time:  $actiontime
$actiontext

"; } echo "
"; } banner($print); pageblock("right", "end"); pagetable("end"); framework("end", "", "", $print);