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.
149 righe
6.8 KiB
149 righe
6.8 KiB
<? |
|
$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; |
|
include_once($configPath); |
|
$error = true; |
|
$id_modulo = "remoto"; |
|
$finale = false; |
|
if (isset($_POST["finale"])) { |
|
$finale = true; |
|
$id_modulo="contratto"; |
|
} |
|
$cmd_info = stipula::getInfoModulo($id_modulo); |
|
if (!empty($_SESSION["utente"]) && $_SESSION["utente"]->permission($cmd_info["modulo_riferimento"]) && $_SESSION["utente"]->permission($radice,$_POST["codice_contratto"],$id_modulo)) { |
|
$contratto = stipula::init($_POST["codice_contratto"]); |
|
if (!empty($contratto)) { |
|
$lock = $contratto->checkLock($cmd_info["id"]); |
|
if (!$lock) { |
|
if ($finale) { |
|
$numero_repertorio = $contratto->getExtraInfo()["numero_repertorio"] ?? ""; |
|
$data_stipula = mysql2date($contratto->info["data_stipula"]); |
|
$codice_sottoscrizione = 0; |
|
$check = $pdo->go("SELECT codice FROM b_contratti_sottoscritti WHERE codice_contratto = :codice_contratto AND codice_firmatario = 0 ORDER BY codice DESC",[":codice_contratto"=>$contratto->info["codice"]]); |
|
if ($check->rowCount() > 1) { |
|
$codice_sottoscrizione = $check->fetch(PDO::FETCH_ASSOC)["codice"]; |
|
} |
|
} else { |
|
unset($codice_sottoscrizione); |
|
} |
|
if (isset($_POST["numero_repertorio"])) { |
|
$numero_repertorio = $_POST["numero_repertorio"]; |
|
} |
|
if (isset($_POST["data_stipula"])) { |
|
$data_stipula = $_POST["data_stipula"]; |
|
} |
|
$error = false; |
|
if (isset($numero_repertorio) && !empty($data_stipula)) { |
|
$sottoscrizioni = $contratto->getContrattoSottoscritto(); |
|
if (count($sottoscrizioni) <= 1 || $finale) { |
|
if (strpos($_POST["filechunk"], "../")===false) { |
|
$chunkPath = $config["chunk_folder"]."/".$_SESSION["utente"]->codice."/".$_POST["filechunk"]; |
|
$p7m = new P7Manager($chunkPath); |
|
if ($p7m !== false) { |
|
$signed = false; |
|
if ($p7m->checkSignatures() || ($finale && $id_modulo == "contratto")) { |
|
$signed = true; |
|
$contratto->saveExtraInfo("sottoscritto",true); |
|
} |
|
if ($signed || !$finale) { |
|
$contratto->saveExtraInfo("numero_repertorio",$numero_repertorio); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$contratto->info["codice"],"data_stipula"=>$data_stipula]; |
|
$salva->save(); |
|
$contrattoSottoscritto = array(); |
|
if (isset($codice_sottoscrizione)) { |
|
$contrattoSottoscritto["codice"] = $codice_sottoscrizione; |
|
} else { |
|
if (!empty($sottoscrizioni[0])) { |
|
$contrattoSottoscritto["codice"] = $sottoscrizioni[0]["codice"]; |
|
} |
|
} |
|
|
|
$crypt = generateStrongPassword(); |
|
$encrypted_content = simple_encrypt($p7m->fileContent, $crypt); |
|
|
|
$path = "{$config["mediaFolder"]}/{$_SESSION["ente"]->codice}/contratti-signed/{$contratto->info["codice"]}"; |
|
if(! is_dir($path)) { mkdir($path, 0755, 1); } |
|
|
|
$filepath = "{$path}/" . md5($crypt) . $p7m->getHash("sha1"); |
|
|
|
$contrattoSottoscritto["codice_contratto"] = $contratto->info["codice"]; |
|
$contrattoSottoscritto["codice_firmatario"] = 0; |
|
$contrattoSottoscritto["md5"] = $p7m->getHash("md5"); |
|
$contrattoSottoscritto["sha1"] = $p7m->getHash("sha1"); |
|
$contrattoSottoscritto["sha256"] = $p7m->getHash("sha256"); |
|
$contrattoSottoscritto["content"] = $crypt; |
|
$contrattoSottoscritto["utente_creazione"] = $_SESSION["utente"]->codice; |
|
$contrattoSottoscritto["timestamp_creazione"] = date('Y-m-d H:i:s'); |
|
$fileMime = getTypeAndExtension($chunkPath); |
|
$contrattoSottoscritto["mime"] = $fileMime["type"]; |
|
$contrattoSottoscritto["name"] = sanitize_string($_POST["filechunk"]); |
|
if (! empty($encrypted_content) && file_put_contents($filepath, $encrypted_content)) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
$salva->nome_tabella = "b_contratti_sottoscritti"; |
|
$salva->operazione = (empty($contrattoSottoscritto["codice"])) ? "INSERT" : "UPDATE"; |
|
$salva->oggetto = $contrattoSottoscritto; |
|
$codice_contratto = $salva->save(); |
|
if ($codice_contratto > 0) { |
|
$url = "remoto"; |
|
if ($finale) { |
|
$url = "contratto"; |
|
$contratto->updateStato("30"); |
|
|
|
stipula::updateBadges($contratto->info['codice']); |
|
} |
|
$url = "/backend/contratti/{$url}/index.php?codice={$contratto->info["codice"]}"; |
|
?> |
|
swal({title:js_dict["success-msg"],type:"success"}).then(function(){ window.location.href = "<?= $url ?>"; }); |
|
<? |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nel salvataggio del contratto") ?>",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nel file content") ?>",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
if ($finale) { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nella firma digitale") ?>",type:"error"}); |
|
<? |
|
} else { |
|
$error = true; |
|
} |
|
} |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nella lettura del file") ?>",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nell'upload") ?>",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore nelle sottoscrizioni") ?>",type:"error"}); |
|
<? |
|
} |
|
} else { |
|
?> |
|
swal({title:js_dict.error,html:"<?= __("Errore negli estremi del contratto") ?>",type:"error"}); |
|
<? |
|
} |
|
} |
|
} |
|
} |
|
if ($error) { |
|
header('HTTP/1.0 403 Forbidden'); |
|
die(); |
|
} |
|
?>
|