« Back to History
policy_master.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('policy_master'); $u = $ctx['user'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); $pdo = $ctx['pdo'] ?? null; // CSRF if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } // ---------- DELETE ---------- if (isset($_POST['delete_id'])) { if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'] ?? '')) { die("Invalid CSRF token"); } $stmt = $pdo->prepare("DELETE FROM policy_master WHERE id=? AND company_id=?"); $stmt->execute([(int)$_POST['delete_id'], $company_id]); header("Location: policy_master_list.php"); exit; } // ---------- FETCH ---------- $stmt = $pdo->prepare("SELECT * FROM policy_master WHERE company_id=? ORDER BY id DESC"); $stmt->execute([$company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container mt-4"> <div class="card"> <div class="card-header d-flex justify-content-between align-items-center"> <h5 class="mb-0">Policy Master</h5> <div> <a href="policy_master_advanced.php" class="btn btn-primary btn-sm"> ➕ Add Policy </a> </div> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered table-hover"> <thead class="table-light"> <tr> <th>ID</th> <th>Policy Name</th> <th>Early Arrival</th> <th>Max OT</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach ($rows as $r): ?> <tr> <td><?= $r['id'] ?></td> <td><?= htmlspecialchars($r['policy_name']) ?></td> <td><?= $r['early_arrival_allow'] ?></td> <td><?= $r['max_ot_allow'] ?></td> <td> <!-- EDIT --> <a href="policy_master_advanced.php?edit=<?= $r['id'] ?>" class="btn btn-sm btn-info"> ✏️ </a> <!-- DELETE --> <form method="POST" style="display:inline;" onsubmit="return confirm('Delete this policy?')"> <input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>"> <input type="hidden" name="delete_id" value="<?= $r['id'] ?>"> <button class="btn btn-sm btn-danger">🗑️</button> </form> </td> </tr> <?php endforeach; ?> <?php if (empty($rows)): ?> <tr><td colspan="5" class="text-center">No policies found</td></tr> <?php endif; ?> </tbody> </table> </div> <!-- FOOT BUTTONS --> <div class="mt-3 d-flex gap-2"> <a href="policy_master_advanced.php" class="btn btn-primary"> ➕ Add </a> <a href="dashboard.php" class="btn btn-warning"> ❌ Exit </a> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>