<?php
require 'db.php';
require 'functions.php';
requireRole(['rnduser']);

$pagetitle = 'Registrations';
$activemenu = 'registrations';
require 'header.php';
?>

<div class="dfp-card">
  <h3>Completed Registrations (Approved &amp; Paid)</h3>
  <table id="tblRegistrations" class="dfp-table" style="width:100%;">
    <thead>
      <tr><th>Name</th><th>Phone</th><th>Panchayat</th><th>Valid Until</th><th>Pass Active</th><th>Printed</th><th>Action</th></tr>
      <tr class="filterrow">
        <th><input class="dfp-colfilter"></th>
        <th><input class="dfp-colfilter"></th>
        <th><input class="dfp-colfilter"></th>
        <th></th><th></th>
        <th>
          <select class="dfp-colfilter">
            <option value="">All</option>
            <option value="Yes">Printed</option>
            <option value="No">Not Printed</option>
          </select>
        </th>
        <th></th>
      </tr>
    </thead>
    <tbody></tbody>
  </table>
</div>

<?php require 'footer.php'; ?>
<script>
$(function () {
  var tbl = $('#tblRegistrations').DataTable({
    order: [[3, 'asc']],
    ajax: { url: 'ajax_rnd_registration.php', data: { action: 'list' }, dataSrc: 'data' },
    columns: [
      { data: 'fullname' },
      { data: 'phone' },
      { data: 'panchayatname' },
      { data: 'passenddate' },
      { data: 'passactive', render: function (d) { return d == 1 ? '<span class="badge badge-approved">Active</span>' : '<span class="badge badge-inactive">Inactive</span>'; } },
      { data: 'isprinted', render: function (d) { return d == 1 ? 'Yes' : 'No'; } },
      { data: null, orderable: false, render: function (d) {
          return '<a class="btn btn-sm btn-outline" href="rnd_registrationview.php?id=' + d.id + '">View</a>';
        } }
    ]
  });
  dfpEnableColumnFilters('#tblRegistrations');
});
</script>
<?php require 'footer2.php'; ?>
