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->internalUsers = false; } private static function extensionExists($class) { if (isset($_SESSION["ente"])) { $pathExtender = $_SESSION["ente"]->getExtensionPath() . DIRECTORY_SEPARATOR . "{$class}.extender.class.php"; $extenderName = "{$class}Extender{$_SESSION["ente"]->codice}"; if (file_exists($pathExtender)) { include_once $pathExtender; return $extenderName; } } } public static function getDirectory() { return ""; } public static function getMainTable() { return ""; } public static function getOeTable() { return ""; } public static function getRichiesteTable() { return ""; } public static function getFormTable() { return ""; } public static function getModulo() { return ""; } public static function getCpvTable() { return ""; } public static function getChiarimentiTable() { return ""; } public static function getSopralluogoTable() { return ""; } public static function getBusteTable() { return ""; } public static function tipologieNoRevisione() { return []; } public static function tipologieObbligoScadenza() { return []; } public static function tipologieShowPartecipanti() { return []; } public static function tipologieConSOA() { return []; } public static function tipologieConServiziTecnici() { return []; } public static function tipologieEsitiCumulativi() { return []; } public static function refPartecipante() { return "operatore"; } public function canShowPartecipanti() { return (in_array($this->info["tipologia"],static::tipologieShowPartecipanti())); } public function showPartecipanti() { if ($this->canShowPartecipanti() && $this->info["visualizza_elenco"] == "S") { return true; } return false; } public static function extraPreliminary() { $return = []; $return["atto_indizione"] = ["label"=>"Provvedimento di indizione","type"=>"text","rel"=>"N;0;0;A","col"=>"col-12 col-xl-6"]; $return["data_atto_indizione"] = ["label"=>"Data del provvedimento di indizione","type"=>"text","rel"=>"N;10;10;D","col"=>"col-12 col-xl-6","class"=>"datepick"]; $return["servizio"] = ["label"=>"Servizio","type"=>"text","rel"=>"N;0;0;A","col"=>"col-12 col-xl-6"]; $return["responsabile_servizio"] = ["label"=>"Responsabile del servizio","type"=>"text","rel"=>"N;0;0;A","col"=>"col-12 col-xl-6"]; return $return; } public static function printEditForm($record, $cpv, $lock = true, $tipologie = []) { if (!empty($record)) { include(__DIR__ . "/views/edit.php"); } } public function printElaborazioneForm() { include(__DIR__ . "/views/elaborazione.php"); } public function printPubblicaForm() { include(__DIR__ . "/views/pubblica.php"); } public function printSospendiForm() { include(__DIR__ . "/views/sospendi.php"); } public static function printIndexTable() { $print = true; include(__DIR__ . "/views/table.php"); } public function printIndexPartecipanti() { $print = true; include(__DIR__ . "/views/partecipanti/table.php"); } public function printModalAddUser() { $print = true; include(__DIR__ . "/views/partecipanti/searchUser.php"); } public function printPanelPartecipante($codice) { $print = true; $partecipante = $this->getPartecipante($codice); if (!empty($partecipante)) { include(__DIR__ . "/views/partecipanti/dettaglio.php"); } else { alertManager::printAlertBox(__("Errore richiesta")); } } public function addUser($email) { $esito = ["error"=>true,"msg"=>"Errore generico"]; if ($this->internalUsers) { $utente = $this->db->go("SELECT codice FROM b_utenti WHERE ruolo = 'USR' AND email = :email",[":email"=>$email])->fetch(PDO::FETCH_COLUMN); if (!empty($utente)) { if ($this->db->go("SELECT codice FROM " . $this->oeTable . " WHERE codice_operatore = :utente AND codice_elenco = :elenco",[":utente"=>$utente,":elenco"=>$this->info["codice"]])->rowCount() === 0) { $partecipante = array(); $partecipante["codice_elenco"] = $this->info["codice"]; $partecipante["codice_operatore"] = $utente; $partecipante["ammesso"] = "S"; $partecipante["valutato"] = "S"; $partecipante["conferma"] = "S"; $partecipante["timestamp_creazione"] = date("Y-m-d H:i:s"); $partecipante["utente_creazione"] = $_SESSION["utente"]->codice; $partecipante["timestamp_abilitazione"] = date("Y-m-d H:i:s"); $partecipante["utente_abilitazione"] = $_SESSION["utente"]->codice; $salva = new salva(); $salva->debug = false; $salva->nome_tabella = $this->oeTable; $salva->operazione = "INSERT"; $salva->oggetto = $partecipante; if ($salva->save()) { $esito["error"] = false; } else { $esito["msg"] = "Errore salvataggio"; } } else { $esito["msg"] = "Utente giĆ associato"; } } else { $esito["msg"] = "Utente sconosciuto"; } } else { $esito["msg"] = "Elenco non compatibile"; } return $esito; } public static function getTotaliPartecipanti($elenco) { global $pdo; $return = []; $bind = [":elenco"=>$elenco]; $base = "SELECT COUNT(codice) AS tot FROM " . static::getOeTable() . " WHERE codice_elenco = :elenco "; $return["nuovi"] = $pdo->go($base . " AND conferma = 'S' AND ammesso = 'N' AND valutato = 'N'",$bind)->fetch(PDO::FETCH_COLUMN); $return["aggiornamenti"] = $pdo->go($base . " AND conferma = 'S' AND ammesso = 'S' AND valutato = 'N'",$bind)->fetch(PDO::FETCH_COLUMN); $return["ammessi"] = $pdo->go($base . " AND conferma = 'S' AND ammesso = 'S'",$bind)->fetch(PDO::FETCH_COLUMN); $return["respinti"] = $pdo->go($base . " AND conferma = 'S' AND ammesso = 'N' AND valutato = 'S'",$bind)->fetch(PDO::FETCH_COLUMN); $return["integrazioni"] = $pdo->go($base . " AND conferma = 'S' AND integrazioni IS NOT NULL AND integrazioni <> 'N'",$bind)->fetch(PDO::FETCH_COLUMN); $return["generale"] = $pdo->go($base . " AND conferma = 'S'",$bind)->fetch(PDO::FETCH_COLUMN); return $return; } public static function getDataTableJSON($input) { if (isset($input["draw"])) { global $pdo; $return = array(); $return["draw"] = (int)$input["draw"]; $return["recordsTotal"] = (int)0; $return["recordsFiltered"] = (int)0; $filters = []; if (isset($input["tipologia"]) && $input["tipologia"] !== "") { $filters[static::getMainTable() . ".tipologia"] = $input["tipologia"]; } $total = static::getList($filters, [], 0, -1); if (!empty($total)) { $tipologie = static::getTipologie(); $return["recordsTotal"] = (int)count($total); if (!empty($input["search"]["value"])) { $filters["*"] = $input["search"]["value"]; } if (isset($input["stato"]) && $input["stato"] !== "") { $filters[static::getMainTable() . ".stato"] = $input["stato"]; } if (isset($input["ente"]) && $input["ente"] !== "") { $filters[static::getMainTable() . ".codice_ente"] = $input["ente"]; } $order = []; if (isset($input["order"][0]["column"])) { switch ($input["order"][0]["column"]) { case "3": $orderKey = static::getMainTable() . ".badge"; break; case "4": $orderKey = static::getMainTable() . ".tipologia"; break; case "5": $orderKey = static::getMainTable() . ".oggetto"; break; default: $orderKey = static::getMainTable() . ".id"; break; } if ($input["order"][0]["dir"] == "desc") { $order[$orderKey] = "DESC"; } else { $order[$orderKey] = "ASC"; } } $risultati = static::getList($filters, $order, $input["start"], $input["length"]); 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) { $stato = $stati[$record["stato"]]; if ($record["stato"] == 20 && strtotime($record["pubblicazione"]) > time()) { $stato["titolo"] = "Programmata pubblicazione"; } $panelHref = "/backend/".static::getDirectory()."/panel.php?codice={$record["codice"]}"; $row = array(); $row[] = '
'; $row[] = __($stato["titolo"]); $row[] = $record["id"]; $row[] = ($record["badge"] > 0) ? "" . $record["badge"] . " " : ""; $row[] = __($tipologie[$record["tipologia"]]); $row[] = "" . $record["oggetto"] . ""; $count = static::getTotaliPartecipanti($record["codice"]); foreach($count AS $num) { $row[] = $num; } $row[] = ""; $return["data"][] = $row; } } else { $return["data"] = array(); } } else { $return["data"] = array(); } return $return; } } public static function getList($filters=[],$order=[],$start=0,$length=1) { $tabella = static::getMainTable(); global $pdo; $select = "SELECT {$tabella}.codice, {$tabella}.badge, {$tabella}.codice_ente, {$tabella}.id, {$tabella}.stato, {$tabella}.tipologia, {$tabella}.oggetto, {$tabella}.pubblicazione "; $from = " FROM {$tabella} "; $bind = []; $where = " WHERE {$tabella}.codice > 0 "; if ($_SESSION["utente"]->gerarchia > 10) { $ids = Utente::getPermissionsInModulo($_SESSION["ente"]->codice,$_SESSION["utente"]->codice,static::getModulo()); $ids = implode(",",$ids); $where .= " AND {$tabella}.codice IN ({$ids}) "; } if (!$_SESSION["utente"]->fromHere()) { $where .= " AND {$tabella}.codice_ente = :codice_ente"; $bind[":codice_ente"] = $_SESSION["utente"]->codice_ente; } if (!empty($filters)) { $keys = ["{$tabella}.id","{$tabella}.oggetto","{$tabella}.descrizione"]; $addWhere = []; foreach($keys AS $key) { if (isset($filters[$key]) || isset($filters["*"])) { $value = $filters[$key] ?? $filters["*"]; $sudd = suddivisione_pdo($value,$key); if (!empty($sudd)) { $bind = $bind + $sudd["bind"]; $addWhere[] = $sudd["sql"]; } } } if (!empty($addWhere)) { $where .= " AND (" . implode(" OR ",$addWhere) . ") "; } if (isset($filters["{$tabella}.codice_ente"])) { $bind[":codice_ente"] = (int)$filters["{$tabella}.codice_ente"]; $where .= " AND {$tabella}.codice_ente = :codice_ente "; } if (isset($filters["{$tabella}.stato"])) { $bind[":stato"] = (int)$filters["{$tabella}.stato"]; $where .= " AND {$tabella}.stato = :stato "; } if (isset($filters["{$tabella}.tipologia"])) { $bind[":tipologia"] = $filters["{$tabella}.tipologia"]; $where .= " AND {$tabella}.tipologia = :tipologia "; } if (isset($filters["{$tabella}.codice"])) { $bind[":codice"] = (int)$filters["{$tabella}.codice"]; $where .= " AND {$tabella}.codice = :codice "; } } $sort = "ORDER BY {$tabella}.id DESC "; if (!empty($order)) { $keys = ["{$tabella}.id","{$tabella}.badge","{$tabella}.stato","{$tabella}.oggetto"]; $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)) { $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 {$tabella}.codice ".$sort.$limit,$bind)->fetchAll(PDO::FETCH_ASSOC); return $return; } public function getCategorieMerceologiche() { $codici_categoria = []; $sql_categoria = "SELECT codice FROM {$this->cpvTable} WHERE codice_elenco = :codice "; $ris_custom = $this->db->go($sql_categoria, array(":codice" => $this->info["codice"])); if ($ris_custom->rowCount() > 0) { while ($categoria = $ris_custom->fetch(PDO::FETCH_ASSOC)) { if (!empty($categoria)) { $codici_categoria[] = $categoria["codice"]; } } } $codici_categoria = array_unique($codici_categoria); return $codici_categoria; } public static function getIstanzeOE(int $codice_oe) : ?array { if (!empty(static::getMainTable())) { $mainTable = static::getMainTable(); $partecipantiTable = static::getOeTable(); global $pdo; return $pdo->go("SELECT {$partecipantiTable}.*, {$mainTable}.tipologia,{$mainTable}.oggetto FROM {$partecipantiTable} JOIN {$mainTable} ON {$partecipantiTable}.codice_elenco = {$mainTable}.codice WHERE {$partecipantiTable}.codice_operatore = :oe AND {$partecipantiTable}.conferma = 'S'",[":oe"=>$codice_oe])->fetchAll(PDO::FETCH_ASSOC); } } public function getIstanzeAffini(int $codice_oe) : ? array { $return = []; if (in_array($this->info["tipologia"],static::tipologieEsitiCumulativi())) { $altreIstanze = static::getIstanzeOE($codice_oe); if (!empty($altreIstanze)) { foreach($altreIstanze AS $istanza) { if ($istanza["tipologia"] == $this->info["tipologia"] && $istanza["valutato"] == "N" && $istanza["codice_elenco"] != $this->info["codice"] && ($_SESSION["utente"]->permission($this->modulo,$istanza["codice_elenco"],"partecipanti"))) { $return[] = $istanza; } } } } return $return; } public function saveMainData(array $input) { $data = ["codice"=>$this->info["codice"]]; $data = $data + $input; $salva = new salva(); $salva->debug = false; $salva->nome_tabella = static::getMainTable(); $salva->operazione = "UPDATE"; $salva->oggetto = $data; return ($salva->save()); } public static function save($data) { if (!empty(static::getMainTable()) && !empty(static::getCpvTable())) { global $pdo; $entiAbilitati = $_SESSION["utente"]->getEntiBeneficiari(); if ($_SESSION["ente"]->checkLimite(static::getModulo()) || $data["codice"] > 0) { $checkEnte = false; $return = false; foreach ($entiAbilitati as $ente) { if ($data["codice_ente"] == $ente["codice"]) { $checkEnte = true; break; } } if ($checkEnte) { $operazione = empty($data["codice"]) ? "INSERT" : "UPDATE"; if ($operazione == "INSERT") { $data["id"] = 1; $data["utente_creazione"] = $_SESSION["utente"]->codice ?? -1; $data["timestamp_creazione"] = date("Y-m-d H:i:s"); $sql = "SELECT id FROM " . static::getMainTable() . " ORDER BY id DESC LIMIT 0,1 "; $ris = $pdo->go($sql); if ($ris->rowCount() === 1) { $rec = $ris->fetch(PDO::FETCH_ASSOC); $data["id"] = $rec["id"] + 1; } } $salva = new salva(); $salva->debug = false; $salva->nome_tabella = static::getMainTable(); $salva->operazione = $operazione; $salva->oggetto = $data; $codice = $salva->save(); if ($codice !== false) { if ($operazione == "INSERT") { if ($_SESSION["utente"]->gerarchia > 15) { $utenti = [$_SESSION["utente"]->codice]; } if (!empty($utenti)) { foreach ($utenti as $utente) { $permesso = []; $permesso["sezione"] = static::getModulo(); $permesso["codice_elemento"] = $codice; $permesso["codice_gestore"] = $_SESSION["ente"]->codice; $permesso["funzione"] = "0"; $permesso["codice_utente"] = $utente; $salva = new salva(); $salva->debug = false; $salva->nome_tabella = "r_permessi"; $salva->operazione = "INSERT"; $salva->oggetto = $permesso; $salva->save(); } } } $elenco = static::init($codice); if (!empty($elenco)) { $elenco->addToLog($operazione,__("Dati preliminari") . " #{$codice}"); if (!empty($data["extra"])) { if (!empty($elenco)) { foreach($data["extra"] AS $key => $value) { $elenco->saveExtraInfo($key,$value); } } } } $bind = array(":codice" => $codice); $strsql = "DELETE FROM " . static::getCpvTable() . " WHERE codice_elenco = :codice"; $pdo->go($strsql, $bind); scriviLog(static::getCpvTable(), "DELETE", $pdo->getSQL()); if (!empty($data["cpv"])) { $data["cpv"] = array_unique($data["cpv"]); foreach ($data["cpv"] as $codice_categoria) { if ($codice_categoria != "") { $bind = array(":codice" => $codice, ":codice_categoria" => $codice_categoria, ":codice_utente" => $_SESSION["utente"]->codice); $strsql = "INSERT INTO " . static::getCpvTable() . " (codice_elenco,codice,utente_modifica) VALUES (:codice,:codice_categoria,:codice_utente)"; $pdo->go($strsql, $bind); scriviLog(static::getCpvTable(), "INSERT", $pdo->getSQL()); } } } if (!$_SESSION["ente"]->checkLimite(static::getModulo()) && empty($data["codice"])) { $_SESSION["ente"]->sendAlertLimite(static::getModulo()); } return $codice; } } } } } public function updateStato($stato) { if (!empty($this->mainTable)) { if ($this->info["stato"] < $stato) { $this->db->go("UPDATE {$this->mainTable} SET stato = :stato WHERE codice = :codice", [":stato" => $stato, ":codice" => $this->info["codice"]]); } if (isset($_SESSION["ente"])) { $_SESSION["ente"]->manageUpdates($this->modulo,$this->info["codice"],$this); } } } public function switchShowPartecipanti() { if ($this->canShowPartecipanti()) { $new = ($this->info["visualizza_elenco"] == "S") ? "N" : "S"; $this->db->go("UPDATE {$this->mainTable} SET visualizza_elenco = :stato WHERE codice = :codice", [":stato" => $new, ":codice" => $this->info["codice"]]); $this->addToLog(($this->info["visualizza_elenco"] == "S") ? "NASCONDI" : "VISUALIZZA",__("Elenco partecipanti")); return true; } } public function getManagerRegistro() { return new registriManager($this->getModulo(), $this->info["codice"]); } public function addToLog($operazione, $oggetto) { return $this->getManagerRegistro()->addToLog($operazione, $oggetto); } public function getLog($start = 0, $length = -1) { return $this->getManagerRegistro()->getLog($start, $length); } public function saveExtraInfo($chiave, $valore) { $extraInfo = $this->getExtraInfo(); $extraInfo[$chiave] = $valore; $this->info["extraInfo"] = $extraInfo = json_encode($extraInfo); $salva = new salva(); $salva->debug = false; $salva->nome_tabella = $this->mainTable; $salva->operazione = "UPDATE"; $salva->oggetto = ["codice" => $this->info["codice"], "extraInfo" => $extraInfo]; if (!empty($salva->save())) { return true; } return false; } public function getExtraInfo() { if (!empty($this->info["extraInfo"])) { return json_decode($this->info["extraInfo"], true); } return false; } public static function getStati() { global $beRoot; return jsonToArray($beRoot . "/" . static::getDirectory() . "/stati.json"); } public function getDestinatari() { $destinatari = $this->getPartecipanti([],[],0,-1) ?? []; return array_column($destinatari,"codice_operatore"); } public function getDestinatariInterni(bool $onlyCode = false) { $return = []; $utenti = $this->getManagerRegistro()->getUtentiCoinvolti(); if (!empty($utenti)) { $info = Utente::getInfoFromID($utenti); if (!empty($info)) { foreach($info AS $u) { if ($u["ruolo"] == "USR") { $return[] = ($onlyCode) ? $u["codice"] : $u["email"]; } } } } return $return; } protected static function initInstance($codice,$class) { if (!empty($codice) && !empty($_SESSION["ente"]) && !empty($_SESSION["utente"])) { global $pdo; $bind = [":codice" => $codice]; $sql = "SELECT * FROM " . static::getMainTable() . " WHERE codice = :codice "; if (! defined("__CMDS_JOB_EXEC") && ! $_SESSION["utente"]->fromHere()) { $sql .= " AND codice_ente = :codice_ente"; $bind[":codice_ente"] = $_SESSION["utente"]->codice_ente; } $elenco = $pdo->go($sql, $bind)->fetch(PDO::FETCH_ASSOC); if (!empty($elenco)) { if (!defined("__CMDS_JOB_EXEC")) { $continua = $_SESSION["utente"]->permission(static::getModulo(),$elenco["codice"],"0",true); } else { $continua = true; } if ($continua) { $extensionClass= self::extensionExists($class); if (!empty($extensionClass)) { $instance = new $extensionClass(); } else { $instance = new $class(); } $instance->info = $elenco; if (isset($instance->info) && $instance->info["stato"] == 20 && !empty($instance->info["scadenza"]) && strtotime($instance->info["scadenza"]) < time()) { $instance->updateStato(21); } return $instance; } } } return false; } private static function defaultAutenticationLevel() { return $_SESSION["ente"]->defaultAutenticationLevel(); } public function checkLock($id_cmd) { $return = true; $stato = $this->info["stato"]; if ($_SESSION["utente"]->readOnly) { return true; } else { if ($_SESSION["utente"]->hasSuperPowers()) { $return = false; } else { if (($stato >= 0) && !empty($id_cmd) && $_SESSION["utente"]->unlockSupporto()) { $cmd = $this->getInfoModulo($id_cmd); if ($cmd !== false) { $loa = $cmd["authenticationLevel"] ?? self::defaultAutenticationLevel(); if ($_SESSION["utente"]->authenticationLevel < $loa) { return true; } if (($stato >= $cmd["stato_minimo"] || $cmd["stato_minimo"] == null) && ($stato <= $cmd["stato_massimo"] || $cmd["stato_massimo"] === null)) { $return = false; } } } } } return $return; } public function soaObbligatorie() { return $this->info["obbligo_soa"] == "S"; } public function serviziTecniciObbligatori() { return $this->info["obbligo_servizi_tecnici"] == "S"; } public function soaRichiedibili() { $tipolgie = static::tipologieConSOA(); return (in_array($this->info["tipologia"],$tipolgie)); } public function serviziTecniciRichiedibili() { $tipolgie = static::tipologieConServiziTecnici(); return (in_array($this->info["tipologia"],$tipolgie)); } public function getForms() { return $this->db->go("SELECT codice_form FROM " . $this->getFormTable() . " WHERE codice_elenco = :elenco",[":elenco"=>$this->info["codice"]])->fetchAll(PDO::FETCH_COLUMN); } public function getRichiestaQuestionari() { $richieste = $this->getRichieste(); foreach($richieste AS $richiesta) { if ($richiesta["locked"] == "S") { return $richiesta; } } } public function associaForm($forms,string $requireSignature = "N") { $this->db->go("DELETE FROM " . $this->getFormTable() . " WHERE codice_elenco = :elenco",[":elenco"=>$this->info["codice"]]); $this->db->go("UPDATE ". $this->getMainTable(). " SET richiedi_firma = 'N' WHERE codice = :elenco",[":elenco"=>$this->info["codice"]]); $richiestaQuestionari = $this->getRichiestaQuestionari(); $deleteRequestQuestionari = false; if (!empty($forms)) { $salva = new salva(); $salva->debug = false; $salva->nome_tabella = $this->getFormTable(); $salva->operazione = "INSERT"; foreach($forms AS $form) { $salva->oggetto = ["codice_elenco"=>$this->info["codice"],"codice_form"=>$form]; $salva->save(); } if ($requireSignature == "S") { $this->db->go("UPDATE ". $this->getMainTable(). " SET richiedi_firma = 'S' WHERE codice = :elenco",[":elenco"=>$this->info["codice"]]); if (empty($richiestaQuestionari)) { $this->saveRichiesta([ "ordinamento" => 0, "titolo" => "Questionari sottoscritti", "descrizione" => "Carica la versione sottoscritta del PDF contenente i questionari compilati", "controllo" => "F", "locked" => "S" ]); } else if (isset($richiestaQuestionari["archiviato"]) && $richiestaQuestionari["archiviato"] == "S") { $this->db->go("UPDATE " . $this->richiesteTable . " SET archiviato = 'N' WHERE codice = :codice", [":codice"=>$richiestaQuestionari["codice"]]); } } else { $deleteRequestQuestionari = true; } } else { $deleteRequestQuestionari = true; } if ($deleteRequestQuestionari) { if (!empty($richiestaQuestionari)) { if (isset($richiestaQuestionari["archiviato"])) { $this->db->go("UPDATE " . $this->richiesteTable . " SET archiviato = 'S' WHERE codice = :codice", [":codice"=>$richiestaQuestionari["codice"]]); } else { $this->db->go("DELETE FROM " . $this->richiesteTable . " WHERE codice = :codice", [":codice"=>$richiestaQuestionari["codice"]]); } } } $this->valutaElaborazione(); } public function getRichieste() { $bind = [":codice" => $this->info["codice"]]; $sql = "SELECT {$this->richiesteTable}.* FROM {$this->richiesteTable} WHERE codice_elenco = :codice ORDER BY {$this->richiesteTable}.ordinamento, {$this->richiesteTable}.codice "; return $this->db->go($sql, $bind)->fetchAll(PDO::FETCH_ASSOC); } public function getRichiesta($codice) { $richieste = $this->getRichieste(); if (!empty($richieste)) { foreach($richieste AS $richiesta) { if ($richiesta["codice"] == $codice) { return $richiesta; } } } return false; } public function addDGUERequest() { if (!$this->checkLock("elaborazione") && $this->db->go("SELECT codice FROM {$this->richiesteTable} WHERE titolo = 'DGUE' AND codice_elenco = :codice", [":codice" => $this->info["codice"]]) ->rowCount() == 0 ) { $richiesta = []; $richiesta["ordinamento"] = 0; $richiesta["titolo"] = "DGUE"; $richiesta["descrizione"] = __("Documento di Gara Unico Europeo"); $richiesta["controllo"] = "F"; return $this->saveRichiesta($richiesta); } } public function deleteDGUERequest() { if (!$this->checkLock("elaborazione")) { $this->db->go("DELETE FROM {$this->richiesteTable} WHERE titolo = 'DGUE' AND codice_elenco = :codice", [":codice" => $this->info["codice"]]); } } public function saveRichiesta($richiesta,$allegati = []) { $richiesta["codice_elenco"] = $this->info["codice"]; $salva = new salva(); $salva->debug = false; $salva->nome_tabella = $this->richiesteTable; $salva->operazione = (!empty($richiesta["codice"])) ? "UPDATE" : "INSERT"; $salva->oggetto = $richiesta; $cod_richiesta = $salva->save(); if (!empty($cod_richiesta)) { if (!empty($allegati)) { foreach($allegati as $allegato) { filesManager::saveFile($allegato["filename"],$cod_richiesta,$this->getModulo()."-richiesta",$allegato["nome"] ?? "","A",$allegato["classificazione"] ?? ""); } } $this->addToLog($salva->operazione,__("Richiesta").": " . $richiesta["titolo"]); $this->valutaElaborazione(); return $cod_richiesta; } } public function valutaElaborazione() { if ($this->info["stato"] < 10) { if (!empty($this->getRichieste()) || !empty($this->getForms())) { $this->updateStato(10); } } } public function getManagerRichieste($partecipante) { $managerRichieste = new richiesteOE($this->modulo, $this->info["codice"],$partecipante); if (!empty($managerRichieste)) { $this->managerRichieste = $managerRichieste; } return $this->managerRichieste; } public function getPartecipanti($filters = [],$order = [], $start=0, $length = 1) { $bind = [":codice_elenco" => $this->info["codice"]]; $sql = "SELECT * FROM {$this->oeTable} WHERE codice_elenco = :codice_elenco AND conferma = 'S' "; if (!empty($filters["codice"])) { $sql .= " AND codice = :codice_partecipante "; $bind[":codice_partecipante"] = $filters["codice"]; } if (!empty($filters["stato"])) { switch($filters["stato"]) { case "nuovi": $sql .= " AND ammesso = 'N' AND valutato = 'N' "; break; case "aggiornamenti": $sql .= " AND ammesso = 'S' AND valutato = 'N' "; break; case "ammessi": $sql .= " AND ammesso = 'S' "; break; case "respinti": $sql .= " AND ammesso = 'N' AND valutato = 'S' "; break; case "integrazioni": $sql .= " AND integrazioni IS NOT NULL AND integrazioni <> 'N' "; break; default: break; } } if (!empty($filters["stato_integrazioni"])) { switch($filters["stato_integrazioni"]) { case "no-richieste": $sql .= " AND (integrazioni IS NULL OR integrazioni = 'N') "; break; case "richieste": $sql .= " AND integrazioni IS NOT NULL AND integrazioni <> 'N' "; break; case "no-risposte": $sql .= " AND integrazioni = 'S' "; break; case "risposte": $sql .= " AND integrazioni = 'R' "; break; default: break; } } $tmp = $this->db->go($sql, $bind)->fetchAll(PDO::FETCH_ASSOC); $return = []; if (!empty($tmp)) { $ids = array_column($tmp,"codice_operatore"); } if (!empty($ids)) { if (static::refPartecipante() == "operatore") { $infos = oeManager::getOE($ids); } else { $usrs = Utente::getInfoFromID($ids); $infos = []; if (!empty($usrs)) { foreach($usrs AS $usr) { $infos[$usr["codice"]] = $usr; } } } foreach($tmp AS $partecipazione) { $infoPartecipante = $infos[$partecipazione["codice_operatore"]]; $insert = true; if (!empty($filters["*"])) { $insert = false; if (static::refPartecipante() == "operatore") { if (stripos($infoPartecipante["codice_fiscale_impresa"],$filters["*"]) !== false || stripos($infoPartecipante["ragione_sociale"],$filters["*"]) !== false) { $insert = true; } } else { if (stripos($infoPartecipante["cf"],$filters["*"]) !== false || stripos($infoPartecipante["cognome"],$filters["*"]) !== false || stripos($infoPartecipante["nome"],$filters["*"]) !== false) { $insert = true; } } } if ($insert) { if (static::refPartecipante() == "operatore") { $partecipazione["codice_fiscale"] = $infoPartecipante["codice_fiscale_impresa"]; $partecipazione["ragione_sociale"] = $infoPartecipante["ragione_sociale"]; $partecipazione["ruolo"] = "OPE"; } else { $partecipazione["codice_fiscale"] = $infoPartecipante["cf"]; $partecipazione["ragione_sociale"] = $infoPartecipante["cognome"] . " " . $infoPartecipante["nome"]; $partecipazione["ruolo"] = $infoPartecipante["ruolo"]; } $badgeIntegrazioni = ""; if (isset($filters["stato"]) && $filters["stato"] != "integrazioni") { if($partecipazione["integrazioni"] == "S") { $badgeIntegrazioni = "Richiesta integrazione