Fix: Debug and enhance agenda external ical view

This commit is contained in:
Laurent Destailleur 2011-06-10 22:05:07 +00:00
parent 47e279d40d
commit 159d6418d5
7 changed files with 689 additions and 598 deletions

View File

@ -29,6 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php');
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php');
require_once(DOL_DOCUMENT_ROOT."/lib/agenda.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
if (!$user->admin)
accessforbidden();
@ -54,7 +55,9 @@ if ($actionsave)
{
$db->begin();
$res=dolibarr_set_const($db,'ENABLE_AGENDA_EXT'.$i,trim(GETPOST("ENABLE_AGENDA_EXT".$i)),'chaine',0);
$disableext=GETPOST("AGENDA_DISABLE_EXT");
if ($disableext) $disableext=0; else $disableext=1;
$res=dolibarr_set_const($db,'AGENDA_DISABLE_EXT',$disableext,'chaine',0);
$i=1;
$error=0;
@ -115,7 +118,9 @@ dol_fiche_head($head, 'extsites', $langs->trans("Agenda"));
print '<form name="extsitesconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print $langs->trans("ExtSitesEnableThisTool").' '.$form->selectyesno("ENABLE_AGENDA_EXT",(GETPOST("ENABLE_AGENDA_EXT"))?GETPOST("ENABLE_AGENDA_EXT"):$conf->global->ENABLE_AGENDA_EXT,1).'<br><br>';
$selectedvalue=(GETPOST("AGENDA_DISABLE_AGENDA"))?GETPOST("AGENDA_DISABLE_EXT"):$conf->global->AGENDA_DISABLE_EXT;
if ($selectedvalue==1) $selectedvalue=0; else $selectedvalue=1;
print $langs->trans("ExtSitesEnableThisTool").' '.$form->selectyesno("AGENDA_DISABLE_EXT",$selectedvalue,1).'<br><br>';
$var=false;
print "<table class=\"noborder\" width=\"100%\">";

View File

@ -638,7 +638,8 @@ class ActionComm extends CommonObject
if ($cachedelay)
{
$nowgmt = dol_now();
if (filemtime($outputfile) > ($nowgmt - $cachedelay))
include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay))
{
dol_syslog("ActionComm::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
$buildfile = false;

View File

@ -86,6 +86,7 @@ class ical
// is this text vcalendar standart text ? on line 1 is BEGIN:VCALENDAR
if (!stristr($this->file_text[0],'BEGIN:VCALENDAR')) return 'error not VCALENDAR';
$insidealarm=0;
foreach ($this->file_text as $text)
{
$text = trim($text); // trim one line
@ -106,6 +107,11 @@ class ical
$type = "VEVENT";
break;
case "BEGIN:VFREEBUSY":
$this->freebusy_count = $this->freebusy_count+1; // new event begin
$type = "VFREEBUSY";
break;
case "BEGIN:VCALENDAR": // all other special string
case "BEGIN:DAYLIGHT":
case "BEGIN:VTIMEZONE":
@ -115,6 +121,7 @@ class ical
case "END:VTODO": // end special text - goto VCALENDAR key
case "END:VEVENT":
case "END:VFREEBUSY":
case "END:VCALENDAR":
case "END:DAYLIGHT":
@ -123,8 +130,16 @@ class ical
$type = "VCALENDAR";
break;
// Manage VALARM that are inside a VEVENT to avoid fields of VALARM to overwrites fields of VEVENT
case "BEGIN:VALARM":
$insidealarm=1;
break;
case "END:VALARM":
$insidealarm=0;
break;
default: // no special string
$this->add_to_array($type, $key, $value); // add to array
if (! $insidealarm) $this->add_to_array($type, $key, $value); // add to array
break;
}
}
@ -133,7 +148,7 @@ class ical
}
/**
* Add to $this->ical array one value and key. Type is VTODO, VEVENT, VCALENDAR ... .
* Add to $this->ical array one value and key. Type is VTODO, VEVENT, VFREEBUSY, VCALENDAR ... .
*
* @param string $type
* @param string $key
@ -141,12 +156,16 @@ class ical
*/
function add_to_array($type, $key, $value)
{
//print 'type='.$type.' key='.$key.' value='.$value.'<br>'."\n";
if ($key == false)
{
$key = $this->last_key;
switch ($type)
{
case 'VEVENT': $value = $this->cal[$type][$this->event_count][$key].$value;break;
case 'VFREEBUSY': $value = $this->cal[$type][$this->freebusy_count][$key].$value;break;
case 'VTODO': $value = $this->cal[$type][$this->todo_count][$key].$value;break;
}
}
@ -157,9 +176,13 @@ class ical
if (stristr($key,"DTSTART") or stristr($key,"DTEND") or stristr($key,"DTSTART;VALUE=DATE") or stristr($key,"DTEND;VALUE=DATE"))
{
if (stristr($key,"DTSTART;VALUE=DATE") or stristr($key,"DTEND;VALUE=DATE"))
{
list($key,$value) = array($key,$value);
}
else
{
list($key,$value) = $this->ical_dt_date($key,$value);
}
}
switch ($type)
@ -172,6 +195,10 @@ class ical
$this->cal[$type][$this->event_count][$key] = $value;
break;
case "VFREEBUSY":
$this->cal[$type][$this->freebusy_count][$key] = $value;
break;
default:
$this->cal[$type][$key] = $value;
break;
@ -228,15 +255,14 @@ class ical
$ical_date = str_replace('T', '', $ical_date);
$ical_date = str_replace('Z', '', $ical_date);
$ntime=0;
// TIME LIMITED EVENT
preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})([0-9]{0,2})/', $ical_date, $date);
if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})([0-9]{0,2})/', $ical_date, $date))
$ntime=dol_mktime($date[4], $date[5], $date[6], $date[2],$date[3], $date[1], true);
// UNIX timestamps can't deal with pre 1970 dates
if ($date[1] <= 1970)
{
$date[1] = 1971;
}
return mktime($date[4], $date[5], $date[6], $date[2],$date[3], $date[1]);
//if (empty($date[4])) print 'Error bad date: '.$ical_date.' - date1='.$date[1];
//print dol_print_date($ntime,'dayhour');exit;
return $ntime; // ntime is a GTM time
}
/**
@ -307,6 +333,16 @@ class ical
return $this->cal['VEVENT'];
}
/**
* Return eventlist array (not sort eventlist array)
*
* @return array
*/
function get_freebusy_list()
{
return $this->cal['VFREEBUSY'];
}
/**
* Return todo array (not sort todo array)
*

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ ViewWithPredefinedFilters=Vues avec filtres prédéfinis
AutoActions=Alimentation automatique de l'agenda
AgendaAutoActionDesc=Définissez dans cet onglet les événements pour lesquels dolibarr créera automatiquement une action dans l'agenda. Si aucune case n'est cochée (par défaut), seules les actions manuelles seront incluses dans l'agenda.
AgendaSetupOtherDesc=Cette page permet de configurer les autres paramètres du module agenda.
AgendaExtSitesDesc=Cette page permet de configurer les calendriers externes.
AgendaExtSitesDesc=Cette page permet d'ajouter des sources de calendriers externes pour les visualiser au sein de l'agenda Dolibarr.
ActionsEvents=Événements pour lesquels Dolibarr doit créer une action dans l'agenda en automatique.
PropalValidatedInDolibarr=Proposition %s validée
InvoiceValidatedInDolibarr=Facture %s validée
@ -65,4 +65,4 @@ ExtSites=Calendriers extérieures
ExtSitesEnableThisTool=Afficher les calendriers externes sur l'agenda
ExtSitesNbOfAgenda=Nombre de calendriers
AgendaExtNb=Calendrier no %s
ExtSiteUrlAgenda=Url de acceso al archivo .ical
ExtSiteUrlAgenda=Url d'accès au fichier ical

View File

@ -551,9 +551,9 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
* "%d/%m/%Y %H:%M",
* "%d/%m/%Y %H:%M:%S",
* "day", "daytext", "dayhour", "dayhourldap", "dayhourtext"
* @param tzoutput true=output string is for Greenwich location
* false or 'tzserver'=output string is for local PHP server TZ usage
* 'tzuser'=output string is for local browser TZ usage
* @param tzoutput true=output or 'gmt' => string is for Greenwich location
* false or 'tzserver' => output string is for local PHP server TZ usage
* 'tzuser' => output string is for local browser TZ usage
* @param outputlangs Object lang that contains language for text translation.
* @param encodetooutput false=no convert into output pagecode
* @return string Formated date or '' if time is null
@ -806,7 +806,7 @@ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$chec
* @return timestamp Date as a timestamp, '' if error
* @see dol_print_date, dol_stringtotime
*/
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1,$isdst=true)
{
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
@ -841,7 +841,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
$date=strtotime($string);
print "- ".$string." ".$date." -";
*/
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm);
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,$isdst,$gm);
}
else
{

View File

@ -41,11 +41,11 @@ function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile)
if (empty($outputfile)) return -1;
// Note: A cal file is an UTF8 encoded file
// Note: A cal file is an UTF8 encoded file
$calfileh=fopen($outputfile,'w');
if ($calfileh)
{
$now=mktime();
$now=dol_now();
$encoding='';
if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:';
@ -58,8 +58,13 @@ function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile)
fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."\n");
fwrite($calfileh,"CALSCALE:GREGORIAN\n");
fwrite($calfileh,"X-WR-CALNAME:".$encoding.format_cal($format,$title)."\n");
fwrite($calfileh,"X-WR-CALDESC:".$encoding.format_cal($format,$desc)."\n");
//fwrite($calfileh,"X-WR-TIMEZONE:Europe/Paris\n");
fwrite($calfileh,"X-WR-CALDESC:".$encoding.format_cal($format,$desc)."\n");
$hh=ConvertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'hour');
$mm=ConvertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'min');
$ss=ConvertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'sec');
//fwrite($calfileh,"X-WR-TIMEZONE:Europe/Paris\n");
if (! empty($conf->global->MAIN_AGENDA_EXPORT_CACHE)
&& $conf->global->MAIN_AGENDA_EXPORT_CACHE > 60) fwrite($calfileh,"X-PUBLISHED-TTL: "."P".$hh."H".$mm."M".$ss."S\n");
foreach ($events_array as $date => $event)
{
@ -149,31 +154,31 @@ function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile)
if ($modified) fwrite($calfileh,"LAST-MODIFIED:".dol_print_date($modified,'dayhourxcard',true)."\n");
fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n");
fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n");
/*
/* Other keys:
// Status values for a "VEVENT"
statvalue = "TENTATIVE" ;Indicates event is
;tentative.
/ "CONFIRMED" ;Indicates event is
;definite.
/ "CANCELLED" ;Indicates event was
;cancelled.
;
// Status values for "VTODO".
statvalue =/ "NEEDS-ACTION" ;Indicates to-do needs action.
/ "COMPLETED" ;Indicates to-do completed.
/ "IN-PROCESS" ;Indicates to-do in process of
/ "CANCELLED" ;Indicates to-do was cancelled.
// Status values for "VJOURNAL".
statvalue =/ "DRAFT" ;Indicates journal is draft.
/ "FINAL" ;Indicates journal is final.
/ "CANCELLED" ;Indicates journal is removed.
*/
if (! empty($location)) fwrite($calfileh,"LOCATION:".$encoding.$location."\n");
//fwrite($calfileh,"CLASS:PUBLIC\n"); // PUBLIC, PRIVATE, CONFIDENTIAL
//fwrite($calfileh,"X-MICROSOFT-CDO-BUSYSTATUS:1\n");
//ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Laurent Destailleur;X-NUM-GUESTS=0:mailto:eldy10@gmail.com
if (! empty($location)) fwrite($calfileh,"LOCATION:".$encoding.$location."\n");
if ($fulldayevent) fwrite($calfileh,"X-FUNAMBOL-ALLDAY:1\n");
if ($fulldayevent) fwrite($calfileh,"X-MICROSOFT-CDO-ALLDAYEVENT:1\n");
// Date must be GMT dates
// Current date