Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
78 righe
2.7 KiB
78 righe
2.7 KiB
<? |
|
class massiveHelper { |
|
|
|
public static function printPanel($elements,$action,$data=NULL,$overideDownload = NULL) { |
|
if (!empty($elements && !empty($action))) { |
|
$id = rand() . time(); |
|
include (__DIR__."/panel.php"); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public static function printErrors($errors) { |
|
if (!empty($errors)) { |
|
include (__DIR__."/errors.php"); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public static function getDataFromUpload($fields,$filename) { |
|
global $config; |
|
if (!empty($fields) && !empty($filename)) { |
|
$path = "{$config["chunk_folder"]}/{$_SESSION["utente"]->codice}/{$filename}"; |
|
$results = fromCSVtoArray($path); |
|
$errors = []; |
|
if ($results != false) { |
|
$fieldsKey = array_keys($fields); |
|
$resultsKey = array_keys($results[0]) ?? ["notFound"]; |
|
$cmp = array_diff($resultsKey,$fieldsKey); |
|
if (empty($cmp)) { |
|
foreach($results AS $cont => $element) { |
|
$cField = 0; |
|
foreach($element AS $field => $value) { |
|
if (!empty($fields[$field])) { |
|
$regole = $fields[$field]; |
|
if (!empty($value)) { |
|
if ($regole["tipo"] == "Number" && !is_numeric($value)) { |
|
$value = str_replace(".","",$value); |
|
$value = str_replace(",",".",$value); |
|
$results[$cont][$field] = $value; |
|
if (!is_numeric($value)) { |
|
$errors[$cont][] = $field . " - " . __("Formato errato"); |
|
} |
|
} |
|
if (!empty($regole["valori"]) && in_array($value,$regole["valori"]) === false) { |
|
$errors[$cont][] = $field . " - " . __("Valore non previsto"); |
|
} |
|
} else { |
|
if ($regole["obbligatorio"] == "S") { |
|
$zero = false; |
|
if ($regole["tipo"] == "Number" && $value === "0") { $zero = true; } |
|
if (!$zero) { $errors[$cont][] = $field . " - " . __("Campo obbligatorio"); } |
|
} |
|
} |
|
} else { |
|
$errors[$cont][] = $field . " - " . __("Campo non previsto"); |
|
} |
|
$cField++; |
|
} |
|
} |
|
} else { |
|
$errors[0][] = __("CSV non corretto"); |
|
} |
|
} else { |
|
$errors[0][] = __("CSV non riconosciuto"); |
|
} |
|
if (!empty($errors)) { |
|
return ["errors" => $errors]; |
|
} else { |
|
return ["data" => $results]; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
} |
|
?>
|