0) { $time = "00:00:01"; } // remove html tags from note text and sanitize $note = strip_tags($note, ""); $note = mysqli_real_escape_string($db, $note); if (strlen($refstring)) { // remove everything except numbers and spaces from references and sanitize $refstring = preg_replace("#[^\d ]{1,}#", " ", $refstring); $refstring = mysqli_real_escape_string($db, $refstring); $refstring = trim($refstring); } if ($doparts == 1) { // inspect part data $maxplidx = max( max(array_keys($uids)), max(array_keys($partnums)), max(array_keys($sernums)) ); for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // for each part line, see what info is available // if uid or pn/sn supplied, pull other info from parts if ($uids[$plidx] != "") { // see if this uid is in parts table. $uidqry = mysqli_query($db, "select * from parts where uid=\"$uids[$plidx]\""); if (mysqli_num_rows($uidqry)) { // if so, populate pn/sn $uiddata = mysqli_fetch_assoc($uidqry); $partnums[$plidx] = $uiddata['partnum']; $sernums[$plidx] = $uiddata['sernum']; } } if ($partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in parts table. $pnsnqry = mysqli_query($db, "select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); if (mysqli_num_rows($pnsnqry)) { // if so, populate uid $pnsndata = mysqli_fetch_assoc($pnsnqry); $uids[$plidx] = $pnsndata['uid']; } } } } if ($authorized) { // add the record to lognotes mysqli_query($db, "insert into lognotes(date,time,shift,tech,subject,lognote) values (\"$date\", \"$time\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\")"); $newnoteid = mysqli_insert_id($db); // add references to the reflinks table if (strlen($refstring)) { $refstring = trim($refstring); $refarray = explode(" ", $refstring); foreach ($refarray as $target) { mysqli_query($db, "insert into reflinks(noteid,target) values($newnoteid,$target)"); } } $chainmembers = generate_chain($newnoteid); // update the flagmap table foreach ($flags as $thisflag) { // set flag for this note mysqli_query($db, "insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$newnoteid\")"); if ($syncflags) { //set flag for reference chain notes foreach ($chainmembers as $refdnote) { if ($refdnote != $newnoteid) { mysqli_query($db, "insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$refdnote\")"); } } } } if ($doparts == 1) { // now run through the part lines for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // update the parts table // if this line includes a uid and a pn/sn if ($uids[$plidx] != "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if it's in the parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts mysqli_query($db, "insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } // if this line includes a uid only } else if ($uids[$plidx] != "" && $partnums[$plidx] == "" && $sernums[$plidx] == "") { // see if this uid is in parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { // if not, add it to parts mysqli_query($db, "insert into parts(uid) values(\"$uids[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } // if this line includes a pn/sn only } else if ($uids[$plidx] == "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in the parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts mysqli_query($db, "insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$newnoteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$newnoteid\")"); } } else { // no part info was entered } } } } } } else { if ($loadtemplate) { $templatevalues = mysqli_fetch_assoc(mysqli_query($db, "select * from notetemplates where templateid=\"$templateid\"")); $defaultshift = $templatevalues["shift"]; $defaultsubject = $templatevalues["subject"]; $note = $templatevalues["lognote"]; $refstringqry = mysqli_query($db, "select target from reflinks where templateid=\"$templateid\""); while ($thistgt = mysqli_fetch_row($refstringqry)) { $refstring = $refstring . " " . $thistgt[0]; } } } } if ($edit) { if ($removepart && $authorized) mysqli_query($db, "delete from logparts where lognoteid=\"$noteid\" and logpartid=\"$removepart\""); if ($submit) { if ($note) { // remove cruft from note text $note = strip_tags($note, ""); $note = mysqli_real_escape_string($db, $note); // remove cruft from references if (strlen($refstring)) { $refstring = trim($refstring); $refstring = preg_replace("#[a-zA-Z]{1,}#", "", $refstring); } if ($doparts == 1) { // inspect part data $maxplidx = max( max(array_keys($uids)), max(array_keys($partnums)), max(array_keys($sernums)) ); for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // for each part line, see what info is available // if uid or pn/sn supplied, pull other info from parts if ($uids[$plidx] != "") { // see if this uid is in parts table. $uidqry = mysqli_query($db, "select * from parts where uid=\"$uids[$plidx]\""); if (mysqli_num_rows($uidqry)) { // if so, populate pn/sn $uiddata = mysqli_fetch_assoc($uidqry); $partnums[$plidx] = $uiddata['partnum']; $sernums[$plidx] = $uiddata['sernum']; } } if ($partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in parts table. $pnsnqry = mysqli_query($db, "select * from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""); if (mysqli_num_rows($pnsnqry)) { // if so, populate uid $pnsndata = mysqli_fetch_assoc($pnsnqry); $uids[$plidx] = $pnsndata['uid']; } } } } if ($authorized) { // update lognotes table mysqli_query($db, "update lognotes set date=\"$date\", time=\"$time\", shift=\"$shift\", tech=\"$efftechid\", subject=\"$subject\", lognote=\"$note\" where lognoteid=\"$noteid\""); // update the reflinks table mysqli_query($db, "delete from reflinks where noteid=\"$noteid\""); if (strlen($refstring)) { $refstring = trim($refstring); $refarray = explode(" ", $refstring); foreach ($refarray as $thisref) { mysqli_query($db, "insert into reflinks(noteid,target) values(\"$noteid\",\"$thisref\")"); } } $chainmembers = generate_chain($noteid); // update the flagmap table mysqli_query($db, "delete from flagmap where lognoteid=\"$noteid\""); if ($syncflags) { foreach ($chainmembers as $refdnote) { if ($refdnote != $noteid) { mysqli_query($db, "delete from flagmap where lognoteid=\"$refdnote\""); } } } foreach ($flags as $thisflag) { // set flag for this note mysqli_query($db, "insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$noteid\")"); if ($syncflags) { //set flag for reference chain notes foreach ($chainmembers as $refdnote) { if ($refdnote != $noteid) { mysqli_query($db, "insert into flagmap(flagid,lognoteid) values(\"$thisflag\",\"$refdnote\")"); } } } } if ($doparts == 1) { // run through the new part lines for ($plidx = 0; $plidx <= $maxplidx; $plidx++) { // update the parts table // if this line includes a uid and a pn/sn if ($uids[$plidx] != "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if it's in the parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts mysqli_query($db, "insert into parts(uid,partnum,sernum) values(\"$uids[$plidx]\",\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } // if this line includes a uid only } else if ($uids[$plidx] != "" && $partnums[$plidx] == "" && $sernums[$plidx] == "") { // see if this uid is in parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\" and partnum is NULL and sernum is NULL"))) { // if not, add it to parts mysqli_query($db, "insert into parts(uid) values(\"$uids[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where uid=\"$uids[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } // if this line includes a pn/sn only } else if ($uids[$plidx] == "" && $partnums[$plidx] != "" && $sernums[$plidx] != "") { // see if this pn/sn is in the parts table if (! mysqli_num_rows(mysqli_query($db, "select partid from parts where uid is NULL and partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))) { // if not, add it to parts mysqli_query($db, "insert into parts(partnum,sernum) values(\"$partnums[$plidx]\",\"$sernums[$plidx]\")"); $lpid = mysqli_insert_id($db); } else { // if so get the partid for the logparts table $lpid = mysqli_fetch_row(mysqli_query($db, "select partid from parts where partnum=\"$partnums[$plidx]\" and sernum=\"$sernums[$plidx]\""))[0]; } // add it to logparts table mysqli_query($db, "insert into logparts(lognoteid,partid,action) values(\"$noteid\",\"$lpid\",\"$actions[$plidx]\")"); // create a maintenance form if required if ($mfreqs[$plidx] == "on") { mysqli_query($db, "insert into maintforms(mfdate,mftech,mfpart,pending,lognoteid) values(\"$date\",\"$techid\",\"$lpid\",1,\"$noteid\")"); } } else { // no part info was entered ; } } } } } } if ($loadtemplate) { // get the note in question from the selected template $getnote = mysqli_query($db, "select * from notetemplates where templateid=\"$templateid\""); } else { // refresh the note in question from the database $getnote = mysqli_query($db, "select * from lognotes where lognoteid=\"$noteid\""); } $notetoedit = mysqli_fetch_assoc($getnote); } if ($delete) { // find notes having this note as a target $drefnoteqry = mysqli_query($db, "select noteid from reflinks where target=\"$noteid\""); while ($drefnoterow = mysqli_fetch_assoc($drefnoteqry)) { $drefnotes[] = $drefnoterow["noteid"]; } // find targets for this note $dreftgtqry = mysqli_query($db, "select target from reflinks where noteid=\"$noteid\""); while ($dreftgtrow = mysqli_fetch_assoc($dreftgtqry)) { $dreftgts[] = $dreftgtrow["target"]; } // for every note having this one as a target, add this note's targets foreach ($drefnotes as $drefnote) { foreach ($dreftgts as $dreftgt) { mysqli_query($db, "insert into reflinks(noteid,target) values(\"$drefnote\",\"$dreftgt\")"); } } // delete this note from reflinks mysqli_query($db, "delete from reflinks where noteid is not null and (noteid=\"$noteid\" or target=\"$noteid\")"); // delete from lognotes table mysqli_query($db, "delete from lognotes where lognoteid=\"$noteid\""); // delete occurances from the flagmap table mysqli_query($db, "delete from flagmap where lognoteid=\"$noteid\""); // delete occurances from the logparts table mysqli_query($db, "delete from logparts where lognoteid=\"$noteid\""); } // ******** end database manipulation ******** pagetable("begin"); if (!$print) { pageblock("left", "begin"); sidemenu(); pageblock("left", "end"); } pageblock("right", "begin"); banner($print); // display the form if ($add) { $notedate = $today; $notetime = $now; } if ($edit || $delete) { $notedate = $notetoedit["date"] ?? $today; $notetime = $notetoedit["time"] ?? $now; $defaultshift = $notetoedit["shift"]; $defaultsubject = $notetoedit["subject"]; $note = $notetoedit["lognote"]; // generate reference string for this note if ($submit) { $refstring = NULL; } $refstringqry = mysqli_query($db, "select target from reflinks where noteid=\"$noteid\""); while ($thistgt = mysqli_fetch_row($refstringqry)) { $refstring = $refstring . " " . $thistgt[0]; } $techid = $notetoedit["tech"]; } $techname = dblookup($db, "techs", "techid", "techname", $techid); if ($submit) { if ($note) { if ($add) { format_message(0, "Note added. You may enter another note or return to main page."); } if ($edit) { format_message(0, "Note changed. Return to main page."); } } else { format_message(1, "You didn't enter any note text. Please try again."); } } if ($delete) { format_message(0, "Note deleted. Return to main page."); } if ($_SESSION['login']) { // show the template selection line templateselect($techid, NULL); } // start note entry section echo "