From af7b44c65a81188d1b86f5642c3874f9cd64b478 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 23 May 2018 10:58:19 -0600 Subject: [PATCH] * Calendar - reset the default alarm if you switch an existing whole day event to duration --- calendar/inc/class.calendar_uiforms.inc.php | 39 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index 7de85d9984..61e7fca5e2 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -209,12 +209,25 @@ class calendar_uiforms extends calendar_ui $cat = (int)$cat; } } + $duration = isset($_GET['duration']) ? (int)$_GET['duration'] : (int) $this->bo->cal_prefs['defaultlength']*60; + if(isset($_GET['end'])) + { + $end = Api\DateTime::to($_GET['end'], 'ts'); + $duration = $end - $start; + } + else + { + $end = $start + $duration; + } + $whole_day = ($duration + 60 == DAY_s); + $alarms = array(); + $alarm_pref = $whole_day ? 'default-alarm-wholeday' : 'default-alarm'; // if default alarm set in prefs --> add it // we assume here that user does NOT have a whole-day but no regular default-alarm, no whole-day! - if ((string)$this->cal_prefs['default-alarm'] !== '') + if ((string)$this->cal_prefs[$alarm_pref] !== '') { - $offset = 60 * $this->cal_prefs['default-alarm']; + $offset = 60 * $this->cal_prefs[$alarm_pref]; $alarms[1] = array( 'default' => 1, 'offset' => $offset , @@ -224,8 +237,7 @@ class calendar_uiforms extends calendar_ui 'id' => 1, ); } - $duration = isset($_GET['duration']) ? (int)$_GET['duration'] : (int) $this->bo->cal_prefs['defaultlength']*60; - $end = isset($_GET['end']) ? Api\DateTime::to($_GET['end'], 'ts') : $start + $duration; + return array( 'participant_types' => $participant_types, 'participants' => $participants, @@ -342,6 +354,25 @@ class calendar_uiforms extends calendar_ui $content['start'] = $this->bo->date2ts($content['start']); } } + else if ($content['cal_id'] && count($content['alarm']) > 0 && current($content['alarm'])['default'] && + // Existing event, check for change from/to whole day + ($old = $this->bo->read($content['cal_id'])) && $old['whole_day'] !== $content['whole_day'] && + ($def_alarm = $this->cal_prefs['default-alarm'.($content['whole_day'] ? '-wholeday' : '')]) + ) + { + // Reset default alarm + $old_default = array_shift($content['alarm']); + $this->bo->delete_alarm($old_default['id']); + $offset = 60 * $def_alarm; + array_unshift($content['alarm'], array( + 'default' => 1, + 'offset' => $offset , + 'time' => $content['start'] - $offset, + 'all' => false, + 'owner' => $owner, + 'id' => 1 + )); + } $event = $content; unset($event['new_alarm']);