gestione gare pubbliche
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.
 
 
 
 
 

631 righe
25 KiB

<?
class busteOE {
public $tipologieBuste;
public $tableBuste;
public $tableEmendamenti;
public $tableSecretate;
public $partecipante;
public $modalPath;
public $variables;
private $raggruppamento;
private $avvalimento;
public $modulo;
public $revoca;
public $raggruppamentoPossibile;
public $avvalimentoPossibile;
public $formPossibile;
public $modalitaFirmaForm;
public $richiestaFirmaFormCumulativa;
public $obj;
public $submit;
public $amend;
public $errori;
public $criptazione;
private $buste;
private $db;
private $config;
public $deletable;
private function configurazioneModuli() {
return [
"gare" => [
"tableBuste" => "b_gare_buste",
"tableEmendamenti" => "b_gare_emendamenti",
"tableSecretate" => "b_gare_buste_secretate",
"tipologiaBuste" => gara::tipologieBusta($this->obj->round["pubblicazione"] ?? ""),
"revoca" => true
],
"albo_fornitori" => [
"tipologiaBuste" => [
"" => [
"titolo" => "Documenti Richiesti"
]
],
"revoca" => false
],
"albi_commissione" => [
"tipologiaBuste" => [
"" => [
"titolo" => "Documenti Richiesti"
]
],
"revoca" => false
]
];
if (class_exists("pcp")) {
$return["pcp"] = [
"tableBuste" => "b_pcp_buste",
"tipologiaBuste" => pcp::tipologieBusta(),
"revoca" => true
];
}
if (class_exists("concorso")) {
$return["concorsi"] = [
"tableBuste" => "b_concorsi_buste",
"tipologiaBuste" => concorso::tipologieBusta(),
"revoca" => true
];
}
}
private function messaggiConfermaInvio() {
return [
"bustaConRevoca" => "Caricando il documento sostituirai eventuali caricamenti precedenti e revocherai la partecipazione già confermata",
"bustaSenzaRevoca" => "Caricando il documento sostituirai eventuali caricamenti precedenti"
];
}
public function __construct() {
$this->errori = [];
$this->buste = [];
$this->partecipante = null;
$this->raggruppamento = [];
$this->avvalimento = [];
$this->raggruppamentoPossibile = true;
$this->avvalimentoPossibile = true;
$this->formPossibile = true;
$this->modalitaFirmaForm = "busta";
$this->richiestaFirmaFormCumulativa = false;
$this->criptazione = true;
$this->amend = false;
$this->deletable = false;
global $pdo;
global $config;
$this->db = $pdo;
$this->config = $config;
}
public function printPanel() {
$this->defineBuste();
include __DIR__ . "/views/panel.php";
}
private function insertUploadForm($richiesta,$secretabile,$_uploadAction,$_uploadId = "main") {
include __DIR__ . "/views/partials/upload-form.php";
}
public function printManage($codice_richiesta) {
$richiesta = $this->getRichiesta($codice_richiesta);
if (!empty($richiesta)) {
$emendabile = false;
$partecipante = $this->partecipante;
$idMsg = $idMsgDefault = "bustaConRevoca";
if (!$this->revoca) {
$idMsg = "bustaSenzaRevoca";
}
$msgConfermaBusta = $this->messaggiConfermaInvio()[$idMsg] ?? $this->messaggiConfermaInvio()[$idMsgDefault];
if (!empty($partecipante)) {
$content = $this->obj->getBusta($partecipante["codice"],$richiesta["codice"],false);
if (method_exists($this->obj,"getBustaSecretata") && !empty($content) && $content["segreta"] == "S") {
$secretata = $this->obj->getBustaSecretata($partecipante["codice"],$richiesta["codice"],"busta",false);
}
}
if (!$this->submit && method_exists($this->obj,"getEmendamento")) {
$emendamento = $this->obj->getEmendamento($partecipante["codice"],$richiesta["codice"],false);
if (method_exists($this->obj,"getBustaSecretata") && !empty($emendamento) && $emendamento["segreta"] == "S") {
$emendamentoSecretato = $this->obj->getBustaSecretata($partecipante["codice"],$richiesta["codice"],"emendamento",false);
}
$emendabile = $this->emendabile($richiesta["codice"]);
}
$secretabile = $this->secretabile($richiesta["codice"]);
$upload = false;
if ($this->submit) {
$upload = true;
if ($richiesta["locked"] == "S") {
$upload = false;
if (!empty($partecipante)) {
if ($this->modalitaFirmaForm == "busta") {
if (isset($richiesta["busta"])) {
$upload = (!empty($this->obj->checkFormFill($richiesta["busta"]))) ? true : false;
}
} else if ($this->modalitaFirmaForm == "cumulativa") {
$erroriForm = [];
$upload = (!empty($this->obj->checkFormFill($erroriForm))) ? true : false;
if (isset($erroriForm[404])) {
$generaFormCumulativo = true;
}
}
}
}
}
include_once __DIR__ . "/views/manage.php";
return true;
}
}
public function emendabile($codice_richiesta) {
if ($this->amend) {
$richiesta = $this->getRichiesta($codice_richiesta);
if (!empty($richiesta) && $richiesta["locked"] == "N" && !empty($this->tipologieBuste[$richiesta["busta"]]["emendabile"]) && !empty($this->obj->getBusta($this->partecipante["codice"],$richiesta["codice"],false))) {
return true;
}
}
return false;
}
public function secretabile($codice_richiesta,$checkBustaPresentata = false) {
if (method_exists($this->obj,"abilitaBusteSecretate") && $this->obj->abilitaBusteSecretate()) {
$richiesta = $this->getRichiesta($codice_richiesta);
if (!empty($richiesta) && $richiesta["locked"] == "N" && !empty($this->tipologieBuste[$richiesta["busta"]]["secretabile"])) {
if ($this->submit) {
if ($checkBustaPresentata) {
if (!empty($this->partecipante)) {
$busta = $this->obj->getBusta($this->partecipante["codice"],$richiesta["codice"],false);
if (isset($busta["segreta"]) && $busta["segreta"] == "S") {
return true;
}
}
} else {
return true;
}
} else if (!$this->submit && method_exists($this->obj,"getEmendamento")) {
if ($checkBustaPresentata) {
if (!empty($this->partecipante)) {
$busta = $this->obj->getEmendamento($this->partecipante["codice"],$richiesta["codice"],false);
if (isset($busta["segreta"]) && $busta["segreta"] == "S" && $this->amend) {
return true;
}
}
} else {
return true;
}
}
}
}
return false;
}
public function defineBuste() {
foreach ($this->tipologieBuste as $id_busta => $busta) {
$tmp = $this->obj->getRichieste($id_busta);
if (!empty($tmp)) {
$this->buste[$id_busta] = ["info" => $busta, "richieste" => $tmp];
}
}
}
public function checkDocumentiMinimi($boolean = true) {
$return = false;
if (!empty($this->partecipante)) {
if (empty($this->buste)) {
$this->defineBuste();
}
if (!empty($this->buste)) {
$obbligatori = 0;
$presenti = 0;
$mancanti = [];
foreach ($this->buste as $busta) {
foreach ($busta["richieste"] as $input) {
$busta = $this->obj->getBusta($this->partecipante["codice"], $input["codice"]);
if ($input["controllo"] != "N" || (isset($busta["segreta"]) && $busta["segreta"] == "S")) {
$obbligatori++;
if (!empty($busta)) {
if (isset($busta["segreta"]) && $busta["segreta"] == "S") {
if (!empty($this->obj->getBustaSecretata($this->partecipante["codice"],$input["codice"],"busta"))) {
$presenti++;
} else {
$input["segreto"] = true;
$mancanti[] = $input;
}
} else {
$presenti++;
}
} else {
$mancanti[] = $input;
}
}
}
}
if ($boolean) {
$return = ($obbligatori === $presenti);
} else {
$return = $mancanti;
}
}
}
return $return;
}
private function getQueryString() {
return http_build_query($this->variables);
}
private function getRichiesta($id) {
$richieste = $this->obj->getRichieste();
if (!empty($richieste)) {
foreach($richieste as $tmp) {
if ($tmp["codice"] == $id) {
return $tmp;
}
}
}
}
private function printHiddenInputs() {
foreach($this->variables AS $key => $value) {
echo "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\">" . PHP_EOL;
}
}
public function check() {
$return = false;
if (empty($this->modulo)) {
$this->errori[] = "Modulo non definito";
} else {
$settings = $this->configurazioneModuli()[$this->modulo] ?? null;
if (empty($settings)) {
$this->errori[] = "Modulo non previsto";
} else {
if (empty($this->tipologieBuste)) {
$this->tipologieBuste = $settings["tipologiaBuste"] ?? null;
}
if (empty($this->tableBuste)) {
$this->tableBuste = $settings["tableBuste"];
}
if (empty($this->tableEmendamenti) && !empty($settings["tableEmendamenti"])) {
$this->tableEmendamenti = $settings["tableEmendamenti"];
}
if (empty($this->tableSecretate) && !empty($settings["tableSecretate"])) {
$this->tableSecretate = $settings["tableSecretate"];
}
}
}
if (empty($this->tipologieBuste)) {
$this->errori[] = "Tipologie di buste non definite";
}
$this->revoca = $settings["revoca"] ?? true;
if (empty($this->tableBuste)) {
$this->errori[] = "Tabella non definita";
}
if (empty($this->variables)) {
$this->errori[] = "Variabili di controllo non definite";
} else {
$this->modalPath = "manage.php?" . $this->getQueryString() . "&codice_richiesta=";
}
if (empty($this->obj)) {
$this->errori[] = "Istanza di riferimento non definita";
} else {
if (!method_exists($this->obj,"getRichieste")) {
$this->errori[] = "Metodo getRichieste non previsto dall'istanza";
}
if (!method_exists($this->obj,"getBusta")) {
$this->errori[] = "Metodo getBusta non previsto dall'istanza";
}
if (!method_exists($this->obj,"miaPartecipazione")) {
$this->errori[] = "Metodo miaPartecipazione non previsto dall'istanza";
}
if (!method_exists($this->obj,"getRaggruppamento") && $this->raggruppamentoPossibile) {
$this->errori[] = "Metodo getRaggruppamento non previsto dall'istanza";
}
if (!method_exists($this->obj,"getAvvalimento") && $this->avvalimentoPossibile) {
$this->errori[] = "Metodo getAvvalimento non previsto dall'istanza";
}
if (!method_exists($this->obj,"checkFormFill") && $this->formPossibile) {
$this->errori[] = "Metodo checkFormFill non previsto dall'istanza";
}
if (!method_exists($this->obj,"revoca") && $this->revoca) {
$this->errori[] = "Metodo revoca non previsto dall'istanza";
}
if (!method_exists($this->obj,"savePartecipante")) {
$this->errori[] = "Metodo savePartecipante non previsto dall'istanza";
}
if (!method_exists($this->obj,"getBustePath")) {
$this->errori[] = "Metodo getBustePath non previsto dall'istanza";
}
if (!method_exists($this->obj,"getSpecificBustaPath")) {
$this->errori[] = "Metodo getSpecificBustaPath non previsto dall'istanza";
}
if (!method_exists($this->obj,"deleteBusta")) {
$this->errori[] = "Metodo deleteBusta non previsto dall'istanza";
}
if (!empty($this->tableEmendamenti) && !method_exists($this->obj,"deleteEmendamento")) {
$this->errori[] = "Metodo deleteEmendamento non previsto dall'istanza";
}
if (!empty($this->tableEmendamenti) && !method_exists($this->obj,"deleteSecretate")) {
$this->errori[] = "Metodo deleteSecretate non previsto dall'istanza";
}
}
if (empty($this->modalPath)) {
$this->errori[] = "Percorso gestione richiesta non definito";
}
if (empty($this->errori)) {
$this->partecipante = $this->obj->miaPartecipazione();
if (!empty($this->partecipante)) {
if ($this->raggruppamentoPossibile) {
$this->raggruppamento = $this->obj->getRaggruppamento($this->partecipante["codice"]);
}
if ($this->avvalimentoPossibile) {
$this->avvalimento = $this->obj->getAvvalimento($this->partecipante["codice"]);
}
}
return true;
}
}
private function saveFile($post,$richiesta,$type,$otherInfo = null) {
$return = ["esito" => false, "feedback" => "Errore configurazione"];
$check_hash = false;
$offerta = null;
$extraInfoBusta = [];
if ($type == "busta") {
$rifTable = $this->tableBuste;
$deleteMethod = "deleteBusta";
$check_hash = $otherInfo["check_hash"] ?? false;
$offerta = $otherInfo["offerta"] ?? null;
$sessionKey = "{$this->modulo}documents";
$pathMethod = "getBustePath";
$specificPathMethod = "getSpecificBustaPath";
$extraInfoBusta["segreta"] = $post["segreta"] ?? "N";
} else if ($type == "emendamento") {
$rifTable = $this->tableEmendamenti;
$deleteMethod = "deleteEmendamento";
$sessionKey = "{$this->modulo}amends";
$pathMethod = "getEmendamentoPath";
$specificPathMethod = "getSpecificEmendamentoPath";
$extraInfoBusta["accettata"] = "W";
$extraInfoBusta["segreta"] = $post["segreta"] ?? "N";
if (!empty($post["salt"])) {
$extraInfoBusta["descrizione"] = simple_encrypt($post["descrizione"],$post["salt"]);
} else {
$extraInfoBusta["descrizione"] = $post["descrizione"];
}
} else if ($type == "secretata") {
$rifTable = $this->tableSecretate;
$deleteMethod = "deleteSecretate";
$sessionKey = "{$this->modulo}secrets";
$pathMethod = "getSecretatePath";
$specificPathMethod = "getSpecificSecretatePath";
$extraInfoBusta["accettata"] = "W";
$extraInfoBusta["derivazione"] = $otherInfo["derivazione"] ?? "busta";
if (!empty($post["salt"])) {
$extraInfoBusta["descrizione"] = simple_encrypt($post["descrizione"],$post["salt"]);
} else {
$extraInfoBusta["descrizione"] = $post["descrizione"];
}
}
if (!empty($rifTable) && !empty($pathMethod) && !empty($specificPathMethod) && !empty($deleteMethod)) {
if (!empty($post["salt"]) || !$this->criptazione) {
$salt = "";
$continua = true;
if (!empty($post["salt"])) {
$continua = false;
$salt = $post["salt"];
$public = openssl_pkey_get_public(trim($this->obj->info["public_key"]));
if (openssl_public_encrypt($salt,$encryptedSalt,$public)) {
$continua = true;
}
}
if ($continua) {
if (!empty($deleteMethod)) {
$this->obj->$deleteMethod($richiesta["codice"]);
}
if (strpos($post["filechunk"], "../")===false) {
$chunkPath = $this->config["chunk_folder"]."/".$_SESSION["utente"]->codice."/".$post["filechunk"];
$p7m = new P7Manager($chunkPath);
if ($p7m !== false) {
if ($richiesta["controllo"] == "F") {
$signed = true;
$esito = $p7m->checkSignatures();
} else {
$signed = false;
$esito = true;
}
if ($esito) {
if (!$check_hash || !empty($offerta)) {
$found = true;
if (!empty($offerta)) {
$hashVerify = array();
if ($offerta["md5"] != "") { $hashVerify[] = $p7m->find($offerta["md5"],"md5",$signed); }
if ($offerta["sha1"] != "") { $hashVerify[] = $p7m->find($offerta["sha1"],"sha1",$signed); }
if ($offerta["sha256"] != "") { $hashVerify[] = $p7m->find($offerta["sha256"],"sha256",$signed); }
$found = false;
if (!empty($hashVerify) && in_array(false,$hashVerify)!==false) {
if ($p7m->find($offerta["shaContent"],"sha256",$signed,true)) {
$found = true;
}
} else {
$found = true;
}
}
if ($found) {
$busta = array();
$busta["codice_richiesta"] = $richiesta["codice"];
$busta["codice_partecipante"] = $this->partecipante["codice"];
$busta["md5"] = $p7m->getHash("md5");
$busta["sha1"] = $p7m->getHash("sha1");
$busta["sha256"] = $p7m->getHash("sha256");
$busta["content"] = generateStrongPassword();
$_SESSION[$sessionKey][$this->partecipante["codice"]][$richiesta["codice"]] = $salt;
if (!empty($encryptedSalt)) {
$busta["salt"] = $encryptedSalt;
$content = $p7m->encrypt($salt);
$busta["open"] = "N";
} else {
$content = simple_encrypt($p7m->fileContent,$busta["content"]);
$busta["open"] = "S";
}
$fileMime = getTypeAndExtension($chunkPath);
$busta["content"] = base64_encode($busta["content"]);
$busta["mime"] = $fileMime["type"];
$busta["nomeFile"] = sanitize_string($post["filechunk"]);
if (!empty($extraInfoBusta)) {
foreach($extraInfoBusta AS $key => $value) {
$busta[$key] = $value;
}
}
if (!empty($content)) {
$path = $this->obj->$pathMethod($this->partecipante["codice"]);
if (is_dir($path)) {
if (file_put_contents($this->obj->$specificPathMethod($busta),$content)) {
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $rifTable;
$salva->operazione = "INSERT";
$salva->oggetto = $busta;
$codice_busta = $salva->save();
if ($codice_busta > 0) {
$return["esito"] = true;
$return["feedback"] = $busta["sha256"];
} else {
$return["feedback"] = "Errore salvataggio busta";
}
} else {
$return["feedback"] = "Errore creazione file";
}
} else {
$return["feedback"] = "Errore creazione cartella";
}
} else {
$return["feedback"] = "Errore contenuto file";
}
} else {
$return["feedback"] = "Il file caricato non corrisponde a quello generato dal sistema";
}
} else {
$return["feedback"] = "File di offerta non generato";
}
} else {
$return["feedback"] = "Firma digitale non valida";
}
} else {
$return["feedback"] = "Errore nell'inizializzazione della classe di verifica";
}
if (file_exists($chunkPath)) {
unlink($chunkPath);
}
} else {
$return["feedback"] = "Errore di sicurezza nell'file selezionato";
}
} else {
$return["feedback"] = "Errore nella criptazione";
}
} else {
$return["feedback"] = "Errore nella richiesta";
}
} else {
$return["feedback"] = "Errore configurazione";
}
return $return;
}
public function saveBusta($post) {
$return = ["esito" => false, "feedback" => "Errore validazione"];
if ($this->check()) {
if ($this->submit) {
$richiesta = $this->getRichiesta($post["codice_richiesta"]);
if (!empty($richiesta)) {
if (!empty($this->partecipante)) {
if ($this->partecipante["conferma"] == "S" && $this->revoca) {
if ($this->obj->revoca() !== false) {
$this->partecipante = $this->obj->miaPartecipazione();
} else {
$this->partecipante = null;
}
}
} else {
$this->partecipante = $this->obj->savePartecipante();
}
if (!empty($this->partecipante)) {
$continue = true;
$check_hash = false;
if ($richiesta["locked"] == "S") {
if ($this->modalitaFirmaForm == "busta") {
if (isset($richiesta["busta"])) {
$offerta = $this->obj->checkFormFill($richiesta["busta"]);
$continue = (!empty($offerta));
if ($richiesta["controllo"] == "F") {
$check_hash = true;
}
}
} else if ($this->modalitaFirmaForm == "cumulativa") {
$offerta = $this->obj->checkFormFill();
$continue = (!empty($offerta));
if ($this->richiestaFirmaFormCumulativa) {
$check_hash = true;
}
}
}
if ($continue) {
$return = $this->saveFile($post,$richiesta,"busta",["check_hash"=>$check_hash,"offerta"=>$offerta ?? null]);
} else {
$return["feedback"] = "Impossibile continuare, controllare generazione documento";
}
} else {
$return["feedback"] = "Errore nell'identificazione del partecipante";
}
} else {
$return["feedback"] = "Errore nella selezione della richiesta";
}
} else {
$return["feedback"] = "Partecipazione non attiva";
}
} else {
$return["feedback"] = implode("<br>",$this->errori);
}
return $return;
}
public function saveBustaSecretata($post) {
$return = ["esito" => false, "feedback" => "Errore validazione"];
if ($this->check()) {
if ($this->submit && !empty($this->partecipante) && $this->partecipante["conferma"] == "S") {
if ($this->obj->revoca() !== false) {
$this->partecipante = $this->obj->miaPartecipazione();
}
}
$richiesta = $this->getRichiesta($post["codice_richiesta"]);
if (!empty($richiesta) && $this->secretabile($richiesta["codice"],true)) {
$return = $this->saveFile($post,$richiesta,"secretata",["derivazione"=>($this->submit) ? "busta":"emendamento"]);
} else {
$return["feedback"] = "Errore nella selezione della richiesta";
}
} else {
$return["feedback"] = implode("<br>",$this->errori);
}
return $return;
}
public function saveEmendamento($post) {
$return = ["esito" => false, "feedback" => "Errore validazione"];
if ($this->check()) {
if ($this->amend && $this->emendabile($post["codice_richiesta"])) {
$richiesta = $this->getRichiesta($post["codice_richiesta"]);
if (!empty($richiesta) && !empty($this->partecipante)) {
$return = $this->saveFile($post,$richiesta,"emendamento");
} else {
$return["feedback"] = "Errore nell'identificazione del partecipante";
}
} else {
$return["feedback"] = "Errore nella selezione della richiesta";
}
} else {
$return["feedback"] = implode("<br>",$this->errori);
}
return $return;
}
}
?>