update
This commit is contained in:
parent
e825aa97f2
commit
3be72a2961
@ -116,8 +116,8 @@ require_once __DIR__ . '/../header.php';
|
||||
<small><?php echo htmlspecialchars($contract['customer_phone']); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-outline-primary disabled">Edit</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-danger disabled">Delete</a>
|
||||
<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; ?>
|
||||
|
||||
87
admin/customer_history.php
Normal file
87
admin/customer_history.php
Normal 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
63
admin/customers.php
Normal 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
13
admin/delete_contract.php
Normal 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
93
admin/edit_contract.php
Normal 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'; ?>
|
||||
@ -27,6 +27,7 @@ require_once '../header.php';
|
||||
<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>
|
||||
|
||||
@ -11,7 +11,7 @@ try {
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`phone` VARCHAR(255) NOT NULL,
|
||||
`address` TEXT NOT NULL,
|
||||
`service_type` VARCHAR(255) NOT NULL,
|
||||
`job_description` TEXT NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
");
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
<?php
|
||||
// Debugging: Dump POST data
|
||||
echo '<pre>';
|
||||
var_dump($_POST);
|
||||
echo '</pre>';
|
||||
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
@ -13,7 +10,7 @@ $contracts = $contracts_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$success_message = '';
|
||||
$error_message = '';
|
||||
$form_data = array_fill_keys(['name', 'phone', 'email', 'address', 'service_type', 'preferred_date', 'description', 'contract_id'], '');
|
||||
$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
|
||||
@ -21,33 +18,31 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$phone = trim($_POST['phone'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$address = trim($_POST['address'] ?? '');
|
||||
$service_type = trim($_POST['service_type'] ?? '');
|
||||
$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', 'service_type', 'preferred_date', 'description', 'contract_id');
|
||||
$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($service_type)) {
|
||||
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 {
|
||||
echo '<pre>';
|
||||
var_dump($name, $phone, $email, $address, $service_type, $preferred_date, $description, $contract_id);
|
||||
echo '</pre>';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "INSERT INTO service_requests (name, phone, email, address, service_type, preferred_date, description, contract_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
$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, $service_type, $date_to_insert, $description, $contract_to_insert]);
|
||||
$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
|
||||
@ -55,7 +50,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Debugging: show exact error
|
||||
var_dump($e->getMessage());
|
||||
//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.';
|
||||
}
|
||||
@ -101,13 +96,13 @@ include 'header.php';
|
||||
<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="service_type" class="form-label">Service Required <span class="text-danger">*</span></label>
|
||||
<select class="form-select" id="service_type" name="service_type" required>
|
||||
<option value="" disabled <?php echo empty($form_data['service_type']) ? 'selected' : ''; ?>>Choose...</option>
|
||||
<option value="Installation" <?php echo ($form_data['service_type'] == 'Installation') ? 'selected' : ''; ?>>New Installation</option>
|
||||
<option value="Repair" <?php echo ($form_data['service_type'] == 'Repair') ? 'selected' : ''; ?>>Repair & Troubleshooting</option>
|
||||
<option value="AMC Service" <?php echo ($form_data['service_type'] == 'AMC Service') ? 'selected' : ''; ?>>AMC Service</option>
|
||||
<option value="Filter Change" <?php echo ($form_data['service_type'] == 'Filter Change') ? 'selected' : ''; ?>>Filter Change</option>
|
||||
<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">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user