Add rss export in agenda module

This commit is contained in:
Laurent Destailleur 2008-04-27 20:31:15 +00:00
parent 1336a3cd41
commit cbfcd1c7e8
4 changed files with 503 additions and 336 deletions

View File

@ -545,13 +545,13 @@ class ActionComm
\param filters Array of filters \param filters 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,$type,$cachedelay,$filename,$filters) function build_exportfile($format,$type,$cachedelay,$filename,$filters)
{ {
global $conf,$langs,$dolibarr_main_url_root; global $conf,$langs,$dolibarr_main_url_root;
require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php"); require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php");
dolibarr_syslog("ActionComm::build_calfile Build cal file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG); dolibarr_syslog("ActionComm::build_exportfile Build export 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;
@ -602,7 +602,7 @@ class ActionComm
} }
$sql.= " ORDER by datec"; $sql.= " ORDER by datec";
dolibarr_syslog("ActionComm::build_vcal select events sql=".$sql); dolibarr_syslog("ActionComm::build_exportfile select events sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -641,14 +641,16 @@ class ActionComm
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dolibarr_syslog("ActionComm::build_calfile ".$this->db->lasterror(), LOG_ERR); dolibarr_syslog("ActionComm::build_exportfile ".$this->db->lasterror(), LOG_ERR);
return -1; return -1;
} }
// Write file // Write file
$title='Dolibarr actions'; $title='Dolibarr actions';
$desc='List of actions - built by Dolibarr'; $desc='List of actions - built by Dolibarr';
$result=build_calfile($format,$title,$desc,$eventarray,$outputfile); if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
if ($format == 'rss') $result=build_rssfile($format,$title,$desc,$eventarray,$outputfile);
} }
return $result; return $result;

View File

@ -118,6 +118,9 @@ $message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal);
$message.='<br>'; $message.='<br>';
$urlical='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>'; $urlical='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>';
$message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical); $message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical);
$message.='<br>';
$urlrss='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=rss&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=rss&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>';
$message.=$langs->trans("WebCalUrlForVCalExport",'rss',$urlrss);
print info_admin($message); print info_admin($message);
$db->close(); $db->close();

View File

