New: Ajout d'un lien export de l'agenda webcalendar au format ical et vcal
This commit is contained in:
parent
d54e0283a6
commit
3f8bc51ce3
@ -304,10 +304,11 @@ print "<br>";
|
|||||||
|
|
||||||
// Show message
|
// Show message
|
||||||
$message='';
|
$message='';
|
||||||
$urlvcal='<a href="'.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal" target="_blank">'.$dolibarr_main_url_root.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal'.'</a>';
|
$urlwithouturlroot=eregi_replace(DOL_URL_ROOT.'$','',$dolibarr_main_url_root);
|
||||||
|
$urlvcal='<a href="'.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/webcal/webcalexport.php?format=vcal'.'</a>';
|
||||||
$message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal);
|
$message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal);
|
||||||
$message.='<br>';
|
$message.='<br>';
|
||||||
$urlical='<a href="'.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical" target="_blank">'.$dolibarr_main_url_root.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical'.'</a>';
|
$urlical='<a href="'.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical&type=event" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/webcal/webcalexport.php?format=ical&type=event'.'</a>';
|
||||||
$message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical);
|
$message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical);
|
||||||
print info_admin($message);
|
print info_admin($message);
|
||||||
|
|
||||||
|
|||||||
@ -68,8 +68,10 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
|
|||||||
|
|
||||||
if ($eventqualified)
|
if ($eventqualified)
|
||||||
{
|
{
|
||||||
# slurp out the fields to make it more convenient
|
// See http://fr.wikipedia.org/wiki/ICalendar for format
|
||||||
$uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
|
//$uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
|
||||||
|
$uid = $event['uid'];
|
||||||
|
$type = $event['type'];
|
||||||
$startdate = $event['startdate'];
|
$startdate = $event['startdate'];
|
||||||
$duration = $event['duration'];
|
$duration = $event['duration'];
|
||||||
$enddate = $event['enddate'];
|
$enddate = $event['enddate'];
|
||||||
@ -93,32 +95,68 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
|
|||||||
$encoding='';
|
$encoding='';
|
||||||
if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:';
|
if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:';
|
||||||
|
|
||||||
# Output the vCard/iCal VEVENT object
|
// Output the vCard/iCal VEVENT object
|
||||||
fwrite($calfileh,"BEGIN:VEVENT\n");
|
if ($type == 'event')
|
||||||
fwrite($calfileh,"UID:".$uid."\n");
|
|
||||||
if ($email <> "")
|
|
||||||
{
|
{
|
||||||
fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
|
fwrite($calfileh,"BEGIN:VEVENT\n");
|
||||||
fwrite($calfileh,"CONTACT:MAILTO:".$email."\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");
|
// Output the vCard/iCal VTODO object
|
||||||
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");
|
|
||||||
|
|
||||||
// Dates
|
// Output the vCard/iCal VJOURNAL object
|
||||||
$startdatef = dolibarr_print_date($startdate,'dayhourxcard');
|
if ($type == 'journal')
|
||||||
fwrite($calfileh,"DTSTART:".$startdatef."\n");
|
{
|
||||||
|
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;
|
fwrite($calfileh,"END:VJOURNAL\n");
|
||||||
$enddatef = dolibarr_print_date($enddate,'dayhourxcard');
|
}
|
||||||
fwrite($calfileh,"DTEND:".$enddatef."\n");
|
|
||||||
|
|
||||||
|
|
||||||
// Put other info in comment
|
// Put other info in comment
|
||||||
/*
|
/*
|
||||||
$comment=array();
|
$comment=array();
|
||||||
@ -131,7 +169,6 @@ function build_calfile($format='vcal',$events_array,$outputfile,$filter='')
|
|||||||
fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n");
|
fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fwrite($calfileh,"END:VEVENT\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +230,7 @@ function CalEncode($line)
|
|||||||
}
|
}
|
||||||
$out .= $newpara;
|
$out .= $newpara;
|
||||||
|
|
||||||
return trim($out);
|
return utf8_encode(trim($out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -178,18 +178,19 @@ class Webcal {
|
|||||||
/**
|
/**
|
||||||
\brief Export fichier cal depuis base webcalendar
|
\brief Export fichier cal depuis base webcalendar
|
||||||
\param format 'ical' or 'vcal'
|
\param format 'ical' or 'vcal'
|
||||||
|
\param type 'event' or 'journal'
|
||||||
\param cachedelay Do not rebuild file if date older than cachedelay seconds
|
\param cachedelay Do not rebuild file if date older than cachedelay seconds
|
||||||
\param filename Force filename
|
\param filename Force filename
|
||||||
\param filter Array of filters
|
\param filter Array of filters
|
||||||
\return int <0 if error, nb of events in new file if ok
|
\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;
|
global $conf,$langs;
|
||||||
|
|
||||||
require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php");
|
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
|
// Check parameters
|
||||||
if (empty($format)) return -1;
|
if (empty($format)) return -1;
|
||||||
@ -233,7 +234,8 @@ class Webcal {
|
|||||||
|
|
||||||
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
|
// 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
|
||||||
$event=array();
|
$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;
|
$date=$obj->cal_date;
|
||||||
$time=$obj->cal_time;
|
$time=$obj->cal_time;
|
||||||
if (eregi('^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$',$date,$reg))
|
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);
|
$datestart=dolibarr_mktime($hour,$min,$sec,$month,$day,$year);
|
||||||
$event['startdate']=$datestart;
|
$event['startdate']=$datestart;
|
||||||
$event['duration']=$obj->cal_duration;
|
//$event['duration']=$obj->cal_duration; // Not required with type 'journal'
|
||||||
$event['enddate']='';
|
//$event['enddate']=''; // Not required with type 'journal'
|
||||||
$event['summary']=$obj->cal_name;
|
$event['summary']=$obj->cal_name;
|
||||||
$event['desc']=$obj->cal_description;
|
$event['desc']=$obj->cal_description;
|
||||||
$event['author']=$obj->cal_create_by;
|
$event['author']=$obj->cal_create_by;
|
||||||
|
|||||||
@ -72,12 +72,14 @@ if (! $webcal->localdb->connected || ! $webcal->localdb->database_selected)
|
|||||||
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
|
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
|
||||||
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
|
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
|
||||||
|
|
||||||
// Define format, filename and filter
|
// Define format, type, filename and filter
|
||||||
$format='vcal';
|
$format='vcal';
|
||||||
|
$type='event';
|
||||||
$filename='';
|
$filename='';
|
||||||
if (! empty($_GET["format"])) $format=$_GET["format"];
|
if (! empty($_GET["format"])) $format=$_GET["format"];
|
||||||
if ($format == 'vcal') $filename='webcalendar.vcs';
|
if ($format == 'vcal') $filename='webcalendar.vcs';
|
||||||
if ($format == 'ical') $filename='webcalendar.ics';
|
if ($format == 'ical') $filename='webcalendar.ics';
|
||||||
|
if (! empty($_GET["type"])) $type=$_GET["type"];
|
||||||
if (! $filename)
|
if (! $filename)
|
||||||
{
|
{
|
||||||
$langs->load("main");
|
$langs->load("main");
|
||||||
@ -91,7 +93,7 @@ $filters=array();
|
|||||||
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
|
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
|
||||||
|
|
||||||
// Build file
|
// Build file
|
||||||
$result=$webcal->build_calfile($format,0,$filename,$filters);
|
$result=$webcal->build_calfile($format,$type,0,$filename,$filters);
|
||||||
if ($result >= 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=webcal&file='.urlencode($filename));
|
header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=webcal&file='.urlencode($filename));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user