Plateforme web de commande de panier bio
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

528 lines
21 KiB

  1. <?php
  2. define('DEFAULT_TITLE', 'Mon panier bio');
  3. define('REQUEST_REGEX', '/^\/(?<supplier>[^\/]+)\/?(?<event>[^\/]+)?\/?$/');
  4. define('SUPPLIER_REGEX', '/^[A-Za-z]\w{0,31}$/');
  5. define('EVENT_REGEX', '/^\d{4}\-[01]\d\-[0123]\d$/');
  6. define('ACTION_REGEX', '/^[a-z]{1,16}$/i');
  7. $requestUrl = trim(str_replace($_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']), '?');
  8. if (preg_match(REQUEST_REGEX, $requestUrl, $match)) {
  9. $requestSupplier = array_key_exists('supplier', $match) ? $match['supplier'] : null;
  10. $requestEvent = array_key_exists('event', $match) ? $match['event'] : null;
  11. if (!is_null($requestEvent))
  12. $requestUrl = rtrim(str_replace($requestEvent, '', $requestUrl), '/');
  13. if (!is_null($requestSupplier))
  14. $requestUrl = rtrim(str_replace($requestSupplier, '', $requestUrl), '/');
  15. }
  16. function generateUrl($supplier = null, $event = null) {
  17. global $requestUrl;
  18. if (is_null($supplier))
  19. return $requestUrl;
  20. if (is_null($event))
  21. return sprintf('%s/%s', $requestUrl, $supplier);
  22. return sprintf('%s/%s/%s', $requestUrl, $supplier, $event);
  23. }
  24. define('CONFIG_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'config.php');
  25. define('DATA_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'data.php');
  26. if (file_exists(CONFIG_FILE)) require_once CONFIG_FILE;
  27. if (!isset($config)) $config = [];
  28. $action = (isset($_REQUEST['action']) and preg_match(ACTION_REGEX, $_REQUEST['action'])) ? $_REQUEST['action'] : null;
  29. $supplier = array_key_exists('supplier', $_REQUEST) ? $_REQUEST['supplier'] : $requestSupplier;
  30. $hasSupplier = is_string($supplier) and preg_match(SUPPLIER_REGEX, $supplier);
  31. if ($hasSupplier) {
  32. if (!isset($config[$supplier]))
  33. $config[$supplier] = [];
  34. $config[$supplier] = array_merge(
  35. [
  36. 'title' => '',
  37. 'subtitle' => '<small class="text-muted text-nowrap d-block d-sm-inline">%date%</small>',
  38. 'description' => '',
  39. 'choices' => [],
  40. 'start' => 'now 00:00:00',
  41. 'frequency' => '1 day',
  42. 'password' => '',
  43. 'excludes' => [],
  44. ],
  45. $config[$supplier]
  46. );
  47. $hasPassword = !empty($config[$supplier]['password']);
  48. if ($action === 'config') {
  49. if ($hasPassword) {
  50. if (!isset($_SERVER['PHP_AUTH_USER'])) {
  51. header(sprintf('WWW-Authenticate: Basic realm="Configuration de mon panier bio pour %s"', $supplier));
  52. header('HTTP/1.0 401 Unauthorized');
  53. printf('Cette configuration est protégée par mot de passe !');
  54. exit;
  55. } elseif (
  56. ($_SERVER['PHP_AUTH_USER'] !== $supplier)
  57. or ($_SERVER['PHP_AUTH_PW'] !== $config[$supplier]['password'])
  58. ) {
  59. header('HTTP/1.0 403 Forbidden');
  60. printf('Cette configuration est protégée par mot de passe !');
  61. exit;
  62. }
  63. }
  64. foreach (array_keys($config[$supplier]) as $key)
  65. if (isset($_REQUEST[$key]))
  66. $config[$supplier][$key] = (!in_array($key, ['title', 'subtitle', 'description']) ? filter_var($_REQUEST[$key], FILTER_SANITIZE_STRING) : $_REQUEST[$key]);
  67. }
  68. if (empty($config[$supplier]['start']))
  69. $config[$supplier]['start'] = 'now 00:00:00';
  70. foreach (['choices', 'excludes'] as $key) {
  71. if (is_string($config[$supplier][$key]))
  72. $config[$supplier][$key] = explode(PHP_EOL, $config[$supplier][$key]);
  73. if (!is_array($config[$supplier][$key]))
  74. $config[$supplier][$key] = [];
  75. $config[$supplier][$key] = array_filter(
  76. $config[$supplier][$key],
  77. function ($choice) {
  78. return is_string($choice) and !empty(trim($choice));
  79. }
  80. );
  81. $config[$supplier][$key] = array_map('trim', $config[$supplier][$key]);
  82. }
  83. }
  84. $isConfig = false;
  85. if ($action === 'config') {
  86. $output = fopen(CONFIG_FILE, 'w+');
  87. if ($output) {
  88. if (flock($output, LOCK_EX)) {
  89. fwrite($output, '<?php' . PHP_EOL);
  90. fprintf(
  91. $output,
  92. '$config = %s;' . PHP_EOL,
  93. var_export($config, true)
  94. );
  95. flock($output, LOCK_UN);
  96. }
  97. fclose($output);
  98. }
  99. $isConfig = true;
  100. }
  101. try {
  102. $event = array_key_exists('event', $_REQUEST) ? $_REQUEST['event'] : $requestEvent;
  103. $hasEvent = (
  104. is_string($event)
  105. and preg_match(EVENT_REGEX, $event)
  106. and ((new \DateTimeImmutable($event)) instanceof \DateTimeImmutable)
  107. );
  108. } catch (\Exception $exception) {
  109. $hasEvent = false;
  110. }
  111. if (!$isConfig and $hasSupplier) {
  112. $start = new \DateTime($config[$supplier]['start']);
  113. if (!$hasEvent) {
  114. $now = new \DateTime('now');
  115. $current = clone $start;
  116. $frequency = \DateInterval::createFromDateString($config[$supplier]['frequency']);
  117. $maxIterations = 1000;
  118. while (
  119. ($current->getTimestamp() < $now->getTimestamp())
  120. and ($maxIterations-- > 0)
  121. ) $current->add($frequency);
  122. $nextEvent = $current->format('Y-m-d');
  123. header('Location: ' . generateUrl($supplier, $nextEvent));
  124. die();
  125. } else {
  126. $current = new \DateTimeImmutable($event);
  127. $frequency = \DateInterval::createFromDateString($config[$supplier]['frequency']);
  128. $previous = $current->sub($frequency);
  129. $previousEvent = $previous->format('Y-m-d');
  130. if (false and !array_key_exists($previousEvent, $data[$supplier]))
  131. unset($previousEvent);
  132. $next = $current->add($frequency);
  133. $nextEvent = $next->format('Y-m-d');
  134. if (false and !array_key_exists($nextEvent, $data[$supplier]))
  135. unset($nextEvent);
  136. }
  137. switch ($action) {
  138. case 'insert' :
  139. case 'delete' :
  140. $isBeginning = (!file_exists(DATA_FILE) or in_array(filesize(DATA_FILE), [ false, 0 ]));
  141. $output = fopen(DATA_FILE, 'a+');
  142. if (!$output) break;
  143. if (!flock($output, LOCK_EX)) break;
  144. if ($isBeginning)
  145. fwrite($output, '<?php' . PHP_EOL);
  146. $item = [];
  147. foreach (['name', 'choice', 'action'] as $field)
  148. $item[$field] = filter_var($_REQUEST[$field], FILTER_SANITIZE_STRING);
  149. $item['timestamp'] = time();
  150. $item['hash'] = md5(implode([ $item['name'], $item['choice'], ]));
  151. fprintf(
  152. $output,
  153. '$data[%s][%s][] = %s;' . PHP_EOL,
  154. var_export($supplier, true),
  155. var_export($event, true),
  156. str_replace(PHP_EOL, '', var_export($item, true))
  157. );
  158. flock($output, LOCK_UN);
  159. fclose($output);
  160. header('Location: ' . generateUrl($supplier, $event));
  161. die();
  162. }
  163. if (!isset($data)) $data = [];
  164. if (file_exists(DATA_FILE)) include DATA_FILE;
  165. $items = [];
  166. $allItems = isset($data[$supplier][$event]) ? $data[$supplier][$event] : [];
  167. usort($allItems, function ($a, $b) {
  168. $a = intval($a['timestamp']);
  169. $b = intval($b['timestamp']);
  170. if ($a === $b)
  171. return 0;
  172. return ($a < $b) ? -1 : 1;
  173. });
  174. foreach ($allItems as $item) {
  175. if ($item['action'] === 'insert') {
  176. $items[] = $item;
  177. } elseif ($item['action'] === 'delete') {
  178. foreach ($items as $index => $prevItem)
  179. if ($prevItem['hash'] === $item['hash'])
  180. unset($items[$index]);
  181. }
  182. }
  183. $date = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format(new \DateTime($event));
  184. foreach (['title', 'subtitle', 'description'] as $key) {
  185. while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))
  186. $config[$supplier][$key] = str_replace(
  187. $match[0],
  188. ${$match[1]},
  189. $config[$supplier][$key]
  190. );
  191. }
  192. if (empty($config[$supplier]['title']))
  193. $config[$supplier]['title'] = $supplier;
  194. $stats = [];
  195. foreach ($items as $item)
  196. if (!empty($item['choice']))
  197. $stats[$item['choice']] += 1;
  198. }
  199. ?><!DOCTYPE html>
  200. <html lang="fr">
  201. <head>
  202. <meta charset="UTF-8" />
  203. <meta name="viewport" content="width=device-width, initial-scale=1" />
  204. <title><?php if ($hasSupplier) : ?><?php echo strip_tags($config[$supplier]['title']); ?><?php if (!$isConfig) : ?> — <?php echo strip_tags($config[$supplier]['subtitle']); ?><?php endif; ?><?php else : ?><?php echo DEFAULT_TITLE; ?><?php endif; ?></title>
  205. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  206. </head>
  207. <body>
  208. <header>
  209. <nav class="navbar navbar-dark bg-dark">
  210. <div class="container-fluid">
  211. <a class="navbar-brand" href="<?php echo $hasSupplier ? generateUrl($supplier) : generateUrl(); ?>">
  212. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-basket d-inline-block align-text-top" viewBox="0 0 16 16">
  213. <path d="M5.757 1.071a.5.5 0 0 1 .172.686L3.383 6h9.234L10.07 1.757a.5.5 0 1 1 .858-.514L13.783 6H15a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1v4.5a2.5 2.5 0 0 1-2.5 2.5h-9A2.5 2.5 0 0 1 1 13.5V9a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h1.217L5.07 1.243a.5.5 0 0 1 .686-.172zM2 9v4.5A1.5 1.5 0 0 0 3.5 15h9a1.5 1.5 0 0 0 1.5-1.5V9H2zM1 7v1h14V7H1zm3 3a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3A.5.5 0 0 1 4 10zm2 0a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3A.5.5 0 0 1 6 10zm2 0a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3A.5.5 0 0 1 8 10zm2 0a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3a.5.5 0 0 1 .5-.5zm2 0a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3a.5.5 0 0 1 .5-.5z"/>
  214. </svg>
  215. <?php echo $hasSupplier ? $supplier : DEFAULT_TITLE; ?>
  216. </a>
  217. <?php if ($hasSupplier) : ?>
  218. <span class="navbar-text text-muted">
  219. <?php if ($isConfig) : ?>
  220. <a class="text-reset" href="<?php echo generateUrl($supplier); ?>">Retour</a>
  221. <?php else : ?>
  222. <?php if ($hasPassword) : ?>
  223. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lock" viewBox="0 0 16 16">
  224. <path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/>
  225. </svg>
  226. <?php else : ?>
  227. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-unlock" viewBox="0 0 16 16">
  228. <path d="M11 1a2 2 0 0 0-2 2v4a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h5V3a3 3 0 0 1 6 0v4a.5.5 0 0 1-1 0V3a2 2 0 0 0-2-2zM3 8a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V9a1 1 0 0 0-1-1H3z"/>
  229. </svg>
  230. <?php endif; ?>
  231. <a tabindex="-1" class="text-reset" href="<?php printf('%s?action=config', generateUrl($supplier)); ?>">Configuration</a>
  232. <?php endif; ?>
  233. </span>
  234. <?php endif; ?>
  235. </div>
  236. </nav>
  237. </header>
  238. <main>
  239. <?php if (!$hasSupplier) : ?>
  240. <section class="container-fluid">
  241. <div class="row my-3">
  242. <div class="col">
  243. <div class="alert alert-danger" role="alert">
  244. Pas de fournisseur !
  245. </div>
  246. </div>
  247. </div>
  248. </section>
  249. <?php else : ?>
  250. <?php if ($isConfig) : ?>
  251. <section class="container-fluid">
  252. <div class="row my-3 g-3">
  253. <div class="col">
  254. <h1>Configuration</h1>
  255. </div>
  256. </div>
  257. </section>
  258. <section class="container-fluid">
  259. <div class="row g-3">
  260. <form action="<?php echo generateUrl($supplier); ?>" method="post">
  261. <div class="row mb-3">
  262. <label for="title" class="col-sm-2 col-form-label">Titre</label>
  263. <div class="col-sm-10">
  264. <input class="form-control" type="text" name="title" value="<?php echo htmlspecialchars($config[$supplier]['title']); ?>" placeholder="<?php echo $supplier; ?>" />
  265. <div class="form-text">Le titre de la page. Par défaut ce sera le nom du fournisseur </div>
  266. </div>
  267. </div>
  268. <div class="row mb-3">
  269. <label for="description" class="col-sm-2 col-form-label">Description</label>
  270. <div class="col-sm-10">
  271. <textarea class="form-control js-ckeditor" name="description" rows="10"><?php echo $config[$supplier]['description']; ?></textarea>
  272. <div class="form-text">La description affichée sous le titre.</div>
  273. </div>
  274. </div>
  275. <div class="row mb-3">
  276. <label for="choices" class="col-sm-2 col-form-label">Choix</label>
  277. <div class="col-sm-10">
  278. <textarea class="form-control" name="choices" rows="5"><?php echo implode(PHP_EOL, $config[$supplier]['choices']); ?></textarea>
  279. <div class="form-text">Les différents choix possibles. Un par ligne. Ou pas.</div>
  280. </div>
  281. </div>
  282. <div class="row mb-3">
  283. <label for="start" class="col-sm-2 col-form-label">Début</label>
  284. <div class="col-sm-10">
  285. <input class="form-control" type="date" name="start" value="<?php echo $config[$supplier]['start']; ?>" />
  286. <div class="form-text">La date du premier événement, si nécessaire de le préciser.</div>
  287. </div>
  288. </div>
  289. <div class="row mb-3">
  290. <label for="frequency" class="col-sm-2 col-form-label">Fréquence</label>
  291. <div class="col-sm-10">
  292. <input class="form-control" type="text" name="frequency" value="<?php echo $config[$supplier]['frequency']; ?>" />
  293. <div class="form-text">La fréquence des événements dans le format <a class="text-reset" href="https://www.php.net/manual/fr/datetime.formats.relative.php" target="_blank">décrit sur cette page</a>.</div>
  294. </div>
  295. </div>
  296. <div class="row mb-3">
  297. <label for="excludes" class="col-sm-2 col-form-label">Exceptions</label>
  298. <div class="col-sm-10">
  299. <textarea class="form-control" name="excludes" rows="5"><?php echo implode(PHP_EOL, $config[$supplier]['excludes']); ?></textarea>
  300. <div class="form-text">Les dates à exclure. Une par ligne. Ou pas.</div>
  301. </div>
  302. </div>
  303. <div class="row mb-3">
  304. <label for="password" class="col-sm-2 col-form-label">Mot de passe</label>
  305. <div class="col-sm-10">
  306. <input class="form-control" type="text" name="password" value="<?php echo $config[$supplier]['password']; ?>" />
  307. <div class="form-text">Ce mot de passe sera demandé pour accéder à la configuration la prochaine fois. Le nom d'utilisateur est le fournisseur courant (en l'occurrence <kbd><?php echo $supplier; ?></kbd>).</div>
  308. </div>
  309. </div>
  310. <div class="row">
  311. <div class="col mb-3">
  312. <button class="btn btn-primary" type="submit" name="action" value="config">Enregistrer</button>
  313. </div>
  314. </div>
  315. </form>
  316. </div>
  317. </section>
  318. <?php else : ?>
  319. <section class="container-fluid">
  320. <div class="row my-3">
  321. <div class="col">
  322. <h1>
  323. <div class="btn-group float-end" role="group">
  324. <?php if (isset($previousEvent)) : ?>
  325. <a class="btn btn-outline-primary" href="<?php echo generateUrl($supplier, $previousEvent); ?>" title="Événement précédent">
  326. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
  327. <path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8z"/>
  328. </svg>
  329. </a>
  330. <?php endif; ?>
  331. <a class="btn btn-outline-primary" href="<?php echo generateUrl($supplier, $event); ?>" title="Cet événement">
  332. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link" viewBox="0 0 16 16">
  333. <path d="M6.354 5.5H4a3 3 0 0 0 0 6h3a3 3 0 0 0 2.83-4H9c-.086 0-.17.01-.25.031A2 2 0 0 1 7 10.5H4a2 2 0 1 1 0-4h1.535c.218-.376.495-.714.82-1z"/>
  334. <path d="M9 5.5a3 3 0 0 0-2.83 4h1.098A2 2 0 0 1 9 6.5h3a2 2 0 1 1 0 4h-1.535a4.02 4.02 0 0 1-.82 1H12a3 3 0 1 0 0-6H9z"/>
  335. </svg>
  336. </a>
  337. <?php if (isset($nextEvent)) : ?>
  338. <a class="btn btn-outline-primary" href="<?php echo generateUrl($supplier, $nextEvent); ?>" title="Événement suivant">
  339. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-right" viewBox="0 0 16 16">
  340. <path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/>
  341. </svg>
  342. </a>
  343. <?php endif; ?>
  344. </div>
  345. <?php echo $config[$supplier]['title']; ?>
  346. <?php echo $config[$supplier]['subtitle']; ?>
  347. </h1>
  348. <?php if (!empty($config[$supplier]['description'])) : ?>
  349. <p class="lead"><?php echo $config[$supplier]['description']; ?></p>
  350. <?php endif; ?>
  351. </div>
  352. </div>
  353. </section>
  354. <section class="container-fluid">
  355. <div class="row g-3">
  356. <form class="js-localremember bg-dark text-light" action="<?php echo generateUrl($supplier); ?>" method="post">
  357. <div class="row my-3">
  358. <label for="title" class="col-sm-2 col-form-label">Nom</label>
  359. <div class="col-sm-10">
  360. <input class="form-control" type="text" name="name" required placeholder="Nom" />
  361. </div>
  362. </div>
  363. <?php if (!empty($config[$supplier]['choices'])) : ?>
  364. <div class="row mb-3">
  365. <label for="title" class="col-sm-2 col-form-label">Choix</label>
  366. <div class="col-sm-10">
  367. <div class="btn-group" role="group">
  368. <?php foreach ($config[$supplier]['choices'] as $index => $choice) : ?>
  369. <input type="radio" class="btn-check" id="<?php printf('option%d', $index); ?>" autocomplete="off" name="choice" value="<?php echo $choice; ?>" />
  370. <label class="btn btn-outline-light" for="<?php printf('option%d', $index); ?>"><?php echo $choice; ?></label>
  371. <?php endforeach; ?>
  372. </div>
  373. </div>
  374. </div>
  375. <?php endif; ?>
  376. <div class="row">
  377. <div class="col mb-3">
  378. <input type="hidden" name="supplier" value="<?php echo $supplier; ?>" />
  379. <input type="hidden" name="event" value="<?php echo $event; ?>" />
  380. <?php if (empty($config[$supplier]['choices'])) : ?>
  381. <input type="hidden" name="choice" value="" />
  382. <?php endif; ?>
  383. <button class="btn btn-primary" type="submit" name="action" value="insert">Commander</button>
  384. </div>
  385. </div>
  386. </form>
  387. </div>
  388. </section>
  389. <section class="container-fluid">
  390. <div class="row my-3">
  391. <?php if (!empty($items)) : ?>
  392. <div class="col-12">
  393. <div class="table-responsive">
  394. <table class="table table-striped table-hover align-middle">
  395. <thead>
  396. <tr>
  397. <th scope="col">
  398. Nom
  399. </th>
  400. <?php if (!empty($config[$supplier]['choices'])) : ?>
  401. <th scope="col">
  402. Choix
  403. </th>
  404. <?php endif; ?>
  405. <th scope="col">
  406. &nbsp;
  407. </th>
  408. </tr>
  409. </thead>
  410. <tbody>
  411. <?php foreach ($items as $item) : ?>
  412. <tr>
  413. <td>
  414. <?php echo $item['name']; ?>
  415. </td>
  416. <?php if (!empty($config[$supplier]['choices'])) : ?>
  417. <td>
  418. <?php if (!empty($item['choice'])) : ?>
  419. <?php echo $item['choice']; ?>
  420. <?php endif; ?>
  421. </td>
  422. <?php endif; ?>
  423. <td>
  424. <form onsubmit="return confirm('Souhaitez-vous vraiment annuler cette commande ?');">
  425. <input type="hidden" name="supplier" value="<?php echo $supplier; ?>" />
  426. <input type="hidden" name="event" value="<?php echo $event; ?>" />
  427. <input type="hidden" name="name" value="<?php echo $item['name']; ?>" />
  428. <input type="hidden" name="choice" value="<?php echo $item['choice']; ?>" />
  429. <button class="btn btn-secondary float-end" type="submit" name="action" value="delete">Annuler</button>
  430. </form>
  431. </td>
  432. </tr>
  433. <?php endforeach; ?>
  434. </tbody>
  435. </table>
  436. </div>
  437. </div>
  438. <?php endif; ?>
  439. <div class="col-12">
  440. <ul class="list-group">
  441. <li class="list-group-item d-flex justify-content-between align-items-center">
  442. Commandes
  443. <span class="badge bg-primary rounded-pill"><?php echo count($items); ?></span>
  444. </li>
  445. <?php foreach ($stats as $choice => $count) : ?>
  446. <li class="list-group-item d-flex justify-content-between align-items-center">
  447. <?php echo $choice; ?>
  448. <span class="badge bg-secondary rounded-pill"><?php echo $count; ?></span>
  449. </li>
  450. <?php endforeach; ?>
  451. </ul>
  452. </div>
  453. </div>
  454. </section>
  455. <?php endif; ?>
  456. <?php endif; ?>
  457. </main>
  458. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  459. <?php if ($isConfig) : ?>
  460. <script src="https://cdn.ckeditor.com/ckeditor5/31.0.0/classic/ckeditor.js"></script>
  461. <script>
  462. document.querySelectorAll('.js-ckeditor').forEach(function (element) {
  463. ClassicEditor.create(element).catch(error => { console.error(error); });
  464. });
  465. </script>
  466. <?php endif; ?>
  467. <script>
  468. document.querySelectorAll('.js-localremember').forEach(function (form) {
  469. const fields = [ 'name', 'choice' ];
  470. form.addEventListener('submit', function (event) {
  471. fields.forEach(function (field) {
  472. window.localStorage.setItem('mon_panier_bio_' + field, form.elements[field].value);
  473. });
  474. });
  475. fields.forEach(function (field) {
  476. if (
  477. (form.elements[field].value === '')
  478. && (window.localStorage.getItem('mon_panier_bio_' + field) !== null)
  479. ) {
  480. form.elements[field].value = window.localStorage.getItem('mon_panier_bio_' + field);
  481. }
  482. });
  483. });
  484. </script>
  485. </body>
  486. </html>