initial creation

This commit is contained in:
Flatlogic Bot 2026-01-23 13:40:12 +00:00
parent 95cf0af616
commit b8eda13904
5 changed files with 473 additions and 455 deletions

View File

@ -1,346 +1,77 @@
:root {
--color-bg: #ffffff;
--color-text: #1a1a1a;
--color-primary: #2563EB; /* Vibrant Blue */
--color-secondary: #000000;
--color-accent: #A3E635; /* Lime Green */
--color-surface: #f8f9fa;
--font-heading: 'Space Grotesk', sans-serif;
--font-body: 'Inter', sans-serif;
--border-width: 2px;
--shadow-hard: 5px 5px 0px #000;
--shadow-hover: 8px 8px 0px #000;
--radius-pill: 50rem;
--radius-card: 1rem;
--primary: #111827;
--secondary: #6B7280;
--accent: #3B82F6;
--bg: #F9FAFB;
--surface: #FFFFFF;
--border: #E5E7EB;
}
body {
font-family: var(--font-body);
background-color: var(--color-bg);
color: var(--color-text);
overflow-x: hidden;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background-color: var(--bg);
color: var(--primary);
font-size: 0.875rem;
}
h1, h2, h3, h4, h5, h6, .navbar-brand {
font-family: var(--font-heading);
letter-spacing: -0.03em;
}
/* Utilities */
.text-primary { color: var(--color-primary) !important; }
.bg-black { background-color: #000 !important; }
.text-white { color: #fff !important; }
.shadow-hard { box-shadow: var(--shadow-hard); }
.border-2-black { border: var(--border-width) solid #000; }
.py-section { padding-top: 5rem; padding-bottom: 5rem; }
/* Navbar */
.navbar {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-bottom: var(--border-width) solid transparent;
transition: all 0.3s;
padding-top: 1rem;
padding-bottom: 1rem;
background-color: var(--surface);
border-bottom: 1px solid var(--border);
}
.navbar.scrolled {
border-bottom-color: #000;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
.card {
border: 1px solid var(--border);
border-radius: 4px;
box-shadow: none;
}
.brand-text {
font-size: 1.5rem;
font-weight: 800;
}
.nav-link {
font-weight: 500;
color: var(--color-text);
margin-left: 1rem;
position: relative;
}
.nav-link:hover, .nav-link.active {
color: var(--color-primary);
}
/* Buttons */
.btn {
font-weight: 700;
font-family: var(--font-heading);
padding: 0.8rem 2rem;
border-radius: var(--radius-pill);
border: var(--border-width) solid #000;
transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
box-shadow: var(--shadow-hard);
}
.btn:hover {
transform: translate(-2px, -2px);
box-shadow: var(--shadow-hover);
}
.btn:active {
transform: translate(2px, 2px);
box-shadow: 0 0 0 #000;
border-radius: 4px;
font-weight: 500;
padding: 0.5rem 1rem;
}
.btn-primary {
background-color: var(--color-primary);
border-color: #000;
color: #fff;
background-color: var(--primary);
border-color: var(--primary);
}
.btn-primary:hover {
background-color: #1d4ed8;
border-color: #000;
color: #fff;
background-color: #1F2937;
border-color: #1F2937;
}
.btn-outline-dark {
background-color: #fff;
color: #000;
.table {
border: 1px solid var(--border);
background: var(--surface);
}
.btn-cta {
background-color: var(--color-accent);
color: #000;
}
.btn-cta:hover {
background-color: #8cc629;
color: #000;
}
/* Hero Section */
.hero-section {
min-height: 100vh;
padding-top: 80px;
}
.background-blob {
position: absolute;
border-radius: 50%;
filter: blur(80px);
opacity: 0.6;
z-index: 1;
}
.blob-1 {
top: -10%;
right: -10%;
width: 600px;
height: 600px;
background: radial-gradient(circle, var(--color-accent), transparent);
}
.blob-2 {
bottom: 10%;
left: -10%;
width: 500px;
height: 500px;
background: radial-gradient(circle, var(--color-primary), transparent);
}
.highlight-text {
background: linear-gradient(120deg, transparent 0%, transparent 40%, var(--color-accent) 40%, var(--color-accent) 100%);
background-repeat: no-repeat;
background-size: 100% 40%;
background-position: 0 88%;
padding: 0 5px;
}
.dot { color: var(--color-primary); }
.badge-pill {
display: inline-block;
padding: 0.5rem 1rem;
border: 2px solid #000;
border-radius: 50px;
font-weight: 700;
background: #fff;
box-shadow: 4px 4px 0 #000;
font-family: var(--font-heading);
font-size: 0.9rem;
}
/* Marquee */
.marquee-container {
overflow: hidden;
white-space: nowrap;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
}
.rotate-divider {
transform: rotate(-2deg) scale(1.05);
z-index: 10;
position: relative;
margin-top: -50px;
margin-bottom: 30px;
}
.marquee-content {
display: inline-block;
animation: marquee 20s linear infinite;
font-family: var(--font-heading);
font-weight: 700;
font-size: 1.5rem;
letter-spacing: 2px;
}
@keyframes marquee {
0% { transform: translateX(0); }
100% { transform: translateX(-50%); }
}
/* Portfolio Cards */
.project-card {
border: 2px solid #000;
border-radius: var(--radius-card);
overflow: hidden;
background: #fff;
transition: transform 0.3s ease;
box-shadow: var(--shadow-hard);
height: 100%;
display: flex;
flex-direction: column;
}
.project-card:hover {
transform: translateY(-10px);
box-shadow: 8px 8px 0 #000;
}
.card-img-holder {
height: 250px;
display: flex;
align-items: center;
justify-content: center;
border-bottom: 2px solid #000;
position: relative;
font-size: 4rem;
}
.placeholder-art {
transition: transform 0.3s ease;
}
.project-card:hover .placeholder-art {
transform: scale(1.2) rotate(10deg);
}
.bg-soft-blue { background-color: #e0f2fe; }
.bg-soft-green { background-color: #dcfce7; }
.bg-soft-purple { background-color: #f3e8ff; }
.bg-soft-yellow { background-color: #fef9c3; }
.category-tag {
position: absolute;
top: 15px;
right: 15px;
background: #000;
color: #fff;
padding: 5px 12px;
border-radius: 20px;
.table th {
background: #F3F4F6;
font-weight: 600;
text-transform: uppercase;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.025em;
border-bottom: 1px solid var(--border);
}
.card-body { padding: 1.5rem; }
.link-arrow {
text-decoration: none;
color: #000;
font-weight: 700;
display: inline-flex;
align-items: center;
margin-top: auto;
.activity-log {
max-height: 400px;
overflow-y: auto;
}
.link-arrow i { transition: transform 0.2s; margin-left: 5px; }
.link-arrow:hover i { transform: translateX(5px); }
/* About */
.about-image-stack {
position: relative;
height: 400px;
width: 100%;
.log-entry {
padding: 0.75rem;
border-bottom: 1px solid var(--border);
font-size: 0.8rem;
}
.stack-card {
position: absolute;
width: 80%;
height: 100%;
border-radius: var(--radius-card);
border: 2px solid #000;
box-shadow: var(--shadow-hard);
left: 10%;
transform: rotate(-3deg);
background-size: cover;
.log-entry:last-child {
border-bottom: none;
}
/* Forms */
.form-control {
border: 2px solid #000;
border-radius: 0.5rem;
padding: 1rem;
.badge {
border-radius: 9999px;
font-weight: 500;
background: #f8f9fa;
}
.form-control:focus {
box-shadow: 4px 4px 0 var(--color-primary);
border-color: #000;
background: #fff;
}
/* Animations */
.animate-up {
opacity: 0;
transform: translateY(30px);
animation: fadeUp 0.8s ease forwards;
}
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
@keyframes fadeUp {
to {
opacity: 1;
transform: translateY(0);
}
}
/* Social */
.social-links a {
transition: transform 0.2s;
display: inline-block;
}
.social-links a:hover {
transform: scale(1.2) rotate(10deg);
color: var(--color-accent) !important;
}
/* Responsive */
@media (max-width: 991px) {
.rotate-divider {
transform: rotate(0);
margin-top: 0;
margin-bottom: 2rem;
}
.hero-section {
padding-top: 120px;
text-align: center;
min-height: auto;
padding-bottom: 100px;
}
.display-1 { font-size: 3.5rem; }
.blob-1 { width: 300px; height: 300px; right: -20%; }
.blob-2 { width: 300px; height: 300px; left: -20%; }
}
padding: 0.25rem 0.625rem;
}

View File

@ -0,0 +1,77 @@
-- Initial Schema for Repairs Multi-tenant App
CREATE TABLE IF NOT EXISTS companies (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
uprn_required BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
role ENUM('admin', 'standard') DEFAULT 'standard',
FOREIGN KEY (company_id) REFERENCES companies(id)
);
CREATE TABLE IF NOT EXISTS clients (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (company_id) REFERENCES companies(id)
);
CREATE TABLE IF NOT EXISTS job_statuses (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
is_default BOOLEAN DEFAULT FALSE,
FOREIGN KEY (company_id) REFERENCES companies(id)
);
CREATE TABLE IF NOT EXISTS jobs (
id INT AUTO_INCREMENT PRIMARY KEY,
company_id INT NOT NULL,
job_ref VARCHAR(100) NOT NULL,
uprn VARCHAR(100),
address_1 VARCHAR(255),
address_2 VARCHAR(255),
address_3 VARCHAR(255),
postcode VARCHAR(20),
description TEXT,
status_id INT,
client_id INT,
works_approved BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(company_id, job_ref),
FOREIGN KEY (company_id) REFERENCES companies(id),
FOREIGN KEY (status_id) REFERENCES job_statuses(id),
FOREIGN KEY (client_id) REFERENCES clients(id)
);
CREATE TABLE IF NOT EXISTS activity_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
job_id INT NOT NULL,
company_id INT NOT NULL,
user_id INT NOT NULL,
user_name VARCHAR(255),
event_type VARCHAR(100),
field_name VARCHAR(100),
old_value TEXT,
new_value TEXT,
metadata JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (job_id) REFERENCES jobs(id),
FOREIGN KEY (company_id) REFERENCES companies(id)
);
-- Seed Initial Demo Company
INSERT INTO companies (name) VALUES ('Repairs Pro Ltd');
SET @company_id = LAST_INSERT_ID();
INSERT INTO users (company_id, name, email, role) VALUES (@company_id, 'Admin User', 'admin@repairspro.com', 'admin');
INSERT INTO job_statuses (company_id, name, is_default) VALUES (@company_id, 'To Be Surveyed', 1), (@company_id, 'Booking Required', 0), (@company_id, 'Completed', 0);
INSERT INTO clients (company_id, name) VALUES (@company_id, 'Main Housing Assoc');

34
includes/helpers.php Normal file
View File

@ -0,0 +1,34 @@
<?php
require_once __DIR__ . '/../db/config.php';
function getCurrentUser() {
// For now, return the seeded admin user
return db()->query("SELECT * FROM users LIMIT 1")->fetch();
}
function logActivity($job_id, $event_type, $field_name = null, $old_value = null, $new_value = null) {
$user = getCurrentUser();
$stmt = db()->prepare("INSERT INTO activity_logs (job_id, company_id, user_id, user_name, event_type, field_name, old_value, new_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([
$job_id,
$user['company_id'],
$user['id'],
$user['name'],
$event_type,
$field_name,
$old_value,
$new_value
]);
}
function getJobStatuses($company_id) {
$stmt = db()->prepare("SELECT * FROM job_statuses WHERE company_id = ?");
$stmt->execute([$company_id]);
return $stmt->fetchAll();
}
function getClients($company_id) {
$stmt = db()->prepare("SELECT * FROM clients WHERE company_id = ? AND is_active = 1");
$stmt->execute([$company_id]);
return $stmt->fetchAll();
}

299
index.php
View File

@ -1,150 +1,167 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
require_once 'includes/helpers.php';
$user = getCurrentUser();
$company_id = $user['company_id'];
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
// Handle Job Creation
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_job') {
$job_ref = $_POST['job_ref'];
$address_1 = $_POST['address_1'];
$description = $_POST['description'];
$status_id = $_POST['status_id'];
$client_id = $_POST['client_id'];
try {
$stmt = db()->prepare("INSERT INTO jobs (company_id, job_ref, address_1, description, status_id, client_id) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$company_id, $job_ref, $address_1, $description, $status_id, $client_id]);
$job_id = db()->lastInsertId();
logActivity($job_id, 'job_created', null, null, "Job Ref: $job_ref");
header("Location: job_detail.php?id=" . $job_id);
exit;
} catch (Exception $e) {
$error = "Error creating job: " . $e->getMessage();
}
}
$jobs = db()->prepare("SELECT j.*, s.name as status_name, c.name as client_name
FROM jobs j
LEFT JOIN job_statuses s ON j.status_id = s.id
LEFT JOIN clients c ON j.client_id = c.id
WHERE j.company_id = ?
ORDER BY j.created_at DESC");
$jobs->execute([$company_id]);
$jobList = $jobs->fetchAll();
$statuses = getJobStatuses($company_id);
$clients = getClients($company_id);
?>
<!doctype html>
<!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>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Repairs Pro</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</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>
</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>
<nav class="navbar navbar-expand-lg py-3">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">Repairs Pro</a>
<div class="d-flex align-items-center">
<span class="me-3 text-secondary"><?php echo htmlspecialchars($user['name']); ?></span>
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#createJobModal">New Job</button>
</div>
</div>
</nav>
<main class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h4 fw-bold m-0">All Jobs</h1>
</div>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<div class="card">
<div class="table-responsive">
<table class="table mb-0">
<thead>
<tr>
<th>Job Ref</th>
<th>Client</th>
<th>Address</th>
<th>Status</th>
<th>Approved</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobList as $job): ?>
<tr>
<td class="fw-medium text-primary"><?php echo htmlspecialchars($job['job_ref']); ?></td>
<td><?php echo htmlspecialchars($job['client_name']); ?></td>
<td class="text-secondary"><?php echo htmlspecialchars($job['address_1']); ?></td>
<td>
<span class="badge bg-light text-dark border">
<?php echo htmlspecialchars($job['status_name']); ?>
</span>
</td>
<td>
<?php if ($job['works_approved']): ?>
<span class="text-success">Yes</span>
<?php else: ?>
<span class="text-muted">No</span>
<?php endif; ?>
</td>
<td>
<a href="job_detail.php?id=<?php echo $job['id']; ?>" class="btn btn-outline-secondary btn-sm">View</a>
</td>
</tr>
<?php endforeach; if (empty($jobList)): ?>
<tr>
<td colspan="6" class="text-center py-5 text-secondary">No jobs found. Start by creating one.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</main>
<!-- Create Job Modal -->
<div class="modal fade" id="createJobModal" tabindex="-1">
<div class="modal-dialog">
<form class="modal-content" method="POST">
<input type="hidden" name="action" value="create_job">
<div class="modal-header">
<h5 class="modal-title">Create New Job</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Job Reference *</label>
<input type="text" name="job_ref" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Client *</label>
<select name="client_id" class="form-select" required>
<?php foreach ($clients as $client): ?>
<option value="<?php echo $client['id']; ?>"><?php echo htmlspecialchars($client['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Address Line 1</label>
<input type="text" name="address_1" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">Status</label>
<select name="status_id" class="form-select">
<?php foreach ($statuses as $status): ?>
<option value="<?php echo $status['id']; ?>" <?php echo $status['is_default'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($status['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<textarea name="description" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Create Job</button>
</div>
</form>
</div>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
</html>

159
job_detail.php Normal file
View File

@ -0,0 +1,159 @@
<?php
require_once 'includes/helpers.php';
$user = getCurrentUser();
$company_id = $user['company_id'];
$job_id = $_GET['id'] ?? null;
if (!$job_id) {
header("Location: index.php");
exit;
}
// Fetch Job
$stmt = db()->prepare("SELECT j.*, s.name as status_name, c.name as client_name
FROM jobs j
LEFT JOIN job_statuses s ON j.status_id = s.id
LEFT JOIN clients c ON j.client_id = c.id
WHERE j.id = ? AND j.company_id = ?");
$stmt->execute([$job_id, $company_id]);
$job = $stmt->fetch();
if (!$job) {
die("Job not found.");
}
// Handle Updates
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action']) && $_POST['action'] === 'toggle_approved') {
$new_val = $job['works_approved'] ? 0 : 1;
$stmt = db()->prepare("UPDATE jobs SET works_approved = ? WHERE id = ?");
$stmt->execute([$new_val, $job_id]);
logActivity($job_id, 'works_approved_toggle', 'works_approved', $job['works_approved'] ? 'True' : 'False', $new_val ? 'True' : 'False');
header("Location: job_detail.php?id=" . $job_id);
exit;
}
}
// Fetch Logs
$logStmt = db()->prepare("SELECT * FROM activity_logs WHERE job_id = ? ORDER BY created_at DESC");
$logStmt->execute([$job_id]);
$logs = $logStmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Job Detail - <?php echo htmlspecialchars($job['job_ref']); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg py-3">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">Repairs Pro</a>
<div class="d-flex align-items-center">
<a href="index.php" class="btn btn-light btn-sm me-2">Back to Dashboard</a>
</div>
</div>
</nav>
<main class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="card p-4 mb-4">
<div class="d-flex justify-content-between align-items-start mb-4">
<div>
<span class="text-secondary text-uppercase small fw-bold">Job Reference</span>
<h1 class="h3 fw-bold"><?php echo htmlspecialchars($job['job_ref']); ?></h1>
</div>
<div class="text-end">
<span class="badge bg-light text-dark border p-2 px-3"><?php echo htmlspecialchars($job['status_name']); ?></span>
</div>
</div>
<div class="row g-4">
<div class="col-md-6">
<label class="text-secondary small">Client</label>
<div class="fw-medium"><?php echo htmlspecialchars($job['client_name']); ?></div>
</div>
<div class="col-md-6">
<label class="text-secondary small">Created At</label>
<div class="fw-medium"><?php echo date('d M Y, H:i', strtotime($job['created_at'])); ?></div>
</div>
<div class="col-12">
<label class="text-secondary small">Address</label>
<div class="fw-medium"><?php echo htmlspecialchars($job['address_1'] ?: 'N/A'); ?></div>
</div>
<div class="col-12">
<label class="text-secondary small">Description</label>
<div class="p-3 bg-light border-start border-primary border-4 rounded-1">
<?php echo nl2br(htmlspecialchars($job['description'] ?: 'No description provided.')); ?>
</div>
</div>
</div>
<hr class="my-4">
<div class="d-flex justify-content-between align-items-center">
<div>
<h5 class="m-0 fw-bold">Works Approved</h5>
<p class="text-secondary small m-0">Toggle this when the scope of work is confirmed.</p>
</div>
<form method="POST">
<input type="hidden" name="action" value="toggle_approved">
<button type="submit" class="btn <?php echo $job['works_approved'] ? 'btn-success' : 'btn-outline-secondary'; ?>">
<?php echo $job['works_approved'] ? 'Approved' : 'Mark as Approved'; ?>
</button>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header bg-white py-3">
<h5 class="m-0 fw-bold">Activity Log</h5>
</div>
<div class="activity-log">
<?php foreach ($logs as $log): ?>
<div class="log-entry">
<div class="d-flex justify-content-between mb-1">
<span class="fw-bold"><?php echo htmlspecialchars($log['user_name']); ?></span>
<span class="text-secondary x-small"><?php echo date('H:i', strtotime($log['created_at'])); ?></span>
</div>
<div class="text-primary small mb-1">
<?php
switch($log['event_type']) {
case 'job_created': echo "Created the job"; break;
case 'works_approved_toggle': echo "Updated 'Works Approved' status"; break;
default: echo htmlspecialchars($log['event_type']);
}
?>
</div>
<?php if ($log['field_name']): ?>
<div class="text-secondary" style="font-size: 0.75rem;">
<span class="text-decoration-line-through"><?php echo htmlspecialchars($log['old_value']); ?></span>
&rarr;
<span class="fw-medium"><?php echo htmlspecialchars($log['new_value']); ?></span>
</div>
<?php endif; ?>
<div class="text-muted mt-1" style="font-size: 0.7rem;">
<?php echo date('d M Y', strtotime($log['created_at'])); ?>
</div>
</div>
<?php endforeach; if (empty($logs)): ?>
<div class="p-4 text-center text-secondary">No activity yet.</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>