diff --git a/index.php b/index.php index 3ff14c4..e1aa3cd 100644 --- a/index.php +++ b/index.php @@ -95,9 +95,10 @@ if ($action === 'config') { $hasEvent = isset($_REQUEST['event']); if (!$isConfig and $hasSupplier) { + $start = new \DateTime($config[$supplier]['start']); if (!$hasEvent) { $now = new \DateTime('now'); - $current = new \DateTime($config[$supplier]['start']); + $current = clone $start; $frequency = \DateInterval::createFromDateString($config[$supplier]['frequency']); $maxIterations = 1000; while ( @@ -107,10 +108,20 @@ if (!$isConfig and $hasSupplier) { $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); } - $event = $_REQUEST['event']; - switch ($action) { case 'insert' : case 'delete' : @@ -295,7 +306,32 @@ if (!$isConfig and $hasSupplier) {
-

+

+ + + +