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'])