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/donations.php
<?php
include 'protect.php';
include 'db.php';
require_once __DIR__ . '/brand_header.php';
require_once __DIR__ . '/donation_helpers.php';
require_once __DIR__ . '/gift_card_helpers.php';

$rawMonth = date('Y-m');
if (isset($_GET['month']) && $_GET['month'] !== '') {
    $rawMonth = $_GET['month'];
} elseif (isset($_POST['month']) && $_POST['month'] !== '') {
    $rawMonth = $_POST['month'];
}
$selectedMonth = normalizeDonationMonth($rawMonth);
$exportScope = isset($_REQUEST['export_scope']) ? normalizeDonationExportScope($_REQUEST['export_scope']) : 'month';
$startDate = isset($_REQUEST['start_date']) ? normalizeDonationDate($_REQUEST['start_date']) : '';
$endDate = isset($_REQUEST['end_date']) ? normalizeDonationDate($_REQUEST['end_date']) : '';
$message = '';
$error = '';
$donations = array();
$monthlyTotal = 0.0;
$totalsByAccount = array();

function hDonation($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_donation') {
            addDonation(
                $conn,
                isset($_POST['donation_date']) ? $_POST['donation_date'] : '',
                isset($_POST['recipient_name']) ? $_POST['recipient_name'] : '',
                isset($_POST['qbo_account']) ? $_POST['qbo_account'] : '',
                isset($_POST['item_description']) ? $_POST['item_description'] : '',
                isset($_POST['quantity']) ? $_POST['quantity'] : '',
                isset($_POST['unit_price']) ? $_POST['unit_price'] : '',
                isset($_POST['notes']) ? $_POST['notes'] : ''
            );
            $message = 'Donation saved.';
        } elseif ($action === 'update_donation') {
            updateDonation(
                $conn,
                isset($_POST['donation_id']) ? (int) $_POST['donation_id'] : 0,
                isset($_POST['quantity']) ? $_POST['quantity'] : '',
                isset($_POST['unit_price']) ? $_POST['unit_price'] : ''
            );
            $message = 'Donation updated.';
        } elseif ($action === 'archive_donation') {
            archiveDonationAndLinkedGiftCard($conn, isset($_POST['donation_id']) ? (int) $_POST['donation_id'] : 0);
            $message = 'Donation moved to archive.';
        }
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
}

try {
    ensureDonationsTable($conn);
    $donations = fetchDonationsForExport($conn, $exportScope, $selectedMonth, $startDate, $endDate);
    $monthlyTotal = donationMonthlyTotal($donations);
    $totalsByAccount = donationTotalsByAccount($donations);
} catch (Exception $e) {
    $error = $e->getMessage();
}

$months = array();
for ($i = 0; $i < 24; $i++) {
    $months[] = date('Y-m', strtotime("-{$i} months"));
}

