Files
2026-02-17 09:29:34 -06:00

235 lines
9.0 KiB
PHP

<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="center">
<div class="header">
<h1>LASUCA CONTROLS</h1>
<p>Controls Database Search</p>
</div>
<div class="row">
<?php
include("session.php");
include("useraccess.php");
include("menuinclude.php");
?>
<div class="col-13">
<table border="1" style="margin: 0px auto;" width="900px">
<thead>
<tr><th></a></th></tr>
</thead>
<?php
// Configuration
$OPTIONS = [
'lbsperhr' => 'PPH/Ton',
'mainspd' => 'MCC Speed',
'mccoutput' => 'MCC Output',
'ttlstmflo' => 'Total Steam Flow',
'exhaustpr' => 'Exhaust Press',
'livstmpr' => 'Live Steam Press',
'prevtons' => 'Previous Tons',
'prevtime' => 'Previous Run Time',
'tonshr' => 'East Tons Per HR',
'WTONSHR' => 'West Tons Per HR',
'15minavg' => 'East Average Tons Per HR',
'W15MINAVG' => 'West Average Tons Per HR',
'avgtcd' => 'Average TCD',
'canetot' => 'East Tons Ground',
'WTOTGROUND' => 'West Tons Ground',
'syruprcvrlvl' => 'Syrup RCVR Lvl',
'syrupoverflow' => 'Syrup Overflow Lvl',
'amollvl' => 'A Molasses RCVR Lvl',
'amoloverflow' => 'A Molasses Overflow Lvl',
'molbreclvl' => 'B Molasses RCVR Lvl',
'bmoloverflow' => 'B Molasses Overflow Lvl',
'tdtotnorth' => 'North Dumps YTD',
'tdtotsouth' => 'South Dumps YTD',
'BBABONOFF' => 'Broadbent Run',
'BBTANKLVL' => 'Broadbent Tank Lvl',
'imb5sp' => 'Imibition 5 SP',
'imbsp' => 'Imibition 6 SP',
'mill1lvl' => 'Mill 1 Level',
'mill1spd' => 'East Mill 1 Speed',
'WMILL1SPD' => 'West Mill 1 Speed',
'mill1output' => 'Mill 1 Output',
'MILL1WSP' => 'Mill 1 Setpoint',
'mill2lvl' => 'Mill 2 Level',
'mill3lvl' => 'Mill 3 Level',
'mill4lvl' => 'Mill 4 Level',
'mill5lvl' => 'Mill 5 Level',
'mill6lvl' => 'Mill 6 Level',
'mill2spd' => 'Mill 2 RPM',
'mill3spd' => 'Mill 3 RPM',
'mill4spd' => 'Mill 4 RPM',
'mill5spd' => 'Mill 5 RPM',
'mill6spd' => 'Mill 6 RPM',
'knife1spd' => 'Knife 1 RPM',
'knife2spd' => 'Knife 2 RPM',
'knife3spd' => 'Knife 3 RPM'
];
// Function to create select options
function generateSelectOptions($name, $selected = '', $options) {
$html = "<select name=\"$name\" id=\"$name\" style=\"width: 132px;\" required>";
$html .= "<option value=\"empty\">Option " . substr($name, -1) . "</option>";
foreach ($options as $value => $label) {
$selectedAttr = ($value == $selected) ? ' selected' : '';
$html .= "<option value=\"$value\"$selectedAttr>$label</option>";
}
$html .= "</select>";
return $html;
}
// Handle form submission
if(isset($_POST['submit'])){
// Sanitize inputs
$inputs = ['yearmin', 'monthmin', 'daymin', 'hourmin', 'minutemin', 'secondmin',
'yearmax', 'monthmax', 'daymax', 'hourmax', 'minutemax', 'secondmax',
'option1', 'option2', 'option3', 'option4', 'option5', 'option6',
'accuracy'];
foreach ($inputs as $input) {
${$input} = isset($_POST[$input]) ? trim($_POST[$input]) : '';
}
// Validate date inputs
if (!checkdate((int)$monthmin, (int)$daymin, (int)$yearmin) ||
!checkdate((int)$monthmax, (int)$daymax, (int)$yearmax)) {
die("Invalid date format");
}
// Validate accuracy
$acc = max(1, (int)$acc);
include("dbinfo2.php");
$con = mysqli_connect($host, $username, $password, $database);
if (!$con) {
die('Connection failed: ' . mysqli_connect_error());
}
// Prepare timestamp range
$timestamp_min = "$yearmin-$monthmin-$daymin $hourmin:$minutemin:$secondmin";
$timestamp_max = "$yearmax-$monthmax-$daymax $hourmax:$minutemax:$secondmax";
// Build query with prepared statement approach
$query = "SELECT ? as option1, ? as option2, ? as option3, ? as option4, ? as option5, ? as option6, Z_TIMESTAMP
FROM milling
WHERE Z_TIMESTAMP BETWEEN ? AND ?
AND milling.id mod ? = 0
ORDER BY id DESC
LIMIT 1500";
// For demonstration purposes - you'd need to adjust this based on your actual requirements
$query = "SELECT `$option1` as option1, `$option2` as option2, `$option3` as option3, `$option4` as option4, `$option5` as option5, `$option6` as option6, Z_TIMESTAMP
FROM milling
WHERE Z_TIMESTAMP BETWEEN ? AND ?
AND milling.id mod ? = 0
ORDER BY id DESC
LIMIT 1500";
// Use prepared statements for security (this is a simplified example)
$stmt = mysqli_prepare($con, $query);
if ($stmt) {
mysqli_stmt_bind_param($stmt, "ssssi", $timestamp_min, $timestamp_max, $acc);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
echo '<table id="table" border="1" style="margin: 5px auto;" width="900px" class="green">';
echo "<thead>";
echo "<tr>";
echo "<th>Timestamp</th>";
echo "<th>" . ($option1 ? $OPTIONS[$option1] : '') . "</th>";
echo "<th>" . ($option2 ? $OPTIONS[$option2] : '') . "</th>";
echo "<th>" . ($option3 ? $OPTIONS[$option3] : '') . "</th>";
echo "<th>" . ($option4 ? $OPTIONS[$option4] : '') . "</th>";
echo "<th>" . ($option5 ? $OPTIONS[$option5] : '') . "</th>";
echo "<th>" . ($option6 ? $OPTIONS[$option6] : '') . "</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr align="center">';
echo "<td>".$row['Z_TIMESTAMP']."</td>";
echo "<td>".$row['option1']."</td>";
echo "<td>".$row['option2']."</td>";
echo "<td>".$row['option3']."</td>";
echo "<td>".$row['option4']."</td>";
echo "<td>".$row['option5']."</td>";
echo "<td>".$row['option6']."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_stmt_close($stmt);
}
mysqli_close($con);
} else {
// Display form
?>
<tr>
<th colspan="2">
<form action="" method="POST">
<p>Select date range</p>
<input type="text" placeholder="2024" name="yearmin" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['yearmin'] ?? ''); ?>" required />
<input type="text" placeholder="month... e.g. 09" name="monthmin" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['monthmin'] ?? ''); ?>" required />
<input type="text" placeholder="day... e.g. 13" name="daymin" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['daymin'] ?? ''); ?>" required />
<input type="text" placeholder="hour... e.g. 05" name="hourmin" style="width: 132px;" value="00"/>
<input type="text" placeholder="minute... e.g. 10" name="minutemin" style="width: 132px;" value="00"/>
<input type="text" placeholder="second... e.g. 10" name="secondmin" style="width: 132px;" value="00" />
<br><p>TO</p>
<input type="text" placeholder="2024" name="yearmax" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['yearmax'] ?? ''); ?>" required />
<input type="text" placeholder="month... e.g. 09" name="monthmax" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['monthmax'] ?? ''); ?>" required />
<input type="text" placeholder="day... e.g. 13" name="daymax" style="width: 132px;" value="<?php echo htmlspecialchars($_POST['daymax'] ?? ''); ?>" required />
<input type="text" placeholder="hour... e.g. 05" name="hourmax" style="width: 132px;" value="00"/>
<input type="text" placeholder="minute... e.g. 10" name="minutemax" style="width: 132px;" value="00"/>
<input type="text" placeholder="second... e.g. 10" name="secondmax" style="width: 132px;" value="00" />
<br><p>AS</p>
<?php
// Generate selects using the function
for ($i = 1; $i <= 6; $i++) {
echo generateSelectOptions("option$i", $_POST["option$i"] ?? '', $OPTIONS);
echo "<br>";
}
?>
<p>display every <input type="text" name="accuracy" value="20" placeholder="Accuracy" /> row(s)</p>
<input type="submit" name="submit" value="Submit" />
<p>20 rows = approximately 1 minute</p>
<p>Results limited to 1500 rows.</p>
</form>
</th>
</tr>
<?php
}
?>
</table>
</div>
</div>
<?php include 'footer.php';?>
<script type="text/javascript">
// create the back to top button
$('body').prepend('<a href="#" class="back-to-top">Back to Top</a>');
var amountScrolled = 300;
$(window).scroll(function() {
if ($(window).scrollTop() > amountScrolled) {
$('a.back-to-top').fadeIn('slow');
} else {
$('a.back-to-top').fadeOut('slow');
}
});
$('a.back-to-top, a.simple-back-to-top').click(function() {
$('body').animate({
scrollTop: 0
}, 'fast');
return false;
});
</script>
</body>
</html>