prepare( "SELECT sr.* FROM service_requests sr WHERE sr.id = ? AND (sr.dealer_id = ? OR ?)" ); $stmt->execute([$request_id, $dealer_id, $_SESSION['is_admin']]); $request = $stmt->fetch(); if (!$request) { // Request not found or doesn't belong to the dealer header('Location: service_requests.php'); exit; } // Fetch service request items $stmt_items = $pdo->prepare( "SELECT sri.serial_number, sri.issue_description, p.name as product_name FROM service_request_items sri JOIN products p ON sri.product_id = p.id WHERE sri.service_request_id = ?" ); $stmt_items->execute([$request_id]); $request_items = $stmt_items->fetchAll(); // Handle comment submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['comment'])) { $comment = trim($_POST['comment']); if (!empty($comment)) { $stmt_insert_comment = $pdo->prepare( "INSERT INTO service_request_comments (service_request_id, user_id, comment) VALUES (?, ?, ?)" ); $stmt_insert_comment->execute([$request_id, $_SESSION['user_id'], $comment]); // Create a notification $current_user_id = $_SESSION['user_id']; $request_owner_id = $request['user_id']; $message = "A new comment has been added to your service request #{$request_id}."; if ($current_user_id != $request_owner_id) { // Notify the request owner $stmt_notify = $pdo->prepare("INSERT INTO notifications (user_id, service_request_id, message) VALUES (?, ?, ?)"); $stmt_notify->execute([$request_owner_id, $request_id, $message]); } else { // Notify all admins $stmt_admins = $pdo->query("SELECT id FROM users WHERE is_admin = 1"); $admins = $stmt_admins->fetchAll(PDO::FETCH_COLUMN); $stmt_notify = $pdo->prepare("INSERT INTO notifications (user_id, service_request_id, message) VALUES (?, ?, ?)"); foreach ($admins as $admin_id) { if($admin_id != $current_user_id) { $stmt_notify->execute([$admin_id, $request_id, $message]); } } } // Redirect to the same page to prevent form resubmission header("Location: service_request_details.php?id=$request_id"); exit; } } // Fetch comments for the service request $stmt_comments = $pdo->prepare( "SELECT c.*, u.username FROM service_request_comments c JOIN users u ON c.user_id = u.id WHERE c.service_request_id = ? ORDER BY c.created_at ASC" ); $stmt_comments->execute([$request_id]); $comments = $stmt_comments->fetchAll(); } catch (PDOException $e) { die("Database error: " . $e->getMessage()); } ?>

Service Request Details

Request #

Submitted At:

Last Updated:


Products
Product Name Serial Number Issue Description

Attached File

View Attached File


Update Status
Shipment Details
prepare("SELECT * FROM shipment_details WHERE service_request_id = ?"); $stmt_shipment->execute([$request_id]); $shipments = $stmt_shipment->fetchAll(); ?>

No shipment details available.

Only administrators and dealers can add shipment details.

Carrier Tracking Number Shipment Date Actions
Edit Delete
Comments

No comments yet.