Browse Source

évite l'affichage de doublons (sans empêcher leur insertion)

master
vince vince 2 years ago
parent
commit
c77560c147
1 changed files with 14 additions and 6 deletions
  1. +14
    -6
      index.php

+ 14
- 6
index.php View File

@ -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, '<?php' . PHP_EOL);
$item = [];
foreach (['name', 'choice', 'action'] as $field)
$item[$field] = filter_var($_REQUEST[$field], FILTER_SANITIZE_STRING);
$item['timestamp'] = time();
$item['hash'] = md5(implode([ $item['name'], $item['choice'], ]));
fprintf(
$output,
'$data[%s][%s][] = %s;' . PHP_EOL,
@ -291,7 +294,12 @@ if (!$isConfig and !$supplierIsNew and $hasSupplier) {
foreach ($allItems as $item) {
if ($item['action'] === 'insert') {
$items[] = $item;
$alreadyInserted = false;
foreach ($items as $index => $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'])


Loading…
Cancel
Save