Compare commits

..

3 Commits

Author SHA1 Message Date
Flatlogic Bot
3be72a2961 update 2025-12-12 10:37:58 +00:00
Flatlogic Bot
e825aa97f2 same 2025-12-12 09:56:45 +00:00
Flatlogic Bot
b4ffcec973 feat: Implement engineer and contract management
- Add Field Engineer Management feature, allowing creation, and assignment of engineers to service requests.

- Add Service Contract/AMC Management feature, allowing creation of contracts and linking them to service requests.

- Update admin panel to manage engineers and contracts.

- Update service request form to include contract selection.
2025-12-12 09:47:39 +00:00
23 changed files with 1263 additions and 148 deletions

7
admin/auth.php Normal file
View File

@ -0,0 +1,7 @@
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}

131
admin/contracts.php Normal file
View File

@ -0,0 +1,131 @@
<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/auth.php';
// Handle form submission for adding a new contract
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_contract'])) {
$customer_name = $_POST['customer_name'] ?? '';
$customer_email = $_POST['customer_email'] ?? '';
$customer_phone = $_POST['customer_phone'] ?? '';
$contract_title = $_POST['contract_title'] ?? '';
$start_date = $_POST['start_date'] ?? null;
$end_date = $_POST['end_date'] ?? null;
if (!empty($customer_name) && !empty($contract_title)) {
$pdo = db();
$stmt = $pdo->prepare(
'INSERT INTO contracts (customer_name, customer_email, customer_phone, contract_title, start_date, end_date) VALUES (?, ?, ?, ?, ?, ?)'
);
$stmt->execute([$customer_name, $customer_email, $customer_phone, $contract_title, $start_date, $end_date]);
}
// Redirect to avoid form resubmission
header('Location: contracts.php');
exit;
}
// Fetch all contracts to display
$pdo = db();
$contracts = $pdo->query('SELECT * FROM contracts ORDER BY created_at DESC')->fetchAll(PDO::FETCH_ASSOC);
require_once __DIR__ . '/../header.php';
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Contract Management</h1>
<div>
<a href="index.php" class="btn btn-sm btn-outline-secondary">Back to Jobs</a>
<a href="engineers.php" class="btn btn-sm btn-outline-secondary">Manage Engineers</a>
<a href="logout.php" class="btn btn-sm btn-outline-danger">Logout</a>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
Add New Contract
</div>
<div class="card-body">
<form method="POST" action="contracts.php">
<input type="hidden" name="add_contract" value="1">
<div class="row">
<div class="col-md-4 mb-3">
<label for="customer_name" class="form-label">Customer Name*</label>
<input type="text" class="form-control" id="customer_name" name="customer_name" required>
</div>
<div class="col-md-4 mb-3">
<label for="customer_email" class="form-label">Customer Email</label>
<input type="email" class="form-control" id="customer_email" name="customer_email">
</div>
<div class="col-md-4 mb-3">
<label for="customer_phone" class="form-label">Customer Phone</label>
<input type="text" class="form-control" id="customer_phone" name="customer_phone">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="contract_title" class="form-label">Contract Title / AMC*</label>
<input type="text" class="form-control" id="contract_title" name="contract_title" required>
</div>
<div class="col-md-3 mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date">
</div>
<div class="col-md-3 mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date">
</div>
</div>
<button type="submit" class="btn btn-primary">Add Contract</button>
</form>
</div>
</div>
<h2 class="h3 mt-5">Existing Contracts</h2>
<div class="card">
<div class="table-responsive">
<table class="table table-striped table-hover mb-0">
<thead class="thead-light">
<tr>
<th>Customer</th>
<th>Contract/AMC Title</th>
<th>Validity</th>
<th>Contact</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($contracts)): ?>
<tr>
<td colspan="5" class="text-center text-muted">No contracts found.</td>
</tr>
<?php else: ?>
<?php foreach ($contracts as $contract): ?>
<tr>
<td><?php echo htmlspecialchars($contract['customer_name']); ?></td>
<td><?php echo htmlspecialchars($contract['contract_title']); ?></td>
<td>
<?php if ($contract['start_date'] && $contract['end_date']): ?>
<?php echo date('M j, Y', strtotime($contract['start_date'])); ?> -
<?php echo date('M j, Y', strtotime($contract['end_date'])); ?>
<?php else: ?>
<span class="text-muted">N/A</span>
<?php endif; ?>
</td>
<td>
<?php echo htmlspecialchars($contract['customer_email']); ?><br>
<small><?php echo htmlspecialchars($contract['customer_phone']); ?></small>
</td>
<td>
<a href="edit_contract.php?id=<?php echo $contract['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
<a href="delete_contract.php?id=<?php echo $contract['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this contract?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php require_once __DIR__ . '/../footer.php'; ?>

