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.
 
 
 

327 righe
9.4 KiB

<?php
require_once ROOT . "/lib/classes/IDataClass.php";
class Aeroporti extends DataClass {
const TABLE_NAME = "AEROPORTI";
const VIEW = "VIEW_TRATTE";
const SPSAVE = "SPAEROPORTISAVE";
public $CODICE = null;
public $NOME = null;
public $REGIONE = 0;
public function __construct($src = null) {
global $con;
$stripSlashes = false;
if ($src == null) {
return;
}
if (is_array($src)) {
$this->_loadByRow($src, $stripSlashes);
} elseif (is_string($src)) {
// Carichiamo tramite ID
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE CODICE = :CODICE";
$query = $con->prepare($sql);
$query->bindParam(":CODICE", $src);
try {
$query->execute();
$it = $query->fetchAll(PDO::FETCH_ASSOC);
Utils::FillObjectFromRow($this, $it[0]);
} catch (Exception $exc) {
$exc->getMessage();
}
}
}
/**
*
* @param $CODICE
* @return array
*/
public function LoadByCodice($CODICE) {
global $con;
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE CODICE = :CODICE";
$query = $con->prepare($sql);
$it = array();
$query->bindParam(":CODICE", $CODICE);
try {
$query->execute();
$it = $query->fetchAll(PDO::FETCH_ASSOC);
Utils::FillObjectFromRow($this, $it[0]);
} catch (Exception $exc) {
$exc->getMessage();
}
return $it;
}
/**
* Restituisce la liste di tutti gli aeroporti
* @return array
*/
public static function ListAeroporti($regione = '') {
global $con;
$filter = '';
if (!empty($regione)) {
$filter = " WHERE REGIONE = :regione ";
}
$sql = "SELECT * FROM " . self::TABLE_NAME. ' '.$filter.' order by REGIONE, NOME';
$query = $con->prepare($sql);
if (!empty($regione)) {
$query->bindParam(":regione", $regione);
}
$return = array();
try {
$query->execute();
$return = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
return $return;
}
/**
* Restituisce tutte le possibili destinazioni dell'aeroporto di partenza
* @param $CODICE_A
* @return array
*/
public static function ListDestinazione($CODICE_A) {
global $con;
$sql = "SELECT * FROM " . self::VIEW . " WHERE CODICE_A = :CODICE_A";
$query = $con->prepare($sql);
$return = array();
$query->bindParam(":CODICE_A", $CODICE_A);
try {
$query->execute();
$return = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
return $return;
}
public static function autocomplete($string = '', $regione = null) {
global $con;
$return = array();
$filter = '';
$searchFix = '';
if (!empty($regione)) {
$filter = " REGIONE = :regione AND ";
}
$string = "%" . strtolower($string) . "%";
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE " . $filter . " LOWER(NOME) LIKE :term ".$searchFix." ORDER BY REGIONE, NOME";
$query = $con->prepare($sql);
if (!empty($regione)) {
$query->bindParam(":regione", $regione);
}
$query->bindParam(":term", $string);
try {
$query->execute();
while ($it = $query->fetch(PDO::FETCH_ASSOC)) {
$descrizione = $it['NOME'];
$row['id'] = $descrizione;
$row['text'] = $descrizione;
$row['label'] = $descrizione;
$row['codice'] = $it['CODICE'];
array_push($return, $row);
}
} catch (Exception $exc) {
echo $exc->getMessage();
}
return $return;
}
public static function autocompleteRitorno($string = '', $codice_a = null) {
global $con;
$return = array();
$filter = '';
$searchFix = '';
if (!empty($codice_a)) {
$filter = " A_CODICE = :codice_a AND ";
}else{
return $return;
}
$string = "%" . strtolower($string) . "%";
$sql = "SELECT * FROM " . self::VIEW . " WHERE " . $filter . " LOWER(R_NOME) LIKE :term ".$searchFix." ORDER BY R_NOME";
$query = $con->prepare($sql);
if (!empty($codice_a)) {
$query->bindParam(":codice_a", $codice_a);
}
$query->bindParam(":term", $string);
try {
$query->execute();
while ($it = $query->fetch(PDO::FETCH_ASSOC)) {
$descrizione = $it['R_NOME'];
$row['id'] = $descrizione;
$row['text'] = $descrizione;
$row['label'] = $descrizione;
$row['codice'] = $it['R_CODICE'];
array_push($return, $row);
}
} catch (Exception $exc) {
echo $exc->getMessage();
}
return $return;
}
public static function Count($filter = null) {
return parent::_count(self::TABLE_NAME, $filter);
}
public static function LoadDataTable($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0, $totCount = false) {
return parent::_loadDataTable(self::TABLE_NAME, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset, $totCount);
}
public function Save()
{
global $con, $LoggedAccount;
$sql = "CALL " . self::SPSAVE . " (?,?,?)";
$query = $con->prepare($sql);
$query->bindParam(1, $this->CODICE);
$query->bindParam(2, $this->NOME);
$query->bindParam(3, $this->REGIONE);
try {
if($query->execute()){
$response['esito'] = 1;
}
} catch (Exception $exc) {
$response['descrizioneErrore'] = $exc->getMessage();
}
return $response;
}
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));
}
}
class AeroportiCompagnie extends DataClass {
const TABLE_NAME = "AEROPORTI_COMPAGNIE";
const SPSAVE = "SPAEROCOMPAGNIESAVE";
public $AEROPORTO = "";
public $COMPAGNIA = 0;
public function __construct($src = null) {
global $con;
$stripSlashes = false;
if ($src == null) {
return;
}
if (is_array($src)) {
$this->_loadByRow($src, $stripSlashes);
}
}
public static function load($AEROPORTO = '') {
global $con, $LoggedAccount;
$rows = array();
if(!empty($AEROPORTO)){
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE AEROPORTO=:aeroporto ";
$sql .= " ORDER BY COMPAGNIA ASC ";
$query = $con->prepare($sql);
$query->bindParam(":aeroporto", $AEROPORTO);
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public static function loadFromAeroporto($AEROPORTO = '') {
global $con, $LoggedAccount;
$rows = array();
if(!empty($AEROPORTO)){
$sql = "SELECT * FROM " . self::TABLE_NAME . " A INNER JOIN ".AnagraficaCompagnie::TABLE_NAME." C ON C.ID = A.COMPAGNIA WHERE A.AEROPORTO=:aeroporto ";
$sql .= " ORDER BY C.NOME ASC ";
$query = $con->prepare($sql);
$query->bindParam(":aeroporto", $AEROPORTO);
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public function Save()
{
global $con, $LoggedAccount;
$sql = "CALL " . self::SPSAVE . " (?,?)";
$query = $con->prepare($sql);
$query->bindParam(1, $this->AEROPORTO);
$query->bindParam(2, $this->COMPAGNIA);
try {
if($query->execute()){
$response['esito'] = 1;
}
} catch (Exception $exc) {
$response['descrizioneErrore'] = $exc->getMessage();
}
return $response;
}
public function DeleteCompagnia()
{
global $con, $LoggedAccount;
$sql = "DELETE " . self::TABLE_NAME . " WHERE AEROPORTO=:aeroporto AND COMPAGNIA = :compagnia";
//echo $sql;
$query = $con->prepare($sql);
$query->bindParam(":aeroporto", $this->AEROPORTO);
$query->bindParam(":compagnia", $this->COMPAGNIA);
try {
$query->execute();
$risultato['esito'] = 1;
} catch (Exception $exc) {
$risultato['esito'] = -999;
$risultato['erroreDescrizione'] = $exc->getMessage();
}
return $risultato;
}
public function Parse(&$record, $campo = "") {
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo));
}
}