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.
189 righe
7.2 KiB
189 righe
7.2 KiB
<? |
|
$error = true; |
|
$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; |
|
include_once($configPath); |
|
|
|
$mailer = new Communicator(); |
|
if (isset($_SESSION["utente"]) && isset($_SESSION["ente"]) && $_SESSION["utente"]->isSupportoOrRoot()) { |
|
$tokenImport = $_POST["importKey"]; |
|
if (!empty($_SESSION["bulkImportFornitori"][$tokenImport])) { |
|
$dataToImport = $_SESSION["bulkImportFornitori"][$tokenImport]; |
|
ini_set("max_execution_time", 10*count($dataToImport)); |
|
$errors = []; |
|
$i = 0; |
|
$checkExisting = $pdo->prepare("SELECT codice FROM b_operatori_economici WHERE pec = :pec"); |
|
$checkRelazione = $pdo->prepare("SELECT codice FROM r_enti_operatori WHERE cod_ente = :ente AND codice_operatore = :codice_operatore"); |
|
$checkExistingUser = $pdo->prepare("SELECT codice FROM b_utenti WHERE email = :email"); |
|
$getOEfromUser = $pdo->prepare("SELECT codice_operatore FROM r_oe_utenti WHERE codice_utente = :codice"); |
|
$checkRelazione->bindValue(":ente",$_SESSION["ente"]->codice); |
|
$insertRelazione = $pdo->prepare("INSERT INTO r_enti_operatori (cod_ente,codice_operatore,utente_modifica) VALUES (:ente, :codice_operatore, -1)"); |
|
$insertRelazione->bindValue(":ente",$_SESSION["ente"]->codice); |
|
if (!empty($_POST["codice_elenco"])) { |
|
$checkElenco = $pdo->prepare("SELECT codice FROM r_partecipanti_albo WHERE codice_elenco = :elenco AND codice_operatore = :operatore"); |
|
$checkElenco->bindValue(":elenco",$_POST["codice_elenco"]); |
|
$insertElenco = $pdo->prepare("INSERT INTO r_partecipanti_albo (codice_elenco,codice_operatore,conferma,valutato,ammesso,visto,utente_modifica) VALUES (:elenco,:operatore,'S','S','S','S',-1)"); |
|
$insertElenco->bindValue(":elenco",$_POST["codice_elenco"]); |
|
} |
|
foreach($dataToImport AS $row) { |
|
$i++; |
|
$codiceOE = null; |
|
$existing = false; |
|
$checkExisting->execute([":pec"=>$row["pec"]]); |
|
$checkExistingUser->execute([":email"=>$row["emailReferente"]]); |
|
if ($checkExisting->rowCount() > 0) { |
|
$existing = true; |
|
$codiceOE = $checkExisting->fetch(PDO::FETCH_COLUMN); |
|
} else if ($checkExistingUser->rowCount() > 0) { |
|
$existing = true; |
|
$codiceUser = $checkExistingUser->fetch(PDO::FETCH_COLUMN); |
|
$getOEfromUser->execute([":codice"=>$codiceUser]); |
|
if ($getOEfromUser->rowCount() > 0) { |
|
$codiceOE = $getOEfromUser->fetch(PDO::FETCH_COLUMN); |
|
} else { |
|
$errors[$i] = __("Impossibile associare l'utente"); |
|
} |
|
} else { |
|
|
|
$post = []; |
|
$post["user"] = [ |
|
"email" => $row["emailReferente"], |
|
"password" => generateStrongPassword(), |
|
"nome" => $row["nomeReferente"], |
|
"cognome" => $row["cognomeReferente"] |
|
]; |
|
$post["oe"] = [ |
|
"tipo" => ($row["tipologia"] == "impresa") ? "IMP" : "PRO", |
|
"ragione_sociale" => $row["denominazione"], |
|
"vecchio_codice" => $row["vecchioCodice"], |
|
"stato_legale" => (strlen($row["nazione"] ?? "") == 2) ? $row["nazione"] : "IT", |
|
"codice_fiscale_impresa" => $row["codiceFiscale"], |
|
"partita_iva" => $row["partitaIva"], |
|
"pec" => $row["pec"], |
|
]; |
|
$post["elenchi"] = []; |
|
if(!empty($row["elenchi"])) { |
|
$post["elenchi"] = explode("/", $row["elenchi"]); |
|
} |
|
$post["soa"] = []; |
|
if(!empty($row["soa"])) { |
|
$soas = explode("/", $row["soa"]); |
|
|
|
foreach($soas as $soa) { |
|
$categoria_soa = $soa[0]; |
|
$classifica_soa = $soa[1]; |
|
$post["soa"][] = ["categoria" => $categoria_soa, "classifica" => $classifica_soa]; |
|
} |
|
} |
|
if (strpos($row["cpv"],"/") !== false) { |
|
$tmpCpv = explode("/",$row["cpv"]); |
|
} else { |
|
$tmpCpv = [$row["cpv"]]; |
|
} |
|
$post["cpv"] = []; |
|
if (!empty($tmpCpv)) { |
|
foreach($tmpCpv AS $codice) { |
|
$check = rtrim($codice,"0"); |
|
$check = cpvManager::getInfo([$check]); |
|
if (!empty($codice)) { |
|
$post["cpv"][] = $codice; |
|
} |
|
} |
|
} |
|
//if (!empty($post["cpv"])) { |
|
|
|
$check = oeManager::create($post,$_SESSION["ente"]->codice); |
|
if (!is_numeric($check)) { |
|
$errors[$i] = json_encode($check); |
|
} else { |
|
$codiceOE = $check; |
|
} |
|
/*} else { |
|
$errors[$i] = __("Categorie CPV mancanti"); |
|
}*/ |
|
} |
|
if (!empty($codiceOE)) { |
|
$checkRelazione->bindValue(":codice_operatore",$codiceOE); |
|
$checkRelazione->execute(); |
|
if (empty($checkRelazione->rowCount())) { |
|
$insertRelazione->bindValue(":codice_operatore",$codiceOE); |
|
$insertRelazione->execute(); |
|
} |
|
if (!empty($_POST["codice_elenco"])) { |
|
$checkElenco->bindValue(":operatore",$codiceOE); |
|
$checkElenco->execute(); |
|
if (empty($checkElenco->rowCount())) { |
|
$insertElenco->bindValue(":operatore",$codiceOE); |
|
$insertElenco->execute(); |
|
} |
|
} |
|
|
|
if (empty($existing)) { |
|
$pdo->go("UPDATE b_operatori_economici SET attivo = 'S' WHERE codice = :codice",[":codice" => $codiceOE]); |
|
$codice_utente = $pdo->go("SELECT codice_utente FROM r_oe_utenti WHERE codice_operatore = :operatore",[":operatore"=>$codiceOE])->fetch(PDO::FETCH_COLUMN); |
|
if (!empty($codice_utente)) { |
|
$utente = Utente::getInfoFromID($codice_utente); |
|
if (!empty($utente)) { |
|
$tmp = array(); |
|
$tmp["codice"] = $utente["codice"]; |
|
$tmp["password_request"] = date("Y-m-d H:m:i"); |
|
$tmp["password_token"] = tokenGen(); |
|
$tmp["attivo"] = "S"; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_utenti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = $tmp; |
|
if ($salva->save() > 0) { |
|
|
|
$link_sito = $config["protocollo"] . $_SESSION["ente"]->getInfo()["dominio"]; |
|
$link = $link_sito . "/profilo/change_pwd.php?email=" . base64_encode($utente["email"]) . "&token=" . base64_encode($tmp["password_token"]); |
|
$link = "<a href='".$link."' target=\"_blank\" title=\"".__("Reset password")."\">".$link."</a>"; |
|
$corpo = str_replace("##--placeholder-link--##",$link,$_POST["messaggio"]); |
|
|
|
|
|
$mailer->oggetto = "Creazione utenza"; |
|
$mailer->corpo = $corpo; |
|
$mailer->codice_pec = -3; |
|
$mailer->comunicazione = false; |
|
$mailer->coda = true; |
|
$mailer->destinatari = $row["emailReferente"]; |
|
$esito = $mailer->send(); |
|
if (!$esito) { |
|
$errors[$i] = __("Errore invio email"); |
|
} |
|
} else { |
|
$errors[$i] = __("Errore generazione reset password"); |
|
} |
|
} else { |
|
$errors[$i] = __("Errore riconoscimento utente"); |
|
} |
|
} else { |
|
$errors[$i] = __("Errore riconoscimento relazione utente"); |
|
} |
|
} |
|
} |
|
} |
|
$error = false; |
|
if (empty($errors)) { |
|
?> |
|
swal({title:js_dict["success-msg"],type:"success"}).then(function(){ window.location.reload(); }); |
|
<? |
|
} else { |
|
$errors = json_encode($errors); |
|
$path = $config["mediaFolder"] . "/logs/import"; |
|
if (!is_dir($path)) { |
|
mkdir($path,0777,true); |
|
} |
|
file_put_contents($path."/".date("YmdHis").".json",$errors); |
|
?> |
|
swal({title:"<?= __("Si sono verificati degli errori, controllare log") ?>",type:"warning"}).then(function(){ window.location.reload(); }); |
|
<? |
|
} |
|
} |
|
} |
|
if ($error) { |
|
header('HTTP/1.0 403 Forbidden'); |
|
die(); |
|
} |
|
?>
|
|
|