mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 08:53:37 +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
2b3211b13d
commit
996d1e4ed7
@ -578,7 +578,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)
|
||||||
{
|
{
|
||||||
@ -592,17 +592,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;
|
||||||
@ -612,19 +630,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();
|
||||||
@ -634,7 +649,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');
|
||||||
@ -651,15 +666,13 @@ class calendar_uiforms extends calendar_ui
|
|||||||
$event = $orig_event;
|
$event = $orig_event;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unset($orig_event);
|
|
||||||
unset($event['uid']);
|
|
||||||
unset($event['id']);
|
|
||||||
$event['alarm'] = array();
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,7 +707,6 @@ class calendar_uiforms extends calendar_ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$edit_series_confirmed = false;
|
|
||||||
$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']);
|
$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']);
|
||||||
unset($event['ignore']);
|
unset($event['ignore']);
|
||||||
}
|
}
|
||||||
@ -720,25 +732,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)
|
||||||
|
{
|
||||||
|
if (($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su+$alarm['offset'], true)))
|
||||||
{
|
{
|
||||||
$alarm['time'] = $next_occurrence['start'] - $alarm['offset'];
|
$alarm['time'] = $next_occurrence['start'] - $alarm['offset'];
|
||||||
}
|
}
|
||||||
$this->bo->save_alarm($event['id'], $alarm);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 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(
|
||||||
@ -749,7 +776,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'];
|
||||||
@ -764,7 +791,7 @@ class calendar_uiforms extends calendar_ui
|
|||||||
$alarms[] = $alarm;
|
$alarms[] = $alarm;
|
||||||
}
|
}
|
||||||
$event['alarm'] = $alarms;
|
$event['alarm'] = $alarms;
|
||||||
$this->bo->update($exception, true, true, true,true,null,$content['no_notifications']);
|
$this->bo->update($exception, true, true, true, true, $msg=null, $content['no_notifications']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1440,11 +1467,6 @@ function replace_eTemplate_onsubmit()
|
|||||||
$readonlys['recur_exception'] = !count($content['recur_exception']); // otherwise we get a delete button
|
$readonlys['recur_exception'] = !count($content['recur_exception']); // otherwise we get a delete button
|
||||||
$onclick =& $etpl->get_cell_attribute('button[delete]','onclick');
|
$onclick =& $etpl->get_cell_attribute('button[delete]','onclick');
|
||||||
$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