Sync Lehrverbände, Studenten, Mitarbeiter

This commit is contained in:
Andreas Österreicher
2006-11-28 16:29:09 +00:00
parent 1de5b19cf4
commit 8df2ca579f
8 changed files with 699 additions and 225 deletions
+57 -23
View File
@@ -1,28 +1,38 @@
<?php
/**
* Benutzer (PORTAL)
* @create 27-11-2006
/* 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>.
*/
class benutzer extends person
{
//var $conn; // @var resource DB-Handle
//var $errormsg; // @var string
//var $new; // @var boolean
//var $benutzer = array(); // @var person Objekt
//Tabellenspalten
var $uid; // varchar(16)
var $bnaktiv; // boolean
var $bnaktiv; // boolean
var $alias; // varchar(256)
//var $person_id; // integer
/**
* Konstruktor - Uebergibt die Connection und laedt optional einen benutzer
* @param $conn Datenbank-Connection
* $benutzer_id Benutzer der geladen werden soll (default=null)
*/
function benutzer($conn, $unicode=false, $benutzer_id=null)
function benutzer($conn, $benutzer_id=null, $unicode=false)
{
$this->conn = $conn;
@@ -33,7 +43,7 @@ class benutzer extends person
if(!pg_query($conn,$qry))
{
$this->errormsg = "Encoding konnte nicht gesetzt werden";
$this->errormsg = 'Encoding konnte nicht gesetzt werden';
return false;
}
@@ -98,29 +108,53 @@ class benutzer extends person
if(!person::save())
return false;
/*if(!pg_query($this->conn,'BEGIN;'))
{
$this->errormsg = 'Benutzertransaktion konnte nicht gesetzt werden';
return false;
}*/
if($this->new) //Wenn new true ist dann ein INSERT absetzen ansonsten ein UPDATE
{
$qry = "INSERT INTO tbl_benutzer (uid, aktiv, alias, person_id) VALUES(".
"'".addslashes($this->uid)."',".($this->aktiv?'true':'false').",".
$this->addslashes($this->alias).",'".$this->person_id."');";
$qry = 'INSERT INTO tbl_benutzer (uid, aktiv, alias, person_id, insertamum, insertvon, updateamum, updatevon) VALUES('.
"'".addslashes($this->uid)."',".
($this->aktiv?'true':'false').','.
$this->addslashes($this->alias).",'".
$this->person_id."',".
$this->addslashes($this->insertamum).",".
$this->addslashes($this->insertvon).",".
$this->addslashes($this->updateamum).",".
$this->addslashes($this->updatevon).",".
");";
}
else
{
$qry = "UPDATE tbl_benutzer SET".
" aktiv=".($this->aktiv?'true':'false').",".
" alias=".$this->addslashes($this->alias).",".
" person_id='".$this->person_id."'".
$qry = 'UPDATE tbl_benutzer SET'.
' aktiv='.($this->aktiv?'true':'false').','.
' alias='.$this->addslashes($this->alias).','.
" person_id='".$this->person_id."',".
' updateamum='.$this->addslashes($this->updateamum).','.
' updatevon='.$this->addslashes($this->updatevon).
" WHERE uid='".addslashes($this->uid)."';";
}
if(pg_query($this->conn,$qry))
{
//Log schreiben
return true;
/*if(!pg_query($this->conn,'COMMIT;'))
{
$this->errormsg = 'Bentuzer commit fehlgeschlagen';
return false;
}
else
{*/
//Log schreiben
return true;
/*}*/
}
else
{
$this->errormsg = "Fehler beim Speichern des Person-Datensatzes:".$qry;
{
//pg_query($this->conn,'ROLLBACK;');
$this->errormsg = 'Fehler beim Speichern des Benutzer-Datensatzes:'.$qry;
return false;
}
}
+34 -26
View File
@@ -8,18 +8,17 @@ class mitarbeiter extends benutzer
{
//Tabellenspalten
//var $uid;
var $ausbildungcode;
var $personalnummer;
var $kurzbz;
var $lektor;
var $fixangestellt;
var $telefonklappe;
var $ausbildungcode; //integer
var $personalnummer; //serial
var $kurzbz; //varchar(8)
var $lektor; //boolean
var $fixangestellt; //boolean
var $telefonklappe; //varchar(25)
/**
* Konstruktor
*/
function mitarbeiter($conn, $unicode=false, $person_id=null)
function mitarbeiter($conn, $person_id=null, $unicode=false)
{
$this->conn = $conn;
@@ -30,7 +29,7 @@ class mitarbeiter extends benutzer
if(!pg_query($conn,$qry))
{
$this->errormsg = "Encoding konnte nicht gesetzt werden";
$this->errormsg = 'Encoding konnte nicht gesetzt werden';
return false;
}
@@ -60,6 +59,11 @@ class mitarbeiter extends benutzer
$this->errormsg = 'Ausbildungscode ist ungueltig';
return false;
}
if(!is_numeric($this->personalnummer))
{
$this->errormsg = 'Personalnummer muss eine gueltige Zahl sein';
return false;
}
if(strlen($this->kurzbz)>8)
{
$this->errormsg = 'kurzbz darf nicht laenger als 8 Zeichen sein';
@@ -100,11 +104,11 @@ class mitarbeiter extends benutzer
if(!$this->validate())
return false;
pg_query($this->conn,"Begin;");
pg_query($this->conn,'BEGIN;');
//Basisdaten speichern
if(!benutzer::save())
{
pg_query($this->conn,"Rollback;");
pg_query($this->conn,'ROLLBACK;');
return false;
}
@@ -114,35 +118,39 @@ class mitarbeiter extends benutzer
$qry = "INSERT INTO tbl_mitarbeiter(uid, ausbildungcode, personalnummer, kurzbz, lektor,
fixangestellt, telefonklappe, updateamum, updatevon)
VALUES('".addslashes($this->uid)."',".
$this->addslashes($this->ausbildungcode).",'".$this->personalnummer."',".
$this->addslashes($this->kurzbz).",".($this->lektor?'true':'false').",".
($this->fixangestellt?'true':'false').",".$this->addslashes($this->telefonklappe).
",now(),'".$this->updatevon."');";
$this->addslashes($this->ausbildungcode).",'".
$this->personalnummer."',". //TODO: in Produktivversion nicht angeben
$this->addslashes($this->kurzbz).','.
($this->lektor?'true':'false').','.
($this->fixangestellt?'true':'false').','.
$this->addslashes($this->telefonklappe).','.
$this->addslashes($this->updateamum).','.
$this->updatevon."');";
}
else
{
//Bestehenden Datensatz updaten
$qry = "UPDATE tbl_mitarbeiter SET".
" ausbildungcode=".$this->addslashes($this->ausbildungcode).",".
//" personalnummer='$this->personalnummer',".
" kurzbz=".$this->addslashes($this->kurzbz).",".
" lektor=".($this->lektor?'true':'false').",".
" fixangestellt=".($this->fixangestellt?'true':'false').",".
" telefonklappe=".$this->addslashes($this->telefonklappe).",".
" updateamum=now(),".
" updatevon=".$this->addslashes($this->updatevon).
$qry = 'UPDATE tbl_mitarbeiter SET'.
' ausbildungcode='.$this->addslashes($this->ausbildungcode).','.
" personalnummer='$this->personalnummer',". //TODO: in Produktivversion nicht angeben
' kurzbz='.$this->addslashes($this->kurzbz).','.
' lektor='.($this->lektor?'true':'false').','.
' fixangestellt='.($this->fixangestellt?'true':'false').','.
' telefonklappe='.$this->addslashes($this->telefonklappe).','.
' updateamum='.$this->addslashes($this->updateamum).','.
' updatevon='.$this->addslashes($this->updatevon).
" WHERE uid='".addslashes($this->uid)."';";
}
if(pg_query($this->conn,$qry))
{
pg_query($this->conn,"Commit;");
pg_query($this->conn,'COMMIT;');
//Log schreiben
return true;
}
else
{
pg_query($this->conn,"Rollback;");
pg_query($this->conn,'ROLLBACK;');
$this->errormsg = 'Fehler beim Speichern des Mitarbeiter-Datensatzes'.$qry;
return false;
}
+103 -61
View File
@@ -1,15 +1,31 @@
<?php
/**
* Basisklasse Person (PORTAL)
* @create 27-11-2006
/* 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>.
*/
class person
{
var $conn; // @var resource DB-Handle
var $errormsg; // @var string
var $new; // @var boolean
var $personen = array(); // @var person Objekt
var $conn; // resource DB-Handle
var $errormsg; // string
var $new; // boolean
var $personen = array(); // person Objekt
//Tabellenspalten
var $person_id; // integer
@@ -42,7 +58,7 @@ class person
* @param $conn Datenbank-Connection
* $person_id Person die geladen werden soll (default=null)
*/
function person($conn, $unicode=false, $person_id=null)
function person($conn, $person_id=null, $unicode=false)
{
$this->conn = $conn;
@@ -53,7 +69,7 @@ class person
if(!pg_query($conn,$qry))
{
$this->errormsg = "Encoding konnte nicht gesetzt werden";
$this->errormsg = 'Encoding konnte nicht gesetzt werden';
return false;
}
@@ -118,7 +134,7 @@ class person
}
else
{
$this->errormsg = "Die person_id muss eine gueltige Zahl sein";
$this->errormsg = 'Die person_id muss eine gueltige Zahl sein';
return false;
}
}
@@ -127,30 +143,31 @@ class person
{
if(strlen($this->sprache)>16)
{
$this->errormsg = "Sprache darf nicht laenger als 16 Zeichen sein";
$this->errormsg = 'Sprache darf nicht laenger als 16 Zeichen sein';
return false;
}
if(strlen($this->anrede)>16)
{
$this->errormsg = "Anrede darf nicht laenger als 16 Zeichen sein";
$this->errormsg = 'Anrede darf nicht laenger als 16 Zeichen sein';
return false;
}
if(strlen($this->titelpost)>32)
{
$this->errormsg = "Titelpost darf nicht laenger als 32 Zeichen sein";
$this->errormsg = 'Titelpost darf nicht laenger als 32 Zeichen sein';
return false;
}
if(strlen($this->titelpre)>64)
{
$this->errormsg = "Titelpre darf nicht laenger als 64 Zeichen sein";
$this->errormsg = 'Titelpre darf nicht laenger als 64 Zeichen sein';
return false;
}
if(strlen($this->nachname)>64)
{
$this->errormsg = "Nachname darf nicht laenger als 64 Zeichen sein";
$this->errormsg = 'Nachname darf nicht laenger als 64 Zeichen sein';
return false;
}
//...
return true;
}
@@ -170,78 +187,103 @@ class person
//Variablen auf Gueltigkeit pruefen
if(!$this->validate())
return false;
/*
if(!pg_query($this->conn,'BEGIN;'))
{
$this->errormsg = 'Transaktion konnte nicht gesetzt werden';
return false;
}
*/
if($this->new) //Wenn new true ist dann ein INSERT absetzen ansonsten ein UPDATE
{
$qry = "INSERT INTO tbl_person (sprache, anrede, titelpost, titelpre, nachname, vorname, vornamen,
$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)
VALUES('".addslashes($this->sprache)."','".addslashes($this->anrede)."','".addslashes($this->titelpost)."','".
addslashes($this->titelpre)."','".addslashes($this->nachname)."','".addslashes($this->vorname)."','".
addslashes($this->vornamen)."','".addslashes($this->gebdatum)."','".addslashes($this->gebort)."',".
($this->gebzeit!=''?"'".addslashes($this->gebzeit)."'":'null').",".
($this->foto!=''?"'".addslashes($this->foto)."'":'null').",'".addslashes($this->anmerkungen)."','".
addslashes($this->homepage)."',".
($this->svnr!=''?"'".addslashes($this->svnr)."'":'null').",".
($this->ersatzkennzeichen!=''?"'".addslashes($this->ersatzkennzeichen)."'":'null').",'".
addslashes($this->familienstand)."',".
($this->anzahlkinder!=''?"'".addslashes($this->anzahlkinder)."'":'null').",".
($this->aktiv?'true':'false').",".
"'now()','".addslashes($this->insertvon)."','now()', '".addslashes($this->updatevon)."',".
($this->ext_id!=''?"'".addslashes($this->ext_id)."'":'null').");";
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).');';
}
else
{
//person_id auf gueltigkeit pruefen
if(!is_numeric($this->person_id))
{
{
$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='now()', updatevon=".$this->addslashes($this->updatevon).",".
" ext_id=".$this->addslashes($this->ext_id).
" WHERE person_id='$this->person_id'";
$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'";
}
if(pg_query($this->conn,$qry))
{
if($this->new)
{
$qry = "Select currval('tbl_person_person_id_seq') as id;";
$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
{
/*if(!pg_query($this->conn,'COMMIT;'))
{
$this->errormsg = 'Personentransaktion konnte nicht commitet werden';
return false;
}*/
}
else
{
$this->errormsg = 'Sequence konnte nicht ausgelesen werden';
pg_query($this->conn,'ROLLBACK');
//pg_query($this->conn,'ROLLBACK;');
return false;
}
}
//Log schreiben
return true;
}
else
{
else
{
$this->errormsg = 'Fehler beim Speichern des Person-Datensatzes:'.$qry;
return false;
}
+175
View File
@@ -0,0 +1,175 @@
<?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>.
*/
class student extends benutzer
{
//Tabellenspalten
var $matrikelnr;
var $prestudent_id;
var $studiengang_kz;
var $semester;
var $verband;
var $gruppe;
/**
* Konstruktor
*/
function student($conn, $student_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;
}
//Student laden
if($student_id!=null)
$this->load($student_id);
}
/**
* ueberprueft die Variablen auf Gueltigkeit
* @return true wenn gueltig, false im Fehlerfall
*/
function validate()
{
if(strlen($this->uid)>16)
{
$this->errormsg = 'UID darf nicht laenger als 16 Zeichen sein';
return false;
}
if($this->uid=='')
{
$this->errormsg = 'UID muss eingegeben werden';
return false;
}
if(strlen($this->matrikelnr)>15)
{
$this->errormsg = 'Matrikelnummer darf nicht laenger als 15 Zeichen sein';
return false;
}
if(strlen($this->updatevon)>32)
{
$this->errormsg = 'Updatevon darf nicht laenger als 32 Zeichen sein';
return false;
}
if($this->prestudent_id!='' && !is_numeric($this->prestudent_id))
{
$this->errormsg = 'Prestudent_id muss eine gueltige Zahl sein';
return false;
}
if(!is_numeric($this->studiengang_kz))
{
$this->errormsg = 'Studiengang_id muss eine gueltige Zahl sein';
return false;
}
if(!is_numeric($this->semester))
{
$this->errormsg = 'Semester muss ein gueltige Zahl sein';
return false;
}
if(strlen($this->verband)>1)
{
$this->errormsg = 'Verband darf nicht laenger als 1 Zeichen sein';
return false;
}
if(strlen($this->gruppe)>1)
{
$this->errormsg = 'Gruppe darf nicht laenger als 1 Zeichen sein';
return false;
}
return true;
}
/**
* Speichert die Studentendaten in die Datenbank
* @return true wenn ok, false im Fehlerfall
*/
function save()
{
//Variablen checken
if(!$this->validate())
return false;
pg_query($this->conn,'BEGIN;');
//Basisdaten speichern
if(!benutzer::save())
{
pg_query($this->conn,'ROLLBACK;');
return false;
}
if($this->new)
{
//Neuen Datensatz anlegen
$qry = "INSERT INTO tbl_student(uid, matrikelnr, updateamum, updatevon, prestudent_id,
studiengang_kz, semester, verband, gruppe)
VALUES('".addslashes($this->uid)."',".
$this->addslashes($this->matrikelnr).",".
$this->addslashes($this->updateamum).','.
$this->addslashes($this->updatevon).','.
$this->addslashes($this->prestudent_id).','.
$this->studiengang_kz.','.
$this->semester.','.
($this->verband!=''?"'".addslashes($this->verband)."'":' ').','.
($this->gruppe!=''?"'".addslashes($this->gruppe)."'":' ').');';
}
else
{
//Bestehenden Datensatz updaten
$qry = 'UPDATE tbl_student SET'.
' matrikelnr='.$this->addslashes($this->matrikelnr).','.
' updateamum='.$this->addslashes($this->updateamum).','.
' updatevon='.$this->addslashes($this->updatevon).','.
' prestudent_id='.$this->addslashes($this->prestudent_id).','.
' studiengang_kz='.$this->studiengang_kz.','.
' semester='.$this->semester.','.
' verband='.$this->addslashes($this->verband).','.
' gruppe='.$this->addslashes($this->gruppe).
" WHERE uid='".addslashes($this->uid)."';";
}
if(pg_query($this->conn,$qry))
{
pg_query($this->conn,'COMMIT;');
//Log schreiben
return true;
}
else
{
pg_query($this->conn,'ROLLBACK;');
$this->errormsg = 'Fehler beim Speichern des Studenten-Datensatzes'.$qry;
return false;
}
}
}
?>