From d28ca1f33108e9d565dfee8056c8fc46d579379c Mon Sep 17 00:00:00 2001 From: Karl Burkhart Date: Wed, 21 Sep 2011 12:07:08 +0000 Subject: [PATCH] =?UTF-8?q?functionen=20und=20variablen=20f=C3=BCr=20zwisc?= =?UTF-8?q?hentabelle=20projekt=5Fressource=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ressource.class.php | 121 +++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/include/ressource.class.php b/include/ressource.class.php index 74648f21b..84fce627d 100644 --- a/include/ressource.class.php +++ b/include/ressource.class.php @@ -37,6 +37,12 @@ class ressource extends basis_db public $insertvon; //string public $updateamum; //timestamp public $updatevon; //string + + // zwischentabelle projekt_ressource + public $projekt_ressource_id; + public $projektphase_id; + public $projekt_kurzbz; + public $funktion_kurzbz; /** @@ -222,7 +228,78 @@ class ressource extends basis_db } } - + /** + * 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 $projekt_kurzbz aktualisiert + * @return true wenn ok, false im Fehlerfall + */ + public function saveProjektRessource($new=null) + { + if($new==null) + $new = $this->new; + + if($new) + { + //Neuen Datensatz einfuegen + $qry='BEGIN; INSERT INTO fue.tbl_projekt_ressource (projektphase_id, projekt_kurzbz, + ressource_id, funktion_kurzbz, beschreibung) VALUES ('. + $this->addslashes($this->projektphase_id).', '. + $this->addslashes($this->projekt_kurzbz).', '. + $this->addslashes($this->ressource_id).', '. + $this->addslashes($this->funktion_kurzbz).', '. + $this->addslashes($this->beschreibung).'); '; + } + else + { + //Updaten des bestehenden Datensatzes + $qry='UPDATE fue.tbl_projekt_ressource SET '. + 'projektphase_id='.$this->addslashes($this->projektphase_id).', '. + 'projekt_kurzbz='.$this->addslashes($this->projekt_kurzbz).', '. + 'ressource_id='.$this->addslashes($this->ressource_id).', '. + 'funktion_kurzbz='.$this->addslashes($this->funktion_kurzbz).', '. + 'beschreibung='.$this->addslashes($this->beschreibung).' '. + 'WHERE projekt_ressource_id='.$this->addslashes($this->projekt_ressource_id).';'; + } + + if($this->db_query($qry)) + { + if($new) + { + //Sequence auslesen + $qry = "SELECT currval('fue.seq_projekt_ressource_projekt_ressource_id') as id;"; + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->projekt_ressource_id = $row->id; + $this->db_query('COMMIT'); + return true; + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + $this->db_query('ROLLBACK;'); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + $this->db_query('ROLLBACK;'); + return false; + } + } + + return true; + } + else + { + $this->errormsg = $qry; + return false; + } + } + /** * Speichert den aktuellen Datensatz in die Datenbank * Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt @@ -300,5 +377,47 @@ class ressource extends basis_db return false; } } + + + /** + * Laedt die Ressource mit der ID $ressource_id + * @param $ressource_id ID der zu ladenden Ressource + * @return true wenn ok, false im Fehlerfall + */ + public function loadProjektRessource($projekt_ressource_id) + { + if(!is_numeric($projekt_ressource_id)) + { + $this->errormsg = 'Ressource_id muss eine gueltige Zahl sein'; + return false; + } + + $qry = "SELECT * FROM fue.tbl_projekt_ressource WHERE projekt_ressource_id='".addslashes($projekt_ressource_id)."'"; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->projekt_ressource_id = $row->projekt_ressource_id; + $this->projektphase_id = $row->projektphase_id; + $this->projekt_kurzbz = $row->projekt_kurzbz; + $this->ressource_id = $row->ressource_id; + $this->funktion_kurzbz = $row->funktion_kurzbz; + $this->beschreibung = $row->beschreibung; + + return true; + } + else + { + $this->errormsg = 'Datensatz wurde nicht gefunden'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } } ?> \ No newline at end of file