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

$tt_story = showAllttdata("mahamudfutureit_gallery");

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

foreach ($tt_story as $the_story) {

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

  if ($the_story['gallery_status'] == 'Published') {
    $single_story_link = $site_domain."picture/".$the_story['gallery_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['gallery_title']."</a> - ".$art_status_now ,
      "pdate" => ttdShow($the_story['gallery_date']),
      "pauthor" => getSingleValue('admin_user', 'admin_id', $the_story['gallery_admin'], 'admin_name'),
      "viewcount" =>$story_view_count,
      "paction" => '
                  <div class="text-end action-btn">
                    <a class="bg-primary" href="photo-gallery-edit.php?gallery_id='.$the_story['id'].'"><i class="bi bi-pencil"></i></a>
                    <a class="bg-danger actiion_to_delete" href="#" data-href="photo-gallery.php?delid='.$the_story['id'].'"><i class="bi bi-trash3"></i></a>
                  </div>
                  '
  ];
}
// Output the data in JSON format
echo json_encode(["data" => $data]);
