SYNC FAS Person

This commit is contained in:
Rudolf Hangl
2006-12-11 17:04:23 +00:00
parent 88794724b6
commit fb802ed08f
5 changed files with 631 additions and 3 deletions
+150
View File
@@ -0,0 +1,150 @@
<?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 Personendatensaetze von FAS DB in PORTAL DB
//*
//*
include('../../../vilesci/config.inc.php');
include('../../../include/person.class.php');
$conn=pg_connect(CONN_STRING) or die("Connection zur Portal Datenbank fehlgeschlagen");
//$conn_vilesci=pg_connect(CONN_STRING_VILESCI) or die("Connection zur Vilesci 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;
/*************************
* FAS-PORTAL - Synchronisation
*/
?>
<html>
<head>
<title>Synchro - FAS -> Portal - Person</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//person
$qry = "SELECT * FROM person";
if($result = pg_query($conn_fas, $qry))
{
echo nl2br("Person Sync\n-------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
$person=new person($conn);
$person->geburtsnation=$row->gebnation;
$person->anrede=$row->anrede;
$person->titelpost=$row->postnomentitel;
$person->titelpre=$row->titel;
$person->nachname=$row->familienname;
$person->vorname=$row->vorname;
$person->vornamen=$row->vornamen;
$person->gebdatum=$row->gebdat;
$person->gebort=$row->gebort;
$person->anmerkungen=$row->bemerkung;
$person->svnr=$row->svnr;
$person->ersatzkennzeichen=$row->ersatzkennzeichen;
$person->familienstand=$row->familienstand;
$person->staatsbuergerschaft=$row->staatsbuergerschaft;
$person->geschlecht=$row->geschlecht;
$person->ext_id=$row->person_pk;
$person->aktiv=true;
if ($row->familienstand==0)
{
$person->familienstand=null;
}
elseif($row->familienstand==1)
{
$person->familienstand='l';
}
elseif($row->familienstand==2)
{
$person->familienstand=='v';
}
elseif($row->familienstand==3)
{
$person->familienstand=='g';
}
elseif($row->familienstand==4)
{
$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))
{
if(pg_num_rows($result1)>0) //wenn dieser eintrag schon vorhanden ist
{
if($row1=pg_fetch_object($result1))
{
//update
$person->new=false;
}
else
{
$error=true;
$error_log.="person von $row->person_pk konnte nicht ermittelt werden\n";
}
}
else
{
//insert
$person->new=true;
}
if(!$error)
if(!$person->save())
{
$error_log.=$person->errormsg."\n";
$anzahl_fehler++;
}
else
$anzahl_eingefuegt++;
else
$anzahl_fehler++;
}
}
echo nl2br("abgeschlossen\n\n");
}
else
$error_log .= 'Personendatensaetze konnten nicht geladen werden';
//echo nl2br($text);
echo nl2br($error_log);
echo nl2br("\nGesamt: $anzahl_quelle / Eingefügt: $anzahl_eingefuegt / Fehler: $anzahl_fehler");
?>
</body>
</html>
@@ -53,7 +53,7 @@ $qry = "SELECT * FROM tbl_fachbereich";
if($result = pg_query($conn_vilesci, $qry))
{
echo nl2br("Fachbereich Sync\n---------------\n");
echo nl2br("Fachbereich Sync\n-----------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
+2 -2
View File
@@ -53,13 +53,13 @@ $qry = "SELECT * FROM tbl_funktion";
if($result = pg_query($conn_vilesci, $qry))
{
echo nl2br("Funktion Sync\n----------------------\n");
echo nl2br("Funktion Sync\n----------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
$error=false;
$funktion = new funktion($conn);
$funktion->bezeichnung =$row->bezeichnung;
$funktion->beschreibung =$row->bezeichnung;
$funktion->funktion_kurzbz =$row->funktion_kurzbz;
$funktion->aktiv =($row->aktiv=='t'?true:false);
+240
View File
@@ -0,0 +1,240 @@
<?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 benutzerfunktion (FAS-Online)
* @create 04-12-2006
*/
class benutzerfunktion
{
var $conn; // @var resource DB-Handle
var $new; // @var boolean
var $errormsg; // @var string
var $result = array(); // @var benutzerfunktion Objekt
//Tabellenspalten
var $benutzerfunktion_id; // @var serial
var $fachbereich_kurzbz; // @var integer
var $uid; // @var varchar(16)
var $studiengang_kz; // @var integer
var $funktion_kurzbz; // @var varchar(16)
var $updateamum; // @var timestamp
var $updatevon=0; // @var string
var $insertamum; // @var timestamp
var $insertvon=0; // @var string
var $ext_id; // @var bigint
/**
* Konstruktor
* @param $conn Connection zur DB
* $benutzerfunktion_id ID der zu ladenden Funktion
*/
function benutzerfunktion($conn, $benutzerfunktion_id=null)
{
$this->conn = $conn;
if($benutzerfunktion_id != null)
$this->load($benutzerfunktion_id);
}
/**
* Laedt alle verfuegbaren Benutzerfunktionen
* @return true wenn ok, false im Fehlerfall
*/
function getAll()
{
$qry = 'SELECT * FROM tbl_benutzerfunktion ORDER BY benutzerfunktion_id;';
if(!$res = pg_query($this->conn, $qry))
{
$this->errormsg = 'Fehler beim Laden der Datensaetze';
return false;
}
while($row = pg_fetch_object($res))
{
$pfunktion_obj = new personenfunktion($this->conn);
$pfunktion_obj->benutzerfunktion_id = $row->benutzerfunktion_id;
$pfunktion_obj->fachbereich_kurzbz = $row->fachbereich_kurzbz;
$pfunktion_obj->uid = $row->uid;
$pfunktion_obj->studiengang_kz = $row->studiengang_kz;
$pfunktion_obj->funktion_kurzbz = $row->funtion_kurzbz;
$pfunktion_obj->insertamum = $row->insertamum;
$pfunktion_obj->insertvon = $row->insertvon;
$pfunktion_obj->updateamum = $row->updateamum;
$pfunktion_obj->updatevon = $row->updatevon;
$this->result[] = $pfunktion_obj;
}
return true;
}
/**
* Laedt eine Benutzerfunktion
* @param $bnutzerfunktion_id ID der zu ladenden Funktion
* @return true wenn ok, false im Fehlerfall
*/
function load($benutzerfunktion_id)
{
if($benutzerfunktion_id == '')
{
$this->errormsg = 'benutzerfunktion_id muß eine gültige Zahl sein';
return false;
}
$qry = "SELECT * FROM tbl_benutzerfunktion WHERE benutzerfunktion_id = '$this->benutzerfunktion_id';";
if(!$res = pg_query($this->conn, $qry))
{
$this->errormsg = 'Fehler beim Laden des Datensatzes';
return false;
}
if($row=pg_fetch_object($res))
{
$this->benutzerfunktion_id = $row->benutzerfunktion_id;
$this->fachbereich_kurzbz = $row->fachbereich_kurzbz;
$this->uid = $row->uid;
$this->studiengang_kz = $row->studiengang_kz;
$this->funktion_kurzbz = $row->funktion_kurzbz;
$this->insertamum = $row->insertamum;
$this->insertvon = $row->insertvon;
$this->updateamum = $row->updateamum;
$this->updatevon = $row->updatevon;
}
else
{
$this->errormsg = 'Es ist kein Datensatz mit dieser ID vorhanden';
return false;
}
return true;
}
/**
* Loescht einen Datensatz
* @param $fbenutzerfunktion_id id des Datensatzes der geloescht werden soll
* @return true wenn ok, false im Fehlerfall
*/
function delete($benutzerfunktion_id)
{
$this->errormsg = 'Noch nicht implementiert';
return false;
}
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
/**
* Speichert den aktuellen Datensatz
* @return true wenn ok, false im Fehlerfall
*/
function save()
{
//Gueltigkeit der Variablen pruefen
//if(!$this->checkvars())
// return false;
if($this->new)
{
//Neuen Datensatz anlegen
//Pruefen ob uid vorhanden
$qry = "SELECT uid FROM tbl_benutzer WHERE uid = '$this->uid';";
if(!$resx = pg_query($this->conn, $qry))
{
$this->errormsg = 'Fehler beim Laden des Datensatzes';
return false;
}
else
{
if (pg_num_rows($resx)==0)
{
$this->errormsg = "uid <b>$this->uid</b> in Tabelle tbl_benutzer nicht gefunden!";
return false;
}
}
$qry = 'INSERT INTO tbl_benutzerfunktion (fachbereich_kurzbz, uid, studiengang_kz, funktion_kurzbz, insertamum, insertvon,
updateamum, updatevon) VALUES ('.
$this->addslashes($this->fachbereich_kurzbz).', '.
$this->addslashes($this->uid).', '.
$this->addslashes($this->studiengang_kz).', '.
$this->addslashes($this->funktion_kurzbz).', '.
$this->addslashes($this->insertamum).', '.
$this->addslashes($this->insertvon).', '.
$this->addslashes($this->updateamum).', '.
$this->addslashes($this->updatevon).'); ';
}
else
{
//bestehenden Datensatz akualisieren
//Pruefen ob benutzerfunktion_id eine gueltige Zahl ist
if(!is_numeric($this->benutzerfunktion_id) || $this->benutzerfunktion_id == '')
{
$this->errormsg = 'benutzerfunktion_id muss eine gueltige Zahl sein';
return false;
}
$qry = 'UPDATE tbl_benutzerfunktion SET '.
'benutzerfunktion_id='.$this->addslashes($this->benutzerfunktion_id).', '.
'fachbereich_kurzbz='.$this->addslashes($this->fachbereich_kurzbz).', '.
'uid='.$this->addslashes($this->uid).', '.
'studiengang_kz='.$this->addslashes($this->studiengang_kz).', '.
'funktion_kurzbz='.$this->addslashes($this->funktion_kurzbz).', '.
'insertamum='.$this->addslashes($this->insertamum).', '.
'insertvon='.$this->addslashes($this->insertvon).', '.
'updateamum='.$this->addslashes($this->updateamum).', '.
'updatevon='.$this->addslashes($this->updatevon).' '.
'WHERE benutzerfunktion_id = '.$this->addslashes($this->benutzerfunktion_id).';';
}
if(pg_query($this->conn, $qry))
{
/*//Log schreiben
$sql = $qry;
$qry = "SELECT nextval('log_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn, $qry)))
{
$this->errormsg = 'Fehler beim Auslesen der Log-Sequence';
return false;
}
$qry = "INSERT INTO log(log_pk, creationdate, creationuser, sql) VALUES('$row->id', now(), '$this->updatevon', '".addslashes($sql)."')";
if(pg_query($this->conn, $qry))
return true;
else
{
$this->errormsg = 'Fehler beim Speichern des Log-Eintrages';
return false;
}*/
return true;
}
else
{
$this->errormsg = 'Fehler beim Speichern des Datensatzes - '.$this->uid;
return false;
}
}
}
?>
+238
View File
@@ -0,0 +1,238 @@
<?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 fas_person (FAS-Online)
* @create 11-12-2006
*/
class fas_person
{
var $conn; // @var resource DB-Handle
var $new; // @var boolean
var $errormsg; // @var string
var $result = array(); // @var fachbereich Objekt
//Tabellenspalten
var $geburtsnation; // @var string
var $anrede; // @var string
var $titelpost; // @var string
var $titelpre; // @var string
var $nachname; // @var string
var $vorname; // @var string
var $vornamen; // @var string
var $gebdatum; // @var date
var $gebort; // @var string
var $anmerkungen; // @var string
var $svnr; // @var string
var $ersatzkennzeichen; // @var string
var $familienstand; // @var string
var $anzahlkinder; // @var smallint
var $staatsbuergerschaft; // @var string
var $geschlecht; // @var string
var $insertamum; // @var timestamp
var $insertvon; // @var string
var $ext_id; // @var bigint
/**
* Konstruktor
* @param $conn Connection zur DB
* $person_id ID der zu ladenden Person
*/
function fas_person($conn, $person_id=null)
{
$this->conn = $conn;
// if($person_id != null) $this->load($person_id);
}
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
function validate($row)
{
$this->geburtsnation = str_replace("'",'´',$this->geburtsnation);
$this->anrede = str_replace("'",'´',$this->anrede);
$this->titelpost = str_replace("'",'´',$this->titelpost);
$this->titelpre = str_replace("'",'´',$this->titelpre);
$this->nachname = str_replace("'",'´',$this->nachname);
$this->vorname = str_replace("'",'´',$this->vorname);
$this->vornamen = str_replace("'",'´',$this->vornamen);
$this->anmerkungen = str_replace("'",'´',$this->anmerkungen);
$this->svnr = str_replace("'",'´',$this->svnr);
$this->ersatzkennzeichen = str_replace("'",'´',$this->ersatzkennzeichen);
//Laenge Pruefen
if(strlen($this->geburtsnation)>3)
{
$this->errormsg = "Geburtsnation darf nicht laenger als 3 Zeichen sein bei <b>$this->person_pk</b> - $this->geburtsnation";
return false;
}
if(strlen($this->anrede)>16)
{
$this->errormsg = "Anrede darf nicht laenger als 16 Zeichen sein bei <b>$this->person_pk</b> - $this->anrede";
return false;
}
if(strlen($this->titelpost)>32)
{
$this->errormsg = "Titelpost darf nicht laenger als 32 Zeichen sein bei <b>$this->person_pk</b> - $this->titelpost";
return false;
}
if(strlen($this->titelpre)>64)
{
$this->errormsg = "Titelpre darf nicht laenger als 64 Zeichen sein bei <b>$this->person_pk</b> - $this->titelpre";
return false;
}
if(strlen($this->nachname)>64)
{
$this->errormsg = "Nachname darf nicht laenger als 64 Zeichen sein bei <b>$this->person_pk</b> - $this->nachname";
return false;
}
if(strlen($this->vorname)>32)
{
$this->errormsg = "Vorname darf nicht laenger als 32 Zeichen sein bei <b>$this->person_pk</b> - $this->vorname";
return false;
}
if(strlen($this->vornamen)>128)
{
$this->errormsg = "Vornamen darf nicht laenger als 128 Zeichen sein bei <b>$this->person_pk</b> - $this->vornamen";
return false;
}
if(strlen($this->anmerkungen)>256)
{
$this->errormsg = "Anmerkungen (Bemerkung) darf nicht laenger als 256 Zeichen sein bei <b>$this->person_pk</b> - $this->bemerkung";
return false;
}
if(strlen($this->svnr)>10)
{
$this->errormsg = "SVNr darf nicht laenger als 8 Zeichen sein bei <b>$this->person_pk</b> - $this->svnr";
return false;
}
if(strlen($this->ersatzkennzeichen)>10)
{
$this->errormsg = "Ersatzkennzeichen darf nicht laenger als 8 Zeichen sein bei <b>$this->person_pk</b> - $this->ersatzkennzeichen";
return false;
}
}
/**
* Speichert den aktuellen Datensatz
* @return true wenn ok, false im Fehlerfall
*/
function save()
{
//Gueltigkeit der Variablen pruefen
if(!$this->checkvars())
return false;
if($this->new)
{
//Pruefen ob person_id gueltig ist
if($this->person_id == '' || !is_numeric(person_id))
{
$this->errormsg = 'person_id ungueltig!';
return false;
}
//Neuen Datensatz anlegen
$qry = 'INSERT INTO tbl_person (geburtsnation, anrede, titelpost, titelpre, nachname, vorname, vornamen,
gebdatum, gebort, anmerkungen, svnr, ersatzkennzeichen, familienstand, anzahlkinder,
staatsbuergerschaft, geschlecht, insertamum, insertvon , ext_id ) VALUES ('.
$this->addslashes($this->geburtsnation).', '.
$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($row->gebdatum).', '.
$this->addslashes($this->gebort).', '.
$this->addslashes($this->anmerkungen).', '.
$this->addslashes($this->svnr).', '.
$this->addslashes($this->ersatzkennzeichen).', '.
$this->addslashes($this->familienstand).', '.
$this->addslashes($this->anzahlkinder).', '.
$this->addslashes($this->staatsbuergerschaft).', '.
$this->addslashes($this->geschlecht).', '.
$this->addslashes($this->insertamum).', '.
'"FASsync" '.
$this->addslashes($this->ext_id).'); ';
}
else
{
//bestehenden Datensatz akualisieren
//Pruefen ob person_id gueltig ist
if($this->person_id == '' || !is_numeric(person_id))
{
$this->errormsg = 'person_id ungueltig.';
return false;
}
$qry = 'UPDATE tbl_person SET '.
'geburtsnation'.$this->addslashes($this->gebnation).', '.
'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).', '.
'anmerkungen='.$this->addslashes($this->anmerkungen).', '.
'svnr='.$this->addslashes($this->svnr).', '.
'ersatzkennzeichen='.$this->addslashes($this->ersatzkennzeichen).', '.
'familienstand='.$this->addslashes($this->familienstand).', '.
'anzahlkinder='.$this->addslashes($this->anzahlkinder).', '.
'staatsbuergerschaft='.$this->addslashes($this->staatsbuergerschaft).', '.
'geschlecht='.$row->addslashes($this->geschlecht).', '.
'insertamum='.$this->addslashes($this->insertamum).', '.
'insertvon= FASsync, '.
'WHERE ext_id = '.$this->addslashes($this->ext_id).';';
}
if(pg_query($this->conn, $qry))
{
/*//Log schreiben
$sql = $qry;
$qry = "SELECT nextval('log_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn, $qry)))
{
$this->errormsg = 'Fehler beim Auslesen der Log-Sequence';
return false;
}
$qry = "INSERT INTO log(log_pk, creationdate, creationuser, sql) VALUES('$row->id', now(), '$this->updatevon', '".addslashes($sql)."')";
if(pg_query($this->conn, $qry))
return true;
else
{
$this->errormsg = 'Fehler beim Speichern des Log-Eintrages';
return false;
}*/
return true;
}
else
{
$this->errormsg = 'Fehler beim Speichern des Datensatzes';
return false;
}
}
}
?>