<?php
session_name('super_admin_session');
if (!is_dir(dirname(__DIR__) . '/session_data/super')) { mkdir(dirname(__DIR__) . '/session_data/super', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/super');
session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);
session_start();
include('includes/dbconnection.php');


if (isset($_GET['id'])) {
    $id = $_GET['id'];

    // Fetch the message by ID
    $query = "SELECT * FROM message WHERE id = ?";
    $stmt = $con->prepare($query);
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $messageData = $result->fetch_assoc();
        $_SESSION['message_data'] = $messageData;

        // Fetch the redirection page from fee_name table
        $fee_query = "SELECT redirect_page FROM fees WHERE name = ?";
        $fee_stmt = $con->prepare($fee_query);
        $fee_stmt->bind_param("s", $messageData['purpose']);
        $fee_stmt->execute();
        $fee_result = $fee_stmt->get_result();

        if ($fee_result->num_rows > 0) {
            $fee_data = $fee_result->fetch_assoc();
            $approvalPage = $fee_data['redirect_page'];
        } else {
            $approvalPage = 'otherpay.php'; // Default page
        }

        header("Location: $approvalPage?id=$id");
        exit();
    } else {
        echo "Message not found.";
    }
} else {
    echo "Invalid request.";
}
?>


