From ad778ec971811a1da750a31e1c2f0f89d806cb66 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 24 Sep 2013 16:23:45 -0400 Subject: [PATCH] CC-5323: User's Timezone Can Improperly Edit Show --- .../application/controllers/ScheduleController.php | 10 +++++----- .../application/services/ShowFormService.php | 9 ++++----- airtime_mvc/application/services/ShowService.php | 2 +- airtime_mvc/public/js/airtime/schedule/add-show.js | 13 +++++++++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 0fc7a1f3a..87f142d4f 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -649,16 +649,16 @@ class ScheduleController extends Zend_Controller_Action */ public function localizeStartEndTimeAction() { - $service_showForm = new Application_Service_ShowFormService( - $this->_getParam("showId")); - $timezone = $this->_getParam('timezone'); + $service_showForm = new Application_Service_ShowFormService(); + $newTimezone = $this->_getParam('newTimezone'); + $oldTimezone = $this->_getParam('oldTimezone'); $localTime = array(); $localTime["start"] = $service_showForm->localizeDateTime( - $this->_getParam('startDate'), $this->_getParam('startTime'), $timezone); + $this->_getParam('startDate'), $this->_getParam('startTime'), $newTimezone, $oldTimezone); $localTime["end"] = $service_showForm->localizeDateTime( - $this->_getParam('endDate'), $this->_getParam('endTime'), $timezone); + $this->_getParam('endDate'), $this->_getParam('endTime'), $newTimezone, $oldTimezone); $this->_helper->json->sendJson($localTime); } diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 5c7c4c0c1..4e8d49f44 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -495,16 +495,15 @@ class Application_Service_ShowFormService * @param $time String * @param $timezone String */ - public function localizeDateTime($date, $time, $timezone) + public function localizeDateTime($date, $time, $newTimezone, $oldTimezone) { - $dt = new DateTime($date." ".$time, new DateTimeZone( - $this->ccShow->getFirstCcShowDay()->getDbTimezone())); + $dt = new DateTime($date." ".$time, new DateTimeZone($oldTimezone)); - $dt->setTimeZone(new DateTimeZone($timezone)); + $dt->setTimeZone(new DateTimeZone($newTimezone)); return array( "date" => $dt->format("Y-m-d"), - "time" => $dt->format("h:i") + "time" => $dt->format("H:i") ); } } \ No newline at end of file diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 6bb492f1a..6576d4f7e 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -1330,7 +1330,7 @@ SQL; $showDay->setDbFirstShow($startDateTime->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTime->format("H:i:s")); - $showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); + $showDay->setDbTimezone($showData['add_show_timezone']); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbRepeatType($this->repeatType); $showDay->setDbShowId($showId); diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index d44e6f563..088601e8e 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -227,13 +227,18 @@ function setAddShowEvents() { } }); + // in case user is creating a new show, there will be + // no show_id so we have to store the default timezone + // to be able to do the conversion when the timezone + // setting changes + var currentTimezone = form.find("#add_show_timezone").val(); + form.find("#add_show_timezone").change(function(){ var startDateField = form.find("#add_show_start_date"), startTimeField = form.find("#add_show_start_time"), endDateField = form.find("#add_show_end_date_no_repeat"), endTimeField = form.find("#add_show_end_time"), - timezone = form.find("#add_show_timezone").val(), - showId = form.find("#add_show_id").val(); + newTimezone = form.find("#add_show_timezone").val(); $.post(baseUrl+"Schedule/localize-start-end-time", {format: "json", @@ -241,8 +246,8 @@ function setAddShowEvents() { startTime: startTimeField.val(), endDate: endDateField.val(), endTime: endTimeField.val(), - timezone: timezone, - showId: showId}, function(json){ + newTimezone: newTimezone, + oldTimezone: currentTimezone}, function(json){ startDateField.val(json.start.date); startTimeField.val(json.start.time);