From 43bf9ba89026eabd8f113697b897b6aafc0cfd33 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 23 May 2014 04:28:57 +0200 Subject: [PATCH] Fix: Import of ical files was broken Fix: Can import of ical files from BlueMind. --- htdocs/admin/agenda_extsites.php | 4 +-- htdocs/comm/action/class/ical.class.php | 13 +++++---- htdocs/comm/action/index.php | 36 ++++++++++++++++++++++--- htdocs/core/lib/agenda.lib.php | 13 +++++---- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php index b133485f866..1da43046b13 100644 --- a/htdocs/admin/agenda_extsites.php +++ b/htdocs/admin/agenda_extsites.php @@ -63,7 +63,7 @@ if ($actionsave) // Save agendas while ($i <= $MAXAGENDA) { - $name=trim(GETPOST('agenda_ext_name'.$i),'alpha'); + $name=trim(GETPOST('agenda_ext_name'.$i,'alpha')); $src=trim(GETPOST('agenda_ext_src'.$i,'alpha')); $color=trim(GETPOST('agenda_ext_color'.$i,'alpha')); if ($color=='-1') $color=''; @@ -76,7 +76,7 @@ if ($actionsave) break; } - //print 'color='.$color; + //print '-name='.$name.'-color='.$color; $res=dolibarr_set_const($db,'AGENDA_EXT_NAME'.$i,$name,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; $res=dolibarr_set_const($db,'AGENDA_EXT_SRC'.$i,$src,'chaine',0,'',$conf->entity); diff --git a/htdocs/comm/action/class/ical.class.php b/htdocs/comm/action/class/ical.class.php index 0e279adc03c..ae1abb6ea08 100644 --- a/htdocs/comm/action/class/ical.class.php +++ b/htdocs/comm/action/class/ical.class.php @@ -56,14 +56,13 @@ class ICal { $this->file = $file; $file_text=''; - + $tmparray=file($file); if (is_array($tmparray)) { $file_text = join("", $tmparray); //load file - $file_text = preg_replace("/[\r\n]{1,} ([:;])/","\\1",$file_text); + $file_text = preg_replace("/[\r\n]{1,} /","",$file_text); } - return $file_text; // return all text } @@ -115,6 +114,7 @@ class ICal { // get Key and Value VCALENDAR:Begin -> Key = VCALENDAR, Value = begin list($key, $value) = $this->retun_key_value($text); + //var_dump($text.' -> '.$key.' - '.$value); switch ($text) // search special string { @@ -165,6 +165,8 @@ class ICal } } } + + //var_dump($this->cal); return $this->cal; } @@ -236,6 +238,7 @@ class ICal */ function retun_key_value($text) { + /* preg_match("/([^:]+)[:]([\w\W]+)/", $text, $matches); if (empty($matches)) @@ -246,8 +249,8 @@ class ICal { $matches = array_splice($matches, 1, 2); return $matches; - } - + }*/ + return explode(':',$text,2); } /** diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index fbb9400acff..efe47defd92 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -146,9 +146,11 @@ if (empty($conf->global->AGENDA_DISABLE_EXT) && $conf->global->AGENDA_EXT_NB > 0 $source='AGENDA_EXT_SRC'.$i; $name='AGENDA_EXT_NAME'.$i; $color='AGENDA_EXT_COLOR'.$i; + $buggedfile='AGENDA_EXT_BUGGEDFILE'.$i; if (! empty($conf->global->$source) && ! empty($conf->global->$name)) { - $listofextcals[]=array('src'=>$conf->global->$source,'name'=>$conf->global->$name,'color'=>$conf->global->$color); + // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight' + $listofextcals[]=array('src'=>$conf->global->$source,'name'=>$conf->global->$name,'color'=>$conf->global->$color,'buggedfile'=>(isset($conf->global->buggedfile)?$conf->global->buggedfile:0)); } } } @@ -527,9 +529,11 @@ if (count($listofextcals)) $url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics $namecal = $extcal['name']; $colorcal = $extcal['color']; - //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal; + $buggedfile = $extcal['buggedfile']; + //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile; $ical=new ICal(); $ical->parse($url); + // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ... //var_dump($ical->cal); exit; $icalevents=array(); @@ -643,6 +647,8 @@ if (count($listofextcals)) // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray foreach($icalevents as $icalevent) { + //var_dump($icalevent); + //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'
';exit; if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule. @@ -659,12 +665,36 @@ if (count($listofextcals)) $event->fulldayevent=true; $addevent=true; } - elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array) + elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch) { $datestart=$icalevent['DTSTART']; $dateend=$icalevent['DTEND']; $addevent=true; } + elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind) + { + $datestart=$icalevent['DTSTART']['unixtime']; + $dateend=$icalevent['DTEND']['unixtime']; + // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight' + if ($buggedfile === 'uselocalandtznodaylight') // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2 + { + // TODO + } + // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind) + if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer + { + $localtzs = new DateTimeZone(preg_replace('/"/','',$icalevent['DTSTART']['TZID'])); + $localtze = new DateTimeZone(preg_replace('/"/','',$icalevent['DTEND']['TZID'])); + $localdts = new DateTime(dol_print_date($datestart,'dayrfc','gmt'), $localtzs); + $localdte = new DateTime(dol_print_date($dateend,'dayrfc','gmt'), $localtze); + $tmps=-1*$localtzs->getOffset($localdts); + $tmpe=-1*$localtze->getOffset($localdte); + $datestart+=$tmps; + $dateend+=$tmpe; + //var_dump($datestart); + } + $addevent=true; + } if ($addevent) { diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index e66d24e576e..f6c84bdeb4a 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -39,7 +39,7 @@ * @param string $filterd Filter of done by user * @param int $pid Product id * @param int $socid Third party id - * @param array $showextcals Array with list of external calendars, or -1 to show no legend + * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend * @param string $actioncode Preselected value of actioncode for filter on type * @return void */ @@ -136,7 +136,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print '});' . "\n"; print '' . "\n"; print ''; - if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA)) + if (! empty($conf->use_javascript_ajax)) { if (count($showextcals) > 0) { @@ -147,7 +147,10 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print '
'; print '' . "\n"; print ' ' . $val ['name']; @@ -434,9 +437,9 @@ function actions_prepare_head($object) $head[$h][1] = $langs->trans('Info'); $head[$h][2] = 'info'; $h++; - + complete_head_from_modules($conf,$langs,$object,$head,$h,'action'); - + complete_head_from_modules($conf,$langs,$object,$head,$h,'action','remove'); return $head;