Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 117 additions & 45 deletions public/all_processing_submit.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,132 @@
<?php
require_once('connect.php');
declare(strict_types=1);

$Name = filter_var($_POST['Name'], FILTER_SANITIZE_STRING);
require_once 'connect.php';

$traytemp = filter_var($_POST['TrayLocation'], FILTER_SANITIZE_STRING);
date_default_timezone_set('America/New_York');

$TrayLocation = filter_var($_POST['TrayLocation'], FILTER_SANITIZE_STRING);
$TrayLocation = !empty($TrayLocation) ? "'$TrayLocation'" : "NULL";

// echo $traytemp;

$sql = "SELECT ptraylocation FROM ProcessingAll WHERE ptraylocation = '$traytemp'";
$i = 0;
$query = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($query))
{
$i = $i + 1;
if (!isset($conn) || !($conn instanceof mysqli)) {
die('Database connection not available.');
}


if($i > 0)

header( 'Location: processing.php?submit=false' ) ;

else {


$Count = filter_var($_POST['Count'], FILTER_SANITIZE_STRING);
$Full = filter_var($_POST['Full'], FILTER_SANITIZE_STRING);
$Full = !empty($Full) ? "'$Full'" : "NULL";
$Verify = filter_var($_POST['Verify'], FILTER_SANITIZE_STRING);
$Checked = filter_var($_POST['Checked'], FILTER_SANITIZE_STRING);
$Library = filter_var($_POST['Library'], FILTER_SANITIZE_STRING);
$Name = trim((string)($_POST['Name'] ?? ''));
$traytemp = trim((string)($_POST['TrayLocation'] ?? ''));
$Count = trim((string)($_POST['Count'] ?? ''));
$Full = trim((string)($_POST['Full'] ?? ''));
$Verify = trim((string)($_POST['Verify'] ?? ''));
$Checked = trim((string)($_POST['Checked'] ?? ''));
$Library = trim((string)($_POST['Library'] ?? ''));

if ($Library === '' || $traytemp === '' || $Count === '' || $Checked === '' || $Verify === '') {
header('Location: processing.php?submit=blank');
exit;
}

$PCode = substr($traytemp, -2);
$timestamp = date('Y-m-d H:i:s');

/*
|--------------------------------------------------------------------------
| Check for duplicate tray/shelf barcode
|--------------------------------------------------------------------------
*/
$checkSql = "SELECT 1 FROM ProcessingAll WHERE ptraylocation = ? LIMIT 1";
$checkStmt = $conn->prepare($checkSql);

if (!$checkStmt) {
die('Prepare failed: ' . $conn->error);
}

$checkStmt->bind_param('s', $traytemp);
$checkStmt->execute();
$checkResult = $checkStmt->get_result();
$isDuplicate = $checkResult instanceof mysqli_result && $checkResult->num_rows > 0;
$checkStmt->close();

if($Library =='' OR $traytemp =='' OR $Count =='' OR $Checked =='' OR $Verify =='')
header( 'Location: processing.php?submit=blank' ) ;

else {


$sql = "INSERT INTO ProcessingAll (ProcessingKey, ptimestamp, pname, ptraylocation, pcode, pcount, pfull, pverify, pchecked, plibrary, cctimestamp, ccname, cccount, ccverify, ccchecked) VALUES (NULL, CURRENT_TIMESTAMP, '$Name', $TrayLocation, '$PCode', '$Count', $Full, '$Verify', '$Checked', '$Library', NULL, NULL, NULL, NULL, NULL)";

if ($conn->query($sql) === TRUE) {
header( 'Location: processing.php?submit=true' ) ;

} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
if ($isDuplicate) {
header('Location: processing.php?submit=false');
exit;
}

/*
|--------------------------------------------------------------------------
| Normalize nullable fields
|--------------------------------------------------------------------------
*/
$fullValue = ($Full !== '') ? $Full : null;

/*
|--------------------------------------------------------------------------
| Insert record
|--------------------------------------------------------------------------
*/
$insertSql = "
INSERT INTO ProcessingAll (
ProcessingKey,
ptimestamp,
pname,
ptraylocation,
pcode,
pcount,
pfull,
pverify,
pchecked,
plibrary,
cctimestamp,
ccname,
cccount,
ccverify,
ccchecked,
updated
) VALUES (
NULL,
?,
?,
?,
?,
?,
?,
?,
?,
?,
NULL,
NULL,
NULL,
NULL,
NULL,
?
)
";

$insertStmt = $conn->prepare($insertSql);

if (!$insertStmt) {
die('Prepare failed: ' . $conn->error);
}
$conn->close();

mysqli_close($conn);
$insertStmt->bind_param(
'ssssssssss',
$timestamp, // ptimestamp
$Name, // pname
$traytemp, // ptraylocation
$PCode, // pcode
$Count, // pcount
$fullValue, // pfull
$Verify, // pverify
$Checked, // pchecked
$Library, // plibrary
$timestamp // updated
);

if ($insertStmt->execute()) {
$insertStmt->close();
$conn->close();
header('Location: processing.php?submit=true');
exit;
}

$error = $insertStmt->error;
$insertStmt->close();
$conn->close();

?>
echo 'Error: ' . htmlspecialchars($error, ENT_QUOTES, 'UTF-8');
Loading
Loading