From 09f42d504e40edcc7d3b748ede878f9d07372d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Tue, 16 Oct 2012 06:22:13 +0000 Subject: [PATCH] Coodle Ressourcen hinzufuegen und entfernen --- cis/private/coodle/coodle_events.php | 5 +- cis/private/coodle/coodle_worker.php | 137 +++++++++++++++++++++++++++ cis/private/coodle/termin.php | 116 +++++++++++++++++++++-- include/coodle.class.php | 131 +++++++++++++++++++++++++ include/ical.class.php | 3 +- include/wochenplan.class.php | 2 +- 6 files changed, 381 insertions(+), 13 deletions(-) create mode 100644 cis/private/coodle/coodle_worker.php diff --git a/cis/private/coodle/coodle_events.php b/cis/private/coodle/coodle_events.php index bfccb2dfa..42b34505b 100755 --- a/cis/private/coodle/coodle_events.php +++ b/cis/private/coodle/coodle_events.php @@ -59,12 +59,11 @@ switch($typ) case 'Ort': // LVPlan/Reservierungen des Raumes holen - $stdplan = new wochenplan(); + $stdplan = new wochenplan('ort'); $stdplan->load_data('ort',null,$id); while($start<$end) { - $i++; if(!date("w",$start)) $start=jump_day($start,1); @@ -142,4 +141,4 @@ function fixDate($date) $sekunde = mb_substr($date,13,2); return $jahr.'-'.$monat.'-'.$tag.'T'.$stunde.':'.$minute.':'.$sekunde; } -?> \ No newline at end of file +?> diff --git a/cis/private/coodle/coodle_worker.php b/cis/private/coodle/coodle_worker.php new file mode 100644 index 000000000..59ac5b298 --- /dev/null +++ b/cis/private/coodle/coodle_worker.php @@ -0,0 +1,137 @@ + + */ +require_once('../../../config/cis.config.inc.php'); +require_once('../../../include/functions.inc.php'); +require_once('../../../include/ort.class.php'); +require_once('../../../include/benutzer.class.php'); +require_once('../../../include/coodle.class.php'); + +$user = get_uid(); + +if(!isset($_POST['work'])) + die('Parameter Work missing'); + +$work = $_POST['work']; + +switch($work) +{ + case 'addressource': + if(isset($_POST['coodle_id'])) + $coodle_id=$_POST['coodle_id']; + else + die('CoodleID Missing'); + + if(isset($_POST['id'])) + $id=$_POST['id']; + else + die('RessourceID Missing'); + if(isset($_POST['typ'])) + $typ=$_POST['typ']; + else + die('Typ Missing'); + + $coodle = new coodle(); + if(!$coodle->load($coodle_id)) + die('Fehler: '.$coodle->errormsg); + + if($coodle->ersteller_uid!=$user) + die('Diese Aktion ist nur durch den Ersteller der Umfrage möglich'); + + $uid=''; + $ort=''; + $email=''; + $name=''; + switch($typ) + { + case 'Ort': $ort = $id; break; + case 'Person': $uid = $id; break; + case 'Extern': $email = $id; $name=''; break; // TODO Name setzen + default: die('Ungueltiger Typ'); break; + } + + if($coodle->RessourceExists($coodle_id, $uid, $ort, $email)) + die('Ressource ist bereits zugeteilt'); + + $coodle->coodle_id = $coodle_id; + $coodle->uid = $uid; + $coodle->ort_kurzbz = $ort; + $coodle->email = $email; + $coodle->name = $name; + $coodle->zugangscode = ''; //TODO + $coodle->insertamum = date('Y-m-d H:i:s'); + $coodle->insertvon = $user; + $coodle->updateamum = date('Y-m-d H:i:s'); + $coodle->updatevon = $user; + + if($coodle->saveRessource(true)) + echo 'true'; + else + echo 'Fehler beim Speichern:'.$coodle->errormsg; + + break; + case 'removeressource': + if(isset($_POST['coodle_id'])) + $coodle_id=$_POST['coodle_id']; + else + die('CoodleID Missing'); + + if(isset($_POST['id'])) + $id=$_POST['id']; + else + die('RessourceID Missing'); + if(isset($_POST['typ'])) + $typ=$_POST['typ']; + else + die('Typ Missing'); + + $coodle = new coodle(); + if(!$coodle->load($coodle_id)) + die('Fehler: '.$coodle->errormsg); + + if($coodle->ersteller_uid!=$user) + die('Diese Aktion ist nur durch den Ersteller der Umfrage möglich'); + + $uid=''; + $ort=''; + $email=''; + $name=''; + switch($typ) + { + case 'Ort': $ort = $id; break; + case 'Person': $uid = $id; break; + case 'Extern': $email = $id; break; + default: die('Ungueltiger Typ'); break; + } + if($coodle_ressource_id = $coodle->RessourceExists($coodle_id, $uid, $ort, $email)) + { + if($coodle->deleteRessource($coodle_ressource_id)) + echo 'true'; + else + echo 'Fehler:'.$coodle->errormsg; + } + else + { + echo 'Ressource nicht gefunden'; + } + break; + default: + die('Invalid Work Parameter'); +} +?> diff --git a/cis/private/coodle/termin.php b/cis/private/coodle/termin.php index 9dc969c2f..6e157075d 100755 --- a/cis/private/coodle/termin.php +++ b/cis/private/coodle/termin.php @@ -22,6 +22,8 @@ require_once('../../../include/functions.inc.php'); require_once('../../../include/phrasen.class.php'); require_once('../../../include/coodle.class.php'); require_once('../../../include/datum.class.php'); +require_once('../../../include/benutzer.class.php'); +require_once('../../../include/ort.class.php'); $uid = get_uid(); $sprache = getSprache(); @@ -34,9 +36,7 @@ echo ' - - - + @@ -305,7 +305,8 @@ echo '

