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 (array_key_exists($plidx,$mfreqs) && $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 (array_key_exists($plidx,$mfreqs) && $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 (array_key_exists($plidx,$mfreqs) && $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) { // sanitize and fix blank date and time $date = fix_date($date); $time = fix_time($time); // 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 (array_key_exists($plidx,$mfreqs) && $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 (array_key_exists($plidx,$mfreqs) && $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 (array_key_exists($plidx,$mfreqs) && $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 (array_key_exists('login', $_SESSION)) { // show the template selection line templateselect($techid, NULL); } // start note entry section echo "
"; if ($isadmin) { // allow tech selection echo " "; } else { echo " "; } echo "
Date:   Time:   Tech:   Tech:  $techname
Shift:   Subject:  
Note: 

    Insert Link
"; // create an array called theseflags of flagids set for this noteid $allflags = mysqli_query($db, "select flagid from flags"); unset($theseflags); $theseflags = []; while ($thisflag = mysqli_fetch_row($allflags)) { if ($templateid) { if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and notetemplateid=\"$templateid\""))) { $theseflags[] = $thisflag[0]; } } else { if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and lognoteid=\"$noteid\""))) { $theseflags[] = $thisflag[0]; } } } // if adding a note/template, only show active flags, otherwise, show all flags if ($add) { $flagslist = mysqli_query($db, "select * from flags where status=1"); } else { $flagslist = mysqli_query($db, "select * from flags"); } $flagsperline = 8; $flagcount = 1; // display checkboxes for all the flags, selecting the ones that are set for this note/template while ($flagcheckbox = mysqli_fetch_assoc($flagslist)) { 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; } } if (mysqli_num_rows($flagslist)) { echo "
Set flags on reference chain "; } else { echo " "; } if ($add && $refto) $refstring = $refto; echo "

References:                                  "; if ($add) { if ($authorized) { echo " "; } if ($doparts) { $defaultaction = 0; echo "

"; for ($partline = 0; $partline <= 5; $partline++) { echo " "; } echo "
$uidtextPart NumberSerial NumberActionMaint Form
"; } } if ($edit) { if ($authorized) { echo "      

Deleted notes are irretrievable! "; } else { echo "

Only the owner of a note or an administrator can change or delete it."; } if ($doparts) { echo "

"; // populate the existing part lines $linekey = 0; $elineqry = mysqli_query($db, "select logpartid, partid, action from logparts where lognoteid=\"$noteid\""); while ($eline = mysqli_fetch_assoc($elineqry)) { $iconpartid = $eline['logpartid']; $lpidvar = $eline['partid']; $eparts = mysqli_fetch_assoc(mysqli_query($db, "select uid,partnum,sernum from parts where partid=\"$lpidvar\"")); $epuid = $eparts['uid']; $eppn = $eparts['partnum']; $epsn = $eparts['sernum']; $defaultaction = $eline['action']; echo " "; // find maint form for this line and show link echo " "; } // add six empty part lines $defaultaction = 0; for ($partline = $linekey; $partline <= $linekey + 5; $partline++) { echo " "; } echo "
$uidtextPart NumberSerial NumberActionMaint Form
  $epuid $eppn $epsn "; if ($defaultaction) { // an action was selected previously, so just display it $actname = dblookup($db, "logpartactions", "lpactionid", "lpactionname", $defaultaction); echo "$actname"; } echo " "; $mflinkqry = mysqli_query($db, "select maintformid from maintforms where lognoteid=\"$noteid\" and mfpart=\"$lpidvar\""); if (mysqli_num_rows($mflinkqry)) { $mflinkdata = mysqli_fetch_assoc($mflinkqry); $mflinknum = $mflinkdata["maintformid"]; echo " $mflinknum "; } echo "
"; } } echo "

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