This commit is contained in:
Flatlogic Bot 2025-10-31 00:13:36 +00:00
parent bd91a1f76e
commit 275165284b
14 changed files with 905 additions and 145 deletions

79
add-dependent.php Normal file
View File

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['member_id']) || !filter_var($_GET['member_id'], FILTER_VALIDATE_INT)) {
header('Location: index.php?error_message=Invalid+member');
exit;
}
$member_id = (int)$_GET['member_id'];
// Fetch member details
$pdo = get_db_connection();
$stmt = $pdo->prepare('SELECT full_name FROM members WHERE id = ?');
$stmt->execute([$member_id]);
$member = $stmt->fetch();
if (!$member) {
header('Location: index.php?error_message=Member+not+found');
exit;
}
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['full_name']) || empty($_POST['relationship']) || empty($_POST['date_of_birth'])) {
$error_message = 'All fields are required.';
} else {
$stmt = $pdo->prepare(
'INSERT INTO dependents (member_id, full_name, relationship, date_of_birth) VALUES (?, ?, ?, ?)'
);
try {
$stmt->execute([
$member_id,
$_POST['full_name'],
$_POST['relationship'],
$_POST['date_of_birth'],
]);
header('Location: index.php?success_message=Dependent+added+successfully');
exit;
} catch (PDOException $e) {
$error_message = "Error adding dependent: " . $e->getMessage();
}
}
}
include __DIR__ . '/layout/header.php';
?>
<h1>Add Dependent for <?php echo htmlspecialchars($member['full_name']); ?></h1>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="add-dependent.php?member_id=<?php echo $member_id; ?>" method="post">
<div class="form-group">
<label for="full_name">Full Name*</label>
<input type="text" id="full_name" name="full_name" required>
</div>
<div class="form-group">
<label for="relationship">Relationship*</label>
<input type="text" id="relationship" name="relationship" required placeholder="e.g., Spouse, Child, Parent">
</div>
<div class="form-group">
<label for="date_of_birth">Date of Birth*</label>
<input type="date" id="date_of_birth" name="date_of_birth" required>
</div>
<button type="submit" class="btn">Add Dependent</button>
<a href="index.php" class="btn" style="background-color: #6c757d; border-color: #6c757d;">Cancel</a>
</form>
<?php include __DIR__ . '/layout/footer.php'; ?>

104
add-member.php Normal file
View File

@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Basic validation
if (empty($_POST['full_name']) || empty($_POST['email'])) {
$error_message = 'Full Name and Email are required.';
} else {
$pdo = get_db_connection();
$stmt = $pdo->prepare(
'INSERT INTO members (full_name, street, number, neighborhood, city, state, zip_code, phone, email, job_title, department) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
);
try {
$stmt->execute([
$_POST['full_name'] ?? null,
$_POST['street'] ?? null,
$_POST['number'] ?? null,
$_POST['neighborhood'] ?? null,
$_POST['city'] ?? null,
$_POST['state'] ?? null,
$_POST['zip_code'] ?? null,
$_POST['phone'] ?? null,
$_POST['email'] ?? null,
$_POST['job_title'] ?? null,
$_POST['department'] ?? null,
]);
header('Location: index.php?success_message=Member+added+successfully');
exit;
} catch (PDOException $e) {
// In a real app, you might want to log this error
$error_message = "Error adding member: " . $e->getMessage();
}
}
}
include __DIR__ . '/layout/header.php';
?>
<h1>Add New Member</h1>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="add-member.php" method="post">
<div class="form-group">
<label for="full_name">Full Name*</label>
<input type="text" id="full_name" name="full_name" required>
</div>
<div class="form-group">
<label for="email">Email*</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="text" id="phone" name="phone">
</div>
<div class="form-group">
<label for="street">Street</label>
<input type="text" id="street" name="street">
</div>
<div class="form-group">
<label for="number">Number</label>
<input type="text" id="number" name="number">
</div>
<div class="form-group">
<label for="neighborhood">Neighborhood</label>
<input type="text" id="neighborhood" name="neighborhood">
</div>
<div class="form-group">
<label for="city">City</label>
<input type="text" id="city" name="city">
</div>
<div class="form-group">
<label for="state">State</label>
<input type="text" id="state" name="state">
</div>
<div class="form-group">
<label for="zip_code">ZIP Code</label>
<input type="text" id="zip_code" name="zip_code">
</div>
<div class="form-group">
<label for="job_title">Job Title</label>
<input type="text" id="job_title" name="job_title">
</div>
<div class="form-group">
<label for="department">Department</label>
<input type="text" id="department" name="department">
</div>
<button type="submit" class="btn">Add Member</button>
<a href="index.php" class="btn" style="background-color: #6c757d; border-color: #6c757d;">Cancel</a>
</form>
<?php include __DIR__ . '/layout/footer.php'; ?>

