HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/video-rental/wp-content/themes/video-rental-olds/invoices/transaction_user.php
<?php
// 🔒 IMPORTANT: No whitespace before this line

ob_start(); // Start output buffering early

require_once('../../../../wp-load.php');
require_once(dirname(__DIR__) . '/vendor/autoload.php'); // Dompdf autoload

use Dompdf\Dompdf;
use Dompdf\Options;

$transid = isset($_GET['transid']) ? intval($_GET['transid']) : 0;
global $wpdb;

$transactions = $wpdb->get_results(
    $wpdb->prepare(
        "SELECT t.*, r.*
         FROM wp_video_transactions t
         LEFT JOIN wp_video_rentals r ON t.rental_id = r.id
         WHERE r.id = %d",
        $transid
    )
);

$total = 0;
$rows = '';
$sl = 1;

foreach ($transactions as $txn) {
    $total += floatval($txn->amount);
    $post = get_post($txn->video_id);
    $title = $post ? $post->post_title : 'Untitled';

    $rented_from = new DateTime($txn->rented_at ?? 'now');
    $rented_to = clone $rented_from;

    if (!empty($txn->duration_days) && is_numeric($txn->duration_days)) {
        $rented_to->modify("+{$txn->duration_days} days");
    }

    $rows .= "<tr>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>{$sl}</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>{$txn->transaction_id}</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>{$title}</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>" . $rented_from->format('M d, Y h:i a') . "</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>" . $rented_to->format('M d, Y h:i a') . "</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>{$txn->license}</td>
        <td style='color: #ffffff; font-family: Ubuntu, sans-serif; font-size: 11px; font-weight: 400; padding: 19px 20px; background-color: #0E0E0E;'>$ " . number_format($txn->amount, 2) . "</td>
    </tr>";
    $sl++;
}

// Build HTML
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Invoice</title>
    <style>
        @page { margin: 0; }
        body { margin: 0; font-family: 'Ubuntu', sans-serif; background: #000; color: #fff; }
        table { border-collapse: collapse; width: 100%; }
        th, td { padding: 12px; }
        th { background-color: #1a1a1a; color: #F9B548; }
    </style>
</head>
<body>
    <div style="padding:50px;">
        <table>
            <tr>
                <td style="text-align: left; font-size: 30px; color: #F9B548;">Invoice</td>
                <td style="text-align: right;">
                    <img src="<?php echo get_template_directory_uri(); ?>/img/logo.svg" style="width:81px;">
                </td>
            </tr>
        </table>

        <table style="margin-top: 40px; background: #0E0E0E;">
            <thead>
                <tr>
                    <th>Sl</th>
                    <th>Transaction ID</th>
                    <th>Purchase title</th>
                    <th>Transaction date</th>
                    <th>Rented till</th>
                    <th>License</th>
                    <th>Amount</th>
                </tr>
            </thead>
            <tbody>
                <?php echo $rows ?: "<tr><td colspan='7' style='color:#fff; padding:20px;'>No transactions found</td></tr>"; ?>
            </tbody>
        </table>

        <table style="margin-top: 30px;" align="right" width="300">
            <tr>
                <td style="color: #F9B548;">SubTotal:</td>
                <td style="text-align: right;">$<?php echo number_format($total, 2); ?></td>
            </tr>
            <tr>
                <td style="color: #F9B548; font-weight: bold;">Total:</td>
                <td style="text-align: right; font-weight: bold;">$<?php echo number_format($total, 2); ?></td>
            </tr>
        </table>
    </div>
</body>
</html>
<?php
$html = ob_get_clean();

// Dompdf settings
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);

$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();

// Clean buffer to prevent header issues
ob_end_clean();
$dompdf->stream("invoice_{$transid}.pdf", ['Attachment' => false]);
exit;