prepare("SELECT cr.status, cr.change_title FROM change_requests cr WHERE cr.id = :id"); $stmt->bindParam(':id', $requestId, PDO::PARAM_INT); $stmt->execute(); $request = $stmt->fetch(PDO::FETCH_ASSOC); if (!$request) { $_SESSION['error_message'] = "Request not found."; header('Location: all_requests.php'); exit; } // Update the request status and/or comment $sql = "UPDATE change_requests SET status = :status, admin_comment = :comment WHERE id = :id"; $stmt = $pdoconn->prepare($sql); $stmt->bindParam(':status', $newStatus, PDO::PARAM_STR); $stmt->bindParam(':comment', $adminComment, PDO::PARAM_STR); $stmt->bindParam(':id', $requestId, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { $_SESSION['success_message'] = "Request status updated successfully."; // Send email notification if the status has changed if ($request['status'] !== $newStatus) { // NOTE: Email sending is disabled because requester email is not available in the users table. /* $to = $request['requester_email']; // This column does not exist $subject = "Update on your Change Request #{$requestId}"; $body = "

The status of your change request '{$request['change_title']}' has been updated to " . htmlspecialchars(ucfirst($newStatus)) . ".

"; if (!empty($adminComment)) { $body .= "

Admin Comment: " . htmlspecialchars($adminComment) . "

"; } $body .= "

You can view the request here: View Request

"; MailService::sendMail($to, $subject, $body, strip_tags($body)); $_SESSION['success_message'] = "Request status updated and notification sent."; */ } } else { $_SESSION['info_message'] = "No changes were made to the request."; } } catch (PDOException $e) { $_SESSION['error_message'] = "Database error: " . $e->getMessage(); error_log("DB Error: " . $e->getMessage()); } catch (Exception $e) { $_SESSION['error_message'] = "Error: " . $e->getMessage(); error_log("General Error: " . $e->getMessage()); } header('Location: view_request.php?id=' . $requestId); exit;