Fix: Import of ical files was broken
Fix: Can import of ical files from BlueMind.
This commit is contained in:
parent
3481884731
commit
43bf9ba890
@ -63,7 +63,7 @@ if ($actionsave)
|
|||||||
// Save agendas
|
// Save agendas
|
||||||
while ($i <= $MAXAGENDA)
|
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'));
|
$src=trim(GETPOST('agenda_ext_src'.$i,'alpha'));
|
||||||
$color=trim(GETPOST('agenda_ext_color'.$i,'alpha'));
|
$color=trim(GETPOST('agenda_ext_color'.$i,'alpha'));
|
||||||
if ($color=='-1') $color='';
|
if ($color=='-1') $color='';
|
||||||
@ -76,7 +76,7 @@ if ($actionsave)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//print 'color='.$color;
|
//print '-name='.$name.'-color='.$color;
|
||||||
$res=dolibarr_set_const($db,'AGENDA_EXT_NAME'.$i,$name,'chaine',0,'',$conf->entity);
|
$res=dolibarr_set_const($db,'AGENDA_EXT_NAME'.$i,$name,'chaine',0,'',$conf->entity);
|
||||||
if (! $res > 0) $error++;
|
if (! $res > 0) $error++;
|
||||||
$res=dolibarr_set_const($db,'AGENDA_EXT_SRC'.$i,$src,'chaine',0,'',$conf->entity);
|
$res=dolibarr_set_const($db,'AGENDA_EXT_SRC'.$i,$src,'chaine',0,'',$conf->entity);
|
||||||
|
|||||||
@ -56,14 +56,13 @@ class ICal
|
|||||||
{
|
{
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
$file_text='';
|
$file_text='';
|
||||||
|
|
||||||
$tmparray=file($file);
|
$tmparray=file($file);
|
||||||
if (is_array($tmparray))
|
if (is_array($tmparray))
|
||||||
{
|
{
|
||||||
$file_text = join("", $tmparray); //load file
|
$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
|
return $file_text; // return all text
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +114,7 @@ class ICal
|
|||||||
{
|
{
|
||||||
// get Key and Value VCALENDAR:Begin -> Key = VCALENDAR, Value = begin
|
// get Key and Value VCALENDAR:Begin -> Key = VCALENDAR, Value = begin
|
||||||
list($key, $value) = $this->retun_key_value($text);
|
list($key, $value) = $this->retun_key_value($text);
|
||||||
|
//var_dump($text.' -> '.$key.' - '.$value);
|
||||||
|
|
||||||
switch ($text) // search special string
|
switch ($text) // search special string
|
||||||
{
|
{
|
||||||
@ -165,6 +165,8 @@ class ICal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var_dump($this->cal);
|
||||||
return $this->cal;
|
return $this->cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +238,7 @@ class ICal
|
|||||||
*/
|
*/
|
||||||
function retun_key_value($text)
|
function retun_key_value($text)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
preg_match("/([^:]+)[:]([\w\W]+)/", $text, $matches);
|
preg_match("/([^:]+)[:]([\w\W]+)/", $text, $matches);
|
||||||
|
|
||||||
if (empty($matches))
|
if (empty($matches))
|
||||||
@ -246,8 +249,8 @@ class ICal
|
|||||||
{
|
{
|
||||||
$matches = array_splice($matches, 1, 2);
|
$matches = array_splice($matches, 1, 2);
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}*/
|
||||||
|
return explode(':',$text,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -146,9 +146,11 @@ if (empty($conf->global->AGENDA_DISABLE_EXT) && $conf->global->AGENDA_EXT_NB > 0
|
|||||||
$source='AGENDA_EXT_SRC'.$i;
|
$source='AGENDA_EXT_SRC'.$i;
|
||||||
$name='AGENDA_EXT_NAME'.$i;
|
$name='AGENDA_EXT_NAME'.$i;
|
||||||
$color='AGENDA_EXT_COLOR'.$i;
|
$color='AGENDA_EXT_COLOR'.$i;
|
||||||
|
$buggedfile='AGENDA_EXT_BUGGEDFILE'.$i;
|
||||||
if (! empty($conf->global->$source) && ! empty($conf->global->$name))
|
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
|
$url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
|
||||||
$namecal = $extcal['name'];
|
$namecal = $extcal['name'];
|
||||||
$colorcal = $extcal['color'];
|
$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=new ICal();
|
||||||
$ical->parse($url);
|
$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, ...
|
// 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;
|
//var_dump($ical->cal); exit;
|
||||||
$icalevents=array();
|
$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
|
// Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
|
||||||
foreach($icalevents as $icalevent)
|
foreach($icalevents as $icalevent)
|
||||||
{
|
{
|
||||||
|
//var_dump($icalevent);
|
||||||
|
|
||||||
//print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
|
//print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
|
||||||
if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
|
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;
|
$event->fulldayevent=true;
|
||||||
$addevent=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'];
|
$datestart=$icalevent['DTSTART'];
|
||||||
$dateend=$icalevent['DTEND'];
|
$dateend=$icalevent['DTEND'];
|
||||||
$addevent=true;
|
$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)
|
if ($addevent)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
* @param string $filterd Filter of done by user
|
* @param string $filterd Filter of done by user
|
||||||
* @param int $pid Product id
|
* @param int $pid Product id
|
||||||
* @param int $socid Third party 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
|
* @param string $actioncode Preselected value of actioncode for filter on type
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -136,7 +136,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh
|
|||||||
print '});' . "\n";
|
print '});' . "\n";
|
||||||
print '</script>' . "\n";
|
print '</script>' . "\n";
|
||||||
print '<table>';
|
print '<table>';
|
||||||
if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA))
|
if (! empty($conf->use_javascript_ajax))
|
||||||
{
|
{
|
||||||
if (count($showextcals) > 0)
|
if (count($showextcals) > 0)
|
||||||
{
|
{
|
||||||
@ -147,7 +147,10 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh
|
|||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
print '<script type="text/javascript">' . "\n";
|
print '<script type="text/javascript">' . "\n";
|
||||||
print 'jQuery(document).ready(function () {' . "\n";
|
print 'jQuery(document).ready(function () {' . "\n";
|
||||||
print 'jQuery("#check_' . $htmlname . '").click(function() { jQuery(".family_' . $htmlname . '").toggle(); });' . "\n";
|
print ' jQuery("#check_' . $htmlname . '").click(function() {';
|
||||||
|
print ' /* alert("'.$htmlname.'"); */';
|
||||||
|
print ' jQuery(".family_' . $htmlname . '").toggle();';
|
||||||
|
print ' });' . "\n";
|
||||||
print '});' . "\n";
|
print '});' . "\n";
|
||||||
print '</script>' . "\n";
|
print '</script>' . "\n";
|
||||||
print '<input type="checkbox" id="check_' . $htmlname . '" name="check_' . $htmlname . '" checked="true"> ' . $val ['name'];
|
print '<input type="checkbox" id="check_' . $htmlname . '" name="check_' . $htmlname . '" checked="true"> ' . $val ['name'];
|
||||||
@ -434,9 +437,9 @@ function actions_prepare_head($object)
|
|||||||
$head[$h][1] = $langs->trans('Info');
|
$head[$h][1] = $langs->trans('Info');
|
||||||
$head[$h][2] = 'info';
|
$head[$h][2] = 'info';
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'action');
|
complete_head_from_modules($conf,$langs,$object,$head,$h,'action');
|
||||||
|
|
||||||
complete_head_from_modules($conf,$langs,$object,$head,$h,'action','remove');
|
complete_head_from_modules($conf,$langs,$object,$head,$h,'action','remove');
|
||||||
|
|
||||||
return $head;
|
return $head;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user