mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 08:23:12 +01:00
* Calendar: fixed many issues when moving or modifiny (parts of a) recurring event (alarms, recurrance type, time)
This commit is contained in:
parent
88be4bea46
commit
2b0dc8e68f
@ -576,7 +576,7 @@ class calendar_uiforms extends calendar_ui
|
|||||||
}
|
}
|
||||||
else // we edited a non-reccuring event or the whole series
|
else // we edited a non-reccuring event or the whole series
|
||||||
{
|
{
|
||||||
if ($old_event = $this->bo->read($event['id']))
|
if (($old_event = $this->bo->read($event['id'])))
|
||||||
{
|
{
|
||||||
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
||||||
{
|
{
|
||||||
@ -590,17 +590,35 @@ class calendar_uiforms extends calendar_ui
|
|||||||
$noerror = false;
|
$noerror = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($edit_series_confirmed)
|
// splitting of series confirmed or first event clicked (no confirmation necessary)
|
||||||
|
if ($edit_series_confirmed || $old_event['start'] == $event['actual_date'])
|
||||||
{
|
{
|
||||||
|
$edit_series_confirmed = true;
|
||||||
$orig_event = $event;
|
$orig_event = $event;
|
||||||
|
|
||||||
|
// calculate offset against old series start or clicked recurrance,
|
||||||
|
// depending on which is smaller
|
||||||
$offset = $event['start'] - $old_event['start'];
|
$offset = $event['start'] - $old_event['start'];
|
||||||
//$event['start'] = $next_occurrence['start'] + $offset;
|
if (abs($offset) > abs($off2 = $event['start'] - $event['actual_date']))
|
||||||
//$event['end'] = $next_occurrence['end'] + $offset;
|
{
|
||||||
|
$offset = $off2;
|
||||||
|
}
|
||||||
|
// base start-date of new series on actual / clicked date
|
||||||
|
$actual_date = $event['actual_date'];
|
||||||
|
$event['start'] = $actual_date + $offset;
|
||||||
|
if ($content['duration'])
|
||||||
|
{
|
||||||
|
$event['end'] = $event['start'] + $content['duration'];
|
||||||
|
}
|
||||||
|
elseif($event['end'] < $event['start'])
|
||||||
|
{
|
||||||
|
$event['end'] = $event['start'] + $event['end'] - $actual_date;
|
||||||
|
}
|
||||||
|
//echo "<p>".__LINE__.": event[start]=$event[start]=".egw_time::to($event['start']).", duration=$content[duration], event[end]=$event[end]=".egw_time::to($event['end']).", offset=$offset</p>\n";
|
||||||
$event['participants'] = $old_event['participants'];
|
$event['participants'] = $old_event['participants'];
|
||||||
foreach ($old_event['recur_exception'] as $key => $exdate)
|
foreach ($old_event['recur_exception'] as $key => $exdate)
|
||||||
{
|
{
|
||||||
if ($exdate > $this->bo->now_su)
|
if ($exdate > $actual_date)
|
||||||
{
|
{
|
||||||
unset($old_event['recur_exception'][$key]);
|
unset($old_event['recur_exception'][$key]);
|
||||||
$event['recur_exception'][$key] += $offset;
|
$event['recur_exception'][$key] += $offset;
|
||||||
@ -610,19 +628,16 @@ class calendar_uiforms extends calendar_ui
|
|||||||
unset($event['recur_exception'][$key]);
|
unset($event['recur_exception'][$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($old_event['start'] > $this->bo->now_su)
|
$old_alarms = $old_event['alarm'];
|
||||||
{
|
if ($old_event['start'] < $actual_date)
|
||||||
// delete the original event
|
|
||||||
if (!$this->bo->delete($old_event['id']))
|
|
||||||
{
|
|
||||||
$msg = lang("Error: Can't delete original series!");
|
|
||||||
$noerror = false;
|
|
||||||
$event = $orig_event;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
unset($orig_event);
|
||||||
|
// copy event by unsetting the id(s)
|
||||||
|
unset($event['id']);
|
||||||
|
unset($event['uid']);
|
||||||
|
unset($event['caldav_name']);
|
||||||
|
|
||||||
|
// set enddate of existing event
|
||||||
$rriter = calendar_rrule::event2rrule($old_event, true);
|
$rriter = calendar_rrule::event2rrule($old_event, true);
|
||||||
$rriter->rewind();
|
$rriter->rewind();
|
||||||
$last = $rriter->current();
|
$last = $rriter->current();
|
||||||
@ -632,7 +647,7 @@ class calendar_uiforms extends calendar_ui
|
|||||||
$occurrence = $rriter->current();
|
$occurrence = $rriter->current();
|
||||||
}
|
}
|
||||||
while ($rriter->valid() &&
|
while ($rriter->valid() &&
|
||||||
egw_time::to($occurrence, 'ts') < $this->bo->now_su &&
|
egw_time::to($occurrence, 'ts') < $actual_date &&
|
||||||
($last = $occurrence));
|
($last = $occurrence));
|
||||||
$last->setTime(0, 0, 0);
|
$last->setTime(0, 0, 0);
|
||||||
$old_event['recur_enddate'] = egw_time::to($last, 'ts');
|
$old_event['recur_enddate'] = egw_time::to($last, 'ts');
|
||||||
@ -649,15 +664,13 @@ class calendar_uiforms extends calendar_ui
|
|||||||
$event = $orig_event;
|
$event = $orig_event;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$event['alarm'] = array();
|
||||||
}
|
}
|
||||||
unset($orig_event);
|
|
||||||
unset($event['uid']);
|
|
||||||
unset($event['id']);
|
|
||||||
$event['alarm'] = array();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$event['button_was'] = $button; // remember for confirm
|
$event['button_was'] = $button; // remember for confirm
|
||||||
|
$preserv['duration'] = $content['duration'];
|
||||||
return $this->confirm_edit_series($event,$preserv);
|
return $this->confirm_edit_series($event,$preserv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -692,7 +705,6 @@ class calendar_uiforms extends calendar_ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$edit_series_confirmed = false;
|
|
||||||
$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages);
|
$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages);
|
||||||
unset($event['ignore']);
|
unset($event['ignore']);
|
||||||
}
|
}
|
||||||
@ -718,25 +730,40 @@ class calendar_uiforms extends calendar_ui
|
|||||||
}
|
}
|
||||||
elseif ($conflicts > 0)
|
elseif ($conflicts > 0)
|
||||||
{
|
{
|
||||||
if ($edit_series_confirmed &&
|
if ($edit_series_confirmed) // series moved by splitting in two
|
||||||
($event = $this->bo->read($conflicts)))
|
|
||||||
{
|
{
|
||||||
// set the alarms again
|
foreach ($old_alarms as $alarm)
|
||||||
foreach ($old_event['alarm'] as $alarm)
|
|
||||||
{
|
{
|
||||||
if ($alarm['time'] > $this->bo->now_su)
|
// check if alarms still needed in old event, if not delete it
|
||||||
|
$event_time = $alarm['time'] + $alarm['offset'];
|
||||||
|
if ($event_time >= $actual_date)
|
||||||
{
|
{
|
||||||
// delete future alarm of the old series
|
|
||||||
$this->bo->delete_alarm($alarm['id']);
|
$this->bo->delete_alarm($alarm['id']);
|
||||||
}
|
}
|
||||||
$alarm['time'] += $offset;
|
$alarm['time'] += $offset;
|
||||||
unset($alarm['id']);
|
unset($alarm['id']);
|
||||||
if (($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su + $alarm['offset'], true)) &&
|
// if alarm would be in the past (eg. event moved back) --> move to next possible recurrence
|
||||||
$alarm['time'] < $next_occurrence['start'])
|
if ($alarm['time'] < $this->bo->now_su)
|
||||||
{
|
{
|
||||||
$alarm['time'] = $next_occurrence['start'] - $alarm['offset'];
|
if (($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su+$alarm['offset'], true)))
|
||||||
|
{
|
||||||
|
$alarm['time'] = $next_occurrence['start'] - $alarm['offset'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$alarm = false; // no (further) recurence found --> ignore alarm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// alarm is currently on a previous recurrence --> set for first recurrence of new series
|
||||||
|
elseif ($event_time < $event['start'])
|
||||||
|
{
|
||||||
|
$alarm['time'] = $event['start'] - $alarm['offset'];
|
||||||
|
}
|
||||||
|
if ($alarm)
|
||||||
|
{
|
||||||
|
$alarm['id'] = $this->bo->save_alarm($event['id'], $alarm);
|
||||||
|
$event['alarm'][$alarm['id']] = $alarm;
|
||||||
}
|
}
|
||||||
$this->bo->save_alarm($event['id'], $alarm);
|
|
||||||
}
|
}
|
||||||
// attach all future exceptions to the new series
|
// attach all future exceptions to the new series
|
||||||
$events =& $this->bo->search(array(
|
$events =& $this->bo->search(array(
|
||||||
@ -747,7 +774,7 @@ class calendar_uiforms extends calendar_ui
|
|||||||
));
|
));
|
||||||
foreach ((array)$events as $exception)
|
foreach ((array)$events as $exception)
|
||||||
{
|
{
|
||||||
if ($exception['recurrence'] > $this->bo->now_su)
|
if ($exception['recurrence'] > $actual_date)
|
||||||
{
|
{
|
||||||
$exception['recurrence'] += $offset;
|
$exception['recurrence'] += $offset;
|
||||||
$exception['reference'] = $event['id'];
|
$exception['reference'] = $event['id'];
|
||||||
@ -1412,11 +1439,6 @@ function replace_eTemplate_onsubmit()
|
|||||||
$onclick =& $etpl->get_cell_attribute('button[delete]','onclick');
|
$onclick =& $etpl->get_cell_attribute('button[delete]','onclick');
|
||||||
// $onclick = 'delete_series('.$event['id'].');';
|
// $onclick = 'delete_series('.$event['id'].');';
|
||||||
$onclick = str_replace('Delete this event','Delete this series of recuring events',$onclick);
|
$onclick = str_replace('Delete this event','Delete this series of recuring events',$onclick);
|
||||||
|
|
||||||
// some fundamental values of an existing series should not be changed by the user
|
|
||||||
//$readonlys['start'] = $readonlys['whole_day'] = true;
|
|
||||||
$readonlys['recur_type'] = $readonlys['recur_data'] = true;
|
|
||||||
$readonlys['recur_interval'] = $readonlys['tzid'] = true;
|
|
||||||
}
|
}
|
||||||
elseif ($event['reference'] != 0)
|
elseif ($event['reference'] != 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user