163
assets/css/style.css Normal file
View File

@ -0,0 +1,163 @@
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #f8f9fa;
color: #212529;
margin: 0;
padding: 1rem;
}
.container {
max-width: 1200px;
margin: auto;
background-color: #ffffff;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1, h2 {
color: #0d6efd;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
}
th, td {
padding: 0.75rem;
text-align: left;
border-bottom: 1px solid #dee2e6;
}
th {
background-color: #f8f9fa;
}
.btn {
display: inline-block;
font-weight: 400;
color: #ffffff;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-color: #0d6efd;
border: 1px solid #0d6efd;
padding: 0.375rem 0.75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: 0.25rem;
text-decoration: none;
margin-top: 1rem;
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
line-height: 1.5;
border-radius: 0.2rem;
}
.dependents-table {
margin-top: 0.5rem;
margin-left: 2rem;
width: calc(100% - 2rem);
}
.dependents-table th, .dependents-table td {
background-color: #e9ecef;
}
.alert {
padding: 1rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-success {
color: #0f5132;
background-color: #d1e7dd;
border-color: #badbcc;
}
form {
margin-top: 1.5rem;
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
}
.form-group input, .form-group select {
width: 100%;
padding: 0.5rem;
font-size: 1rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
}
.actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.search-form {
display: flex;
gap: 0.5rem;
margin-top: 0;
}
.search-form input {
width: 300px;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border: 1px solid #ced4da;
border-radius: 0.25rem;
}
.search-form .btn {
margin-top: 0;
}
.main-header {
background-color: #0d6efd;
color: #ffffff;
padding: 1rem 0;
margin-bottom: 2rem;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1200px;
margin: auto;
padding: 0 2rem;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
}
.user-info {
display: flex;
align-items: center;
gap: 1rem;
}
.user-info .btn {
background-color: #ffffff;
color: #0d6efd;
border-color: #ffffff;
margin-top: 0;
}

8
auth.php Normal file
View File

@ -0,0 +1,8 @@
<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}

70
db/database.php Normal file
View File

@ -0,0 +1,70 @@
<?php
require_once __DIR__ . '/config.php';
function get_db_connection() {
static $pdo;
if (!$pdo) {
try {
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
// In a real app, you'd want to log this and show a user-friendly error.
die("Database connection failed: " . $e->getMessage());
}
}
return $pdo;
}
function initialize_database() {
$pdo = get_db_connection();
$statements = [
'CREATE TABLE IF NOT EXISTS members (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
street VARCHAR(255),
number VARCHAR(50),
neighborhood VARCHAR(100),
city VARCHAR(100),
state VARCHAR(50),
zip_code VARCHAR(20),
phone VARCHAR(50),
email VARCHAR(255),
job_title VARCHAR(255),
department VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);',
'CREATE TABLE IF NOT EXISTS dependents (
id INT AUTO_INCREMENT PRIMARY KEY,
member_id INT NOT NULL,
full_name VARCHAR(255) NOT NULL,
relationship VARCHAR(100),
date_of_birth DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (member_id) REFERENCES members(id) ON DELETE CASCADE
);',
'CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);'
];
foreach ($statements as $statement) {
$pdo->exec($statement);
}
// Add a default admin user if one doesn't exist
$stmt = $pdo->query("SELECT id FROM users WHERE username = 'admin'");
if ($stmt->rowCount() == 0) {
$admin_pass = password_hash('password', PASSWORD_DEFAULT);
$pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)")
->execute(['admin', $admin_pass]);
}
}
// Initialize the database schema when this file is included.
initialize_database();

