diff --git a/htdocs/admin/webcalendar.php b/htdocs/admin/webcalendar.php
index 71ec5d87d5e..e766599b2ac 100644
--- a/htdocs/admin/webcalendar.php
+++ b/htdocs/admin/webcalendar.php
@@ -304,10 +304,11 @@ print "
";
// Show message
$message='';
-$urlvcal=''.$dolibarr_main_url_root.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal'.'';
+$urlwithouturlroot=eregi_replace(DOL_URL_ROOT.'$','',$dolibarr_main_url_root);
+$urlvcal=''.$urlwithouturlroot.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal'.'';
$message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal);
$message.='
';
-$urlical=''.$dolibarr_main_url_root.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical'.'';
+$urlical=''.$urlwithouturlroot.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical&type=event'.'';
$message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical);
print info_admin($message);
diff --git a/htdocs/lib/xcal.lib.php b/htdocs/lib/xcal.lib.php
index 3b850a3dc4b..40d3bcb62e5 100644
--- a/htdocs/lib/xcal.lib.php
+++ b/htdocs/lib/xcal.lib.php
@@ -68,8 +68,10 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
if ($eventqualified)
{
- # slurp out the fields to make it more convenient
- $uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
+ // See http://fr.wikipedia.org/wiki/ICalendar for format
+ //$uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
+ $uid = $event['uid'];
+ $type = $event['type'];
$startdate = $event['startdate'];
$duration = $event['duration'];
$enddate = $event['enddate'];
@@ -93,32 +95,68 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
$encoding='';
if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:';
- # Output the vCard/iCal VEVENT object
- fwrite($calfileh,"BEGIN:VEVENT\n");
- fwrite($calfileh,"UID:".$uid."\n");
- if ($email <> "")
+ // Output the vCard/iCal VEVENT object
+ if ($type == 'event')
{
- fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
- fwrite($calfileh,"CONTACT:MAILTO:".$email."\n");
+ fwrite($calfileh,"BEGIN:VEVENT\n");
+ fwrite($calfileh,"UID:".$uid."\n");
+ if (! empty($email))
+ {
+ fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
+ fwrite($calfileh,"CONTACT:MAILTO:".$email."\n");
+ }
+ if (! empty($url))
+ {
+ fwrite($calfileh,"URL:".$url."\n");
+ };
+
+ fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
+ fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
+ //fwrite($calfileh,'STATUS:CONFIRMED'."\n"); // TENTATIVE, CONFIRMED, CANCELLED
+ fwrite($calfileh,"CATEGORIES:".$category."\n");
+ fwrite($calfileh,"LOCATION:".$location."\n");
+ fwrite($calfileh,"TRANSP:OPAQUE\n");
+ fwrite($calfileh,"CLASS:CONFIDENTIAL\n");
+ fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($now,'dayhourxcard')."\n");
+ $startdatef = dolibarr_print_date($startdate,'dayhourxcard');
+ fwrite($calfileh,"DTSTART:".$startdatef."\n");
+ if (empty($enddate)) $enddate=$startdate+$duration;
+ $enddatef = dolibarr_print_date($enddate,'dayhourxcard');
+ fwrite($calfileh,"DTEND:".$enddatef."\n");
+ fwrite($calfileh,"END:VEVENT\n");
}
- if ($url <> "") { fwrite($calfileh,"URL:".$url."\n"); };
- fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
- fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
- fwrite($calfileh,"CATEGORIES:".$category."\n");
- fwrite($calfileh,"LOCATION:".$location."\n");
- fwrite($calfileh,"TRANSP:OPAQUE\n");
- fwrite($calfileh,"CLASS:CONFIDENTIAL\n");
- fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($now,'dayhourxcard')."\n");
+ // Output the vCard/iCal VTODO object
+ // ...
- // Dates
- $startdatef = dolibarr_print_date($startdate,'dayhourxcard');
- fwrite($calfileh,"DTSTART:".$startdatef."\n");
+ // Output the vCard/iCal VJOURNAL object
+ if ($type == 'journal')
+ {
+ fwrite($calfileh,"BEGIN:VJOURNAL\n");
+ fwrite($calfileh,"UID:".$uid."\n");
+ if (! empty($email))
+ {
+ fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
+ fwrite($calfileh,"CONTACT:MAILTO:".$email."\n");
+ }
+ if (! empty($url))
+ {
+ fwrite($calfileh,"URL:".$url."\n");
+ };
+
+ fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
+ fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
+ fwrite($calfileh,'STATUS:CONFIRMED'."\n");
+ fwrite($calfileh,"CATEGORIES:".$category."\n");
+ fwrite($calfileh,"LOCATION:".$location."\n");
+ fwrite($calfileh,"TRANSP:OPAQUE\n");
+ fwrite($calfileh,"CLASS:CONFIDENTIAL\n");
+ fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($startdatef,'dayhourxcard')."\n");
- if (empty($enddate)) $enddate=$startdate+$duration;
- $enddatef = dolibarr_print_date($enddate,'dayhourxcard');
- fwrite($calfileh,"DTEND:".$enddatef."\n");
+ fwrite($calfileh,"END:VJOURNAL\n");
+ }
+
// Put other info in comment
/*
$comment=array();
@@ -131,7 +169,6 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n");
*/
- fwrite($calfileh,"END:VEVENT\n");
}
}
@@ -193,7 +230,7 @@ function CalEncode($line)
}
$out .= $newpara;
- return trim($out);
+ return utf8_encode(trim($out));
}
diff --git a/htdocs/webcal/webcal.class.php b/htdocs/webcal/webcal.class.php
index d62c5fa8557..e98efc516e8 100644
--- a/htdocs/webcal/webcal.class.php
+++ b/htdocs/webcal/webcal.class.php
@@ -178,18 +178,19 @@ class Webcal {
/**
\brief Export fichier cal depuis base webcalendar
\param format 'ical' or 'vcal'
+ \param type 'event' or 'journal'
\param cachedelay Do not rebuild file if date older than cachedelay seconds
\param filename Force filename
\param filter Array of filters
\return int <0 if error, nb of events in new file if ok
*/
- function build_calfile($format,$cachedelay,$filename,$filters)
+ function build_calfile($format,$type,$cachedelay,$filename,$filters)
{
global $conf,$langs;
require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php");
- dolibarr_syslog("webcal::build_calfile Build cal file format=".$format.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG);
+ dolibarr_syslog("webcal::build_calfile Build cal file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG);
// Check parameters
if (empty($format)) return -1;
@@ -233,7 +234,8 @@ class Webcal {
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
$event=array();
- $event['uid']=$obj->cal_id;
+ $event['uid']='dolibarrwebcal-'.$this->localdb->database_name.'-'.$obj->cal_id."-export@".$_SERVER["SERVER_NAME"];
+ $event['type']=$type;
$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))
@@ -253,8 +255,8 @@ class Webcal {
}
$datestart=dolibarr_mktime($hour,$min,$sec,$month,$day,$year);
$event['startdate']=$datestart;
- $event['duration']=$obj->cal_duration;
- $event['enddate']='';
+ //$event['duration']=$obj->cal_duration; // Not required with type 'journal'
+ //$event['enddate']=''; // Not required with type 'journal'
$event['summary']=$obj->cal_name;
$event['desc']=$obj->cal_description;
$event['author']=$obj->cal_create_by;
diff --git a/htdocs/webcal/webcalexport.php b/htdocs/webcal/webcalexport.php
index 5977736efe1..dc8423819c6 100644
--- a/htdocs/webcal/webcalexport.php
+++ b/htdocs/webcal/webcalexport.php
@@ -72,12 +72,14 @@ if (! $webcal->localdb->connected || ! $webcal->localdb->database_selected)
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
-// Define format, filename and filter
+// Define format, type, filename and filter
$format='vcal';
+$type='event';
$filename='';
if (! empty($_GET["format"])) $format=$_GET["format"];
if ($format == 'vcal') $filename='webcalendar.vcs';
if ($format == 'ical') $filename='webcalendar.ics';
+if (! empty($_GET["type"])) $type=$_GET["type"];
if (! $filename)
{
$langs->load("main");
@@ -91,7 +93,7 @@ $filters=array();
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
// Build file
-$result=$webcal->build_calfile($format,0,$filename,$filters);
+$result=$webcal->build_calfile($format,$type,0,$filename,$filters);
if ($result >= 0)
{
header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=webcal&file='.urlencode($filename));