<?php
require_once('config.php');
header('Content-Type: application/json');

$tt_all_poll = showAllttdata("mahamudfutureit_poll", " ORDER BY  PollDatePublic  DESC ");

// Initialize an empty array
$data = [];

foreach ($tt_all_poll as $the_poll) {

  if ($the_poll['PollStatus'] == 'Published') {
    $poll_status_now = '<span class="bg-success text-white   rounded-pill  d-inline-block" style="font-size: 13px; padding: 3px 16px 0; ">Published<span>';
  }
  elseif ($the_poll['PollStatus'] == 'Draft') {
    $poll_status_now = '<span class="bg-secondary text-white   rounded-pill  d-inline-block" style="font-size: 13px; padding: 3px 16px 0; ">Draft<span>';
  }

  if ($the_poll['PollStatus'] == 'Published') {
    $poll_title = '<a target="_blank" href="'.pollLink($the_poll['PollID']).'">'.$the_poll['PollTitle'].' - '.$poll_status_now.'</a>';
  }else {
    $poll_title = $the_poll['PollTitle']." - ".$poll_status_now;
  }
  $data[] = [
      "ptitle" => $poll_title ,
      "pop1" => $the_poll['PollOptionOne']." - ".$the_poll['PollOptionOneView'],
      "pop2" =>  $the_poll['PollOptionTwo']." - ".$the_poll['PollOptionTwoView'],
      "pop3" => $the_poll['PollOptionThree']." - ".$the_poll['PollOptionThreeView'],
      "date" => ttdShow($the_poll['PollDatePublic']),
      "paction" => '
                  <div class="text-end action-btn">
                    <a class="bg-primary" href="poll-edit.php?poll_id='.$the_poll['PollID'].'"><i class="bi bi-pencil"></i></a>
                    <a class="bg-danger actiion_to_delete" href="#" data-href="poll.php?delid='.$the_poll['PollID'].'"><i class="bi bi-trash3"></i></a>
                  </div>
                  '
  ];
}
// Output the data in JSON format
echo json_encode(["data" => $data]);
