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.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, " . " D.ESTENZIONE_FILE, D.VERIFICA_FIRMA_P7M, D.FILE_DA_GENERARE, D.MODULE, D.OBBLIGO_CONDIZIONATO, 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; $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.PRIORITA, D.ID as DOCUMENTO_ID, D.NOME as DOCUMENTO_NOME, D.OBBLIGO, D.FASE, D.CANCELLATO AS DOCUMENTO_CANCELLATO, D.ESTENZIONE_FILE, D.VERIFICA_FIRMA_P7M, D.FILE_DA_GENERARE, D.MODULE, D.OBBLIGO_CONDIZIONATO , 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 A.CANCELLATO = 0 AND D.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(); } 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['erroreDescrizione'] = $exc->getMessage(); } if ($it['esito'] == 1 && !$this->deleteIstanzaGenerataDomanda()) { $it['esito'] = -999; } return $it; } public function Delete() { return parent::_Delete(self::TABLE_NAME, "ID = " . $this->ID); //return parent::_LogicalDelete(self::TABLE_NAME, "ID = " . $this->ID); } public function DeleteDocumentiBando($idDomanda = 0, $idDocumento = 0) { $response = Utils::initDefaultResponse(); if (intval($idDomanda) > 0 && intval($idDocumento) > 0) { $response = parent::_Delete(self::TABLE_NAME, "ID_DOMANDA = " . $idDomanda . " AND ID_DOCUMENTO = " . $idDocumento); } return $response; } /** * Funzione per la visualizzazione dei logs * @param type $record * @param type $campo */ public function Parse(&$record, $campo = "") { array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); } /** * * @param type $idDomanda * @param type $ateco * @return type */ public static function checkAllegatiObbligatoriCompletatiPreInvio() { global $LoggedAccount; $response = false; $domanda = Domanda::loadDomandaFromAccount(); $fase = Utils::getFaseDocumenti(); $documentiBandoObbligatori = DocumentiBando::loadFromCheckFinale($fase); $docBandoObbligatoriFinale = array(); $docObbligatoriCaricati = array(); foreach ($documentiBandoObbligatori as $vd) { if ($vd->OBBLIGO >= 1) { $docBandoObbligatoriFinale[$vd->ID] = $vd->ID; } else { $split = explode("|", $vd->OBBLIGO_CONDIZIONATO); $table = trim($split[0]); $column = trim($split[1]); $value = trim($split[2]); if ($table == Domanda::TABLE_NAME) { if ($domanda->ISEE == $value) { $vd->OBBLIGO = 1; } } if ($table == DomandaDichiarazioni::TABLE_NAME) { foreach ($domanda->dichiarazioni as $dichiarazioni) { if ($dichiarazioni[$column] == $value) { $docBandoObbligatoriFinale[$vd->ID] = $vd->ID; } } } } foreach ($domanda->allegati as $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; } } } $response = count($docBandoObbligatoriFinale) == count($docObbligatoriCaricati); return $response; } public static function checkDocumentiObbligatoriCompletati($check = true, $docObbligatori = false, $docCaricati = false) { $response = false; $domanda = Domanda::loadDomandaFromAccount(); $fase = Utils::getFaseDocumenti(); if ($domanda->ID > 0) { $allegati = Allegati::load($domanda->ID, TIPO_UPLOAD_OBBLIGATORIO, $fase, 1); // $documentiBandoObbligatori = DocumentiBando::loadFromCheckFinale($fase, 1); $docBandoObbligatoriFinale = array(); $docObbligatoriCaricati = array(); foreach ($documentiBandoObbligatori as $vd) { if ($vd->OBBLIGO_CONDIZIONATO != "") { $split = explode("|", $vd->OBBLIGO_CONDIZIONATO); $table = trim($split[0]); $column = trim($split[1]); $value = trim($split[2]); if ($table == Domanda::TABLE_NAME) { if ($domanda->ISEE == $value) { $vd->OBBLIGO = 1; } } if ($table == DomandaDichiarazioni::TABLE_NAME) { foreach ($domanda->dichiarazioni as $dichiarazione) { if ($dichiarazione[$column] == $value) { $vd->OBBLIGO = 1; } } } } if ($vd->OBBLIGO == 1) { $docBandoObbligatoriFinale[$vd->ID] = $vd->ID; foreach ($allegati as $va) { if ($va["ID_DOCUMENTO"] == $vd->ID && $va["FILEPATH"] != "" && intval($va["FILESIZE"]) > 0) { $docObbligatoriCaricati[$va["ID_DOCUMENTO"]] = $vd->ID; break; } } } } $response = count($docBandoObbligatoriFinale) == count($docObbligatoriCaricati); } if ($check) { $response = $response; } else if (!$check && $docObbligatori) { $response = count($docBandoObbligatoriFinale); } else if (!$check && $docCaricati) { $response = count($docObbligatoriCaricati); } return $response; } public static function checkControlliPreliminariUploadObbligatorio($idDocumento = 0, $uploadedName = '', $tipoAllegato = '', $format = 'p7m') { global $LoggedAccount; $response = Utils::initDefaultRowsResponse(); $domanda = Domanda::loadDomandaFromAccount(); $idDocumentoEsistente = false; foreach ($domanda->allegati as $allegato) { if ($allegato->ID_DOCUMENTO == $idDocumento) { $idDocumentoEsistente = true; } } if (intval($domanda->ID) > 0 && intval($idDocumento) > 0 && $uploadedName != '' && $tipoAllegato != '' && !$idDocumentoEsistente) { if ($tipoAllegato == TIPO_UPLOAD_ISTANZA && !self::checkDocumentiObbligatoriCompletati()) { $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 { $response = File::checkFileAllegato($uploadedName, MAX_SIZE_FILE, $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 = Domanda::loadDomandaFromAccount(); if ($this->TIPO_DOCUMENTO == TIPO_UPLOAD_ISTANZA) { $fileNameTmp = $domanda->ALLEGATO_GENERATO; } else { $fileNameTmp = $this->FILEPATH; } $response = $this->Delete(); if ($response['esito'] == 1 && $fileNameTmp != "") { /* SPOSTAMENTO FILE */ $documenti_bando = new DocumentiBando($this->ID_DOCUMENTO); $pathInfo = $documenti_bando->getPathInfoDocumento($this->ID_DOCUMENTO); $filePath = $domanda->generateDirForUpload(ROOT_UPLOAD_PRESENTAZIONE, $pathInfo["PATH_DOCUMENTO"]); $fileSource .= $filePath . "/" . $fileNameTmp; $fileDest = $filePath . "/deleted_" . $fileNameTmp; if (!file_exists($fileSource) || rename($fileSource, $fileDest)) { $response['esito'] = 1; } else { $response = Utils::initDefaultResponse(-999, "Si è verificato un errore (1571) " . $fileSource); } } } 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; } /** * * @global type $con * @param type $idDomanda * @param type $soloAllegati * @return int */ public static function resetHashIstanza($idDomanda = 0, $soloAllegati = false) { global $con; $response = Utils::initDefaultResponse(1); if (intval($idDomanda) > 0) { $sql = " SELECT A.* FROM " . Allegati::TABLE_NAME . " A " . "LEFT JOIN DOCUMENTI_BANDO B ON B.ID=A.ID_DOCUMENTO " . "WHERE A.ID_DOMANDA = :id_domanda AND A.CANCELLATO = 0 AND (A.TIPO_DOCUMENTO = " . TIPO_UPLOAD_ISTANZA . " OR B.FILE_DA_GENERARE=1)"; $query = $con->prepare($sql); $query->bindParam(":id_domanda", $idDomanda); try { $query->execute(); $r = $query->fetchAll(PDO::FETCH_ASSOC); if (count($r) > 0) { foreach ($r as $res) { $allegato = new Allegati($res); $response = $allegato->deleteAllegato(); } } else { $response['esito'] = 1; } } catch (Exception $exc) { $response['esito'] = -999; $response['erroreDescrizione'] = $exc->getMessage(); } // if ($response['esito'] == 1) { // if (!$soloAllegati) { // $domanda = new Domanda($idDomanda); // //$domanda->ResetPdfGenerato(); // $response = $domanda->Save(); // } else { // $response['esito'] = 1; // } // } } return $response; } /** * @param $idDomanda * @param $id_documento * @return array|bool */ public static function resetDeleteAllegato($idDomanda = 0, $id_documento = 0) { global $con; $response = Utils::initDefaultResponse(1); if (intval($idDomanda) > 0 && intval($id_documento) > 0) { $sql = " SELECT * FROM " . Allegati::TABLE_NAME . " WHERE ID_DOMANDA = :id_domanda AND ID_DOCUMENTO = :id_documento "; $query = $con->prepare($sql); $query->bindParam(":id_domanda", $idDomanda); $query->bindParam(":id_documento", $id_documento); try { $query->execute(); $r = $query->fetchAll(PDO::FETCH_ASSOC); if (count($r) > 0) { foreach ($r as $res) { $allegato = new Allegati($res); $response = $allegato->deleteAllegato(); } } else { $response['esito'] = 1; } } catch (Exception $exc) { $response['esito'] = -999; $response['erroreDescrizione'] = $exc->getMessage(); } } return $response; } }