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.
336 righe
8.5 KiB
336 righe
8.5 KiB
<? |
|
class publicRispostaDocumentale extends rispostaDocumentale{ |
|
|
|
/** |
|
* Elimina tutti i campi null |
|
* Inserire in una funzione dove c'è l'insert o l'update |
|
* |
|
* @var Array; |
|
*/ |
|
protected function purifyCampi() |
|
{ |
|
$array = []; |
|
|
|
if (!empty($this->info)) { |
|
foreach ($this->info as $key => $value) { |
|
if (!empty($value)) { |
|
$array[$key] = $value; |
|
} |
|
} |
|
|
|
$this->info = $array; |
|
} |
|
|
|
return $array; |
|
} |
|
|
|
|
|
public static function init($codice = null) |
|
{ |
|
if(!empty($_SESSION["ente"]) && !empty($_SESSION["utente"])){ |
|
|
|
$instance = new publicRispostaDocumentale(); |
|
|
|
if (!empty($codice) && is_numeric($codice) ) { |
|
global $pdo; |
|
|
|
$bind[':codice'] = $codice; |
|
|
|
$sql = "SELECT b_contratti_risposta_documentale.* |
|
FROM b_contratti_risposta_documentale |
|
JOIN b_contratti_richiesta_documentale ON b_contratti_risposta_documentale.codice_richiesta = b_contratti_richiesta_documentale.codice |
|
WHERE b_contratti_risposta_documentale.codice = :codice"; |
|
|
|
if(!empty($_SESSION['utente']->oe['codice'])){ |
|
$bind[':codice_oe'] = $_SESSION['utente']->oe['codice']; |
|
$sql .= " AND b_contratti_richiesta_documentale.codice_oe = :codice_oe "; |
|
} |
|
|
|
$risposta = $pdo->go($sql, $bind)->fetch(PDO::FETCH_ASSOC); |
|
|
|
if (!empty($risposta)) { |
|
$instance->info = $risposta; |
|
return $instance; |
|
} |
|
} |
|
|
|
return $instance; |
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
/** |
|
* Salva la risposta |
|
* @var $this |
|
*/ |
|
public function save() |
|
{ |
|
$this->purifyCampi(); |
|
|
|
$salva = new salva(); |
|
$salva->debug = false; |
|
$salva->nome_tabella = "b_contratti_risposta_documentale"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = $this->info; |
|
|
|
$codice = $salva->save(); |
|
|
|
if (!empty($codice)) { |
|
return self::init($codice); |
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
/** |
|
* Salva il file della risposta |
|
* @var string |
|
*/ |
|
public function saveFile($filechunk) |
|
{ |
|
|
|
if (!empty($filechunk)) { |
|
$chunkPath = self::getPath($filechunk); |
|
|
|
if (!empty($chunkPath)) { |
|
|
|
adaptMemoryLimitToFile($chunkPath,-1); |
|
ini_set("max_execution_time","600"); |
|
|
|
|
|
$password = generateStrongPassword(); |
|
|
|
$file = [ |
|
'codice' => $this->info['codice'], |
|
'content' => base64_encode($password), |
|
'nomeFile' => sanitize_string($filechunk), |
|
'mime' => getTypeAndExtension($chunkPath)['type'], |
|
'md5' => self::getHash($chunkPath,'md5'), |
|
'sha1' => self::getHash($chunkPath, 'sha1'), |
|
'sha256' => self::getHash($chunkPath, 'sha256'), |
|
]; |
|
|
|
$dir = self::getDir('risposta-documentale', $this->info['codice']); |
|
$path = $dir . "/" . $file["sha1"]; |
|
$content = simple_encrypt(file_get_contents($chunkPath),$password); |
|
|
|
if ( !empty($file['content']) && file_put_contents($path,$content) ) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
$salva->nome_tabella = "b_contratti_risposta_documentale"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = $file; |
|
|
|
$codice = $salva->save(); |
|
|
|
if(!empty($codice)){ |
|
return self::init($this->info['codice']); |
|
} |
|
} |
|
} |
|
} |
|
|
|
return false; |
|
} |
|
|
|
public function getFile() |
|
{ |
|
if (!empty($this->info['codice'])) { |
|
$return['codice'] = $this->info['codice']; |
|
$return['sha1'] = $this->info['sha1']; |
|
$return['dir'] = self::getDir('risposta-documentale',$this->info['codice']); |
|
$return['file'] = self::getFilePath('risposta-documentale',$return); |
|
$return['content'] = $this->info['content']; |
|
$return['mime'] = $this->info['mime']; |
|
$return['nomeFile'] = $this->info['nomeFile']; |
|
return $return; |
|
} |
|
|
|
return null; |
|
} |
|
|
|
|
|
public static function getPath($filechunk) |
|
{ |
|
global $config; |
|
|
|
if (!empty($filechunk)) { |
|
|
|
$chunkFolder = $config['chunk_folder']; |
|
$codice = $_SESSION['utente']->codice; |
|
|
|
return "$chunkFolder/$codice/$filechunk"; |
|
|
|
} |
|
|
|
return null; |
|
} |
|
|
|
public static function getHash($chunkPath, $algorithm) |
|
{ |
|
if (!empty($chunkPath) && !empty($algorithm)) { |
|
|
|
$content = file_get_contents($chunkPath); |
|
|
|
if (!empty($content)) { |
|
return hash($algorithm, $content); |
|
} |
|
|
|
} |
|
|
|
return null; |
|
} |
|
|
|
public static function getDir($modulo, $codice) |
|
{ |
|
global $config; |
|
|
|
$path = "{$config["mediaFolder"]}/{$_SESSION["ente"]->codice}/{$modulo}/{$codice}"; |
|
|
|
if (!is_dir($path)) { |
|
mkdir($path,0777,true); |
|
} |
|
|
|
if (is_dir($path)) { |
|
return $path; |
|
} |
|
} |
|
|
|
public static function getFilePath($modulo, $relazione) |
|
{ |
|
|
|
$dir = self::getDir($modulo, $relazione["codice"]); |
|
|
|
if (!empty($dir) && !empty($relazione["sha1"])) { |
|
return "{$dir}/{$relazione["sha1"]}"; |
|
} |
|
} |
|
|
|
/** |
|
* Ottieni la classe documentale associata alla risposta |
|
* |
|
* @var string || null |
|
*/ |
|
public function getDocumentaleAssociato($campo = null) |
|
{ |
|
|
|
if (!empty($this->info['codice_richiesta'])) { |
|
global $pdo; |
|
|
|
$bind = [ |
|
':codice' => $this->info['codice_richiesta'], |
|
]; |
|
|
|
$sql = "SELECT codice, codice_classe_documentale FROM b_contratti_richiesta_documentale WHERE codice = :codice AND soft_delete = 'N' "; |
|
|
|
$ris = $pdo->go($sql, $bind)->fetch(PDO::FETCH_ASSOC); |
|
|
|
if (!empty($ris['codice_classe_documentale'])) { |
|
|
|
$bind = [ |
|
'codice' => $ris['codice_classe_documentale'] |
|
]; |
|
|
|
$sql = "SELECT codice, titolo, descrizione FROM b_classe_documentale WHERE codice = :codice AND soft_delete = 'N' "; |
|
|
|
$ris2 = $pdo->go($sql, $bind)->fetch(PDO::FETCH_ASSOC); |
|
|
|
if (!empty($ris2['codice'])) { |
|
|
|
if(empty($campo)){ |
|
return $ris2; |
|
}elseif (!empty($campo) && !empty($ris2[$campo])) { |
|
return $ris2[$campo]; |
|
}else{ |
|
return __('Errore nella visualizzazione della classe documentale'); |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
|
|
|
|
/** |
|
* La invia comunicazione invia le richieste per tutte le modifiche fatte lato OE |
|
* |
|
* @var Int $codice_contratto |
|
* @var Array $filters |
|
*/ |
|
public function inviaComunicazione($codice_contratto, $filtersOE = [], $filtersSA = []) |
|
{ |
|
|
|
$managerContratto = publicStipula::init($codice_contratto); |
|
|
|
if(!empty($managerContratto->info['codice'])){ |
|
|
|
$destinatari = $_SESSION["utente"]->oe['codice']; // codice operatore economico |
|
$oggetto = "Richiesta Documentale contratti"; |
|
$corpo = __("Inviata risposta ad una richiesta documentale"); |
|
|
|
// filtri per OE |
|
if(!empty($filtersOE)){ |
|
if(!empty($filtersOE['sha256'])){ |
|
$corpo .= '<br><br>' . __('Hash File: ') . $filtersOE['sha256']; |
|
} |
|
} |
|
|
|
//email per OE |
|
$mailer = new Communicator(); |
|
$mailer->oggetto = $oggetto; |
|
$mailer->corpo = $corpo; |
|
$mailer->codice_pec = $managerContratto->info['codice_pec'] ?? 0; //utilizzare codice pec del contratto b_contratti |
|
$mailer->comunicazione = true; |
|
$mailer->sezione = "contratti"; |
|
$mailer->codice_gara = $codice_contratto; |
|
$mailer->coda = true; |
|
$mailer->destinatari = $destinatari; |
|
$mailer->send(); |
|
|
|
|
|
// filtri per oe |
|
if (!empty($filtersSA)) { |
|
if (!empty($filtersSA['corpo'])) { |
|
$corpo = $filtersSA['corpo']; |
|
} |
|
if (!empty($filtersSA['corpo2'])) { |
|
$corpo .= $filtersSA['corpo2']; |
|
} |
|
if(!empty($filtersSA['sha256'])){ |
|
$corpo .= '<br><br>' . __('Hash File: ') . $filtersSA['sha256']; |
|
} |
|
} |
|
|
|
$corpo .= "<br><br>" . $_SESSION["config"]["link_sito"]."/backend/contratti/documentale/panel.php?codice={$managerContratto->info['codice']}"; |
|
|
|
//email per SA |
|
$mailer->comunicazione = false; |
|
$mailer->corpo = $corpo; |
|
$mailer->codice_pec = -1; |
|
$destinatari = [Communicator::getPecAddress($managerContratto->info["codice_pec"])]; |
|
$tmp = Ente::getUtentiFromModulo("contratti",$_SESSION["ente"]->codice,"",$managerContratto->info["codice"]); |
|
$utenti = Utente::getInfoFromID($tmp); |
|
if (!empty($utenti)) { |
|
foreach($utenti AS $utente) { |
|
$destinatari[] = $utente["email"]; |
|
} |
|
} |
|
|
|
$mailer->destinatari = $destinatari; |
|
$mailer->send(); |
|
|
|
return true; |
|
|
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
} |
|
?>
|
|
|