403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/tabs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/tabs/gift_card_detail.php
<?php
include 'protect.php';
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/brand_header.php';
require_once __DIR__ . '/gift_card_helpers.php';

$taxRate = getStoreTaxRate($conn);
$giftCardId = isset($_GET['gift_card_id']) ? (int) $_GET['gift_card_id'] : 0;
if ($giftCardId <= 0 && isset($_POST['gift_card_id'])) {
    $giftCardId = (int) $_POST['gift_card_id'];
}

$message = '';
$error = '';
$giftCard = null;

function hGiftDetail($value)
{
    return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = isset($_POST['action']) ? trim((string) $_POST['action']) : '';

    try {
        if ($action === 'add_gift_card_transaction') {
            $transactionDate = isset($_POST['transaction_date']) ? $_POST['transaction_date'] : '';
            $items = isset($_POST['item_description']) && is_array($_POST['item_description']) ? $_POST['item_description'] : array();
            $quantities = isset($_POST['quantity']) && is_array($_POST['quantity']) ? $_POST['quantity'] : array();
            $prices = isset($_POST['unit_price']) && is_array($_POST['unit_price']) ? $_POST['unit_price'] : array();
            $taxableRows = isset($_POST['taxable']) && is_array($_POST['taxable']) ? $_POST['taxable'] : array();
            $notesRows = isset($_POST['notes']) && is_array($_POST['notes']) ? $_POST['notes'] : array();
            $savedCount = 0;

            foreach ($items as $index => $itemDescription) {
                $itemDescription = trim((string) $itemDescription);
                $quantity = isset($quantities[$index]) ? $quantities[$index] : '';
                $unitPrice = isset($prices[$index]) ? $prices[$index] : '';
                $notes = isset($notesRows[$index]) ? $notesRows[$index] : '';
                $isTaxable = !empty($taxableRows[$index]) ? 1 : 0;

                if ($itemDescription === '' && trim((string) $quantity) === '' && trim((string) $unitPrice) === '' && trim((string) $notes) === '') {
                    continue;
                }

                addGiftCardTransaction(
                    $conn,
                    $giftCardId,
                    $transactionDate,
                    $itemDescription,
                    $quantity,
                    $unitPrice,
                    $isTaxable,
                    $notes
                );
                $savedCount++;
            }

            if ($savedCount === 0) {
                throw new RuntimeException('Enter at least one gift card item before saving.');
            }

            $message = $savedCount === 1 ? 'Gift card use saved.' : 'Gift card uses saved: ' . $savedCount . '.';
        } elseif ($action === 'update_gift_card_transaction') {
            updateGiftCardTransaction(
                $conn,
                isset($_POST['transaction_id']) ? (int) $_POST['transaction_id'] : 0,
                isset($_POST['quantity']) ? $_POST['quantity'] : '',
                isset($_POST['unit_price']) ? $_POST['unit_price'] : '',
                !empty($_POST['taxable']) ? 1 : 0,
                isset($_POST['notes']) ? $_POST['notes'] : ''
            );
            $message = 'Gift card use updated.';
        } elseif ($action === 'update_gift_card_info') {
            updateGiftCardInfo(
                $conn,
                $giftCardId,
                isset($_POST['card_label']) ? $_POST['card_label'] : '',
                isset($_POST['card_number']) ? $_POST['card_number'] : '',
                isset($_POST['card_notes']) ? $_POST['card_notes'] : ''
            );
            $message = 'Gift card details updated.';
        } elseif ($action === 'delete_gift_card_transaction') {
            deleteGiftCardTransaction($conn, isset($_POST['transaction_id']) ? (int) $_POST['transaction_id'] : 0);
            $message = 'Gift card use deleted.';
        } elseif ($action === 'archive_gift_card') {
            archiveGiftCardAndLinkedDonation($conn, $giftCardId);
            header('Location: gift_cards.php');
            exit;
        }
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
}

try {
    $giftCard = fetchGiftCard($conn, $giftCardId, $taxRate);
} catch (Exception $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Gift Card Details</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 30px;
            background: #f8fafc;
            color: #1f2937;
        }

        .container {
            max-width: 1100px;
            margin: 0 auto;
            background: #fff;
            padding: 28px;
            border-radius: 16px;
            box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
        }

        .header-row {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            gap: 16px;
            flex-wrap: wrap;
            margin-bottom: 18px;
        }

        .header-edit {
            flex: 1 1 420px;
        }

        .header-edit-form {
            display: grid;
            grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
            gap: 8px 10px;
            align-items: end;
        }

        .header-edit-form label {
            display: block;
            font-weight: 700;
            margin-bottom: 2px;
            color: #475569;
            font-size: 0.8rem;
        }

        .header-edit-form input {
            width: 100%;
            padding: 6px 8px;
            border: 1px solid #cbd5e1;
            border-radius: 10px;
            font: inherit;
            box-sizing: border-box;
        }

        .header-edit-note {
            margin-top: 4px;
            color: #64748b;
            font-size: 0.9rem;
        }

        .btn {
            display: inline-block;
            padding: 10px 14px;
            background: #1d4ed8;
            color: #fff;
            text-decoration: none;
            border: none;
            border-radius: 10px;
            font-weight: 700;
            cursor: pointer;
        }

        .btn-secondary {
            background: #64748b;
        }

        .btn-danger {
            background: #b91c1c;
        }

        .muted {
            color: #64748b;
            font-size: 0.92rem;
        }

        .msg {
            margin-bottom: 16px;
            padding: 12px 14px;
            border-radius: 10px;
        }

        .msg.ok {
            background: #ecfdf5;
            border: 1px solid #86efac;
            color: #166534;
        }

        .msg.err {
            background: #fef2f2;
            border: 1px solid #fca5a5;
            color: #991b1b;
        }

        .summary-grid {
            display: grid;
            grid-template-columns: repeat(6, minmax(0, 1fr));
            gap: 14px;
            margin-bottom: 22px;
        }

        .summary-box {
            background: #eff6ff;
            border-radius: 14px;
            padding: 14px;
        }

        .summary-box .label {
            color: #475569;
            font-size: 0.9rem;
        }

        .summary-box .value {
            margin-top: 6px;
            font-size: 1.45rem;
            font-weight: 800;
            color: #0f172a;
        }

        .negative {
            color: #b91c1c;
        }

        .card {
            background: #f8fafc;
            border: 1px solid #e5e7eb;
            border-radius: 16px;
            padding: 20px;
            margin-bottom: 22px;
        }

        .card h2 {
            margin-top: 0;
        }

        .form-grid {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 16px;
        }

        .entry-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 6px;
        }

        .entry-table th,
        .entry-table td {
            border: 1px solid #dbe5f1;
            padding: 8px;
            vertical-align: middle;
        }

        .entry-table th {
            background: #eff6ff;
            font-size: 0.92rem;
        }

        .entry-table input[type="text"],
        .entry-table input[type="number"] {
            width: 100%;
            padding: 8px 9px;
            min-width: 0;
        }

        .entry-table input[type="checkbox"] {
            width: auto;
            transform: scale(1.1);
        }

        .full {
            grid-column: 1 / -1;
        }

        label {
            display: block;
            font-weight: 700;
            margin-bottom: 6px;
            color: #475569;
        }

        input, textarea {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #cbd5e1;
            border-radius: 10px;
            font: inherit;
            box-sizing: border-box;
        }

        textarea {
            min-height: 82px;
            resize: vertical;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            text-align: left;
            padding: 10px 8px;
            border-bottom: 1px solid #e5e7eb;
            vertical-align: top;
        }

        th {
            background: #eff6ff;
            white-space: nowrap;
        }

        @media (max-width: 900px) {
            .summary-grid, .form-grid {
                grid-template-columns: 1fr;
            }

            .header-edit-form {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
    <?php renderAppBrandHeader(); ?>

    <div class="header-row">
        <div class="header-edit">
            <?php if ($giftCard): ?>
                <form method="post" class="header-edit-form">
                    <input type="hidden" name="action" value="update_gift_card_info">
                    <input type="hidden" name="gift_card_id" value="<?php echo hGiftDetail($giftCard['id']); ?>">
                    <div>
                        <label for="card_label">Card Name / Label</label>
                        <input id="card_label" name="card_label" type="text" value="<?php echo hGiftDetail($giftCard['card_label']); ?>" required>
                    </div>
                    <div>
                        <label for="card_number">Card Number</label>
                        <input id="card_number" name="card_number" type="text" value="<?php echo hGiftDetail($giftCard['card_number']); ?>">
                    </div>
                    <div>
                        <button class="btn btn-secondary" type="submit" style="padding:8px 10px;font-size:0.88rem;">Save</button>
                    </div>
                </form>
                <div class="header-edit-note">Track partial gift card use here. Tax is added into the amount used when taxable is checked.</div>
            <?php else: ?>
                <h1 style="margin:0;">Gift Card</h1>
            <?php endif; ?>
        </div>
        <div style="display:flex;gap:10px;flex-wrap:wrap;">
            <?php if ($giftCard): ?>
                <form method="post" onsubmit="return confirm('Remove this gift card to the archive? If it is linked to a donation, that donation will be moved to the archive too.');" style="margin:0;">
                    <input type="hidden" name="action" value="archive_gift_card">
                    <input type="hidden" name="gift_card_id" value="<?php echo hGiftDetail($giftCard['id']); ?>">
                    <button class="btn btn-danger" type="submit">Remove Card</button>
                </form>
            <?php endif; ?>
            <a class="btn btn-secondary" href="gift_cards.php">&larr; Back to Gift Cards</a>
        </div>
    </div>

    <?php if ($message !== ''): ?>
        <div class="msg ok"><?php echo hGiftDetail($message); ?></div>
    <?php endif; ?>

    <?php if ($error !== ''): ?>
        <div class="msg err"><?php echo hGiftDetail($error); ?></div>
    <?php endif; ?>

    <?php if ($giftCard): ?>
        <div class="summary-grid">
            <div class="summary-box">
                <div class="label">Issued</div>
                <div class="value"><?php echo hGiftDetail($giftCard['issued_date']); ?></div>
            </div>
            <div class="summary-box">
                <div class="label">Expires</div>
                <div class="value"><?php echo hGiftDetail($giftCard['expiration_date']); ?></div>
            </div>
            <div class="summary-box">
                <div class="label">Starting Amount</div>
                <div class="value">$<?php echo hGiftDetail(number_format((float) $giftCard['initial_amount'], 2)); ?></div>
            </div>
            <div class="summary-box">
                <div class="label">Used</div>
                <div class="value">$<?php echo hGiftDetail(number_format((float) $giftCard['spent_total'], 2)); ?></div>
            </div>
            <div class="summary-box">
                <div class="label">Remaining</div>
                <div class="value <?php echo (float) $giftCard['remaining_balance'] < 0 ? 'negative' : ''; ?>">
                    $<?php echo hGiftDetail(number_format((float) $giftCard['remaining_balance'], 2)); ?>
                </div>
            </div>
            <div class="summary-box">
                <div class="label">Amount Still Owed</div>
                <div class="value <?php echo (float) $giftCard['amount_owed'] > 0 ? 'negative' : ''; ?>">
                    $<?php echo hGiftDetail(number_format((float) $giftCard['amount_owed'], 2)); ?>
                </div>
            </div>
        </div>

        <?php if (!empty($giftCard['is_donation'])): ?>
            <div class="card" style="padding:14px 18px;">
                <strong>Linked Donation:</strong>
                <div class="muted" style="margin-top:6px;">
                    This gift card was marked as a donation<?php echo !empty($giftCard['donation_recipient']) ? ' for ' . hGiftDetail($giftCard['donation_recipient']) : ''; ?>.
                    <a href="donations.php" style="margin-left:8px;color:#1d4ed8;text-decoration:none;">Open Donations</a>
                </div>
            </div>
        <?php endif; ?>

        <div class="card">
            <h2>Add Gift Card Use</h2>
            <?php if ((float) $giftCard['amount_owed'] > 0): ?>
                <div class="msg err" style="margin-top:0;">This card has already gone over. Amount still owed: $<?php echo hGiftDetail(number_format((float) $giftCard['amount_owed'], 2)); ?></div>
            <?php endif; ?>
            <?php if (!empty($giftCard['notes'])): ?>
                <div class="muted" style="margin:-4px 0 10px;">Card notes: <?php echo hGiftDetail($giftCard['notes']); ?></div>
            <?php endif; ?>
            <form method="post">
                <input type="hidden" name="action" value="add_gift_card_transaction">
                <input type="hidden" name="gift_card_id" value="<?php echo hGiftDetail($giftCard['id']); ?>">

                <div class="form-grid">
                    <div>
                        <label for="transaction_date">Date</label>
                        <input id="transaction_date" name="transaction_date" type="date" value="<?php echo hGiftDetail(date('Y-m-d')); ?>" required>
                    </div>
                    <div class="full">
                        <label>Items</label>
                        <table class="entry-table">
                            <thead>
                                <tr>
                                    <th style="width:90px;">Qty</th>
                                    <th>Item</th>
                                    <th style="width:120px;">Price</th>
                                    <th style="width:90px;">Taxable</th>
                                    <th>Notes</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php for ($rowIndex = 0; $rowIndex < 3; $rowIndex++): ?>
                                    <tr>
                                        <td><input type="number" name="quantity[]" step="0.01" min="0.01" value="1.00"></td>
                                        <td><input type="text" name="item_description[]" placeholder="What was bought with the card"></td>
                                        <td><input type="number" name="unit_price[]" step="0.01" min="0.00" placeholder="0.00"></td>
                                        <td style="text-align:center;"><input type="checkbox" name="taxable[<?php echo $rowIndex; ?>]" value="1"></td>
                                        <td><input type="text" name="notes[]" placeholder="Optional note"></td>
                                    </tr>
                                <?php endfor; ?>
                            </tbody>
                        </table>
                        <div class="muted" style="margin-top:8px;">Current store tax rate: <?php echo hGiftDetail(number_format($taxRate * 100, 2)); ?>%. Blank rows are ignored.</div>
                    </div>
                </div>

                <div style="margin-top:18px;">
                    <button class="btn" type="submit">Save Gift Card Uses</button>
                </div>
            </form>
        </div>

        <div class="card">
            <h2>Uses / Charges</h2>
            <?php if (empty($giftCard['transactions'])): ?>
                <div class="muted">No charges have been entered for this gift card yet.</div>
            <?php else: ?>
                <table>
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Item</th>
                            <th>Qty</th>
                            <th>Price</th>
                            <th>Taxable</th>
                            <th>Tax</th>
                            <th>Total</th>
                            <th>Notes</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($giftCard['transactions'] as $transaction): ?>
                        <?php $updateFormId = 'gift-card-transaction-' . (int) $transaction['id']; ?>
                        <tr>
                            <td><?php echo hGiftDetail($transaction['transaction_date']); ?></td>
                            <td><?php echo hGiftDetail($transaction['item_description']); ?></td>
                            <td>
                                <input form="<?php echo hGiftDetail($updateFormId); ?>" type="number" name="quantity" step="0.01" min="0.01" value="<?php echo hGiftDetail(number_format((float) $transaction['quantity'], 2, '.', '')); ?>" style="max-width:84px;padding:8px 10px;">
                            </td>
                            <td>
                                <div style="display:flex;align-items:center;gap:6px;">
                                    <span>$</span>
                                    <input form="<?php echo hGiftDetail($updateFormId); ?>" type="number" name="unit_price" step="0.01" min="0.00" value="<?php echo hGiftDetail(number_format((float) $transaction['unit_price'], 2, '.', '')); ?>" style="max-width:92px;padding:8px 10px;">
                                </div>
                            </td>
                            <td>
                                <input form="<?php echo hGiftDetail($updateFormId); ?>" type="checkbox" name="taxable" value="1" <?php echo !empty($transaction['taxable']) ? 'checked' : ''; ?> style="width:auto;">
                            </td>
                            <td>$<?php echo hGiftDetail(number_format((float) $transaction['tax_amount'], 2)); ?></td>
                            <td>$<?php echo hGiftDetail(number_format((float) $transaction['line_total'], 2)); ?></td>
                            <td>
                                <input form="<?php echo hGiftDetail($updateFormId); ?>" type="text" name="notes" value="<?php echo hGiftDetail($transaction['notes']); ?>" style="min-width:180px;">
                            </td>
                            <td>
                                <form method="post" id="<?php echo hGiftDetail($updateFormId); ?>" style="margin:0;">
                                    <input type="hidden" name="action" value="update_gift_card_transaction">
                                    <input type="hidden" name="gift_card_id" value="<?php echo hGiftDetail($giftCard['id']); ?>">
                                    <input type="hidden" name="transaction_id" value="<?php echo hGiftDetail($transaction['id']); ?>">
                                </form>
                                <button form="<?php echo hGiftDetail($updateFormId); ?>" class="btn btn-secondary" type="submit" style="padding:8px 11px;font-size:0.9rem;">Update</button>
                                <form method="post" onsubmit="return confirm('Delete this gift card charge?');" style="margin-top:8px;">
                                    <input type="hidden" name="action" value="delete_gift_card_transaction">
                                    <input type="hidden" name="gift_card_id" value="<?php echo hGiftDetail($giftCard['id']); ?>">
                                    <input type="hidden" name="transaction_id" value="<?php echo hGiftDetail($transaction['id']); ?>">
                                    <button class="btn btn-danger" type="submit" style="padding:8px 11px;font-size:0.9rem;">Delete</button>
                                </form>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    <?php endif; ?>
</div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit