SYNC FAS Person mit Update-Überprüfung

SYNC FAS Nation
This commit is contained in:
Rudolf Hangl
2006-12-15 10:48:59 +00:00
parent 0976f1bc22
commit 13af44dac5
6 changed files with 392 additions and 85 deletions
+85 -22
View File
@@ -1,4 +1,25 @@
<?php
/* Copyright (C) 2006 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
*/
/**
* Klasse Nation (FAS-Online)
* @create 06-04-2006
@@ -6,17 +27,18 @@
class nation
{
var $conn;
var $errormsg;
var $result = array();
var $conn; // resource DB-Handle
var $errormsg; // string
var $new; // boolean
var $nation = array(); // nation Objekt
//Tabellenspalten
var $code;
var $sperre;
var $kontinent;
var $entwland;
var $euflag;
var $ewrflag;
var $entwicklungsstand;
var $eu;
var $ewr;
var $kurztext;
var $langtext;
var $engltext;
@@ -26,19 +48,26 @@ class nation
* @param $conn Connection
* $code Zu ladende Nation
*/
function nation($conn,$code=null)
function nation($conn, $code=null, $unicode=false)
{
$this->conn = $conn;
$qry = "SET CLIENT_ENCODING TO 'UNICODE';";
if($unicode)
$qry = "SET CLIENT_ENCODING TO 'UNICODE';";
else
$qry = "SET CLIENT_ENCODING TO 'LATIN9';";
if(!pg_query($conn,$qry))
{
$this->errormsg = "Encoding konnte nicht gesetzt werden";
$this->errormsg = 'Encoding konnte nicht gesetzt werden';
return false;
}
if($code != null)
$this->load($code);
//if($person_id != null)
// $this->load($person_id);
}
/**
* Laedt die Funktion mit der ID $adress_id
* @param $code code der zu ladenden Nation
@@ -72,21 +101,55 @@ class nation
while($row = pg_fetch_object($res))
{
$nation_obj = new nation($this->conn);
$nation = new nation($this->conn);
$nation_obj->code = $row->code;
$nation_obj->sperre = $row->sperre;
$nation_obj->kontinent = $row->sperre;
$nation_obj->entwland = $row->entwland;
$nation_obj->euflag = $row->euflag;
$nation_obj->ewrflag = $row->ewrflag;
$nation_obj->kurztext = $row->kurztext;
$nation_obj->langtext = $row->langtext;
$nation_obj->engltext = $row->engltext;
$nation->code = $row->code;
$nation->sperre = $row->sperre;
$nation->kontinent = $row->sperre;
$nation->entwland = $row->entwland;
$nation->euflag = $row->euflag;
$nation->ewrflag = $row->ewrflag;
$nation->kurztext = $row->kurztext;
$nation->langtext = $row->langtext;
$nation->engltext = $row->engltext;
$this->result[] = $nation_obj;
$this->nation[] = $nation;
}
return true;
}
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
// ************************************************************
// * Speichert die Personendaten in die Datenbank
// * @return true wenn erfolgreich, false im Fehlerfall
// ************************************************************
function save()
{
$qry='INSERT INTO bis.tbl_nation (code, entwicklungsstand, eu, ewr, kontinent, kurztext, langtext, engltext, sperre) VALUES('.
$this->addslashes($this->code).', '.
$this->addslashes($this->entwicklungsstand).', '.
$this->addslashes($this->eu).', '.
$this->addslashes($this->ewr).', '.
$this->addslashes($this->kontinent).', '.
$this->addslashes($this->kurztext).', '.
$this->addslashes($this->langtext).', '.
$this->addslashes($this->engltext).', '.
$this->addslashes($this->sperre).');';
if(pg_query($this->conn,$qry))
{
return true;
}
else
{
$this->errormsg = 'Fehler beim Speichern des Nationen-Datensatzes:'.$this->code.' '.$qry;
return false;
}
}
}
?>
+6 -1
View File
@@ -37,6 +37,7 @@ class ort
var $planbezeichnung; // @var string
var $max_person; // @var integer
var $aktiv; // @var boolean
var $lehre; // @var boolean
var $lageplan; // @var oid
var $dislozierung; // @var smallint
var $kosten; // @var numeric(8,2)
@@ -77,6 +78,7 @@ class ort
$ort_obj->planbezeichnung = $row->planbezeichnung;
$ort_obj->max_person = $row->max_person;
$ort_obj->aktiv = $row->aktiv;
$ort_obj->lehre = $row->lehre;
$ort_obj->lageplan = $row->lageplan;
$ort_obj->dislozierung = $row->dislozierung;
$ort_obj->kosten = $row->kosten;
@@ -114,6 +116,7 @@ class ort
$this->planbezeichnung = $row->planbezeichnung;
$this->max_person = $row->max_person;
$this->aktiv = $row->aktiv;
$ort_obj->lehre = $row->lehre;
$this->lageplan = $row->lageplan;
$this->dislozierung = $row->dislozierung;
$this->kosten = $row->kosten;
@@ -190,13 +193,14 @@ class ort
return false;
}
//Neuen Datensatz anlegen
$qry = 'INSERT INTO tbl_ort (ort_kurzbz, bezeichnung, planbezeichnung, max_person, aktiv, lageplan,
$qry = 'INSERT INTO tbl_ort (ort_kurzbz, bezeichnung, planbezeichnung, max_person, aktiv, lehre, lageplan,
dislozierung, kosten) VALUES ('.
$this->addslashes($this->ort_kurzbz).', '.
$this->addslashes($this->bezeichnung).', '.
$this->addslashes($this->planbezeichnung).', '.
$this->addslashes($this->max_person).', '.
($this->aktiv?'true':'false').', '.
($this->lehre?'true':'false').', '.
$this->addslashes($this->lageplan).', '.
$this->addslashes($this->dislozierung).', '.
$this->addslashes($this->kosten).');';
@@ -217,6 +221,7 @@ class ort
'planbezeichnung='.$this->addslashes($this->planbezeichnung).', '.
'max_person='.$this->addslashes($this->max_person).', '.
'aktiv='.($this->aktiv?'true':'false') .', '.
'lehre='.($this->lehre?'true':'false') .', '.
'lageplan='.$this->addslashes($this->lageplan).', '.
'dislozierung='.$this->addslashes($this->dislozierung).', '.
'kosten='.$this->addslashes($this->kosten).' '.
+117 -50
View File
@@ -51,6 +51,9 @@ class person
var $insertvon; // varchar(16)
var $updateamum; // timestamp
var $updatevon; // varchar(16)
var $geschlecht; // varchar(1)
var $staatsbuergerschaft; // varchar(3)
var $geburtsnation; // varchar(3);
var $ext_id; // bigint
// *************************************************************************
@@ -125,6 +128,9 @@ class person
$this->updateamum = $row->updateamum;
$this->updatevon = $row->updatevon;
$this->ext_id = $row->ext_id;
$this->geschlecht = $row->geschlecht;
$this->staatsbuergerschaft = $row->staatsbuergerschaft;
$this->geburtsnation = $row->geburtsnation;
}
else
{
@@ -190,11 +196,11 @@ class person
return false;
}
//ToDo Gebdatum pruefen -> laut bis muss er aelter als 10 Jahre sein
if(strlen($this->gebdatum)==0 || is_null($this->gebdatum))
/*if(strlen($this->gebdatum)==0 || is_null($this->gebdatum))
{
$this->errormsg = 'Geburtsdatum muss eingegeben werden';
return false;
}
}*/
if(strlen($this->gebort)>128)
{
$this->errormsg = 'Geburtsort darf nicht laenger als 128 Zeichen sein';
@@ -255,15 +261,34 @@ class person
$this->errormsg = 'Ext_ID ist keine gueltige Zahl';
return false;
}
if(strlen($this->geschlecht)>1)
{
$this->errormsg = 'geschlecht darf nicht laenger als 1 Zeichen sein';
return false;
}
if(strlen($this->geburtsnation)>3)
{
$this->errormsg = 'Geburtsnation darf nicht laenger als 3 Zeichen sein';
return false;
}
if(strlen($this->staatsbuergerschaft)>3)
{
$this->errormsg = 'Staatsbuergerschaft darf nicht laenger als 3 Zeichen sein';
return false;
}
if($this->geschlecht!='m' && $this->geschlecht!='w')
{
$this->errormsg = 'Geschlecht muß entweder w oder m sein!';
}
return true;
}
// ************************************************
// * wenn $var '' ist wird "null" zurueckgegeben
// * wenn $var !='' ist werden Datenbankkritische
// * zeichen mit backslash versehen und das ergbnis
// * unter hochkomma gesetzt.
// * wenn $var !='' ist werden datenbankkritische
// * Zeichen mit backslash versehen und das Ergebnis
// * unter Hochkomma gesetzt.
// ************************************************
function addslashes($var)
{
@@ -286,30 +311,34 @@ class person
{
$qry = 'INSERT INTO tbl_person (sprache, anrede, titelpost, titelpre, nachname, vorname, vornamen,
gebdatum, gebort, gebzeit, foto, anmerkungen, homepage, svnr, ersatzkennzeichen,
familienstand, anzahlkinder, aktiv, insertamum, insertvon, updateamum, updatevon , ext_id)
familienstand, anzahlkinder, aktiv, insertamum, insertvon, updateamum, updatevon,
geschlecht, geburtsnation, staatsbuergerschaft, ext_id)
VALUES('.$this->addslashes($this->sprache).','.
$this->addslashes($this->anrede).','.
$this->addslashes($this->titelpost).','.
$this->addslashes($this->titelpre).','.
$this->addslashes($this->nachname).','.
$this->addslashes($this->vorname).','.
$this->addslashes($this->vornamen).','.
$this->addslashes($this->gebdatum).','.
$this->addslashes($this->gebort).','.
$this->addslashes($this->gebzeit).','.
$this->addslashes($this->foto).','.
$this->addslashes($this->anmerkungen).','.
$this->addslashes($this->homepage).','.
$this->addslashes($this->svnr).','.
$this->addslashes($this->ersatzkennzeichen).','.
$this->addslashes($this->familienstand).','.
$this->addslashes($this->anzahlkinder).','.
($this->aktiv?'true':'false').','.
$this->addslashes($this->insertamum).','.
$this->addslashes($this->insertvon).','.
$this->addslashes($this->updateamum).','.
$this->addslashes($this->updatevon).','.
$this->addslashes($this->ext_id).');';
$this->addslashes($this->titelpre).','.
$this->addslashes($this->nachname).','.
$this->addslashes($this->vorname).','.
$this->addslashes($this->vornamen).','.
$this->addslashes($this->gebdatum).','.
$this->addslashes($this->gebort).','.
$this->addslashes($this->gebzeit).','.
$this->addslashes($this->foto).','.
$this->addslashes($this->anmerkungen).','.
$this->addslashes($this->homepage).','.
$this->addslashes($this->svnr).','.
$this->addslashes($this->ersatzkennzeichen).','.
$this->addslashes($this->familienstand).','.
$this->addslashes($this->anzahlkinder).','.
($this->aktiv?'true':'false').','.
$this->addslashes($this->insertamum).','.
$this->addslashes($this->insertvon).','.
$this->addslashes($this->updateamum).','.
$this->addslashes($this->updatevon).','.
$this->addslashes($this->geschlecht).','.
$this->addslashes($this->geburtsnation).','.
$this->addslashes($this->staatsbuergerschaft).','.
$this->addslashes($this->ext_id).');';
}
else
{
@@ -319,30 +348,68 @@ class person
$this->errormsg = 'person_id muss eine gueltige Zahl sein';
return false;
}
$qry = 'UPDATE tbl_person SET'.
' sprache='.$this->addslashes($this->sprache).','.
' anrede='.$this->addslashes($this->anrede).','.
' titelpost='.$this->addslashes($this->titelpost).','.
' titelpre='.$this->addslashes($this->titelpre).','.
' nachname='.$this->addslashes($this->nachname).','.
' vorname='.$this->addslashes($this->vorname).','.
' vornamen='.$this->addslashes($this->vornamen).','.
' gebdatum='.$this->addslashes($this->gebdatum).','.
' gebort='.$this->addslashes($this->gebort).','.
' gebzeit='.$this->addslashes($this->gebzeit).','.
' foto='.$this->addslashes($this->foto).','.
' anmerkungen='.$this->addslashes($this->anmerkungen).','.
' homepage='.$this->addslashes($this->homepage).','.
' svnr='.$this->addslashes($this->svnr).','.
' ersatzkennzeichen='.$this->addslashes($this->ersatzkennzeichen).','.
' familienstand='.$this->addslashes($this->familienstand).','.
' anzahlkinder='.$this->addslashes($this->anzahlkinder).','.
' aktiv='.($this->aktiv?'true':'false').','.
' updateamum='.$this->addslashes($this->updateamum).','.
' updatevon='.$this->addslashes($this->updatevon).','.
' ext_id='.$this->addslashes($this->ext_id).
" WHERE person_id='$this->person_id'";
//update nur wenn änderungen gemacht
$qry="SELECT * FROM tbl_person";
if($result = pg_query($conn, $qry))
{
while($row = pg_fetch_object($result))
{
$update=false;
if($row->sprache!=$this->sprache) $update=true;
if($row->anrede!=$this->anrede) $update=true;
if($row->titelpost!=$this->titelpost) $update=true;
if($row->titelpre!=$this->titelpre) $update=true;
if($row->nachname!=$this->nachname) $update=true;
if($row->vorname!=$this->vorname) $update=true;
if($row->vornamen!=$this->vornamen) $update=true;
if($row->gebdatum!=$this->gebdatum) $update=true;
if($row->gebort!=$this->gebort) $update=true;
if($row->gebzeit!=$this->gebzeit) $update=true;
if($row->foto!=$this->foto) $update=true;
if($row->anmerkungen!=$this->anmerkungen) $update=true;
if($row->homepage!=$this->homepage) $update=true;
if($row->svnr!=$this->svnr) $update=true;
if($row->ersatzkennzeichen!=$this->ersatzkennzeichen) $update=true;
if($row->familienstand!=$this->familienstand) $update=true;
if($row->anzahlkinder!=$this->anzahlkinder) $update=true;
if($row->aktiv!=$this->aktiv) $update=true;
if($row->geburtsnation!=$this->geburtsnation) $update=true;
if($row->geschlecht!=$this->geschlecht) $update=true;
if($row->staatsbuergerschaft!=$this->staatsbuergerschaft) $update=true;
if($update)
{
$qry = 'UPDATE tbl_person SET'.
' sprache='.$this->addslashes($this->sprache).','.
' anrede='.$this->addslashes($this->anrede).','.
' titelpost='.$this->addslashes($this->titelpost).','.
' titelpre='.$this->addslashes($this->titelpre).','.
' nachname='.$this->addslashes($this->nachname).','.
' vorname='.$this->addslashes($this->vorname).','.
' vornamen='.$this->addslashes($this->vornamen).','.
' gebdatum='.$this->addslashes($this->gebdatum).','.
' gebort='.$this->addslashes($this->gebort).','.
' gebzeit='.$this->addslashes($this->gebzeit).','.
' foto='.$this->addslashes($this->foto).','.
' anmerkungen='.$this->addslashes($this->anmerkungen).','.
' homepage='.$this->addslashes($this->homepage).','.
' svnr='.$this->addslashes($this->svnr).','.
' ersatzkennzeichen='.$this->addslashes($this->ersatzkennzeichen).','.
' familienstand='.$this->addslashes($this->familienstand).','.
' anzahlkinder='.$this->addslashes($this->anzahlkinder).','.
' aktiv='.($this->aktiv?'true':'false').','.
' updateamum='.$this->addslashes($this->updateamum).','.
' updatevon='.$this->addslashes($this->updatevon).','.
' geschlecht='.$this->addslashes($this->geschlecht).','.
' geburtsnation='.$this->addslashes($this->geburtsnation).','.
' staatsbuergerschaft='.$this->addslashes($this->staatsbuergerschaft).','.
' ext_id='.$this->addslashes($this->ext_id).
" WHERE person_id='$this->person_id'";
}
}
}
}
if(pg_query($this->conn,$qry))