Files
OpenLog/distfiles/maintformentry.php

674 lines
27 KiB
PHP

<?php
/*
maintformentry.php
OpenLog Online Logbook
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("functions.php");
if (!$_SESSION['login'] && ($_REQUEST['mfadd'] || $_REQUEST['actionadd'])) {
header("Location: login.php");
}
$loggedinas = $_SESSION['login'];
$isadmin = dblookup($db, "techs", "techid", "admin", $loggedinas);
function getmfdata($maintformid)
{
// pull maintenance form data from maintforms table
global $db;
$mfdata = mysqli_fetch_assoc(mysqli_query($db, "select * from maintforms where maintformid=\"$maintformid\""));
return $mfdata;
}
function getactiondata($maintactionid)
{
// pull maintenance action data from maintactions table
global $db;
$actiondata = mysqli_fetch_assoc(mysqli_query($db, "select * from maintactions where maintactionid=\"$maintactionid\""));
return $actiondata;
}
$print = $_REQUEST['print'] ?? NULL;
$maintformid = $_REQUEST['maintformid'] ?? NULL;
$lognoteid = $_REQUEST['lognoteid'] ?? NULL;
$mfdate = $_REQUEST['date'] ?? NULL;
$mftime = $_REQUEST['time'] ?? NULL;
$mfsubmit = $_REQUEST['mfsubmit'] ?? NULL;
$mfadd = $_REQUEST['mfadd'] ?? NULL;
$mfedit = $_REQUEST['mfedit'] ?? NULL;
$mfdelete = $_REQUEST['mfdelete'] ?? NULL;
$mfpartloc = $_REQUEST['mfpartloc'] ?? NULL;
$mfmalfunction = $_REQUEST['mfmalfunction'] ?? NULL;
$nha = $_REQUEST['nha'] ?? NULL;
$repord = $_REQUEST['repord'] ?? NULL;
$mfpart = $_REQUEST['mfpart'] ?? NULL;
$uid = $_REQUEST['uid'] ?? NULL;
$partnum = $_REQUEST['partnum'] ?? NULL;
$sernum = $_REQUEST['sernum'] ?? NULL;
$partname = $_REQUEST['partname'] ?? NULL;
$actionadd = $_REQUEST['actionadd'] ?? NULL;
$actionedit = $_REQUEST['actionedit'] ?? NULL;
$actiondelete = $_REQUEST['actiondelete'] ?? NULL;
$maintactionid = $_REQUEST['maintactionid'] ?? NULL;
$actiondate = $_REQUEST['actiondate'] ?? NULL;
$actiontime = $_REQUEST['actiontime'] ?? NULL;
$actiontech = $_REQUEST['actiontech'] ?? NULL;
$action = $_REQUEST['action'] ?? NULL;
$actionaddsubmit = $_REQUEST['actionaddsubmit'] ?? NULL;
$actioneditsubmit = $_REQUEST['actioneditsubmit'] ?? NULL;
$printfmt = $_REQUEST['printfmt'] ?? NULL;
if ($printfmt) $print = TRUE;
$flags = $_POST['flags'] ?? [];
$logname = LOG_NAME;
$uidtext = UID_TEXT;
if ($print) {
$sbcolor = P_SIDEBAR_COLOR;
$mbgcolor = P_MENUBG_COLOR;
} else {
$sbcolor = SIDEBAR_COLOR;
$mbgcolor = MENUBG_COLOR;
}
if ($printfmt) {
framework("begin", "", "", $print);
} else if ($mfedit) {
framework("begin", "$logname", "Maintenance Form Edit", $print);
if ($loggedinas) $mfauthorized = TRUE;
} else if ($mfdelete) {
framework("begin", "$logname", "Maintenance Form Edit", $print);
$mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid);
if (($loggedinas == $mfowner) || $isadmin) $mfauthorized = TRUE;
} else if ($actionadd) {
framework("begin", "$logname", "Maintenance Action Entry", $print);
$mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid);
if ($loggedinas) {
$mfauthorized = TRUE;
$actionauthorized = TRUE;
}
} else if ($actionedit || $actiondelete) {
framework("begin", "$logname", "Maintenance Action Edit", $print);
$mfowner = dblookup($db, "maintforms", "maintformid", "mftech", $maintformid);
if ($loggedinas) $mfauthorized = TRUE;
$actionowner = dblookup($db, "maintactions", "maintactionid", "actiontech", $maintactionid);
if (($loggedinas == $actionowner) || $isadmin) $actionauthorized = TRUE;
} else {
$mfadd = TRUE;
framework("begin", "$logname", "Maintenance Form Entry", $print);
$mftech = $loggedinas;
$mfauthorized = TRUE;
}
// ******** begin database manipulation ********
//var_dump($_REQUEST);
$pdatamismatch = NULL;
if ((($mfedit || $actionadd || $actionedit) && ! $mfsubmit) || $printfmt) {
// pull mf data from database
$mftoedit = getmfdata($maintformid);
$partdatainput = [];
if ($mftoedit['mfpart']) $partdatainput['partid'] = $mftoedit['mfpart'];
if ($uid) $partdatainput['uid'] = $uid;
if ($partnum) $partdatainput['partnum'] = $partnum;
if ($sernum) $partdatainput['sernum'] = $sernum;
$partinfo = get_part_data($partdatainput);
if ($partinfo['result'] == 2) {
$pdatamismatch = TRUE;
} else {
$pdatamismatch = FALSE;
if ($partinfo['partid']) $mfpart = $partinfo['partid'];
if ($partinfo['uid']) $uid = $partinfo['uid'];
if ($partinfo['partnum']) $partnum = $partinfo['partnum'];
if ($partinfo['sernum']) $sernum = $partinfo['sernum'];
if ($partinfo['partname']) $partname = $partinfo['partname'];
}
}
if ($mfadd) {
if ($mfsubmit) {
// add the entry if submit is pressed
if ($mfmalfunction && ($uid || ($partnum && $sernum))) {
// sanitize and fix blank date and time
$mfdate = fix_date($mfdate);
$mftime = fix_time($mftime);
// determine whether supplied date is future or past
$datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$mfdate\",CURRENT_DATE)"));
// if future, set time to 00:00:01, if past, set to 23:59:59
if ($datediff[0] < 0) {
$mftime = "23:59:59:";
}
if ($datediff[0] > 0) {
$mftime = "00:00:01:";
}
// remove cruft from malfunction text
$mfmalfunction = htmlentities($mfmalfunction);
$mfmalfunction = addslashes($mfmalfunction);
if ($mfauthorized) {
$partdatainput = array();
if ($uid) $partdatainput['uid'] = $uid;
if ($partnum) $partdatainput['partnum'] = $partnum;
if ($sernum) $partdatainput['sernum'] = $sernum;
$partinfo = get_part_data($partdatainput);
// add to parts table
if ($partinfo['result'] == 1) {
// if this part has not been seen before, add it to the parts table and get partid
mysqli_query($db, "insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")");
$mfpart = mysqli_insert_id($db);
} else if ($partinfo['result'] == 2) {
$pdatamismatch = TRUE;
} else {
// if it is in parts table, get partid for this record
$pdatamismatch = FALSE;
$mfpart = $partinfo['partid'];
}
if ($uid == "" || $partnum == "" || $sernum == "") {
// have the maintenance form stay pending due to incomplete part data
$pending = 1;
} else {
$pending = 0;
}
// add the record to maintforms
if (! $pdatamismatch) {
mysqli_query($db, "insert into maintforms(mfdate,mftime,mftech,mfpart,mfpartloc,mfmalfunction,nha,repord,lognoteid,pending)
values (\"$mfdate\", \"$mftime\",\"$loggedinas\",\"$mfpart\",\"$mfpartloc\",\"$mfmalfunction\",\"$nha\",\"$repord\",\"$lognoteid\",\"$pending\")");
$newmaintformid = mysqli_insert_id($db);
$mfidtoprint = $newmaintformid;
// update the flagmap table
foreach ($flags as $thisflag) {
// set flag for this maintenance form
mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$$newmaintformid\")");
}
}
}
}
}
}
if ($mfedit) {
$mfidtoprint = $maintformid;
if ($mfsubmit && $mfauthorized) {
if ($mfmalfunction && ($uid || ($partnum && $sernum))) {
// remove cruft from malfunction text
$mfmalfunction = htmlentities($mfmalfunction);
$mfmalfunction = addslashes($mfmalfunction);
// update parts table
if ($uid == "" || $partnum == "" || $sernum == "") {
// have the maintenance form stay pending due to incomplete part data
$pending = 1;
} else {
$pending = 0;
}
if (! $pdatamismatch) {
mysqli_query($db, "update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$mfpart\"");
}
// update the record in maintforms
if (! $pdatamismatch) {
mysqli_query($db, "update maintforms set mfdate=\"$mfdate\", mftime=\"$mftime\", mfpart=\"$mfpart\", mfpartloc=\"$mfpartloc\",
mfmalfunction=\"$mfmalfunction\", nha=\"$nha\", repord=\"$repord\", lognoteid=\"$lognoteid\", pending=\"$pending\" where maintformid=\"$maintformid\"");
// update the flagmap table
mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\"");
foreach ($flags as $thisflag) {
// set flag for this maintenance form
mysqli_query($db, "insert into flagmap(flagid,maintformid) values(\"$thisflag\",\"$maintformid\")");
}
}
}
}
// refresh the maintenance form in question from the database
$mftoedit = getmfdata($maintformid);
}
if ($mfdelete && $mfauthorized) {
// delete from maintforms table
mysqli_query($db, "delete from maintforms where maintformid=\"$maintformid\"");
// delete occurances from the flagmap table
mysqli_query($db, "delete from flagmap where maintformid=\"$maintformid\"");
}
if ($actionadd) {
if ($actionaddsubmit) {
if ($action) {
// sanitize and fix blank date and time
$actiondate = fix_date($actiondate);
$actiontime = fix_time($actiontime);
// determine whether supplied date is future or past
$datediff = mysqli_fetch_row(mysqli_query($db, "select datediff(\"$actiondate\",CURRENT_DATE)"));
// if future, set time to 00:00:01, if past, set to 23:59:59
if ($datediff[0] < 0) {
$actiontime = "23:59:59:";
}
if ($datediff[0] > 0) {
$actiontime = "00:00:01:";
}
// remove cruft from action text
$action = htmlentities($action);
$action = addslashes($action);
// add to maintactions table
mysqli_query($db, "insert into maintactions (actiondate,actiontime,maintformnum,actiontech,action)
values (\"$actiondate\",\"$actiontime\",\"$maintformid\",\"$loggedinas\",\"$action\")");
echo mysqli_error($db);
}
}
}
if ($actionedit) {
if ($actioneditsubmit && $actionauthorized) {
// update the action
// sanitize and fix blank date and time
$actiondate = fix_date($actiondate);
$actiontime = fix_time($actiontime);
// remove cruft from action text
$action = htmlentities($action);
$action = addslashes($action);
// update maintactions table
mysqli_query($db, "update maintactions set actiondate=\"$actiondate\", actiontime=\"$actiontime\", action=\"$action\" where maintactionid=\"$maintactionid\"");
}
// refresh the action in question from the database
$actiontoedit = getactiondata($maintactionid);
}
if ($actiondelete && $actionauthorized) {
// delete the action
mysqli_query($db, "delete from maintactions where maintactionid=\"$maintactionid\"");
}
// ******** end database manipulation ********
pagetable("begin");
if (!$print) {
pageblock("left", "begin");
sidemenu();
pageblock("left", "end");
}
pageblock("right", "begin");
banner($print);
// display the form
if ($mfadd || $actionadd) {
$mfdate = $today;
$mftime = $now;
$actiondate = $today;
$actiontime = $now;
}
if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) {
$mfdate = $mftoedit["mfdate"];
$mftime = $mftoedit["mftime"];
$mfpart = $mftoedit["mfpart"];
$mfpartloc = $mftoedit["mfpartloc"];
$mfmalfunction = $mftoedit["mfmalfunction"];
$nha = $mftoedit["nha"];
$repord = $mftoedit["repord"];
$lognoteid = $mftoedit["lognoteid"];
if ($mfedit || $mfdelete || $actionadd || $actionedit || $actiondelete || $printfmt) $mftech = $mftoedit["mftech"];
if (! $mftime) $mftime = $now;
}
if (($mfedit || $actionadd || $actionedit) && ! ($mfsubmit || $actionaddsubmit || $actioneditsubmit)) {
$partinfo = array();
$partinfoinput['partid'] = $mfpart;
$partinfo = get_part_data($partinfoinput);
$mfpart = $partinfo['partid'];
$uid = $partinfo['uid'];
$partnum = $partinfo['partnum'];
$sernum = $partinfo['sernum'];
$partname = $partinfo['partname'];
$pluresult = $partinfo['result'];
if ($pluresult == 2) $pdatamismatch = TRUE;
else $pdatamismatch = FALSE;
}
$techname = dblookup($db, "techs", "techid", "techname", $mftech);
if ($mfsubmit) {
if ($mfmalfunction) {
if (($uid || ($partnum && $sernum)) || $mfpart) {
if ($mfadd) {
format_message(0, "Maintenance Form added. You may enter another one or <a href=\"maintform.php\">return to Maintenance Forms page.</a>");
}
if ($mfedit) {
format_message(0, "Maintenance Form changed. <a href=\"maintform.php\">Return to Maintenance Forms page.</a>");
}
} else {
format_message(1, "You didn't enter any part information. Please try again.");
}
} else {
format_message(1, "You didn't enter any malfunction description. Please try again.");
}
}
if ($mfdelete) {
format_message(0, "Maintenance Form Deleted. <a href=\"maintform.php\">Return to Maintenance Forms page.</a>");
}
if ($pdatamismatch) {
$advtxt = "
<img src=\"icons/exclamation-red.png\" border=\"0\">&nbsp;
<b>Warning:</b> The $uidtext doesn't match the Part Number/Serial Number associated
with it in our database. Please ensure the part information
you entered is correct and try again. If you know it to be correct, please use
the <a href=\"parts.php\">Parts</a> page to correct the database.</b>
";
} else {
$advtxt = "
<font size=\"-1\">You can enter a $uidtext or Part Number/Serial Number or both.</font>
";
}
if ($printfmt) {
// show entire maint form
echo "
<hr>
<table width=\"100%\" border=\"0\">
<tr><td align=\"center\"><font size=\"+1\"><b>Maintenance Form</b></font></td></tr>
</table>
<hr>
<table width=\"100%\" border=\"0\">
<tr><td><b>Form ID:</b><br> $maintformid </td><td><b>Date:</b><br> $mfdate </td><td><b>Time:</b><br> $mftime </td><td><b> Tech:</b><br> $techname </td><td><b>Log Note ID:</b><br> $lognoteid </td><td><b>Repair Order:</b><br> $repord </td></tr>
</table><hr>
<table width=\"100%\" border=\"0\">
<tr><td colspan=\"4\"><b><u>Part Data</u></b><br><br></td></tr>
<tr><td><b>$uidtext:</b><br> $uid </td><td><b>Part Number:</b><br> $partnum </td><td><b>Serial Number:</b><br> $sernum </td><td><b>Part Name:</b><br> $partname </td></tr>
<tr><td><b>Part Location:</b><br> $mfpartloc </td><td><b>Next Higher Assembly:</b><br> $nha </td></tr>
</table><hr>
<b><u>Malfuction Description</u></b><br>
<table width=\"100%\" border=\"0\">
<tr><td>$mfmalfunction</td></tr>
</table><br>
<b><u>Flags</u></b><br>
<table width=\"100%\" border=\"0\">
";
// create an array called theseflags of flagids set for this maintformid
$allflags = mysqli_query($db, "select flagid from flags");
unset($theseflags);
$theseflags = [];
while ($thisflag = mysqli_fetch_row($allflags)) {
if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) {
$theseflags[] = $thisflag[0];
}
}
// display flag symbols for set flags
$flagslist = mysqli_query($db, "select * from flags");
while ($flagsymbol = mysqli_fetch_assoc($flagslist)) {
if ($theseflags[0] == "") $theseflags = [];
if (!empty($theseflags) && in_array($flagsymbol["flagid"], $theseflags)) {
echo $flagsymbol['flagsym'] . "&nbsp;&nbsp;";
}
}
echo "
</table><hr>
<b><u>Maintenance Actions</u></b><br>
";
$maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc");
while ($actiontable = mysqli_fetch_assoc($maintactionqry)) {
$actiondate = $actiontable["actiondate"];
$actiontime = $actiontable["actiontime"];
$tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]);
$actiontext = convertweblinks($actiontable["action"]);
// print the actions
echo "<table border=\"0\" cellpadding=\"5\">
<tr>
<td><b>Tech:</b>&nbsp;&nbsp;$tname</td>
<td><b>Date:</b>&nbsp;&nbsp;$actiondate</td>
<td><b>Time:</b>&nbsp;&nbsp;$actiontime</td>
</tr></table>
<table width=\"100%\" border=\"0\" cellpadding=\"5\">
<tr>
<td colspan=\"4\">$actiontext</td>
</tr>
</table>
<hr>
";
}
} else {
echo "
<form method=\"post\" action=\"maintformentry.php\">
<table class=\"mfentry\" border=\"0\" cellpadding=\"8\">
<tr>
<td valign=\"bottom\"><b>Date <br><font size=\"-1\">(YYYY-MM-DD):</font></b><br>
<input type=\"text\" name=\"date\" size=\"10\" maxlength=\"10\" id=\"singledatepicker\" value=\"$mfdate\"></td>
<td valign=\"bottom\"><b>Time:</b><br>
<input type=\"text\" name=\"time\" size=\"8\" maxlength=\"8\" value=\"$mftime\"></td>
<td valign=\"bottom\"><b>Tech:</b><br>
$techname</td>
<td valign=\"bottom\"><b>Log Note ID:</b><br>
<input type=\"text\" name=\"lognoteid\" size=\"8\" value=\"$lognoteid\"></td>
</tr>
</table>
<table class=\"mfentry\" border=\"0\" cellpadding=\"8\">
<tr>
<td class=\"forcewrap\" colspan=\"3\"><font size=\"-1\">$advtxt</td>
</tr>
<input type=\"hidden\" name=\"mfpart\" value=\"$mfpart\">
<tr>
<td valign=\"bottom\"><b>$uidtext:</b><br>
<input type=\"text\" name=\"uid\" size=\"8\" value=\"$uid\"></td>
<td valign=\"bottom\"><b>Part Number:</b><br>
<input type=\"text\" name=\"partnum\" size=\"20\" value=\"$partnum\"></td>
<td valign=\"bottom\"><b>Serial Number:</b><br>
<input type=\"text\" name=\"sernum\" size=\"20\" value=\"$sernum\"></td>
</tr><tr>
<td colspan=\"3\" valign=\"bottom\"><b>Part Name:</b><br>
<input type=\"text\" name=\"partname\" size=\"80\" value=\"$partname\"></td>
</tr><tr>
<td valign=\"bottom\"><b>Part Location:</b><br>
<input type=\"text\" name=\"mfpartloc\" size=\"20\" value=\"$mfpartloc\"></td>
<td valign=\"bottom\"><b>Next Higher Assembly:</b><br>
<input type=\"text\" name=\"nha\" size=\"20\" value=\"$nha\"></td>
<td valign=\"bottom\"><b>Repair Order:</b><br>
<input type=\"text\" name=\"repord\" size=\"12\" value=\"$repord\"></td>
</tr></table>
<hr>
<table border=\"0\" cellpadding=\"8\">
<tr><td><b>Malfunction Description:</b></td></tr>
<tr><td><textarea rows=\"4\" cols=\"65\" name=\"mfmalfunction\" wrap=\"soft\">$mfmalfunction</textarea></td></tr>
<tr><td>
";
// create an array called theseflags of flagids set for this maintformid
$allflags = mysqli_query($db, "select flagid from flags");
unset($theseflags);
$theseflags = [];
while ($thisflag = mysqli_fetch_row($allflags)) {
if (mysqli_num_rows(mysqli_query($db, "select id from flagmap where flagid=\"$thisflag[0]\" and maintformid=\"$maintformid\""))) {
$theseflags[] = $thisflag[0];
}
}
if ($mfadd) {
$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 ($theseflags[0]=="") $theseflags=[];
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 "
</td></tr>
<tr><td>
";
if ($mfadd) {
if ($mfauthorized) {
echo "
<input type=\"hidden\" name=\"mfadd\" value=\"1\">
<input type=\"submit\" name=\"mfsubmit\" value=\"Submit Maintenance Form\">
</td></tr>
";
}
if ($mfsubmit) {
echo "
<tr><td><a href=\"maintformentry.php?printfmt=1&maintformid=$mfidtoprint\" target=\"_blank\">Print This Maintenance Form</a></td></tr>
";
}
echo "</table><br>";
} else {
if ($mfauthorized) {
echo "
<table border=\"0\">
<tr>
<td valign=\"top\">
<input type=\"hidden\" name=\"mfedit\" value=\"1\">
<input type=\"hidden\" name=\"maintformid\" value=\"$maintformid\">
<input type=\"submit\" name=\"mfsubmit\" value=\"Change This Maintenance Form\">
</td><td valign=\"top\">
<input type=\"submit\" name=\"mfdelete\" value=\"Delete This Maintenance Form\"><font color=\"#FF0000\"><br><b>Deleted maintenance forms are irretrievable!</b></font>
</td></tr>
<tr><td><a href=\"maintformentry.php?printfmt=1&maintformid=$mfidtoprint\" target=\"_blank\">Print This Maintenance Form</a></td></tr>
</table>
";
} else {
echo "
<br>Only the owner of a maintenance form or an administrator can delete it.<br><br>
<input type=\"hidden\" name=\"maintformid\" value=\"$maintformid\">
<a href=\"maintformentry.php?printfmt=1&maintformid=$mfidtoprint\" target=\"_blank\">Print This Maintenance Form</a>
";
}
echo "
</td></tr></table>
";
}
echo "
</form>
<hr>
<form method=\"post\" action=\"maintformentry.php?maintformid=$maintformid\">";
if ($actionadd || $actionedit) {
// show the action form
if ($actionadd) {
$matime = $now;
$actiontext = "";
$actiontech = $loggedinas;
} else if ($actionedit) {
$actiontext = $actiontoedit['action'];
$actiontech = $actiontoedit['actiontech'];
$actiondate = $actiontoedit['actiondate'];
$actiontime = $actiontoedit['actiontime'];
}
$tname = dblookup($db, "techs", "techid", "techname", $actiontech);
echo "<table width=\"70\" border=\"0\" cellpadding=\"5\">
<tr>
<td>Tech:&nbsp;&nbsp;$tname
<input type=\"hidden\" name=\"actiontech\" value=\"$actiontech\">
</td>
<td><Date <font size=\"-1\">(YYYY-MM-DD):</font> &nbsp;
<input type=\"text\" name=\"actiondate\" size=\"10\" maxlength=\"10\" value=\"$actiondate\">
</td>
<td>Time: &nbsp;
<input type=\"text\" name=\"actiontime\" size=\"8\" maxlength=\"8\" value=\"$actiontime\">
</td>
</tr>
<tr>
<td colspan=\"3\">Action Taken:<br>
<textarea rows=\"4\" cols=\"65\" name=\"action\" wrap=\"soft\">$actiontext</textarea>
</td>
</tr>
</table><br>
";
if ($actionadd) {
echo "
<input type=\"hidden\" name=\"actionadd\" value=\"1\">
<input type=\"submit\" name=\"actionaddsubmit\" value=\"Add This Action\">
<hr>
";
} else if ($actionedit) {
echo "
<input type=\"hidden\" name=\"maintformid\" value=\"$maintformid\">
<input type=\"hidden\" name=\"maintactionid\" value=\"$maintactionid\">
<input type=\"hidden\" name=\"actionedit\" value=\"1\">
<input type=\"submit\" name=\"actioneditsubmit\" value=\"Change This Action\">
";
}
echo "
<br><br>
";
}
echo "<b>Maintenance Actions</b>&nbsp;&nbsp;&nbsp;&nbsp;";
if ($_SESSION['login'] && $maintformid) echo "<input type=\"submit\" name=\"actionadd\" value=\"Add New Action\">";
echo "<br><br>";
$maintactionqry = mysqli_query($db, "select * from maintactions where maintformnum=\"$maintformid\" order by actiondate asc, actiontime asc");
while ($actiontable = mysqli_fetch_assoc($maintactionqry)) {
$maintactionid = $actiontable["maintactionid"];
$actiondate = $actiontable["actiondate"];
$actiontime = $actiontable["actiontime"];
$maintformnum = $actiontable["maintformnum"];
$tname = dblookup($db, "techs", "techid", "techname", $actiontable["actiontech"]);
$actiontext = convertweblinks($actiontable["action"]);
// print the table
echo "<table width=\"100%\" border=\"1\" cellpadding=\"5\">
<tr><td>
";
if (($loggedinas == $actiontable["actiontech"]) || $isadmin) {
echo "
<a href=\"maintformentry.php?maintformid=$maintformid&actionedit=1&maintactionid=$maintactionid\"><img src=\"icons/notebook--pencil.png\" border=\"0\" title=\"Edit this action\" alt=\"Edit this action\"></a>&nbsp;&nbsp;
<a href=\"maintformentry.php?maintformid=$maintformid&actiondelete=1&maintactionid=$maintactionid\"><img src=\"icons/minus-button.png\" border=\"0\" title=\"Delete this action\" alt=\"Delete this action\"></a>
";
} else {
echo "
<img src=\"icons/notebook--pencil.png\" border=\"0\" title=\"Only the owner or an admin can edit an action\" alt=\"Only the owner or an admin can edit an action\">
<img src=\"icons/minus-button.png\" border=\"0\" title=\"Only the owner or an admin can delete an action\" alt=\"Only the owner or an admin can delete an action\">
";
}
echo "
</td>
<td>Tech:&nbsp;&nbsp;$tname</td>
<td>Date:&nbsp;&nbsp;$actiondate</td>
<td>Time:&nbsp;&nbsp;$actiontime</td>
</tr>
<tr>
<td colspan=\"4\">$actiontext</td>
</tr>
</table><br>
";
}
echo "
</form>
";
}
banner($print);
pageblock("right", "end");
pagetable("end");
framework("end", "", "", $print);