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.
307 righe
11 KiB
307 righe
11 KiB
<?php |
|
|
|
require_once ROOT . "lib/classes/IDataClass.php"; |
|
|
|
/** |
|
* Description of AccountNucleoFamiliare |
|
* |
|
* @author Anselmo |
|
*/ |
|
class AccountNucleoFamiliare extends DataClass { |
|
|
|
const TABLE_NAME = "ACCOUNT_NUCLEO_FAMILIARE"; |
|
const SEQ_NAME = "ACCOUNT_NUCLEO_ID_SEQ"; |
|
|
|
public $ID = 0; |
|
public $ID_ACCOUNT = 0; |
|
public $COGNOME = ""; |
|
public $NOME = ""; |
|
public $DATA_NASCITA = null; |
|
public $COMUNE_RESIDENZA = ""; |
|
public $PROV_RESIDENZA = ""; |
|
public $CAP_RESIDENZA = ""; |
|
public $RAPPORTO_PARENTELA = 0; |
|
public $CODICE_FISCALE = ""; |
|
public $CONFERMATO = 0; |
|
public $STUDENTE = 0; |
|
public $FLAG = ""; |
|
public $PRIORITY = 0; |
|
|
|
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)) { |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":id", $src); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
Utils::FillObjectFromRow($this, $it[0]); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* |
|
* @param type $filter |
|
* @return type |
|
*/ |
|
public static function Count($filter = null) { |
|
return parent::_count(self::TABLE_NAME, $filter); |
|
} |
|
|
|
/** |
|
* |
|
* @param type $searchQuery |
|
* @param type $searchArray |
|
* @param type $columnName |
|
* @param type $columnSortOrder |
|
* @param type $start |
|
* @param type $offset |
|
* @return type |
|
*/ |
|
public static function LoadDataTable($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0) { |
|
|
|
return parent::_loadDataTable(self::TABLE_NAME, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset); |
|
} |
|
|
|
/** |
|
* |
|
* @global type $con |
|
* @global type $LoggedAccount |
|
* @return type array |
|
*/ |
|
public static function load($ID_ACCOUNT = -1) { |
|
global $con, $LoggedAccount; |
|
$rows = array(); |
|
if($ID_ACCOUNT<=0){ |
|
$ID_ACCOUNT = $LoggedAccount->ID; |
|
} |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID_ACCOUNT=:account "; |
|
|
|
$sql .= " ORDER BY ID ASC "; |
|
|
|
$query = $con->prepare($sql); |
|
$query->bindParam(":account", $ID_ACCOUNT); |
|
|
|
try { |
|
$query->execute(); |
|
$rows = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
|
|
return $rows; |
|
} |
|
|
|
public static function loadFromCf($cf = null) { |
|
global $con; |
|
$nucleo = new AccountNucleoFamiliare(); |
|
if (!empty($cf)) { |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE CODICE_FISCALE=:cf "; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":cf", $cf); |
|
try { |
|
$query->execute(); |
|
$res = $query->fetchAll(PDO::FETCH_ASSOC); |
|
Utils::FillObjectFromRow($nucleo, $res[0]); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
} |
|
return $nucleo; |
|
} |
|
|
|
public function CheckDataSave() { |
|
$response = Utils::initDefaultResponse(); |
|
$dataDaControllare = new DateTime($this->DATA_NASCITA); |
|
$dataLimite = new DateTime(Date::FormatDate(DATA_NASCITA_MAX_NUCLEO_FAMILIARE, DATE_FORMAT_ISO)); |
|
if (Date::verifyMinorDate($dataDaControllare, $dataLimite)) { |
|
$response['esito'] = 1; |
|
} else { |
|
$response['erroreDescrizione'] = 'La data di nascita deve essere inferiore al ' . DATA_NASCITA_MAX_NUCLEO_FAMILIARE . '.'; |
|
} |
|
|
|
return $response; |
|
} |
|
|
|
/** |
|
* |
|
* @global type $con |
|
* @global type $LoggedAccount |
|
* @return type |
|
*/ |
|
public function Save() { |
|
global $con, $LoggedAccount; |
|
$vars = get_object_vars($this); |
|
unset($vars['STUDENTE']); |
|
$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(); |
|
} |
|
return $it; |
|
} |
|
|
|
public function Delete() { |
|
return parent::_Delete(self::TABLE_NAME, "ID = " . $this->ID); |
|
} |
|
|
|
public function Parse(&$record, $campo = "") { |
|
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); |
|
} |
|
|
|
public function controlloPresenzaConiuge() { |
|
global $con, $LoggedAccount; |
|
$return = array(); |
|
$sel = $con->prepare("SELECT COUNT(ID) AS NUM FROM " . self::TABLE_NAME . " WHERE " |
|
. "ID_ACCOUNT=:ID_ACCOUNT AND RAPPORTO_PARENTELA=:RAPPORTO_PARENTELA"); |
|
$sel->bindParam(":ID_ACCOUNT", $LoggedAccount->ID); |
|
$sel->bindValue(":RAPPORTO_PARENTELA", RAPPORTO_PARENTELA_NON_RIPETIBILE); |
|
try { |
|
$sel->execute(); |
|
$it = $sel->fetch(PDO::FETCH_ASSOC); |
|
$return['esito'] = 1; |
|
$return['ripetuto'] = $it['NUM']; |
|
} catch (Exception $exc) { |
|
$return['esito'] = -999; |
|
} |
|
return $return; |
|
} |
|
|
|
public function setConfermatoForAccount() { |
|
global $con, $LoggedAccount; |
|
$return = array(); |
|
$sel = $con->prepare("UPDATE " . self::TABLE_NAME . " SET CONFERMATO=1 WHERE " |
|
. "ID_ACCOUNT=:ID_ACCOUNT"); |
|
$sel->bindParam(":ID_ACCOUNT", $LoggedAccount->ID); |
|
try { |
|
$sel->execute(); |
|
$return['esito'] = 1; |
|
} catch (Exception $exc) { |
|
$return['esito'] = -999; |
|
} |
|
return $return; |
|
} |
|
|
|
public static function checkVerificaDatiPreSalvataggio() { |
|
global $LoggedAccount; |
|
$_POST['ID'] = Utils::get_filter_string_POST('ID'); |
|
$_POST['ID_ACCOUNT'] = $LoggedAccount->ID; |
|
$_POST['COGNOME'] = Utils::get_filter_string_POST('COGNOME'); |
|
$_POST['NOME'] = Utils::get_filter_string_POST('NOME'); |
|
$_POST['DATA_NASCITA'] = Utils::get_filter_string_POST('DATA_NASCITA'); |
|
$_POST['COMUNE_RESIDENZA'] = Utils::get_filter_string_POST('COMUNE_RESIDENZA'); |
|
$_POST['CAP_RESIDENZA'] = Utils::get_filter_string_POST('CAP_RESIDENZA'); |
|
$_POST['PROV_RESIDENZA'] = Utils::get_filter_string_POST('PROV_RESIDENZA'); |
|
$_POST['CODICE_FISCALE'] = Utils::get_filter_string_POST('CODICE_FISCALE'); |
|
$_POST['RAPPORTO_PARENTELA'] = Utils::get_filter_int_POST('RAPPORTO_PARENTELA'); |
|
$_POST['DATA_NASCITA'] = Utils::get_filter_string_POST('DATA_NASCITA'); |
|
$_POST['STUDENTE'] = (strtolower($_POST['STUDENTE']) == 'on' ? 1 : 0); |
|
$_POST['FLAG'] = (strtolower($_POST['FLAG']) == 'on' ? 1 : 0); |
|
} |
|
|
|
public function checkDatiPreSave() { |
|
global $LoggedAccount; |
|
$response = array(); |
|
$controllValidita = true; |
|
$dati_mancanti = ''; |
|
if ($this->ID > 0 && $this->ID_ACCOUNT != $LoggedAccount->ID) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Operazione non consentita.<br>"; |
|
} |
|
if ($this->CODICE_FISCALE == $LoggedAccount->CODICE_FISCALE) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Non è possibile registrare il proprio codice fiscale.<br>" |
|
. "Per la modifica dei propri dati è necessario recarsi nella 'Sezione Anagrafica del Richiedente'.<br>"; |
|
} |
|
if ($this->COGNOME == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Cognome Obbligatorio.<br>"; |
|
} |
|
if ($this->NOME == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Nome Obbligatorio.<br>"; |
|
} |
|
if ($this->COMUNE_RESIDENZA == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Comune di Residenza Obbligatorio.<br>"; |
|
} |
|
if ($this->CAP_RESIDENZA == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo CAP di Residenza Obbligatorio.<br>"; |
|
} |
|
if (!is_numeric($this->CAP_RESIDENZA) || (is_numeric($this->CAP_RESIDENZA) && (strlen($this->CAP_RESIDENZA) != LUNGHEZZA_CAP))) { |
|
$controllValidita = false; |
|
$dati_mancanti .= '<br><b>CAP</b> del comune di residenza errato.<br>'; |
|
} |
|
if ($this->PROV_RESIDENZA == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Provincia di Residenza Obbligatorio.<br>"; |
|
} |
|
if (strlen($this->CODICE_FISCALE) != 16) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Codice Fiscale Non Valido.<br>"; |
|
} |
|
|
|
if (CONTROLLO_FORMATTAZIONE_CF && !Utils::ControlloCodiceFiscale(trim($this->CODICE_FISCALE))) { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>Codice fiscale del componente non valido</b><br>"; |
|
} |
|
|
|
|
|
$countCF = AccountNucleoFamiliare::Count("ID_ACCOUNT= " . $LoggedAccount->ID . " AND CODICE_FISCALE = '" . trim($this->CODICE_FISCALE) . "'"); |
|
if ($countCF > 0 && intval($this->ID) == 0) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Il codice fiscale inserito è già presente nel nucleo familiare!<br>"; |
|
} |
|
if (intval($this->RAPPORTO_PARENTELA) < 1) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Rapporto di Parentela Obbligatorio.<br>"; |
|
} |
|
$controlloRapporto = AccountNucleoFamiliare::controlloPresenzaConiuge(); |
|
if ($this->RAPPORTO_PARENTELA == RAPPORTO_PARENTELA_NON_RIPETIBILE && $controlloRapporto['ripetuto'] > 0 && intval($this->ID) == 0) { |
|
$controllValidita = false; |
|
$dati_mancanti .= "Campo Rapporto di Parentela Non Ripetibile.<br>"; |
|
} |
|
if ($this->DATA_NASCITA != "") { |
|
$res = Date::checkSaveDate($this->DATA_NASCITA, '', false); |
|
if ($res['esito'] == 1) { |
|
$ckd = $this->CheckDataSave(); |
|
if ($ckd['esito'] != 1) { |
|
$controllValidita = false; |
|
$dati_mancanti .= $ckd['erroreDescrizione']; |
|
} else { |
|
$this->DATA_NASCITA = Date::dateOracleDateNascita($this->DATA_NASCITA, "d-M-Y"); |
|
// $this->DATA_NASCITA = date("d-M-y", strtotime($this->DATA_NASCITA)); |
|
} |
|
} else { |
|
$controllValidita = false; |
|
$dati_mancanti .= $res['erroreDescrizione']; |
|
} |
|
} |
|
$response['checkDati'] = $controllValidita; |
|
$response['txt_dati_mancanti'] = $dati_mancanti; |
|
|
|
return $response; |
|
} |
|
}
|
|
|