From 9e8fdb50cae79de630f5b0165dd1e294afc12720 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 24 Sep 2013 15:04:25 -0400 Subject: [PATCH 1/6] CC-5323: User's Timezone Can Improperly Edit Show --- .../controllers/ScheduleController.php | 21 +++++++++++++++ airtime_mvc/application/forms/AddShowWhen.php | 9 +++++++ .../application/models/airtime/CcShowDays.php | 9 ++++--- .../application/services/ShowFormService.php | 27 ++++++++++++++++++- .../views/scripts/form/add-show-when.phtml | 10 +++++++ airtime_mvc/public/css/styles.css | 4 +++ .../public/js/airtime/schedule/add-show.js | 24 +++++++++++++++++ 7 files changed, 99 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index e13547c88..0fc7a1f3a 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -35,6 +35,7 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('calculate-duration', 'json') ->addActionContext('get-current-show', 'json') ->addActionContext('update-future-is-scheduled', 'json') + ->addActionContext('localize-start-end-time', 'json') ->initContext(); $this->sched_sess = new Zend_Session_Namespace("schedule"); @@ -641,4 +642,24 @@ class ScheduleController extends Zend_Controller_Action $redrawLibTable = Application_Model_StoredFile::setIsScheduled($schedId, false); $this->_helper->json->sendJson(array("redrawLibTable" => $redrawLibTable)); } + + /** + * When the timezone is changed in add-show form this function + * applies the new timezone to the start and end time + */ + public function localizeStartEndTimeAction() + { + $service_showForm = new Application_Service_ShowFormService( + $this->_getParam("showId")); + $timezone = $this->_getParam('timezone'); + $localTime = array(); + + $localTime["start"] = $service_showForm->localizeDateTime( + $this->_getParam('startDate'), $this->_getParam('startTime'), $timezone); + + $localTime["end"] = $service_showForm->localizeDateTime( + $this->_getParam('endDate'), $this->_getParam('endTime'), $timezone); + + $this->_helper->json->sendJson($localTime); + } } diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 007852ba4..9be8aa218 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -78,6 +78,15 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm 'decorators' => array('ViewHelper') )); + $timezone = new Zend_Form_Element_Select('add_show_timezone'); + $timezone->setRequired(true) + ->setLabel(_("Timezone:")) + ->setMultiOptions(Application_Common_Timezone::getTimezones()) + ->setValue(Application_Model_Preference::GetDefaultTimezone()) + ->setAttrib('class', 'input_select add_show_input_select') + ->setDecorators(array('ViewHelper')); + $this->addElement($timezone); + // Add repeats element $this->addElement('checkbox', 'add_show_repeats', array( 'label' => _('Repeats?'), diff --git a/airtime_mvc/application/models/airtime/CcShowDays.php b/airtime_mvc/application/models/airtime/CcShowDays.php index 7b08204a2..215ebdcf8 100644 --- a/airtime_mvc/application/models/airtime/CcShowDays.php +++ b/airtime_mvc/application/models/airtime/CcShowDays.php @@ -31,6 +31,7 @@ class CcShowDays extends BaseCcShowDays { return $dt; } + // Returns the start of a show in the timezone it was created in public function getLocalStartDateAndTime() { $dt = new DateTime( @@ -38,16 +39,16 @@ class CcShowDays extends BaseCcShowDays { new DateTimeZone($this->getDbTimezone()) ); - //make timezone current user specific - $dt->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); + //set timezone to that of the show + $dt->setTimezone(new DateTimeZone($this->getDbTimezone())); return $dt; } /** * - * Enter description here ... - * @param DateTime $startDateTime first show in user's local time + * Returns the end of a show in the timezone it was created in + * @param DateTime $startDateTime first show in show's local time */ public function getLocalEndDateAndTime($showStart) { diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index c651c8ebd..5c7c4c0c1 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -150,6 +150,7 @@ class Application_Service_ShowFormService 'add_show_end_date_no_repeat' => $showEnd->format("Y-m-d"), 'add_show_end_time' => $showEnd->format("H:i"), 'add_show_duration' => $ccShowDay->formatDuration(true), + 'add_show_timezone' => $ccShowDay->getDbTimezone(), 'add_show_repeats' => $ccShowDay->isRepeating() ? 1 : 0)); return $showStart; @@ -159,7 +160,10 @@ class Application_Service_ShowFormService { $ccShowInstance = CcShowInstancesQuery::create()->findPk($this->instanceId); - $timezone = new DateTimeZone(Application_Model_Preference::GetTimezone()); + //get timezone the show is created in + $timezone = $ccShowInstance->getCcShow()->getFirstCcShowDay()->getDbTimezone(); + //$timezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone()); + //DateTime object in UTC $showStart = $ccShowInstance->getDbStarts(null); $showStart->setTimezone($timezone); @@ -180,6 +184,7 @@ class Application_Service_ShowFormService 'add_show_end_time' => $showEnd->format("H:i"), 'add_show_duration' => $this->calculateDuration( $showStart->format("Y-m-d H:i:s"), $showEnd->format("Y-m-d H:i:s")), + 'add_show_timezone' => $timezone, 'add_show_repeats' => 0)); $form->getElement('add_show_repeats')->setOptions(array("disabled" => true)); @@ -482,4 +487,24 @@ class Application_Service_ShowFormService return "Invalid Date"; } } + + /** + * + * Enter description here ... + * @param $date String + * @param $time String + * @param $timezone String + */ + public function localizeDateTime($date, $time, $timezone) + { + $dt = new DateTime($date." ".$time, new DateTimeZone( + $this->ccShow->getFirstCcShowDay()->getDbTimezone())); + + $dt->setTimeZone(new DateTimeZone($timezone)); + + return array( + "date" => $dt->format("Y-m-d"), + "time" => $dt->format("h:i") + ); + } } \ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/form/add-show-when.phtml b/airtime_mvc/application/views/scripts/form/add-show-when.phtml index 3a4d3f99d..f0569ce28 100644 --- a/airtime_mvc/application/views/scripts/form/add-show-when.phtml +++ b/airtime_mvc/application/views/scripts/form/add-show-when.phtml @@ -55,6 +55,16 @@ + +
+ +
+
+ element->getElement('add_show_timezone') ?> +
+
diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 2d9ac34b7..14d27f775 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -445,6 +445,10 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus, .input_t vertical-align: top; } +.add_show_input_select{ + width: 150px; +} + /***** LIBRARY QTIP METADATA SPECIFIC STYLES BEGIN *****/ table.library-track-md{ width: 280px; diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index fd2625559..d44e6f563 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -227,6 +227,30 @@ function setAddShowEvents() { } }); + 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(); + + $.post(baseUrl+"Schedule/localize-start-end-time", + {format: "json", + startDate: startDateField.val(), + startTime: startTimeField.val(), + endDate: endDateField.val(), + endTime: endTimeField.val(), + timezone: timezone, + showId: showId}, function(json){ + + startDateField.val(json.start.date); + startTimeField.val(json.start.time); + endDateField.val(json.end.date); + endTimeField.val(json.end.time); + }); + }); + form.find("#add_show_repeat_type").change(function(){ toggleRepeatDays(); toggleMonthlyRepeatType(); From ad778ec971811a1da750a31e1c2f0f89d806cb66 Mon Sep 17 00:00:00 2001 From: denise Date: Tue, 24 Sep 2013 16:23:45 -0400 Subject: [PATCH 2/6] 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); From 002a80ee6c4d8e9a53ddc4a4db055d2d42c02163 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 25 Sep 2013 14:32:16 -0400 Subject: [PATCH 3/6] CC-5323: User's Timezone Can Improperly Edit Show -made localizeDate a static function in ShowFormService --- .../application/controllers/ScheduleController.php | 9 ++------- airtime_mvc/application/services/ShowFormService.php | 7 ++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 87f142d4f..d8d5d6d30 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -643,21 +643,16 @@ class ScheduleController extends Zend_Controller_Action $this->_helper->json->sendJson(array("redrawLibTable" => $redrawLibTable)); } - /** - * When the timezone is changed in add-show form this function - * applies the new timezone to the start and end time - */ public function localizeStartEndTimeAction() { - $service_showForm = new Application_Service_ShowFormService(); $newTimezone = $this->_getParam('newTimezone'); $oldTimezone = $this->_getParam('oldTimezone'); $localTime = array(); - $localTime["start"] = $service_showForm->localizeDateTime( + $localTime["start"] = Application_Service_ShowFormService::localizeDateTime( $this->_getParam('startDate'), $this->_getParam('startTime'), $newTimezone, $oldTimezone); - $localTime["end"] = $service_showForm->localizeDateTime( + $localTime["end"] = Application_Service_ShowFormService::localizeDateTime( $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 4e8d49f44..2ef3b3c3d 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -489,13 +489,14 @@ class Application_Service_ShowFormService } /** - * - * Enter description here ... + * When the timezone is changed in add-show form this function + * applies the new timezone to the start and end time + * * @param $date String * @param $time String * @param $timezone String */ - public function localizeDateTime($date, $time, $newTimezone, $oldTimezone) + public static function localizeDateTime($date, $time, $newTimezone, $oldTimezone) { $dt = new DateTime($date." ".$time, new DateTimeZone($oldTimezone)); From 2666e97b7e161c53360e9e6a0e59eae3dc0072cf Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 25 Sep 2013 14:33:43 -0400 Subject: [PATCH 4/6] CC-5323: User's Timezone Can Improperly Edit Show -added comments to timezone getters and setters in Prefences model to reduce confusion on station timezone and user timezone --- airtime_mvc/application/models/Preference.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 9edf53755..1097a3d29 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -505,12 +505,14 @@ class Application_Model_Preference return self::getValue("description"); } + // Sets station default timezone (from preferences) public static function SetDefaultTimezone($timezone) { self::setValue("timezone", $timezone); date_default_timezone_set($timezone); } + // Returns station default timezone (from preferences) public static function GetDefaultTimezone() { return self::getValue("timezone"); @@ -536,6 +538,7 @@ class Application_Model_Preference } } + // Always attempts to returns the current user's personal timezone setting public static function GetTimezone() { $auth = Zend_Auth::getInstance(); From 3439611ef33d82aa1a1583c93842ef81d81605f0 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 25 Sep 2013 14:40:09 -0400 Subject: [PATCH 5/6] CC-5323: User's Timezone Can Improperly Edit Show -overlapping show check was using the user's local timezone to compare new shows instead of the show's timezone --- airtime_mvc/application/forms/AddShowWhen.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowWhen.php b/airtime_mvc/application/forms/AddShowWhen.php index 9be8aa218..3ca08b99e 100644 --- a/airtime_mvc/application/forms/AddShowWhen.php +++ b/airtime_mvc/application/forms/AddShowWhen.php @@ -167,7 +167,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm */ if ($valid) { $utc = new DateTimeZone('UTC'); - $localTimezone = new DateTimeZone(Application_Model_Preference::GetTimezone()); + $showTimezone = new DateTimeZone($formData["add_show_timezone"]); $show_start = new DateTime($start_time); $show_start->setTimezone($utc); $show_end = new DateTime($end_time); @@ -233,8 +233,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm * adding the interval for the next repeating show */ - $repeatShowStart->setTimezone($localTimezone); - $repeatShowEnd->setTimezone($localTimezone); + $repeatShowStart->setTimezone($showTimezone); + $repeatShowEnd->setTimezone($showTimezone); $repeatShowStart->add(new DateInterval("P".$daysAdd."D")); $repeatShowEnd->add(new DateInterval("P".$daysAdd."D")); //set back to UTC @@ -273,8 +273,8 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm $this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows'))); break 1; } else { - $repeatShowStart->setTimezone($localTimezone); - $repeatShowEnd->setTimezone($localTimezone); + $repeatShowStart->setTimezone($showTimezone); + $repeatShowEnd->setTimezone($showTimezone); $repeatShowStart->add(new DateInterval($interval)); $repeatShowEnd->add(new DateInterval($interval)); $repeatShowStart->setTimezone($utc); @@ -337,7 +337,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm * show start back to local time */ $rebroadcastShowStart->setTimezone(new DateTimeZone( - Application_Model_Preference::GetTimezone())); + $formData["add_show_timezone"])); $rebroadcastWhenDays = explode(" ", $formData["add_show_rebroadcast_date_".$i]); $rebroadcastWhenTime = explode(":", $formData["add_show_rebroadcast_time_".$i]); $rebroadcastShowStart->add(new DateInterval("P".$rebroadcastWhenDays[0]."D")); From 7fa3fe9a4900a02005e4a344d52a1160588b4fe0 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 25 Sep 2013 14:44:08 -0400 Subject: [PATCH 6/6] CC-5323: User's Timezone Can Improperly Edit Show - fixed to use show's timezone instead of user's timezone when updating a show's start and end time after a show has been edited --- airtime_mvc/application/services/ShowService.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index 6576d4f7e..6018cb5b5 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -740,10 +740,10 @@ SQL; //CcShowDay object $currentShowDay = $this->ccShow->getFirstCcShowDay(); - //DateTime in user's local time + //DateTime in show's local time $newStartDateTime = new DateTime($showData["add_show_start_date"]." ". $showData["add_show_start_time"], - new DateTimeZone(Application_Model_Preference::GetTimezone())); + new DateTimeZone($showData["add_show_timezone"])); $diff = $this->calculateShowStartDiff($newStartDateTime, $currentShowDay->getLocalStartDateAndTime()); @@ -1152,6 +1152,7 @@ SQL; do { $nextDT = date_create($weekNumberOfMonth." ".$dayOfWeek. " of ".$tempDT->format("F")." ".$tempDT->format("Y")); + $nextDT->setTimezone(new DateTimeZone($timezone)); /* We have to check if the next date is in the same month in case * the repeat day is in the fifth week of the month. @@ -1356,7 +1357,7 @@ SQL; $showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d")); $showDay->setDbLastShow($endDate); $showDay->setDbStartTime($startDateTimeClone->format("H:i")); - $showDay->setDbTimezone(Application_Model_Preference::GetTimezone()); + $showDay->setDbTimezone($showData['add_show_timezone']); $showDay->setDbDuration($showData['add_show_duration']); $showDay->setDbDay($day); $showDay->setDbRepeatType($this->repeatType); @@ -1481,12 +1482,13 @@ SQL; private function createUTCStartEndDateTime($showStart, $duration, $offset=null) { $startDateTime = clone $showStart; + $timezone = $startDateTime->getTimezone(); if (isset($offset)) { //$offset["hours"] and $offset["mins"] represents the start time //of a rebroadcast show $startDateTime = new DateTime($startDateTime->format("Y-m-d")." ". - $offset["hours"].":".$offset["mins"]); + $offset["hours"].":".$offset["mins"], $timezone); $startDateTime->add(new DateInterval("P{$offset["days"]}D")); } //convert time to UTC