Folder reorganize 1
This commit is contained in:
373
reports/mill-names-admin.php
Normal file
373
reports/mill-names-admin.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php // phpcs:ignoreFile
|
||||
/**
|
||||
* Mill Names Admin - Manage mill code to display name mappings
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../session.php';
|
||||
require __DIR__ . '/../userAccess.php';
|
||||
|
||||
// Only allow admin or controls
|
||||
if ($_SESSION['SESS_MEMBER_LEVEL'] < 4) {
|
||||
header("Location: ../access-denied.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$config = [
|
||||
'server' => '192.168.0.16',
|
||||
'database' => 'lasucaai',
|
||||
'username' => 'lasucaai',
|
||||
'password' => 'is413#dfslw',
|
||||
];
|
||||
|
||||
$connectionOptions = [
|
||||
"Database" => $config['database'],
|
||||
"Uid" => $config['username'],
|
||||
"PWD" => $config['password'],
|
||||
"TrustServerCertificate" => true,
|
||||
"Encrypt" => false,
|
||||
];
|
||||
|
||||
$conn = sqlsrv_connect($config['server'], $connectionOptions);
|
||||
|
||||
if ($conn === false) {
|
||||
die("Connection failed: " . print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
$message = '';
|
||||
$messageType = '';
|
||||
|
||||
// Handle form submissions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['action'])) {
|
||||
switch ($_POST['action']) {
|
||||
case 'update':
|
||||
$millId = intval($_POST['mill_id']);
|
||||
$displayName = trim($_POST['display_name']);
|
||||
$sortOrder = intval($_POST['sort_order']);
|
||||
$isActive = isset($_POST['is_active']) ? 1 : 0;
|
||||
|
||||
$sql = "UPDATE mill_names SET display_name = ?, sort_order = ?, is_active = ? WHERE mill_id = ?";
|
||||
$result = sqlsrv_query($conn, $sql, [$displayName, $sortOrder, $isActive, $millId]);
|
||||
|
||||
if ($result) {
|
||||
$message = "Mill name updated successfully!";
|
||||
$messageType = 'success';
|
||||
} else {
|
||||
$message = "Error updating: " . print_r(sqlsrv_errors(), true);
|
||||
$messageType = 'error';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$millCode = trim($_POST['mill_code']);
|
||||
$displayName = trim($_POST['display_name']);
|
||||
$sortOrder = intval($_POST['sort_order']);
|
||||
|
||||
$sql = "INSERT INTO mill_names (mill_code, display_name, sort_order) VALUES (?, ?, ?)";
|
||||
$result = sqlsrv_query($conn, $sql, [$millCode, $displayName, $sortOrder]);
|
||||
|
||||
if ($result) {
|
||||
$message = "Mill name added successfully!";
|
||||
$messageType = 'success';
|
||||
} else {
|
||||
$message = "Error adding: " . print_r(sqlsrv_errors(), true);
|
||||
$messageType = 'error';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$millId = intval($_POST['mill_id']);
|
||||
|
||||
$sql = "DELETE FROM mill_names WHERE mill_id = ?";
|
||||
$result = sqlsrv_query($conn, $sql, [$millId]);
|
||||
|
||||
if ($result) {
|
||||
$message = "Mill name deleted!";
|
||||
$messageType = 'success';
|
||||
} else {
|
||||
$message = "Error deleting: " . print_r(sqlsrv_errors(), true);
|
||||
$messageType = 'error';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all mill names
|
||||
$sql = "SELECT * FROM mill_names ORDER BY sort_order, mill_code";
|
||||
$result = sqlsrv_query($conn, $sql);
|
||||
$millNames = [];
|
||||
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
|
||||
$millNames[] = $row;
|
||||
}
|
||||
|
||||
// Layout config
|
||||
$layoutWithoutSidebar = true;
|
||||
$layoutReturnUrl = 'milldata-dashboard.php';
|
||||
$layoutCloseWindowLabel = 'Back to Dashboard';
|
||||
$assetBasePath = '../';
|
||||
|
||||
include __DIR__ . '/../includes/layout/header.php';
|
||||
?>
|
||||
|
||||
<style>
|
||||
.admin-container {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--text);
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
border: 1px solid #4caf50;
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background: rgba(244, 67, 54, 0.2);
|
||||
border: 1px solid #f44336;
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.mill-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--surface);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.mill-table th,
|
||||
.mill-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.mill-table th {
|
||||
background: var(--surface-alt, #2a2a4a);
|
||||
color: var(--text);
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.mill-table tr:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.mill-table input[type="text"],
|
||||
.mill-table input[type="number"] {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 6px 10px;
|
||||
color: var(--text);
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.mill-table input[type="text"]:focus,
|
||||
.mill-table input[type="number"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #f44336;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.add-form {
|
||||
background: var(--surface);
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.add-form h2 {
|
||||
color: var(--text);
|
||||
font-size: 1.1rem;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted, #888);
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
background: var(--surface-alt, #2a2a4a);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 8px 12px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-badge.active {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.status-badge.inactive {
|
||||
background: rgba(158, 158, 158, 0.2);
|
||||
color: #9e9e9e;
|
||||
}
|
||||
|
||||
.code-cell {
|
||||
font-family: monospace;
|
||||
background: var(--surface-alt, #2a2a4a);
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="admin-container">
|
||||
<h1>🏭 Mill Names Admin</h1>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="message <?= $messageType ?>"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="mill-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Mill Code</th>
|
||||
<th>Display Name</th>
|
||||
<th>Sort Order</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($millNames as $mill): ?>
|
||||
<tr>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="update">
|
||||
<input type="hidden" name="mill_id" value="<?= $mill['mill_id'] ?>">
|
||||
|
||||
<td><span class="code-cell"><?= htmlspecialchars($mill['mill_code']) ?></span></td>
|
||||
<td>
|
||||
<input type="text" name="display_name"
|
||||
value="<?= htmlspecialchars($mill['display_name']) ?>"
|
||||
placeholder="Display name...">
|
||||
</td>
|
||||
<td style="width: 80px;">
|
||||
<input type="number" name="sort_order"
|
||||
value="<?= $mill['sort_order'] ?>"
|
||||
style="width: 60px;">
|
||||
</td>
|
||||
<td>
|
||||
<label style="display: flex; align-items: center; gap: 6px; cursor: pointer;">
|
||||
<input type="checkbox" name="is_active" <?= $mill['is_active'] ? 'checked' : '' ?>>
|
||||
<span class="status-badge <?= $mill['is_active'] ? 'active' : 'inactive' ?>">
|
||||
<?= $mill['is_active'] ? 'Active' : 'Inactive' ?>
|
||||
</span>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<div class="actions">
|
||||
<button type="submit" class="btn btn-primary btn-sm">Save</button>
|
||||
</form>
|
||||
<form method="POST" style="display: inline;"
|
||||
onsubmit="return confirm('Delete this mill name?');">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="mill_id" value="<?= $mill['mill_id'] ?>">
|
||||
<button type="submit" class="btn btn-danger btn-sm">×</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="add-form">
|
||||
<h2>Add New Mill Name</h2>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="add">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>Mill Code (exact match from data)</label>
|
||||
<input type="text" name="mill_code" required placeholder="e.g., EastMill">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Display Name</label>
|
||||
<input type="text" name="display_name" required placeholder="e.g., East Mill">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Sort Order</label>
|
||||
<input type="number" name="sort_order" value="<?= count($millNames) + 1 ?>" style="width: 80px;">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add Mill</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
sqlsrv_close($conn);
|
||||
include __DIR__ . '/../includes/layout/footer.php';
|
||||
?>
|
||||
Reference in New Issue
Block a user