diff --git a/admin/sync/sync_vilesci_portal_ort.php b/admin/sync/sync_vilesci_portal_ort.php index 6d52faca4..f256872a1 100644 --- a/admin/sync/sync_vilesci_portal_ort.php +++ b/admin/sync/sync_vilesci_portal_ort.php @@ -53,7 +53,7 @@ $qry = "SELECT * FROM tbl_ort"; if($result = pg_query($conn_vilesci, $qry)) { - echo nl2br("Ort Sync\n--------\n"); + echo nl2br("Ort Sync\n---------\n"); $anzahl_quelle=pg_num_rows($result); while($row = pg_fetch_object($result)) { @@ -72,14 +72,14 @@ if($result = pg_query($conn_vilesci, $qry)) //ort->updateamum=''; //$ort->updatevon=$row->updatevon; - $qry = "SELECT ort_kurzbz FROM tbl_ort WHERE ort_kurzbz='$ort->ort_kurzbz'"; + $qry = "SELECT ort_kurzbz FROM tbl_ort WHERE ort_kurzbz='$row->ort_kurzbz'"; if($result1 = pg_query($conn, $qry)) { if(pg_num_rows($result1)>0) //wenn dieser eintrag schon vorhanden ist { if($row1=pg_fetch_object($result1)) { - //Funktionsdaten updaten + //Ortdaten updaten $ort->new=false; $ort->ort_kurzbz=$row->ort_kurzbz; } diff --git a/admin/sync/sync_vilesci_portal_ortraumtyp.php b/admin/sync/sync_vilesci_portal_ortraumtyp.php new file mode 100644 index 000000000..3d3d87d4f --- /dev/null +++ b/admin/sync/sync_vilesci_portal_ortraumtyp.php @@ -0,0 +1,125 @@ +, + * Andreas Oesterreicher and + * Rudolf Hangl . + */ + +//* +//* Synchronisiert Funktiondatensaetze von Vilesci DB in PORTAL DB +//* +//* + +include('../../vilesci/config.inc.php'); +include('../../include/fas/ortraumtyp.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"); + +$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) +{ +} + +/************************* + * VILESCI-PORTAL - Synchronisation + */ + +//funktion +$qry = "SELECT * FROM tbl_ortraumtyp"; + +if($result = pg_query($conn_vilesci, $qry)) +{ + echo nl2br("OrtRaumtyp Sync\n----------------\n"); + $anzahl_quelle=pg_num_rows($result); + while($row = pg_fetch_object($result)) + { + $error=false; + $ortraumtyp = new ortraumtyp($conn); + $ortraumtyp->ort_kurzbz=$row->ort_kurzbz; + $ortraumtyp->hierarchie=$row->hierarchie; + $ortraumtyp->raumtyp_kurzbz=$row->raumtyp_kurzbz; + //$ort->insertamum=''; + $ortraumtyp->insertvon='SYNC'; + //ort->updateamum=''; + //$ort->updatevon=$row->updatevon; + + $qry = "SELECT ort_kurzbz, hierarchie FROM tbl_ortraumtyp WHERE ort_kurzbz='$row->ort_kurzbz' AND hierarchie='$row->hierarchie'"; + if($result1 = pg_query($conn, $qry)) + { + if(pg_num_rows($result1)>0) //wenn dieser eintrag schon vorhanden ist + { + if($row1=pg_fetch_object($result1)) + { + //OrtRaumtypdaten updaten + $ortraumtyp->new=false; + } + else + { + $error_log.="ort_kurzbz von $row->ort_kurzbz konnte nicht ermittelt werden\n"; + $error=true; + } + } + else + { + //OrtRaumtyp neu anlegen + $ort->new=true; + } + + if(!$error) + if(!$ortraumtyp->save()) + { + $error_log.=$ort->errormsg."\n"; + $anzahl_fehler++; + } + else + $anzahl_eingefuegt++; + else + $anzahl_fehler++; + } + } + echo nl2br("abgeschlossen\n\n"); +} +else + $error_log .= 'Funktiondatensaetze konnten nicht geladen werden'; + +?> + + + +Synchro - Vilesci -> Portal - OrtRaumtyp + + + + + + \ No newline at end of file diff --git a/include/fas/funktion.class.php b/include/fas/funktion.class.php index ebfeaa2e9..baa03e371 100644 --- a/include/fas/funktion.class.php +++ b/include/fas/funktion.class.php @@ -198,7 +198,6 @@ class funktion } $qry = 'UPDATE tbl_funktion SET '. - 'funktion_kurzbz='.$this->addslashes($this->funktion_kurzbz).', '. 'bezeichnung='.$this->addslashes($this->bezeichnung).', '. 'aktiv='.($this->aktiv?'true':'false') .', '. 'insertamum='.$this->addslashes($this->insertamum).', '. diff --git a/include/fas/ort.class.php b/include/fas/ort.class.php index e687bc7b2..e158568ed 100644 --- a/include/fas/ort.class.php +++ b/include/fas/ort.class.php @@ -144,7 +144,7 @@ class ort /** * Loescht einen Datensatz - * @param $fachb_id id des Datensatzes der geloescht werden soll + * @param $ort_kurzbz ID des Datensatzes der geloescht werden soll * @return true wenn ok, false im Fehlerfall */ function delete($ort_kurzbz) @@ -163,18 +163,24 @@ class ort function checkvars() { $this->bezeichnung = str_replace("'",'´',$this->bezeichnung); + $this->ort_kurzbz = str_replace("'",'´',$this->ort_kurzbz); $this->planbezeichnung = str_replace("'",'´',$this->planbezeichnung); //Laenge Pruefen if(strlen($this->bezeichnung)>30) { - $this->errormsg = "Bezeichnung darf nicht laenger als 30 Zeichen sein bei $this->ext_id - $this->bezeichnung"; + $this->errormsg = "Bezeichnung darf nicht laenger als 30 Zeichen sein bei $this->ort_kurzbz - $this->bezeichnung"; return false; } - if(strlen($this->planbezeichnung)>5) + if(strlen($this->planbezeichnung)>30) { - $this->errormsg = "Planbezeichnung darf nicht laenger als 5 Zeichen sein bei $this->ext_id - $this->kurzbz"; + $this->errormsg = "Planbezeichnung darf nicht laenger als 30 Zeichen sein bei $this->ort_kurzbz - $this->planbezeichnung"; + return false; + } + if(strlen($this->ort_kurzbz)>8) + { + $this->errormsg = "Ort_kurzbz darf nicht laenger als 8 Zeichen sein bei $this->ort_kurzbz/b>"; return false; } $this->errormsg = ''; @@ -219,7 +225,7 @@ class ort else { //bestehenden Datensatz akualisieren - + //Pruefen ob ort_kurzbz gueltig ist if($this->ort_kurzbz == '') { @@ -228,7 +234,6 @@ class ort } $qry = 'UPDATE tbl_ort SET '. - 'ort_kurzbz='.$this->addslashes($this->ort_kurzbz).', '. 'bezeichnung='.$this->addslashes($this->bezeichnung).', '. 'planbezeichnung='.$this->addslashes($this->planbezeichnung).', '. 'max_person='.$this->addslashes($this->max_person).', '. diff --git a/include/fas/ortraumtyp.class.php b/include/fas/ortraumtyp.class.php new file mode 100644 index 000000000..8841fd283 --- /dev/null +++ b/include/fas/ortraumtyp.class.php @@ -0,0 +1,243 @@ +, + * Andreas Oesterreicher and + * Rudolf Hangl . + */ +/** + * Klasse ortraumtyp (FAS-Online) + * @create 14-03-2006 + */ + +class ortraumtyp +{ + var $conn; // @var resource DB-Handle + var $new; // @var boolean + var $errormsg; // @var string + var $result = array(); // @var fachbereich Objekt + + //Tabellenspalten + var $ort_kurzbz; // @var string + var $hierarchie; // @var smallint + var $raumtyp_kurzbz; // @var string + var $updateamum; // @var timestamp + var $updatevon=0; // @var string + var $insertamum; // @var timestamp + var $insertvon=0; // @var string + + + /** + * Konstruktor + * @param $conn Connection zur DB + * $ort_kurzbz und hierarchie ID des zu ladenden OrtRaumtyps + */ + function ortraumtyp($conn, $ort_kurzbz=null, $hierarchie=0) + { + $this->conn = $conn; + if($ort_kurzbz != null && $hierarchie!=null && is_numeric($hierarchie)) + $this->load($ort_kurzbz, $hierarchie); + } + + /** + * Laedt alle verfuegbaren OrtRaumtypen + * @return true wenn ok, false im Fehlerfall + */ + function getAll() + { + $qry = 'SELECT * FROM tbl_ortraumtyp order by ort_kurzbz, hierarchie;'; + + if(!$res = pg_query($this->conn, $qry)) + { + $this->errormsg = 'Fehler beim Laden der Datensaetze'; + return false; + } + + while($row = pg_fetch_object($res)) + { + $ortraumtyp_obj = new ort($this->conn); + + $ortraumtyp_obj->ort_kurzbz = $row->ort_kurzbz; + $ortraumtyp_obj->hierarchie = $row->hierarchie; + $ortraumtyp_obj->raumtyp_kurzbz = $row->raumtyp_kurzbz; + $ortraumtyp_obj->insertamum = $row->insertamum; + $ortraumtyp_obj->insertvon = $row->insertvon; + $ortraumtyp_obj->updateamum = $row->updateamum; + $ortraumtyp_obj->updatevon = $row->updatevon; + + $this->result[] = $ortraumtyp_obj; + } + return true; + } + + /** + * Laedt einen OrtRaumtyp + * @param $ortraumtyp, hierarchie ID des zu ladenden OrtRaumtyps + * @return true wenn ok, false im Fehlerfall + */ + function load($ort_kurzbz, $hierarchie) + { + if($ort_kurzbz == '' || !is_numeric($hierarche) || $hierarchie=='') + { + $this->errormsg = 'Kein gültiger Schlüssel vorhanden'; + return false; + } + + $qry = "SELECT * FROM tbl_ortraumtyp WHERE ort_kurzbz = '$ort_kurzbz' AND hierarchie = '$hierarchie';"; + + if(!$res = pg_query($this->conn, $qry)) + { + $this->errormsg = 'Fehler beim laden des Datensatzes'; + return false; + } + + if($row=pg_fetch_object($res)) + { + $this->ort_kurzbz = $row->ort_kurzbz; + $this->hierarchie = $row->hierarchie; + $this->raumtyp_kurzbz = $row->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 $ort_kurzbz, hierarchie ID des Datensatzes der geloescht werden soll + * @return true wenn ok, false im Fehlerfall + */ + function delete($ort_kurzbz) + { + $this->errormsg = 'Noch nicht implementiert'; + return false; + } + function addslashes($var) + { + return ($var!=''?"'".addslashes($var)."'":'null'); + } + /** + * Prueft die Gueltigkeit der Variablen + * @return true wenn ok, false im Fehlerfall + */ + function checkvars() + { + $this->ort_kurzbz = str_replace("'",'´',$this->ort_kurzbz); + $this->raumtyp_kurzbz = str_replace("'",'´',$this->raumtyp_kurzbz); + + + //Laenge Pruefen + if(strlen($this->ort_kurzbz)>8) + { + $this->errormsg = "Ort_kurzbz darf nicht laenger als 8 Zeichen sein bei $this->kurzbz, $hierarchie"; + return false; + } + if(strlen($this->raumtyp_kurzbz)>8) + { + $this->errormsg = "Raumtyp_kurzbz darf nicht laenger als 8 Zeichen sein bei $this->kurzbz, $hierarchie - $this->raumtyp_kurzbz"; + return false; + } + $this->errormsg = ''; + return true; + } + /** + * 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 id gültig ist + if($this->ort_kurzbz == '' || !is_numeric($this->hierarchie) || $this_hierarchie=='') + { + $this->errormsg = 'Keine gültige ID'; + return false; + } + //Neuen Datensatz anlegen + $qry = 'INSERT INTO tbl_ortraumtyp (ort_kurzbz, hierarchie, raumtyp_kurzbz, + insertamum, insertvon, updateamum, updatevon) VALUES ('. + $this->addslashes($this->ort_kurzbz).', '. + $this->addslashes($this->hierarchie).', '. + $this->addslashes($this->raumtyp_kurzbz).', '. + $this->addslashes($this->insertamum).', '. + $this->addslashes($this->insertvon).', '. + $this->addslashes($this->updateamum).', '. + $this->addslashes($this->updatevon).');'; + + } + else + { + //bestehenden Datensatz akualisieren + + //Pruefen ob id gueltig ist + if($this->ort_kurzbz == '' || !is_numeric($this->hierarchie) || $this->hierarchie=='') + { + $this->errormsg = 'Keine gültige ID'; + return false; + } + + $qry = 'UPDATE tbl_ortraumtyp SET '. + 'raumtyp_kurzbz='.$this->addslashes($this->raumtyp_kurzbz).', '. + 'insertamum='.$this->addslashes($this->insertamum).', '. + 'insertvon='.$this->addslashes($this->insertvon).', '. + 'updateamum='.$this->addslashes($this->updateamum).', '. + 'updatevon='.$this->addslashes($this->updatevon).' '. + 'WHERE ort_kurzbz = '.$this->addslashes($this->ort_kurzbz).' AND hierarchie = '.$this->addslashes($this->hierarchie).';'; + } + + 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; + } + } +} +?> \ No newline at end of file