22
delete-dependent.php Normal file
View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}
$dependent_id = (int)$_GET['id'];
$pdo = get_db_connection();
$stmt = $pdo->prepare('DELETE FROM dependents WHERE id = ?');
$stmt->execute([$dependent_id]);
header('Location: index.php?success_message=Dependent deleted successfully');
exit;

27
delete-member.php Normal file
View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}
$member_id = (int)$_GET['id'];
$pdo = get_db_connection();
// First, delete dependents of the member
$stmt = $pdo->prepare('DELETE FROM dependents WHERE member_id = ?');
$stmt->execute([$member_id]);
// Then, delete the member
$stmt = $pdo->prepare('DELETE FROM members WHERE id = ?');
$stmt->execute([$member_id]);
header('Location: index.php?success_message=Member deleted successfully');
exit;

64
edit-dependent.php Normal file
View File

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}
$dependent_id = (int)$_GET['id'];
$pdo = get_db_connection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle form submission for updating the dependent
$full_name = $_POST['full_name'] ?? '';
$relationship = $_POST['relationship'] ?? '';
$date_of_birth = $_POST['date_of_birth'] ?? '';
$stmt = $pdo->prepare(
'UPDATE dependents SET full_name = ?, relationship = ?, date_of_birth = ? WHERE id = ?'
);
$stmt->execute([$full_name, $relationship, $date_of_birth, $dependent_id]);
header('Location: index.php?success_message=Dependent updated successfully');
exit;
}
// Fetch the dependent to edit
$stmt = $pdo->prepare('SELECT * FROM dependents WHERE id = ?');
$stmt->execute([$dependent_id]);
$dependent = $stmt->fetch();
if (!$dependent) {
header('Location: index.php');
exit;
}
include __DIR__ . '/layout/header.php';
?>
<h1>Edit Dependent</h1>
<form action="edit-dependent.php?id=<?php echo $dependent_id; ?>" method="post">
<div class="form-group">
<label for="full_name">Full Name</label>
<input type="text" id="full_name" name="full_name" value="<?php echo htmlspecialchars($dependent['full_name']); ?>" required>
</div>
<div class="form-group">
<label for="relationship">Relationship</label>
<input type="text" id="relationship" name="relationship" value="<?php echo htmlspecialchars($dependent['relationship']); ?>" required>
</div>
<div class="form-group">
<label for="date_of_birth">Date of Birth</label>
<input type="date" id="date_of_birth" name="date_of_birth" value="<?php echo htmlspecialchars($dependent['date_of_birth']); ?>" required>
</div>
<button type="submit" class="btn">Update Dependent</button>
</form>
<?php include __DIR__ . '/layout/footer.php'; ?>

104
edit-member.php Normal file
View File

