'%supplier% %date%',
'description' => '',
'choices' => [],
'start' => 'now 00:00:00',
'frequency' => '1 day',
'password' => '',
],
$config[$supplier]
);
$hasPassword = !empty($config[$supplier]['password']);
if ($action === 'config') {
if ($hasPassword) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header(sprintf('WWW-Authenticate: Basic realm="mon-panier-bio config %s"', $supplier));
header('HTTP/1.0 401 Unauthorized');
printf('Cette config est protégée par mot de passe !');
exit;
} elseif (
($_SERVER['PHP_AUTH_USER'] !== $supplier)
or ($_SERVER['PHP_AUTH_PW'] !== $config[$supplier]['password'])
) {
header('HTTP/1.0 403 Forbidden');
printf('Cette config est protégée par mot de passe !');
exit;
}
}
foreach (array_keys($config[$supplier]) as $key)
if (isset($_REQUEST[$key]))
$config[$supplier][$key] = (!in_array($key, ['title', 'description']) ? filter_var($_REQUEST[$key], FILTER_SANITIZE_STRING) : $_REQUEST[$key]);
}
if (empty($config[$supplier]['start']))
$config[$supplier]['start'] = 'now 00:00:00';
if (is_string($config[$supplier]['choices']))
$config[$supplier]['choices'] = explode(PHP_EOL, $config[$supplier]['choices']);
if (!is_array($config[$supplier]['choices']))
$config[$supplier]['choices'] = [];
$config[$supplier]['choices'] = array_filter(
$config[$supplier]['choices'],
function ($choice) {
return is_string($choice) and !empty(trim($choice));
}
);
$config[$supplier]['choices'] = array_map('trim', $config[$supplier]['choices']);
}
$isConfig = false;
if ($action === 'config') {
$output = fopen(CONFIG_FILE, 'w+');
if ($output) {
if (flock($output, LOCK_EX)) {
fwrite($output, 'getTimestamp() < $now->getTimestamp())
and ($maxIterations-- > 0)
) $current->add($frequency);
$nextEvent = $current->format('Y-m-d');
header(sprintf('Location: %s?supplier=%s&event=%s', $requestUrl, $supplier, $nextEvent));
die();
} else {
$event = $_REQUEST['event'];
$current = new \DateTimeImmutable($event);
$frequency = \DateInterval::createFromDateString($config[$supplier]['frequency']);
$previous = $current->sub($frequency);
$previousEvent = $previous->format('Y-m-d');
if (false and !array_key_exists($previousEvent, $data[$supplier]))
unset($previousEvent);
$next = $current->add($frequency);
$nextEvent = $next->format('Y-m-d');
if (false and !array_key_exists($nextEvent, $data[$supplier]))
unset($nextEvent);
}
switch ($action) {
case 'insert' :
case 'delete' :
$isBeginning = (!file_exists(DATA_FILE) or in_array(filesize(DATA_FILE), [ false, 0 ]));
$output = fopen(DATA_FILE, 'a+');
if (!$output) break;
if (!flock($output, LOCK_EX)) break;
if ($isBeginning)
fwrite($output, ' $prevItem)
if ($prevItem['hash'] === $item['hash'])
unset($items[$index]);
}
}
$date = (new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'Europe/Paris'))->format(new \DateTime($event));
while (preg_match('/%([^%]+)%/i', $config[$supplier]['title'], $match))
$config[$supplier]['title'] = str_replace(
$match[0],
${$match[1]},
$config[$supplier]['title']
);
$stats = [];
foreach ($items as $item)
if (!empty($item['choice']))
$stats[$item['choice']] += 1;
}
?>
Nom
|
Choix
|
|
|
|
|
Commandes
$count) : ?>
/