Coodle Ressourcen hinzufuegen und entfernen

This commit is contained in:
Andreas Österreicher
2012-10-16 06:22:13 +00:00
parent 10087645aa
commit 09f42d504e
6 changed files with 381 additions and 13 deletions
+2 -3
View File
@@ -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;
}
?>
?>
+137
View File
@@ -0,0 +1,137 @@
<?php
/* Copyright (C) 2012 FH 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: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
*/
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');
}
?>
+108 -8
View File
@@ -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 '<html>
<link rel="stylesheet" href="../../../skin/fhcomplete.css" type="text/css">
<link rel="stylesheet" href="../../../skin/style.css.php" type="text/css">
<link rel="stylesheet" href="../../../skin/jquery.css" type="text/css"/>
<script type="text/javascript" src="../../../include/js/jquery.js"></script>
<script type="text/javascript" src="../../../include/js/jquery.tablehover.js"></script>
<script type="text/javascript" src="../../../include/js/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="../../../include/js/fullcalendar/fullcalendar.css" />
<link rel="stylesheet" type="text/css" href="../../../include/js/fullcalendar/fullcalendar.print.css" media="print" />
<script type="text/javascript" src="../../../include/js/jquery-ui.js"></script>
@@ -305,7 +305,8 @@ echo '
</div>
<div id="ressourcen">
<h4>'.$p->t('coodle/ressourcen').'</h4>
<div id="ressourcecontainer"></div>
<div id="ressourcecontainer">
</div>
<input id="input_ressource" type="text" size="10" />
<script>
@@ -352,14 +353,43 @@ echo '
*/
function addRessource(id, typ, bezeichnung)
{
// Ressource Speichern
$.ajax({
type:"POST",
url:"coodle_worker.php",
data:{
"work": "addressource",
"id": id,
"typ": typ,
"coodle_id": "'.$coodle_id.'"
},
success: function(data)
{
if(data!="true")
alert("ERROR:"+data)
else
{
// Speichern der Ressource OK
addRessourceToContent(id, typ, bezeichnung);
}
},
error: function() { alert("error"); }
});
}
// Zeigt eine Ressoure mit deren Events an
function addRessourceToContent(id, typ, bezeichnung)
{
// Anzeige der Ressource mit Loeschen Button
var code = \'<span class="ressourceItem"> \
<a href="#delete" onclick="removeRessource(this, \\\'\'+id+\'\\\',\\\'\'+typ+\'\\\'); return false;"> \
<img src="../../../skin/images/delete_round.png" height="13px" title="'.$p->t('coodle/ressourceEntfernen').'"/> \
</a> \
\'+bezeichnung+\' \
<br /></span>\';
$("#ressourcecontainer").append(code);
// Events der Ressource hinzufuegen
$("#calendar").fullCalendar("addEventSource",
{
url:"coodle_events.php?code="+encodeURIComponent(id+typ),
@@ -374,13 +404,40 @@ echo '
color:"gray"
//textColor:"black"
});
$("#ressourcecontainer").append(code);
}
function removeRessource(item, id, typ)
{
// Ressource entfernen
$.ajax({
type:"POST",
url:"coodle_worker.php",
data:{
"work": "removeressource",
"id": id,
"typ": typ,
"coodle_id": "'.$coodle_id.'"
},
success: function(data)
{
if(data!="true")
alert("ERROR:"+data)
else
{
// Entfernen der Ressource OK
removeRessourceFromContent(item, id, typ);
}
},
error: function() { alert("error"); }
});
}
/*
* Loescht eine Ressource
*/
function removeRessource(item, id, typ)
function removeRessourceFromContent(item, id, typ)
{
$("#calendar").fullCalendar("removeEventSource",
@@ -396,7 +453,50 @@ echo '
}
});
$(item).parent().remove();
}';
// Bereits zugeteilte Ressourcen laden
if(!$coodle->getRessourcen($coodle_id))
die('Fehler:'.$coodle->errormsg);
echo '
$(document).ready(function()
{';
foreach($coodle->result as $row)
{
echo "\n\t";
$typ='';
$id='';
$bezeichnung='';
if($row->uid!='')
{
$typ='Person';
$id=$row->uid;
$benutzer = new benutzer();
$benutzer->load($row->uid);
$bezeichnung = $benutzer->nachname.' '.$benutzer->vorname;
}
elseif($row->ort_kurzbz!='')
{
$typ='Ort';
$id=$row->ort_kurzbz;
$ort = new ort();
$ort->load($row->ort_kurzbz);
$bezeichnung = $ort->bezeichnung;
}
elseif($row->email!='')
{
$typ = 'Extern';
$id = $row->email;
$bezeichnung = $row->name;
}
echo 'addRessourceToContent("'.$db->convert_html_chars($id).'", "'.$db->convert_html_chars($typ).'", "'.$db->convert_html_chars($bezeichnung).'");';
}
echo '
});';
echo '
</script>
<p>
'.$p->t('coodle/ressourcenBeschreibung').'
+131
View File
@@ -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;
}
}
}
?>
+2 -1
View File
@@ -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
}
}
}
?>
?>
+1 -1
View File
@@ -870,7 +870,7 @@ class wochenplan extends basis_db
echo '</td>';
echo '</tr></table></form>';
echo ' <a href="/cis/private/lvplan/stpl_reserve_list.php">'.$p->t('lvplan/reservierungenLoeschen').' </a>';
echo ' <a href="stpl_reserve_list.php">'.$p->t('lvplan/reservierungenLoeschen').' </a>';
}
}