From aef984c7fa8108980c3b83c14a020657b7d8c630 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 29 Aug 2013 14:39:01 +0000 Subject: [PATCH] * Calendar: automatic cancel alarms from removed or rejected participants --- calendar/inc/class.calendar_boupdate.inc.php | 37 +++++++++++++++++++- calendar/inc/class.calendar_so.inc.php | 15 ++++---- calendar/inc/class.calendar_uiforms.inc.php | 11 ++++++ 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index e8c54b17f9..fe6d15b53a 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1067,6 +1067,18 @@ class calendar_boupdate extends calendar_bo { // recalculate alarms to also cope with moved events (beside server time adjustment) $event['alarm'][$id]['time'] = $event['start'] - $alarm['offset']; + + // remove alarms belonging to not longer existing or rejected participants + if ($alarm['owner'] && isset($event['participants'])) + { + $status = $event['participants'][$alarm['owner']]; + if (!isset($status) || calendar_so::split_status($status) === 'R') + { + unset($event['alarm'][$id]); + $this->so->delete_alarm($id); + error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm)); + } + } } } // update all existing alarm times, in case alarm got moved and alarms are not include in $event @@ -1077,7 +1089,19 @@ class calendar_boupdate extends calendar_bo if (!isset($event['alarm'][$id])) { $alarm['time'] = $event['start'] - $alarm['offset']; - $this->so->save_alarm($event['id'],$alarm, $this->now); + // remove (not store) alarms belonging to not longer existing or rejected participants + $status = isset($event['participants']) ? $event['participants'][$alarm['owner']] : + $old_event['participants'][$alarm['owner']]; + if (!$alarm['owner'] || isset($status) && calendar_so::split_status($status) !== 'R') + { + $this->so->save_alarm($event['id'], $alarm, $this->now); + error_log(__LINE__.': '.__METHOD__."() so->save_alarm($event[id], ".array2string($alarm).", $this->now)"); + } + else + { + $this->so->delete_alarm($id); + error_log(__LINE__.': '.__METHOD__."(".array2string($event).") deleting alarm=".array2string($alarm).", $status=".array2string($alarm)); + } } } } @@ -1303,6 +1327,17 @@ class calendar_boupdate extends calendar_bo is_numeric($uid)?$uid:substr($uid,1),$status, $recur_date?$this->date2ts($recur_date,true):0,$role))) { + if ($status == 'R') // remove alarms belonging to rejected participants + { + foreach(isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm) + { + if ((string)$alarm['owner'] === (string)$uid) + { + $this->so->delete_alarm($id); + error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm)); + } + } + } if ($updateTS) { $GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now); diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index 1ac46c0971..a5fa63e558 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1020,7 +1020,7 @@ ORDER BY cal_user_type, cal_usre_id $old_min = $old_duration = 0; - //error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag)"); + //error_log(__METHOD__.'('.array2string($event).",$set_recurrences,$change_since,$etag) ".function_backtrace()); $cal_id = (int) $event['id']; unset($event['id']); @@ -1435,10 +1435,11 @@ ORDER BY cal_user_type, cal_usre_id * splits the combined status, quantity and role * * @param string &$status I: combined value, O: status letter: U, T, A, R - * @param int &$quantity only O: quantity - * @param string &$role only O: role + * @param int &$quantity=null only O: quantity + * @param string &$role=null only O: role + * @return string status U, T, A or R, same as $status parameter on return */ - static function split_status(&$status,&$quantity,&$role) + static function split_status(&$status,&$quantity=null,&$role=null) { $quantity = 1; $role = 'REQ-PARTICIPANT'; @@ -1453,6 +1454,7 @@ ORDER BY cal_user_type, cal_usre_id { $status = 'U'; } + return $status; } /** @@ -1888,8 +1890,7 @@ ORDER BY cal_user_type, cal_usre_id */ function save_alarm($cal_id, $alarm, $update_modified=true) { - //echo "

save_alarm(cal_id=$cal_id, alarm="; print_r($alarm); echo ")

\n"; - //error_log(__METHOD__."(.$cal_id,$now,".array2string($alarm).')'); + //error_log(__METHOD__."($cal_id, ".array2string($alarm).', '.array2string($update_modified).') '.function_backtrace()); if (!($id = $alarm['id'])) { $alarms = $this->read_alarms($cal_id); // find a free alarm# @@ -1932,6 +1933,7 @@ ORDER BY cal_user_type, cal_usre_id */ private function delete_alarms($cal_id) { + //error_log(__METHOD__."($cal_id) ".function_backtrace()); $alarms = $this->read_alarms($cal_id); foreach($alarms as $id => $alarm) @@ -1952,6 +1954,7 @@ ORDER BY cal_user_type, cal_usre_id */ function delete_alarm($id) { + //error_log(__METHOD__."('$id') ".function_backtrace()); // update the modification information of the related event list(,$cal_id) = explode(':',$id); if ($cal_id) diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index ae3ef43793..5b13c69ca8 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -405,6 +405,17 @@ class calendar_uiforms extends calendar_ui { $msg = lang('Status changed'); } + if ($status == 'R' && $event['alarm']) + { + // remove from bo->set_status deleted alarms of rejected users from UI too + foreach($event['alarm'] as $alarm_id => $alarm) + { + if ((string)$alarm['owner'] === (string)$uid) + { + unset($event['alarm'][$alarm_id]); + } + } + } } if (!$preserv['no_popup']) {