2004-10-20 00:47:16 +02:00
|
|
|
|
<?php
|
2003-08-01 22:58:08 +02:00
|
|
|
|
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2008-01-02 16:23:47 +01:00
|
|
|
|
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
2002-05-03 22:53:19 +02:00
|
|
|
|
*
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-07-08 00:47:02 +02:00
|
|
|
|
/**
|
2008-01-02 16:23:47 +01:00
|
|
|
|
\file htdocs/webcal/webcal.class.php
|
2005-09-09 23:18:12 +02:00
|
|
|
|
\ingroup webcalendar
|
2004-10-30 03:45:57 +02:00
|
|
|
|
\brief Ensemble des fonctions permettant d'acceder a la database webcalendar.
|
|
|
|
|
|
\author Rodolphe Quiedeville.
|
2005-07-10 02:21:11 +02:00
|
|
|
|
\author Laurent Destailleur.
|
2008-04-08 00:11:22 +02:00
|
|
|
|
\version $Id$
|
2004-07-12 21:57:28 +02:00
|
|
|
|
*/
|
2004-06-19 12:09:05 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
|
2005-07-08 00:47:02 +02:00
|
|
|
|
/**
|
2004-10-30 03:45:57 +02:00
|
|
|
|
\class Webcal
|
|
|
|
|
|
\brief Classe permettant d'acceder a la database webcalendar
|
2004-07-15 20:43:48 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2002-05-03 22:53:19 +02:00
|
|
|
|
class Webcal {
|
2005-07-08 00:47:02 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
var $localdb;
|
2007-05-10 01:55:59 +02:00
|
|
|
|
var $error;
|
|
|
|
|
|
var $version; /* Version string from webcalendar. Not defined in 1.0 */
|
2005-07-10 02:21:11 +02:00
|
|
|
|
var $date;
|
2007-05-04 23:19:15 +02:00
|
|
|
|
var $duree = 0; /* Secondes */
|
2005-07-10 02:21:11 +02:00
|
|
|
|
var $texte;
|
|
|
|
|
|
var $desc;
|
2005-09-09 23:18:12 +02:00
|
|
|
|
|
2002-05-09 16:57:48 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
\brief Constructeur de la classe d'interface <EFBFBD> Webcalendar
|
|
|
|
|
|
*/
|
|
|
|
|
|
function Webcal()
|
2003-08-01 22:58:08 +02:00
|
|
|
|
{
|
2005-07-10 02:21:11 +02:00
|
|
|
|
global $conf;
|
2005-09-11 18:29:14 +02:00
|
|
|
|
global $dolibarr_main_db_type,$dolibarr_main_db_host,$dolibarr_main_db_user;
|
|
|
|
|
|
global $dolibarr_main_db_pass,$dolibarr_main_db_name;
|
|
|
|
|
|
|
|
|
|
|
|
// D<>fini parametres webcal (avec substitution eventuelle)
|
|
|
|
|
|
$webcaltype=eregi_replace('__dolibarr_main_db_type__',$dolibarr_main_db_type,$conf->webcal->db->type);
|
|
|
|
|
|
$webcalhost=eregi_replace('__dolibarr_main_db_host__',$dolibarr_main_db_host,$conf->webcal->db->host);
|
2008-03-10 23:38:43 +01:00
|
|
|
|
$webcalport=eregi_replace('__dolibarr_main_db_port__',$dolibarr_main_db_port,$conf->webcal->db->port);
|
2005-09-11 18:29:14 +02:00
|
|
|
|
$webcaluser=eregi_replace('__dolibarr_main_db_user__',$dolibarr_main_db_user,$conf->webcal->db->user);
|
|
|
|
|
|
$webcalpass=eregi_replace('__dolibarr_main_db_pass__',$dolibarr_main_db_pass,$conf->webcal->db->pass);
|
|
|
|
|
|
$webcalname=eregi_replace('__dolibarr_main_db_name__',$dolibarr_main_db_name,$conf->webcal->db->name);
|
|
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
// On initie la connexion <20> la base Webcalendar
|
2006-08-06 19:56:55 +02:00
|
|
|
|
require_once (DOL_DOCUMENT_ROOT ."/lib/databases/".$webcaltype.".lib.php");
|
2008-03-10 23:38:43 +01:00
|
|
|
|
$this->localdb = new DoliDb($webcaltype,$webcalhost,$webcaluser,$webcalpass,$webcalname,$webcalport);
|
2002-05-09 16:57:48 +02:00
|
|
|
|
}
|
2004-06-19 12:09:05 +02:00
|
|
|
|
|
2004-10-30 03:45:57 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
/**
|
2005-09-09 23:18:12 +02:00
|
|
|
|
\brief Ajoute objet en tant qu'entree dans le calendrier de l'utilisateur
|
|
|
|
|
|
\param[in] user Le login de l'utilisateur
|
2005-07-10 02:21:11 +02:00
|
|
|
|
\return int 1 en cas de succ<EFBFBD>s, -1,-2,-3 en cas d'erreur, -4 si login webcal non d<EFBFBD>fini
|
|
|
|
|
|
*/
|
2005-09-09 23:18:12 +02:00
|
|
|
|
function add($user)
|
2008-01-02 23:11:50 +01:00
|
|
|
|
{
|
2005-07-10 02:21:11 +02:00
|
|
|
|
global $langs;
|
|
|
|
|
|
|
2007-03-30 10:34:26 +02:00
|
|
|
|
dolibarr_syslog("Webcal::add user=".$user->id);
|
2005-09-09 23:18:12 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
// Test si login webcal d<>fini pour le user
|
2007-02-11 17:32:29 +01:00
|
|
|
|
if (! $user->webcal_login)
|
|
|
|
|
|
{
|
|
|
|
|
|
$langs->load("other");
|
|
|
|
|
|
$this->error=$langs->transnoentities("ErrorWebcalLoginNotDefined","<a href=\"".DOL_URL_ROOT."/user/fiche.php?id=".$user->id."\">".$user->login."</a>");
|
|
|
|
|
|
dolibarr_syslog("Webcal::add ERROR ".$this->error);
|
2005-09-09 23:18:12 +02:00
|
|
|
|
return -4;
|
2005-07-10 02:21:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->localdb->begin();
|
|
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
// Recup<75>re l'id max+1 dans la base webcalendar
|
|
|
|
|
|
$id = $this->get_next_id();
|
|
|
|
|
|
|
|
|
|
|
|
if ($id > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$cal_id = $id;
|
|
|
|
|
|
$cal_create_by = $user->webcal_login;
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$cal_date = strftime('%Y%m%d', $this->date);
|
|
|
|
|
|
$cal_time = strftime('%H%M%S', $this->date);
|
2005-07-10 02:21:11 +02:00
|
|
|
|
$cal_mod_date = strftime('%Y%m%d', time());
|
2005-07-10 04:05:09 +02:00
|
|
|
|
$cal_mod_time = strftime('%H%M%S', time());
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$cal_duration = round($this->duree / 60);
|
2007-05-10 01:55:59 +02:00
|
|
|
|
$cal_priority = 2; // Medium avec 1.0, Haute avec 1.1
|
|
|
|
|
|
// Rem: 1.0: 1=bas, 2=medium, 3=haut
|
|
|
|
|
|
// 1.1: 1=haut, 2=haut, 3=haut, 4=medium ... 9=bas
|
|
|
|
|
|
$cal_type = "E"; // Evenement de type "intemporel"
|
|
|
|
|
|
$cal_access = "P"; // Acces publique
|
|
|
|
|
|
$cal_name = $this->texte; // Title for event
|
|
|
|
|
|
$cal_description = $this->desc; // Desc for event
|
2005-09-09 23:18:12 +02:00
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO webcal_entry (cal_id, cal_create_by,cal_date,cal_time,cal_mod_date, cal_mod_time,cal_duration,cal_priority,cal_type, cal_access, cal_name,cal_description)";
|
|
|
|
|
|
$sql.= " VALUES ($cal_id, '$cal_create_by', '$cal_date', '$cal_time', '$cal_mod_date', '$cal_mod_time', $cal_duration, $cal_priority, '$cal_type', '$cal_access', '$cal_name','$cal_description')";
|
|
|
|
|
|
|
2007-02-11 17:32:29 +01:00
|
|
|
|
dolibarr_syslog("Webcal::add sql=".$sql);
|
|
|
|
|
|
$resql=$this->localdb->query($sql);
|
|
|
|
|
|
if ($resql)
|
2005-07-10 02:21:11 +02:00
|
|
|
|
{
|
2004-10-30 03:45:57 +02:00
|
|
|
|
$sql = "INSERT INTO webcal_entry_user (cal_id, cal_login, cal_status)";
|
|
|
|
|
|
$sql .= " VALUES ($cal_id, '$cal_create_by', 'A')";
|
|
|
|
|
|
|
2007-02-11 17:32:29 +01:00
|
|
|
|
$resql=$this->localdb->query($sql);
|
|
|
|
|
|
if ($resql)
|
2005-07-10 02:21:11 +02:00
|
|
|
|
{
|
|
|
|
|
|
// OK
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->localdb->commit();
|
2005-07-10 02:21:11 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->localdb->rollback();
|
2005-07-10 02:21:11 +02:00
|
|
|
|
$this->error = $this->localdb->error() . '<br>' .$sql;
|
2007-02-11 17:32:29 +01:00
|
|
|
|
dolibarr_syslog("Webcal::add ERROR ".$this->error);
|
2005-07-10 02:21:11 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-10-30 03:45:57 +02:00
|
|
|
|
else
|
2005-07-10 02:21:11 +02:00
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->localdb->rollback();
|
2005-07-10 02:21:11 +02:00
|
|
|
|
$this->error = $this->localdb->error() . '<br>' .$sql;
|
2007-02-11 17:32:29 +01:00
|
|
|
|
dolibarr_syslog("Webcal::add ERROR ".$this->error);
|
2005-07-10 02:21:11 +02:00
|
|
|
|
return -2;
|
|
|
|
|
|
}
|
2004-10-30 03:45:57 +02:00
|
|
|
|
}
|
2005-07-10 02:21:11 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->localdb->rollback();
|
2004-11-03 23:02:33 +01:00
|
|
|
|
$this->error = $this->localdb->error() . '<br>' .$sql;
|
2007-02-11 17:32:29 +01:00
|
|
|
|
dolibarr_syslog("Webcal::add ERROR ".$this->error);
|
2004-10-30 03:45:57 +02:00
|
|
|
|
return -3;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-10 00:22:12 +02:00
|
|
|
|
|
2005-07-10 02:21:11 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\brief Obtient l'id suivant dans le webcalendar
|
2005-09-09 23:18:12 +02:00
|
|
|
|
\return int Retourne l'id suivant dans webcalendar, <0 si ko
|
2005-07-10 02:21:11 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function get_next_id()
|
2003-08-01 22:58:08 +02:00
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$sql = "SELECT max(cal_id) as id FROM webcal_entry";
|
2004-10-30 03:45:57 +02:00
|
|
|
|
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$resql=$this->localdb->query($sql);
|
|
|
|
|
|
if ($resql)
|
2004-10-30 03:45:57 +02:00
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$obj=$this->localdb->fetch_object($resql);
|
|
|
|
|
|
return ($obj->id + 1);
|
2004-10-30 03:45:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-09-09 23:18:12 +02:00
|
|
|
|
$this->error=$this->localdb->error();
|
2004-10-30 03:45:57 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2002-05-03 22:53:19 +02:00
|
|
|
|
}
|
2008-01-02 23:11:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
\brief Export fichier cal depuis base webcalendar
|
|
|
|
|
|
\param format 'ical' or 'vcal'
|
2008-01-03 00:39:29 +01:00
|
|
|
|
\param type 'event' or 'journal'
|
2008-01-02 23:11:50 +01:00
|
|
|
|
\param cachedelay Do not rebuild file if date older than cachedelay seconds
|
|
|
|
|
|
\param filename Force filename
|
2008-01-20 20:24:05 +01:00
|
|
|
|
\param filters Array of filters
|
2008-01-02 23:11:50 +01:00
|
|
|
|
\return int <0 if error, nb of events in new file if ok
|
|
|
|
|
|
*/
|
2008-01-03 00:39:29 +01:00
|
|
|
|
function build_calfile($format,$type,$cachedelay,$filename,$filters)
|
2008-01-02 23:11:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
global $conf,$langs;
|
|
|
|
|
|
|
|
|
|
|
|
require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php");
|
|
|
|
|
|
|
2008-01-03 00:39:29 +01:00
|
|
|
|
dolibarr_syslog("webcal::build_calfile Build cal file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG);
|
2008-01-02 23:11:50 +01:00
|
|
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
|
|
if (empty($format)) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
// Clean parameters
|
|
|
|
|
|
if (! $filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
$extension='vcs';
|
|
|
|
|
|
if ($format == 'ical') $extension='ics';
|
|
|
|
|
|
$filename=$format.'.'.$extension;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
create_exdir($conf->webcal->dir_temp);
|
|
|
|
|
|
$outputfile=$conf->webcal->dir_temp.'/'.$filename;
|
|
|
|
|
|
$result=0;
|
|
|
|
|
|
|
|
|
|
|
|
$buildfile=true;
|
|
|
|
|
|
if ($cachedelay)
|
|
|
|
|
|
{
|
|
|
|
|
|
// \TODO Check cache
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($buildfile)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Build event array
|
|
|
|
|
|
$eventarray=array();
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT cal_id, cal_create_by, ";
|
|
|
|
|
|
$sql.= " cal_date, cal_time, cal_mod_date,";
|
|
|
|
|
|
$sql.= " cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, cal_name, cal_description";
|
|
|
|
|
|
$sql.= " FROM webcal_entry";
|
|
|
|
|
|
$sql.= " order by cal_date";
|
|
|
|
|
|
|
|
|
|
|
|
dolibarr_syslog("Webcal::build_vcal select events sql=".$sql);
|
|
|
|
|
|
$resql=$this->localdb->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
while ($obj=$this->localdb->fetch_object($resql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$qualified=true;
|
|
|
|
|
|
|
|
|
|
|
|
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
|
|
|
|
|
|
$event=array();
|
2008-01-03 03:22:29 +01:00
|
|
|
|
$event['uid']='dolibarrwebcal-'.$this->localdb->database_name.'-'.$obj->cal_id."@".$_SERVER["SERVER_NAME"];
|
2008-01-03 00:39:29 +01:00
|
|
|
|
$event['type']=$type;
|
2008-01-02 23:11:50 +01:00
|
|
|
|
$date=$obj->cal_date;
|
|
|
|
|
|
$time=$obj->cal_time;
|
|
|
|
|
|
if (eregi('^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$',$date,$reg))
|
|
|
|
|
|
{
|
|
|
|
|
|
$year=$reg[1];
|
|
|
|
|
|
$month=$reg[2];
|
|
|
|
|
|
$day=$reg[3];
|
|
|
|
|
|
if (! empty($filters['year']) && $year != $filters['year']) $qualified=false;
|
|
|
|
|
|
if (! empty($filters['month']) && $year != $filters['month']) $qualified=false;
|
|
|
|
|
|
if (! empty($filters['day']) && $year != $filters['day']) $qualified=false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (eregi('^([0-9]?[0-9])([0-9][0-9])([0-9][0-9])$',$time,$reg))
|
|
|
|
|
|
{
|
|
|
|
|
|
$hour=sprintf("%02d",$reg[1]);
|
|
|
|
|
|
$min=sprintf("%02d",$reg[2]);
|
|
|
|
|
|
$sec=sprintf("%02d",$reg[3]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$datestart=dolibarr_mktime($hour,$min,$sec,$month,$day,$year);
|
|
|
|
|
|
$event['startdate']=$datestart;
|
2008-01-03 00:39:29 +01:00
|
|
|
|
//$event['duration']=$obj->cal_duration; // Not required with type 'journal'
|
|
|
|
|
|
//$event['enddate']=''; // Not required with type 'journal'
|
2008-01-02 23:11:50 +01:00
|
|
|
|
$event['summary']=$obj->cal_name;
|
|
|
|
|
|
$event['desc']=$obj->cal_description;
|
|
|
|
|
|
$event['author']=$obj->cal_create_by;
|
2008-01-03 03:22:29 +01:00
|
|
|
|
$event['transparency']='TRANSPARENT'; // TRANSPARENT or OPAQUE
|
|
|
|
|
|
$url=$conf->global->PHPWEBCALENDAR_URL;
|
|
|
|
|
|
if (! eregi('\/$',$url)) $url.='/';
|
|
|
|
|
|
$url.='view_entry.php?id='.$obj->cal_id;
|
|
|
|
|
|
$event['url']=$url;
|
2008-01-02 23:11:50 +01:00
|
|
|
|
|
|
|
|
|
|
if ($qualified)
|
|
|
|
|
|
{
|
|
|
|
|
|
$eventarray[$datestart]=$event;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("webcal::build_calfile ".$this->localdb->lasterror());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Write file
|
2008-01-03 00:55:26 +01:00
|
|
|
|
$title='Webcalendar events ';
|
2008-01-03 01:29:15 +01:00
|
|
|
|
$desc='Webcalendar events for database '.$this->localdb->database_name.' - built by Dolibarr';
|
2008-01-03 00:55:26 +01:00
|
|
|
|
$result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
|
2008-01-02 23:11:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-05-09 16:57:48 +02:00
|
|
|
|
}
|
2002-05-03 22:53:19 +02:00
|
|
|
|
?>
|