35667-vm/header.php
Flatlogic Bot b471fc9c7f Final 1
2025-11-12 18:44:00 +00:00

212 lines
11 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TWU Local 555 BNA Ramp Grievance Tracker</title>
<meta name="description" content="A tool for TWU Local 555 to track ramp grievances at BNA.">
<meta name="keywords" content="grievance tracker, union grievance, ramp grievance, TWU Local 555, BNA, employee relations, dispute resolution, union representative, workplace issues, Built with Flatlogic Generator">
<meta property="og:title" content="TWU Local 555 BNA Ramp Grievance Tracker">
<meta property="og:description" content="A tool for TWU Local 555 to track ramp grievances at BNA.">
<meta property="og:image" content="">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="assets/css/status-colors.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="assets/css/dark-mode.css?v=<?php echo time(); ?>">
</head>
<body>
<?php
require_once 'db/config.php';
$message = '';
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'Local Grievances';
$categories = ['Local Grievances', 'FWD to Office', 'Terminations'];
$status_options = [];
if ($page === 'Local Grievances') {
$status_options = ['Pending Submission', '1st Step', '1st Step Pending', '2nd Step', '2nd Step Pending', 'Settled', 'Withdrawn'];
} elseif ($page === 'FWD to Office') {
$status_options = ['FWD', 'System Board', 'Arbitration', 'MED/ARB', 'Settled', 'Withdrawn'];
} elseif ($page === 'Terminations') {
$status_options = ['FWD', 'System Board', 'Arbitration', 'Settled', 'Withdrawn/Resigned'];
}
try {
$pdo = db();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdotest = $pdo->query('SHOW TABLES');
if ($pdotest->rowCount() == 0) {
$pdo->exec("CREATE TABLE IF NOT EXISTS grievances (
id INT AUTO_INCREMENT PRIMARY KEY,
grievant_name VARCHAR(255) NOT NULL,
discipline VARCHAR(255) NOT NULL,
subject VARCHAR(255) NOT NULL,
status VARCHAR(100) NOT NULL,
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
union_representative VARCHAR(255) NOT NULL,
category VARCHAR(255) NOT NULL DEFAULT 'Local Grievances'
);");
}
// Check if 'category' column exists and add it if it doesn't
$stmt = $pdo->query("SHOW COLUMNS FROM grievances LIKE 'category'");
if ($stmt->rowCount() == 0) {
$pdo->exec("ALTER TABLE grievances ADD COLUMN category VARCHAR(255) NOT NULL DEFAULT 'Local Grievances'");
}
// Check if 'case_number' column exists and add it if it doesn't
$stmt = $pdo->query("SHOW COLUMNS FROM grievances LIKE 'case_number'");
if ($stmt->rowCount() == 0) {
$pdo->exec("ALTER TABLE grievances ADD COLUMN case_number VARCHAR(255) NULL");
}
$pdo->exec("CREATE TABLE IF NOT EXISTS grievance_updates (
id INT AUTO_INCREMENT PRIMARY KEY,
grievance_id INT NOT NULL,
update_text TEXT NOT NULL,
representative_name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (grievance_id) REFERENCES grievances(id) ON DELETE CASCADE
);");
} catch (PDOException $e) {
$message = '<div class="alert alert-danger" role="alert">Database error: ' . $e->getMessage() . '</div>';
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['add_grievance'])) {
$grievant_name = trim($_POST['grievant_name']);
$discipline = trim($_POST['discipline']);
$subject = trim($_POST['subject']);
$status = trim($_POST['status']);
$union_representative = trim($_POST['union_representative']);
$category = trim($_POST['category']);
if (!empty($grievant_name) && !empty($discipline) && !empty($subject) && !empty($status) && !empty($union_representative) && !empty($category)) {
try {
$stmt = $pdo->prepare("INSERT INTO grievances (grievant_name, discipline, subject, status, union_representative, category) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$grievant_name, $discipline, $subject, $status, $union_representative, $category]);
$message = '<div class="alert alert-success" role="alert">Grievance added successfully!</div>';
} catch (PDOException $e) {
$message = '<div class="alert alert-danger" role="alert">Error adding grievance: ' . $e->getMessage() . '</div>';
}
} else {
$message = '<div class="alert alert-warning" role="alert">Please fill out all fields.</div>';
}
} elseif (isset($_POST['move_grievance'])) {
$grievance_id = $_POST['grievance_id'];
$new_category = $_POST['new_category'];
if (!empty($grievance_id) && !empty($new_category) && in_array($new_category, $categories)) {
try {
$stmt = $pdo->prepare("UPDATE grievances SET category = ? WHERE id = ?");
$stmt->execute([$new_category, $grievance_id]);
$message = '<div class="alert alert-success" role="alert">Grievance moved successfully!</div>';
} catch (PDOException $e) {
$message = '<div class="alert alert-danger" role="alert">Error moving grievance: ' . $e->getMessage() . '</div>';
}
} else {
$message = '<div class="alert alert-warning" role="alert">Invalid move operation.</div>';
}
} elseif (isset($_POST['edit_grievance'])) {
$grievance_id = $_POST['grievance_id'];
$grievant_name = trim($_POST['grievant_name']);
$discipline = trim($_POST['discipline']);
$subject = trim($_POST['subject']);
$status = trim($_POST['status']);
$union_representative = trim($_POST['union_representative']);
$case_number = isset($_POST['case_number']) ? trim($_POST['case_number']) : null;
if (!empty($grievance_id) && !empty($grievant_name) && !empty($discipline) && !empty($subject) && !empty($status) && !empty($union_representative)) {
try {
// Check category to decide if case_number should be updated
$stmt_cat = $pdo->prepare("SELECT category FROM grievances WHERE id = ?");
$stmt_cat->execute([$grievance_id]);
$grievance_category = $stmt_cat->fetchColumn();
$sql = "UPDATE grievances SET grievant_name = ?, discipline = ?, subject = ?, status = ?, union_representative = ?";
$params = [$grievant_name, $discipline, $subject, $status, $union_representative];
if (($grievance_category === 'FWD to Office' || $grievance_category === 'Terminations')) {
$sql .= ", case_number = ?";
$params[] = $case_number;
}
$sql .= " WHERE id = ?";
$params[] = $grievance_id;
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$message = '<div class="alert alert-success" role="alert">Grievance updated successfully!</div>';
} catch (PDOException $e) {
$message = '<div class="alert alert-danger" role="alert">Error updating grievance: ' . $e->getMessage() . '</div>';
}
} else {
$message = '<div class="alert alert-warning" role="alert">Please fill out all fields.</div>';
}
} elseif (isset($_POST['add_grievance_update'])) {
$grievance_id = $_POST['grievance_id'];
$update_text = trim($_POST['update_text']);
$representative_name = trim($_POST['representative_name']);
if (!empty($grievance_id) && !empty($update_text) && !empty($representative_name)) {
try {
$stmt = $pdo->prepare("INSERT INTO grievance_updates (grievance_id, update_text, representative_name) VALUES (?, ?, ?)");
$stmt->execute([$grievance_id, $update_text, $representative_name]);
$message = '<div class="alert alert-success" role="alert">Update added successfully!</div>';
} catch (PDOException $e) {
$message = '<div class="alert alert-danger" role="alert">Error adding update: ' . $e->getMessage() . '</div>';
}
} else {
$message = '<div class="alert alert-warning" role="alert">Please fill out all fields for the update.</div>';
}
}
}
$sort_column = $_GET['sort'] ?? 'last_updated';
$sort_order = $_GET['order'] ?? 'desc';
// The 'timeframes' column in the UI is a date input, not a database field.
// Sorting by 'timeframes' will sort by 'last_updated' as a sensible default.
$valid_columns = ['last_updated', 'status', 'timeframes'];
if (!in_array($sort_column, $valid_columns)) {
$sort_column = 'last_updated';
}
$order_by_column = ($sort_column === 'timeframes') ? 'last_updated' : $sort_column;
$order_clause = "ORDER BY " . $order_by_column . " " . ($sort_order === 'asc' ? 'ASC' : 'DESC');
try {
$stmt = $pdo->prepare("SELECT * FROM grievances WHERE category = ? $order_clause");
$stmt->execute([$page]);
$grievances = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$grievances = [];
$message .= '<div class="alert alert-danger" role="alert">Error fetching grievances: ' . $e->getMessage() . '</div>';
}
?>
<header class="header">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
<div>
<h1><a href="index.php" class="text-decoration-none text-dark">TWU Local 555 BNA Ramp Grievance Tracker</a></h1>
<p class="lead">A simple tool to track and manage ramp grievances.</p>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="darkModeToggle">
<label class="form-check-label" for="darkModeToggle">Dark Mode</label>
</div>
</div>
</div>
</header>
<main class="container mt-5">
<?php echo $message; ?>