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.
 
 
 

411 righe
18 KiB

<?php
require_once "IDataClass.php";
/**
* Description of Allegati
*
* @author Anselmo
*/
class Allegati extends DataClass {
//put your code here
const TABLE_NAME = "ALLEGATI";
const SEQ_NAME = "ALLEGATI_ID_SEQ";
public $ID = 0; //PK
public $ID_DOMANDA = 0;
public $TIPO_DOCUMENTO = 0;
public $ID_DOCUMENTO = 0; //FK
public $FILEPATH = "";
public $FILESIZE = "";
public $DATA_REGISTRAZIONE = null;
public $CANCELLATO = 0;
public $NOTE = "";
public $NOMEFILEORIGINALE = "";
public $HASH_FILE = "";
public $identificativo = 0;
public $documento_bando = array();
public function __construct($src = null) {
global $con;
if ($src == null)
return;
if (is_array($src)) {
if (isset($src['ID']) && $src['ID'] > 0) {
$this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src);
} else {
$this->_loadByRow($src, $stripSlashes);
}
} elseif (intval($src)) {
$this->_loadById($src, self::TABLE_NAME, true);
}
$this->loadTipoDocumentoBando();
}
public static function ListByDomanda($id_domanda = 0) {
global $con;
$return = array();
if (intval($id_domanda) > 0) {
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID_DOMANDA=:id_domanda AND CANCELLATO=0 ORDER BY TIPO_DOCUMENTO, ID";
$query = $con->prepare($sql);
$query->bindParam(":id_domanda", $id_domanda);
try {
$query->execute();
$r = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($r as $res) {
$allegato = new Allegati($res);
$return[]= $allegato;
}
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $return;
}
public function loadTipoDocumentoBando(){
$this->documento_bando = new DocumentiBando($this->ID_DOCUMENTO);
$this->identificativo = $this->getIdentificativo();
}
public function getIdentificativo() {
$return = 0;
if($this->documento_bando->ESTENZIONE_FILE == 'p7m'){
$return = "F" . Date::dateOracleTimeStamp($this->DATA_REGISTRAZIONE, 'Ym') . str_pad($this->ID, 6, '0', STR_PAD_LEFT);
}else{
$return = "A" . Date::dateOracleTimeStamp($this->DATA_REGISTRAZIONE, 'Ym') . str_pad($this->ID, 6, '0', STR_PAD_LEFT);
}
return $return;
}
/* Numero di tipi (DISTINTI) caricati per la domanda */
public static function CountTipiAllegati($id_domanda) {
global $con;
$count = 0;
if ($id_domanda > 0) {
$sql = "SELECT COUNT(DISTINCT(TIPO_DOCUMENTO)) as TOT FROM " . self::TABLE_NAME . " WHERE ID_DOMANDA=:id_domanda AND CANCELLATO=0 ";
$query = $con->prepare($sql);
$query->bindParam(":id_domanda", $id_domanda);
try {
$query->execute();
$rec = $query->fetch(PDO::FETCH_ASSOC);
$count = $rec['TOT'];
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $count;
}
/**
*
* @global type $con
* @param type $id_domanda
* @param type $tipo
* @param type $fase
* @param type $obbligo
* @return type
*/
public static function load($id_domanda = 0, $tipo = null, $fase = null, $obbligo = null) {
global $con;
$rows = array();
if (intval($id_domanda) > 0) {
$filter = (!empty($tipo) ? " AND A.TIPO_DOCUMENTO = :tipo_documento " : "");
$filter .= (!empty($fase) ? " AND D.FASE = :fase " : "");
$filter .= ($obbligo !== null && $obbligo >= 0 ? " AND D.OBBLIGO <= :obbligo " : "");
$sql = "SELECT D.PRIORITA, D.ID as DOCUMENTO_ID, D.NOME as DOCUMENTO_NOME, D.ATECO, D.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, D.ESTENZIONE_FILE, D.VERIFICA_FIRMA_P7M, D.FILE_DA_GENERARE, D.MODULE, A.* FROM " . self::TABLE_NAME . " A INNER JOIN " . DocumentiBando::TABLE_NAME
. " D ON D.ID = A.ID_DOCUMENTO WHERE A.ID_DOMANDA=:id_domanda AND A.CANCELLATO=0 " . $filter; //AND D.OBBLIGO <= 1
$sql .= " ORDER BY D.OBBLIGO, D.PRIORITA ";
$query = $con->prepare($sql);
$query->bindParam(":id_domanda", $id_domanda);
if (!empty($tipo)) {
$query->bindParam(":tipo_documento", $tipo);
}
if (!empty($fase)) {
$query->bindParam(":fase", $fase);
}
if ($obbligo !== null && $obbligo >= 0) {
$query->bindParam(":obbligo", $obbligo);
}
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public static function LoadDataTableAllegati($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0, $totCount = true) {
global $LoggedAccount;
$sql = "SELECT "
. "D.ID_BANDO , D.PRIORITA, D.ID as DOCUMENTO_ID, D.NOME as DOCUMENTO_NOME, D.ATECO, D.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, D.ESTENZIONE_FILE, D.VERIFICA_FIRMA_P7M, D.FILE_DA_GENERARE, D.MODULE, A.*"
. " FROM " . DocumentiBando::TABLE_NAME . " D "
. "LEFT JOIN " . self::TABLE_NAME . " A ON A.ID_DOCUMENTO = D.ID AND A.ID_DOMANDA = :ID_DOMANDA AND D.ATECO = :CODICE_ATECO AND A.CANCELLATO = 0 AND D.ID_BANDO = ".ID_BANDO." AND D.CANCELLATO = 0 ";
//echo $sql;
return parent::_loadDataTable($sql, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset, $totCount);
}
// public static function LoadDataTableDocsPresentazione($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0, $totCount = true) {
// global $LoggedAccount;
// // $field = "D.NOME as DOCUMENTO, D.* ";
// // $table = DocumentiBando::TABLE_NAME . " D INNER JOIN " . self::TABLE_NAME . " A ON A.ID_DOCUMENTO = D.ID"
// $sql = "SELECT D.PRIORITA, D.ID as DOCUMENTO_ID, D.NOME as DOCUMENTO_NOME, D.ID_BANDO, D.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, A.* FROM " . DocumentiBando::TABLE_NAME . " D LEFT JOIN " . self::TABLE_NAME . " A ON A.ID_DOCUMENTO = D.ID AND A.ID_DOMANDA = :ID_DOMANDA AND D.ID_BANDO = :ID_BANDO AND A.CANCELLATO = 0 ";
// // SELECT T.* FROM ( SELECT T.*, rowNum as rowIndex FROM ( SELECT D.NOME as DOCUMENTO, D.* FROM (
// // DOCUMENTI_BANDO D LEFT JOIN ALLEGATI A ON A.ID_DOCUMENTO = D.ID AND A.ID_DOMANDA = 189
// // ) WHERE 1 = 1 AND D.ID_BANDO = 1 ) T)T;
// return parent::_loadDataTable($sql, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset, $totCount);
// // return parent::_loadDataTableEx($field, $table, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset);
// }
// public static function LoadDataTableDocsRichiesta($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0, $totCount = true) {
// global $LoggedAccount;
// $sql = "SELECT D.PRIORITA, D.ID as DOCUMENTO_ID, D.NOME as DOCUMENTO_NOME, D.ID_BANDO, D.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, A.* FROM " . DocumentiBando::TABLE_NAME . " D LEFT JOIN " . self::TABLE_NAME . " A ON A.ID_DOCUMENTO = D.ID AND A.ID_DOMANDA = :ID_DOMANDA AND D.ID_BANDO = :ID_BANDO AND A.CANCELLATO = 0 ";
// return parent::_loadDataTable($sql, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset, $totCount);
// }
public static function Count($filter = null) {
return parent::_count(self::TABLE_NAME, $filter);
}
public function deleteIstanzaGenerataDomanda() {
$response = false;
if ($this->TIPO_DOCUMENTO == TIPO_UPLOAD_OPZIONALE && $this->ID_DOMANDA > 0) {
$domanda = new Domanda($this->ID_DOMANDA);
if ($domanda->STATO == AMMESSA_A_PARTECIPAZIONE && $domanda->HASHFILE != '') {
$domanda->FILEPATH_GENERATO = null;
$domanda->HASHFILE = null;
$response = $domanda->Save();
$response = $response['esito'] == 1 ? true : false;
} else {
$response = true;
}
} else {
$response = true;
}
return $response;
}
public function Save() {
global $con, $LoggedAccount;
$vars = get_object_vars($this);
UNSET($vars['DATA_REGISTRAZIONE']);
UNSET($vars['identificativo']);
UNSET($vars['documento_bando']);
$sql = Utils::prepareQuery(self::TABLE_NAME, $vars);
$queryabi = $con->prepare($sql);
foreach ($vars as $k => $v) {
if ($k == "ID" && $v == 0)
continue;
$queryabi->bindValue(":" . $k, $v);
}
try {
$it = parent::_Save($queryabi);
} catch (Exception $exc) {
$it['descrizioneErrore'] = $exc->getMessage();
}
if ($it['esito'] == 1) {
if (!$this->deleteIstanzaGenerataDomanda()) {
$it['esito'] = -999;
}
}
return $it;
}
public function Delete() {
return parent::_LogicalDelete(self::TABLE_NAME, "ID = " . $this->ID);
}
/**
* Funzione per la visualizzazione dei logs
* @param type $record
* @param type $campo
*/
public function Parse(&$record, $campo = "") {
$props = get_class_vars(get_class($this));
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo));
}
/**
*
* @param type $idDomanda
* @param type $ateco
* @return type
*/
public static function checkAllegatiObbligatoriCompletatiPreInvio($idDomanda = 0, $ateco = "") {
// $domanda->loadAllegati();
$response = false;
if ($idDomanda > 0 && $ateco != "") {
//$allegati = Allegati::load($idDomanda, null, null, 1); //
$domanda = new Domanda($idDomanda);
$documentiBandoObbligatori = DocumentiBando::loadFromCheckFinale($ateco);
$docObbligatoriCaricati = array();
foreach ($documentiBandoObbligatori as $kd => $vd) {
foreach ($domanda->allegati as $ka => $va) {
if ($va->ID_DOCUMENTO == $vd->ID && $va->FILEPATH!="" && intval($va->FILESIZE) > 0) {
$pathInfo = $vd->getPathInfoDocumento($vd->ID);
$folder = $domanda->generateDirForUpload(ROOT_UPLOAD_PRESENTAZIONE, $pathInfo["PATH_DOCUMENTO"]);
$fileFullPath = $folder . "/" . $va->FILEPATH;
$finalCheck = File::checkFileConsistency($fileFullPath);
if($finalCheck){
$docObbligatoriCaricati[$va->ID_DOCUMENTO] = $vd->ID;
}
break;
}
}
}
//echo "-->".count($documentiBandoObbligatori)." == ".count($docObbligatoriCaricati)."<--";
$response = count($documentiBandoObbligatori) == count($docObbligatoriCaricati);
}
return $response;
}
public static function checkDocumentiObbligatoriCompletati($idDomanda = 0, $ateco = "", $allegati = null) {
// $domanda->loadAllegati();
$response = false;
if ($idDomanda > 0 && $ateco != "") {
if (empty($allegati)) {
$allegati = Allegati::load($idDomanda, TIPO_UPLOAD_OBBLIGATORIO, DOCUMENTI_FASE_1, 1); //
}
$documentiBandoObbligatori = DocumentiBando::load($ateco, DOCUMENTI_FASE_1, 1);
$docObbligatoriCaricati = array();
foreach ($documentiBandoObbligatori as $kd => $vd) {
if ($vd["OBBLIGO"] == 1) {
foreach ($allegati as $ka => $va) {
if ($va["ID_DOCUMENTO"] == $vd["ID"] && $va["FILEPATH"]!="" && intval($va["FILESIZE"]) > 0) {
$docObbligatoriCaricati[$va["ID_DOCUMENTO"]] = $vd["ID"];
break;
}
}
}
}
$response = count($documentiBandoObbligatori) == count($docObbligatoriCaricati);
}
return $response;
}
public static function checkControlliPreliminariUploadObbligatorio($idDomanda = 0, $idDocumento = 0, $uploadedName = '', $tipoAllegato = '', $domanda = null, $format = 'p7m') {
global $LoggedAccount;
$response = Utils::initDefaultRowsResponse();
if (!empty($domanda) && isset($domanda->ID)) {
$idDomanda = $domanda->ID;
}
if (intval($idDomanda) > 0 && intval($idDocumento) > 0 && $uploadedName != '' && $tipoAllegato != '') {
if (empty($domanda) || !isset($domanda->ID) || $domanda->ID <= 0) {
$domanda = new Domanda($idDomanda);
}
$checkDocumento = DocumentiBando::compareAtecoDomanda($idDocumento, $domanda->CODICE_ATECO);
if ($tipoAllegato == TIPO_UPLOAD_ISTANZA && !self::checkDocumentiObbligatoriCompletati($domanda->ID, $domanda->CODICE_ATECO)) {
$response['erroreDescrizione'] = 'Allegare tutti i documenti obbligatori richiesti prima di procedere';
} else if (!Utils::isStatoSportelloPreparazione()) { /* Controllo stato sportello */
$response['erroreDescrizione'] = 'Operazione non consentita in questa fase.';
} else if (empty($domanda->CODICE_FISCALE_IMPRESA)) { /* Controllo sulla domanda */
$response['erroreDescrizione'] = 'Si è verificato un errore (870)';
} else if (!$LoggedAccount->checkImpresaFromLoggedAccount($domanda->CODICE_FISCALE_IMPRESA)) { /* Controllo permesso codice meccanografico su account */
$response['erroreDescrizione'] = 'Si è verificato un errore (871)';
} else if (!$checkDocumento) { /* controllo idBando tra documento e domanda */
$response['erroreDescrizione'] = 'Attenzione, al momento non è possibile procedere con l\'operazione scelta.';
} else {
$response = File::checkFileAllegato($uploadedName, MAX_FILE_SIZE, $format); /* controllo sul file allegato */
}
} else {
$response['erroreDescrizione'] = 'Si è verificato un errore (857)';
}
if ($response['esito'] == 1) {
$response['rows'] = $domanda;
}
return $response;
}
/*
* Funzione per il reset dei dati relativi all'istanza generata in caso di cancellazione di un allegato
*/
public function deleteAllegato() {
global $con, $LoggedAccount;
$response = Utils::initDefaultResponse();
if ($this->ID > 0 && $this->CANCELLATO == 0) {
$domanda = new Domanda($this->ID_DOMANDA);
if ($LoggedAccount->checkImpresaFromLoggedAccount($domanda->CODICE_FISCALE_IMPRESA)) {
// if ($this->TIPO_DOCUMENTO == TIPO_UPLOAD_OBBLIGATORIO) {
$response = $this->Delete();
if ($response['esito'] == 1) {
/* SPOSTAMENTO FILE */
$filePath = $domanda->generateDirForUpload(ROOT_UPLOAD_PRESENTAZIONE, 'obbligatori');
$fileSource .= $filePath . "/" . $this->FILEPATH;
$fileDest = $filePath . "/deleted_" . $this->FILEPATH;
if (!file_exists($fileSource) || rename($fileSource, $fileDest)) {
//$domanda->DESCRIZIONE_INTERVENTO = null;
$response['esito'] = 1;
} else {
$response = Utils::initDefaultResponse(-999, "Si è verificato un errore (1571)");
}
}
// }
}
}
return $response;
}
public function checkFaseDocumento() {
$response = Utils::initDefaultResponse(-999, "Operazione non consentita in questa fase");
$fase = Utils::getFaseDocumenti();
$documentoBando = new DocumentiBando($this->ID_DOCUMENTO);
if ($documentoBando->FASE == $fase) {
$response['esito'] = 1;
}
return $response;
}
public static function resetHashIstanza($idDomanda = 0, $soloAllegati = false){
global $con;
$response = Utils::initDefaultResponse();
if(intval($idDomanda)>0){
$domanda = new Domanda($idDomanda);
$domanda->HASH_ALLEGATO2 = '';
$domanda->ALLEGATO2_GENERATO = '';
$domanda->DATA_ALLEGATO2 = null;
if(!$soloAllegati){
$response = $domanda->Save();
}else{
$response['esito'] = 1;
}
if($response['esito'] == 1){
$sql = " SELECT * FROM ".Allegati::TABLE_NAME." WHERE ID_DOMANDA = :id_domanda AND TIPO_DOCUMENTO = ".TIPO_UPLOAD_ISTANZA;
$query = $con->prepare($sql);
$query->bindParam(":id_domanda", $domanda->ID);
try {
$query->execute();
$r = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($r as $res) {
$allegato = new Allegati($res);
$allegato->HASH_FILE = '';
$allegato->FILEPATH = '';
$allegato->NOMEFILEORIGINALE = '';
$allegato->FILESIZE = '';
$allegato->DATA_REGISTRAZIONE = null;
$response = $allegato->Save();
}
} catch (Exception $exc) {
$response['esito'] = -999;
$response['erroreDescrizione'] = $exc->getMessage();
}
}
}
return $response;
}
}