@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit;
}
$member_id = (int)$_GET['id'];
$pdo = get_db_connection();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle form submission for updating the member
$full_name = $_POST['full_name'] ?? '';
$street = $_POST['street'] ?? '';
$number = $_POST['number'] ?? '';
$neighborhood = $_POST['neighborhood'] ?? '';
$city = $_POST['city'] ?? '';
$state = $_POST['state'] ?? '';
$zip_code = $_POST['zip_code'] ?? '';
$phone = $_POST['phone'] ?? '';
$email = $_POST['email'] ?? '';
$job_title = $_POST['job_title'] ?? '';
$department = $_POST['department'] ?? '';
$stmt = $pdo->prepare(
'UPDATE members SET full_name = ?, street = ?, number = ?, neighborhood = ?, city = ?, state = ?, zip_code = ?, phone = ?, email = ?, job_title = ?, department = ? WHERE id = ?'
);
$stmt->execute([$full_name, $street, $number, $neighborhood, $city, $state, $zip_code, $phone, $email, $job_title, $department, $member_id]);
header('Location: index.php?success_message=Member updated successfully');
exit;
}
// Fetch the member to edit
$stmt = $pdo->prepare('SELECT * FROM members WHERE id = ?');
$stmt->execute([$member_id]);
$member = $stmt->fetch();
if (!$member) {
header('Location: index.php');
exit;
}
include __DIR__ . '/layout/header.php';
?>
<h1>Edit Member</h1>
<form action="edit-member.php?id=<?php echo $member_id; ?>" method="post">
<div class="form-group">
<label for="full_name">Full Name</label>
<input type="text" id="full_name" name="full_name" value="<?php echo htmlspecialchars($member['full_name']); ?>" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($member['email']); ?>" required>
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="text" id="phone" name="phone" value="<?php echo htmlspecialchars($member['phone']); ?>">
</div>
<div class="form-group">
<label for="street">Street</label>
<input type="text" id="street" name="street" value="<?php echo htmlspecialchars($member['street']); ?>">
</div>
<div class="form-group">
<label for="number">Number</label>
<input type="text" id="number" name="number" value="<?php echo htmlspecialchars($member['number']); ?>">
</div>
<div class="form-group">
<label for="neighborhood">Neighborhood</label>
<input type="text" id="neighborhood" name="neighborhood" value="<?php echo htmlspecialchars($member['neighborhood']); ?>">
</div>
<div class="form-group">
<label for="city">City</label>
<input type="text" id="city" name="city" value="<?php echo htmlspecialchars($member['city']); ?>">
</div>
<div class="form-group">
<label for="state">State</label>
<input type="text" id="state" name="state" value="<?php echo htmlspecialchars($member['state']); ?>">
</div>
<div class="form-group">
<label for="zip_code">ZIP Code</label>
<input type="text" id="zip_code" name="zip_code" value="<?php echo htmlspecialchars($member['zip_code']); ?>">
</div>
<div class="form-group">
<label for="job_title">Job Title</label>
<input type="text" id="job_title" name="job_title" value="<?php echo htmlspecialchars($member['job_title']); ?>">
</div>
<div class="form-group">
<label for="department">Department</label>
<input type="text" id="department" name="department" value="<?php echo htmlspecialchars($member['department']); ?>">
</div>
<button type="submit" class="btn">Update Member</button>
</form>
<?php include __DIR__ . '/layout/footer.php'; ?>

276
index.php
View File

