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.
129 righe
4.4 KiB
129 righe
4.4 KiB
<? |
|
class registriManager { |
|
|
|
private $gestore; |
|
private $modulo; |
|
private $elemento; |
|
private $db; |
|
private $sub; |
|
|
|
public static function moduliAbilitati() { |
|
$return = []; |
|
$return["pcp"] = ["titolo"=>"Appalti pre-commerciali","script"=>"/pcp/log/init.php"]; |
|
$return["gare"] = ["titolo"=>"Gare e affidamenti","script"=>"/gare/log/init.php"]; |
|
$return["concorsi"] = ["titolo"=>"Concorsi progettazione","script"=>"/concorsi/log/init.php"]; |
|
$return["progetti"] = ["titolo"=>"Progetti","script"=>"/progetti/log/init.php"]; |
|
$return["anac"] = ["titolo"=>"ANAC","script"=>"/anac/log/init.php"]; |
|
$return["cpn"] = ["titolo"=>"Contratti Pubblici Nazionali","script"=>"/cpn/log/init.php"]; |
|
$return["omc"] = ["titolo"=>"Consultazioni di mercato","script"=>"/omc/log/init.php"]; |
|
$return["albo_fornitori"] = ["titolo"=>"Albo fornitori","script"=>"/albo_fornitori/log/init.php"]; |
|
$return["matchmaking"] = ["titolo"=>"Fabbisogni innovazione","script"=>"/matchmaking/log/init.php"]; |
|
$return["albi_commissione"] = ["titolo"=>"Albi Commissione","script"=>"/albi_commissione/log/init.php"]; |
|
return $return; |
|
} |
|
|
|
|
|
public function __construct($modulo,$codice_elemento) { |
|
if (!empty(self::moduliAbilitati()[$modulo])) { |
|
if (isset($_SESSION["ente"])) { |
|
global $pdo; |
|
$this->gestore = $_SESSION["ente"]->codice; |
|
$this->modulo = $modulo; |
|
$this->elemento = $codice_elemento; |
|
$this->db = $pdo; |
|
return $this; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getInfo() { |
|
global $beRoot; |
|
$path = $beRoot . self::moduliAbilitati()[$this->modulo]["script"]; |
|
if (file_exists($path)) { |
|
include($path); |
|
return $return; |
|
} |
|
return false; |
|
} |
|
|
|
public function printTable() { |
|
include(__DIR__."/backend-table.php"); |
|
} |
|
|
|
public function addToLog($operazione,$oggetto,$sub = 0) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_registri"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = ["modulo"=>$this->modulo,"codice_elemento"=>$this->elemento,"sub"=>$sub,"codice_gestore"=>$this->gestore,"operazione"=>$operazione,"oggetto"=>$oggetto]; |
|
if (!empty($salva->save())) { return true; } |
|
return false; |
|
} |
|
|
|
public function getLog($start=0,$length=-1) { |
|
$sql = "SELECT * FROM b_registri WHERE modulo = :modulo AND codice_elemento = :codice_elemento "; |
|
$utentiMonitoraggio = Utente::getUtentiMonitoraggio(); |
|
if (!empty($utentiMonitoraggio)) { |
|
$sql .= " AND utente_modifica NOT IN (" . implode(",",$utentiMonitoraggio). ") "; |
|
} |
|
$sql .= "ORDER BY codice DESC"; |
|
$limit = ""; |
|
if (is_numeric($start) && is_numeric($length) && $length > 0) { |
|
$start = (int)$start; |
|
$length = (int)$length; |
|
$limit = " LIMIT {$start}, {$length}"; |
|
} |
|
return $this->db->go($sql.$limit,[":modulo"=>$this->modulo,":codice_elemento"=>$this->elemento])->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public function getUtentiCoinvolti() { |
|
$logs = $this->getLog(); |
|
if (!empty($logs)) { |
|
$utenti = array_column($logs,"utente_modifica"); |
|
if (!empty($utenti)) { |
|
$utenti = array_unique($utenti); |
|
return $this->cleanResult($utenti); |
|
} |
|
} |
|
} |
|
|
|
public function getUtentiCoinvoltiConRuolo(string $ruolo, bool $onlyCode = false) { |
|
$return = []; |
|
$utenti = $this->getUtentiCoinvolti(); |
|
if (!empty($utenti)) { |
|
$info = Utente::getInfoFromID($utenti); |
|
if (!empty($info)) { |
|
foreach($info AS $u) { |
|
if ($u["ruolo"] === $ruolo) { |
|
$return[] = ($onlyCode) ? $u["codice"] : $u["email"]; |
|
} |
|
} |
|
} |
|
} |
|
return $this->cleanResult($return); |
|
} |
|
|
|
/** |
|
* Rimuove i riferimenti relativi alle utenze di monitoragio |
|
* |
|
* @param array $data: I dati da pulire |
|
* @return Array |
|
*/ |
|
private static function cleanResult(Array $data) : Array { |
|
$utentiMonitoraggio = Utente::getUtentiMonitoraggio(); |
|
$return = []; |
|
if (!empty($utentiMonitoraggio)) { |
|
foreach($data AS $r) { |
|
if (!in_array($r["utente_modifica"] ?? -1,$utentiMonitoraggio)) { |
|
$return[] = $r; |
|
} |
|
} |
|
} else { |
|
$return = $data; |
|
} |
|
return $return; |
|
} |
|
} |
|
?>
|