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.
525 righe
18 KiB
525 righe
18 KiB
<? |
|
class Communicator { |
|
|
|
public $attachment; |
|
public $codice_relazione; |
|
public $destinatari; |
|
public $comunicazione; |
|
public $codice_pec; |
|
public $oggetto; |
|
public $corpo; |
|
public $allegati; |
|
public $coda; |
|
public $codice_gara; |
|
public $codice_lotto; |
|
public $codice_ente; |
|
public $ente; |
|
public $sezione; |
|
public $intestazione; |
|
public $elaborazione_coda; |
|
public $root; |
|
public $config; |
|
public $configurazione; |
|
public $address; |
|
public $identifiers; |
|
public $utenti; |
|
public $type; |
|
public $codice_coda; |
|
public $comunicazione_tecnica; |
|
public $utenti_pec; |
|
public $enable_smtp; |
|
public $force_coda; |
|
private $class; |
|
|
|
function __construct() |
|
{ |
|
global $root, $config; |
|
$this->root = $root; |
|
$this->config = $config; |
|
$this->enable_smtp = $config["enable_smtp_send"]; |
|
$this->class = null; |
|
$this->type = null; |
|
$this->configurazione = array(); |
|
$this->codice_pec = -1; |
|
$this->coda = FALSE; |
|
$this->elaborazione_coda = FALSE; |
|
$this->comunicazione = FALSE; |
|
$this->address = array(); |
|
$this->codice_relazione = 0; |
|
$this->utenti = array(); |
|
$this->utenti_pec = array(); |
|
$this->codice_lotto = 0; |
|
$this->intestazione = TRUE; |
|
$this->allegati = null; |
|
$this->destinatari = ""; |
|
$this->attachment = array(); |
|
$this->comunicazione_tecnica = true; |
|
$this->force_coda = false; |
|
} |
|
|
|
public function send() |
|
{ |
|
if (empty($this->codice_ente) && isset($_SESSION["ente"])) { $this->codice_ente = $_SESSION["ente"]->codice; } |
|
|
|
if (! empty($this->codice_ente)) { |
|
|
|
global $pdo; |
|
|
|
$ente = $pdo->go("SELECT * FROM b_enti WHERE codice = :codice", [":codice" => $this->codice_ente]); |
|
if ($ente->rowCount() === 1) { |
|
|
|
$this->ente = $ente->fetch(PDO::FETCH_ASSOC); |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
require_once "{$this->root}/inc/communicator.default.class.php"; |
|
|
|
|
|
$this->class = new CommunicatorDefault($this, $pdo); |
|
|
|
if(! empty($this->ente["codice"]) && $this->enable_smtp && ($this->codice_pec >= 0 || $this->ente["force_bridge"] === "S")) { |
|
$extendedClass = Ente::getTenantExtensionPath($this->ente["codice"]) . DIRECTORY_SEPARATOR . "communicator.bridge.class.php"; |
|
if (file_exists($extendedClass)) { |
|
require_once $extendedClass; |
|
$class_name = "Communicator{$this->ente["codice"]}"; |
|
$this->class = new $class_name($this); |
|
} |
|
} |
|
|
|
return $this->class->send(); |
|
|
|
} |
|
|
|
public static function getDefaultAddress($codice_ente) { |
|
global $pdo; |
|
$sql = "SELECT pec FROM b_pec WHERE codice_ente = :codice_ente AND predefinita = 'S' AND attivo = 'S' AND eliminato = 'N'"; |
|
$pec = $pdo->go($sql,[":codice_ente"=>$codice_ente]); |
|
if ($pec->rowCount() === 1) { |
|
return $pec->fetch(PDO::FETCH_ASSOC)["pec"]; |
|
} |
|
return false; |
|
} |
|
|
|
public static function getPecAddress($codice,$codice_ente = null) { |
|
global $pdo; |
|
if (empty($codice_ente) && isset($_SESSION["ente"])) { $codice_ente = $_SESSION["ente"]->codice; } |
|
if (!empty($codice)) { |
|
$sql = "SELECT pec FROM b_pec WHERE codice = :codice AND codice_ente = :codice_ente AND attivo = 'S' AND eliminato = 'N'"; |
|
$ris = $pdo->go($sql,[":codice"=>$codice,":codice_ente"=>$codice_ente]); |
|
if ($ris->rowCount() === 1) { |
|
return $ris->fetch(PDO::FETCH_ASSOC)["pec"]; |
|
} |
|
} |
|
return self::getDefaultAddress($codice_ente); |
|
} |
|
|
|
public static function availablePEC($codice_ente=0) { |
|
$return = array(); |
|
global $pdo; |
|
if (empty($codice_ente) && !empty($_SESSION["ente"])) { |
|
$codice_ente = $_SESSION["ente"]->codice; |
|
} |
|
if (!empty($codice_ente)) { |
|
$bind = array(":codice_ente"=>$codice_ente); |
|
$strsql = "SELECT * FROM b_pec WHERE codice_ente = :codice_ente AND attivo = 'S' AND eliminato = 'N'"; |
|
$risultato = $pdo->go($strsql,$bind); |
|
if ($risultato->rowCount() > 0) { |
|
$return = $risultato->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function checkPermission(string $_input_sezione,int $_input_codice_elemento, $_input_sub_elemento = false) { |
|
$continua = $_SESSION["utente"]->permission($_input_sezione,$_input_codice_elemento); |
|
if (!$continua && !empty(Communicator::sezioniSpeciali()[$_input_sezione])) { |
|
$bypass = Communicator::sezioniSpeciali()[$_input_sezione]; |
|
$pathBypass = $bypass["check"]; |
|
if (file_exists($pathBypass)) { |
|
$continua = include($pathBypass); |
|
} |
|
} |
|
return $continua; |
|
} |
|
|
|
public static function getMyChats(Int $codice = null) { |
|
if (!empty($_SESSION["utente"]) && !empty($_SESSION["ente"])) { |
|
global $pdo; |
|
$sql = "SELECT b_chat.*, r_chat.letto |
|
FROM b_chat JOIN r_chat ON b_chat.codice = r_chat.codice_messaggio |
|
WHERE r_chat.codice_utente = :utente |
|
AND b_chat.codice_ente = :codice_ente "; |
|
if (!empty($codice)) { |
|
$bind[":codice"] = $codice; |
|
$sql .= " AND b_chat.codice = :codice "; |
|
} |
|
$sql .= " ORDER BY codice DESC"; |
|
$bind = [] ; |
|
$bind[":codice_ente"] = $_SESSION["ente"]->codice; |
|
$bind[":utente"] = $_SESSION["utente"]->codice; |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() > 0) { |
|
return $ris->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
} |
|
|
|
public static function listInitiativeChat(string $sezione,int $codice_elemento, $codice = false, $sub_elemento = false) { |
|
if (!empty($_SESSION["utente"]) && !empty($_SESSION["ente"]) && !empty($sezione)) { |
|
if (self::checkPermission($sezione,$codice_elemento,$sub_elemento)) { |
|
global $pdo; |
|
$sql = "SELECT * |
|
FROM b_chat |
|
WHERE sezione = :sezione |
|
AND codice_ente = :codice_ente |
|
AND elemento = :codice_elemento "; |
|
$bind = [] ; |
|
if ($sub_elemento !== false) { |
|
$bind[":sub_elemento"]=$sub_elemento; |
|
$sql .= " AND sub_elemento = :sub_elemento "; |
|
} |
|
$bind[":sezione"] = $sezione; |
|
$bind[":codice_ente"] = $_SESSION["ente"]->codice; |
|
$bind[":codice_elemento"] = $codice_elemento; |
|
if (!empty($codice)) { |
|
$bind[":codice"] = $codice; |
|
$sql .= " AND codice = :codice "; |
|
} |
|
$sql .= " ORDER BY codice DESC"; |
|
|
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() > 0) { |
|
return $ris->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
} |
|
} |
|
|
|
public static function sezioniSpeciali() { |
|
global $root; |
|
return [ |
|
"matchmaking" => [ |
|
"check"=>$root."/backend/matchmaking/partecipanti/_checkChat.php", |
|
"destinatari"=>$root."/backend/matchmaking/partecipanti/_destinatariChat.php", |
|
"directLink"=> "/matchmaking/dettaglio.php?codice={##--elemento--##}" |
|
] |
|
]; |
|
} |
|
|
|
public static function countUnreadInitiativeChat(string $sezione,int $codice_elemento, $sub_elemento = false) { |
|
if (!empty($_SESSION["utente"]) && !empty($_SESSION["ente"]) && !empty($sezione)) { |
|
if (self::checkPermission($sezione,$codice_elemento,$sub_elemento)) { |
|
global $pdo; |
|
$sql = "SELECT codice |
|
FROM b_chat |
|
WHERE sezione = :sezione |
|
AND codice_ente = :codice_ente AND elemento = :codice_elemento AND codice NOT IN (SELECT codice_messaggio FROM r_chat WHERE codice_utente = :codice_utente)"; |
|
$bind = [] ; |
|
if ($sub_elemento !== false) { |
|
$bind[":sub_elemento"]=$sub_elemento; |
|
$sql .= " AND sub_elemento = :sub_elemento "; |
|
} |
|
$bind[":sezione"] = $sezione; |
|
$bind[":codice_utente"] = $_SESSION["utente"]->codice; |
|
$bind[":codice_ente"] = $_SESSION["ente"]->codice; |
|
$bind[":codice_elemento"] = $codice_elemento; |
|
$ris = $pdo->go($sql . " ORDER BY codice DESC",$bind); |
|
return $ris->rowCount(); |
|
} |
|
} |
|
} |
|
|
|
|
|
public static function getMessage($codice) { |
|
global $pdo; |
|
if (isset($_SESSION["utente"])) { |
|
$messaggio = $pdo->go("SELECT * FROM b_comunicazioni WHERE codice = :codice AND eliminato = 'N' ",[":codice"=>$codice])->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($messaggio)) { |
|
if ($_SESSION["utente"]->gerarchia >= 100) { |
|
$check = $pdo->go("SELECT codice, r_comunicazioni_utenti.codice AS protocollo_interno, |
|
r_comunicazioni_utenti.timestamp AS timestamp_interno, |
|
r_comunicazioni_utenti.protocollo, |
|
r_comunicazioni_utenti.data_protocollo |
|
FROM r_comunicazioni_utenti WHERE codice_comunicazione = :codice AND codice_operatore = :codice_operatore", |
|
[":codice"=>$messaggio["codice"],":codice_operatore"=>$_SESSION["utente"]->oe["codice"]]); |
|
if ($check->rowCount() == 1) { |
|
$messaggio = $messaggio + $check->fetch(PDO::FETCH_ASSOC); |
|
return $messaggio; |
|
} |
|
} else { |
|
if ($_SESSION["utente"]->permission($messaggio["sezione"],$messaggio["codice_gara"])) { return $messaggio; } |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function listMessageOE($codice_operatore,$content=false,$filters=[],$order=[],$start=0,$limit=-1) { |
|
global $pdo; |
|
if (isset($_SESSION["utente"])) { |
|
if ($_SESSION["utente"]->gerarchia > 99) { |
|
$codice_operatore = $_SESSION["utente"]->oe["codice"]; |
|
} |
|
} |
|
|
|
$select = "b_comunicazioni.codice, b_comunicazioni.sezione, b_comunicazioni.codice_gara, b_comunicazioni.oggetto, b_comunicazioni.timestamp, b_comunicazioni.numero_protocollo, b_comunicazioni.data_protocollo "; |
|
if ($content) { $select = "*"; } |
|
$bind = [":codice_operatore"=>$codice_operatore,":codice_ente"=>$_SESSION["ente"]->codice]; |
|
$sql = "SELECT {$select}, |
|
r_comunicazioni_utenti.codice AS protocollo_interno, |
|
r_comunicazioni_utenti.timestamp AS timestamp_interno, |
|
r_comunicazioni_utenti.protocollo, |
|
r_comunicazioni_utenti.data_protocollo, |
|
r_comunicazioni_utenti.letto |
|
FROM b_comunicazioni |
|
JOIN r_comunicazioni_utenti ON b_comunicazioni.codice = r_comunicazioni_utenti.codice_comunicazione |
|
WHERE r_comunicazioni_utenti.codice_operatore = :codice_operatore AND b_comunicazioni.codice_ente = :codice_ente "; |
|
if (!empty($filters)) { |
|
$keys = ["oggetto"]; |
|
$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 (count($addWhere) > 0) { $sql .= " AND (" . implode(" OR ",$addWhere) . ") "; } |
|
if (isset($filters["codice"])) { |
|
$bind[":codice"] = (int)$filters["codice"]; |
|
$sql .= " AND codice = :codice "; |
|
} |
|
if (isset($filters["nonletto"])) { |
|
$sql .= " AND r_comunicazioni_utenti.letto = 'N' "; |
|
} |
|
} |
|
if (!empty($order)) { |
|
$keys = ["timestamp","codice","letto"]; |
|
$sortArray = []; |
|
foreach($keys AS $key) { |
|
if (isset($order[$key])) { |
|
if (strcmp($order[$key],"ASC") === 0) { |
|
$sortArray[] = "{$key} ASC"; |
|
} else { |
|
$sortArray[] = "{$key} DESC"; |
|
} |
|
} |
|
} |
|
if (count($sortArray) > 0) { |
|
$sql .= " ORDER BY " . implode(",",$sortArray) . ", codice DESC"; |
|
} |
|
} else { |
|
$sql .= " ORDER BY timestamp DESC"; |
|
} |
|
if (is_numeric($limit) && is_numeric($start) && $limit != -1) { |
|
$start = (int)$start; |
|
$limit = (int)$limit; |
|
$sql .= " LIMIT {$start}, {$limit}"; |
|
} |
|
$return = $pdo->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
return $return; |
|
} |
|
|
|
public static function listInitiativeMessage(string $sezione,int $codice_elemento, $codice = false, $content = false,$start=0,$limit=-1,$filtro_destinatario = null) { |
|
$return = array(); |
|
if ((!empty($_SESSION["utente"]) || defined("__CMDS_JOB_EXEC")) && !empty($_SESSION["ente"]) && !empty($sezione)) { |
|
$procedi = false; |
|
if (isset($_SESSION["utente"]) && $_SESSION["utente"]->permission($sezione,$codice_elemento)) { $procedi = true; } |
|
if ($procedi || defined("__CMDS_JOB_EXEC")) { |
|
global $pdo; |
|
$bind = [] ; |
|
$select = "b_comunicazioni.codice, b_comunicazioni.oggetto, b_comunicazioni.timestamp, b_comunicazioni.numero_protocollo, b_comunicazioni.data_protocollo "; |
|
$join = ""; |
|
$where = ""; |
|
if (!empty($filtro_destinatario)) { |
|
$join = " JOIN r_comunicazioni_utenti ON b_comunicazioni.codice = r_comunicazioni_utenti.codice_comunicazione "; |
|
$where = " AND r_comunicazioni_utenti.codice_operatore = :operatore "; |
|
$bind[":operatore"] = $filtro_destinatario; |
|
} |
|
if ($content) { $select = "b_comunicazioni.*"; } |
|
$sql = "SELECT {$select} |
|
FROM b_comunicazioni {$join} |
|
WHERE b_comunicazioni.eliminato = 'N' |
|
AND b_comunicazioni.sezione = :sezione |
|
AND b_comunicazioni.codice_gara = :codice_elemento |
|
AND b_comunicazioni.codice_ente = :codice_ente |
|
{$where} "; |
|
$bind[":codice_ente"]=$_SESSION["ente"]->codice; |
|
$bind[":sezione"] = $sezione; |
|
$bind[":codice_elemento"] = $codice_elemento; |
|
if (!empty($codice)) { |
|
$bind[":codice"] = $codice; |
|
$sql .= " AND b_comunicazioni.codice = :codice "; |
|
} |
|
$sql .= " ORDER BY b_comunicazioni.codice DESC "; |
|
if (is_numeric($limit) && is_numeric($start) && $limit != -1) { |
|
$start = (int)$start; |
|
$limit = (int)$limit; |
|
$sql .= " LIMIT {$start}, {$limit}"; |
|
} |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() > 0) { |
|
return $ris->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function getDestinatari(int $codice) |
|
{ |
|
global $pdo; |
|
|
|
if(!empty($codice)){ |
|
$sql = "SELECT b_operatori_economici.codice, b_operatori_economici.ragione_sociale, |
|
r_comunicazioni_utenti.codice AS protocollo_interno, |
|
r_comunicazioni_utenti.timestamp AS timestamp_interno, |
|
r_comunicazioni_utenti.protocollo, |
|
r_comunicazioni_utenti.data_protocollo, |
|
r_comunicazioni_utenti.ricevute, |
|
r_comunicazioni_utenti.pec |
|
FROM r_comunicazioni_utenti |
|
LEFT JOIN b_operatori_economici ON b_operatori_economici.codice = r_comunicazioni_utenti.codice_operatore |
|
WHERE r_comunicazioni_utenti.codice_comunicazione = :codice "; |
|
|
|
$ris = $pdo->prepare($sql); |
|
|
|
$ris->bindValue(":codice", $codice); |
|
$ris->execute(); |
|
|
|
if($ris->rowCount() > 0){ |
|
|
|
return $ris->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
|
|
return []; |
|
} |
|
|
|
|
|
public static function getMessagePDF(int $codice) |
|
{ |
|
$comunicazione = self::getMessage($codice); |
|
|
|
if(!empty($comunicazione)){ |
|
|
|
global $root; |
|
global $config; |
|
$enteInfo = $_SESSION["ente"]->getInfo(); |
|
|
|
$comunicazione["corpo"] = preg_replace('/(http.+)\/allegati\/open\.php\?codice\=/',"/allegati/open.php?codice=", $comunicazione["corpo"]); |
|
|
|
if($_SESSION["utente"]->gerarchia < 100){ |
|
$comunicazione['destinatari'] = Communicator::getDestinatari($comunicazione['codice']); |
|
} |
|
|
|
$html = ob_get_clean(); |
|
|
|
ob_start(); |
|
|
|
include($root.'/comunicazioni/partial/pdf.php'); |
|
|
|
$html = ob_get_clean(); |
|
|
|
$pdf = documentConverter::getPDFWithWKHTML($html, 'A4', 'portrait', false); |
|
|
|
return $pdf; |
|
} |
|
|
|
return []; |
|
} |
|
|
|
|
|
public static function getPDFListInitiativeMessage(string $modulo,int $codice_elemento) |
|
{ |
|
|
|
$comunicazioni = self::listInitiativeMessage($modulo,$codice_elemento,false,false,0,-1,null); |
|
|
|
if(!empty($comunicazioni)){ |
|
|
|
global $root; |
|
global $config; |
|
$enteInfo = $_SESSION["ente"]->getInfo(); |
|
|
|
|
|
$html = ob_get_clean(); |
|
ob_start(); |
|
include_once("$root/comunicazioni/partial/elenco-pdf.php"); |
|
$html = ob_get_clean(); |
|
$pdf = documentConverter::getPDFWithWKHTML($html, 'A4', 'landscape', false); |
|
|
|
return $pdf; |
|
} |
|
|
|
return []; |
|
} |
|
|
|
public static function getZipListInitiativeMessage(string $modulo,int $codice_elemento) |
|
{ |
|
|
|
$comunicazioni = self::listInitiativeMessage($modulo,$codice_elemento,false,false,0,-1,null); |
|
|
|
if(!empty($comunicazioni)){ |
|
|
|
global $root; |
|
global $config; |
|
$enteInfo = $_SESSION["ente"]->getInfo(); |
|
|
|
$string = bin2hex(random_bytes(5)); |
|
|
|
$path = "{$config["chunk_folder"]}/{$enteInfo['codice']}/esportazoni-comunicazioni-pdf/{$string}"; |
|
|
|
if(!is_dir($path)){ |
|
mkdir("$path", 0755, true); |
|
} |
|
|
|
$z = "{$config["chunk_folder"]}/{$enteInfo['codice']}/esportazoni-comunicazioni-pdf/{$string}/esportazioni-comunicazioni.zip"; |
|
|
|
$arrFiles = []; |
|
|
|
foreach ($comunicazioni as $key => $comunicazione) { |
|
$pdf = self::getMessagePDF($comunicazione['codice']); |
|
|
|
if(!empty($pdf)){ |
|
|
|
$fileName = "comunicazione-{$comunicazione['codice']}.pdf"; |
|
$newPDF = fopen("{$path}/$fileName", "w"); |
|
fwrite($newPDF, $pdf); |
|
fclose($newPDF); |
|
|
|
$arrFiles[] = $fileName; |
|
|
|
} |
|
} |
|
|
|
$zip = new ZipArchive; |
|
|
|
if ($zip->open($z, ZipArchive::CREATE) === TRUE) { |
|
foreach ($arrFiles as $file) { |
|
$zip->addFile("{$path}/$file", basename($file)); |
|
} |
|
} |
|
|
|
$zip->close(); |
|
|
|
if(file_exists($z) && filesize($z) > 0) { |
|
unset($_SESSION["communicatoriArchivePaths"][$_GET["tokenEsportazione"]]); |
|
$_SESSION["communicatoriArchivePaths"][$_GET["tokenEsportazione"]] = $z; |
|
return true; |
|
} |
|
|
|
} |
|
|
|
return []; |
|
} |
|
} |
|
?>
|
|
|