175 lines
5.7 KiB
PHP
175 lines
5.7 KiB
PHP
<?php
|
|
/*
|
|
partentry.php
|
|
OpenLog Online Logbook
|
|
Copyright (C) 2026 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("functions.php");
|
|
|
|
|
|
if (!isset($_SESSION['login'])) {
|
|
header("Location: login.php");
|
|
}
|
|
|
|
$loggedinas = $_SESSION['login'];
|
|
$isadmin = dblookup($db, "techs", "techid", "admin", $loggedinas);
|
|
|
|
$print = $_REQUEST['print'] ?? NULL;
|
|
$add = $_REQUEST['add'] ?? NULL;
|
|
$edit = $_REQUEST['edit'] ?? NULL;
|
|
$delete = $_REQUEST['delete'] ?? NULL;
|
|
|
|
$partid = $_REQUEST['partid'] ?? NULL;
|
|
$uid = $_REQUEST['uid'] ?? NULL;
|
|
$partnum = $_REQUEST['partnum'] ?? NULL;
|
|
$sernum = $_REQUEST['sernum'] ?? NULL;
|
|
$partname = $_REQUEST['partname'] ?? NULL;
|
|
$submit = $_REQUEST['submit'] ?? NULL;
|
|
|
|
$logname = LOG_NAME;
|
|
$uidtext = UID_TEXT;
|
|
|
|
if ($print) {
|
|
$sbcolor = P_SIDEBAR_COLOR;
|
|
$mbgcolor = P_MENUBG_COLOR;
|
|
} else {
|
|
$sbcolor = SIDEBAR_COLOR;
|
|
$mbgcolor = MENUBG_COLOR;
|
|
}
|
|
if ($edit || $delete) {
|
|
framework("begin", "$logname", "Part Edit", $print);
|
|
} else {
|
|
$add = 1;
|
|
framework("begin", "$logname", "Part Entry", $print);
|
|
}
|
|
|
|
// ******** begin database manipulation ********
|
|
//var_dump($_REQUEST);
|
|
|
|
if ($add) {
|
|
if ($submit) {
|
|
// add the entry if submit is pressed
|
|
if ($uid || ($partnum && $sernum)) {
|
|
$partexists = mysqli_num_rows(mysqli_query($db, "select partid from parts where uid=\"$uid\" or (partnum=\"$partnum\" and sernum=\"$sernum\")"));
|
|
if (! $partexists) {
|
|
// add to parts table
|
|
mysqli_query($db, "insert into parts(uid,partnum,sernum,partname) values(\"$uid\",\"$partnum\",\"$sernum\",\"$partname\")");
|
|
$partid = mysqli_insert_id($db);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($edit) {
|
|
if ($submit) {
|
|
if ($uid || ($partnum && $sernum)) {
|
|
// update parts table
|
|
mysqli_query($db, "update parts set uid=\"$uid\", partnum=\"$partnum\", sernum=\"$sernum\", partname=\"$partname\" where partid=\"$partid\"");
|
|
}
|
|
}
|
|
}
|
|
if ($delete) {
|
|
// check for occurrence in logparts table
|
|
$inlogparts = mysqli_num_rows(mysqli_query($db, "select logpartid from logparts where partid=\"$partid\""));
|
|
// check for occurrence in maintforms table
|
|
$inmaintforms = mysqli_num_rows(mysqli_query($db, "select maintformid from maintforms where mfpart=\"$partid\""));
|
|
// delete from parts table
|
|
if (!$inlogparts && !$inmaintforms) {
|
|
mysqli_query($db, "delete from parts where partid=\"$partid\"");
|
|
}
|
|
}
|
|
|
|
// ******** end database manipulation ********
|
|
|
|
pagetable("begin");
|
|
if (!$print) {
|
|
pageblock("left", "begin");
|
|
sidemenu();
|
|
pageblock("left", "end");
|
|
}
|
|
pageblock("right", "begin");
|
|
banner($print);
|
|
// display the form
|
|
$partdatainput = array();
|
|
$partdatainput['partid'] = $partid;
|
|
$partinfo = get_part_data($partdatainput);
|
|
if ($partinfo['result'] == 2) {
|
|
$pdatamismatch = TRUE;
|
|
} else {
|
|
$pdatamismatch = FALSE;
|
|
$uid = (array_key_exists('uid', $partinfo)) ? $partinfo['uid'] : NULL;
|
|
$partnum = (array_key_exists('partnum', $partinfo)) ? $partinfo['partnum'] : NULL;
|
|
$sernum = (array_key_exists('sernum', $partinfo)) ? $partinfo['sernum'] : NULL;
|
|
$partname = (array_key_exists('partname', $partinfo)) ? $partinfo['partname'] : NULL;
|
|
}
|
|
if ($delete) {
|
|
if ($inmaintforms) {
|
|
echo "<br><img src=\"icons/exclamation-red.png\" border=\"0\"> Part has a maintenance form and cannot be deleted.<br><br>";
|
|
} elseif ($inlogparts) {
|
|
echo "<br><img src=\"icons/exclamation-red.png\" border=\"0\"> Part is referenced in a log note and cannot be deleted.<br><br>";
|
|
} else {
|
|
echo "<br>Part successfully deleted. <a href=\"parts.php\">Return to Parts</a>.<br>";
|
|
}
|
|
} else {
|
|
if ($submit) {
|
|
if ($add) {
|
|
if ($partexists) {
|
|
echo "<br><img src=\"icons/exclamation-red.png\" border=\"0\"> Part cannot be added because it already exists.<br><br>";
|
|
} else {
|
|
echo "<br>Part successfully added. <a href=\"parts.php\">Return to Parts</a>.<br>";
|
|
}
|
|
}
|
|
if ($edit) {
|
|
echo "<br>Part successfully modified. <a href=\"parts.php\">Return to Parts</a>.<br>";
|
|
}
|
|
}
|
|
echo "
|
|
<form method=\"post\" action=\"partentry.php\">
|
|
<table class=\"mfentry\" border=\"0\" cellpadding=\"8\">
|
|
<input type=\"hidden\" name=\"partid\" value=\"$partid\">
|
|
<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=\"2\" valign=\"bottom\"><b>Part Name:</b><br>
|
|
<input type=\"text\" name=\"partname\" size=\"40\" value=\"$partname\"></td>
|
|
</tr>
|
|
</table>
|
|
<hr>
|
|
";
|
|
if ($add) {
|
|
echo "
|
|
<table border=\"0\">
|
|
<input type=\"hidden\" name=\"add\" value=\"1\">
|
|
<input type=\"submit\" name=\"submit\" value=\"Add Part\">
|
|
</td></tr></table><br>";
|
|
} else {
|
|
echo "
|
|
<table border=\"0\" cellpadding=\"10\">
|
|
<tr>
|
|
<td valign=\"top\">
|
|
<input type=\"hidden\" name=\"edit\" value=\"1\">
|
|
<input type=\"hidden\" name=\"partid\" value=\"$partid\">
|
|
<input type=\"submit\" name=\"submit\" value=\"Modify Part Data\">
|
|
</td><td valign=\"top\">
|
|
<input type=\"submit\" name=\"delete\" value=\"Delete This Part\"><font color=\"#FF0000\"><br><b>Deleted parts are irretrievable!</b></font>
|
|
</td></tr>
|
|
</table>
|
|
";
|
|
}
|
|
}
|
|
echo "
|
|
</form>
|
|
";
|
|
banner($print);
|
|
pageblock("right", "end");
|
|
pagetable("end");
|
|
|
|
framework("end", "", "", $print);
|