SYNC FAS Adresse mit Firma

This commit is contained in:
Rudolf Hangl
2006-12-18 16:57:02 +00:00
parent e2947bc1f9
commit c187c5c1fe
4 changed files with 503 additions and 54 deletions
+184
View File
@@ -0,0 +1,184 @@
<?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 Adressendatensaetze von Vilesci DB in PORTAL DB
//*
//*
include('../../../vilesci/config.inc.php');
include('../../../include/adresse.class.php');
include('../../../include/firma.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;
$anzahl_quelle2=0;
$anzahl_eingefuegt2=0;
$anzahl_fehler2=0;
function validate($row)
{
}
/*************************
* FAS-PORTAL - Synchronisation
*/
//nation
$qry = "SELECT * FROM adresse";
if($result = pg_query($conn_fas, $qry))
{
echo nl2br("Adresse Sync\n--------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
$error=false;
$adresse =new adresse($conn);
$adresse->name =$row->name;
$adresse->strasse =$row->strasse;
$adresse->plz =$row->plz;
$adresse->ort =$row->ort;
$adresse->gemeinde =$row->gemeinde;
$adresse->nation =$row->nation;
$adresse->typ =$row->typ;
$adresse->heimatadresse =$row->bismeldeadresse=='J'?true:false;
$adresse->zustelladresse =$row->zustelladresse=='J'?true:false;
$adresse->firma_id =null;
//$adresse->updateamum =$row->;
$adresse->updatevon ="SYNC";
//$adresse->insertamum =$row->;
$adresse->insertvon ="SYNC";
$adresse->ext_id =$row->adresse_pk;
//person_id herausfinden
$qry1="SELECT person_portal FROM public.tbl_syncperson WHERE person_fas=".$row->adresse_pk.";";
if($result1 = pg_query($conn, $qry1))
{
if(pg_num_rows($result1)>0) //eintrag gefunden
{
if($row1=pg_fetch_object($result1))
{
$adresse->person_id=$row1->person_portal;
$adresse->new=true;
//firma eintragen
if ($row->typ==1)
{
$anzahl_quelle2++;
$firma=new firma($conn);
$firma->name=$row->bezeichnung;
$firma->anmerkung=null;
$firma->ext_id=$row->adresse_pk;
$qry2="SELECT firma_id, ext_id FROM tbl_firma WHERE ext_id=".$row->adresse_pk.";";
if($result2 = pg_query($conn, $qry2))
{
if(pg_num_rows($result2)>0) //eintrag gefunden
{
if($row2=pg_fetch_object($result2))
{
$firma->new=false;
$firma->firma_id=$row2->firma_id;
}
else
{
$error=true;
$error_log.="firma mit adresse_pk: $row->adresse_pk konnte nicht ermittelt werden!\n";
}
}
else
{
$firma->new=true;
}
}
if(!$error)
{
if(!$firma->save())
{
$error_log.=$firma->errormsg."\n";
$anzahl_fehler2++;
}
else
{
$anzahl_eingefuegt2++;
}
$adresse->firma_id=$firma->firma_id;
}
}
}
else
{
$error=true;
$error_log.="adresse mit adresse_pk: ".$row->adresse_pk." konnte nicht ermittelt werden! (".pg_num_rows($result1).")\n";
$anzahl_fehler++;
}
}
else
{
$error=true;
$error_log.="adresse mit adresse_pk: $row->adresse_pk konnte nicht gefunden werden! (".pg_num_rows($result1).")\n";
$anzahl_fehler++;
}
}
if(!$error)
{
if(!$adresse->save())
{
$error_log.=$adresse->errormsg."\n";
$anzahl_fehler++;
}
else
{
$anzahl_eingefuegt++;
}
}
}
}
?>
<html>
<head>
<title>Synchro - Vilesci -> Portal - Adresse</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("\nAdresse\nGesamt: $anzahl_quelle / Eingefügt: $anzahl_eingefuegt / Fehler: $anzahl_fehler");
echo nl2br("\nFirma\nGesamt: $anzahl_quelle2 / Eingefügt: $anzahl_eingefuegt2 / Fehler: $anzahl_fehler2");
?>
</body>
</html>
+109 -46
View File
@@ -1,4 +1,24 @@
<?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 Adresse (FAS-Online)
* @create 13-03-2006
@@ -12,36 +32,46 @@ class adresse
var $result = array(); // @var adresse Objekt
//Tabellenspalten
var $adresse_id; // @var integer
var $bismeldeadresse; // @var boolean
var $gemeinde; // @var string
var $name; // @var string
var $nation; // @var string
var $ort; // @var string
var $person_id; // @var integer
var $plz; // @var string
var $strasse; // @var string
var $typ; // @var integer
var $updateamum; // @var timestamp
var $updatevon=0; // @var string
var $zustelladresse; // @var boolean
var $adresse_id; // @var integer
var $person_id; // @var integer
var $name; // @var string
var $strasse; // @var string
var $plz; // @var string
var $ort; // @var string
var $gemeinde; // @var string
var $nation; // @var string
var $typ; // @var integer
var $heimatadresse; // @var boolean
var $zustelladresse; // @var boolean
var $firma_id; // @var integer
var $updateamum; // @var timestamp
var $updatevon=0; // @var string
var $insertamum; // @var timestamp
var $insertvon=0; // @var string
var $ext_id; // @var integer
/**
* Konstruktor
* @param $conn Connection
* $adress_id ID der Adresse die geladen werden soll (Default=null)
*/
function adresse($conn,$adress_id=null)
function adresse($conn,$adress_id=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";
return false;
}
if($adress_id != null)
$this->load($adress_id);
//if($adress_id != null) $this->load($adress_id);
}
/**
@@ -60,7 +90,7 @@ class adresse
}
//Daten aus der Datenbank lesen
$qry = "SELECT * FROM adresse WHERE adresse_pk=$adress_id";
$qry = "SELECT * FROM tbl_adresse WHERE adresse_id=$adress_id";
if(!$res = pg_query($this->conn,$qry))
{
@@ -71,18 +101,21 @@ class adresse
if($row = pg_fetch_object($res))
{
$this->adresse_id = $row->adresse_pk;
$this->bismeldeadresse = ($row->bismeldeadresse=='J'?true:false);
$this->heimatadresse = ($row->heimatadresse=='J'?true:false);
$this->zustelladresse = ($row->zustelladresse=='J'?true:false);
$this->gemeinde = $row->gemeinde;
$this->name = $row->name;
$this->nation = $row->nation;
$this->ort = $row->ort;
$this->person_id = $row->person_fk;
$this->person_id = $row->person_id;
$this->plz = $row->plz;
$this->strasse = $row->strasse;
$this->typ = $row->typ;
$this->updateamum = $row->creationdate;
$this->updatevon = $row->creationuser;
$this->zustelladresse = ($row->zustelladresse=='J'?true:false);
$this->updateamum = $row->updateamum;
$this->updatevon = $row->updatevon;
$this->updateamum = $row->insertamum;
$this->updatevon = $row->inservon;
$this->firma_id=$row->firma_id;
}
else
{
@@ -184,54 +217,63 @@ class adresse
function checkvars()
{
//Zahlenfelder pruefen
$this->errormsg='Ein Zahlenfeld enthaelt ungueltige Zeichen';
if(!is_numeric($this->person_id))
{
$this->errormsg='Person_id enthaelt ungueltige Zeichen:'.$this->person_id;
$this->errormsg='person_id enthaelt ungueltige Zeichen:'.$this->person_id.' - person: '.$row->adresse_id;
return false;
}
if(!is_numeric($this->typ))
{
$this->errormsg='Typ enthaelt ungueltige Zeichen';
$this->errormsg='Typ enthaelt ungueltige Zeichen - person: '.$row->adresse_id;
return false;
}
//Gesamtlaenge pruefen
$this->errormsg='Eine der Gesamtlaengen wurde ueberschritten';
//$this->errormsg='Eine der Gesamtlaengen wurde ueberschritten';
if(strlen($this->name)>255)
{
$this->errormsg = 'Name darf nicht länger als 255 Zeichen sein';
$this->errormsg = 'Name darf nicht länger als 255 Zeichen sein - person: '.$row->adresse_id;
return false;
}
if(strlen($this->strasse)>255)
{
$this->errormsg = 'Strasse darf nicht länger als 255 Zeichen sein';
$this->errormsg = 'Strasse darf nicht länger als 255 Zeichen sein - person: '.$row->adresse_id;
return false;
}
if(strlen($this->plz)>10)
{
$this->errormsg = 'Plz darf nicht länger als 10 Zeichen sein';
$this->errormsg = 'Plz darf nicht länger als 10 Zeichen sein - person: '.$row->adresse_id;
return false;
}
if(strlen($this->ort)>255)
{
$this->errormsg = 'Ort darf nicht länger als 255 Zeichen sein';
$this->errormsg = 'Ort darf nicht länger als 255 Zeichen sein - person: '.$row->adresse_id;
return false;
}
if(strlen($this->nation)>3)
{
$this->errormsg = 'Nation darf nicht länger als 3 Zeichen sein';
$this->errormsg = 'Nation darf nicht länger als 3 Zeichen sein - person: '.$row->adresse_id;
return false;
}
if(strlen($this->gemeinde)>255)
{
$this->errormsg = 'Gemeinde darf nicht länger als 255 Zeichen sein';
$this->errormsg = 'Gemeinde darf nicht länger als 255 Zeichen sein - person: '.$row->adresse_id;
return false;
}
$this->errormsg = '';
return true;
}
// ************************************************
// * wenn $var '' ist wird "null" zurueckgegeben
// * wenn $var !='' ist werden datenbankkritische
// * Zeichen mit backslash versehen und das Ergebnis
// * unter Hochkomma gesetzt.
// ************************************************
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
/**
* Speichert den aktuellen Datensatz in die Datenbank
@@ -250,7 +292,7 @@ class adresse
//Neuen Datensatz einfuegen
//naechste ID aus der Sequence holen
$qry="SELECT nextval('adresse_seq') as id;";
$qry="SELECT nextval('tbl_adresse_adresse_id_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn,$qry)))
{
$this->errormsg = 'Fehler beim auslesen der Sequence';
@@ -258,11 +300,23 @@ class adresse
}
$this->adresse_id = $row->id;
$qry="INSERT INTO adresse (adresse_pk, person_fk, name, strasse, plz, typ, ort, nation, creationdate, creationuser,".
" gemeinde, bismeldeadresse, zustelladresse) VALUES(".
" $this->adresse_id, $this->person_id, '$this->name', '$this->strasse', '$this->plz', $this->typ, '$this->ort',".
" '$this->nation', now(), $this->updatevon, '$this->gemeinde', '".($this->bismeldeadresse?'J':'N')."',".
" '".($this->zustelladresse?'J':'N')."');";
$qry='INSERT INTO tbl_adresse (adresse_id, person_id, name, strasse, plz, typ, ort, nation, insertamum, insertvon,
gemeinde, heimatadresse, zustelladresse, firma_id, updateamum, updatevon, ext_id) VALUES('.
$this->addslashes($this->adresse_id).', '.
$this->addslashes($this->person_id).', '.
$this->addslashes($this->name).', '.
$this->addslashes($this->strasse).', '.
$this->addslashes($this->plz).', '.
$this->addslashes($this->typ).', '.
$this->addslashes($this->ort).', '.
$this->addslashes($this->nation).', now(), '.
$this->addslashes($this->insertvon).', '.
$this->addslashes($this->gemeinde).', '.
($this->heimatadresse?'true':'false').', '.
($this->zustelladresse?'true':'false').', '.
($this->firma_id!=null?$this->addslashes($this->firma_id):'null').', now(), '.
$this->addslashes($this->updatevon).', '.
$this->addslashes($this->ext_id).');';
}
else
{
@@ -275,16 +329,24 @@ class adresse
return false;
}
$qry="UPDATE adresse SET person_fk='$this->person_id', name='$this->name', strasse='$this->strasse', plz='$this->plz',".
" typ='$this->typ', ort='$this->ort', nation='$this->nation', gemeinde='$this->gemeinde',".
" bismeldeadresse='".($this->bismeldeadresse?'J':'N')."', zustelladresse='".($this->zustelladresse?'J':'N')."'".
" WHERE adresse_pk='$this->adresse_id'";
$qry='UPDATE tbl_adresse SET'.
' person_fk='.$this->addslashes($this->person_id).', '.
' name='.$this->addslashes($this->name).', '.
' strasse='.$this->addslashes($this->strasse).', '.
' plz='.$this->addslashes($this->plz).', '.
' typ='.$this->addslashes($this->typ).', '.
' ort='.$this->addslashes($this->ort).', '.
' nation='.$this->addslashes($this->nation).', '.
' gemeinde='.$this->addslashes($this->gemeinde).', '.
' heimatadresse='.($this->heimatadresse?'true':'false').', '.
' zustelladresse='.($this->zustelladresse?'true':'false').', '.
'WHERE adresse_pk='.$this->adresse_id.';';
}
//echo $qry;
if(pg_query($this->conn,$qry))
{
//Log schreiben
$sql = $qry;
/*$sql = $qry;
$qry = "SELECT nextval('log_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn, $qry)))
{
@@ -299,7 +361,8 @@ class adresse
{
$this->errormsg = 'Fehler beim Speichern des Log-Eintrages';
return false;
}
} */
return true;
}
else
{
+202
View File
@@ -0,0 +1,202 @@
<?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 firma
* @create 18-12-2006
*/
class firma
{
var $conn; // @var resource DB-Handle
var $new; // @var boolean
var $errormsg; // @var string
var $result = array(); // @var adresse Objekt
//Tabellenspalten
var $firma_id; // @var integer
var $name; // @var string
var $anmerkung; // @var string
var $ext_id; // @var integer
var $insertamum; // @var timestamp
var $insertvon; // @var bigint
var $updateamum; // @var timestamp
var $updatevon; // @var bigint
/**
* Konstruktor
* @param $conn Connection
* $firma_id ID der Adresse die geladen werden soll (Default=null)
*/
function firma($conn,$firma_id=null, $unicode=false)
{
$this->conn = $conn;
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";
return false;
}
//if($firma_id != null) $this->load($firma_id);
}
/**
* Laedt die Funktion mit der ID $adress_id
* @param $adress_id ID der zu ladenden Funktion
* @return true wenn ok, false im Fehlerfall
*/
function load($adress_id)
{
//noch nicht implementiert
}
/**
* Prueft die Variablen auf gueltigkeit
* @return true wenn ok, false im Fehlerfall
*/
function checkvars()
{
//Gesamtlaenge pruefen
//$this->errormsg='Eine der Gesamtlaengen wurde ueberschritten';
if(strlen($this->name)>64)
{
$this->errormsg = 'Name darf nicht länger als 64 Zeichen sein - firma_id: '.$row->firma_id;
return false;
}
if(strlen($this->anmerkung)>256)
{
$this->errormsg = 'anmerkung darf nicht länger als 256 Zeichen sein - firma_id: '.$row->firma_id;
return false;
}
$this->errormsg = '';
return true;
}
// ************************************************
// * wenn $var '' ist wird "null" zurueckgegeben
// * wenn $var !='' ist werden datenbankkritische
// * Zeichen mit backslash versehen und das Ergebnis
// * unter Hochkomma gesetzt.
// ************************************************
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
/**
* Speichert den aktuellen Datensatz in die Datenbank
* Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt
* andernfalls wird der Datensatz mit der ID in $firma_id aktualisiert
* @return true wenn ok, false im Fehlerfall
*/
function save()
{
//Variablen pruefen
if(!$this->checkvars())
return false;
if($this->new)
{
//Neuen Datensatz einfuegen
//naechste ID aus der Sequence holen
$qry="SELECT nextval('public.tbl_firma_firma_id_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn,$qry)))
{
$this->errormsg = 'Fehler beim Auslesen der Sequence';
return false;
}
$this->firma_id = $row->id;
$qry='INSERT INTO tbl_firma (firma_id, name, anmerkung, ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('.
$this->addslashes($this->firma_id).', '.
$this->addslashes($this->name).', '.
$this->addslashes($this->anmerkung).', '.
$this->addslashes($this->ext_id).', now(), '.
$this->addslashes($this->insertvon).', now(), '.
$this->addslashes($this->updatevon).');';
}
else
{
//Updaten des bestehenden Datensatzes
//Pruefen ob firma_id eine gueltige Zahl ist
if(!is_numeric($this->firma_id))
{
$this->errormsg = 'firma_id muss eine gueltige Zahl sein';
return false;
}
$qry='UPDATE tbl_firma SET '.
'firma_id='.$this->addslashes($this->firma_id).', '.
'name='.$this->addslashes($this->name).', '.
'anmerkung='.$this->addslashes($this->anmerkung).', '.
'updateamum= now(), '.
'updatevon='.$this->addslashes($this->updatevon).' '.
'WHERE ext_id='.$this->addslashes($this->ext_id).';';
}
//echo $qry;
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 der Daten';
return false;
}
}
/**
* Loescht den Datenensatz mit der ID die uebergeben wird
* @param $firma_id ID die geloescht werden soll
* @return true wenn ok, false im Fehlerfall
*/
function delete($firma_id)
{
//noch nicht implementiert!
}
}
?>
+8 -8
View File
@@ -42,7 +42,7 @@ class person
var $foto; // oid
var $anmerkungen; // varchar(256)
var $homepage; // varchar(256)
var $svnr; // char(10)
var $svnr; // char(10)
var $ersatzkennzeichen; // char(10)
var $familienstand; // char(1)
var $anzahlkinder; // smalint
@@ -356,7 +356,7 @@ class person
while($row = pg_fetch_object($result))
{
$update=false;
if($row->sprache!=$this->sprache) $update=true;
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;
@@ -371,12 +371,12 @@ class person
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($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)