Files
OpenLog/distfiles/logentry.php

842 lines
40 KiB
PHP

<?php
/*
logentry.php
OpenLog Online Logbook
Copyright (C) 2025 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("functions.php");
if (!$_SESSION['login'] && !$_REQUEST['partview']) {
header ("Location: login.php");
}
$techid=$_SESSION['login'] ?? NULL;
$isadmin=dblookup($db,"techs","techid","admin",$techid);
$efftechid=$_REQUEST['efftechid'] ?? NULL;
$noteid=$_REQUEST['noteid'] ?? NULL;
$print=$_REQUEST['print'] ?? NULL;
$refto=$_REQUEST['refto'] ?? NULL;
$date=$_REQUEST['date'] ?? NULL;
$time=$_REQUEST['time'] ?? NULL;
$note=$_REQUEST['note'] ?? NULL;
$shift=$_REQUEST['shift'] ?? NULL;
$subject=$_REQUEST['subject'] ?? NULL;
$refs=$_REQUEST['refs'] ?? NULL;
$submit=$_REQUEST['submit'] ?? NULL;
$add=$_REQUEST['add'] ?? NULL;
$edit=$_REQUEST['edit'] ?? NULL;
$delete=$_REQUEST['delete'] ?? NULL;
$templateid=$_REQUEST['templateid'] ?? NULL;
$loadtemplate=$_REQUEST['loadtemplate'] ?? NULL;
$savetemplate=$_REQUEST['savetemplate'] ?? NULL;
$copytemplate=$_REQUEST['copytemplate'] ?? NULL;
$deltemplate=$_REQUEST['deltemplate'] ?? NULL;
$templatename=$_REQUEST['templatename'] ?? NULL;
$removepart=$_REQUEST['removepart'] ?? NULL;
$syncflags=$_REQUEST['syncflags'] ?? NULL;
$flags=$_POST['flags'] ?? [];
$uids=$_POST['uids'] ?? [];
$partnums=$_POST['partnums'] ?? [];
$sernums=$_POST['sernums'] ?? [];
$actions=$_POST['actions'] ?? [];
$mfreqs=$_POST['mfreqs'] ?? [];
$schedmaintcomplete=$_REQUEST['schedmaintcomplete'] ?? NULL;
$partview=$_REQUEST['partview'] ?? NULL;
$doparts=PARTS_FUNCTIONS;
$logname=LOG_NAME;
$techalpha=TECH_ALPHA;
$subjalpha=SUBJ_ALPHA;
$uidtext=UID_TEXT;
$defaultshift=dblookup($db,"techs","techid","shift",$techid);
if ($print=="Printer Friendly") {
$sbcolor=P_SIDEBAR_COLOR;
$mbgcolor=P_MENUBG_COLOR;
} else {
$sbcolor=SIDEBAR_COLOR;
$mbgcolor=MENUBG_COLOR;
}
if ($partview) $edit=1;
if (!$add && !$edit && !$delete && !$submit) $add=1;
if ($add) {
framework("begin","$logname","Note Entry",$print);
$authorized=1;
}
if ($edit || $delete) {
framework("begin","$logname","Note Edit",$print);
$owner=dblookup($db,"lognotes","lognoteid","tech",$noteid);
if (($techid==$owner) || $isadmin) $authorized=1;
}
//var_dump($_REQUEST);
// ******** begin database manipulation ********
if ($add) {
if ($submit) {
// add the entry if submit is pressed
if ($note) {
// sanitize and fix blank date and time
$date=mysqli_real_escape_string($db,$date);
$time=mysqli_real_escape_string($db,$time);
if (!$date) $date=$today;
if (!$time) $time=$now;
// determine whether supplied date is future or past
$datediff=mysqli_fetch_row(mysqli_query($db,"select datediff(\"$date\",CURRENT_DATE)"));
// if future, set time to 00:00:01, if past, set to 23:59:59
if ($datediff[0]<0) {
$time="23:59:59";
}
if ($datediff[0]>0) {
$time="00:00:01";
}
// remove html tags from note text and sanitize
$note=strip_tags($note,"<a>");
$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,"<a>");
$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,"<a>");
$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,"<a>");
$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,"<strong>Note added.</strong> You may enter another note or <a href=\"lognotes.php\">return to main page.</a>");
}
if ($edit) {
format_message(0,"<strong>Note changed.</strong> <a href=\"lognotes.php\">Return to main page.</a>");
}
} else {
format_message(1,"You didn't enter any note text. Please try again.");
}
}
if ($delete) {
format_message(0,"<strong>Note deleted.</strong> <a href=\"lognotes.php\">Return to main page.</a>");
}
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 "
<form method=\"post\" action=\"logentry.php\">
";
if ($_SESSION['login']) {
// generate template line
echo "
<table border=\"0\" cellpadding=\"10\"><tr><td>
<select name=\"templateid\" title=\"Select the template you'd like to load and click the Load Template button.\">
";
if ($loadtemplate) $templatename=dblookup($db,"notetemplates","templateid","templatename",$templateid);
$templaterow=mysqli_query($db,"select * from notetemplates where tech=\"$techid\" order by templatename asc");
if ($loadtemplate) {
printf("<option value=\"%s\">%s</option>","0","Select template");
} else {
printf("<option value=\"%s\" selected>%s</option>","0","Select template");
}
while ($templateitem=mysqli_fetch_assoc($templaterow)) {
if ($loadtemplate && ($templateitem["templateid"] == $templateid)) {
printf("<option value=\"%s\" selected>%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
} else {
printf("<option value=\"%s\">%s</option>",$templateitem["templateid"],$templateitem["templatename"]);
}
}
echo "
</select>&nbsp;&nbsp;<input type=\"submit\" name=\"loadtemplate\" value=\"Load Template\">
</td><td>
<input type=\"submit\" name=\"savetemplate\" value=\"Save As:\" title=\"Enter the name you'd like to use in the field to the right.\">&nbsp;
<input type=\"text\" size=\"25\" name=\"templatename\" value=\"$templatename\" title=\"Name of the template you'd like to save or modify\">
</td>
";
if ($loadtemplate) {
echo "
<!-- <input type=\"hidden\" name=\"templateid\" value=\"$templateid\"> -->
<td>
<input type=\"submit\" name=\"deltemplate\" value=\"Delete\" title=\"Delete the template whose name is shown in the field to the left.\">
<input type=\"submit\" name=\"copytemplate\" value=\"Copy\" title=\"Copy the template whose data is shown below to the new name in the field to the left.\">
</td>
";
}
echo "
</tr></table>
<hr>
";
}
// start note entry section
echo "
<table border=\"0\" cellpadding=\"5\">
<tr>
<td align=\"center\" colspan=\"2\"><b>Date: </b>&nbsp;
<input type=\"text\" name=\"date\" size=\"10\" maxlength=\"10\" value=\"$notedate\" id=\"singledatepicker\" title=\"Format: YYYY-MM-DD\"></td>
<td align=\"center\"><b>Time: </b>&nbsp;
<input type=\"text\" name=\"time\" size=\"8\" maxlength=\"8\" value=\"$notetime\" title=\"Format: HH:MM:SS\"></td>
";
if ($isadmin) {
// allow tech selection
echo "
<td><b>Tech: </b>&nbsp;
<select name=\"efftechid\">
";
if ($techalpha) $torder="techname"; else $torder="techid";
$techrow=mysqli_query($db,"select * from techs order by $torder asc");
while ($techitem=mysqli_fetch_assoc($techrow)) {
if ($techitem["status"] == 1) {
if ($techitem["techid"]==$techid) {
printf("<option value=\"%s\" selected>%s</option>",$techitem["techid"],$techitem["techname"]);
} else {
printf("<option value=\"%s\">%s</option>",$techitem["techid"],$techitem["techname"]);
}
}
}
echo "
</select></td>
";
} else {
echo "
<td align=\"center\">
<input type=\"hidden\" name=\"efftechid\" value=\"$techid\">
<b>Tech: </b>&nbsp;$techname
</td>
";
}
echo "
</tr>
<tr>
<td><b>Shift: </b>&nbsp;
<select name=\"shift\">
";
$shiftrow=mysqli_query($db,"select * from shifts");
while ($shiftitem=mysqli_fetch_assoc($shiftrow)) {
if ($shiftitem["status"] == 1) {
if ($shiftitem["shiftid"]==$defaultshift) {
printf("<option value=\"%s\" selected>%s</option>",$shiftitem["shiftid"],$shiftitem["shiftname"]);
} else {
printf("<option value=\"%s\">%s</option>",$shiftitem["shiftid"],$shiftitem["shiftname"]);
}
}
}
echo "
</select></td>
<td colspan=\"2\"><b>Subject: </b>&nbsp;
<select name=\"subject\">
";
if ($subjalpha) $sorder="subjectname"; else $sorder="subjectid";
$subjrow=mysqli_query($db,"select * from subjects order by $sorder asc");
while ($subjitem=mysqli_fetch_assoc($subjrow)) {
if ($subjitem["status"]==1) {
$defaultsubject=$defaultsubject ?? NULL;
if ($subjitem["subjectid"]==$defaultsubject) {
printf("<option value=\"%s\" selected>%s</option>",$subjitem["subjectid"],$subjitem["subjectname"]);
} else {
printf("<option value=\"%s\">%s</option>",$subjitem["subjectid"],$subjitem["subjectname"]);
}
}
}
echo "
</select></td>
</tr></table>
<b>Note:</b>&nbsp;<img src=\"icons/question.png\" title=\"Enter note text below. To insert a link to a web page, enter it in the link field below the Note box and click Insert Link. \"><br>
<textarea rows=\"10\" cols=\"60\" name=\"note\" id=\"notetextarea\" wrap=\"soft\">";
if ($edit || $templateid || $schedmaintcomplete) echo "$note";
echo "</textarea><br>
<input type=\"text\" size=\"50\" id=\"linktextfield\" placeholder=\"Enter a URL to insert here\">&nbsp;<a href=\"#\" onclick=\"insertUrlAtCaret('notetextarea','linktextfield');return false;\">Insert Link</a><br>
";
// get an array of flagids set for this noteid
$allflags=mysqli_query($db,"select flagid from flags");
unset($theseflags);
$theseflags=[];
while ($thisflag=mysqli_fetch_row($allflags)) {
$thisflagtbl="flag_".$thisflag[0];
if ($templateid) {
if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"notetemplates\" and id=\"$templateid\""))) {
$theseflags[]=$thisflag[0];
}
} else {
if (mysqli_num_rows(mysqli_query($db,"select id from $thisflagtbl where target=\"lognotes\" and id=\"$noteid\""))) {
$theseflags[]=$thisflag[0];
}
}
}
if ($add) {
$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 (in_array($flagcheckbox["flagid"],$theseflags)) {
printf("<input type=\"checkbox\" name=\"flags[]\" value=\"%s\" checked><font color=\"%s\" title=\"%s\">%s</font>",
$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("<input type=\"checkbox\" name=\"flags[]\" value=\"%s\"><font color=\"%s\" title=\"%s\">%s</font>",
$flagcheckbox["flagid"],$flagcheckbox["flagcolor"],$flagcheckbox["flagname"],$flagcheckbox["flagsym"]);
}
}
if ($flagcount<$flagsperline) {
echo "&nbsp;&nbsp;&nbsp;";
$flagcount++;
} else {
echo "<br>";
$flagcount=1;
}
}
echo "
<br><input type=\"checkbox\" name=\"syncflags\" value=\"1\"><font title=\"Set the selected flags on the other notes in the reference chain\">Set flags on reference chain</font>
<br><br><b>References: </b>&nbsp;
<input type=\"text\" name=\"refs\" size=\"20\" value=\"$refto\" title=\"One or more Note ID numbers separated by commas\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
";
if ($add) {
if ($authorized) {
echo "
<input type=\"hidden\" name=\"add\" value=\"1\">
<input type=\"submit\" name=\"submit\" value=\"Submit Note\">";
}
if ($doparts) {
$defaultaction=0;
echo "
<br><br>
<table border=\"0\" cellpadding=\"5\">
<tr><th>$uidtext</th><th>Part Number</th><th>Serial Number</th><th>Action</th><th>Maint Form</th></tr>
";
for ($partline=0;$partline <=5;$partline++) {
echo "
<tr>
<td align=\"center\"><input type=\"text\" name=\"uids[$partline]\" size=\"8\"></td>
<td align=\"center\"><input type=\"text\" name=\"partnums[$partline]\" size=\"20\"></td>
<td align=\"center\"><input type=\"text\" name=\"sernums[$partline]\" size=\"20\"></td>
<td align=\"center\"><select name=\"actions[$partline]\">
<option value=\"select\">Select Action</option>
";
$actrow=mysqli_query($db,"select * from logpartactions");
while ($actitem=mysqli_fetch_assoc($actrow)) {
if ($actitem["status"]==1) {
if ($actitem["lpactionid"]==$defaultaction) {
printf("<option value=\"%s\" selected>%s</option>",$actitem["lpactionid"],$actitem["lpactionname"]);
} else {
printf("<option value=\"%s\">%s</option>",$actitem["lpactionid"],$actitem["lpactionname"]);
}
}
}
echo "
</select>
</td>
<td align=\"center\"><input type=\"checkbox\" name=\"mfreqs[$partline]\" id=\"mfreqs[$partline]\"></td>
</tr>
";
}
echo "
</table>
";
}
}
if ($edit) {
if ($authorized) {
echo "
<input type=\"hidden\" name=\"edit\" value=\"1\">
<input type=\"hidden\" name=\"noteid\" value=\"$noteid\">
<input type=\"submit\" name=\"submit\" value=\"Change this note\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br>
<input type=\"submit\" name=\"delete\" value=\"Delete this note\"><font color=\"#FF0000\"><b>Deleted notes are irretrievable!</b></font>
";
} else {
echo "<br><br>Only the owner of a note or an administrator can change or delete it.";
}
if ($doparts) {
echo "
<br><br>
<table border=\"0\" cellpadding=\"5\">
<tr><th>$uidtext</th><th>Part Number</th><th>Serial Number</th><th>Action</th><th>Maint Form</th></tr>
";
// 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 "
<tr>
<td align=\"left\"><a href=\"partentry.php?edit=1&partid=$lpidvar\" title=\"Click to edit this part\"><img src=\"icons/notebook--pencil.png\"></a>
<a href=\"logentry.php?edit=1&noteid=$noteid&removepart=$iconpartid\" title=\"Click to remove part from this note\"><img src=\"icons/minus-button.png\"></a>&nbsp;&nbsp;$epuid</td>
<td align=\"center\">$eppn</td>
<td align=\"center\">$epsn</td>
<td align=\"center\">
";
$actrow=mysqli_query($db,"select * from logpartactions");
while ($actitem=mysqli_fetch_assoc($actrow)) {
if ($actitem["lpactionid"]==$defaultaction) {
echo "$actitem[lpactionname]";
}
}
echo "
</td>
";
// find maint form for this line and show link
$mflinknum=mysqli_fetch_assoc(mysqli_query($db,"select maintformid from maintforms where lognoteid=\"$noteid\" and mfpart=\"$lpidvar\""))["maintformid"];
echo "
<td align=\"center\"><a href=\"maintformentry.php?mfedit=1&maintformid=$mflinknum\" title=\"Click to view/edit this maintenance form\">$mflinknum</a></td>
</tr>
";
}
// add six empty part lines
$defaultaction=0;
for ($partline=$linekey;$partline <=$linekey+5;$partline++) {
echo "
<tr>
<td align=\"center\"><input type=\"text\" name=\"uids[$partline]\" size=\"8\"></td>
<td align=\"center\"><input type=\"text\" name=\"partnums[$partline]\" size=\"20\"></td>
<td align=\"center\"><input type=\"text\" name=\"sernums[$partline]\" size=\"20\"></td>
<td align=\"center\"><select name=\"actions[$partline]\">
<option value=\"select\">Select Action</option>
";
$actrow=mysqli_query($db,"select * from logpartactions");
while ($actitem=mysqli_fetch_assoc($actrow)) {
if ($actitem["status"]==1) {
if ($actitem["lpactionid"]==$defaultaction) {
printf("<option value=\"%s\" selected>%s</option>",$actitem["lpactionid"],$actitem["lpactionname"]);
} else {
printf("<option value=\"%s\">%s</option>",$actitem["lpactionid"],$actitem["lpactionname"]);
}
}
}
echo "
</select>
</td>
<td align=\"center\"><input type=\"checkbox\" name=\"mfreqs[$partline]\" id=\"mfreqs[$partline]\"></td>
</tr>
";
}
echo "
</table>
";
}
}
echo "
</form>
<br>
";
banner($print);
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>