<?php

require '../../config.php';
require '../admin_config.php';
require '../functions.php';

$connect = connect($database);

// Get all products with store and category info
$products = $connect->query("SELECT p.*, s.store_title, s.store_slug, c.category_title, c.category_slug 
                              FROM products p
                              LEFT JOIN stores s ON p.product_store = s.store_id
                              LEFT JOIN categories c ON p.product_category = c.category_id
                              ORDER BY p.product_id DESC")->fetchAll();

$results = array(
    "sEcho" => 1,
    "iTotalRecords" => count($products),
    "iTotalDisplayRecords" => count($products),
    "aaData"=>$products);
echo json_encode($results);

?>
