0) { $time="00:00:01"; } // remove html tags from note text and sanitize $note=strip_tags($note,""); $note=mysqli_real_escape_string($db,$note); // remove cruft from references and sanitize $refs=preg_replace("#[a-zA-Z]{1,}#","",$refs); $refs=mysqli_real_escape_string($db,$refs); 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,refs) values (\"$date\", \"$time\", \"$shift\",\"$efftechid\",\"$subject\",\"$note\",\"$refs\")"); $newnoteid=mysqli_insert_id($db); // add this noteid to the appropriate flag_tables $chainmembers=generate_chain($newnoteid); foreach ($flags as $flagtblnum) { $flagtblname="flag_".$flagtblnum; // set flag for this note mysqli_query($db,"insert into $flagtblname(target,id) values(\"lognotes\",\"$newnoteid\")"); if ($syncflags) { //set flag for reference chain notes foreach ($chainmembers as $refdnote) { mysqli_query($db,"insert into $flagtblname(target,id) values(\"lognotes\",\"$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 } } } } } } elseif ($loadtemplate) { if ($templateid) { $templatevalues=mysqli_fetch_assoc(mysqli_query($db,"select * from notetemplates where templateid=\"$templateid\"")); $defaultshift=$templatevalues["shift"]; $defaultsubject=$templatevalues["subject"]; $note=$templatevalues["lognote"]; $refto=$templatevalues["refs"]; $techid=$templatevalues["tech"]; } } elseif ($savetemplate) { if ($note) { // remove cruft from note text $note=strip_tags($note,""); $note=mysqli_real_escape_string($db,$note); // remove cruft from references $refs=preg_replace("#[a-zA-Z]{1,}#","",$refs); if ($authorized) { if ($templateid) { // update the existing template mysqli_query($db,"update notetemplates set templatename=\"$templatename\", shift=\"$shift\", subject=\"$subject\", lognote=\"$note\", refs=\"$refs\" where templateid=\"$templateid\""); // update the flag_ tables $flagids=mysqli_query($db,"select flagid from flags"); while ($thisflagid=mysqli_fetch_row($flagids)) { $thisflag_tbl="flag_".$thisflagid[0]; if ($flags[0]=="") $flags=[]; if (in_array($thisflagid[0],$flags)) { if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\""))) { mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"notetemplates\",\"$templateid\")"); } } else { if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\""))) { mysqli_query($db,"delete from $thisflag_tbl where target=\"notetemplates\" and id=\"$templateid\""); } } } } else { // check if supplied name already exists if (! mysqli_num_rows(mysqli_query($db,"select templateid from notetemplates where templatename=\"$templatename\""))) { // add the record to notetemplates mysqli_query($db,"insert into notetemplates(templatename,shift,tech,subject,lognote,refs) values (\"$templatename\", \"$shift\",\"$techid\",\"$subject\",\"$note\",\"$refs\")"); $newtemplateid=mysqli_insert_id($db); // add this templateid to the appropriate flag_tables foreach ($flags as $flagtblnum) { $flagtblname="flag_".$flagtblnum; mysqli_query($db,"insert into $flagtblname(target,id) values(\"notetemplates\",\"$newtemplateid\")"); } $templateid=$newtemplateid; } else { $save_nameexists=TRUE; } } } } } elseif ($copytemplate) { if ($note) { // remove cruft from note text $note=strip_tags($note,""); $note=mysqli_real_escape_string($db,$note); // remove cruft from references $refs=preg_replace("#[a-zA-Z]{1,}#","",$refs); if ($authorized) { // check if supplied name already exists if (! mysqli_num_rows(mysqli_query($db,"select templateid from notetemplates where templatename=\"$templatename\""))) { // add the record to notetemplates mysqli_query($db,"insert into notetemplates(templatename,shift,tech,subject,lognote,refs) values (\"$templatename\", \"$shift\",\"$techid\",\"$subject\",\"$note\",\"$refs\")"); $newtemplateid=mysqli_insert_id($db); // add this templateid to the appropriate flag_tables foreach ($flags as $flagtblnum) { $flagtblname="flag_".$flagtblnum; mysqli_query($db,"insert into $flagtblname(target,id) values(\"notetemplates\",\"$newtemplateid\")"); } $templateid=$newtemplateid; } else { $copy_nameexists=TRUE; } } } } elseif ($deltemplate) { // delete from notetemplates table mysqli_query($db,"delete from notetemplates where templateid=\"$templateid\""); // delete occurances from the flag_ tables $flagids=mysqli_query($db,"select flagid from flags"); while ($thisflagid=mysqli_fetch_row($flagids)) { $delflag_tbl="flag_".$thisflagid[0]; mysqli_query($db,"delete from $delflag_tbl where target=\"notetemplates\" and id=\"$templateid\""); } unset($templateid); } } 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 $refs=preg_replace("#[a-zA-Z]{1,}#","",$refs); 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\", refs=\"$refs\" where lognoteid=\"$noteid\""); // update the flag_tables $flagids=mysqli_query($db,"select flagid from flags"); $chainmembers=generate_chain($noteid); while ($thisflagid=mysqli_fetch_row($flagids)) { $thisflag_tbl="flag_".$thisflagid[0]; if ($flags[0]=="") $flags=[]; if (in_array($thisflagid[0],$flags)) { if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\""))) { // set flag for this noteid mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"lognotes\",\"$noteid\")"); // set flag for reference chain notes if ($syncflags) { foreach($chainmembers as $refdnote) { if(!mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$refdnote\""))) { mysqli_query($db,"insert into $thisflag_tbl(target,id) values(\"lognotes\",\"$refdnote\")"); } } } } } else { if(mysqli_num_rows(mysqli_query($db,"select id from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\""))) { // clear flag for this note mysqli_query($db,"delete from $thisflag_tbl where target=\"lognotes\" and id=\"$noteid\""); } } } 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 } } } } } } // 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) { // delete from lognotes table mysqli_query($db,"delete from lognotes where lognoteid=\"$noteid\""); // delete occurances from the flag_ tables $flagids=mysqli_query($db,"select flagid from flags"); while ($thisflagid=mysqli_fetch_row($flagids)) { $delflag_tbl="flag_".$thisflagid[0]; mysqli_query($db,"delete from $delflag_tbl where target=\"lognotes\" and id=\"$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"]; $notetime=$notetoedit["time"]; $defaultshift=$notetoedit["shift"]; $defaultsubject=$notetoedit["subject"]; $note=$notetoedit["lognote"]; $refto=$notetoedit["refs"]; $techid=$notetoedit["tech"]; } $techname=dblookup($db,"techs","techid","techname",$techid); $copy_nameexists=$copy_nameexists ?? NULL; $save_nameexists=$save_nameexists ?? NULL; 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 ($copy_nameexists) { format_message(1,"Template copy failed because the name you supplied already exists."); } if ($save_nameexists) { format_message(1,"Template save failed because the name you supplied already exists."); } echo "