Files
OpenLog/distfiles/logentry.php

791 lines
36 KiB
PHP

<?php
/*
logentry.php
OpenLog Online Logbook
Copyright (C) 2026 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;
$date=$_REQUEST['date'] ?? NULL;
$time=$_REQUEST['time'] ?? NULL;
$note=$_REQUEST['note'] ?? NULL;
$shift=$_REQUEST['shift'] ?? NULL;
$subject=$_REQUEST['subject'] ?? NULL;
$refstring=$_REQUEST['refstring'] ?? NULL;
$refto=$_REQUEST['refto'] ?? NULL;
$submit=$_REQUEST['submit'] ?? NULL;
$add=$_REQUEST['add'] ?? NULL;
$edit=$_REQUEST['edit'] ?? NULL;
$delete=$_REQUEST['delete'] ?? NULL;
$usertemplateid=$_REQUEST['usertemplateid'] ?? NULL;
$globaltemplateid=$_REQUEST['globaltemplateid'] ?? NULL;
$loadtemplate=$_REQUEST['loadtemplate'] ?? 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 ($isadmin) {
$authorized=TRUE;
} else {
$authorized=FALSE;
}
if ($add) {
framework("begin","$logname","Note Entry",$print);
$authorized=TRUE;
}
if ($edit || $delete) {
framework("begin","$logname","Note Edit",$print);
$owner=dblookup($db,"lognotes","lognoteid","tech",$noteid);
if ($techid==$owner) $authorized=TRUE;
}
// var_dump($_REQUEST);
// ******** begin database manipulation ********
if ($usertemplateid) {
$templateid=$usertemplateid;
} else if ($globaltemplateid) {
$templateid=$globaltemplateid;
} else {
$templateid=NULL;
$loadtemplate=NULL;
}
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);
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,"<a>");
$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,"<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 ($_SESSION['login']) {
// show the template selection line
templateselect($techid,NULL);
}
// start note entry section
echo "
<form method=\"post\" action=\"logentry.php\">
<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's info in the link fields below the Note box and click Insert Link. You must provide the URL, but the link text is optional. \"><br>
<textarea rows=\"10\" cols=\"60\" name=\"note\" id=\"notetextarea\" wrap=\"soft\">";
if ($edit || $usertemplateid || $globaltemplateid || $schedmaintcomplete) echo "$note";
echo "</textarea><br>
<input type=\"text\" size=\"23\" id=\"linktextfield\" placeholder=\"Enter link text here\">&nbsp;
<input type=\"text\" size=\"23\" id=\"linkurlfield\" placeholder=\"Enter URL here\">&nbsp;
<a href=\"#\" onclick=\"insertUrlAtCaret('notetextarea','linktextfield','linkurlfield');return false;\">Insert Link</a><br>
";
// 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("<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>
";
if ($add && $refto) $refstring=$refto;
echo "
<br><br><b>References: </b>&nbsp;
<input type=\"text\" name=\"refstring\" size=\"20\" value=\"$refstring\" title=\"One or more Note ID numbers separated by spaces\">&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);
?>