@ -29,6 +29,18 @@ require("../../master.inc.php");
require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php'); require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php');
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
// Define format, type and filter
$format='ical';
$type='event';
if (! empty($_GET["format"])) $format=$_GET["format"];
if (! empty($_GET["type"])) $type=$_GET["type"];
$filters=array();
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
if (! empty($_GET["idaction"])) $filters['idaction']=$_GET["idaction"];
// C'est un wrapper, donc header vierge // C'est un wrapper, donc header vierge
function llxHeader() { print '<html><title>Export agenda cal</title><body>'; } function llxHeader() { print '<html><title>Export agenda cal</title><body>'; }
function llxFooter() { print '</body></html>'; } function llxFooter() { print '</body></html>'; }
@ -37,29 +49,34 @@ function llxFooter() { print '</body></html>'; }
if (! $conf->agenda->enabled) if (! $conf->agenda->enabled)
accessforbidden(); accessforbidden();
// Check config // Check config
if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY)) if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY))
{ {
$user->getrights(); $user->getrights();
llxHeader(); llxHeader();
print '<div class="error">Module Agenda was not configured properly.</div>'; print '<div class="error">Module Agenda was not configured properly.</div>';
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');
exit; exit;
} }
// Check exportkey
if (empty($_GET["exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET["exportkey"])
{
$user->getrights();
llxHeader();
print '<div class="error">Bad value for key.</div>';
llxFooter('$Date$ - $Revision$');
exit;
}
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:""; // Define filename
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
// Define format, type, filename and filter
$format='ical';
$type='event';
$filename=''; $filename='';
if (! empty($_GET["format"])) $format=$_GET["format"];
if ($format == 'vcal') $filename='dolibarrcalendar.vcs'; if ($format == 'vcal') $filename='dolibarrcalendar.vcs';
if ($format == 'ical') $filename='dolibarrcalendar.ics'; if ($format == 'ical') $filename='dolibarrcalendar.ics';
if (! empty($_GET["type"])) $type=$_GET["type"]; if ($format == 'rss') $filename='dolibarrcalendar.rss';
// Check filename // Check filename
if (! $filename) if (! $filename)
{ {
@ -70,41 +87,70 @@ if (! $filename)
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');
exit; exit;
} }
// Check exportkey
// \TODO
$filters=array();
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
if (! empty($_GET["idaction"])) $filters['idaction']=$_GET["idaction"];
$agenda=new ActionComm($db); $agenda=new ActionComm($db);
// Build file // Build file
$result=$agenda->build_calfile($format,$type,0,$filename,$filters); if ($format == 'ical' || $format == 'vcal')
if ($result >= 0) {
{ $result=$agenda->build_exportfile($format,$type,0,$filename,$filters);
$encoding='UTF-8'; if ($result >= 0)
$attachment = true; {
$type='text/calendar'; $encoding='UTF-8';
//$type='text/plain'; // OK $attachment = true;
//$attachment = false; // OK $type='text/calendar';
//$type='text/plain'; // OK
//$attachment = false; // OK
if ($encoding) header('Content-Encoding: '.$encoding);
if ($type) header('Content-Type: '.$type);
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
// Clean parameters
$outputfile=$conf->agenda->dir_temp.'/'.$filename;
$result=readfile($outputfile);
if (! $result) print 'File '.$outputfile.' was empty.';
if ($encoding) header('Content-Encoding: '.$encoding); // header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
if ($type) header('Content-Type: '.$type); exit;
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); }
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
// Clean parameters
$outputfile=$conf->agenda->dir_temp.'/'.$filename;
$result=readfile($outputfile);
if (! $result) print 'File '.$outputfile.' was empty.';
// header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
exit;
} }
if ($format == 'rss')
{
$result=$agenda->build_exportfile($format,$type,0,$filename,$filters);
if ($result >= 0)
{
$encoding='iso-8859-1';
$attachment = false;
$type='application/rss+xml';
//$type='text/plain'; // OK
//$attachment = false; // OK
if ($encoding) header('Content-Encoding: '.$encoding);
if ($type) header('Content-Type: '.$type);
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
// Clean parameters
$outputfile=$conf->agenda->dir_temp.'/'.$filename;
$result=readfile($outputfile);
if (! $result) print 'File '.$outputfile.' was empty.';
// header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
exit;
}
}
llxHeader(); llxHeader();
print '<div class="error">'.$agenda->error.'</div>'; print '<div class="error">'.$agenda->error.'</div>';
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');

View File

@ -1,295 +1,411 @@
<?php <?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
/** /**
\file htdocs/lib/xcal.lib.php \file htdocs/lib/xcal.lib.php
\brief Function to manage calendar files (vcal/ical/...) \brief Function to manage calendar files (vcal/ical/...)
\version $Id$ \version $Id$
*/ */
/** /**
\brief Build a file from an array of events \brief Build a file from an array of events
\param format 'vcal' or 'ical' \param format 'vcal' or 'ical'
\param title Title of export \param title Title of export
\param desc Description of export \param desc Description of export
\param events_array Array of events ('eid','startdate','duration','enddate','title','summary','category','email','url','desc','author') \param events_array Array of events ('eid','startdate','duration','enddate','title','summary','category','email','url','desc','author')
\param outputfile Output file \param outputfile Output file
\param filter Filter \param filter Filter
\return int <0 if ko, Nb of events in file if ok \return int <0 if ko, Nb of events in file if ok
*/ */
function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile,$filter='') function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile,$filter='')
{ {
dolibarr_syslog("xcal.lib.php::build_cal_file Build cal file ".$outputfile." to format ".$format); dolibarr_syslog("xcal.lib.php::build_calfile Build cal file ".$outputfile." to format ".$format);
if (empty($outputfile)) return -1; if (empty($outputfile)) return -1;
$calfileh=fopen($outputfile,'w'); $calfileh=fopen($outputfile,'w');
if ($calfileh) if ($calfileh)
{ {
$now=mktime(); $now=mktime();
// Print header // Print header
fwrite($calfileh,"BEGIN:VCALENDAR\n"); fwrite($calfileh,"BEGIN:VCALENDAR\n");
fwrite($calfileh,"VERSION:2.0\n"); fwrite($calfileh,"VERSION:2.0\n");
fwrite($calfileh,"METHOD:PUBLISH\n"); fwrite($calfileh,"METHOD:PUBLISH\n");
fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."//EN\n"); fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."//EN\n");
fwrite($calfileh,"CALSCALE:GREGORIAN\n"); fwrite($calfileh,"CALSCALE:GREGORIAN\n");
fwrite($calfileh,"X-WR-CALNAME:".utf8_encode($title)."\n"); fwrite($calfileh,"X-WR-CALNAME:".utf8_encode($title)."\n");
fwrite($calfileh,"X-WR-CALDESC:".utf8_encode($desc)."\n"); fwrite($calfileh,"X-WR-CALDESC:".utf8_encode($desc)."\n");
//fwrite($calfileh,"X-WR-TIMEZONE:Europe/Paris\n"); //fwrite($calfileh,"X-WR-TIMEZONE:Europe/Paris\n");
foreach ($events_array as $date => $event) foreach ($events_array as $date => $event)
{ {
$eventqualified=true; $eventqualified=true;
if ($filter) if ($filter)
{ {
// \TODO Add a filter // \TODO Add a filter
$eventqualified=false; $eventqualified=false;
} }
if ($eventqualified) if ($eventqualified)
{ {
// See http://fr.wikipedia.org/wiki/ICalendar for format // 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']; $uid = $event['uid'];
$type = $event['type']; $type = $event['type'];
$startdate = $event['startdate']; $startdate = $event['startdate'];
$duration = $event['duration']; $duration = $event['duration'];
$enddate = $event['enddate']; $enddate = $event['enddate'];
$summary = $event['summary']; $summary = $event['summary'];
$category = $event['category']; $category = $event['category'];
$location = $event['location']; $location = $event['location'];
$email = $event['email']; $email = $event['email'];
$url = $event['url']; $url = $event['url'];
$transparency = $event['transparency']; $transparency = $event['transparency'];
$description=eregi_replace('<br[ \/]?>',"\n",$event['desc']); $description=eregi_replace('<br[ \/]?>',"\n",$event['desc']);
$description=clean_html($description,0); // Remove html tags $description=clean_html($description,0); // Remove html tags
// Uncomment for tests // Uncomment for tests
//$summary="Resume"; //$summary="Resume";
//$description="Description"; //$description="Description";
//$description="MemberValidatedInDolibarr gd gdf gd gdff\nNom: tgdf g dfgdf gfd r ter\nType: gdfgfdf dfg fd gfd gd gdf gdf gfd gdfg dfg ddf\nAuteur: AD01fg dgdgdfg df gdf gd"; //$description="MemberValidatedInDolibarr gd gdf gd gdff\nNom: tgdf g dfgdf gfd r ter\nType: gdfgfdf dfg fd gfd gd gdf gdf gfd gdfg dfg ddf\nAuteur: AD01fg dgdgdfg df gdf gd";
// Format // Format
$summary=format_cal($format,$summary); $summary=format_cal($format,$summary);
$description=format_cal($format,$description); $description=format_cal($format,$description);
$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
if ($type == 'event') if ($type == 'event')
{ {
fwrite($calfileh,"BEGIN:VEVENT\n"); fwrite($calfileh,"BEGIN:VEVENT\n");
fwrite($calfileh,"UID:".$uid."\n"); fwrite($calfileh,"UID:".$uid."\n");
if (! empty($email)) if (! empty($email))
{ {
fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); fwrite($calfileh,"CONTACT:MAILTO:".$email."\n");
} }
if (! empty($url)) if (! empty($url))
{ {
fwrite($calfileh,"URL:".$url."\n"); fwrite($calfileh,"URL:".$url."\n");
}; };
fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n"); fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
//fwrite($calfileh,'STATUS:CONFIRMED'."\n"); //fwrite($calfileh,'STATUS:CONFIRMED'."\n");
/* /*
statvalue = "TENTATIVE" ;Indicates event is statvalue = "TENTATIVE" ;Indicates event is
;tentative. ;tentative.
/ "CONFIRMED" ;Indicates event is / "CONFIRMED" ;Indicates event is
;definite. ;definite.
/ "CANCELLED" ;Indicates event was / "CANCELLED" ;Indicates event was
;cancelled. ;cancelled.
;Status values for a "VEVENT" ;Status values for a "VEVENT"
statvalue =/ "NEEDS-ACTION" ;Indicates to-do needs action. statvalue =/ "NEEDS-ACTION" ;Indicates to-do needs action.
/ "COMPLETED" ;Indicates to-do completed. / "COMPLETED" ;Indicates to-do completed.
/ "IN-PROCESS" ;Indicates to-do in process of / "IN-PROCESS" ;Indicates to-do in process of
/ "CANCELLED" ;Indicates to-do was cancelled. / "CANCELLED" ;Indicates to-do was cancelled.
;Status values for "VTODO". ;Status values for "VTODO".
statvalue =/ "DRAFT" ;Indicates journal is draft. statvalue =/ "DRAFT" ;Indicates journal is draft.
/ "FINAL" ;Indicates journal is final. / "FINAL" ;Indicates journal is final.
/ "CANCELLED" ;Indicates journal is removed. / "CANCELLED" ;Indicates journal is removed.
;Status values for "VJOURNAL". ;Status values for "VJOURNAL".
*/ */
if (! empty($category)) fwrite($calfileh,"CATEGORIES:".$category."\n"); if (! empty($category)) fwrite($calfileh,"CATEGORIES:".$category."\n");
if (! empty($location)) fwrite($calfileh,"LOCATION:".$location."\n"); if (! empty($location)) fwrite($calfileh,"LOCATION:".$location."\n");
//fwrite($calfileh,"TRANSP:".$transparency."\n"); //fwrite($calfileh,"TRANSP:".$transparency."\n");
//fwrite($calfileh,"CLASS:PUBLIC\n"); // PUBLIC, PRIVATE, CONFIDENTIAL //fwrite($calfileh,"CLASS:PUBLIC\n"); // PUBLIC, PRIVATE, CONFIDENTIAL
fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($now,'dayhourxcard')."\n"); fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($now,'dayhourxcard')."\n");
$startdatef = dolibarr_print_date($startdate,'dayhourxcard'); $startdatef = dolibarr_print_date($startdate,'dayhourxcard');
fwrite($calfileh,"DTSTART:".$startdatef."\n"); fwrite($calfileh,"DTSTART:".$startdatef."\n");
if (empty($enddate)) $enddate=$startdate+$duration; if (empty($enddate)) $enddate=$startdate+$duration;
$enddatef = dolibarr_print_date($enddate,'dayhourxcard'); $enddatef = dolibarr_print_date($enddate,'dayhourxcard');
fwrite($calfileh,"DTEND:".$enddatef."\n"); fwrite($calfileh,"DTEND:".$enddatef."\n");
fwrite($calfileh,"END:VEVENT\n"); fwrite($calfileh,"END:VEVENT\n");
} }
// Output the vCard/iCal VTODO object // Output the vCard/iCal VTODO object
// ... // ...
//PERCENT-COMPLETE:39 //PERCENT-COMPLETE:39
// Output the vCard/iCal VJOURNAL object // Output the vCard/iCal VJOURNAL object
if ($type == 'journal') if ($type == 'journal')
{ {
fwrite($calfileh,"BEGIN:VJOURNAL\n"); fwrite($calfileh,"BEGIN:VJOURNAL\n");
fwrite($calfileh,"UID:".$uid."\n"); fwrite($calfileh,"UID:".$uid."\n");
if (! empty($email)) if (! empty($email))
{ {
fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n");
fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); fwrite($calfileh,"CONTACT:MAILTO:".$email."\n");
} }
if (! empty($url)) if (! empty($url))
{ {
fwrite($calfileh,"URL:".$url."\n"); fwrite($calfileh,"URL:".$url."\n");
}; };
fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n"); fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
fwrite($calfileh,'STATUS:CONFIRMED'."\n"); fwrite($calfileh,'STATUS:CONFIRMED'."\n");
fwrite($calfileh,"CATEGORIES:".$category."\n"); fwrite($calfileh,"CATEGORIES:".$category."\n");
fwrite($calfileh,"LOCATION:".$location."\n"); fwrite($calfileh,"LOCATION:".$location."\n");
fwrite($calfileh,"TRANSP:OPAQUE\n"); fwrite($calfileh,"TRANSP:OPAQUE\n");
fwrite($calfileh,"CLASS:CONFIDENTIAL\n"); fwrite($calfileh,"CLASS:CONFIDENTIAL\n");
fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($startdatef,'dayhourxcard')."\n"); fwrite($calfileh,"DTSTAMP:".dolibarr_print_date($startdatef,'dayhourxcard')."\n");
fwrite($calfileh,"END:VJOURNAL\n"); fwrite($calfileh,"END:VJOURNAL\n");
} }
// Put other info in comment // Put other info in comment
/* /*
$comment=array(); $comment=array();
$comment ['eid'] = $eid; $comment ['eid'] = $eid;
$comment ['url'] = $linktoevent; $comment ['url'] = $linktoevent;
$comment ['date'] = dolibarr_mktime($evttime,"Ymd"); $comment ['date'] = dolibarr_mktime($evttime,"Ymd");
$comment ['duration'] = $duration; $comment ['duration'] = $duration;
$comment ['startdate'] = $startdate; $comment ['startdate'] = $startdate;
$comment ['enddate'] = $enddate; $comment ['enddate'] = $enddate;
fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n"); fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n");
*/ */
} }
} }
// Footer // Footer
fwrite($calfileh,"END:VCALENDAR"); fwrite($calfileh,"END:VCALENDAR");
fclose($calfileh); fclose($calfileh);
} }
else else
{ {
dolibarr_syslog("xcal.lib.php::build_cal_file Failed to open file ".$outputfile." for writing"); dolibarr_syslog("xcal.lib.php::build_cal_file Failed to open file ".$outputfile." for writing");
return -2; return -2;
} }
} }
/**
function format_cal($format,$string) \brief Build a file from an array of events
{ \param format 'rss'
$newstring=$string; \param title Title of export
\param desc Description of export
if ($format == 'vcal') \param events_array Array of events ('eid','startdate','duration','enddate','title','summary','category','email','url','desc','author')
{ \param outputfile Output file
$newstring=QPEncode($newstring); \param filter Filter
} \return int <0 if ko, Nb of events in file if ok
if ($format == 'ical') */
{ function build_rssfile($format='rss',$title,$desc,$events_array,$outputfile,$filter='')
// Replace new lines chars by '\n' {
$newstring=eregi_replace("\r\n","\n",$newstring); dolibarr_syslog("xcal.lib.php::build_rssfile Build rss file ".$outputfile." to format ".$format);
$newstring=eregi_replace("\n\r","\n",$newstring);
$newstring=eregi_replace("\n",'\n',$newstring); if (empty($outputfile)) return -1;
// Must not exceed 75 char. Cut with "\r\n"+Space
$newstring=CalEncode($newstring); $fichier=fopen($outputfile,'w');
} if ($fichier)
{
return $newstring; $now=mktime();
} $date=date("r");
/** // Print header
\brief Cut string after 75 chars. Add CRLF+Space. $html='<?xml version="1.0" encoding="iso-8859-1"?>';
\param string String to convert fwrite($fichier, $html);
\return string String converted fwrite($fichier, "\n");
*/ $html='<rss version="2.0">';
function CalEncode($line) fwrite($fichier, $html);
{ fwrite($fichier, "\n");
$out = '';
$html="<channel>".
$newpara = ''; "\n".
"<title>".$title."</title>";
for ($j = 0; $j <= strlen($line) - 1; $j++) fwrite($fichier, $html);
{ fwrite($fichier, "\n");
$char = substr ( $line, $j, 1 );
$html='<description><![CDATA['.$desc.'.]]></description>'.
if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 75 ) // '<language>fr</language>'.
{ '<copyright>Dolibarr</copyright>'.
$out .= $newpara . "\r\n "; // CRLF + Space for cal '<lastBuildDate>'.$date.'</lastBuildDate>'.
$newpara = ''; '<generator>Dolibarr</generator>'.
} '<link><![CDATA['.$_SERVER["PHP_SELF"].']]></link>';
$newpara .= $char; // '<image>'.
} // '<url><![CDATA[http://www.lesbonnesannonces.com/images/logo_rss.gif]]></url>'.
$out .= $newpara; // '<title><![CDATA[Dolibarr events]]></title>'.
// '<link><![CDATA[http://www.lesbonnesannonces.com/]]></link>'.
return utf8_encode(trim($out)); // '<width>144</width>'.
} // '<height>36</height>'.
// '</image>'."\n";
function QPEncode($str,$forcal=0) #print $html;
{ fwrite($fichier, $html);
$lines = preg_split("/\r\n/", $str);
$out = '';
foreach ($events_array as $date => $event)
foreach ($lines as $line) {
{ $eventqualified=true;
$newpara = ''; if ($filter)
{
for ($j = 0; $j <= strlen($line) - 1; $j++) // \TODO Add a filter
{
$char = substr ( $line, $j, 1 ); $eventqualified=false;
$ascii = ord ( $char ); }
if ( $ascii < 32 || $ascii == 61 || $ascii > 126 ) if ($eventqualified)
$char = '=' . strtoupper ( sprintf("%02X", $ascii ) ); {
//$uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 76 ) $uid = $event['uid'];
{ $type = $event['type'];
$out .= $newpara . '=' . "\r\n"; // CRLF $startdate = $event['startdate'];
if ($forcal) $out .= " "; // + Space for cal $duration = $event['duration'];
$newpara = ''; $enddate = $event['enddate'];
} $summary = $event['summary'];
$newpara .= $char; $category = $event['category'];
} $location = $event['location'];
$out .= $newpara; $email = $event['email'];
} $url = $event['url'];
return trim ( $out ); $transparency = $event['transparency'];
} $description=eregi_replace('<br[ \/]?>',"\n",$event['desc']);
$description=clean_html($description,0); // Remove html tags
function QPDecode( $str )
{
$out = preg_replace('/=\r?\n/', '', $str); fwrite ($fichier, "<item>");
$out = preg_replace('/=([A-F0-9]{2})/e', chr( hexdec ('\\1' ) ), $out); fwrite ($fichier, "\n");
fwrite ($fichier, "<title><![CDATA[".$summary."]]></title>");
return trim($out); fwrite ($fichier, "\n");
} fwrite ($fichier, "<link><![CDATA[".$url."]]></link>");
fwrite ($fichier, "\n");
fwrite ($fichier, "<description><![CDATA[");
if ($description) fwrite ($fichier, $description);
//else fwrite ($fichier, 'NoDesc');
fwrite ($fichier, "]]></description>");
fwrite ($fichier, "\n");
fwrite ($fichier, "<pubDate>".date("r", $startdate)."</pubDate>");
fwrite ($fichier, "\n");
fwrite ($fichier, '<guid isPermaLink="true"><![CDATA[');
// http://www.lesbonnesannonces.com/index_categ.php?origine=&id_categ='.$id_categ.
fwrite ($fichier, $url);
fwrite ($fichier, ']]></guid>');
fwrite ($fichier, "\n");
fwrite ($fichier, "</item>");
fwrite ($fichier, "\n");
//chmod($fichierout, 0664);
}
}
fwrite($fichier, '</channel>');
fwrite ($fichier, "\n");
fwrite($fichier, '</rss>');
fclose($fichier);
}
}
function format_cal($format,$string)
{
$newstring=$string;
if ($format == 'vcal')
{
$newstring=QPEncode($newstring);
}
if ($format == 'ical')
{
// Replace new lines chars by '\n'
$newstring=eregi_replace("\r\n","\n",$newstring);
$newstring=eregi_replace("\n\r","\n",$newstring);
$newstring=eregi_replace("\n",'\n',$newstring);
// Must not exceed 75 char. Cut with "\r\n"+Space
$newstring=CalEncode($newstring);
}
return $newstring;
}
/**
\brief Cut string after 75 chars. Add CRLF+Space.
\param string String to convert
\return string String converted
*/
function CalEncode($line)
{
$out = '';
$newpara = '';
for ($j = 0; $j <= strlen($line) - 1; $j++)
{
$char = substr ( $line, $j, 1 );
if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 75 )
{
$out .= $newpara . "\r\n "; // CRLF + Space for cal
$newpara = '';
}
$newpara .= $char;
}
$out .= $newpara;
return utf8_encode(trim($out));
}
function QPEncode($str,$forcal=0)
{
$lines = preg_split("/\r\n/", $str);
$out = '';
foreach ($lines as $line)
{
$newpara = '';
for ($j = 0; $j <= strlen($line) - 1; $j++)
{
$char = substr ( $line, $j, 1 );
$ascii = ord ( $char );
if ( $ascii < 32 || $ascii == 61 || $ascii > 126 )
$char = '=' . strtoupper ( sprintf("%02X", $ascii ) );
if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 76 )
{
$out .= $newpara . '=' . "\r\n"; // CRLF
if ($forcal) $out .= " "; // + Space for cal
$newpara = '';
}
$newpara .= $char;
}
$out .= $newpara;
}
return trim ( $out );
}
function QPDecode( $str )
{
$out = preg_replace('/=\r?\n/', '', $str);
$out = preg_replace('/=([A-F0-9]{2})/e', chr( hexdec ('\\1' ) ), $out);
return trim($out);
}
?> ?>