Fix: Debug and enhance agenda external ical view
This commit is contained in:
parent
47e279d40d
commit
159d6418d5
@ -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%\">";
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -30,7 +30,7 @@ class ical
|
||||
var $event_count; // Number of Events
|
||||
var $todo_count; // Number of TODOs
|
||||
var $last_key; //Help variable save last key (multiline string)
|
||||
|
||||
|
||||
/**
|
||||
* Read text file, icalender text file
|
||||
*
|
||||
@ -40,9 +40,9 @@ class ical
|
||||
function read_file($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
$file_text = join ("", file ($file)); //load file
|
||||
$file_text = join ("", file ($file)); //load file
|
||||
$file_text = preg_replace("/[\r\n]{1,} ([:;])/","\\1",$file_text);
|
||||
|
||||
|
||||
return $file_text; // return all text
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ class ical
|
||||
{
|
||||
return $this->event_count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of ToDo
|
||||
*
|
||||
@ -65,7 +65,7 @@ class ical
|
||||
{
|
||||
return $this->todo_count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translate Calendar
|
||||
*
|
||||
@ -76,16 +76,17 @@ class ical
|
||||
{
|
||||
$this->cal = array(); // new empty array
|
||||
|
||||
$this->event_count = -1;
|
||||
$this->event_count = -1;
|
||||
|
||||
// read FILE text
|
||||
$this->file_text = $this->read_file($uri);
|
||||
|
||||
$this->file_text = preg_split("[\n]", $this->file_text);
|
||||
|
||||
|
||||
// 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
|
||||
@ -93,7 +94,7 @@ class ical
|
||||
{
|
||||
// get Key and Value VCALENDAR:Begin -> Key = VCALENDAR, Value = begin
|
||||
list($key, $value) = $this->retun_key_value($text);
|
||||
|
||||
|
||||
switch ($text) // search special string
|
||||
{
|
||||
case "BEGIN:VTODO":
|
||||
@ -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,17 +130,25 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->cal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@ -154,12 +173,16 @@ class ical
|
||||
if (($key == "DTSTAMP") or ($key == "LAST-MODIFIED") or ($key == "CREATED")) $value = $this->ical_date_to_unix($value);
|
||||
if ($key == "RRULE" ) $value = $this->ical_rrule($value);
|
||||
|
||||
if (stristr($key,"DTSTART") or stristr($key,"DTEND") or stristr($key,"DTSTART;VALUE=DATE") or stristr($key,"DTEND;VALUE=DATE"))
|
||||
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,15 +195,19 @@ 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;
|
||||
}
|
||||
$this->last_key = $key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse text "XXXX:value text some with : " and return array($key = "XXXX", $value="value");
|
||||
* Parse text "XXXX:value text some with : " and return array($key = "XXXX", $value="value");
|
||||
*
|
||||
* @param string $text
|
||||
* @return array
|
||||
@ -188,19 +215,19 @@ class ical
|
||||
function retun_key_value($text)
|
||||
{
|
||||
preg_match("/([^:]+)[:]([\w\W]+)/", $text, $matches);
|
||||
|
||||
|
||||
if (empty($matches))
|
||||
{
|
||||
return array(false,$text);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
$matches = array_splice($matches, 1, 2);
|
||||
return $matches;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse RRULE return array
|
||||
*
|
||||
@ -210,7 +237,7 @@ class ical
|
||||
function ical_rrule($value)
|
||||
{
|
||||
$rrule = explode(';',$value);
|
||||
foreach ($rrule as $line)
|
||||
foreach ($rrule as $line)
|
||||
{
|
||||
$rcontent = explode('=', $line);
|
||||
$result[$rcontent[0]] = $rcontent[1];
|
||||
@ -228,17 +255,16 @@ 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
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return unix date from iCal date format
|
||||
*
|
||||
@ -252,21 +278,21 @@ class ical
|
||||
|
||||
// Analyse TZID
|
||||
$temp = explode(";",$key);
|
||||
|
||||
|
||||
if (empty($temp[1])) // not TZID
|
||||
{
|
||||
$value = str_replace('T', '', $value);
|
||||
return array($key,$value);
|
||||
}
|
||||
// adding $value and $tzid
|
||||
// adding $value and $tzid
|
||||
$key = $temp[0];
|
||||
$temp = explode("=", $temp[1]);
|
||||
$return_value[$temp[0]] = $temp[1];
|
||||
$return_value['unixtime'] = $value;
|
||||
|
||||
|
||||
return array($key,$return_value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return sorted eventlist as array or false if calenar is empty
|
||||
*
|
||||
@ -279,12 +305,12 @@ class ical
|
||||
{
|
||||
usort($temp, array(&$this, "ical_dtstart_compare"));
|
||||
return $temp;
|
||||
} else
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare two unix timestamp
|
||||
*
|
||||
@ -294,9 +320,9 @@ class ical
|
||||
*/
|
||||
function ical_dtstart_compare($a, $b)
|
||||
{
|
||||
return strnatcasecmp($a['DTSTART']['unixtime'], $b['DTSTART']['unixtime']);
|
||||
return strnatcasecmp($a['DTSTART']['unixtime'], $b['DTSTART']['unixtime']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return eventlist array (not sort eventlist array)
|
||||
*
|
||||
@ -306,7 +332,17 @@ 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)
|
||||
*
|
||||
@ -316,7 +352,7 @@ class ical
|
||||
{
|
||||
return $this->cal['VTODO'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return base calendar data
|
||||
*
|
||||
@ -326,7 +362,7 @@ class ical
|
||||
{
|
||||
return $this->cal['VCALENDAR'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return array with all data
|
||||
*
|
||||
@ -337,4 +373,4 @@ class ical
|
||||
return $this->cal;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user