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.

923 lines
41 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. define('DEFAULT_TITLE', 'Mon panier bio');
  3. define('SUPPLIER_REGEX', '[A-Za-z]\w{0,31}(-\w+)?');
  4. define('EVENT_REGEX', '\d{4}\-[01]\d\-[0123]\d');
  5. define('EVENT_FORMAT', 'Y-m-d');
  6. define('REQUEST_REGEX', '/^https?:\/\/.+\/(?<supplier>' . SUPPLIER_REGEX . ')\/?(?<event>' . EVENT_REGEX . ')?\/?$/');
  7. define('ACTION_REGEX', '/^[a-z]{1,16}$/i');
  8. $baseUrl = trim((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '/');
  9. if (($pos = strpos($baseUrl, '?')) !== false)
  10. $baseUrl = substr($baseUrl, 0, $pos);
  11. $requestUrl = trim(array_key_exists('QUERY_STRING', $_SERVER) ? str_replace($_SERVER['QUERY_STRING'], '', $baseUrl) : $baseUrl, '?');
  12. if (preg_match(REQUEST_REGEX, $requestUrl, $match)) {
  13. $requestSupplier = array_key_exists('supplier', $match) ? $match['supplier'] : null;
  14. $requestEvent = array_key_exists('event', $match) ? $match['event'] : null;
  15. if (!is_null($requestEvent))
  16. $requestUrl = rtrim(str_replace($requestEvent, '', $requestUrl), '/');
  17. if (!is_null($requestSupplier))
  18. $requestUrl = rtrim(str_replace($requestSupplier, '', $requestUrl), '/');
  19. } else {
  20. $requestSupplier = null;
  21. $requestEvent = null;
  22. }
  23. function isInPast($event) {
  24. $now = new \DateTimeImmutable('now');
  25. $then = new \DateTimeImmutable($event);
  26. return $then->getTimestamp() < $now->getTimestamp();
  27. }
  28. function ago($value) {
  29. $now = new \DateTimeImmutable('now 00:00:00');
  30. $value = (clone $value)->setTime(0, 0, 0);
  31. $diff = $now->diff($value, false);
  32. if (abs($diff->y) > 0) $output = sprintf('%d an%s', $diff->y, $diff->y > 1 ? 's' : '');
  33. elseif (abs($diff->m) > 0) $output = sprintf('%d mois', $diff->m);
  34. elseif (abs($diff->d) > 1) $output = sprintf('%d jours', $diff->d);
  35. if (isset($output)) $output = sprintf('%s %s', ($diff->invert === 1 ? 'il y a' : 'dans'), $output);
  36. elseif (abs($diff->d) > 0) $output = $diff->invert ? 'hier' : 'demain';
  37. else $output = 'aujourd\'hui';
  38. return $output;
  39. }
  40. function generatePassword($length = 20) {
  41. $chars = array_merge(
  42. range('A', 'Z'),
  43. range('a', 'z'),
  44. range('0', '9'),
  45. [ '!', '?', '~', '@', '#', '$', '%', '*', ';', ':', '-', '+', '=', ',', '.', '_' ]
  46. );
  47. $value ='';
  48. while ($length-- > 0)
  49. $value .= $chars[mt_rand(0, count($chars) - 1)];
  50. return $value;
  51. }
  52. function generateUrl($supplier = null, $event = null, $iframe = null) {
  53. global $requestUrl, $inIframe;
  54. $queryString = ($inIframe or !is_null($iframe)) ? '?iframe' : '';
  55. if (is_null($supplier))
  56. return $requestUrl . $queryString;
  57. if (is_null($event))
  58. return sprintf('%s/%s', $requestUrl, $supplier) . $queryString;
  59. return sprintf('%s/%s/%s', $requestUrl, $supplier, $event) . $queryString;
  60. }
  61. function findNext($start, $frequency, $excludes = [], $vsNow = true, $maxIterations = 1000, $direction = +1) {
  62. $now = new \DateTime('now');
  63. $current = clone $start;
  64. $frequency = \DateInterval::createFromDateString($frequency);
  65. do {
  66. if ($direction === abs($direction)) {
  67. if (!$vsNow and ($maxIterations-- > 0)) {
  68. $current->add($frequency);
  69. } else {
  70. while (
  71. ($current->getTimestamp() < $now->getTimestamp())
  72. and ($maxIterations-- > 0)
  73. ) $current->add($frequency);
  74. }
  75. } else {
  76. if (!$vsNow and ($maxIterations-- > 0)) {
  77. $current->sub($frequency);
  78. } else {
  79. while (
  80. ($current->getTimestamp() > $now->getTimestamp())
  81. and ($maxIterations-- > 0)
  82. ) $current->sub($frequency);
  83. }
  84. }
  85. $nextEvent = $current->format('Y-m-d');
  86. } while (
  87. in_array($nextEvent, $excludes)
  88. and ($maxIterations > 0)
  89. );
  90. return $current;
  91. }
  92. function findPrevious($start, $frequency, $excludes = [], $vsNow = true, $maxIterations = 1000) {
  93. return findNext($start, $frequency, $excludes, $vsNow, $maxIterations, -1);
  94. }
  95. define('CONFIG_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'config.php');
  96. define('DATA_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'data.php');
  97. if (file_exists(CONFIG_FILE)) require_once CONFIG_FILE;
  98. if (!isset($config)) $config = [];
  99. $availableLocations = [];
  100. foreach (array_keys($config) as $supplier) {
  101. $hasLocation = (($pos = strpos($supplier, '-')) !== false);
  102. if (!$hasLocation)
  103. continue;
  104. $locationKey = substr($supplier, ($pos + 1));
  105. $shortSupplier = substr($supplier, 0, $pos);
  106. $locationValue = empty($config[$supplier]['location']) ? $locationKey : $config[$supplier]['location'];
  107. $availableLocations[$shortSupplier][$locationKey] = $locationValue;
  108. }
  109. $inIframe = isset($_REQUEST['iframe']);
  110. $action = (isset($_REQUEST['action']) and preg_match(ACTION_REGEX, $_REQUEST['action'])) ? $_REQUEST['action'] : null;
  111. $supplier = array_key_exists('supplier', $_REQUEST) ? $_REQUEST['supplier'] : $requestSupplier;
  112. $hasLocation = (($pos = strpos($supplier, '-')) !== false);
  113. if ($hasLocation) {
  114. $location = substr($supplier, ($pos + 1));
  115. }
  116. $hasSupplier = is_string($supplier) and preg_match('/^' . SUPPLIER_REGEX . '$/', $supplier);
  117. $excludesFormatter = new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, 'Europe/Paris');
  118. if (
  119. $hasSupplier
  120. and !isset($config[$supplier])
  121. and !$hasLocation
  122. and is_array($availableLocations[$supplier])
  123. and !empty($availableLocations[$supplier])
  124. ) {
  125. $supplierNeedLocation = true;
  126. } else {
  127. $supplierNeedLocation = false;
  128. $supplierIsNew = false;
  129. if ($hasSupplier) {
  130. if (!isset($config[$supplier])) {
  131. $config[$supplier] = [];
  132. $supplierIsNew = true;
  133. }
  134. $config[$supplier] = array_merge(
  135. [
  136. 'title' => '',
  137. 'subtitle' => '<small class="%color% text-nowrap d-block d-sm-inline">%date% (%ago%)</small>',
  138. 'location' => '',
  139. 'description' => '',
  140. 'choices' => [],
  141. 'start' => 'now 00:00:00',
  142. 'end' => '+1 year 23:59:59',
  143. 'frequency' => '1 day',
  144. 'password' => '',
  145. 'excludes' => [],
  146. ],
  147. $config[$supplier]
  148. );
  149. $hasPassword = !empty($config[$supplier]['password']);
  150. if ($action === 'config') {
  151. if ($hasPassword) {
  152. if (!isset($_SERVER['PHP_AUTH_USER'])) {
  153. header(sprintf('WWW-Authenticate: Basic realm="Configuration de mon panier bio pour %s"', $supplier));
  154. header('HTTP/1.0 401 Unauthorized');
  155. printf('Cette configuration est protégée par mot de passe !');
  156. exit;
  157. } elseif (
  158. ($_SERVER['PHP_AUTH_USER'] !== $supplier)
  159. or ($_SERVER['PHP_AUTH_PW'] !== $config[$supplier]['password'])
  160. ) {
  161. header('HTTP/1.0 403 Forbidden');
  162. printf('Cette configuration est protégée par mot de passe !');
  163. exit;
  164. }
  165. }
  166. foreach (array_keys($config[$supplier]) as $key)
  167. if (isset($_REQUEST[$key]))
  168. $config[$supplier][$key] = (!in_array($key, ['title', 'subtitle', 'description']) ? filter_var($_REQUEST[$key], FILTER_SANITIZE_STRING) : $_REQUEST[$key]);
  169. }
  170. if (empty($config[$supplier]['start']))
  171. $config[$supplier]['start'] = 'now 00:00:00';
  172. foreach (['choices', 'excludes'] as $key) {
  173. if (is_string($config[$supplier][$key]))
  174. $config[$supplier][$key] = explode(PHP_EOL, $config[$supplier][$key]);
  175. if (!is_array($config[$supplier][$key]))
  176. $config[$supplier][$key] = [];
  177. $config[$supplier][$key] = array_filter(
  178. $config[$supplier][$key],
  179. function ($choice) {
  180. return is_string($choice) and !empty(trim($choice));
  181. }
  182. );
  183. $config[$supplier][$key] = array_map('trim', $config[$supplier][$key]);
  184. }
  185. $config[$supplier]['excludes'] = array_filter(
  186. array_map(
  187. function ($value) use ($excludesFormatter) {
  188. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value))
  189. return $value;
  190. $timestamp = $excludesFormatter->parse($value, $offset);
  191. if ($timestamp !== false)
  192. return (new \DateTimeImmutable('@' . $timestamp, new \DateTimeZone('Europe/Paris')))->format('Y-m-d');
  193. try {
  194. return (new \DateTimeImmutable($value, new \DateTimeZone('Europe/Paris')))->format('Y-m-d');
  195. } catch (\Exception $exception) {
  196. return null;
  197. }
  198. },
  199. $config[$supplier]['excludes']
  200. ),
  201. function ($value) {
  202. return !is_null($value);
  203. }
  204. );
  205. }
  206. $isConfig = false;
  207. if ($action === 'config') {
  208. $output = fopen(CONFIG_FILE, 'w+');
  209. if ($output) {
  210. if (flock($output, LOCK_EX)) {
  211. fwrite($output, '<?php' . PHP_EOL);
  212. fprintf(
  213. $output,
  214. '$config = %s;' . PHP_EOL,
  215. var_export($config, true)
  216. );
  217. flock($output, LOCK_UN);
  218. }
  219. fclose($output);
  220. }
  221. $isConfig = true;
  222. }
  223. $suppliers = array_keys($config);
  224. sort($suppliers);
  225. try {
  226. $event = array_key_exists('event', $_REQUEST) ? $_REQUEST['event'] : $requestEvent;
  227. $hasEvent = (
  228. is_string($event)
  229. and preg_match('/^' . EVENT_REGEX . '$/', $event)
  230. and ((new \DateTimeImmutable($event)) instanceof \DateTimeImmutable)
  231. );
  232. } catch (\Exception $exception) {
  233. $hasEvent = false;
  234. }
  235. if (!$isConfig and !$supplierIsNew and $hasSupplier) {
  236. $start = new \DateTime($config[$supplier]['start']);
  237. if (!$hasEvent) {
  238. $next = findNext($start, $config[$supplier]['frequency'], $config[$supplier]['excludes'], true);
  239. $nextEvent = $next->format('Y-m-d');
  240. header('Location: ' . generateUrl($supplier, $nextEvent));
  241. die();
  242. } else {
  243. $current = new \DateTime($event);
  244. $previous = findPrevious($current, $config[$supplier]['frequency'], $config[$supplier]['excludes'], false);
  245. $previousEvent = $previous->format('Y-m-d');
  246. if (false and !array_key_exists($previousEvent, $data[$supplier]))
  247. unset($previousEvent);
  248. $first = new \DateTime($config[$supplier]['start']);
  249. if (true and ($previous->getTimestamp() < $first->getTimestamp()))
  250. unset($previousEvent);
  251. $next = findNext($current, $config[$supplier]['frequency'], $config[$supplier]['excludes'], false);
  252. $nextEvent = $next->format('Y-m-d');
  253. if (false and !array_key_exists($nextEvent, $data[$supplier]))
  254. unset($nextEvent);
  255. $last = new \DateTime($config[$supplier]['end']);
  256. if (true and ($next->getTimestamp() > $last->getTimestamp()))
  257. unset($nextEvent);
  258. }
  259. switch ($action) {
  260. case 'insert' :
  261. case 'delete' :
  262. $item = [];
  263. foreach (['name', 'choice', 'action'] as $field)
  264. $item[$field] = filter_var($_REQUEST[$field], FILTER_SANITIZE_STRING);
  265. $item['timestamp'] = time();
  266. $hash = md5(implode([ trim($item['name']), $item['choice'], ]));
  267. $item['hash'] = $hash;
  268. $isBeginning = (!file_exists(DATA_FILE) or in_array(filesize(DATA_FILE), [ false, 0 ]));
  269. $output = fopen(DATA_FILE, 'a+');
  270. if (!$output) break;
  271. if (!flock($output, LOCK_EX)) break;
  272. if ($isBeginning)
  273. fwrite($output, '<?php' . PHP_EOL);
  274. fprintf(
  275. $output,
  276. '$data[%s][%s][] = %s;' . PHP_EOL,
  277. var_export($supplier, true),
  278. var_export($event, true),
  279. str_replace(PHP_EOL, '', var_export($item, true))
  280. );
  281. flock($output, LOCK_UN);
  282. fclose($output);
  283. header('Location: ' . generateUrl($supplier, $event));
  284. die();
  285. }
  286. if (!isset($data)) $data = [];
  287. if (file_exists(DATA_FILE)) include DATA_FILE;
  288. $items = [];
  289. $allItems = isset($data[$supplier][$event]) ? $data[$supplier][$event] : [];
  290. usort($allItems, function ($a, $b) {
  291. $a = intval($a['timestamp']);
  292. $b = intval($b['timestamp']);
  293. if ($a === $b)
  294. return 0;
  295. return ($a < $b) ? -1 : 1;
  296. });
  297. foreach ($allItems as $item) {
  298. if ($item['action'] === 'insert') {
  299. $alreadyInserted = false;
  300. foreach ($items as $index => $prevItem)
  301. if ($prevItem['hash'] === $item['hash'])
  302. $alreadyInserted = true;
  303. if (!$alreadyInserted)
  304. $items[] = $item;
  305. } elseif ($item['action'] === 'delete') {
  306. foreach ($items as $index => $prevItem)
  307. if ($prevItem['hash'] === $item['hash'])
  308. unset($items[$index]);
  309. }
  310. }
  311. $date = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format(new \DateTime($event));
  312. $ago = ago(new \DateTimeImmutable($event));
  313. $color = isInPast($event) ? 'text-danger' : 'text-muted';
  314. $currentEvent = findNext(new \DateTime($config[$supplier]['start']), $config[$supplier]['frequency'], $config[$supplier]['excludes'], true);
  315. $currentDate = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format($currentEvent);
  316. $currentAgo = ago($currentEvent);
  317. foreach (['title', 'subtitle', 'description'] as $key) {
  318. while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))
  319. $config[$supplier][$key] = str_replace(
  320. $match[0],
  321. ${$match[1]},
  322. $config[$supplier][$key]
  323. );
  324. }
  325. if (empty($config[$supplier]['title']))
  326. $config[$supplier]['title'] = $supplier;
  327. $stats = [];
  328. foreach ($items as $item)
  329. if (!empty($item['choice']))
  330. $stats[$item['choice']] += 1;
  331. }
  332. if ($supplierIsNew and !empty($suppliers)) {
  333. $closestSuppliers = array_filter(
  334. array_map(
  335. function ($other) use ($supplier) {
  336. return [
  337. 'supplier' => $other,
  338. 'score' => levenshtein($supplier, $other),
  339. ];
  340. },
  341. $suppliers
  342. ),
  343. function ($item) {
  344. return $item['score'] > 0;
  345. }
  346. );
  347. usort($closestSuppliers, function ($a, $b) {
  348. if ($a['score'] == $b['score']) {
  349. return 0;
  350. }
  351. return ($a['score'] < $b['score']) ? -1 : 1;
  352. });
  353. }
  354. }
  355. $linkUrl = !$hasSupplier ? generateUrl() : (!$hasEvent ? generateUrl($supplier) : generateUrl($supplier, $event));
  356. ?><!DOCTYPE html>
  357. <html lang="fr">
  358. <head>
  359. <meta charset="UTF-8" />
  360. <meta name="viewport" content="width=device-width, initial-scale=1" />
  361. <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>
  362. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  363. <style type="text/css">.is-fixed { position: fixed; bottom: 0; width: 100%; box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.5); }</style>
  364. <style type="text/css">.sortable th.dir-d::after{color:inherit;content:' \025BE'}.sortable th.dir-u::after{color:inherit;content:' \025B4'}</style>
  365. </head>
  366. <body>
  367. <?php if (!$inIframe) : ?>
  368. <header>
  369. <nav class="navbar navbar-dark bg-dark">
  370. <div class="container-fluid">
  371. <a class="navbar-brand" href="<?php echo $hasSupplier ? generateUrl($supplier) : generateUrl(); ?>">
  372. <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">
  373. <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"/>
  374. </svg>
  375. <?php echo $hasSupplier ? $supplier : DEFAULT_TITLE; ?>
  376. </a>
  377. <span class="navbar-text text-muted">
  378. <a class="text-reset me-3" data-bs-toggle="modal" href="#linkModal">Lien</a>
  379. <?php if ($hasSupplier) : ?>
  380. <?php if ($isConfig) : ?>
  381. <a class="text-reset" href="<?php echo generateUrl($supplier); ?>">Retour</a>
  382. <?php else : ?>
  383. <a tabindex="-1" class="text-reset" href="<?php printf('%s?action=config', generateUrl($supplier)); ?>">
  384. <?php if ($hasPassword) : ?>
  385. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lock" viewBox="0 0 16 16">
  386. <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"/>
  387. </svg>
  388. <?php else : ?>
  389. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-unlock" viewBox="0 0 16 16">
  390. <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"/>
  391. </svg>
  392. <?php endif; ?>
  393. Configuration
  394. </a>
  395. <?php endif; ?>
  396. <?php endif; ?>
  397. </span>
  398. </div>
  399. </nav>
  400. </header>
  401. <?php endif; // !$inIframe ?>
  402. <main>
  403. <?php if ($supplierNeedLocation) : ?>
  404. <section class="container-fluid pt-3">
  405. <div class="alert alert-info alert-dismissible mb-3" role="alert">
  406. Il existe plusieurs possibilités pour commander, merci d'en choisir une parmi celles proposées ci-dessous.
  407. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
  408. </div>
  409. <div class="d-grid gap-2 col-xs-12 col-sm-6 mx-auto">
  410. <?php foreach ($availableLocations[$supplier] as $locationKey => $locationValue) : ?>
  411. <a class="btn btn-primary" href="<?php echo generateUrl($supplier . '-' . $locationKey); ?>"><?php echo $locationValue; ?></a>
  412. <?php endforeach; ?>
  413. </div>
  414. </section>
  415. <?php elseif (!$hasSupplier) : ?>
  416. <section class="container-fluid pt-3">
  417. <div class="alert alert-danger alert-dismissible mb-3" role="alert">
  418. Pas de fournisseur !
  419. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
  420. </div>
  421. <div class="row mb-3 g-3">
  422. <div class="col-12">
  423. <form action="<?php echo generateUrl(); ?>" method="post">
  424. <?php if ($inIframe) : ?><input type="hidden" name="iframe" /><?php endif; // $inIframe ?>
  425. <datalist id="supplierList">
  426. <?php foreach ($suppliers as $supplier) : ?>
  427. <option value="<?php echo $supplier; ?>" />
  428. <?php endforeach; ?>
  429. </datalist>
  430. <div class="input-group input-group-lg">
  431. <span class="input-group-text">
  432. <span class="d-none d-sm-inline"><?php echo generateUrl(); ?></span>
  433. <span class="d-inline d-sm-none" title="<?php echo generateUrl(); ?>">&hellip;</span>
  434. /
  435. </span>
  436. <input type="text" class="form-control js-closealerts" name="supplier" list="supplierList" required placeholder="MonFournisseur" tabindex="1" autofocus />
  437. <button class="btn btn-primary" type="submit">Aller&nbsp;&rarr;</button>
  438. </div>
  439. </form>
  440. </div>
  441. <div class="col-12">
  442. <details>
  443. <summary>En savoir plus…</summary>
  444. <p>La documentation se trouvera ici quand elle sera prête.</p>
  445. <p>En attendant, ce logiciel est <a href="https://fr.wikipedia.org/wiki/WTFPL" target="_blank">libre</a> et ses sources sont disponibles <a href="https://caboulot.org/gitea/vince/mon-panier-bio" target="_blank">ici</a>.</p>
  446. <p><i>utere felix</i></p>
  447. </details>
  448. </div>
  449. </div>
  450. </section>
  451. <?php else : /* $hasSupplier */ ?>
  452. <?php if ($isConfig) : ?>
  453. <section class="container-fluid">
  454. <div class="row my-3 g-3">
  455. <div class="col">
  456. <h1>Configuration</h1>
  457. </div>
  458. </div>
  459. </section>
  460. <section class="container-fluid">
  461. <div class="row g-3">
  462. <form action="<?php echo generateUrl($supplier); ?>" method="post">
  463. <?php if ($inIframe) : ?><input type="hidden" name="iframe" /><?php endif; // $inIframe ?>
  464. <div class="row mb-3">
  465. <label for="title" class="col-sm-2 col-form-label">Titre</label>
  466. <div class="col-sm-10">
  467. <input class="form-control" type="text" name="title" value="<?php echo htmlspecialchars($config[$supplier]['title']); ?>" placeholder="<?php echo $supplier; ?>" />
  468. <div class="form-text">Le titre de la page. Par défaut ce sera le nom du fournisseur </div>
  469. </div>
  470. </div>
  471. <div class="row mb-3">
  472. <label for="location" class="col-sm-2 col-form-label">Emplacement</label>
  473. <div class="col-sm-10">
  474. <input class="form-control" type="text" name="location" value="<?php echo htmlspecialchars($config[$supplier]['location']); ?>" placeholder="Emplacement" />
  475. <div class="form-text">L'emplacement de la commande. N'est vraiement utile que s'il y a plusieurs emplacements différents. Par convention c'est le cas quand il y a un tiret (<tt>-</tt>) dans le nom du fournisseur.</div>
  476. </div>
  477. </div>
  478. <div class="row mb-3">
  479. <label for="description" class="col-sm-2 col-form-label">Description</label>
  480. <div class="col-sm-10">
  481. <textarea class="form-control js-ckeditor" name="description" rows="20"><?php echo $config[$supplier]['description']; ?></textarea>
  482. <div class="form-text">La description affichée sous le titre.</div>
  483. </div>
  484. </div>
  485. <div class="row mb-3">
  486. <label for="choices" class="col-sm-2 col-form-label">Choix</label>
  487. <div class="col-sm-10">
  488. <textarea class="form-control" name="choices" rows="5"><?php echo implode(PHP_EOL, $config[$supplier]['choices']); ?></textarea>
  489. <div class="form-text">Les différents choix possibles. Un par ligne. Ou pas.</div>
  490. </div>
  491. </div>
  492. <div class="row mb-3">
  493. <label for="start" class="col-sm-2 col-form-label">Début</label>
  494. <div class="col-sm-10">
  495. <input class="form-control" type="date" name="start" value="<?php echo $config[$supplier]['start']; ?>" />
  496. <div class="form-text">La date du premier événement, si nécessaire de le préciser.</div>
  497. </div>
  498. </div>
  499. <div class="row mb-3">
  500. <label for="frequency" class="col-sm-2 col-form-label">Fréquence</label>
  501. <div class="col-sm-10">
  502. <input class="form-control" type="text" name="frequency" value="<?php echo $config[$supplier]['frequency']; ?>" />
  503. <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>
  504. </div>
  505. </div>
  506. <div class="row mb-3">
  507. <label for="excludes" class="col-sm-2 col-form-label">Exceptions</label>
  508. <div class="col-sm-10">
  509. <textarea class="form-control" name="excludes" rows="5"><?php echo implode(PHP_EOL, array_map(function ($value) use ($excludesFormatter) { return $excludesFormatter->format(new \DateTimeImmutable($value, new \DateTimeZone('Europe/Paris'))); }, $config[$supplier]['excludes'])); ?></textarea>
  510. <div class="form-text">Les dates à exclure. Une par ligne. Ou pas. En tous cas le format c'est celui de l'<a class="text-reset" href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/" target="_blank">ICU</a> : <kbd><?php echo $excludesFormatter->getPattern(); ?></kbd>. Par exemple <kbd><?php echo $excludesFormatter->format(new \DateTimeImmutable('first day of january this year', new \DateTimeZone('Europe/Paris'))); ?></kbd>, <kbd><?php echo $excludesFormatter->format(new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris'))); ?></kbd> ou <kbd><?php echo $excludesFormatter->format(new \DateTimeImmutable('last day of december this year', new \DateTimeZone('Europe/Paris'))); ?></kbd>.</div>
  511. </div>
  512. </div>
  513. <div class="row mb-3">
  514. <label for="password" class="col-sm-2 col-form-label">Mot de passe</label>
  515. <div class="col-sm-10">
  516. <input class="form-control" type="text" name="password" value="<?php echo $config[$supplier]['password']; ?>" />
  517. <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>). Par exemple <kbd><?php echo generatePassword(); ?></kbd>. Et pas de mot de passe, pas de protection.</div>
  518. </div>
  519. </div>
  520. <div class="row">
  521. <div class="col px-0">
  522. <div class="js-fixed bg-light p-3">
  523. <button class="btn btn-primary" type="submit" name="action" value="config">Enregistrer</button>
  524. </div>
  525. </div>
  526. </div>
  527. </form>
  528. </div>
  529. </section>
  530. <?php else /* !$isConfig */ : ?>
  531. <?php if ($supplierIsNew) : ?>
  532. <section class="container-fluid pt-3">
  533. <div class="alert alert-warning alert-dismissible" role="alert">
  534. Ce fournisseur n'existe pas encore !
  535. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
  536. </div>
  537. <div class="row g-3">
  538. <div class="col-xs-12 col-sm-6">
  539. <div class="card h-100">
  540. <div class="card-body">
  541. <h2 class="card-title">Oops !</h2>
  542. <p class="card-text">Le nom du fournisseur « <tt><?php echo $supplier; ?></tt> » est probablement mal orthographié, c'est pour ça qu'il n'existe pas.</p>
  543. <p class="card-text">
  544. Peut-être sagissait-il de
  545. <?php $max = 3; foreach ($closestSuppliers as $index => $item) : ?>
  546. <?php if ($index < $max) : ?>
  547. <?php if ($index > 0) : ?>
  548. <?php if ($index === min($max, count($closestSuppliers) - 1)) : ?>
  549. ou
  550. <?php else : ?>
  551. ,
  552. <?php endif; ?>
  553. <?php endif; ?>
  554. « <tt><a class="card-link" href="<?php echo generateUrl($item['supplier']); ?>"><?php echo $item['supplier']; ?></a></tt> »
  555. <?php endif; ?>
  556. <?php endforeach; ?>
  557. ?
  558. </p>
  559. <a class="btn btn-primary" href="<?php echo generateUrl(); ?>">Recommencer</a>
  560. </div>
  561. </div>
  562. </div>
  563. <div class="col-xs-12 col-sm-6">
  564. <div class="card h-100">
  565. <div class="card-body">
  566. <h2 class="card-title">C'est normal !</h2>
  567. <p class="card-text">On souhaite le créer.</p>
  568. <p class="card_text">Une fois configuré il sera prêt à être utilisé.</p>
  569. <a class="btn btn-primary" href="<?php echo generateUrl($supplier) . '?action=config'; ?>">Configurer</a>
  570. </div>
  571. </div>
  572. </div>
  573. </div>
  574. </section>
  575. <?php else /* !$supplierIsNew */ : ?>
  576. <section class="container-fluid">
  577. <div class="row my-3">
  578. <div class="col">
  579. <h1>
  580. <?php if (!$inIframe) : ?>
  581. <div class="btn-group float-end" role="group">
  582. <?php if (isset($previousEvent)) : ?>
  583. <a class="btn btn-outline-primary" href="<?php echo generateUrl($supplier, $previousEvent); ?>" title="Événement précédent">
  584. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
  585. <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"/>
  586. </svg>
  587. </a>
  588. <?php endif; ?>
  589. <?php /* ?>
  590. <a class="btn btn-outline-primary d-none d-sm-inline" href="<?php echo generateUrl($supplier, $event); ?>" title="Cet événement">
  591. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-link" viewBox="0 0 16 16">
  592. <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"/>
  593. <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"/>
  594. </svg>
  595. </a>
  596. <?php */ ?>
  597. <?php if (isset($nextEvent)) : ?>
  598. <a class="btn btn-outline-primary" href="<?php echo generateUrl($supplier, $nextEvent); ?>" title="Événement suivant">
  599. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-right" viewBox="0 0 16 16">
  600. <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"/>
  601. </svg>
  602. </a>
  603. <?php endif; ?>
  604. </div>
  605. <?php endif; // !$inIframe ?>
  606. <?php echo $config[$supplier]['title']; ?>
  607. <?php echo $config[$supplier]['subtitle']; ?>
  608. </h1>
  609. <?php if (!empty($config[$supplier]['description'])) : ?>
  610. <p class="lead"><?php echo $config[$supplier]['description']; ?></p>
  611. <?php endif; ?>
  612. </div>
  613. </div>
  614. </section>
  615. <section class="container-fluid">
  616. <div class="row g-3">
  617. <form class="js-localremember bg-dark text-light" action="<?php echo generateUrl($supplier); ?>" method="post">
  618. <?php if ($inIframe) : ?><input type="hidden" name="iframe" /><?php endif; // $inIframe ?>
  619. <div class="row my-3">
  620. <label for="title" class="col-sm-2 col-form-label">Nom</label>
  621. <div class="col-sm-10">
  622. <input class="form-control" type="text" name="name" required placeholder="Nom" />
  623. </div>
  624. </div>
  625. <?php if (!empty($config[$supplier]['choices'])) : ?>
  626. <div class="row mb-3">
  627. <label for="title" class="col-sm-2 col-form-label">Choix</label>
  628. <div class="col-sm-10">
  629. <div class="btn-group" role="group">
  630. <?php foreach ($config[$supplier]['choices'] as $index => $choice) : ?>
  631. <input type="radio" class="btn-check" id="<?php printf('option%d', $index); ?>" autocomplete="off" name="choice" value="<?php echo $choice; ?>" required />
  632. <label class="btn btn-outline-light" for="<?php printf('option%d', $index); ?>"><?php echo $choice; ?></label>
  633. <?php endforeach; ?>
  634. </div>
  635. </div>
  636. </div>
  637. <?php endif; ?>
  638. <div class="row">
  639. <div class="col mb-3">
  640. <input type="hidden" name="supplier" value="<?php echo $supplier; ?>" />
  641. <input type="hidden" name="event" value="<?php echo $event; ?>" />
  642. <?php if (empty($config[$supplier]['choices'])) : ?>
  643. <input type="hidden" name="choice" value="" />
  644. <?php endif; ?>
  645. <?php if (isInPast($event)) :?>
  646. <div class="alert alert-warning alert-dismissible" role="alert">
  647. Êtes-vous sûr·e de vouloir commander pour <strong>le <?php echo $date; ?> (<?php echo $ago; ?>)</strong> et pas plutôt pour <strong><a href="<?php echo generateUrl($supplier, $currentEvent->format(EVENT_FORMAT)); ?>">le <?php echo $currentDate; ?> (<?php echo $currentAgo; ?>)</a></strong> ?
  648. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
  649. </div>
  650. <?php endif; ?>
  651. <button class="btn btn-primary" type="submit" name="action" value="insert">Commander</button>
  652. </div>
  653. </div>
  654. </form>
  655. </div>
  656. </section>
  657. <section class="container-fluid">
  658. <div class="row my-3">
  659. <?php if (!empty($items)) : ?>
  660. <div class="col-12">
  661. <div class="table-responsive">
  662. <table class="table table-striped table-hover align-middle sortable">
  663. <thead>
  664. <tr>
  665. <th scope="col">
  666. Nom
  667. </th>
  668. <?php if (!empty($config[$supplier]['choices'])) : ?>
  669. <th scope="col">
  670. Choix
  671. </th>
  672. <?php endif; ?>
  673. <th scope="col" class="no-sort">
  674. &nbsp;
  675. </th>
  676. </tr>
  677. </thead>
  678. <tbody>
  679. <?php foreach ($items as $item) : ?>
  680. <tr>
  681. <td>
  682. <?php echo $item['name']; ?>
  683. </td>
  684. <?php if (!empty($config[$supplier]['choices'])) : ?>
  685. <td>
  686. <?php if (!empty($item['choice'])) : ?>
  687. <?php echo $item['choice']; ?>
  688. <?php endif; ?>
  689. </td>
  690. <?php endif; ?>
  691. <td>
  692. <form onsubmit="return confirm('Souhaitez-vous vraiment annuler cette commande ?');">
  693. <?php if ($inIframe) : ?><input type="hidden" name="iframe" /><?php endif; // $inIframe ?>
  694. <input type="hidden" name="supplier" value="<?php echo $supplier; ?>" />
  695. <input type="hidden" name="event" value="<?php echo $event; ?>" />
  696. <input type="hidden" name="name" value="<?php echo $item['name']; ?>" />
  697. <input type="hidden" name="choice" value="<?php echo $item['choice']; ?>" />
  698. <button class="btn btn-secondary float-end" type="submit" name="action" value="delete">Annuler</button>
  699. </form>
  700. </td>
  701. </tr>
  702. <?php endforeach; ?>
  703. </tbody>
  704. </table>
  705. </div>
  706. </div>
  707. <?php endif; ?>
  708. <?php if (!$inIframe) : ?>
  709. <div class="col-12">
  710. <div class="accordion accordion-flush">
  711. <div class="accordion-item">
  712. <div id="accordion1" class="accordion-collapse collapse">
  713. <div class="accordion-body">
  714. <ul class="list-group">
  715. <?php foreach ($stats as $choice => $count) : ?>
  716. <li class="list-group-item d-flex justify-content-between align-items-center">
  717. <?php echo $choice; ?>
  718. <span class="badge bg-secondary rounded-pill"><?php echo $count; ?></span>
  719. </li>
  720. <?php endforeach; ?>
  721. </ul>
  722. </div>
  723. </div>
  724. <h2 class="accordion-header">
  725. <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#accordion1" aria-expanded="false">
  726. Commandes
  727. <span class="badge bg-primary rounded-pill ms-1"><?php echo count($items); ?></span>
  728. </button>
  729. </h2>
  730. </div>
  731. </div>
  732. </div>
  733. <?php endif; // !$inIframe ?>
  734. </div>
  735. </section>
  736. <?php endif; /* $supplierIsNew */ ?>
  737. <?php endif; /* $isConfig*/ ?>
  738. <?php endif; /* $hasSupplier */ ?>
  739. </main>
  740. <div class="modal fade" id="linkModal" tabindex="-1" aria-hidden="true">
  741. <div class="modal-dialog">
  742. <div class="modal-content">
  743. <div class="modal-header">
  744. <h5 class="modal-title">Lien</h5>
  745. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
  746. </div>
  747. <div class="modal-body">
  748. <div class="container-fluid">
  749. <div class="row g-3">
  750. <div class="col-12">
  751. Adresse web
  752. </div>
  753. <div class="col-12 text-center">
  754. <a href="<?php echo $linkUrl; ?>"><tt id="linkURL"><?php echo $linkUrl; ?></tt></a>
  755. <button class="btn btn-outline-dark js-clipboard" type="button" role="button" data-clipboard-target="#linkURL" data-bs-toggle="tooltip" data-bs-trigger="manual">
  756. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16">
  757. <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
  758. <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
  759. </svg>
  760. </button>
  761. </div>
  762. <?php if ($hasSupplier) : ?>
  763. <div class="col-12">
  764. IFrame
  765. </div>
  766. <div class="col-12 text-center">
  767. <pre id="iframeCode"><?php ob_start(); ?>
  768. <iframe src="<?php echo generateUrl($supplier, null, true); ?>">
  769. </iframe>
  770. <?php echo htmlentities(ob_get_clean()); ?></pre>
  771. <button class="btn btn-outline-dark js-clipboard" type="button" role="button" data-clipboard-target="#iframeCode" data-bs-toggle="tooltip" data-bs-trigger="manual">
  772. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16">
  773. <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
  774. <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
  775. </svg>
  776. </button>
  777. </div>
  778. <?php endif; // $hasSupplier ?>
  779. <div class="col-12">
  780. QR Code
  781. </div>
  782. <div class="col-12">
  783. <div id="linkQRCode"></div>
  784. </div>
  785. </div>
  786. </div>
  787. </div>
  788. <div class="modal-footer">
  789. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
  790. </div>
  791. </div>
  792. </div>
  793. </div>
  794. <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>
  795. <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  796. <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
  797. <?php if ($isConfig) : ?>
  798. <script src="https://cdn.ckeditor.com/ckeditor5/31.0.0/classic/ckeditor.js"></script>
  799. <script>
  800. document.querySelectorAll('.js-ckeditor').forEach(function (element) {
  801. ClassicEditor.create(element).catch(error => { console.error(error); });
  802. });
  803. </script>
  804. <?php else : ?>
  805. <script>document.addEventListener("click",function(b){function n(a,e){a.className=a.className.replace(u,"")+e}function p(a){return a.getAttribute("data-sort")||a.innerText}var u=/ dir-(u|d) /,c=/\bsortable\b/;b=b.target;if("TH"===b.nodeName)try{var q=b.parentNode,f=q.parentNode.parentNode;if(c.test(f.className)){var g,d=q.cells;for(c=0;c<d.length;c++)d[c]===b?g=c:n(d[c],"");d=" dir-d ";-1!==b.className.indexOf(" dir-d ")&&(d=" dir-u ");n(b,d);var h=f.tBodies[0],k=[].slice.call(h.rows,0),r=" dir-u "===d;k.sort(function(a,
  806. e){var l=p((r?a:e).cells[g]),m=p((r?e:a).cells[g]);return isNaN(l-m)?l.localeCompare(m):l-m});for(var t=h.cloneNode();k.length;)t.appendChild(k.splice(0,1)[0]);f.replaceChild(t,h)}}catch(a){}});</script>
  807. <?php endif; ?>
  808. <script>
  809. document.addEventListener('DOMContentLoaded', function () {
  810. document.querySelectorAll('.js-localremember').forEach(function (form) {
  811. const fields = [ 'name', 'choice' ];
  812. form.addEventListener('submit', function (event) {
  813. fields.forEach(function (field) {
  814. window.localStorage.setItem('mon_panier_bio_' + field, form.elements[field].value);
  815. });
  816. });
  817. fields.forEach(function (field) {
  818. if (
  819. (form.elements[field].value === '')
  820. && (window.localStorage.getItem('mon_panier_bio_' + field) !== null)
  821. ) {
  822. form.elements[field].value = window.localStorage.getItem('mon_panier_bio_' + field);
  823. }
  824. });
  825. });
  826. document.querySelectorAll('.js-closealerts').forEach(function (element) {
  827. element.addEventListener('input', function (event) {
  828. if (event.target.value !== '') {
  829. document.querySelectorAll('.alert').forEach(function (alertElement) {
  830. var alert = bootstrap.Alert.getOrCreateInstance(alertElement)
  831. alert.close();
  832. });
  833. }
  834. });
  835. });
  836. var qrcode = new QRCode('linkQRCode', {
  837. text: document.getElementById('linkURL').innerText,
  838. width: 300,
  839. height: 300,
  840. colorDark : '#000000',
  841. colorLight : '#ffffff',
  842. correctLevel : QRCode.CorrectLevel.H,
  843. });
  844. document.querySelector('#linkQRCode img').classList.add('img-fluid', 'mx-auto', 'd-block');
  845. var clipboard = new ClipboardJS('.js-clipboard');
  846. clipboard.on('success', function (event) {
  847. var tooltip = new bootstrap.Tooltip(event.trigger, {
  848. title: 'Copié dans le presse-papier'
  849. });
  850. tooltip.show();
  851. });
  852. document.querySelectorAll('.js-fixed').forEach(function (element) {
  853. const height = window.getComputedStyle(element).height;
  854. element.parentElement.style.height = height;
  855. element.classList.add('is-fixed');
  856. });
  857. }, false);
  858. </script>
  859. </body>
  860. </html>