'.$p->t('coodle/ressourcen').'

-
+
+

'.$p->t('coodle/ressourcenBeschreibung').' diff --git a/include/coodle.class.php b/include/coodle.class.php index b6e91d91b..4dc6cc226 100755 --- a/include/coodle.class.php +++ b/include/coodle.class.php @@ -420,5 +420,136 @@ class coodle extends basis_db return true; } + + /** + * Prueft ob eine Ressource bereits zu einer Umfrage zugeteilt ist + * + * @param $coodle_id ID der CoodleUmfrage + * @param $uid UID des Benutzers + * @param $ort_kurzbz Ort + * @param $email EMail des externen Teilnehmers + * @return boolean true wenn vorhanden sonst false + */ + public function RessourceExists($coodle_id, $uid, $ort_kurzbz, $email) + { + $qry="SELECT coodle_ressource_id FROM campus.tbl_coodle_ressource WHERE coodle_id=".$this->db_add_param($coodle_id, FHC_INTEGER); + if($uid!='') + $qry.=' AND uid='.$this->db_add_param($uid); + if($ort_kurzbz!='') + $qry.=' AND ort_kurzbz='.$this->db_add_param($ort_kurzbz); + if($email!='') + $qry.=' AND email='.$this->db_add_param($email); + + if($result = $this->db_query($qry)) + { + if($this->db_num_rows($result)>0) + { + if($row = $this->db_fetch_object($result)) + return $row->coodle_ressource_id; + } + else + return false; + } + } + + /** + * Validiert die Ressourcedaten vor dem Speichern + */ + public function validateRessource() + { + return true; + } + + /** + * Speichert die aktuelle Ressource in die Datenbank + * Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt + * andernfalls wird der Datensatz mit der ID in $coodle_id aktualisiert + * @return true wenn ok, false im Fehlerfall + */ + public function saveRessource($new = null) + { + if(is_null($new)) + $new = $this->new; + + //Variablen pruefen + if(!$this->validateRessource()) + return false; + + if($new) + { + //Neuen Datensatz einfuegen + $qry='BEGIN;INSERT INTO campus.tbl_coodle_ressource(coodle_id, uid, ort_kurzbz, + email, name, zugangscode, insertamum, insertvon, updateamum, updatevon) VALUES('. + $this->db_add_param($this->coodle_id).', '. + $this->db_add_param($this->uid).', '. + $this->db_add_param($this->ort_kurzbz).', '. + $this->db_add_param($this->email).', '. + $this->db_add_param($this->name).', '. + $this->db_add_param($this->zugangscode).', '. + $this->db_add_param($this->insertamum).', '. + $this->db_add_param($this->insertvon).', '. + $this->db_add_param($this->updateamum).', '. + $this->db_add_param($this->updatevon).');'; + } + else + { + $this->errormsg = 'Update not Implemented'; + return false; + } + + if($this->db_query($qry)) + { + if($new) + { + //naechste ID aus der Sequence holen + $qry="SELECT currval('campus.seq_coodle_ressource_coodle_ressource_id') as id;"; + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->coodle_ressource_id = $row->id; + $this->db_query('COMMIT'); + } + else + { + $this->db_query('ROLLBACK'); + $this->errormsg = "Fehler beim Auslesen der Sequence"; + return false; + } + } + else + { + $this->db_query('ROLLBACK'); + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + return false; + } + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern des Datensatzes'; + return false; + } + } + + /** + * Entfernt eine Ressourcezuteilung von einer Umfrage + * @param $coodle_ressource_id ID der Ressourcezuteilung + * @return boolean true wenn ok, false im Fehlerfall + */ + public function deleteRessource($coodle_ressource_id) + { + $qry = "DELETE FROM campus.tbl_coodle_ressource_termin WHERE coodle_ressource_id=".$this->db_add_param($coodle_ressource_id, FHC_INTEGER)."; + DELETE FROM campus.tbl_coodle_ressource WHERE coodle_ressource_id=".$this->db_add_param($coodle_ressource_id).";"; + + if($this->db_query($qry)) + return true; + else + { + $this->errormsg = 'Fehler beim Löschen der Daten'; + return false; + } + } } ?> diff --git a/include/ical.class.php b/include/ical.class.php index ef27a921b..e55d04d1d 100755 --- a/include/ical.class.php +++ b/include/ical.class.php @@ -27,6 +27,7 @@ class ical extends basis_db { public $new; public $result = array(); + public $dtresult = array(); /** @@ -126,4 +127,4 @@ class ical extends basis_db } } } -?> \ No newline at end of file +?> diff --git a/include/wochenplan.class.php b/include/wochenplan.class.php index e02871c1e..1ea108009 100644 --- a/include/wochenplan.class.php +++ b/include/wochenplan.class.php @@ -870,7 +870,7 @@ class wochenplan extends basis_db echo ''; echo ''; - echo ' '.$p->t('lvplan/reservierungenLoeschen').' '; + echo ' '.$p->t('lvplan/reservierungenLoeschen').' '; } }