MANAGEMENT_TIMEOUT_SECONDS)) {
unset($_SESSION['MANAGEMENT_PASSWORD_authenticated']);
unset($_SESSION['MANAGEMENT_last_activity']);
header("Location: " . $_SERVER['PHP_SELF'] . "?reason=timeout");
exit;
}
$_SESSION['MANAGEMENT_last_activity'] = time();
}
if (isset($_GET['reason']) && $_GET['reason'] === 'timeout') {
unset($_SESSION['MANAGEMENT_PASSWORD_authenticated']);
unset($_SESSION['MANAGEMENT_last_activity']);
}
if (!isset($_SESSION['MANAGEMENT_PASSWORD_authenticated']) || $_SESSION['MANAGEMENT_PASSWORD_authenticated'] !== true) {
$display_msg = "Management Access";
if (isset($_GET['reason']) && $_GET['reason'] === 'timeout') {
$login_error = "Logged out due to 20 min of inactivity.";
}
?>
Management Login
= htmlspecialchars($display_msg) ?>
= htmlspecialchars($login_error) ?>
PDO::ERRMODE_EXCEPTION]);
} catch (PDOException $e) { die("Database connection failed: " . $e->getMessage()); }
$message = "";
// 1. Handle Form Submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['cards'])) {
try {
$pdo->beginTransaction();
$stmt = $pdo->prepare("UPDATE names SET CardID = ?, Name = ? WHERE id = ?");
foreach ($_POST['cards'] as $id => $data) {
$stmt->execute([trim($data['CardID']), trim($data['Name']), $id]);
}
$pdo->commit();
$message = "Database updated successfully!
";
} catch (Exception $e) {
$pdo->rollBack();
$message = "Error: " . $e->getMessage() . "
";
}
}
// 2. Fetch data with dynamic sorting logic
$allowed_sorts = ['id', 'CardID', 'Name'];
$allowed_dirs = ['ASC', 'DESC'];
$sort_col = (isset($_GET['sort']) && in_array($_GET['sort'], $allowed_sorts)) ? $_GET['sort'] : 'id';
$sort_dir = (isset($_GET['dir']) && in_array($_GET['dir'], $allowed_dirs)) ? $_GET['dir'] : 'ASC';
// SAFELY check if the table exists before querying
$rows = []; // Initialize as empty array
try {
$check = $pdo->query("SELECT 1 FROM names LIMIT 1");
if ($check) {
$stmt = $pdo->query("SELECT id, CardID, Name FROM names ORDER BY $sort_col $sort_dir");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
} catch (PDOException $e) {
// Table doesn't exist, $rows remains empty, no error thrown
}
// Helper function to build header links
function getSortUrl($column, $current_col, $current_dir) {
$next_dir = 'ASC';
if ($column === $current_col) {
$next_dir = ($current_dir === 'ASC') ? 'DESC' : 'ASC';
}
return "?sort=" . urlencode($column) . "&dir=" . urlencode($next_dir);
}
?>
PiClock NFC Card Management
To update the employee names use the fields below to rename each NFC Card.
Then scroll to the bottom and click "Save Changes".
⚠️ WARNING: "Save Changes" writes ALL VALUES to the database!
🔒 For security, this session will automatically time out after 20 minutes of inactivity.
= $message ?>