<?php if (!defined('DASHBOARD_ROOT')) define('DASHBOARD_ROOT', realpath(__DIR__ . '/../..')); require_once DASHBOARD_ROOT . '/api/bootstrap.php'; header('Content-Type: application/json'); CSRF::enforce(); $storeId = (int)($_GET['store_id'] ?? $_POST['store_id'] ?? 0); $query = "SELECT id, title, price, image_url, status_code FROM products"; $params = []; if ($storeId > 0) { $query .= " WHERE store_id = :sid"; $params[':sid'] = $storeId; } $query .= " ORDER BY display_order ASC, id ASC LIMIT 200"; $products = Database::fetchAll($query, $params); $result = []; foreach ($products as $p) { $titleDec = 'Product #' . $p['id']; try { if ($p['title']) $titleDec = Encryption::decrypt($p['title']); } catch (\Throwable $e) {} $result[] = [ 'id' => (int)$p['id'], 'title' => $titleDec, 'price' => $p['price'], 'image_url' => $p['image_url'], 'status_code' => (int)$p['status_code'] ]; } exit(json_encode(['success' => true, 'products' => $result])); 