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.
 
 
 
 
 

1217 righe
46 KiB

<?
class publicElenchi extends Elenchi
{
public $potentialAction; // serve ad identificare se l'utente che ha istanziato l'oggetto può interagire con la gara
public $richiestaFirmaFormCumulativa;
private $managerPartecipazione;
public const VALID_API_FILTERS = [
"soa" => "SOA",
"cpv" => "CPV",
"servizioTecnico" => "Servizi tecnici"
];
public const VALID_API_SORT_BY = [
"codice_fiscale_impresa" => "Codice Fiscale",
"ragione_sociale" => "Ragione sociale",
"pec" => "PEC",
];
public static function API_getAlbi(?int $codice = 0) {
global $pdo;
$table = static::getMainTable();
$query = "SELECT codice, tipologia, oggetto, descrizione, pubblicazione FROM {$table} WHERE api_access_level > 0";
$bind = [];
if($codice > 0) {
$query .= " AND codice = :codice";
$bind[":codice"] = $codice;
}
$data = $pdo->go($query, $bind)->fetchAll(PDO::FETCH_ASSOC);
return empty($data) ? [] : $data;
}
public static function API_getFiltriAlbo(int $codice) {
global $pdo;
$table = static::getMainTable();
$data = $pdo->go("SELECT codice, extraInfo FROM {$table} WHERE api_access_level > 0 AND codice = :codice", [":codice" => $codice])->fetch(PDO::FETCH_ASSOC);
if(empty($data)) {
return false;
}
$filters = json_decode($data["extraInfo"], true) ?? [];
$filters = $filters["api_access_filters"] ?? [];
foreach(self::VALID_API_FILTERS as $filter => $_) {
$retval[$filter]["available"] = in_array($filter, $filters);
}
$retval["search"] = ["available" => true];
return $retval;
}
public static function API_getPartecipantiAlbo(int $codice, array $filters, array $sortBy, array $limit) {
$return = array();
$availableFilters = static::API_getFiltriAlbo($codice);
if($availableFilters === false)
return false;
$filterKeys = array_keys($filters);
foreach($filterKeys as $key) {
$available = $availableFilters[$key]["available"] ?? false;
if(!$available) {
unset($filters[$key]);
} else {
if(is_array($filters[$key]) && isset($filters[$key]["value"])) {
$filters[$key] = $filters[$key]["value"];
}
}
}
$oeManager = new oeManager();
$tabella_elenco = static::getMainTable();
$filters["elenco"] = "{$tabella_elenco}|{$codice}";
if (!empty($filters["search"])) {
$oeManager->generalFilter = $filters["search"];
unset($filters["search"]);
}
$oeManager->setFilters($filters);
$partecipanti = $oeManager->getOERelations($_SESSION["ente"]->codice);
if(empty($partecipanti)) {
$return["data"] = [];
$return["recordsTotal"] = 0;
return $return;
}
$return["recordsTotal"] = count($partecipanti);
$partecipanti = array_column($partecipanti, "codice_operatore");
$partecipanti = oeManager::getOE($partecipanti);
$orderKey = isset(self::VALID_API_SORT_BY[$sortBy["column"] ?? ""]) ? $sortBy["column"] : null;
$orderDir = ($sortBy["dir"] ?? "asc") == "desc";
if($orderKey) {
usort($partecipanti, function($a, $b) use ($orderKey, $orderDir) {
return $orderDir ? ($a[$orderKey] < $b[$orderKey]) : ($a[$orderKey] > $b[$orderKey]);
});
}
$limitStart = isset($limit["start"]) ? intval($limit["start"]) : 0;
$limitCount = isset($limit["limit"]) ? intval($limit["limit"]) : 0;
if($limitCount > 0) {
$partecipanti = array_slice($partecipanti, $limitStart, $limitCount);
}
$i = intval($limitStart) + 1;
foreach ($partecipanti as $record) {
$row = [];
$row[] = $i++;
$row[] = $record["codice_fiscale_impresa"];
$row[] = $record["ragione_sociale"];
$row[] = $record["pec"];
$return["data"][] = $row;
}
return $return;
}
private function __construct()
{
global $pdo;
$this->db = $pdo;
$this->directory = static::getDirectory();
$this->mainTable = static::getMainTable();
$this->oeTable = static::getOeTable();
$this->cpvTable = static::getCpvTable();
$this->richiesteTable = static::getRichiesteTable();
$this->formTable = static::getFormTable();
$this->chiarimentiTable = static::getChiarimentiTable();
$this->sopralluogoTable = static::getSopralluogoTable();
$this->busteTable = static::getBusteTable();
$this->modulo = static::getModulo();
$this->managerPartecipazione = null;
}
public static function getDataTableJSON($input)
{
$mainTable = static::getMainTable();
$enti = $_SESSION["ente"]->entiBeneficiari();
$return = array();
$return["draw"] = (int)$input["draw"];
$return["recordsTotal"] = (int)0;
$return["recordsFiltered"] = (int)0;
$filters = [];
if (isset($input["stato"]) && $input["stato"]!=="") {
$filters["{$mainTable}.stato"] = $input["stato"];
}
if (isset($input["tipologia"]) && $input["tipologia"]!=="") {
$filters["{$mainTable}.tipologia"] = $input["tipologia"];
}
$total = static::getList($filters,[],0,-1);
if (!empty($total)) {
$return["recordsTotal"] = (int)count($total);
if (!empty($input["search"]["value"])) {
$filters["*"] = $input["search"]["value"];
}
if (isset($input["ente"]) && $input["ente"]!=="") {
$filters["{$mainTable}.codice_ente"] = $input["ente"];
}
$order = [];
$orderKey = "{$mainTable}.id";
switch($input["order"][0]["column"]) {
case "2": $orderKey = "{$mainTable}.id"; break;
case "3": $orderKey = "{$mainTable}.oggetto"; break;
case "4": $orderKey = "{$mainTable}.pubblicazione"; break;
case "5": $orderKey = "{$mainTable}.tipologia"; break;
}
if ($input["order"][0]["dir"] == "desc") {
$order[$orderKey] = "DESC";
} else {
$order[$orderKey] = "ASC";
}
$risultati = static::getList($filters,$order,$input["start"],$input["length"]);
global $pdo;
$update_scadute = $pdo->prepare("UPDATE {$mainTable} SET stato = 21 WHERE codice = :codice AND stato = 20");
if (count($risultati) > 0) {
if (!empty($input["search"]["value"])) {
$return["recordsFiltered"] = (int)count($risultati);
} else {
$return["recordsFiltered"] = $return["recordsTotal"];
}
$return["data"] = array();
$stati = static::getStati();
foreach($risultati AS $record) {
if (!empty($record["scadenza"]) && strtotime($record["scadenza"]) < time() && $record["stato"] == 20) {
$update_scadute->execute([":codice"=>$record["codice"]]);
$record["stato"] = 21;
}
$stato = $stati[$record["stato"]];
$path = "/".static::getModulo()."/dettaglio.php?codice={$record["codice"]}";
$row = array();
$row[] = '<div id="flag_'.$record["codice"].'" class="status_flag" style="background-color:'.$stato["color"].'"></div>';
$row[] = __($stato["titolo"]);
$row[] = $record["id"];
$row[] = "<a href='{$path}' title='".__("dettagli")."'><strong>" . $record["oggetto"] . "</strong></a>";
$row[] = mysql2date($record["pubblicazione"]);
if (method_exists(get_called_class(),"getTipologie") && !empty($input["stato"]) && !is_numeric($input["stato"])) {
$row[] = __(static::getTipologie()[$record["tipologia"]]);
}
if (count($enti) > 1) {
$row[] = $enti[$record["codice_ente"]]["denominazione"] ?? "";
}
$row[] = "<a href='{$path}' title='".__("dettagli")."' class='btn btn-info btn-sm'><span class='fa fa-search'></span><span class='sr-only'>" . __("Dettagli") . "</span></a>";
$return["data"][] = $row;
}
} else {
$return["data"] = array();
}
} else {
$return["data"] = array();
}
return $return;
}
public static function getRefPartecipante() {
if (static::refPartecipante() == "operatore") {
return $_SESSION["utente"]->oe["codice"] ?? null;
} else {
return $_SESSION["utente"]->codice ?? null;
}
}
public static function getList($filters=[],$order=[],$start=0,$length=1) {
global $pdo;
$mainTable = static::getMainTable();
$oeTable = static::getOeTable();
$refPartecipante = static::getRefPartecipante();
$bind = [];
$select = "SELECT {$mainTable}.codice, {$mainTable}.codice_ente, {$mainTable}.id, {$mainTable}.stato, {$mainTable}.oggetto, {$mainTable}.tipologia,
{$mainTable}.pubblicazione, {$mainTable}.chiarimenti, {$mainTable}.scadenza";
$from = " FROM {$mainTable} ";
$where = " WHERE (({$mainTable}.pubblica = 2 AND {$mainTable}.pubblicazione <= now()) ";
if (isset($_SESSION["utente"])) {
$where .= " OR ({$mainTable}.pubblica = 1 AND {$mainTable}.pubblicazione <= now()) ";
}
$where .= ")";
if (!empty($filters)) {
$keys = ["{$mainTable}.id","{$mainTable}.oggetto","{$mainTable}.descrizione","{$mainTable}.tipologia"];
$addWhere = [];
foreach($keys AS $key) {
if (isset($filters[$key]) || isset($filters["*"])) {
$value = $filters[$key] ?? $filters["*"];
if (!is_array($value)) {
$value = [$value];
}
foreach($value AS $v) {
$sudd = suddivisione_pdo($v,$key);
if (!empty($sudd)) {
$bind = $bind + $sudd["bind"];
$addWhere[] = $sudd["sql"];
}
}
}
}
if (count($addWhere) > 0) { $where .= " AND (" . implode(" OR ",$addWhere) . ") "; }
if (isset($filters["{$mainTable}.codice_ente"])) {
$bind[":codice_ente"] = (int)$filters["{$mainTable}.codice_ente"];
$where .= " AND {$mainTable}.codice_ente = :codice_ente ";
}
if (isset($filters["{$mainTable}.stato"])) {
if (is_numeric($filters["{$mainTable}.stato"])) {
$bind[":stato"] = (int)$filters["{$mainTable}.stato"];
$where .= " AND {$mainTable}.stato = :stato ";
} else if (!empty($refPartecipante)) {
$stato = $filters["{$mainTable}.stato"];
if ($stato == "bozza") {
$bind[":operatore"] = $refPartecipante;
$from .= " JOIN {$oeTable} ON {$mainTable}.codice = {$oeTable}.codice_elenco ";
$where .= " AND {$oeTable}.codice_operatore = :operatore AND ({$mainTable}.scadenza IS NULL OR {$mainTable}.scadenza > now()) AND {$oeTable}.conferma = 'N' ";
} else if ($stato == "valutazione") {
$bind[":operatore"] = $refPartecipante;
$from .= " JOIN {$oeTable} ON {$mainTable}.codice = {$oeTable}.codice_elenco ";
$where .= " AND {$oeTable}.codice_operatore = :operatore AND {$oeTable}.conferma = 'S' AND {$oeTable}.valutato = 'N' ";
} else if ($stato == "ammesso") {
$bind[":operatore"] = $refPartecipante;
$from .= " JOIN {$oeTable} ON {$mainTable}.codice = {$oeTable}.codice_elenco ";
$where .= " AND {$oeTable}.codice_operatore = :operatore AND {$oeTable}.ammesso = 'S' ";
} else if ($stato == "archivio") {
$bind[":operatore"] = $refPartecipante;
$from .= " JOIN {$oeTable} ON {$mainTable}.codice = {$oeTable}.codice_elenco ";
$where .= " AND {$oeTable}.codice_operatore = :operatore AND {$oeTable}.conferma = 'S' ";
}
} else {
return [];
}
}
if (isset($filters["{$mainTable}.codice"])) {
$bind[":codice"] = (int)$filters["{$mainTable}.codice"];
$where .= " AND {$mainTable}.codice = :codice ";
}
}
$sort = "ORDER BY {$mainTable}.id DESC ";
if (!empty($order)) {
$keys = ["{$mainTable}.id","{$mainTable}.stato","{$mainTable}.oggetto","{$mainTable}.pubblicazione","{$mainTable}.tipologia"];
$sortArray = [];
foreach($keys AS $key) {
if (isset($order[$key])) {
if (strcmp($order[$key],"ASC") === 0) {
$sortArray[] = "{$key} ASC";
} else {
$sortArray[] = "{$key} DESC";
}
}
}
if (!empty($sortArray) > 0) {
$sort = " ORDER BY " . implode(",",$sortArray);
}
}
$limit = "";
if (is_numeric($start) && is_numeric($length) && $length > 0) {
$start = (int)$start;
$length = (int)$length;
$limit = " LIMIT {$start}, {$length}";
}
return $pdo->go($select.$from.$where." GROUP BY {$mainTable}.codice ".$sort.$limit,$bind)->fetchAll(PDO::FETCH_ASSOC);
}
public static function initInstance($codice,$object) {
if (!empty($codice) && !empty($_SESSION["ente"])) {
$mainTable = static::getMainTable();
$check = self::getList($_SESSION["ente"]->codice,["{$mainTable}.codice"=>$codice]);
if (!empty($check) && count($check) == 1) {
global $pdo;
$bind = [":codice"=>$codice];
$sql = "SELECT * FROM {$mainTable} WHERE codice = :codice ";
$elenco = $pdo->go($sql,$bind)->fetch(PDO::FETCH_ASSOC);
if (!empty($elenco) && (!isset($elenco["pubblica"]) || $elenco["pubblica"] === "2" || ($elenco["pubblica"] === "1" && isset($_SESSION["utente"])))) {
$instance = new $object();
$instance->info = $elenco;
$instance->richiestaFirmaFormCumulativa = (isset($elenco["richiedi_firma"]) && $elenco["richiedi_firma"] == "S");
if (isset($_SESSION["utente"]) && $_SESSION["utente"]->gerarchia >= 100 && !empty($_SESSION["utente"]->oe)) {
$instance->potentialAction = true;
}
if (isset($instance->info) && $instance->info["stato"] == 20 && !empty($instance->info["scadenza"]) && strtotime($instance->info["scadenza"]) < time()) {
$instance->updateStato(21);
$record["stato"] = 21;
}
return $instance;
}
}
return false;
}
}
public function getFrontOfficePartecipantiJSON(array $input) {
if (isset($input["draw"])) {
$return = array();
$return["draw"] = (int)$input["draw"];
parse_str(str_replace("&amp;", "&", $input["filters"]), $user_filters);
$oeManager = new oeManager();
$tabella_elenco = static::getMainTable();
$user_filters["elenco"] = "{$tabella_elenco}|{$this->info['codice']}";
$oeManager->setFilters($user_filters);
if (!empty($input["search"]["value"])) {
$oeManager->generalFilter = $input["search"]["value"];
}
$partecipanti = $oeManager->getOERelations($_SESSION["ente"]->codice);
if(empty($partecipanti)) {
$return["data"] = [];
$return["recordsFiltered"] = $return["recordsTotal"] = 0;
$return["reason"] = "no-partecipanti";
return $return;
}
$return["recordsFiltered"] = $return["recordsTotal"] = count($partecipanti);
$partecipanti = array_column($partecipanti, "codice_operatore");
$partecipanti = oeManager::getOE($partecipanti);
$orderKey = null;
switch ($input["order"][0]["column"]) {
case "1":
$orderKey = "codice_fiscale_impresa";
break;
case "2":
$orderKey = "ragione_sociale";
break;
}
if($orderKey) {
if ($input["order"][0]["dir"] == "desc") {
usort($partecipanti, function($a, $b) use ($orderKey) {
return $a[$orderKey] > $b[$orderKey];
});
} else {
usort($partecipanti, function($a, $b) use ($orderKey) {
return $a[$orderKey] < $b[$orderKey];
});
}
}
$partecipanti = array_slice($partecipanti, $_POST["start"], $_POST["length"]);
$i = intval($_POST["start"]) + 1;
foreach ($partecipanti as $record) {
$row = [];
$row[] = $i++;
$row[] = $record["codice_fiscale_impresa"];
$row[] = $record["ragione_sociale"];
$return["data"][] = $row;
}
return $return;
}
$return = [];
$return["data"] = [];
$return["recordsFiltered"] = $return["recordsTotal"] = 0;
$return["reason"] = "no-draw";
return $return;
}
public function getRichieste()
{
$tmp = parent::getRichieste();
$return = [];
if (!empty($tmp)) {
foreach($tmp AS $ric) {
if (!isset($ric["archiviato"]) || $ric["archiviato"] == "N") {
$return[] =$ric;
}
}
}
return $return;
}
public function getChiarimenti($codice = NULL) {
$tmp = parent::getChiarimenti($codice);
$chiarimenti = [];
$codice_oe = $_SESSION["utente"]->oe["codice"] ?? null;
foreach($tmp AS $chiarimento) {
if ($codice_oe == $chiarimento["codice_richiedente"] || (!empty($chiarimento["risposta"]) && $chiarimento["attivo"] == "S")) {
$chiarimenti[] = $chiarimento;
}
}
return $chiarimenti;
}
public function getSopralluoghi($codice = NULL) {
$tmp = parent::getSopralluoghi($codice);
$sopralluoghi = [];
$codice_oe = $_SESSION["utente"]->oe["codice"] ?? null;
foreach($tmp AS $chiarimento) {
if ($codice_oe == $chiarimento["codice_richiedente"]) {
if ($chiarimento["attivo"] == "P") {
$chiarimento["risposta"] = "";
$chiarimento["appuntamento"] = null;
}
$sopralluoghi[] = $chiarimento;
}
}
return $sopralluoghi;
}
public function chiarimentiAperti() {
if ($this->potentialAction) {
if ($this->info["stato"] == "20") {
if (!empty($this->info["chiarimenti"]) && strtotime($this->info["chiarimenti"]) > time()) {
return true;
}
}
}
return false;
}
public function saveChiarimento($input) {
$array = array();
$array["codice_elenco"] = $this->info["codice"];
$array["quesito"] = $input["quesito"];
$array["utente_richiesta"] = $_SESSION["utente"]->codice;
$array["timestamp_richiesta"] = date('Y-m-d H:i:s');
$array["codice_richiedente"] = $_SESSION["utente"]->oe["codice"];
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->chiarimentiTable;
$salva->operazione = "INSERT";
$salva->oggetto = $array;
$codice = $salva->save();
if ($codice !== false) {
$this->updateBadges();
if (isset($input["allegato"])) {
foreach($input["allegato"] as $allegato) {
filesManager::saveFile($allegato["filename"],$codice,$this->modulo."-quesiti",$allegato["nome"]);
}
}
$corpo = "<h1>" . __("Elenco") . " #" . $this->info["id"] . "</h1>";
$corpo .= "<h2>" . $this->info["oggetto"] . "</h2>";
$corpo .= "<strong>" . $array["quesito"] . "</strong>";
$mailer = new Communicator();
$mailer->oggetto = __("E' stato richiesto un chiarimento");
$mailer->corpo = $corpo;
$mailer->codice_pec = $this->info["codice_pec"] ?? -1;
$mailer->comunicazione = true;
$mailer->sezione = $this->modulo;
$mailer->codice_gara = $this->info["codice"];
$mailer->coda = true;
$mailer->destinatari = $array["codice_richiedente"];
$mailer->send();
$mailer->codice_pec = -1;
$mailer->comunicazione = false;
$destinatari = [Communicator::getPecAddress($this->info["codice_pec"])];
$utenti = $this->getDestinatariInterni();
if (!empty($utenti)) {
$destinatari = array_merge($destinatari,$utenti);
}
$mailer->destinatari = $destinatari;
$mailer->send();
return true;
}
}
public function sopralluogoAperti() {
if ($this->potentialAction) {
if ($this->info["stato"] == "20") {
if (!empty($this->info["sopralluogo"]) && strtotime($this->info["sopralluogo"]) > time()) {
return true;
}
}
}
return false;
}
public function saveSopralluogo($input) {
if ($this->sopralluogoAperti()) {
$array = array();
$array["codice_elenco"] = $this->info["codice"];
$array["richiesta"] = $input["richiesta"];
$array["utente_richiesta"] = $_SESSION["utente"]->codice;
$array["timestamp_richiesta"] = date('Y-m-d H:i:s');
$array["attivo"] = "P";
$array["codice_richiedente"] = $_SESSION["utente"]->oe["codice"];
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->sopralluogoTable;
$salva->operazione = "INSERT";
$salva->oggetto = $array;
$codice = $salva->save();
if ($codice !== false) {
$this->updateBadges();
if (isset($_POST["allegato-sopralluogo"])) {
foreach($_POST["allegato-sopralluogo"] as $allegato) {
filesManager::saveFile($allegato["filename"],$codice,$this->modulo."-ric-sopr",$allegato["nome"]);
}
}
$corpo = "<h1>" . __("Elenco") . " #" . $this->info["id"] . "</h1>";
$corpo .= "<h2>" . $this->info["oggetto"] . "</h2>";
$corpo .= "<strong>" . $array["richiesta"] . "</strong>";
$mailer = new Communicator();
$mailer->oggetto = __("E' stato richiesto un sopralluogo");
$mailer->corpo = $corpo;
$mailer->codice_pec = $this->info["codice_pec"] ?? -1;
$mailer->comunicazione = true;
$mailer->sezione = $this->modulo;
$mailer->codice_gara = $this->info["codice"];
$mailer->coda = true;
$mailer->destinatari = $array["codice_richiedente"];
$mailer->send();
$mailer->codice_pec = -1;
$mailer->comunicazione = false;
$destinatari = [Communicator::getPecAddress($this->info["codice_pec"])];
$utenti = $this->getDestinatariInterni();
if (!empty($utenti)) {
$destinatari = array_merge($destinatari,$utenti);
}
$mailer->destinatari = $destinatari;
$mailer->send();
return true;
}
}
}
public function miaPartecipazione() {
if (isset($_SESSION["utente"]) && $_SESSION["utente"]->gerarchia >= 100 && !empty($_SESSION["utente"]->oe)) {
$bind = [":codice_elenco"=>$this->info["codice"]];
$bind[":codice_operatore"]=static::getRefPartecipante();
$sql = "SELECT * FROM {$this->oeTable} WHERE codice_elenco = :codice_elenco AND codice_operatore = :codice_operatore";
return $this->db->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC)[0] ?? false;
}
}
public function partecipazioneAttiva() {
if ($this->potentialAction) {
if ($this->info["stato"] == "20") {
if (empty($this->info["scadenza"]) || strtotime($this->info["scadenza"]) > time()) {
return true;
}
}
}
return false;
}
public function showPanel() {
$return = $this->partecipazioneAttiva();
if (!$return) {
$return = $this->miaPartecipazione();
if (!empty($return)) {
if ($return["conferma"] != "S") { return false; }
}
}
if (!empty($return)) { return true; }
return false;
}
public function getManagerRichieste($partecipante = null) {
if (!empty($this->miaPartecipazione())) {
$manager = new publicRichiesteOE($this->getModulo(),$this->info["codice"],$this->miaPartecipazione()["codice"]);
if (!empty($manager)) {
return $manager;
}
}
}
public function getRichiesteIntegrazione() {
$manager = $this->getManagerRichieste();
if (!empty($manager)) {
return $manager->getRichieste();
}
}
public function deleteBusta($codice_richiesta) {
if ($this->partecipazioneAttiva() && !empty($this->miaPartecipazione())) {
$partecipante = $this->miaPartecipazione();
$busta = $this->getBusta($partecipante,$codice_richiesta,false);
if (!empty($busta)) {
if ($partecipante["conferma"] == "S") {
$sql = "UPDATE {$this->busteTable} SET soft_delete = 'S', timestamp_delete = NOW() WHERE codice_partecipante = :codice_partecipante AND codice_richiesta = :codice_richiesta AND codice = :codice ";
} else {
unlink($this->getSpecificBustaPath($busta));
$sql = "DELETE FROM {$this->busteTable} WHERE codice_partecipante = :codice_partecipante AND codice_richiesta = :codice_richiesta AND codice = :codice ";
}
$this->db->go($sql,array(":codice_partecipante"=>$partecipante["codice"],":codice_richiesta"=>$codice_richiesta,":codice"=>$busta["codice"]));
scriviLog($this->busteTable,"DELETE",$this->db->getSQL());
}
}
}
public function revoca($delete = false) {
$return = false;
if ($this->partecipazioneAttiva()) {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante) && ($partecipante["conferma"] == "S" || $delete)) {
if (!$delete) {
$update = [
"codice" => $partecipante["codice"],
"valutato" => "N",
"conferma" => "N",
];
if (settingsManager::getValue("qualificaAutomatica") == "S" && isset($this->info["abilitazione_automatica"]) && $this->info["abilitazione_automatica"] == "S") {
$update["ammesso"] = "N";
}
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->oeTable;
$salva->operazione = "UPDATE";
$salva->oggetto = $update;
$return = $salva->save();
} else {
$richieste = $this->getRichieste();
foreach($richieste AS $richiesta) {
$this->deleteBusta($richiesta["codice"]);
}
$ris = $this->db->go("DELETE FROM {$this->oeTable} WHERE codice = :codice",[":codice"=>$partecipante["codice"]]);
if ($ris->rowCount() > 0) {
$return = true;
scriviLog($this->oeTable,"DELETE",$this->db->getSQL());
}
}
if (!empty($return)) {
$this->updateBadges();
if ($partecipante["conferma"] == "S") {
$editor = new editorManager("msg-revoca-albo",0);
$editor->vocabolario["ragione-sociale"] = $_SESSION["utente"]->oe["ragione_sociale"];
$editor->vocabolario["elenco"] = $this->info;
$corpo = $editor->getModello();
$mailer = new Communicator();
$mailer->oggetto = __('Revoca iscrizione') . " Elenco #" . $this->info["id"];
$mailer->corpo = $corpo;
$mailer->codice_pec = $this->info["codice_pec"] ?? -1;
$mailer->comunicazione = true;
$mailer->sezione = $this->modulo;
$mailer->codice_gara = $this->info["codice"];
$mailer->coda = false;
$mailer->destinatari = (static::refPartecipante() == "operatore") ? $_SESSION["utente"]->oe["codice"] : $_SESSION["utente"]->getInfo()["email"];
$mailer->send();
$mailer->codice_pec = -1;
$mailer->comunicazione = false;
$mailer->destinatari = Communicator::getPecAddress($this->info["codice_pec"]);
$mailer->send();
}
}
}
}
return $return;
}
public function aggiorna() {
$return = false;
if ($this->partecipazioneAttiva()) {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante) && ($partecipante["conferma"] == "S")) {
$partecipante["valutato"] = "N";
$expectedKeys = ["codice","valutato","timestamp_aggiornamento","utente_aggiornamento"];
if (settingsManager::getValue("qualificaAutomatica") == "S" && isset($this->info["abilitazione_automatica"]) && $this->info["abilitazione_automatica"] == "S") {
$partecipante["valutato"] = "S";
$partecipante["ammesso"] = "S";
$expectedKeys[] = "timestamp_abilitazione";
$expectedKeys[] = "ammesso";
if (empty($partecipante["timestamp_abilitazione"])) {
$partecipante["timestamp_abilitazione"] = date("Y-m-d H:i:s");
}
}
$partecipante["timestamp_aggiornamento"] = date("Y-m-d H:i:s");
$partecipante["utente_aggiornamento"] = $_SESSION["utente"]->codice;
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->oeTable;
$salva->operazione = "UPDATE";
$salva->expect = $expectedKeys;
$salva->oggetto = $partecipante;
$return = $salva->save();
if ($return != false) {
$this->updateBadges();
$editor = new editorManager("msg-aggiorna-albo",0);
if (static::refPartecipante() == "operatore") {
$editor->vocabolario["ragione-sociale"] = $_SESSION["utente"]->oe["ragione_sociale"];
} else {
$userInfo = $_SESSION["utente"]->getInfo();
$editor->vocabolario["ragione-sociale"] = $userInfo["cognome"] . " " . $userInfo["nome"];
}
$editor->vocabolario["elenco"] = $this->info;
$corpo = $editor->getModello();
$mailer = new Communicator();
$mailer->oggetto = __('Aggiornamento iscrizione') . " Elenco #" . $this->info["id"];
$mailer->corpo = $corpo;
$mailer->codice_pec = $this->info["codice_pec"] ?? -1;
$mailer->comunicazione = true;
$mailer->sezione = $this->modulo;
$mailer->codice_gara = $this->info["codice"];
$mailer->coda = false;
$mailer->destinatari = (static::refPartecipante() == "operatore") ? $_SESSION["utente"]->oe["codice"] : $_SESSION["utente"]->getInfo()["email"];
$mailer->send();
$mailer->codice_pec = -1;
$mailer->comunicazione = false;
$mailer->destinatari = Communicator::getPecAddress($this->info["codice_pec"]);
$mailer->send();
}
}
}
return $return;
}
public function printUploadRichiesta($codice_richiesta) {
$return = false;
include(__DIR__."/partecipa/manage.php");
return $return;
}
public function printForm($codice_form) {
$return = false;
include(__DIR__."/partecipa/form.php");
return $return;
}
public function printPanelPartecipazione() {
$return = false;
include(__DIR__."/partecipa/panel.php");
return $return;
}
public function getBusta($partecipante,$richiesta,bool $contenuto = false) {
$partecipazione = $this->miaPartecipazione();
if (!empty($partecipazione)) {
$partecipazione = $partecipazione["codice"];
return parent::getBusta($partecipazione,$richiesta,$contenuto);
}
return false;
}
public function savePartecipante($placeholder = null) {
$return = false;
$partecipante = array();
$partecipante["codice_elenco"] = $this->info["codice"];
$partecipante["codice_operatore"] = static::getRefPartecipante();
$partecipante["timestamp_creazione"] = date("Y-m-d H:i:s");
$partecipante["utente_creazione"] = $_SESSION["utente"]->codice;
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->oeTable;
$salva->operazione = "INSERT";
$salva->oggetto = $partecipante;
if ($salva->save()) {
$return = $this->miaPartecipazione();
}
return $return;
}
public function saveForm($input) {
if ($this->partecipazioneAttiva()) {
$forms = $this->getForms();
if (!empty($forms)) {
foreach($forms AS $tmp) {
if ($tmp == $input["codice_form"]) {
$form = $tmp;
break;
}
}
}
if (!empty($form)) {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante)) {
$validazione = $this->valida();
if ($partecipante["conferma"]=="S" && $validazione === true) {
if ($this->aggiorna() !== false) {
$partecipante = $this->miaPartecipazione();
}
}
} else {
$partecipante = $this->savePartecipante();
}
if (!empty($partecipante)) {
$formManager = new FormManager;
$formManager->stripEnte = true;
$formManager->init($form,$this->modulo."-".$_SESSION["ente"]->codice,$partecipante["codice"]);
if ($partecipante["conferma"]=="S") {
$formManager->saveVersion();
}
if ($formManager->saveData($input["dyn-form-input"][$formManager->info["codice"]])) {
$validazione = $formManager->validateData();
if (empty($validazione)) {
alertManager::printSuccessBox(__('Operazione effettuata con successo'));
if ($this->generaPDF()) {
?>
<a class="btn btn-block btn-lg btn-warning" onclick="$('#downloadOffer').slideDown();" target="_blank" href="download-pdf.php?codice_elenco=<?= $this->info["codice"] ?>">
<span class="fa fa-download"></span> <?= __("Download documento da firmare") ?>
</a>
<div class="collapse" id="downloadOffer">
<a class="btn btn-block btn-lg btn-success" href="partecipa.php?codice=<?= $this->info["codice"] ?>&open=cumulativa">
<span class="fa fa-upload"></span> <?= __("Carica documento") ?>
</a>
</div>
<?
}
} else {
alertManager::printWarningBox(__('Salvataggio effettuato con successo'),__('Sono presenti errori di validazione'));
foreach($validazione AS $msg) {
?>
<div class="alert alert-warning p-2 mb-1"><span class="fa fa-exclamation-triangle"></span> <?= $msg ?></div>
<?
}
}
} else {
alertManager::printAlertBox(__('errore nel salvataggio del questionario') . " - #003");
}
} else {
alertManager::printAlertBox(__('Impossibile continuare') . " - #002");
}
} else {
alertManager::printAlertBox(__('Impossibile continuare') . " - #001");
}
} else {
alertManager::printAlertBox(__("Impossibile continuare") . " - #000");
}
}
public function getFormPDFPath() : ?String {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante)) {
$partecipante = $partecipante["codice"];
global $config;
$path = "{$config["mediaFolder"]}/{$_SESSION["ente"]->codice}/{$this->modulo}-pdf-form/{$this->info["codice"]}";
if (!file_exists($path)) {
mkdir($path,0777,true);
}
if (is_dir($path)) {
return $path . "/form-{$partecipante}.pdf";
}
}
return null;
}
public function getPDF() : ?String {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante["extraInfo"])) {
$info = json_decode($partecipante["extraInfo"],true);
if (!empty($info["salt"])) {
$path = $this->getFormPDFPath();
if (file_exists($path)) {
$content = file_get_contents($path);
if (!empty($content)) {
return simple_decrypt($content,$info["salt"]);
}
}
}
}
return null;
}
public function generaPDF() : Bool {
if ($this->richiestaFirmaFormCumulativa && $this->partecipazioneAttiva()) {
$partecipante = $this->miaPartecipazione();
$richiesta = $this->getRichiestaQuestionari();
$this->deleteBusta($richiesta["codice"]);
if (!empty($partecipante["extraInfo"])) {
$this->db->go("UPDATE {$this->oeTable} SET extraInfo = NULL WHERE codice = :codice",[":codice"=>$partecipante["codice"]]);
}
$errori = [];
$this->checkFormFill($errori);
if (count($errori) === 1 && isset($errori[404])) {
$forms = $this->getForms();
if (!empty($forms)) {
ob_start();
foreach($forms AS $form) {
$formManager = new FormManager;
$formManager->stripEnte = true;
$formManager->init($form,$this->modulo."-".$_SESSION["ente"]->codice,$partecipante["codice"]);
echo "<br><h1>" . json_decode($formManager->info["titolo"],true)[$_SESSION["language"]] . "</h1>";
$formManager->printForm(false);
}
$html = ob_get_clean();
$pdfBase = file_get_contents(__DIR__.DIRECTORY_SEPARATOR."partials".DIRECTORY_SEPARATOR."pdfStyle.html") ;
$pdfBase = str_replace("##--html--##",$html,$pdfBase);
$pdf = documentConverter::getPDFWithWKHTML($pdfBase, 'A4', 'portrait', false);
$path = $this->getFormPDFPath();
if (!empty($pdf) && !empty($path)) {
if (file_put_contents($path,$pdf)) {
$p7m = new P7Manager($path);
$extraInfo = ["salt" => generateStrongPassword()];
foreach(["md5","sha1","sha256"] AS $alg) {
$extraInfo[$alg] = $p7m->getHash($alg);
}
$parser = new \Smalot\PdfParser\Parser();
$contentForHash = $parser->parseFile($path)->getText();
$contentForHash = preg_replace("/[^a-zA-Z0-9]/", '', $contentForHash);
$extraInfo["shaContent"] = hash("sha256",$contentForHash);
unset($p7m);
$pdf = simple_encrypt($pdf,$extraInfo["salt"]);
if (file_put_contents($path,$pdf)) {
$this->db->go("UPDATE {$this->oeTable} SET extraInfo = :extraInfo WHERE codice = :codice",[":extraInfo"=>json_encode($extraInfo),":codice"=>$partecipante["codice"]]);
return true;
}
}
}
}
}
}
return false;
}
public function checkFormFill(&$errori = []) {
$forms = $this->getForms();
$partecipante = $this->miaPartecipazione();
$errors = [];
$return = false;
if (!empty($forms)) {
foreach($forms AS $form) {
$formManager = new FormManager;
$formManager->stripEnte = true;
$formManager->init($form,$this->modulo."-".$_SESSION["ente"]->codice,$partecipante["codice"]);
$validaForm = $formManager->validateData();
if (!empty($validaForm)) {
$errors[] = json_decode($formManager->info["titolo"],true)[$_SESSION["language"]] . " - " . __("Obbligatorio");
}
}
}
if (empty($errors)) {
if ($this->richiestaFirmaFormCumulativa) {
$extraInfo = json_decode($partecipante["extraInfo"],true);
if (!empty($extraInfo)) {
$return = $extraInfo;
} else {
$errors[404] = __("Generazione PDF mancante");
}
}
}
if (!empty($errors)) {
$errori = $errors;
}
return $return;
}
public function valida() {
$errors = [];
$forms = $this->getForms();
$partecipante = $this->miaPartecipazione();
$richieste = $this->getRichieste();
if (!empty($richieste) || !empty($forms)) {
$this->checkFormFill($errors);
if (!empty($richieste)) {
foreach($richieste AS $input) {
$content = $this->getBusta($partecipante["codice"],$input["codice"]);
if (empty($content) && $input["controllo"] != "N") {
$errors[] = $input["titolo"] . " - " . __("Obbligatorio");
}
}
}
} else {
$errors[] = __("Errore nella richiesta");
}
if (empty($errors)) {
return true;
} else {
if ($partecipante["conferma"] == "S") {
$this->revoca();
}
return $errors;
}
}
public function send() {
if ($this->partecipazioneAttiva()) {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante)) {
ob_start();
?>
<h1 class="clearfix">
<?= __("Elenco") ?> #<?= $this->info["id"] ?>
</h1>
<h2><?= $this->info["oggetto"] ?></h2><br>
<?= __("Operatore economico") ?>:
<strong><?= $_SESSION["utente"]->oe["codice_fiscale_impresa"] ?> <?= $_SESSION["utente"]->oe["ragione_sociale"] ?></strong><br><br>
<?
$forms = $this->getForms();
$richieste = $this->getRichieste();
$validazione = $this->valida();
$errori = [];
if ($validazione === true) {
if ($partecipante["conferma"]=="N" || $partecipante["valutato"]=="S") {
?>
<div class="card card-body">
<ul>
<?
if (!empty($forms)) {
foreach($forms AS $form) {
$formManager = new FormManager;
$formManager->stripEnte = true;
$formManager->init($form,$this->modulo."-".$_SESSION["ente"]->codice,static::getRefPartecipante());
$formInfo = $formManager->info;
$formInfo["titolo"] = json_decode($formInfo["titolo"],true)[$_SESSION["language"]];
$hash = hash("sha256",json_encode($formManager->getValues()));
?>
<li><strong><?= $formInfo["titolo"] ?></strong>
<? if (!empty($hash)) { ?>
<ul>
<li><?= __("Impronta hash") ?> SHA256: <strong><?= $hash ?></strong></li>
</ul>
<? } ?>
</li>
<?
}
}
if (!empty($richieste)) {
foreach($richieste AS $input) {
$content = $this->getBusta($partecipante["codice"],$input["codice"]);
?>
<li><strong><?= $input["titolo"] ?></strong>
<? if (!empty($content["nomeFile"])) { ?>
<ul>
<li><span class="far fa-file"></span> <?= $content["nomeFile"] ?></li>
<li><?= __("Impronta hash") ?> SHA256: <strong><?= $content["sha256"] ?></strong></li>
</ul>
<? } ?>
</li>
<? } ?>
<? } ?>
</ul>
</div>
<?
$expectedKeys = ["codice","conferma","valutato","timestamp_aggiornamento","utente_aggiornamento"];
$partecipante["conferma"] = "S";
$partecipante["valutato"] = "N";
if (settingsManager::getValue("qualificaAutomatica") == "S" && isset($this->info["abilitazione_automatica"]) && $this->info["abilitazione_automatica"] == "S") {
$partecipante["conferma"] = "S";
$partecipante["valutato"] = "S";
$partecipante["ammesso"] = "S";
$expectedKeys[] = "timestamp_abilitazione";
$expectedKeys[] = "ammesso";
if (empty($partecipante["timestamp_abilitazione"])) {
$partecipante["timestamp_abilitazione"] = date("Y-m-d H:i:s");
}
}
$partecipante["timestamp_aggiornamento"] = date("Y-m-d H:i:s");
$partecipante["utente_aggiornamento"] = $_SESSION["utente"]->codice;
$salva = new salva();
$salva->debug = false;
$salva->nome_tabella = $this->oeTable;
$salva->operazione = "UPDATE";
$salva->oggetto = $partecipante;
$salva->expect = $expectedKeys;
$partecipante["codice"] = $salva->save();
if (!empty($partecipante["codice"])) {
$this->updateBadges();
$html = ob_get_clean();
$corpo = purify($html);
ob_start();
echo $html;
$mailer = new Communicator();
$mailer->oggetto = __('Conferma di ricezione istanza') . ' elenco #' . $this->info["id"];
$mailer->corpo = $corpo;
$mailer->codice_pec = $this->info["codice_pec"] ?? -1;
$mailer->comunicazione = true;
$mailer->sezione = $this->modulo;
$mailer->codice_gara = $this->info["codice"];
$mailer->coda = true;
$mailer->destinatari = (static::refPartecipante() == "operatore") ? $_SESSION["utente"]->oe["codice"] : $_SESSION["utente"]->getInfo()["email"];
$mailer->send();
$mailer->codice_pec = -1;
$mailer->comunicazione = false;
$mailer->destinatari = Communicator::getPecAddress($this->info["codice_pec"]);
$mailer->send();
alertManager::printSuccessBox(__("L'istanza è stata ricevuta con successo"),__("Un messaggio di posta elettronica certificata è stato inviato per confermare l'operazione"));
} else {
$errori[] = __("Errore invio istanza");
}
} else {
$errori[] = __("Istanza già inviata");
}
} else {
$errori = $validazione;
}
if (!empty($errori)) {
$msg = __("Errore generico");
if (!empty($errori)) {
$msg = "<ul>";
foreach($errori AS $txt) {
$msg .= "<li>{$txt}</li>";
}
$msg .= "</ul>";
}
alertManager::printAlertBox(__("Errori"),$msg);
}
$html = ob_get_clean();
echo $html;
$this->updateBadges();
}
}
}
public function uploadBusta($input) {
if ($this->partecipazioneAttiva()) {
$return = $this->getManagerPartecipazione()->saveBusta($_POST);
$validazione = $this->valida();
if ($this->miaPartecipazione()["conferma"]=="S" && $validazione === true) {
$this->aggiorna();
}
return $return;
}
}
/**
* Aggiorna la posizione dell'operatore economico per memorizzare l'avvenuta risposta di integrazione
*
* @param Array $oe
* @return void
*/
public function postRispostaRichiesteOE(Array $infoRichiesta) {
if (!empty($infoRichiesta["codice"]) && !empty($infoRichiesta["codice_relazione"])) {
$partecipante = $this->miaPartecipazione();
if (!empty($partecipante)) {
$this->updateStatoIntegrazioni([$partecipante],"R");
}
}
}
public function getManagerPartecipazione() {
if (empty($this->managerPartecipazione)) {
$manager = new busteOE;
$manager->submit = $this->partecipazioneAttiva();
$manager->deletable = $this->partecipazioneAttiva();
$manager->obj = $this;
$manager->modulo = $this->modulo;
$manager->tableBuste = $this->busteTable;
$manager->variables = ["codice_elenco"=>$this->info["codice"]];
$manager->formPossibile = true;
$manager->modalitaFirmaForm = "cumulativa";
$manager->richiestaFirmaFormCumulativa = $this->richiestaFirmaFormCumulativa;
$manager->raggruppamentoPossibile = false;
$manager->avvalimentoPossibile = false;
$manager->criptazione = false;
$this->managerPartecipazione = $manager;
}
return $this->managerPartecipazione;
}
}