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

$tt_story = showAllttdata("mahamudfutureit_photostories");

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

foreach ($tt_story as $the_story) {

  if ($the_story['story_view'] !='') {
    $story_view_count = $the_story['story_view'];
  }else {
    $story_view_count = 0;
  }

  if ($the_story['story_status'] == 'Published') {
    $single_story_link = $site_domain."photo-stories/".$the_story['story_url']."/'  target='_blank'";
    $art_status_now = '<span class="bg-success text-white   rounded-pill  d-inline-block" style="font-size: 13px; padding: 3px 16px 0; ">Published<span>';
  }
  else{
    $single_story_link = "#'";
    $art_status_now = '<span class="bg-secondary text-white   rounded-pill  d-inline-block" style="font-size: 13px; padding: 3px 16px 0; ">Draft<span>';
  }
?>

<?php
  $data[] = [
      "ptitle" => "<a href='".$single_story_link." class='text-dark'>".$the_story['story_title']."</a> - ".$art_status_now ,
      "pdate" => ttdShow($the_story['story_date']),
      "pauthor" => getSingleValue('admin_user', 'admin_id', $the_story['story_admin'], 'admin_name'),
      "viewcount" =>$story_view_count,
      "paction" => '
                  <div class="text-end action-btn">
                    <a class="bg-primary" href="photo-stories-edit.php?story_id='.$the_story['id'].'"><i class="bi bi-pencil"></i></a>
                    <a class="bg-danger actiion_to_delete" href="#" data-href="photo-stories.php?delid='.$the_story['id'].'"><i class="bi bi-trash3"></i></a>
                  </div>
                  '
  ];
}
// Output the data in JSON format
echo json_encode(["data" => $data]);