View File

@ -0,0 +1,87 @@
<?php
require_once 'auth.php';
require_once '../db/config.php';
if (!isset($_GET['email']) || empty($_GET['email'])) {
header('Location: customers.php');
exit;
}
$email = $_GET['email'];
// Fetch customer details from the first request
$stmt = db()->prepare("SELECT name, phone FROM service_requests WHERE email = ? LIMIT 1");
$stmt->execute([$email]);
$customer = $stmt->fetch();
// Fetch all service requests for this customer
$stmt = db()->prepare("
SELECT sr.*, c.contract_title
FROM service_requests sr
LEFT JOIN contracts c ON sr.contract_id = c.id
WHERE sr.email = ?
ORDER BY sr.created_at DESC
");
$stmt->execute([$email]);
$requests = $stmt->fetchAll();
require_once '../header.php';
?>
<div class="container my-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1>History for <?php echo htmlspecialchars($customer['name'] ?? $email); ?></h1>
<p class="text-muted">
Email: <?php echo htmlspecialchars($email); ?> |
Phone: <?php echo htmlspecialchars($customer['phone'] ?? 'N/A'); ?>
</p>
</div>
<a href="customers.php" class="btn btn-outline-secondary">Back to Customer List</a>
</div>
<div class="card">
<div class="card-body">
<?php if (count($requests) > 0): ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Job Title</th>
<th>Job Description</th>
<th>Contract</th>
<th>Status</th>
<th>Submitted</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>
<?php foreach ($requests as $request): ?>
<tr>
<td><?php echo htmlspecialchars($request['id']); ?></td>
<td><?php echo htmlspecialchars($request['job_title']); ?></td>
<td><?php echo htmlspecialchars($request['job_description']); ?></td>
<td>
<?php if (!empty($request['contract_title'])): ?>
<span class="badge bg-secondary"><?php echo htmlspecialchars($request['contract_title']); ?></span>
<?php else: ?>
<span class="text-muted">N/A</span>
<?php endif; ?>
</td>
<td><span class="badge bg-info text-dark"><?php echo htmlspecialchars($request['status']); ?></span></td>
<td><?php echo date("M d, Y", strtotime($request['created_at'])); ?></td>
<td><?php echo date("M d, Y", strtotime($request['updated_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p class="text-center">No service requests found for this customer.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once '../footer.php'; ?>

63
admin/customers.php Normal file
View File

@ -0,0 +1,63 @@
<?php
require_once 'auth.php';
require_once '../db/config.php';
// Fetch unique customers (by email)
$stmt = db()->query("
SELECT
name,
email,
phone,
COUNT(id) as request_count
FROM service_requests
GROUP BY email
ORDER BY name ASC
");
$customers = $stmt->fetchAll();
require_once '../header.php';
?>
<div class="container my-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Customer History</h1>
<a href="index.php" class="btn btn-outline-secondary">Back to Dashboard</a>
</div>
<div class="card">
<div class="card-body">
<?php if (count($customers) > 0): ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Customer Name</th>
<th>Email</th>
<th>Phone</th>
<th>Service Requests</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($customers as $customer): ?>
<tr>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td><?php echo htmlspecialchars($customer['phone']); ?></td>
<td><span class="badge bg-primary"><?php echo $customer['request_count']; ?></span></td>
<td>
<a href="customer_history.php?email=<?php echo urlencode($customer['email']); ?>" class="btn btn-sm btn-info">View History</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p class="text-center">No customers found.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once '../footer.php'; ?>

13
admin/delete_contract.php Normal file
View File

@ -0,0 +1,13 @@
<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/auth.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
$pdo = db();
$stmt = $pdo->prepare('DELETE FROM contracts WHERE id = ?');
$stmt->execute([$id]);
}
header('Location: contracts.php');
exit;

93
admin/edit_contract.php Normal file
View File

@ -0,0 +1,93 @@
<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/auth.php';
$contract = null;
if (isset($_GET['id'])) {
$id = $_GET['id'];
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM contracts WHERE id = ?');
$stmt->execute([$id]);
$contract = $stmt->fetch(PDO::FETCH_ASSOC);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_contract'])) {
$id = $_POST['id'];
$customer_name = $_POST['customer_name'] ?? '';
$customer_email = $_POST['customer_email'] ?? '';
$customer_phone = $_POST['customer_phone'] ?? '';
$contract_title = $_POST['contract_title'] ?? '';
$start_date = $_POST['start_date'] ?? null;
$end_date = $_POST['end_date'] ?? null;
if (!empty($customer_name) && !empty($contract_title)) {
$pdo = db();
$stmt = $pdo->prepare(
'UPDATE contracts SET customer_name = ?, customer_email = ?, customer_phone = ?, contract_title = ?, start_date = ?, end_date = ? WHERE id = ?'
);
$stmt->execute([$customer_name, $customer_email, $customer_phone, $contract_title, $start_date, $end_date, $id]);
}
// Redirect to avoid form resubmission
header('Location: contracts.php');
exit;
}
require_once __DIR__ . '/../header.php';
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Edit Contract</h1>
<div>
<a href="contracts.php" class="btn btn-sm btn-outline-secondary">Back to Contracts</a>
<a href="logout.php" class="btn btn-sm btn-outline-danger">Logout</a>
</div>
</div>
<?php if ($contract): ?>
<div class="card">
<div class="card-header">
Update Contract Details
</div>
<div class="card-body">
<form method="POST" action="edit_contract.php">
<input type="hidden" name="update_contract" value="1">
<input type="hidden" name="id" value="<?php echo $contract['id']; ?>">
<div class="row">
<div class="col-md-4 mb-3">
<label for="customer_name" class="form-label">Customer Name*</label>
<input type="text" class="form-control" id="customer_name" name="customer_name" value="<?php echo htmlspecialchars($contract['customer_name']); ?>" required>
</div>
<div class="col-md-4 mb-3">
<label for="customer_email" class="form-label">Customer Email</label>
<input type="email" class="form-control" id="customer_email" name="customer_email" value="<?php echo htmlspecialchars($contract['customer_email']); ?>">
</div>
<div class="col-md-4 mb-3">
<label for="customer_phone" class="form-label">Customer Phone</label>
<input type="text" class="form-control" id="customer_phone" name="customer_phone" value="<?php echo htmlspecialchars($contract['customer_phone']); ?>">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="contract_title" class="form-label">Contract Title / AMC*</label>
<input type="text" class="form-control" id="contract_title" name="contract_title" value="<?php echo htmlspecialchars($contract['contract_title']); ?>" required>
</div>
<div class="col-md-3 mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date" value="<?php echo $contract['start_date']; ?>">
</div>
<div class="col-md-3 mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date" value="<?php echo $contract['end_date']; ?>">
</div>
</div>
<button type="submit" class="btn btn-primary">Update Contract</button>
</form>
</div>
</div>
<?php else: ?>
<div class="alert alert-danger">Contract not found.</div>
<?php endif; ?>
</div>
<?php require_once __DIR__ . '/../footer.php'; ?>

82
admin/engineers.php Normal file
View File

@ -0,0 +1,82 @@
<?php
require_once '../header.php';
require_once '../db/config.php';
require_once 'auth.php';
// Handle form submission for adding a new engineer
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_engineer'])) {
$name = trim($_POST['name']);
$phone = trim($_POST['phone']);
if (!empty($name)) {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO engineers (name, phone) VALUES (:name, :phone)");
$stmt->execute([':name' => $name, ':phone' => $phone]);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
}
// Fetch all engineers
try {
$pdo = db();
$engineers = $pdo->query("SELECT * FROM engineers ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Engineer Management</h1>
<p><a href="index.php">Back to Job Management</a></p>
<div class="card mb-4">
<div class="card-header">Add New Engineer</div>
<div class="card-body">
<form action="engineers.php" method="POST">
<div class="form-group">
<label for="name">Engineer Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" class="form-control" id="phone" name="phone">
</div>
<button type="submit" name="add_engineer" class="btn btn-primary">Add Engineer</button>
</form>
</div>
</div>
<div class="card">
<div class="card-header">All Engineers</div>
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Registered On</th>
</tr>
</thead>
<tbody>
<?php foreach ($engineers as $engineer): ?>
<tr>
<td><?php echo htmlspecialchars($engineer['name']); ?></td>
<td><?php echo htmlspecialchars($engineer['phone']); ?></td>
<td><?php echo htmlspecialchars($engineer['created_at']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php require_once '../footer.php'; ?>

121
admin/index.php Normal file
View File

@ -0,0 +1,121 @@
<?php
require_once 'auth.php';
require_once '../db/config.php';
// Fetch all service requests with contract info
$stmt = db()->query("
SELECT
sr.*,
c.contract_title,
c.customer_name AS contract_customer_name
FROM service_requests sr
LEFT JOIN contracts c ON sr.contract_id = c.id
ORDER BY sr.created_at DESC
");
$requests = $stmt->fetchAll();
// Fetch all engineers
$stmt = db()->query("SELECT * FROM engineers ORDER BY name ASC");
$engineers = $stmt->fetchAll();
require_once '../header.php';
?>
<div class="container-fluid my-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Admin Dashboard</h1>
<div>
<a href="engineers.php" class="btn btn-sm btn-outline-secondary">Manage Engineers</a>
<a href="contracts.php" class="btn btn-sm btn-outline-secondary">Manage Contracts</a>
<a href="customers.php" class="btn btn-sm btn-outline-info">Customer History</a>
<a href="logout.php" class="btn btn-sm btn-outline-danger">Logout</a>
</div>
</div>
<h2 class="mb-4">Job Management</h2>
<div class="card">
<div class="card-body">
<?php if (count($requests) > 0): ?>
<div class="table-responsive">
<form action="update_status.php" method="POST">
<table class="table table-striped table-hover align-middle">
<thead>
<tr>
<th>ID</th>
<th>Customer</th>
<th>Contract</th>
<th>Job Title</th>
<th>Job Description</th>
<th>Assigned Engineer</th>
<th>Scheduled For</th>
<th>Status</th>
<th>Submitted</th>
<th style="width: 150px;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($requests as $request): ?>
<tr>
<td><?php echo htmlspecialchars($request['id']); ?></td>
<td>
<strong><?php echo htmlspecialchars($request['name']); ?></strong>
<small class="d-block"><?php echo htmlspecialchars($request['phone']); ?></small>
</td>
<td>
<?php if (!empty($request['contract_id'])): ?>
<span class="badge bg-secondary">
<?php echo htmlspecialchars($request['contract_title']); ?><br>
<small><?php echo htmlspecialchars($request['contract_customer_name']); ?></small>
</span>
<?php else: ?>
<span class="text-muted">N/A</span>
<?php endif; ?>
</td>
<td>
<input type="text" name="jobs[<?php echo $request['id']; ?>][job_title]"
value="<?php echo htmlspecialchars($request['job_title']); ?>"
class="form-control form-control-sm">
</td>
<td><?php echo htmlspecialchars($request['job_description']); ?></td>
<td>
<select name="jobs[<?php echo $request['id']; ?>][engineer_id]" class="form-select form-select-sm">
<option value="">Unassigned</option>
<?php foreach ($engineers as $engineer): ?>
<option value="<?php echo $engineer['id']; ?>" <?php echo ($request['engineer_id'] == $engineer['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($engineer['name']); ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<input type="datetime-local" name="jobs[<?php echo $request['id']; ?>][scheduled_for]"
value="<?php echo !empty($request['scheduled_for']) ? date('Y-m-d\\TH:i', strtotime($request['scheduled_for'])) : ''; ?>"
class="form-control form-control-sm">
</td>
<td>
<select name="jobs[<?php echo $request['id']; ?>][status]" class="form-select form-select-sm">
<option value="New" <?php echo ($request['status'] === 'New') ? 'selected' : ''; ?>>New</option>
<option value="In Progress" <?php echo ($request['status'] === 'In Progress') ? 'selected' : ''; ?>>In Progress</option>
<option value="Completed" <?php echo ($request['status'] === 'Completed') ? 'selected' : ''; ?>>Completed</option>
</select>
</td>
<td><?php echo date("M d, Y", strtotime($request['created_at'])); ?></td>
<td>
<button type="submit" name="update_single" value="<?php echo $request['id']; ?>" class="btn btn-sm btn-success">Update</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<button type="submit" name="update_all" class="btn btn-primary">Update All</button>
</form>
</div>
<?php else: ?>
<p class="text-center">No service requests yet.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once '../footer.php'; ?>

54
admin/login.php Normal file
View File

@ -0,0 +1,54 @@
<?php
session_start();
require_once '../db/config.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error = 'Please enter username and password.';
} else {
$stmt = db()->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
header('Location: index.php');
exit;
} else {
$error = 'Invalid username or password.';
}
}
}
require_once '../header.php';
?>
<div class="container my-5">
<div class="row justify-content-center">
<div class="col-lg-6">
<h1 class="mb-4 text-center">Admin Login</h1>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form action="login.php" method="POST">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</div>
</div>
<?php require_once '../footer.php'; ?>

6
admin/logout.php Normal file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header('Location: login.php');
exit;

47
admin/update_status.php Normal file
View File

@ -0,0 +1,47 @@
<?php
require_once 'auth.php';
require_once '../db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['jobs'])) {
$jobs = $_POST['jobs'];
$update_all = isset($_POST['update_all']);
$update_single_id = $_POST['update_single'] ?? null;
$allowed_statuses = ['New', 'In Progress', 'Completed'];
foreach ($jobs as $id => $job_data) {
// If we are not updating all, only process the job that was singled out
if (!$update_all && $id != $update_single_id) {
continue;
}
$job_title = $job_data['job_title'] ?? 'Service Request';
$scheduled_for = !empty($job_data['scheduled_for']) ? date('Y-m-d H:i:s', strtotime($job_data['scheduled_for'])) : null;
$status = $job_data['status'] ?? 'New';
$engineer_id = !empty($job_data['engineer_id']) ? (int)$job_data['engineer_id'] : null;
// Validate status
if (in_array($status, $allowed_statuses)) {
try {
$stmt = db()->prepare(
"UPDATE service_requests
SET job_title = ?, scheduled_for = ?, status = ?, engineer_id = ?
WHERE id = ?"
);
$stmt->execute([$job_title, $scheduled_for, $status, $engineer_id, $id]);
} catch (PDOException $e) {
// Optional: Handle database errors
// For now, we will ignore and continue
}
}
// If we were only updating one, we can stop now
if (!$update_all) {
break;
}
}
}
// Redirect back to the admin dashboard
header('Location: index.php');
exit;

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

@ -0,0 +1,54 @@
/* Custom Styles for Water Purifier Service CRM */
:root {
--primary-color: #20c997; /* Teal */
--secondary-color: #343a40; /* Dark Grey */
--light-grey: #f8f9fa;
--white: #ffffff;
}
body {
font-family: 'system-ui', '-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'sans-serif';
}
.navbar-brand i {
color: var(--primary-color);
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-primary:hover {
background-color: #1aa07e;
border-color: #1aa07e;
}
.form-control:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 0.25rem rgba(32, 201, 151, 0.25);
}
.hero-section {
background: var(--light-grey);
padding: 4rem 0;
text-align: center;
border-radius: .5rem;
}
.hero-section h1 {
font-weight: 700;
color: var(--secondary-color);
}
.hero-section .lead {
max-width: 600px;
margin: 1.5rem auto;
}
.card {
border: 1px solid #dee2e6;
border-radius: .5rem;
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

View File

@ -0,0 +1,42 @@
<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
// Function to check if a column exists
function columnExists($pdo, $table, $column) {
$stmt = $pdo->prepare("SHOW COLUMNS FROM `$table` LIKE ?");
$stmt->execute([$column]);
return $stmt->fetch() !== false;
}
// Add scheduled_for column if it doesn't exist
if (!columnExists($pdo, 'service_requests', 'scheduled_for')) {
$pdo->exec("ALTER TABLE service_requests ADD COLUMN scheduled_for DATETIME DEFAULT NULL");
echo "Column 'scheduled_for' added.\n";
} else {
echo "Column 'scheduled_for' already exists.\n";
}
// Add job_title column if it doesn't exist
if (!columnExists($pdo, 'service_requests', 'job_title')) {
$pdo->exec("ALTER TABLE service_requests ADD COLUMN job_title VARCHAR(255) NOT NULL DEFAULT 'Service Request'");
echo "Column 'job_title' added.\n";
} else {
echo "Column 'job_title' already exists.\n";
}
// Rename service_type to job_description if service_type exists and job_description does not
if (columnExists($pdo, 'service_requests', 'service_type') && !columnExists($pdo, 'service_requests', 'job_description')) {
$pdo->exec("ALTER TABLE service_requests CHANGE service_type job_description TEXT");
echo "Column 'service_type' renamed to 'job_description'.\n";
} else {
echo "Column 'service_type' not found or 'job_description' already exists.\n";
}
echo "Migration completed successfully.";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage());
}

View File

@ -0,0 +1,25 @@
<?php
require_once __DIR__ . '/../../db/config.php';
try {
$pdo = db();
// Check if the engineers table already exists
$stmt = $pdo->query("SHOW TABLES LIKE 'engineers'");
if ($stmt->rowCount() == 0) {
$pdo->exec("
CREATE TABLE engineers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
phone VARCHAR(255) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
");
echo "Table 'engineers' created successfully." . PHP_EOL;
} else {
echo "Table 'engineers' already exists." . PHP_EOL;
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

View File

@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/../../db/config.php';
try {
$pdo = db();
// Check if the column already exists
$stmt = $pdo->query("SHOW COLUMNS FROM service_requests LIKE 'engineer_id'");
if ($stmt->rowCount() == 0) {
$pdo->exec("ALTER TABLE service_requests ADD COLUMN engineer_id INT NULL");
echo "Column 'engineer_id' added to 'service_requests' table successfully." . PHP_EOL;
} else {
echo "Column 'engineer_id' already exists in 'service_requests' table." . PHP_EOL;
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

View File

@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
// Check if the table already exists
$stmt = $pdo->query("SHOW TABLES LIKE 'contracts'");
if ($stmt->rowCount() == 0) {
$sql = "
CREATE TABLE contracts (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(255) NOT NULL,
customer_email VARCHAR(255),
customer_phone VARCHAR(50),
contract_title VARCHAR(255) NOT NULL,
start_date DATE,
end_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
";
$pdo->exec($sql);
echo "Table 'contracts' created successfully." . PHP_EOL;
} else {
echo "Table 'contracts' already exists." . PHP_EOL;
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

View File

@ -0,0 +1,24 @@
<?php
require_once __DIR__ . '/../config.php';
try {
$pdo = db();
// Check if the column already exists
$stmt = $pdo->query("SHOW COLUMNS FROM `service_requests` LIKE 'contract_id'");
if ($stmt->rowCount() == 0) {
$sql = "
ALTER TABLE service_requests
ADD COLUMN contract_id INT NULL,
ADD CONSTRAINT fk_contract_id
FOREIGN KEY (contract_id)
REFERENCES contracts(id)
ON DELETE SET NULL;
";
$pdo->exec($sql);
echo "Column 'contract_id' added to 'service_requests' table." . PHP_EOL;
} else {
echo "Column 'contract_id' already exists in 'service_requests' table." . PHP_EOL;
}
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}

41
db/setup.php Normal file
View File

@ -0,0 +1,41 @@
<?php
require_once 'config.php';
try {
$pdo = db();
// Create service_requests table
$pdo->exec("
CREATE TABLE IF NOT EXISTS `service_requests` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`phone` VARCHAR(255) NOT NULL,
`address` TEXT NOT NULL,
`job_description` TEXT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
");
// Create users table for admin authentication
$pdo->exec("
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL UNIQUE,
`password_hash` VARCHAR(255) NOT NULL
);
");
// Add a default admin user if one doesn't exist
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
$stmt->execute();
if ($stmt->fetch() === false) {
$pdo->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)")
->execute(['admin', password_hash('password', PASSWORD_DEFAULT)]);
}
echo "Database setup completed successfully.\n";
} catch (PDOException $e) {
die("Database setup failed: " . $e->getMessage() . "\n");
}

10
footer.php Normal file
View File

@ -0,0 +1,10 @@
</main>
<footer class="text-center py-4 bg-light">
<p class="text-center text-muted">&copy; <?php echo date('Y'); ?> Your Company, Inc. All rights reserved.</p>
<p class="text-center text-muted"><a href="/admin/login.php">Admin Login</a></p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

40
header.php Normal file
View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Water Purifier Service'); ?></title>
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'CRM for Water Purifier Service Business'); ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/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/style.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="index.php">
<i class="bi bi-droplet-half me-2" style="color: #20c997;"></i>
<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Water Purifier Service'); ?>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="request-service.php">Request Service</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Admin Login</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container my-5">

177
index.php
View File

@ -1,150 +1,33 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
<?php include 'header.php'; ?>
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!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>
<div class="hero-section text-center p-5 mb-4 rounded-3">
<h1 class="display-5 fw-bold">Reliable Water Purifier Service</h1>
<p class="fs-4">Your one-stop solution for installation, repair, and maintenance. Keep your water safe and pure.</p>
<a href="request-service.php" class="btn btn-primary btn-lg">Request a Service Today</a>
</div>
<div class="row text-center">
<div class="col-md-4">
<div class="card p-3">
<i class="bi bi-wrench-adjustable-circle-fill fs-1 text-primary"></i>
<h3 class="mt-3">Expert Repair</h3>
<p>Our certified technicians can fix any issue with your water purifier, ensuring optimal performance.</p>
</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>
<div class="col-md-4">
<div class="card p-3">
<i class="bi bi-shield-check fs-1 text-primary"></i>
<h3 class="mt-3">AMC Plans</h3>
<p>Enjoy peace of mind with our Annual Maintenance Contracts, including regular check-ups and filter changes.</p>
</div>
</div>
<div class="col-md-4">
<div class="card p-3">
<i class="bi bi-gem fs-1 text-primary"></i>
<h3 class="mt-3">Genuine Parts</h3>
<p>We use only genuine, high-quality spare parts and filters to guarantee the longevity of your appliance.</p>
</div>
</div>
</div>
<?php include 'footer.php'; ?>

137
request-service.php Normal file
View File

@ -0,0 +1,137 @@
<?php
require_once 'db/config.php';
// Fetch all contracts for the dropdown
$pdo = db();
$contracts_stmt = $pdo->query('SELECT id, contract_title, customer_name FROM contracts ORDER BY customer_name, contract_title');
$contracts = $contracts_stmt->fetchAll(PDO::FETCH_ASSOC);
$success_message = '';
$error_message = '';
$form_data = array_fill_keys(['name', 'phone', 'email', 'address', 'job_description', 'preferred_date', 'description', 'contract_id'], '');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize and retrieve form data
$name = trim($_POST['name'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$email = trim($_POST['email'] ?? '');
$address = trim($_POST['address'] ?? '');
$job_description = trim($_POST['job_description'] ?? '');
$preferred_date = trim($_POST['preferred_date'] ?? '');
$description = trim($_POST['description'] ?? '');
$contract_id = trim($_POST['contract_id'] ?? '');
// Store submitted data to re-populate the form on error
$form_data = compact('name', 'phone', 'email', 'address', 'job_description', 'preferred_date', 'description', 'contract_id');
// Server-side validation
if (empty($name) || empty($phone) || empty($address) || empty($job_description)) {
$error_message = 'Please fill in all required fields: Name, Phone, Address, and Service Type.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($email)) {
$error_message = 'Please provide a valid email address.';
} else {
try {
$pdo = db();
$sql = "INSERT INTO service_requests (name, phone, email, address, job_description, preferred_date, description, contract_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
// Handle empty date and contract
$date_to_insert = !empty($preferred_date) ? $preferred_date : null;
$contract_to_insert = !empty($contract_id) ? $contract_id : null;
$stmt->execute([$name, $phone, $email, $address, $job_description, $date_to_insert, $description, $contract_to_insert]);
$success_message = "Thank you! Your service request has been submitted successfully. We will contact you shortly.";
// Clear form data on success
$form_data = array_fill_keys(array_keys($form_data), '');
} catch (PDOException $e) {
// Debugging: show exact error
//var_dump($e->getMessage());
error_log("Service Request Error: " . $e->getMessage());
$error_message = 'Sorry, there was an error submitting your request. Please try again later.';
}
}
}
include 'header.php';
?>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h2 class="card-title text-center mb-4">Submit a Service Request</h2>
<?php if ($success_message): ?>
<div class="alert alert-success">
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger">
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<form action="request-service.php" method="POST" id="service-form" novalidate>
<div class="mb-3">
<label for="name" class="form-label">Full Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($form_data['name']); ?>" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number <span class="text-danger">*</span></label>
<input type="tel" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($form_data['phone']); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($form_data['email']); ?>">
</div>
<div class="mb-3">
<label for="address" class="form-label">Full Address <span class="text-danger">*</span></label>
<textarea class="form-control" id="address" name="address" rows="3" required><?php echo htmlspecialchars($form_data['address']); ?></textarea>
</div>
<div class="mb-3">
<label for="job_description" class="form-label">Service Required <span class="text-danger">*</span></label>
<select class="form-select" id="job_description" name="job_description" required>
<option value="" disabled <?php echo empty($form_data['job_description']) ? 'selected' : ''; ?>>Choose...</option>
<option value="Installation" <?php echo ($form_data['job_description'] == 'Installation') ? 'selected' : ''; ?>>New Installation</option>
<option value="Repair" <?php echo ($form_data['job_description'] == 'Repair') ? 'selected' : ''; ?>>Repair & Troubleshooting</option>
<option value="AMC Service" <?php echo ($form_data['job_description'] == 'AMC Service') ? 'selected' : ''; ?>>AMC Service</option>
<option value="Filter Change" <?php echo ($form_data['job_description'] == 'Filter Change') ? 'selected' : ''; ?>>Filter Change</option>
</select>
</div>
<div class="mb-3">
<label for="contract_id" class="form-label">Associated Contract (if any)</label>
<select class="form-select" id="contract_id" name="contract_id">
<option value="" selected>None</option>
<?php foreach ($contracts as $contract): ?>
<option value="<?php echo $contract['id']; ?>"
<?php echo ($form_data['contract_id'] == $contract['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($contract['customer_name'] . ' - ' . $contract['contract_title']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="preferred_date" class="form-label">Preferred Service Date</label>
<input type="date" class="form-control" id="preferred_date" name="preferred_date" value="<?php echo htmlspecialchars($form_data['preferred_date']); ?>">
</div>
<div class="mb-3">
<label for="description" class="form-label">Problem Description</label>
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($form_data['description']); ?></textarea>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Submit Request</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include 'footer.php'; ?>

109
whatsapp_webhook.php Normal file
View File

@ -0,0 +1,109 @@
<?php
// Log all incoming requests to a temporary file for debugging
file_put_contents('whatsapp_log.txt', print_r($_REQUEST, true), FILE_APPEND);
require_once 'db/config.php';
// --- Placeholder for a function to send a reply via WhatsApp API ---
// You will need to replace this with the actual API call from your provider (e.g., Twilio)
function send_whatsapp_reply($to, $message) {
// In a real application, you would make an HTTP request to the WhatsApp API provider here.
// For now, we will just log the message that would be sent.
$log_message = "-----
" . "TO: $to
" . "MESSAGE: $message
" . "-----
";
file_put_contents('whatsapp_sent_messages.txt', $log_message, FILE_APPEND);
}
// Get the sender's phone number and the message they sent
// The field names might be different depending on your API provider (e.g., 'From', 'Body' for Twilio)
$from = $_REQUEST['From'] ?? null;
$body = $_REQUEST['Body'] ?? null;
// Basic validation
if (!$from || !$body) {
http_response_code(400);
echo 'Missing From or Body parameter';
exit;
}
// Sanitize the input
$from = htmlspecialchars($from);
$body = trim($body);
// --- Conversation Logic ---
// We'll use a simple session system based on files to keep track of the conversation state for each user.
$session_file = 'session_' . md5($from) . '.txt';
// Get the user's current state, or start a new conversation
$session_data = file_exists($session_file) ? json_decode(file_get_contents($session_file), true) : [];
$state = $session_data['state'] ?? 'new';
// --- State Machine for the conversation ---
switch ($state) {
case 'new':
// New conversation
$session_data['state'] = 'waiting_for_name';
file_put_contents($session_file, json_encode($session_data));
send_whatsapp_reply($from, "Welcome to our service booking bot! What is your full name?");
break;
case 'waiting_for_name':
// User sent their name
$session_data['name'] = $body;
$session_data['state'] = 'waiting_for_email';
file_put_contents($session_file, json_encode($session_data));
send_whatsapp_reply($from, "Thanks, {$body}! What is your email address?");
break;
case 'waiting_for_email':
// User sent their email
if (!filter_var($body, FILTER_VALIDATE_EMAIL)) {
send_whatsapp_reply($from, "That doesn't look like a valid email. Please provide a correct email address.");
break;
}
$session_data['email'] = $body;
$session_data['state'] = 'waiting_for_description';
file_put_contents($session_file, json_encode($session_data));
send_whatsapp_reply($from, "Got it. Please describe the service you need.");
break;
case 'waiting_for_description':
// User sent the service description
$session_data['description'] = $body;
// Save to database
try {
$stmt = db()->prepare("INSERT INTO service_requests (name, email, description, status) VALUES (?, ?, ?, 'New')");
$stmt->execute([
$session_data['name'],
$session_data['email'],
$session_data['description']
]);
send_whatsapp_reply($from, "Thank you! Your service request has been booked. We will contact you shortly.");
// End of conversation, so delete the session file
unlink($session_file);
} catch (PDOException $e) {
error_log("Database Error: " . $e->getMessage());
send_whatsapp_reply($from, "Sorry, there was a problem booking your service. Please try again later.");
}
// Reset state for the next conversation
$session_data = ['state' => 'new'];
file_put_contents($session_file, json_encode($session_data));
break;
default:
send_whatsapp_reply($from, "Sorry, I'm not sure how to respond. Let's start over. What is your full name?");
// Reset state
$session_data = ['state' => 'waiting_for_name'];
file_put_contents($session_file, json_encode($session_data));
break;
}
echo "OK";