| Current Path : /home/happyrenas/fun/public/api/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/fun/public/api/products.php |
<?php
/**
* GET /api/products.php?activityId=...
* -> {ok:true, items:[...]}
*/
require_once __DIR__ . '/_bootstrap.php';
rate_limit_or_429('get', $config);
$activityId = str_limit((string)q('activityId',''), 80);
if ($activityId === '') json_error(400, "Paramètre 'activityId' requis.");
$db = $config['sheets']['db'];
$values = sheets_get_all($db['spreadsheet_id'], $db['products_sheet'], $config);
$t = table_from_values($values);
$refCol = 'ReferencePaiement (id activité)';
$filtered = [];
foreach ($t['rows'] as $r) {
$idp = (string)($r['id_produit'] ?? '');
if ($idp === '') continue;
if ((string)($r[$refCol] ?? '') === (string)$activityId) {
$filtered[] = $r;
}
}
$items = $filtered;
if (count($items) === 0) {
// fallback: tous
$items = array_values(array_filter($t['rows'], fn($r) => (string)($r['id_produit'] ?? '') !== ''));
}
json_out(['ok'=>true, 'items'=>$items, 'filtered' => (count($filtered) > 0)]);