diff --git a/admin/contracts.php b/admin/contracts.php index 10264a1..470b2ac 100644 --- a/admin/contracts.php +++ b/admin/contracts.php @@ -116,8 +116,8 @@ require_once __DIR__ . '/../header.php'; - Edit - Delete + Edit + Delete diff --git a/admin/customer_history.php b/admin/customer_history.php new file mode 100644 index 0000000..fbee3c9 --- /dev/null +++ b/admin/customer_history.php @@ -0,0 +1,87 @@ +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'; +?> + +
+
+
+

History for

+

+ Email: | + Phone: +

+
+ Back to Customer List +
+ +
+
+ 0): ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDJob TitleJob DescriptionContractStatusSubmittedLast Updated
+ + + + N/A + +
+
+ +

No service requests found for this customer.

+ +
+
+
+ + diff --git a/admin/customers.php b/admin/customers.php new file mode 100644 index 0000000..7f6c8fc --- /dev/null +++ b/admin/customers.php @@ -0,0 +1,63 @@ +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'; +?> + +
+
+

Customer History

+ Back to Dashboard +
+ +
+
+ 0): ?> +
+ + + + + + + + + + + + + + + + + + + + + +
Customer NameEmailPhoneService RequestsAction
+ View History +
+
+ +

No customers found.

+ +
+
+
+ + diff --git a/admin/delete_contract.php b/admin/delete_contract.php new file mode 100644 index 0000000..40ad171 --- /dev/null +++ b/admin/delete_contract.php @@ -0,0 +1,13 @@ +prepare('DELETE FROM contracts WHERE id = ?'); + $stmt->execute([$id]); +} + +header('Location: contracts.php'); +exit; diff --git a/admin/edit_contract.php b/admin/edit_contract.php new file mode 100644 index 0000000..abc1554 --- /dev/null +++ b/admin/edit_contract.php @@ -0,0 +1,93 @@ +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'; +?> + +
+
+

Edit Contract

+
+ Back to Contracts + Logout +
+
+ + +
+
+ Update Contract Details +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
Contract not found.
+ +
+ + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index 245715d..e9bbd3a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -27,6 +27,7 @@ require_once '../header.php';
Manage Engineers Manage Contracts + Customer History Logout
diff --git a/db/setup.php b/db/setup.php index e21844a..a19c9c0 100644 --- a/db/setup.php +++ b/db/setup.php @@ -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 ); "); diff --git a/request-service.php b/request-service.php index acd208c..d61305c 100644 --- a/request-service.php +++ b/request-service.php @@ -1,8 +1,5 @@ '; -var_dump($_POST); -echo ''; + 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 '
';
-        var_dump($name, $phone, $email, $address, $service_type, $preferred_date, $description, $contract_id);
-        echo '
'; + 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';
- - + + + + +