Browse Source

affiche un warning si on tente de commander dans le passé

master
vince vince 1 year ago
parent
commit
0895752ea9
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      index.php

+ 11
- 0
index.php View File

@ -4,6 +4,7 @@ define('DEFAULT_TITLE', 'Mon panier bio');
define('SUPPLIER_REGEX', '[A-Za-z]\w{0,31}');
define('EVENT_REGEX', '\d{4}\-[01]\d\-[0123]\d');
define('EVENT_FORMAT', 'Y-m-d');
define('REQUEST_REGEX', '/^https?:\/\/.+\/(?<supplier>' . SUPPLIER_REGEX . ')\/?(?<event>' . EVENT_REGEX . ')?\/?$/');
define('ACTION_REGEX', '/^[a-z]{1,16}$/i');
@ -330,6 +331,10 @@ if (!$isConfig and !$supplierIsNew and $hasSupplier) {
$ago = ago(new \DateTimeImmutable($event));
$color = isInPast($event) ? 'text-danger' : 'text-muted';
$currentEvent = findNext(new \DateTime($config[$supplier]['start']), $config[$supplier]['frequency'], $config[$supplier]['excludes'], true);
$currentDate = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format($currentEvent);
$currentAgo = ago($currentEvent);
foreach (['title', 'subtitle', 'description'] as $key) {
while (preg_match('/%([^%]+)%/i', $config[$supplier][$key], $match))
$config[$supplier][$key] = str_replace(
@ -635,6 +640,12 @@ $linkUrl = !$hasSupplier ? generateUrl() : (!$hasEvent ? generateUrl($supplier)
<?php if (empty($config[$supplier]['choices'])) : ?>
<input type="hidden" name="choice" value="" />
<?php endif; ?>
<?php if (isInPast($event)) :?>
<div class="alert alert-warning alert-dismissible" role="alert">
Ê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> ?
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
</div>
<?php endif; ?>
<button class="btn btn-primary" type="submit" name="action" value="insert">Commander</button>
</div>
</div>


Loading…
Cancel
Save