<?php
$pdo = new PDO('mysql:host=localhost;dbname=mjposliv_mjpos_db_kussiya;charset=utf8mb4',
    'mjposliv_kussiya', 'Ishara@1994Bubu',
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id  = (int)$_POST['emp_id'];
    $val = $_POST['epf_val'] === '1' ? 1 : 0;
    $pdo->prepare("UPDATE employees SET epf_eligible=? WHERE id=?")->execute([$val, $id]);
    echo "<p style='color:green;font-size:1.2rem'>✅ Employee #$id epf_eligible = $val saved!</p>";
}

$emps = $pdo->query("SELECT id, full_name, epf_eligible FROM employees ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>EPF Debug</title>
<style>
body{font-family:Arial;padding:20px;max-width:700px;margin:0 auto}
table{width:100%;border-collapse:collapse}
td,th{padding:10px;border:1px solid #ddd;text-align:left}
th{background:#f1f5f9;font-weight:700}
.on{color:#16a34a;font-weight:800}
.off{color:#dc2626;font-weight:800}
button{padding:6px 14px;border-radius:6px;border:none;cursor:pointer;font-weight:700}
.btn-off{background:#fee2e2;color:#dc2626}
.btn-on{background:#dcfce7;color:#16a34a}
</style></head><body>
<h2>EPF Eligible — Direct DB Fix</h2>
<table>
<tr><th>ID</th><th>Name</th><th>DB Value</th><th>Set OFF</th><th>Set ON</th></tr>
<?php foreach ($emps as $e): ?>
<tr>
  <td><?= $e['id'] ?></td>
  <td><?= htmlspecialchars($e['full_name']) ?></td>
  <td class="<?= $e['epf_eligible'] ? 'on' : 'off' ?>">
    <?= $e['epf_eligible'] ? '1 — ON' : '0 — OFF' ?>
  </td>
  <td>
    <form method="POST">
      <input type="hidden" name="emp_id" value="<?= $e['id'] ?>">
      <input type="hidden" name="epf_val" value="0">
      <button class="btn-off" type="submit">Set OFF</button>
    </form>
  </td>
  <td>
    <form method="POST">
      <input type="hidden" name="emp_id" value="<?= $e['id'] ?>">
      <input type="hidden" name="epf_val" value="1">
      <button class="btn-on" type="submit">Set ON</button>
    </form>
  </td>
</tr>
<?php endforeach; ?>
</table>
<p style="color:#d97706;margin-top:20px">⚠ Delete this file after use!</p>
</body></html>