From bf02358a6444651c627316f9568154898c49de81 Mon Sep 17 00:00:00 2001 From: vince Date: Wed, 29 Dec 2021 11:26:38 +0100 Subject: [PATCH] =?UTF-8?q?g=C3=A8re=20la=20cr=C3=A9ation=20de=20suppliers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 324 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 198 insertions(+), 126 deletions(-) diff --git a/index.php b/index.php index e176be2..5b91ffe 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ define('REQUEST_REGEX', '/^https?:\/\/.+\/(?' . SUPPLIER_REGEX . ')\/? define('ACTION_REGEX', '/^[a-z]{1,16}$/i'); $baseUrl = trim((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '/'); -$requestUrl = trim(str_replace($_SERVER['QUERY_STRING'], '', $baseUrl), '?'); +$requestUrl = trim(array_key_exists('QUERY_STRING', $_SERVER) ? str_replace($_SERVER['QUERY_STRING'], '', $baseUrl) : $baseUrl, '?'); if (preg_match(REQUEST_REGEX, $requestUrl, $match)) { $requestSupplier = array_key_exists('supplier', $match) ? $match['supplier'] : null; @@ -83,8 +83,12 @@ $excludesFormatter = new \IntlDateFormatter('fr_FR.UTF8', \IntlDateFormatter::SH if ($hasSupplier) { - if (!isset($config[$supplier])) + if (!isset($config[$supplier])) { $config[$supplier] = []; + $supplierIsNew = true; + } else { + $supplierIsNew = false; + } $config[$supplier] = array_merge( [ @@ -201,7 +205,7 @@ try { } catch (\Exception $exception) { $hasEvent = false; } -if (!$isConfig and $hasSupplier) { +if (!$isConfig and !$supplierIsNew and $hasSupplier) { $start = new \DateTime($config[$supplier]['start']); if (!$hasEvent) { @@ -294,6 +298,28 @@ if (!$isConfig and $hasSupplier) { } +if ($supplierIsNew and !empty($suppliers)) { + $closestSuppliers = array_filter( + array_map( + function ($other) use ($supplier) { + return [ + 'supplier' => $other, + 'score' => levenshtein($supplier, $other), + ]; + }, + $suppliers + ), + function ($item) { + return $item['score'] > 0; + } + ); + usort($closestSuppliers, function ($a, $b) { + if ($a['score'] == $b['score']) { + return 0; + } + return ($a['score'] < $b['score']) ? -1 : 1; + }); +} ?> @@ -437,144 +463,190 @@ if (!$isConfig and $hasSupplier) { - -
-
-
-

- - - -

- -

- + + +
+ -
-
-
-
-
-
- -
- +
+
+
+
+

Oops !

+

Le nom du fournisseur «  » est probablement mal orthographié, c'est pour ça qu'il n'existe pas.

+

+ Peut-être sagissait-il de + $item) : ?> + + 0) : ?> + + ou + + , + + + «  » + + + ? +

+ Recommencer +
- -
- -
-
- $choice) : ?> - - - +
+
+
+

C'est normal !

+

On souhaite le créer.

+

Une fois configuré il sera prêt à être utilisé.

+ Configurer
- -
-
- - - - - - -
+
+
+ +
+
+
+

+ + + +

+ +

+
- -
-
-
-
- -
-
- - - - - - - - - - - - + + +
+
+
+
+ +
+ +
+
+ +
+ +
+
+ $choice) : ?> + + + +
+
+
+ +
+
+ + + + + + +
+
+ +
+
+
+
+ +
+
+
- Nom - - Choix - -   -
+ - + - + - + - - -
- - + Nom + - - - - + Choix + -
- - - - - -
-
+   +
+ + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + +
-
- -
-
    -
  • - Commandes - -
  • - $count) : ?> + +
    +
    • - - + Commandes +
    • - -
    + $count) : ?> +
  • + + +
  • + +
+
- -
- + + +