SYNC FAS EMail und Telefon

This commit is contained in:
Rudolf Hangl
2006-12-20 15:42:28 +00:00
parent 8c5ff5fe40
commit abbd930c7b
8 changed files with 703 additions and 108 deletions
+73 -51
View File
@@ -51,9 +51,17 @@ function validate($row)
/*************************
* FAS-PORTAL - Synchronisation
*/
?>
<html>
<head>
<title>Synchro - Vilesci -> Portal - Adresse</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//nation
$qry = "SELECT * FROM adresse";
$qry = "SELECT * FROM adresse ORDER BY person_fk;";
if($result = pg_query($conn_fas, $qry))
{
@@ -79,8 +87,9 @@ if($result = pg_query($conn_fas, $qry))
$adresse->insertvon ="SYNC";
$adresse->ext_id =$row->adresse_pk;
//echo nl2br ($adresse->ext_id."\n");
//person_id herausfinden
$qry1="SELECT person_portal FROM public.tbl_syncperson WHERE person_fas=".$row->adresse_pk.";";
$qry1="SELECT person_portal FROM public.tbl_syncperson WHERE person_fas=".$row->person_fk.";";
if($result1 = pg_query($conn, $qry1))
{
if(pg_num_rows($result1)>0) //eintrag gefunden
@@ -88,49 +97,67 @@ if($result = pg_query($conn_fas, $qry))
if($row1=pg_fetch_object($result1))
{
$adresse->person_id=$row1->person_portal;
$adresse->new=true;
//firma eintragen
if ($row->typ==1)
$qry2="SELECT adresse_id, ext_id FROM tbl_adresse WHERE ext_id=".$row->adresse_pk.";";
if($result2 = pg_query($conn, $qry2))
{
$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(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";
}
if($row2=pg_fetch_object($result2))
{
// update adresse, wenn datensatz bereits vorhanden
$adresse->new=false;
$adresse->adresse_id=$row2->adresse_id;
}
else
{
$firma->new=true;
}
}
if(!$error)
}
else
{
if(!$firma->save())
// insert, wenn datensatz noch nicht vorhanden
$adresse->new=true;
//firma eintragen, wenn firmenadresse
if ($row->typ==1)
{
$error_log.=$firma->errormsg."\n";
$anzahl_fehler2++;
}
else
{
$anzahl_eingefuegt2++;
}
$adresse->firma_id=$firma->firma_id;
$anzahl_quelle2++;
$firma=new firma($conn);
$firma->name=$row->bezeichnung;
$firma->anmerkung=null;
$firma->ext_id=$row->adresse_pk;
$qry3="SELECT firma_id, ext_id FROM tbl_firma WHERE ext_id=".$row->adresse_pk.";";
if($result3 = pg_query($conn, $qry3))
{
if(pg_num_rows($result3)>0) //eintrag gefunden
{
if($row3=pg_fetch_object($result3))
{
$firma->new=false;
$firma->firma_id=$row3->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;
}
}
}
}
}
@@ -144,7 +171,7 @@ if($result = pg_query($conn_fas, $qry))
else
{
$error=true;
$error_log.="adresse mit adresse_pk: $row->adresse_pk konnte nicht gefunden werden! (".pg_num_rows($result1).")\n";
$error_log.="adresse mit adresse_pk: $row->adresse_pk ($row->person_fk) konnte in tbl_syncperson nicht gefunden werden! (".pg_num_rows($result1).")\n";
$anzahl_fehler++;
}
}
@@ -159,20 +186,15 @@ if($result = pg_query($conn_fas, $qry))
else
{
$anzahl_eingefuegt++;
echo "- ";
ob_flush();
flush();
}
}
}
flush();
}
}
?>
<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);
+143
View File
@@ -0,0 +1,143 @@
<?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 EMaildatensaetze von FAS DB in PORTAL DB
//*
//*
include('../../../vilesci/config.inc.php');
include('../../../include/kontakt.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)
{
}
?>
<html>
<head>
<title>Synchro - FAS -> Portal - EMail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
/*************************
* FAS-PORTAL - Synchronisation
*/
//nation
$qry = "SELECT * FROM email ORDER BY person_fk;";
if($result = pg_query($conn_fas, $qry))
{
echo nl2br("E-Mail Sync\n--------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
echo "- ";
ob_flush();
flush();
$error=false;
$kontakt =new kontakt($conn);
$kontakt->firma_id ='';
$kontakt->kontakttyp ='email';
$kontakt->anmerkung =$row->name;
$kontakt->kontakt =$row->email;
$kontakt->zustellung =$row->zustelladresse=='J'?true:false;
$kontakt->updatevon ="SYNC";
$kontakt->insertvon ="SYNC";
$kontakt->ext_id =$row->email_pk;
//Person_id feststellen
$qry1="SELECT person_portal FROM public.tbl_syncperson WHERE person_fas=".$row->person_fk.";";
if($result1 = pg_query($conn, $qry1))
{
if(pg_num_rows($result1)>0) //eintrag gefunden
{
if($row1=pg_fetch_object($result1))
{
$qry2="SELECT kontakt_id, ext_id FROM tbl_kontakt WHERE ext_id=".$row->email_pk." AND kontakttyp='email';";
if($result2 = pg_query($conn, $qry2))
{
if(pg_num_rows($result2)>0) //eintrag gefunden
{
if($row2=pg_fetch_object($result2))
{
// update , wenn datensatz bereits vorhanden
$kontakt->person_id=$row1->person_portal;
$kontakt->kontakt_id=$row2->kontakt_id;
$kontakt->new=false;
}
}
else
{
// insert, wenn datensatz noch nicht vorhanden
$kontakt->new=true;
$kontakt->person_id=$row1->person_portal;
}
}
}
}
else
{
$error=true;
$error_log.="person mit person_fk: $row->person_fk konnte in tbl_syncperson nicht gefunden werden! (".pg_num_rows($result1).")\n";
$anzahl_fehler++;
}
}
If (!$error)
{
if(!$kontakt->save())
{
$error_log.=$kontakt->errormsg."\n";
$anzahl_fehler++;
}
else
{
$anzahl_eingefuegt++;
}
}
}
}
//echo nl2br($text);
echo nl2br($error_log);
echo nl2br("\nGesamt: $anzahl_quelle / Eingefügt: $anzahl_eingefuegt / Fehler: $anzahl_fehler");
?>
</body>
</html>
+8 -3
View File
@@ -32,6 +32,8 @@ $conn=pg_connect(CONN_STRING) or die("Connection zur Portal Datenbank fehlgeschl
//$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");
//set_time_limit(60);
$adress='ruhan@technikum-wien.at';
//$adress='fas_sync@technikum-wien.at';
@@ -41,6 +43,7 @@ $anzahl_quelle=0;
$anzahl_eingefuegt=0;
$anzahl_fehler=0;
/*************************
* FAS-PORTAL - Synchronisation
*/
@@ -53,7 +56,6 @@ $anzahl_fehler=0;
<body>
<?php
//person
flush();
?>
<?php
$qry = "SELECT * FROM person";
@@ -186,8 +188,8 @@ if($result = pg_query($conn_fas, $qry))
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))
$qryz="SELECT person_fas FROM tbl_syncperson WHERE person_fas='$row->person_pk' AND person_portal='$person->person_id'";
if($resultz = pg_query($conn, $qryz))
{
if(pg_num_rows($resultz)==0) //wenn dieser eintrag noch nicht vorhanden ist
{
@@ -197,6 +199,9 @@ if($result = pg_query($conn_fas, $qry))
}
}
$anzahl_eingefuegt++;
echo "- ";
ob_flush();
flush();
}
}
else
+146
View File
@@ -0,0 +1,146 @@
<?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 Telefondatensaetze von FAS DB in PORTAL DB
//*
//*
include('../../../vilesci/config.inc.php');
include('../../../include/kontakt.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)
{
}
?>
<html>
<head>
<title>Synchro - FAS -> Portal - Telefon</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
/*************************
* FAS-PORTAL - Synchronisation
*/
//nation
$qry = "SELECT * FROM telefonnummer ORDER BY person_fk;";
if($result = pg_query($conn_fas, $qry))
{
echo nl2br("Telefon Sync\n-------------\n");
$anzahl_quelle=pg_num_rows($result);
while($row = pg_fetch_object($result))
{
echo "- ";
ob_flush();
flush();
$error=false;
$kontakt =new kontakt($conn);
$kontakt->firma_id ='';
$kontakt->kontakttyp ='telefon';
$kontakt->anmerkung =$row->name;
$kontakt->kontakt =$row->nummer;
$kontakt->zustellung =false;
$kontakt->updatevon ="SYNC";
$kontakt->insertvon ="SYNC";
$kontakt->ext_id =$row->telefonnummer_pk;
//Person_id feststellen
if($row->nummer!='')
{
$qry1="SELECT person_portal FROM public.tbl_syncperson WHERE person_fas=".$row->person_fk.";";
if($result1 = pg_query($conn, $qry1))
{
if(pg_num_rows($result1)>0) //eintrag gefunden
{
if($row1=pg_fetch_object($result1))
{
$qry2="SELECT kontakt_id, ext_id FROM tbl_kontakt WHERE ext_id=".$row->telefonnummer_pk." AND kontakttyp='telefon';";
if($result2 = pg_query($conn, $qry2))
{
if(pg_num_rows($result2)>0) //eintrag gefunden
{
if($row2=pg_fetch_object($result2))
{
// update , wenn datensatz bereits vorhanden
$kontakt->person_id=$row1->person_portal;
$kontakt->kontakt_id=$row2->kontakt_id;
$kontakt->new=false;
}
}
else
{
// insert, wenn datensatz noch nicht vorhanden
$kontakt->new=true;
$kontakt->person_id=$row1->person_portal;
}
}
}
}
else
{
$error=true;
$error_log.="person mit person_fk: $row->person_fk konnte in tbl_syncperson nicht gefunden werden! (".pg_num_rows($result1).")\n";
$anzahl_fehler++;
}
}
If (!$error)
{
if(!$kontakt->save())
{
$error_log.=$kontakt->errormsg."\n";
$anzahl_fehler++;
}
else
{
$anzahl_eingefuegt++;
}
}
}
}
}
//echo nl2br($text);
echo nl2br($error_log);
echo nl2br("\nGesamt: $anzahl_quelle / Eingefügt: $anzahl_eingefuegt / Fehler: $anzahl_fehler");
?>
</body>
</html>
+64 -31
View File
@@ -30,6 +30,7 @@ class adresse
var $new; // @var boolean
var $errormsg; // @var string
var $result = array(); // @var adresse Objekt
var $done=false; //@ boolean
//Tabellenspalten
var $adresse_id; // @var integer
@@ -316,7 +317,8 @@ class adresse
($this->zustelladresse?'true':'false').', '.
($this->firma_id!=null?$this->addslashes($this->firma_id):'null').', now(), '.
$this->addslashes($this->updatevon).', '.
$this->addslashes($this->ext_id).');';
$this->addslashes($this->ext_id).');';
$this->done=true;
}
else
{
@@ -325,49 +327,80 @@ class adresse
//Pruefen ob adresse_id eine gueltige Zahl ist
if(!is_numeric($this->adresse_id))
{
$this->errormsg = 'adresse_id muss eine gueltige Zahl sein';
$this->errormsg = 'adresse_id muss eine gueltige Zahl sein: '.$this->adresse_id;
return false;
}
$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.';';
$qryz="SELECT * FROM tbl_adresse WHERE adresse_id='$this->adresse_id';";
if($resultz = pg_query($this->conn, $qryz))
{
while($rowz = pg_fetch_object($resultz))
{
$update=false;
if($rowz->person_id!=$this->person_id) $update=true;
if($rowz->name!=$this->name) $update=true;
if($rowz->strasse!=$this->strasse) $update=true;
if($rowz->plz!=$this->plz) $update=true;
if($rowz->typ!=$this->typ) $update=true;
if($rowz->ort!=$this->ort) $update=true;
if($rowz->nation!=$this->nation) $update=true;
if($rowz->gemeinde!=$this->gemeinde) $update=true;
if($rowz->heimatadresse!=$this->heimatadresse?'true':'false') $update=true;
if($rowz->zustelladresse!=$this->zustelladresse?'true':'false') $update=true;
if($update)
{
$qry='UPDATE tbl_adresse SET'.
' person_id='.$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).', '.
' updateamum= now(), '.
' updatevon='.$this->addslashes($this->updatevon).', '.
' heimatadresse='.($this->heimatadresse?'true':'false').', '.
' zustelladresse='.($this->zustelladresse?'true':'false').' '.
'WHERE adresse_id='.$this->adresse_id.';';
$this->done=true;
}
}
}
}
//echo $qry;
if(pg_query($this->conn,$qry))
if ($this->done)
{
//Log schreiben
/*$sql = $qry;
$qry = "SELECT nextval('log_seq') as id;";
if(!$row = pg_fetch_object(pg_query($this->conn, $qry)))
if(pg_query($this->conn,$qry))
{
$this->errormsg = 'Fehler beim Auslesen der Log-Sequence';
return false;
//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;
}
$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';
$this->errormsg = 'Fehler beim Speichern der Daten';
return false;
} */
return true;
}
}
else
{
$this->errormsg = 'Fehler beim Speichern der Daten';
return false;
return true;
}
}
+1 -1
View File
@@ -158,7 +158,7 @@ class firma
'anmerkung='.$this->addslashes($this->anmerkung).', '.
'updateamum= now(), '.
'updatevon='.$this->addslashes($this->updatevon).' '.
'WHERE ext_id='.$this->addslashes($this->ext_id).';';
'WHERE firma_id='.$this->addslashes($this->firma_id).';';
}
//echo $qry;
if(pg_query($this->conn,$qry))
+237
View File
@@ -0,0 +1,237 @@
<?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 kontakt
* @create 20-12-2006
*/
class kontakt
{
var $conn; // @var resource DB-Handle
var $new; // @var boolean
var $errormsg; // @var string
var $result = array(); // @var adresse Objekt
var $done=false; // @var boolean
//Tabellenspalten
Var $kontakt_id; // @var integer
var $person_id; // @var integer
var $firma_id; // @var integer
var $kontakttyp; // @var string
var $anmerkung; // @var string
var $kontakt; // @var string
var $zustellung; // @var boolean
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
* $kontakt_id ID der Adresse die geladen werden soll (Default=null)
*/
function kontakt($conn,$kontakt_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 $kontakt_id
* @param $kontakt_id ID der zu ladenden Email
* @return true wenn ok, false im Fehlerfall
*/
function load($kontakt_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->kontakttyp)>32)
{
$this->errormsg = 'kontakttyp darf nicht länger als 32 Zeichen sein - firma_id: '.$row->email_id;
return false;
}
if(strlen($this->anmerkung)>64)
{
$this->errormsg = 'anmerkung darf nicht länger als 64 Zeichen sein - firma_id: '.$row->email_id;
return false;
}
if(strlen($this->kontakt)>128)
{
$this->errormsg = 'kontakt darf nicht länger als 128 Zeichen sein - firma_id: '.$row->email_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 $kontakt_id aktualisiert
* @return true wenn ok, false im Fehlerfall
*/
function save()
{
$this->done=false;
//Variablen pruefen
if(!$this->checkvars())
return false;
if($this->new)
{
//Neuen Datensatz einfuegen
$qry='INSERT INTO tbl_kontakt (person_id, firma_id, kontakttyp, anmerkung, kontakt, zustellung, ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('.
$this->addslashes($this->person_id).', '.
$this->addslashes($this->firma_id).', '.
$this->addslashes($this->kontakttyp).', '.
$this->addslashes($this->anmerkung).', '.
$this->addslashes($this->kontakt).', '.
($this->zustellung?'true':'false').', '.
$this->addslashes($this->ext_id).', now(), '.
$this->addslashes($this->insertvon).', now(), '.
$this->addslashes($this->updatevon).');';
$this->done=true;
}
else
{
//Updaten des bestehenden Datensatzes
//Pruefen ob kontakt_id eine gueltige Zahl ist
if(!is_numeric($this->kontakt_id))
{
$this->errormsg = 'kontakt_id muss eine gueltige Zahl sein: '.$this->kontakt_id.' ('.$this->person_id.')';
return false;
}
$qry="SELECT * FROM tbl_kontakt WHERE kontakt_id='$this->kontakt_id';";
if($resultz = pg_query($this->conn, $qry))
{
while($rowz = pg_fetch_object($resultz))
{
$update=false;
if($rowz->person_id!=$this->person_id) $update=true;
if($rowz->firma_id!=$this->firma_id) $update=true;
if($rowz->kontakttyp!=$this->kontakttyp) $update=true;
if($rowz->anmerkung!=$this->anmerkung) $update=true;
if($rowz->kontakt!=$this->kontakt) $update=true;
if($rowz->zustellung!=$this->zustellung) $update=true;
if($rowz->ext_id!=$this->ext_id) $update=true;
if($update)
{
$qry='UPDATE tbl_kontakt SET '.
'person_id='.$this->addslashes($this->person_id).', '.
'firma_id='.$this->addslashes($this->firma_id).', '.
'kontakttyp='.$this->addslashes($this->kontakttyp).', '.
'anmerkung='.$this->addslashes($this->anmerkung).', '.
'kontakt='.$this->addslashes($this->kontakt).', '.
'zustellung='.($this->zustellung?'true':'false').', '.
'ext_id='.$this->addslashes($this->ext_id).', '.
'updateamum= now(), '.
'updatevon='.$this->addslashes($this->updatevon).' '.
'WHERE kontakt_id='.$this->addslashes($this->kontakt_id).';';
$this->done=true;
}
}
}
}
//echo $qry;
if ($this->done)
{
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;
}
}
else
{
return true;
}
}
/**
* 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!
}
}
?>
+31 -22
View File
@@ -26,6 +26,7 @@ class person
var $errormsg; // string
var $new; // boolean
var $personen = array(); // person Objekt
var $done=false; // boolean
//Tabellenspalten
var $person_id; // integer
@@ -339,6 +340,7 @@ class person
$this->addslashes($this->geburtsnation).','.
$this->addslashes($this->staatsbuergerschaft).','.
$this->addslashes($this->ext_id).');';
$this->done=true;
}
else
{
@@ -350,8 +352,8 @@ class person
}
//update nur wenn änderungen gemacht
$qry="SELECT * FROM tbl_person";
if($result = pg_query($conn, $qry))
$qry="SELECT * FROM tbl_person WHERE person_id='$this->person_id';";
if($result = pg_query($this->conn, $qry))
{
while($row = pg_fetch_object($result))
{
@@ -376,7 +378,7 @@ class person
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->staatsbuergerschaft!=$this->staatsbuergerschaft) $update=true;
if($update)
@@ -406,34 +408,41 @@ class person
' geburtsnation='.$this->addslashes($this->geburtsnation).','.
' staatsbuergerschaft='.$this->addslashes($this->staatsbuergerschaft).','.
' ext_id='.$this->addslashes($this->ext_id).
" WHERE person_id='$this->person_id'";
' WHERE person_id='.$this->person_id.';';
$this->done=true;
}
}
}
}
if(pg_query($this->conn,$qry))
if ($this->done)
{
if($this->new)
if(pg_query($this->conn,$qry))
{
$qry = "SELECT currval('tbl_person_person_id_seq') AS id;";
if($row=pg_fetch_object(pg_query($this->conn,$qry)))
$this->person_id=$row->id;
else
{
$this->errormsg = 'Sequence konnte nicht ausgelesen werden';
return false;
if($this->new)
{
$qry = "SELECT currval('tbl_person_person_id_seq') AS id;";
if($row=pg_fetch_object(pg_query($this->conn,$qry)))
$this->person_id=$row->id;
else
{
$this->errormsg = 'Sequence konnte nicht ausgelesen werden';
return false;
}
}
//Log schreiben
return true;
}
//Log schreiben
else
{
$this->errormsg = 'Fehler beim Speichern des Person-Datensatzes:'.$this->nachname.' '.$qry;
return false;
}
}
else
{
return true;
}
else
{
$this->errormsg = 'Fehler beim Speichern des Person-Datensatzes:'.$this->nachname.' '.$qry;
return false;
}
}
}
}
?>