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
|
||||
$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.='<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);
|
||||
print info_admin($message);
|
||||
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user