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
+100
View File
@@ -0,0 +1,100 @@
<?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>.
*/
//*
//* Synchronisiert Nationendatensaetze von Vilesci DB in PORTAL DB
//*
//*
include('../../../vilesci/config.inc.php');
include('../../../include/nation.class.php');
$conn=pg_connect(CONN_STRING) or die("Connection zur Portal Datenbank fehlgeschlagen");
$conn_fas=pg_connect(CONN_STRING_FAS) or die("Connection zur FAS Datenbank fehlgeschlagen");
$adress='ruhan@technikum-wien.at';
//$adress='fas_sync@technikum-wien.at';
$error_log='';
$text = '';
$anzahl_quelle=0;
$anzahl_eingefuegt=0;
$anzahl_fehler=0;
function validate($row)
{
}
/*************************
* FAS-PORTAL - Synchronisation
*/
//nation
$qry = "SELECT * FROM nation";
if($result = pg_query($conn_fas, $qry))
{
echo nl2br("Nation Sync\n--------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
$error=false;
$nation =new nation($conn);
$nation->code =$row->code;
$nation->entwicklungsstand =$row->entwland;
$nation->eu =$row->euflag=='U'?true:false;
$nation->ewr =$row->ewrflag=='W'?true:false;
$nation->kontinent =$row->kontinent;
$nation->kurztext =$row->kurztext;
$nation->langtext =$row->langtext;
$nation->engltext =$row->engltext;
$nation->sperre =$row->sperre=='J'?true:false;
if(!$nation->save())
{
$error_log.=$nation->errormsg."\n";
$anzahl_fehler++;
}
else
{
$anzahl_eingefuegt++;
}
}
}
?>
<html>
<head>
<title>Synchro - Vilesci -> Portal - Nation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//echo nl2br($text);
echo nl2br($error_log);
echo nl2br("\nGesamt: $anzahl_quelle / Eingefügt: $anzahl_eingefuegt / Fehler: $anzahl_fehler");
?>
</body>
</html>
+82 -11
View File
@@ -53,6 +53,9 @@ $anzahl_fehler=0;
<body>
<?php
//person
flush();
?>
<?php
$qry = "SELECT * FROM person";
if($result = pg_query($conn_fas, $qry))
{
@@ -61,6 +64,7 @@ if($result = pg_query($conn_fas, $qry))
while($row = pg_fetch_object($result))
{
$person=new person($conn);
$person->geburtsnation=$row->gebnation;
$person->anrede=$row->anrede;
$person->titelpost=$row->postnomentitel;
@@ -99,39 +103,106 @@ if($result = pg_query($conn_fas, $qry))
{
$person->familienstand=='w';
}
$error=false;
$qry="SELECT ext_id FROM public.tbl_person WHERE ext_id='$row->person_pk'";
if($result1 = pg_query($conn, $qry))
$qry="SELECT person_id FROM public.tbl_benutzer WHERE uid='$row->uid'";
if($resultu = pg_query($conn, $qry))
{
if(pg_num_rows($result1)>0) //wenn dieser eintrag schon vorhanden ist
if(pg_num_rows($resultu)>0) //wenn dieser eintrag schon vorhanden ist
{
if($row1=pg_fetch_object($result1))
if($rowu=pg_fetch_object($resultu))
{
//update
$person->new=false;
$person->person_id=$rowu->person_id;
$person->new=false;
//echo nl2br("update1 von ".$row->uid.", ".$row->familienname."\n");
}
else
{
$error=true;
$error_log.="person von $row->person_pk konnte nicht ermittelt werden\n";
$error_log.="benutzer von $row->uid konnte nicht ermittelt werden\n";
}
}
else
else
{
//insert
$person->new=true;
}
$qry="SELECT person_fas, person_portal FROM public.tbl_syncperson WHERE person_fas='$row->person_pk'";
if($result1 = pg_query($conn, $qry))
{
if(pg_num_rows($result1)>0) //wenn dieser eintrag schon vorhanden ist
{
if($row1=pg_fetch_object($result1))
{
//update
$person->person_id=$row1->person_portal;
$person->new=false;
//echo nl2br("update2 von ".$row->uid.", ".$row->familienname."\n");
}
else
{
$error=true;
$error_log.="person von $row->person_pk konnte nicht ermittelt werden\n";
}
}
else
{
//vergleich svnr und ersatzkennzeichen
$qry="SELECT person_id FROM public.tbl_person
WHERE ('$row->svnr' is not null AND svnr = '$row->svnr')
OR ('$row->ersatzkennzeichen' is not null AND ersatzkennzeichen = '$row->ersatzkennzeichen')";
if($resultz = pg_query($conn, $qry))
{
if(pg_num_rows($resultz)>0) //wenn dieser eintrag schon vorhanden ist
{
if($rowz=pg_fetch_object($resultz))
{
$person->new=false;
$person->person_id=$rowz->person_id;
//echo nl2br("update3 von ".$row->uid.", ".$row->familienname."\n");
}
else
{
$error=true;
$error_log.="person mit svnr: $row->svnr bzw. ersatzkennzeichen: $row->ersatzkennzeichen konnte nicht ermittelt werden (".pg_num_rows($resultz).")\n";
}
}
else
{
//insert
$person->new=true;
//echo nl2br("insert von ".$row->uid.", ".$row->familienname."\n");
}
}
}
}
}
if(!$error)
{
if(!$person->save())
{
$error_log.=$person->errormsg."\n";
$anzahl_fehler++;
}
else
{
//überprüfen, ob eintrag schon vorhanden
$qry="SELECT person_fas FROM tbl_syncperson WHERE person_fas='$row->person_pk' AND person_portal='$person->person_id'";
if($resultz = pg_query($conn, $qry))
{
if(pg_num_rows($resultz)==0) //wenn dieser eintrag noch nicht vorhanden ist
{
$qry='INSERT INTO tbl_syncperson (person_fas, person_portal)'.
'VALUES ('.$row->person_pk.', '.$person->person_id.');';
$resulti = pg_query($conn, $qry);
}
}
$anzahl_eingefuegt++;
}
}
else
{
$anzahl_fehler++;
}
}
}
echo nl2br("abgeschlossen\n\n");
+2 -1
View File
@@ -62,7 +62,8 @@ if($result = pg_query($conn_vilesci, $qry))
$ort->bezeichnung =$row->bezeichnung;
$ort->planbezeichnung =$row->planbezeichnung;
$ort->max_person =$row->max_person;
$ort->aktiv =($row->aktiv=='t'?true:false);
$ort->aktiv =($row->aktiv=='t'?true:false);
$ort->lehre =($row->lehre=='t'?true:false);
$ort->lageplan =$row->lageplan;
$ort->dislozierung =$row->dislozierung;
$ort->kosten =$row->kosten;
+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))