Fix alarm handling for recurring events starting in the past

This commit is contained in:
Jörg Lehrke 2010-08-10 21:21:18 +00:00
parent 8728ba5512
commit f90e1da24f

View File

@ -1090,20 +1090,22 @@ ORDER BY cal_user_type, cal_usre_id
$alarm['time'] = $event['cal_start'] - $alarm['offset']; $alarm['time'] = $event['cal_start'] - $alarm['offset'];
} }
//pgoerzen: don't add an alarm in the past $start = (int)time() + $alarm['offset'];
if ($event['recur_type'] != MCAL_RECUR_NONE) if ($alarm['time'] < $start)
{ {
$where = array('cal_id' => $cal_id); //pgoerzen: don't add an alarm in the past
$where[] = 'cal_start >= ' . (int)(time() + $alarm['offset']); if ($event['recur_type'] == MCAL_RECUR_NONE) continue;
if (($next_occurrence = (int) $this->db->select($this->dates_table,'MIN(cal_start)',$where,__LINE__,__FILE__,false,'','calendar')->fetchColumn()) $event['start'] = $event['cal_start'];
&& ($time = $next_occurrence - $alarm['offset']) > $alarm['time']) $event['end'] = $event['cal_end'];
$event['tzid'] = $event['cal_tzid'];
$rrule = calendar_rrule::event2rrule($event, false);
foreach ($rrule as $time)
{ {
$alarm['time'] = $time; if ($start< ($ts = egw_time::to($time,'server'))) break;
} $ts = 0;
elseif (!$next_occurrence)
{
continue;
} }
if (!$ts) continue;
$alarm['time'] = $ts - $alarm['offset'];
} }
$this->save_alarm($cal_id,$alarm); $this->save_alarm($cal_id,$alarm);
} }
@ -1601,6 +1603,7 @@ ORDER BY cal_user_type, cal_usre_id
function save_alarm($cal_id, $alarm, $now=0) function save_alarm($cal_id, $alarm, $now=0)
{ {
//echo "<p>save_alarm(cal_id=$cal_id, alarm="; print_r($alarm); echo ")</p>\n"; //echo "<p>save_alarm(cal_id=$cal_id, alarm="; print_r($alarm); echo ")</p>\n";
//error_log(__METHOD__."(.$cal_id,$now,".array2string($alarm).')');
if (!($id = $alarm['id'])) if (!($id = $alarm['id']))
{ {
$alarms = $this->read_alarms($cal_id); // find a free alarm# $alarms = $this->read_alarms($cal_id); // find a free alarm#