Allow alarms for recurring events starting in the past

This commit is contained in:
Jörg Lehrke 2010-06-08 16:36:55 +00:00
parent 0c60f43c61
commit f6eb00e6a1
2 changed files with 41 additions and 13 deletions

View File

@ -1066,13 +1066,12 @@ ORDER BY cal_user_type, cal_usre_id
} }
} }
} }
// updating or saving the alarms, new alarms have a temporary numeric id! // updating or saving the alarms; new alarms have a temporary numeric id!
// ToDo: recuring events !!!
if (is_array($event['alarm'])) if (is_array($event['alarm']))
{ {
foreach ($event['alarm'] as $id => $alarm) foreach ($event['alarm'] as $id => $alarm)
{ {
if (is_numeric($id)) unset($alarm['id']); // unset the temporary id, to add the alarm if (is_numeric($id)) unset($alarm['id']); // unset the temporary id to add the alarm
if(!isset($alarm['offset'])) if(!isset($alarm['offset']))
{ {
@ -1083,12 +1082,18 @@ 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 if it is before the current date. //pgoerzen: don't add an alarm in the past
/*if ($event['recur_type'] && ($tmp_event = $this->read($eventID, time() + $alarm['offset']))) if ($event['recur_type'] != MCAL_RECUR_NONE)
{ {
$alarm['time'] = $tmp_event['cal_start'] - $alarm['offset']; $where = array('cal_id' => $cal_id);
} */ $where[] = 'cal_start >= ' . (int)(time() + $alarm['offset']);
if (($next_occurrence = (int) $this->db->select($this->dates_table,'MIN(cal_start)',$where,__LINE__,__FILE__,false,'','calendar')->fetchColumn())
&& ($time = $next_occurrence - $alarm['offset']) > $alarm['time'])
{
$alarm['time'] = $time;
}
else continue;
}
$this->save_alarm($cal_id,$alarm); $this->save_alarm($cal_id,$alarm);
} }
} }

View File

@ -216,6 +216,9 @@ class calendar_uiforms extends calendar_ui
{ {
$msg = lang('Alarm deleted'); $msg = lang('Alarm deleted');
unset($content['alarm'][$id]); unset($content['alarm'][$id]);
$js = 'opener.location.href=\''.addslashes(egw::link($referer,array(
'msg' => $msg,
))).'\';';
} }
else else
{ {
@ -393,7 +396,7 @@ class calendar_uiforms extends calendar_ui
$msg = lang('Status changed'); $msg = lang('Status changed');
} }
} }
if (!$preserv['no_popup']) if (!$content['no_popup'])
{ {
$js = 'opener.location.href=\''.addslashes(egw::link($referer,array( $js = 'opener.location.href=\''.addslashes(egw::link($referer,array(
'msg' => $msg, 'msg' => $msg,
@ -424,7 +427,9 @@ class calendar_uiforms extends calendar_ui
'template' => $content['template'], 'template' => $content['template'],
); );
$noerror=true; $noerror=true;
//error_log(__METHOD__.$button.'#'.array2string($content['edit_single']).'#'); //error_log(__METHOD__.$button.'#'.array2string($content['edit_single']).'#');
switch((string)$button) switch((string)$button)
{ {
case 'exception': // create an exception in a recuring event case 'exception': // create an exception in a recuring event
@ -605,7 +610,7 @@ class calendar_uiforms extends calendar_ui
case 'delete_exceptions': // series and user selected to delete the exceptions too case 'delete_exceptions': // series and user selected to delete the exceptions too
if ($this->bo->delete($event['id'],(int)$content['edit_single'])) if ($this->bo->delete($event['id'],(int)$content['edit_single']))
{ {
if ($content['reference'] == 0 && !$content['edit_single'] && $button != 'delete') if ($event['recur_type'] != MCAL_RECUR_NONE && $content['reference'] == 0 && !$content['edit_single'])
{ {
$msg = lang('Series deleted'); $msg = lang('Series deleted');
$delete_exceptions = $button == 'delete_exceptions'; $delete_exceptions = $button == 'delete_exceptions';
@ -648,12 +653,20 @@ class calendar_uiforms extends calendar_ui
break; break;
case 'add_alarm': case 'add_alarm':
$time = ($content['actual_date'] ? $content['actual_date'] : $content['start']);
if ($event['recur_type'] != MCAL_RECUR_NONE &&
($next_occurrence = $this->bo->read($event['id'], $this->bo->now_su, true)) &&
$time < $next_occurrence['start'])
{
$time = $next_occurrence['start'];
}
if ($this->bo->check_perms(EGW_ACL_EDIT,!$content['new_alarm']['owner'] ? $event : 0,$content['new_alarm']['owner'])) if ($this->bo->check_perms(EGW_ACL_EDIT,!$content['new_alarm']['owner'] ? $event : 0,$content['new_alarm']['owner']))
{ {
$offset = DAY_s * $content['new_alarm']['days'] + HOUR_s * $content['new_alarm']['hours'] + 60 * $content['new_alarm']['mins']; $offset = DAY_s * $content['new_alarm']['days'] + HOUR_s * $content['new_alarm']['hours'] + 60 * $content['new_alarm']['mins'];
$alarm = array( $alarm = array(
'offset' => $offset, 'offset' => $offset,
'time' => $content['start'] - $offset, //'time' => $content['start'] - $offset,
'time' => $time - $offset,
'all' => !$content['new_alarm']['owner'], 'all' => !$content['new_alarm']['owner'],
'owner' => $content['new_alarm']['owner'] ? $content['new_alarm']['owner'] : $this->user, 'owner' => $content['new_alarm']['owner'] ? $content['new_alarm']['owner'] : $this->user,
); );
@ -669,6 +682,9 @@ class calendar_uiforms extends calendar_ui
$event['alarm'][$alarm_id] = $alarm; $event['alarm'][$alarm_id] = $alarm;
$msg = lang('Alarm added'); $msg = lang('Alarm added');
$js = 'opener.location.href=\''.addslashes(egw::link($referer,array(
'msg' => $msg,
))).'\';';
} }
else else
{ {
@ -875,7 +891,7 @@ class calendar_uiforms extends calendar_ui
else else
{ {
$preserv['actual_date'] = $event['start']; // remember the date clicked $preserv['actual_date'] = $event['start']; // remember the date clicked
if ($event['recur_type'] != MCAL_RECUR_NONE && $_GET['exception']) if ($event['recur_type'] != MCAL_RECUR_NONE)
{ {
if (empty($event['whole_day'])) if (empty($event['whole_day']))
{ {
@ -889,7 +905,14 @@ class calendar_uiforms extends calendar_ui
} }
$event = $this->bo->read($cal_id, $date, true); $event = $this->bo->read($cal_id, $date, true);
$preserv['actual_date'] = $event['start']; // remember the date clicked $preserv['actual_date'] = $event['start']; // remember the date clicked
$msg = $this->_create_exception($event,$preserv); if ($_GET['exception'])
{
$msg = $this->_create_exception($event,$preserv);
}
else
{
$event = $this->bo->read($cal_id, null, true);
}
} }
} }
if ($event['recur_type'] != MCAL_RECUR_NONE) if ($event['recur_type'] != MCAL_RECUR_NONE)