From 3fa98b8209c1a643f7dd3cf0c4dfb7fa71ea77b4 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 29 Aug 2013 14:31:45 +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 ++++++ calendar/lang/egw_de.lang | 1 + calendar/lang/egw_en.lang | 1 + 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index b56e8a2b3f..22fcb94fc2 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1134,6 +1134,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 @@ -1144,7 +1156,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)); + } } } } @@ -1388,6 +1412,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 e9ec9352ec..93012ef3a3 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1029,7 +1029,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']); @@ -1466,10 +1466,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'; @@ -1484,6 +1485,7 @@ ORDER BY cal_user_type, cal_usre_id { $status = 'U'; } + return $status; } /** @@ -1913,8 +1915,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# @@ -1957,6 +1958,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) @@ -1977,6 +1979,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 570593ea69..d275583a8d 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -425,6 +425,17 @@ class calendar_uiforms extends calendar_ui $js = "opener.location.search += (opener.location.search?'&msg=':'?msg=')+'". addslashes($msg)."';"; } + 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 ($uid && $status != 'G') diff --git a/calendar/lang/egw_de.lang b/calendar/lang/egw_de.lang index cdcad57a7b..2af43996ce 100644 --- a/calendar/lang/egw_de.lang +++ b/calendar/lang/egw_de.lang @@ -5,6 +5,7 @@ %1 records imported calendar de %1 Datensätze importiert %1 records read (not yet imported, you may go back and uncheck test import) calendar de %1 Datensätze gelesen (noch nicht importiert, Sie können zurück gehen und Test Import ausschalten) %1 weeks calendar de %1 Wochen +%s the event calendar de %s dem Termin (%1 events in %2 seconds) calendar de (%1 Termine in %2 Sekunden , exceptions preserved calendar de und Ausnahmen erhalten , stati of participants reset calendar de , Status der Teilnehmer zurückgesetzt diff --git a/calendar/lang/egw_en.lang b/calendar/lang/egw_en.lang index f62c4a52d5..c17556fe83 100644 --- a/calendar/lang/egw_en.lang +++ b/calendar/lang/egw_en.lang @@ -5,6 +5,7 @@ %1 records imported calendar en %1 records imported. %1 records read (not yet imported, you may go back and uncheck test import) calendar en %1 records read. Not yet imported, go back and uncheck Test import. %1 weeks calendar en %1 weeks +%s the event calendar en %s the event (%1 events in %2 seconds) calendar en (%1 events in %2 seconds) , exceptions preserved calendar en , exceptions preserved , stati of participants reset calendar en , status of participants reset