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.
595 righe
18 KiB
595 righe
18 KiB
<? |
|
Class progetto { |
|
|
|
public $info; |
|
private $db; |
|
|
|
private function __construct() { |
|
global $pdo; |
|
$this->info = null; |
|
$this->db = $pdo; |
|
} |
|
|
|
static function pannelli($filters = null) |
|
{ |
|
$moduli = self::getModuli($filters); |
|
$tmp = []; |
|
foreach ($moduli as $modulo) { |
|
$tmp[] = $modulo["tipo"]; |
|
} |
|
$tmp = array_unique($tmp); |
|
if (!empty($tmp)) { |
|
$tipologie = []; |
|
global $config; |
|
$conf = jsonToArray($config["jsonFolder"] . "/progetti-tipologie.json"); |
|
foreach ($tmp as $tipo) { |
|
$tipologie[$tipo] = $conf[$tipo]; |
|
} |
|
return $tipologie; |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
static function getInfoModulo($radice) |
|
{ |
|
$return = false; |
|
if (!empty($radice)) { |
|
$moduli = self::getModuli(false); |
|
if (!empty($moduli[$radice])) { |
|
$return = $moduli[$radice]; |
|
$return["id"] = $radice; |
|
$return["titolo"] = __($return["titolo"]); |
|
$return["descrizione"] = __($return["descrizione"]); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
static function getModuli($filters = null) |
|
{ |
|
global $config; |
|
$moduli = jsonToArray($config["jsonFolder"] . "/progetti-panel.json"); |
|
$tmp = []; |
|
foreach ($moduli as $id_modulo => $modulo) { |
|
$insert = true; |
|
if (is_array($filters) && !empty($filters)) { |
|
foreach ($filters as $key => $value) { |
|
if ($modulo[$key] !== $value) { |
|
$insert = false; |
|
} |
|
} |
|
} |
|
if ($insert) { |
|
$tmp[$id_modulo] = $modulo; |
|
} |
|
$moduli = $tmp; |
|
} |
|
return $moduli; |
|
} |
|
|
|
private static function defaultAutenticationLevel() { |
|
return $_SESSION["ente"]->defaultAutenticationLevel(); |
|
} |
|
|
|
public function checkLock($id_cmd,$checkStato = null) |
|
{ |
|
$return = false; |
|
$loa = self::defaultAutenticationLevel(); |
|
if ($_SESSION["utente"]->authenticationLevel < $loa) { |
|
return true; |
|
} |
|
return $return; |
|
} |
|
|
|
public function getManagerMonitoraggio() { |
|
if (empty($this->managerMonitoraggio)) { |
|
$manager = new mop($this); |
|
if (!empty($manager)) { |
|
$this->managerMonitoraggio = $manager; |
|
} |
|
} |
|
return $this->managerMonitoraggio; |
|
} |
|
|
|
public function getManagerIncarichi() |
|
{ |
|
if (empty($this->managerIncarichi)) { |
|
$manager = new Incarichi("progetti", $this->info["codice"]); |
|
if (!empty($manager)) { |
|
$this->managerIncarichi = $manager; |
|
} |
|
} |
|
return $this->managerIncarichi; |
|
} |
|
|
|
public function getManagerRegistro() |
|
{ |
|
return new registriManager("progetti", $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 static function tipologie() { |
|
return [ |
|
"L" => "Lavori", |
|
"S" => "Servizi", |
|
"F" => "Forniture" |
|
]; |
|
} |
|
|
|
public static function getImmobili($codice_ente = null,$codice = null) { |
|
$where = ""; |
|
$bind = []; |
|
if (!isset($codice_ente)) { |
|
if (!$_SESSION["utente"]->fromHere()) { |
|
$codice_ente = $_SESSION["utente"]->codice_ente; |
|
} |
|
} |
|
if (!empty($codice_ente)) { |
|
$bind[":codice_ente"] = $codice_ente; |
|
$where = " WHERE codice_ente = :codice_ente "; |
|
} |
|
if (!empty($codice)) { |
|
if (!empty($where)) { |
|
$where .= " AND "; |
|
} else { |
|
$where = " WHERE "; |
|
} |
|
$bind[":codice"] = $codice; |
|
$where .= " codice = :codice "; |
|
} |
|
global $pdo; |
|
$return = $pdo->go("SELECT * FROM b_progetti_immobili {$where} ORDER BY descrizione ASC ",$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($codice)) { |
|
return $return[0]; |
|
} |
|
return $return; |
|
} |
|
|
|
public static function init($codice) { |
|
if (!empty($codice) && !empty($_SESSION["utente"]) && !empty($_SESSION["ente"])) { |
|
global $pdo; |
|
$bind = [":codice" => $codice]; |
|
$sql = "SELECT * FROM b_progetti WHERE codice = :codice "; |
|
if (!$_SESSION["utente"]->fromHere()) { |
|
$sql .= " AND codice_ente = :codice_ente"; |
|
$bind[":codice_ente"] = $_SESSION["utente"]->codice_ente; |
|
} |
|
$progetto = $pdo->go($sql, $bind)->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($progetto)) { |
|
$instance = new progetto(); |
|
$instance->info = $progetto; |
|
return $instance; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function saveCIG($cig) { |
|
$continua = true; |
|
if (!empty($cig["codice"])) { |
|
$continua = false; |
|
if (!empty($this->getCIG(["codice"=>$cig["codice"]]))) { |
|
$continua = true; |
|
} |
|
} |
|
if ($continua) { |
|
$cig["codice_progetto"] = $this->info["codice"]; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti_cig"; |
|
$salva->operazione = (empty($cig["codice"])) ? "INSERT" : "UPDATE"; |
|
$salva->oggetto = $cig; |
|
return $salva->save(); |
|
} |
|
} |
|
|
|
public static function save($data) |
|
{ |
|
global $pdo; |
|
$return = false; |
|
$operazione_generale = $operazione = empty($data["codice"]) ? "INSERT" : "UPDATE"; |
|
$expect = ["codice", "cup", "oggetto", "anno", "descrizione","area","tipologia", "importo", "codice_ente", "utente_creazione", "timestamp_creazione"]; |
|
if ($operazione == "INSERT") { |
|
$data["utente_creazione"] = $_SESSION["utente"]->codice ?? -1; |
|
$data["timestamp_creazione"] = date('d/m/Y H:i:s'); |
|
} |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti"; |
|
$salva->operazione = $operazione; |
|
$salva->oggetto = $data; |
|
$salva->expect = $expect; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
|
|
$bind = array(":codice" => $codice); |
|
$strsql = "DELETE FROM r_cpv_progetti WHERE codice_progetto = :codice"; |
|
$pdo->go($strsql, $bind); |
|
scriviLog("r_cpv_progetti", "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 r_cpv_progetti (codice_progetto,codice,utente_modifica) VALUES (:codice,:codice_categoria,:codice_utente)"; |
|
$pdo->go($strsql, $bind); |
|
scriviLog("r_cpv_progetti", "INSERT", $pdo->getSQL()); |
|
} |
|
} |
|
} |
|
|
|
if ($operazione_generale == "INSERT") { |
|
if ($_SESSION["utente"]->gerarchia > 15) { |
|
$utenti = [$_SESSION["utente"]->codice]; |
|
} |
|
if (!empty($utenti)) { |
|
foreach ($utenti as $utente) { |
|
$permesso = []; |
|
$permesso["sezione"] = "progetti"; |
|
$permesso["codice_elemento"] = $codice; |
|
$permesso["funzione"] = "0"; |
|
$permesso["codice_gestore"] = $_SESSION["ente"]->codice; |
|
$permesso["codice_utente"] = $utente; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "r_permessi"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = $permesso; |
|
$salva->save(); |
|
} |
|
} |
|
} |
|
|
|
$return = progetto::init($codice); |
|
if (empty($return)) { |
|
$return = -1; |
|
if ($operazione == "INSERT") { |
|
$pdo->go("DELETE FROM b_progetti WHERE codice = :codice", [":codice" => $codice]); |
|
} |
|
} else { |
|
$return->addToLog($operazione_generale, "Dati generali"); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
|
|
public function dichiaraIncompiuta() |
|
{ |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$this->info["codice"],"stato_programmazione"=>"I"]; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public function nonRiproposto() |
|
{ |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$this->info["codice"],"stato_programmazione"=>"A"]; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public function getDotazione($codice = null) { |
|
return self::getDotazioneProgetto($this->info["codice"],["codice"=>$codice]); |
|
} |
|
|
|
public function getCIG($filtri = null) { |
|
$bind = [":progetto"=>$this->info["codice"]]; |
|
$filters = ""; |
|
if (!empty($filtri["codice"])) { |
|
$filters .= " AND codice = :codice "; |
|
$bind[":codice"] = $filtri["codice"]; |
|
} |
|
if (!empty($filtri["cig"])) { |
|
$filters .= " AND cig = :cig "; |
|
$bind[":cig"] = $filtri["cig"]; |
|
} |
|
return $this->db->go("SELECT * FROM b_progetti_cig WHERE codice_progetto = :progetto {$filters} ORDER BY codice",$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public static function evaluateStepCIG($procedura) { |
|
$previsti = progetto::getOpzioni("monitoraggio","tipoProcedureAggiudicazione")[$procedura["procedura"]]["step"] ?? null; |
|
$status = "danger"; |
|
if (!empty($procedura["step"]) && !empty($previsti)) { |
|
$procedura["step"] = json_decode($procedura["step"],true); |
|
$status = "success"; |
|
$previsti = array_keys($previsti); |
|
foreach($previsti AS $idStep) { |
|
if (empty($procedura["step"][$idStep]["prevista"])) { |
|
$status = "warning"; |
|
} |
|
} |
|
} |
|
return $status; |
|
} |
|
|
|
public static function getOpzioni($contesto,$source,$version = null) { |
|
$path = ""; |
|
if (preg_match('/^[a-zA-Z0-9]+$/', $source)) { |
|
if ($contesto == "monitoraggio") { |
|
if (empty($version)) { |
|
$version = "latest"; |
|
} |
|
$path = __DIR__ . "/ws/monitoraggio/sources/{$version}/"; |
|
} else if ($contesto == "programmazione") { |
|
if (empty($version)) { |
|
$version = "latest"; |
|
} |
|
$path = __DIR__ . "/ws/programmazione/sources/{$version}/"; |
|
} else if ($contesto == "cup") { |
|
if (empty($version)) { |
|
$version = "latest"; |
|
} |
|
$path = __DIR__ . "/ws/cup/sources/{$version}/"; |
|
} |
|
if (!empty($path)) { |
|
$path .= $source . ".json"; |
|
if (file_exists($path)) { |
|
return jsonToArray($path); |
|
} |
|
} |
|
} |
|
} |
|
|
|
public static function availableInfoTypes() { |
|
return ["select","text","settore-cup","nuts","localizzazione-istat","textarea","geolocalizzazione","quadro-economico","advanced","iter-progetto"]; |
|
} |
|
|
|
public static function getKeyInfo($keyName) { |
|
$dictionary = jsonToArray(__DIR__."/utilities/info/dictionary.json"); |
|
$return = $dictionary[$keyName] ?? null; |
|
if (!empty($return)) { |
|
$return["key"] = $keyName; |
|
return $return; |
|
} |
|
} |
|
|
|
public function printForm($keyName) { |
|
$keyInfo = self::getKeyInfo($keyName); |
|
$values = $this->getInfo($keyName); |
|
include (__DIR__."/utilities/info/form-card.php"); |
|
} |
|
|
|
public function printFormWithKeys($keys) { |
|
foreach($keys AS $key) { |
|
$this->printForm($key); |
|
} |
|
} |
|
|
|
public function saveInfo($keyName,$data) { |
|
$keyInfo = self::getKeyInfo($keyName); |
|
if (!empty($keyInfo)) { |
|
$codici = []; |
|
if (!empty($data)) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti_info"; |
|
foreach($data AS $codice => $value) { |
|
$input = []; |
|
$input["codice_progetto"] = $this->info["codice"]; |
|
$input["key"] = $keyName; |
|
$input["codice"] = (is_numeric($codice)) ? $codice : null; |
|
if (is_array($value)) { |
|
$value = json_encode($value); |
|
} |
|
$input["value"] = $value; |
|
$salva->operazione = (empty($input["codice"])) ? "INSERT" : "UPDATE"; |
|
$salva->oggetto = $input; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
$codici[] = $codice; |
|
} |
|
} |
|
} |
|
$bind = [":progetto"=>$this->info["codice"], ":keyName" => $keyName]; |
|
$this->db->go("DELETE FROM b_progetti_info WHERE b_progetti_info.codice_progetto = :progetto AND b_progetti_info.key = :keyName AND codice NOT IN (" . implode(",",$codici) . ")",$bind); |
|
scriviLog("b_progetti_info","DELETE",$this->db->getSQL()); |
|
} |
|
} |
|
|
|
public function getInfo($keyName) { |
|
return self::getInfoProgetto($this->info["codice"],$keyName); |
|
} |
|
|
|
public function getCategorieMerceologiche() { |
|
return self::getCategorieMerceologicheProgetto($this->info["codice"]); |
|
} |
|
|
|
public static function getCategorieMerceologicheProgetto($codice_progetto) |
|
{ |
|
global $_state_cpvProgetto; |
|
if (empty($_state_cpvProgetto)) { |
|
global $pdo; |
|
$_state_cpvProgetto = $pdo->prepare("SELECT codice FROM r_cpv_progetti WHERE codice_progetto = :codice "); |
|
} |
|
$codici_categoria = []; |
|
$_state_cpvProgetto->execute(array(":codice" => $codice_progetto)); |
|
if ($_state_cpvProgetto->rowCount() > 0) { |
|
while ($categoria = $_state_cpvProgetto->fetch(PDO::FETCH_ASSOC)) { |
|
if (!empty($categoria)) { |
|
$codici_categoria[] = $categoria["codice"]; |
|
} |
|
} |
|
} |
|
$codici_categoria = array_unique($codici_categoria); |
|
return $codici_categoria; |
|
} |
|
|
|
public function generaCUI() { |
|
if (empty($this->info["cui"])) { |
|
$tipologie = ($this->info["tipologia"] == "L") ? "'L'" : "'S','F'"; |
|
$sql = "SELECT codice FROM b_progetti WHERE codice_ente = :ente AND anno = :anno AND tipologia IN ({$tipologie}) AND cui IS NOT NULL AND cui <> '' "; |
|
$bind = []; |
|
$bind[":ente"] = $this->info["codice_ente"]; |
|
$bind[":anno"] = $this->info["anno"]; |
|
$count = $this->db->go($sql,$bind)->rowCount(); |
|
$id = $count + 1; |
|
$cui = $this->info["tipologia"] . Ente::getInfoFromID($this->info["codice_ente"])[0]["cf"] . $this->info["anno"] . str_pad($id,5,"0",STR_PAD_LEFT); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_progetti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$this->info["codice"],"cui"=>$cui]; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
$this->addToLog("UPDATE",__("Generato CUI")); |
|
return $cui; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function getInfoProgetto($codice_progetto,$keyName) { |
|
$keyInfo = self::getKeyInfo($keyName); |
|
if (!empty($keyInfo)) { |
|
global $_progetInfoStatement; |
|
if (!isset($_progetInfoStatement)) { |
|
global $pdo; |
|
$_progetInfoStatement = $pdo->prepare("SELECT b_progetti_info.* FROM b_progetti_info WHERE b_progetti_info.codice_progetto = :progetto AND b_progetti_info.key = :keyName"); |
|
} |
|
$bind = [":progetto"=>$codice_progetto, ":keyName" => $keyName]; |
|
$_progetInfoStatement->execute($bind); |
|
if ($_progetInfoStatement->rowCount() > 0) { |
|
if (!empty($keyInfo["multiple"])) { |
|
return $_progetInfoStatement->fetchAll(PDO::FETCH_ASSOC); |
|
} else { |
|
return $_progetInfoStatement->fetch(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
} |
|
} |
|
|
|
public static function getDotazioneProgetto($codice_progetto,$filtri = null) { |
|
$bind = [":progetto"=>$codice_progetto]; |
|
$filters = ""; |
|
if (!empty($filtri["codice"])) { |
|
$filters .= " AND codice = :codice "; |
|
$bind[":codice"] = $filtri["codice"]; |
|
} |
|
if (!empty($filtri["anno"])) { |
|
$filters .= " AND anno = :anno "; |
|
$bind[":anno"] = $filtri["anno"]; |
|
} |
|
if (!empty($filtri["annoMaggioreDi"])) { |
|
$filters .= " AND anno > :annoMaggioreDi "; |
|
$bind[":annoMaggioreDi"] = $filtri["annoMaggioreDi"]; |
|
} |
|
if (!empty($filtri["annoMinoreDi"])) { |
|
$filters .= " AND anno < :annoMinoreDi "; |
|
$bind[":annoMinoreDi"] = $filtri["annoMinoreDi"]; |
|
} |
|
if (!empty($filtri["privata"])) { |
|
$filters .= " AND privata = :privata "; |
|
$bind[":privata"] = $filtri["privata"]; |
|
} |
|
global $pdo; |
|
return $pdo->go("SELECT * FROM b_progetti_dotazione WHERE codice_progetto = :progetto {$filters} ORDER BY anno",$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
} |
|
|
|
private static function moduliSuggerimenti() { |
|
$moduli = []; |
|
$moduli["gare"] = ["titolo"=>"Gare e affidamenti","url"=>"/backend/gare/progetti/suggestions.php"]; |
|
return $moduli; |
|
} |
|
|
|
public function suggerimenti() { |
|
$data = []; |
|
global $root; |
|
$moduli = self::moduliSuggerimenti(); |
|
$cup = $this->info["cup"]; |
|
if (!empty($moduli)) { |
|
foreach($moduli AS $modulo => $info) { |
|
if (!empty($info["url"])) { |
|
if (file_exists($root.$info["url"])) { |
|
include($root.$info["url"]); |
|
} |
|
} |
|
} |
|
} |
|
return $data; |
|
} |
|
} |
|
|
|
function quickInfoProgetto($codice_progetto,$keyName) { |
|
$return = progetto::getInfoProgetto($codice_progetto,$keyName); |
|
if (!empty($return) && (isset($return["value"]))) { |
|
return $return["value"]; |
|
} |
|
return ""; |
|
} |
|
|
|
function quickDotazioneProgetto($codice_progetto,$anno=null,$privata=null,$annoMaggioreDi = false,$onlyImmobili = false) { |
|
$filters = []; |
|
if (!empty($anno)) { |
|
$keyAnno = ($annoMaggioreDi) ? "annoMaggioreDi" : "anno"; |
|
$filters[$keyAnno] = $anno; |
|
} |
|
if (isset($privata)) { |
|
$filters["privata"] = $privata; |
|
} |
|
$return = progetto::getDotazioneProgetto($codice_progetto,$filters); |
|
if (!empty($return)) { |
|
$totale = 0; |
|
$tipologiaPrivata = []; |
|
foreach($return AS $dotazione) { |
|
if (!$onlyImmobili || $dotazione["codice_immobile"] > 0) { |
|
$totale += $dotazione["importo"]; |
|
if (!empty($privata) && $privata == "S") { |
|
$extraInfo = json_decode($dotazione["extraInfo"],true); |
|
$tipologiaPrivata[] = $extraInfo["tipologiaPrivata"]; |
|
} |
|
} |
|
} |
|
if (!empty($privata) && $privata == "S") { |
|
return ["totale"=>$totale,"tipologie"=>$tipologiaPrivata]; |
|
} else { |
|
return $totale; |
|
} |
|
} |
|
} |
|
|
|
function quickResponsabileProgetto($codice_progetto) { |
|
$return = Incarichi::getIncaricatiFromElement("progetti",$codice_progetto,14); |
|
if (empty($return)) { |
|
$return["cognome"] = quickInfoProgetto($codice_progetto,"legacy-rup-cognome"); |
|
$return["nome"] = quickInfoProgetto($codice_progetto,"legacy-rup-nome"); |
|
$return["codice_fiscale"] = quickInfoProgetto($codice_progetto,"legacy-rup-cf"); |
|
} else { |
|
$return = $return[0]; |
|
$return = array_merge($return,$return["extraInfo"]); |
|
} |
|
return $return; |
|
} |
|
?>
|
|
|