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.
168 righe
5.1 KiB
168 righe
5.1 KiB
<? |
|
|
|
class avvisiProcedura { |
|
|
|
public $modulo; |
|
public $elemento; |
|
public $sub; |
|
public $returnURL; |
|
private $codice_ente; |
|
private $db; |
|
|
|
public function __construct($codice_ente,$modulo = 0,$elemento=0,$sub=0) { |
|
global $pdo; |
|
$this->db = $pdo; |
|
$this->codice_ente = $codice_ente; |
|
$this->modulo = $modulo; |
|
$this->elemento = $elemento; |
|
$this->sub = $sub; |
|
} |
|
|
|
public function printEditor() { |
|
include(__DIR__."/backend-table.php"); |
|
} |
|
|
|
public function getAvvisiHP() { |
|
return $this->getAvvisi("S",["homepage"=>true]); |
|
} |
|
|
|
public function getAvvisi($attivi="S",$filters=[],$order=[],$start=0,$limit=-1) { |
|
$sql = "SELECT * FROM b_avvisi WHERE codice_ente = :codice_ente AND soft_delete = 'N' "; |
|
$bind = [":codice_ente"=>$this->codice_ente]; |
|
if (!empty($this->modulo)) { |
|
$bind[":modulo"] = $this->modulo; |
|
$sql .= " AND modulo = :modulo " ; |
|
} |
|
if (!empty($this->elemento)) { |
|
$bind[":elemento"] = $this->elemento; |
|
$sql .= " AND codice_elemento = :elemento " ; |
|
} |
|
if (!empty($this->sub)) { |
|
$bind[":sub"] = $this->sub; |
|
$sql .= " AND sub = :sub " ; |
|
} |
|
if ($attivi === "S" || $attivi === "I") { |
|
$sql .= " AND (attivo = 'S' OR attivo = 'I') "; |
|
if ($attivi === "S") { |
|
$sql .= " AND data <= now() "; |
|
} |
|
} |
|
if (!empty($filters)) { |
|
$keys = ["titolo","testo"]; |
|
$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)) { $sql .= " AND (" . implode(" OR ",$addWhere) . ") "; } |
|
if (isset($filters["codice"])) { |
|
$bind[":codice"] = (int)$filters["codice"]; |
|
$sql .= " AND codice = :codice "; |
|
} |
|
if (isset($filters["homepage"])) { |
|
$sql .= " AND data_homepage > now()"; |
|
} |
|
} |
|
if (!empty($order)) { |
|
$keys = ["timestamp","data","codice"]; |
|
$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)) { |
|
$sql .= " ORDER BY " . implode(",",$sortArray); |
|
} |
|
} else { |
|
$sql .= " ORDER BY data DESC"; |
|
} |
|
if (is_numeric($limit) && is_numeric($start) && $limit != -1) { |
|
$start = (int)$start; |
|
$limit = (int)$limit; |
|
$sql .= " LIMIT {$start}, {$limit}"; |
|
} |
|
return $this->db->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public function printPublic() { |
|
$avvisi = $this->getAvvisi(); |
|
$printModulo = false; |
|
if (!empty($avvisi)) { |
|
foreach($avvisi AS $avviso) { |
|
include(__DIR__."/public-view.php"); |
|
} |
|
} |
|
} |
|
|
|
public function saveAvviso($avviso) { |
|
$avviso["codice_ente"] = $_SESSION["ente"]->codice; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_avvisi"; |
|
$salva->operazione = (is_numeric($avviso["codice"])) ? "UPDATE" : "INSERT"; |
|
$salva->oggetto = $avviso; |
|
$codice = $salva->save(); |
|
if (!empty($codice) && isset($avviso["allegato-avviso"])) { |
|
foreach($avviso["allegato-avviso"] as $allegato) { |
|
filesManager::saveFile($allegato["filename"],$codice,"avvisi",$allegato["nome"] ?? "","A",$allegato["classificazione"] ?? ""); |
|
} |
|
} |
|
return $codice; |
|
} |
|
|
|
public function sendAvviso($codice) { |
|
global $beRoot; |
|
if (file_exists($beRoot.$this->modulo."/avvisi/send.php")) { |
|
include($beRoot.$this->modulo."/avvisi/send.php"); |
|
} |
|
} |
|
|
|
public static function verifyPublic($avviso) { |
|
$return = false; |
|
global $beRoot; |
|
if (file_exists($beRoot.$avviso["modulo"]."/avvisi/verifyPublic.php")) { |
|
include($beRoot.$avviso["modulo"]."/avvisi/verifyPublic.php"); |
|
} |
|
return $return; |
|
} |
|
|
|
public function printHP() { |
|
$tmp = $this->getAvvisiHP(); |
|
$printModulo = true; |
|
if (!empty($tmp)) { |
|
$avvisi = []; |
|
$verified = []; |
|
foreach($tmp AS $avviso) { |
|
if (!isset($verified[$avviso["modulo"]][$avviso["codice_elemento"]][$avviso["sub"]])) { |
|
$continua = static::verifyPublic($avviso); |
|
$verified[$avviso["modulo"]][$avviso["codice_elemento"]][$avviso["sub"]] = $continua; |
|
} else { |
|
$continua = $verified[$avviso["modulo"]][$avviso["codice_elemento"]][$avviso["sub"]]; |
|
} |
|
if ($continua) { |
|
$avvisi[] = $avviso; |
|
} |
|
} |
|
} |
|
if (!empty($avvisi)) { |
|
foreach($avvisi AS $avviso) { |
|
include(__DIR__."/public-view.php"); |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
?>
|