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.

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