if (isset($_GET['export']) && $_GET['export'] === 'csv' && $error === '') {
    $csv = exportDonationsCsv($donations);
    $filename = donationExportFilename($exportScope, $selectedMonth, $startDate, $endDate);

    header('Content-Type: text/csv; charset=UTF-8');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    echo $csv;
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Donations</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);
        }

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

        .toolbar form {
            display: flex;
            gap: 12px;
            align-items: flex-end;
            flex-wrap: wrap;
        }

        .toolbar label {
            margin-bottom: 4px;
            font-size: 0.92rem;
        }

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

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

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

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

        .toolbar .btn {
            padding: 9px 13px;
            font-size: 0.92rem;
        }

        .toolbar select {
            padding: 8px 10px;
            font-size: 0.94rem;
        }

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

        .btn-danger {
            background: #b91c1c;
        }

        .grid {
            display: grid;
            grid-template-columns: 1.1fr 0.9fr;
            gap: 22px;
            margin-bottom: 24px;
        }

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

        .card h2 {
            margin-top: 0;
        }

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

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

        .summary-total {
            font-size: 32px;
            font-weight: 800;
            color: #0f172a;
        }

        .title-line {
            display: flex;
            align-items: baseline;
            gap: 12px;
            flex-wrap: wrap;
        }

        .title-note {
            color: #64748b;
            font-size: 0.95rem;
        }

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

        .msg.ok {
            background: #ecfdf5;
            border: 1px solid #86efac;
            color: #166534;
            transition: opacity 0.8s ease, transform 0.8s ease;
        }

        .msg.fade-out {
            opacity: 0;
            transform: translateY(-4px);
        }

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

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }

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

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

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

        .empty {
            padding: 18px 0;
            color: #64748b;
        }

        @media (max-width: 900px) {
            .grid, .form-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
    <?php renderAppBrandHeader(); ?>

    <div class="toolbar">
        <div>
            <div class="title-line">
                <h1 style="margin:0;">Donations</h1>
                <div class="title-note">Track cash, store product, and other donation write-offs by month.</div>
            </div>
        </div>

        <form method="get">
            <div>
                <label for="export_scope">Show / Export</label>
                <select id="export_scope" name="export_scope">
                    <option value="month" <?php echo $exportScope === 'month' ? 'selected' : ''; ?>>By Month</option>
                    <option value="range" <?php echo $exportScope === 'range' ? 'selected' : ''; ?>>By Date Range</option>
                    <option value="all" <?php echo $exportScope === 'all' ? 'selected' : ''; ?>>All</option>
                </select>
            </div>
            <div>
                <label for="month">Month</label>
                <select id="month" name="month">
                    <?php foreach ($months as $month): ?>
                        <option value="<?php echo hDonation($month); ?>" <?php echo $selectedMonth === $month ? 'selected' : ''; ?>>
                            <?php echo hDonation(date('F Y', strtotime($month . '-01'))); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div>
                <label for="start_date">Start Date</label>
                <input id="start_date" name="start_date" type="date" value="<?php echo hDonation($startDate); ?>">
            </div>
            <div>
                <label for="end_date">End Date</label>
                <input id="end_date" name="end_date" type="date" value="<?php echo hDonation($endDate); ?>">
            </div>
            <div>
                <button class="btn btn-secondary" type="submit">Apply</button>
            </div>
            <div>
                <button class="btn" type="submit" name="export" value="csv">Export CSV</button>
            </div>
            <div>
                <a class="btn btn-secondary" href="donations_archive.php">Donation Archive</a>
            </div>
            <div>
                <a class="btn btn-secondary" href="index.php">Back to Dashboard</a>
            </div>
        </form>
    </div>

    <div class="muted" style="margin:-2px 0 14px;">
        For CSV export, choose `By Date Range` and fill in `Start Date` and `End Date`, or switch to `All`.
    </div>

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

    <div class="grid">
        <div class="card">
            <h2>Add Donation</h2>
            <form method="post">
                <input type="hidden" name="action" value="add_donation">
                <input type="hidden" name="month" value="<?php echo hDonation($selectedMonth); ?>">

                <div class="form-grid">
                    <div>
                        <label for="donation_date">Donation Date</label>
                        <input id="donation_date" name="donation_date" type="date" value="<?php echo hDonation(date('Y-m-d')); ?>" required>
                    </div>
                    <div>
                        <label for="recipient_name">Recipient / Organization</label>
                        <input id="recipient_name" name="recipient_name" type="text" placeholder="School fundraiser, church, club..." required>
                    </div>
                    <div>
                        <label for="qbo_account">QBO Account / Category</label>
                        <input id="qbo_account" name="qbo_account" type="text" placeholder="Donations, Charitable Contributions..." required>
                    </div>
                    <div>
                        <label for="item_description">Item Description</label>
                        <input id="item_description" name="item_description" type="text" placeholder="Feed, gift basket, raffle items..." required>
                    </div>
                    <div>
                        <label for="quantity">Quantity</label>
                        <input id="quantity" name="quantity" type="number" step="0.01" min="0.01" value="1.00" required>
                    </div>
                    <div>
                        <label for="unit_price">Price</label>
                        <input id="unit_price" name="unit_price" type="number" step="0.01" min="0.00" placeholder="0.00" required>
                    </div>
                    <div class="full">
                        <label for="notes">Notes</label>
                        <textarea id="notes" name="notes" placeholder="Optional details for your records"></textarea>
                    </div>
                </div>

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

        <div class="card">
            <h2><?php echo hDonation(date('F Y', strtotime($selectedMonth . '-01'))); ?> Summary</h2>
            <?php if ($message !== ''): ?>
                <div id="donation-save-message" class="msg ok" style="margin-top:0;"><?php echo hDonation($message); ?></div>
            <?php endif; ?>
            <div class="summary-total">$<?php echo hDonation(number_format($monthlyTotal, 2)); ?></div>
            <div class="muted" style="margin-top:8px;">Monthly total for donations entered here.</div>

            <h3 style="margin:24px 0 12px;">Totals by QBO Account</h3>
            <?php if (!$totalsByAccount): ?>
                <div class="empty">No donations entered for this month yet.</div>
            <?php else: ?>
                <table>
                    <thead>
                        <tr>
                            <th>QBO Account</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($totalsByAccount as $account => $total): ?>
                        <tr>
                            <td><?php echo hDonation($account); ?></td>
                            <td>$<?php echo hDonation(number_format($total, 2)); ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>

    <div class="card">
        <h2 style="margin-top:0;"><?php echo hDonation(date('F Y', strtotime($selectedMonth . '-01'))); ?> Entries</h2>

        <?php if (!$donations): ?>
            <div class="empty">No donations have been entered for this month.</div>
        <?php else: ?>
            <table>
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Recipient</th>
                        <th>Account</th>
                        <th>Description</th>
                        <th>Qty</th>
                        <th>Price</th>
                        <th>Total</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach ($donations as $donation): ?>
                    <?php $updateFormId = 'donation-update-' . (int) $donation['id']; ?>
                    <tr>
                        <td><?php echo hDonation($donation['donation_date']); ?></td>
                        <td><?php echo hDonation($donation['recipient_name']); ?></td>
                        <td><?php echo hDonation($donation['qbo_account']); ?></td>
                        <td>
                            <?php echo hDonation($donation['item_description']); ?>
                            <?php if (donationLinkedGiftCardId($conn, (int) $donation['id']) > 0): ?>
                                <div class="muted" style="margin-top:4px;color:#166534;">Linked gift card donation</div>
                            <?php endif; ?>
                            <?php if (!empty($donation['notes'])): ?>
                                <div class="muted" style="margin-top:4px;"><?php echo hDonation($donation['notes']); ?></div>
                            <?php endif; ?>
                        </td>
                        <td>
                            <input form="<?php echo hDonation($updateFormId); ?>" type="number" name="quantity" step="0.01" min="0.01" value="<?php echo hDonation(number_format((float) $donation['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 hDonation($updateFormId); ?>" type="number" name="unit_price" step="0.01" min="0.00" value="<?php echo hDonation(number_format((float) $donation['unit_price'], 2, '.', '')); ?>" style="max-width:92px;padding:8px 10px;">
                            </div>
                        </td>
                        <td>$<?php echo hDonation(number_format((float) $donation['line_total'], 2)); ?></td>
                        <td>
                            <form method="post" id="<?php echo hDonation($updateFormId); ?>" style="margin:0;">
                                <input type="hidden" name="action" value="update_donation">
                                <input type="hidden" name="month" value="<?php echo hDonation($selectedMonth); ?>">
                                <input type="hidden" name="donation_id" value="<?php echo hDonation($donation['id']); ?>">
                            </form>
                            <button form="<?php echo hDonation($updateFormId); ?>" class="btn btn-secondary" type="submit" style="padding:8px 11px;font-size:0.9rem;">Update</button>
                            <form method="post" onsubmit="return confirm('Remove this donation to the archive? If it is linked to a gift card, that card will be moved to the archive too.');" style="margin-top:8px;">
                                <input type="hidden" name="action" value="archive_donation">
                                <input type="hidden" name="month" value="<?php echo hDonation($selectedMonth); ?>">
                                <input type="hidden" name="donation_id" value="<?php echo hDonation($donation['id']); ?>">
                                <button class="btn btn-danger" type="submit" style="padding:8px 11px;font-size:0.9rem;">Remove</button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>
<script>
var donationSaveMessage = document.getElementById('donation-save-message');
if (donationSaveMessage) {
    window.setTimeout(function () {
        donationSaveMessage.className += ' fade-out';
        window.setTimeout(function () {
            if (donationSaveMessage && donationSaveMessage.parentNode) {
                donationSaveMessage.parentNode.removeChild(donationSaveMessage);
            }
        }, 900);
    }, 10000);
}
</script>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit