diff --git a/calendar/inc/class.calendar_ical.inc.php b/calendar/inc/class.calendar_ical.inc.php index 73f7c96172..cd98dcecf9 100644 --- a/calendar/inc/class.calendar_ical.inc.php +++ b/calendar/inc/class.calendar_ical.inc.php @@ -1443,6 +1443,10 @@ class calendar_ical extends calendar_boupdate // if no edit rights, allow participants to set alarms directly (like status) if ($event_info['stored_event'] && !$event_info['acl_edit']) { + if ($alarm['time'] < time() && !calendar_so::shift_alarm($event, $alarm)) + { + continue; //pgoerzen: don't add an alarm in the past + } $this->save_alarm($event_info['stored_event']['id'], $alarm); } diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index fccd566ea6..b7f3efd0a8 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1263,22 +1263,9 @@ ORDER BY cal_user_type, cal_usre_id $alarm['time'] = $event['cal_start'] - $alarm['offset']; } - if ($alarm['time'] < time()) + if ($alarm['time'] < time() && !self::shift_alarm($event, $alarm)) { - //pgoerzen: don't add an alarm in the past - if ($event['recur_type'] == MCAL_RECUR_NONE) continue; - $start = (int)time() + $alarm['offset']; - $event['start'] = $event['cal_start']; - $event['end'] = $event['cal_end']; - $event['tzid'] = $event['cal_tzid']; - $rrule = calendar_rrule::event2rrule($event, false); - foreach ($rrule as $time) - { - if ($start < ($ts = egw_time::to($time,'server'))) break; - $ts = 0; - } - if (!$ts) continue; - $alarm['time'] = $ts - $alarm['offset']; + continue; // pgoerzen: don't add alarm in the past } $this->save_alarm($cal_id,$alarm); } @@ -1290,6 +1277,33 @@ ORDER BY cal_user_type, cal_usre_id return $cal_id; } + /** + * Shift alarm on recurring events to next future recurrence + * + * @param array $event event with optional 'cal_' prefix in keys + * @param array &$alarm + * @return boolean true if alarm could be shifted, false if not + */ + public static function shift_alarm(array $event, array &$alarm) + { + if ($event['recur_type'] == MCAL_RECUR_NONE) + { + return false; + } + $start = (int)time() + $alarm['offset']; + egw_db::strip_array_keys($event, 'cal_'); + $rrule = calendar_rrule::event2rrule($event, false); + foreach ($rrule as $time) + { + if ($start < ($ts = egw_time::to($time,'server'))) + { + $alarm['time'] = $ts - $alarm['offset']; + return true; + } + } + return false; + } + /** * moves an event to an other start- and end-time taken into account the evtl. recurrences of the event(!) *