Erstversion der Free/Busy Url

This commit is contained in:
Andreas Österreicher
2012-02-01 16:12:13 +00:00
parent e92268053c
commit ec63a5e019
5 changed files with 1577 additions and 136 deletions
+77
View File
@@ -0,0 +1,77 @@
<?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>
*/
/**
* Dieses Script liefert die FreeBusy Informationen
*
* Aufruf: http://www.example.com/cis/public/freebusy.php/[uid]
* zB
* http://www.example.com/cis/public/freebusy.php/oesi
*/
require_once('../../config/cis.config.inc.php');
require_once('../../include/freebusy.class.php');
require_once('../../include/benutzer.class.php');
require_once('../../include/ical.class.php');
$uid = mb_substr($_SERVER['PATH_INFO'],1);
$bn = new benutzer();
if(!$bn->load($uid))
die('User invalid');
$freebusy = new freebusy();
$freebusy->getFreeBusy($uid);
header("Content-Type: text/calendar; charset=UTF-8");
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//FH TECHNIKUM WIEN//EN\n";
echo "METHOD:PUBLISH\n";
echo 'ORGANIZER;CN=',$bn->vorname,' ',$bn->nachname,':mailto:',$uid,'@',DOMAIN,"\n";
echo 'DTSTAMP:',date('Ymd', mktime(date('H'),date('i'),date('s'),date('m'),date('d')-5,date('Y'))),'T',date('Hms'),"Z\n";
echo 'DTSTART:',date('Ymd', mktime(0,0,0,date('m'),date('d')-5,date('Y'))),"T000000Z\n";
echo 'DTEND:',date('Ymd', mktime(0,0,0,date('m'),date('d')+30,date('Y'))),"T000000Z\n";
echo 'URL:',APP_ROOT,'cis/public/freebusy.php/',$uid,"\n";
$ical = new ical();
foreach($freebusy->result as $row)
{
$fp = fopen($row->url,'r');
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$doc = '';
while (!feof($fp))
{
$line = fgets($fp);
$doc.=$line;
}
fclose($fp);
$ical->importFreeBusy($doc, $row->freebusytyp_kurzbz);
}
}
echo $ical->getFreeBusy();
echo "\nEND:VCALENDAR";
?>
+167
View File
@@ -0,0 +1,167 @@
<?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> and
*/
/**
* Klasse FreeBusy
* @create 27-01-2012
*/
require_once(dirname(__FILE__).'/basis_db.class.php');
class freebusy extends basis_db
{
public $new;
public $result = array();
public $freebusy_id;
public $uid;
public $freebusytyp_kurzbz;
public $url;
public $aktiv;
public $bezeichnung;
public $insertamum;
public $insertvon;
public $updateamum;
public $updatevon;
public $beschreibung;
/**
* Konstruktor
* @param $freebusy_id ID der FreeBusy Eintrags der geladen werden soll (Default=null)
*/
public function __construct($freebusy_id=null)
{
parent::__construct();
if(!is_null($freebusy_id))
$this->load($freebusy_id);
}
/**
* Laedt einen FreeBusy Eintrag mit der ID $freebusy_id
* @param freebusy_id
* @return true wenn ok, false im Fehlerfall
*/
public function load($freebusy_id)
{
//Pruefen ob id eine gueltige Zahl ist
if(!is_numeric($freebusy_id) || $freebusy_id == '')
{
$this->errormsg = 'id muss eine Zahl sein';
return false;
}
//Daten aus der Datenbank lesen
$qry = "SELECT * FROM campus.tbl_freebusy WHERE freebusy_id='".addslashes($freebusy_id)."'";
if(!$this->db_query($qry))
{
$this->errormsg = 'Fehler bei einer Datenbankabfrage';
return false;
}
if($row = $this->db_fetch_object())
{
$this->freebusy_id = $row->freebusy_id;
$this->uid = $row->uid;
$this->freebusytyp_kurzbz = $row->freebusytyp_kurzbz;
$this->url = $row->url;
$this->aktiv = ($row->aktiv=='t'?true:false);
$this->bezeichnung = $row->bezeichnung;
$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;
}
/**
* Liefert die FreeBusy Eintraege eines Benutzers
*
* @param $uid
*/
public function getFreeBusy($uid)
{
$qry = "SELECT * FROM campus.tbl_freebusy WHERE uid='".addslashes($uid)."' ORDER BY freebusy_id";
if($result = $this->db_query($qry))
{
while($row = $this->db_fetch_object($result))
{
$obj = new freebusy();
$obj->freebusy_id = $row->freebusy_id;
$obj->uid = $row->uid;
$obj->freebusytyp_kurzbz = $row->freebusytyp_kurzbz;
$obj->url = $row->url;
$obj->aktiv = ($row->aktiv=='t'?true:false);
$obj->bezeichnung = $row->bezeichnung;
$obj->insertamum = $row->insertamum;
$obj->insertvon = $row->insertvon;
$obj->updateamum = $row->updateamum;
$obj->updatevon = $row->updatevon;
$this->result[] = $obj;
}
return true;
}
else
{
$this->errormsg = 'Fehler beim Laden der Daten';
return false;
}
}
/**
* Laedt die FreeBusyTypen
*
*/
public function getTyp()
{
$qry = "SELECT * FROM campus.tbl_freebusytyp ORDER BY bezeichnung";
if($result = $this->db_query($qry))
{
while($row = $this->db_fetch_object($result))
{
$obj = new freebusy();
$obj->freebusytyp_kurbz = $row->freebusytyp_kurzbz;
$obj->bezeichnung = $row->bezeichnung;
$obj->beschreibung = $row->beschreibung;
$this->result[] = $obj;
}
return false;
}
else
{
$this->errormsg = 'Fehler beim Laden der Daten';
return false;
}
}
}
?>
+99
View File
@@ -0,0 +1,99 @@
<?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> and
*/
/**
* Klasse ical
* @create 27-01-2012
*/
require_once(dirname(__FILE__).'/basis_db.class.php');
class ical extends basis_db
{
public $new;
public $result = array();
/**
* Konstruktor
*/
public function __construct()
{
parent::__construct();
}
/**
* Importiert ein FreeBusy File
*
* @param $ical
* @param $typ
*/
public function importFreeBusy($ical, $typ)
{
$rows = explode("\n",$ical);
$idx = count($result);
$status=0;
$dtstart='';
$dtend='';
foreach($rows as $row)
{
if(mb_strstr($row,'BEGIN:VFREEBUSY'))
{
$status=1;
if(!isset($this->result[$idx]))
$this->result[$idx]='';
$this->result[$idx].=$row."\n";
}
elseif(mb_strstr($row,'END:VFREEBUSY'))
{
$status=0;
$this->result[$idx].=$row."\n";
$idx++;
}
elseif($status==1)
{
if($typ=='Google')
{
if(mb_strstr($row,'DTSTART:'))
{
$dtstart = mb_substr($row,8,-1);
}
elseif(mb_strstr($row,'DTEND:'))
{
$dtend = mb_substr($row,6,-1);
$this->result[$idx].='FREEBUSY:'.$dtstart.'/'.$dtend."\n";
$dtstart='';
$dtend='';
}
}
elseif(mb_strstr($row,'FREEBUSY:'))
$this->result[$idx].=$row."\n";
}
}
}
/**
* Liefert die FreeBusy Eintraege
*/
public function getFreeBusy()
{
return implode($this->result);
}
}
?>
+1175 -135
View File
File diff suppressed because it is too large Load Diff
+59 -1
View File
@@ -3205,6 +3205,62 @@ if(!$result = @$db->db_query('SELECT 1 FROM campus.tbl_dms_kategorie_gruppe LIMI
else
echo 'Tabelle campus.tbl_dms_kategorie_gruppe hinzugefuegt!<br>';
}
// Tabelle fuer FreeBusy
if(!@$db->db_query("SELECT 1 FROM campus.tbl_freebusy LIMIT 1"))
{
$qry = "
CREATE TABLE campus.tbl_freebusy
(
freebusy_id integer NOT NULL,
uid varchar(32) NOT NULL,
freebusytyp_kurzbz varchar(32) NOT NULL,
url varchar(1024) NOT NULL,
aktiv boolean NOT NULL,
bezeichnung varchar(256),
insertamum timestamp,
insertvon varchar(32),
updateamum timestamp,
updatevon varchar(32)
);
CREATE TABLE campus.tbl_freebusytyp
(
freebusytyp_kurzbz varchar(32) NOT NULL,
bezeichnung varchar(256),
beschreibung text
);
CREATE SEQUENCE campus.seq_freebusy_freebusy_id
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE campus.tbl_freebusy ALTER COLUMN freebusy_id SET DEFAULT nextval('campus.seq_freebusy_freebusy_id');
ALTER TABLE campus.tbl_freebusy ADD CONSTRAINT pk_freebusy PRIMARY KEY (freebusy_id);
ALTER TABLE campus.tbl_freebusytyp ADD CONSTRAINT pk_freebusytyp PRIMARY KEY (freebusytyp_kurzbz);
ALTER TABLE campus.tbl_freebusy ADD CONSTRAINT fk_freebusytyp_freebusy FOREIGN KEY(freebusytyp_kurzbz) REFERENCES campus.tbl_freebusytyp(freebusytyp_kurzbz) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE campus.tbl_freebusy ADD CONSTRAINT fk_benutzer_freebusy FOREIGN KEY(uid) REFERENCES public.tbl_benutzer(uid) ON DELETE CASCADE ON UPDATE CASCADE;
GRANT SELECT, INSERT, UPDATE, DELETE ON campus.tbl_freebusy TO admin;
GRANT SELECT, INSERT, UPDATE, DELETE ON campus.tbl_freebusytyp TO admin;
GRANT SELECT, INSERT, UPDATE, DELETE ON campus.tbl_freebusy TO web;
GRANT SELECT, INSERT, UPDATE, DELETE ON campus.tbl_freebusytyp TO web;
GRANT SELECT, UPDATE ON campus.seq_freebusy_freebusy_id TO admin;
GRANT SELECT, UPDATE ON campus.seq_freebusy_freebusy_id TO web;
";
if(!$db->db_query($qry))
echo '<strong>campus.tbl_freebusy: '.$db->db_last_error().'</strong><br>';
else
echo 'Tabelle campus.tbl_freebusy, campus.tbl_freebusytyp hinzugefuegt!<br>';
}
echo '<br>';
$tabellen=array(
@@ -3243,8 +3299,10 @@ $tabellen=array(
"campus.tbl_dms_version" => array("dms_id","version","filename","mimetype","name","beschreibung","letzterzugriff","updateamum","updatevon","insertamum","insertvon"),
"campus.tbl_erreichbarkeit" => array("erreichbarkeit_kurzbz","beschreibung","farbe"),
"campus.tbl_feedback" => array("feedback_id","betreff","text","datum","uid","lehrveranstaltung_id","updateamum","updatevon","insertamum","insertvon"),
"campus.tbl_freebusy" => array("freebusy_id","uid","freebusytyp_kurzbz","url","aktiv","bezeichnung","insertamum","insertvon","updateamum","updatevon"),
"campus.tbl_freebusytyp" => array("freebusytyp_kurzbz","bezeichnung","beschreibung"),
"campus.tbl_infoscreen" => array("infoscreen_id","bezeichnung","beschreibung","ipadresse"),
"campus.tbl_infoscreen_content" => array("infoscreen_content_id","infoscreen_id","content_id","gueltigvon","gueltigbis","insertamum","insertvon","updateamum","updatevon"),
"campus.tbl_infoscreen_content" => array("infoscreen_content_id","infoscreen_id","content_id","gueltigvon","gueltigbis","insertamum","insertvon","updateamum","updatevon","refreshzeit"),
"campus.tbl_legesamtnote" => array("student_uid","lehreinheit_id","note","benotungsdatum","updateamum","updatevon","insertamum","insertvon"),
"campus.tbl_lvgesamtnote" => array("lehrveranstaltung_id","studiensemester_kurzbz","student_uid","note","mitarbeiter_uid","benotungsdatum","freigabedatum","freigabevon_uid","bemerkung","updateamum","updatevon","insertamum","insertvon"),
"campus.tbl_lvinfo" => array("lehrveranstaltung_id","sprache","titel","lehrziele","lehrinhalte","methodik","voraussetzungen","unterlagen","pruefungsordnung","anmerkung","kurzbeschreibung","genehmigt","aktiv","updateamum","updatevon","insertamum","insertvon"),