From c77560c147d310f7b81974c7628dc8f922dd3837 Mon Sep 17 00:00:00 2001 From: vince Date: Sat, 8 Jan 2022 17:12:02 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A9vite=20l'affichage=20de=20doublons=20(san?= =?UTF-8?q?s=20emp=C3=AAcher=20leur=20insertion)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 8560c85..94b75ef 100644 --- a/index.php +++ b/index.php @@ -250,17 +250,20 @@ if (!$isConfig and !$supplierIsNew and $hasSupplier) { switch ($action) { case 'insert' : case 'delete' : + $item = []; + + foreach (['name', 'choice', 'action'] as $field) + $item[$field] = filter_var($_REQUEST[$field], FILTER_SANITIZE_STRING); + $item['timestamp'] = time(); + $hash = md5(implode([ $item['name'], $item['choice'], ])); + $item['hash'] = $hash; + $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']) + $alreadyInserted = true; + if (!$alreadyInserted) + $items[] = $item; } elseif ($item['action'] === 'delete') { foreach ($items as $index => $prevItem) if ($prevItem['hash'] === $item['hash'])