@ -1,150 +1,136 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
ini_set('display_errors', '1');
error_reporting(E_ALL);
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db/database.php';
$pdo = get_db_connection();
// Search logic
$search = $_GET['search'] ?? '';
$sql = 'SELECT * FROM members';
$params = [];
if ($search) {
$sql .= ' WHERE full_name LIKE ? OR department LIKE ? OR city LIKE ?';
$params[] = "%$search%";
$params[] = "%$search%";
$params[] = "%$search%";
}
$sql .= ' ORDER BY created_at DESC';
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$members = $stmt->fetchAll();
// Fetch dependents for each member
$dependentsByMember = [];
if ($members) {
$memberIds = array_column($members, 'id');
if (!empty($memberIds)) {
$placeholders = implode(',', array_fill(0, count($memberIds), '?'));
$stmt = $pdo->prepare("SELECT * FROM dependents WHERE member_id IN ($placeholders) ORDER BY created_at DESC");
$stmt->execute($memberIds);
$dependents = $stmt->fetchAll();
foreach ($dependents as $dependent) {
$dependentsByMember[$dependent['member_id']][] = $dependent;
}
}
}
function calculate_age($dob) {
if (!$dob) return 'N/A';
$birthDate = new DateTime($dob);
$today = new DateTime('today');
$age = $birthDate->diff($today)->y;
return $age;
}
include __DIR__ . '/layout/header.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
<h1>Members</h1>
<div class="actions">
<a href="add-member.php" class="btn">Add New Member</a>
<form action="index.php" method="get" class="search-form">
<input type="text" name="search" placeholder="Search by name, department, city..." value="<?php echo htmlspecialchars($search); ?>">
<button type="submit" class="btn">Search</button>
</form>
</div>
<?php if (isset($_GET['success_message'])): ?>
<div class="alert alert-success">
<?php echo htmlspecialchars($_GET['success_message']); ?>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
</body>
</html>
<?php endif; ?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Job Title</th>
<th>Department</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($members)): ?>
<tr>
<td colspan="5">No members found.</td>
</tr>
<?php else: ?>
<?php foreach ($members as $member): ?>
<tr>
<td><?php echo htmlspecialchars($member['full_name']); ?></td>
<td><?php echo htmlspecialchars($member['email']); ?></td>
<td><?php echo htmlspecialchars($member['job_title']); ?></td>
<td><?php echo htmlspecialchars($member['department']); ?></td>
<td>
<a href="add-dependent.php?member_id=<?php echo $member['id']; ?>" class="btn btn-sm">Add Dependent</a>
<a href="edit-member.php?id=<?php echo $member['id']; ?>" class="btn btn-sm">Edit</a>
<a href="delete-member.php?id=<?php echo $member['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this member and all their dependents?');">Delete</a>
</td>
</tr>
<?php if (!empty($dependentsByMember[$member['id']])): ?>
<tr>
<td colspan="5">
<table class="dependents-table">
<thead>
<tr>
<th>Dependent Name</th>
<th>Relationship</th>
<th>Date of Birth</th>
<th>Age</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($dependentsByMember[$member['id']] as $dependent): ?>
<tr>
<td><?php echo htmlspecialchars($dependent['full_name']); ?></td>
<td><?php echo htmlspecialchars($dependent['relationship']); ?></td>
<td><?php echo htmlspecialchars($dependent['date_of_birth']); ?></td>
<td><?php echo calculate_age($dependent['date_of_birth']); ?></td>
<td>
<a href="edit-dependent.php?id=<?php echo $dependent['id']; ?>" class="btn btn-sm">Edit</a>
<a href="delete-dependent.php?id=<?php echo $dependent['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this dependent?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php include __DIR__ . '/layout/footer.php'; ?>

3
layout/footer.php Normal file
View File

@ -0,0 +1,3 @@
</div>
</body>
</html>

21
layout/header.php Normal file
View File

@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Member Management</title>
<link rel="stylesheet" href="/assets/css/style.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="main-header">
<div class="container">
<div class="header-content">
<div class="logo">Member Management</div>
<div class="user-info">
<span>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</span>
<a href="logout.php" class="btn btn-sm">Logout</a>
</div>
</div>
</div>
</header>
<div class="container">

87
login.php Normal file
View File

@ -0,0 +1,87 @@
<?php
session_start();
require_once __DIR__ . '/db/database.php';
$error_message = '';
// If already logged in, redirect to main page
if (isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error_message = 'Please enter both username and password.';
} else {
$pdo = get_db_connection();
$stmt = $pdo->prepare("SELECT id, password FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $username;
header('Location: index.php');
exit;
} else {
$error_message = 'Invalid username or password.';
}
}
}
$page_title = "Login";
// We don't include the main header as it would create a redirect loop.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($page_title) ?> - Member Management</title>
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f8f9fa;
}
.login-container {
background: #fff;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
</style>
</head>
<body>
<div class="login-container">
<h1>Login</h1>
<p>Welcome to the Member Management System.</p>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required autofocus>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
<div class="alert alert-info" style="margin-top: 1rem;">
Use <strong>admin</strong> / <strong>password</strong> to login.
</div>
</div>
</body>
</html>

22
logout.php Normal file
View File

@ -0,0 +1,22 @@
<?php
session_start();
// Unset all of the session variables.
$_SESSION = [];
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();
// Redirect to the login page.
header('Location: login.php');
exit;