public function editShowAction()
 {
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new User($userInfo->id);
     if (!$user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
         return;
     }
     $showInstanceId = $this->_getParam('id');
     $formWhat = new Application_Form_AddShowWhat();
     $formWho = new Application_Form_AddShowWho();
     $formWhen = new Application_Form_AddShowWhen();
     $formRepeats = new Application_Form_AddShowRepeats();
     $formStyle = new Application_Form_AddShowStyle();
     $formRecord = new Application_Form_AddShowRR();
     $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
     $formRebroadcast = new Application_Form_AddShowRebroadcastDates();
     $formWhat->removeDecorator('DtDdWrapper');
     $formWho->removeDecorator('DtDdWrapper');
     $formWhen->removeDecorator('DtDdWrapper');
     $formRepeats->removeDecorator('DtDdWrapper');
     $formStyle->removeDecorator('DtDdWrapper');
     $formRecord->removeDecorator('DtDdWrapper');
     $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
     $formRebroadcast->removeDecorator('DtDdWrapper');
     $this->view->what = $formWhat;
     $this->view->when = $formWhen;
     $this->view->repeats = $formRepeats;
     $this->view->who = $formWho;
     $this->view->style = $formStyle;
     $this->view->rr = $formRecord;
     $this->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
     $this->view->rebroadcast = $formRebroadcast;
     $this->view->addNewShow = false;
     $showInstance = new ShowInstance($showInstanceId);
     $show = new Show($showInstance->getShowId());
     $formWhat->populate(array('add_show_id' => $show->getId(), 'add_show_name' => $show->getName(), 'add_show_url' => $show->getUrl(), 'add_show_genre' => $show->getGenre(), 'add_show_description' => $show->getDescription()));
     $formWhen->populate(array('add_show_start_date' => $show->getStartDate(), 'add_show_start_time' => DateHelper::removeSecondsFromTime($show->getStartTime()), 'add_show_end_date_no_repeat' => $show->getEndDate(), 'add_show_end_time' => DateHelper::removeSecondsFromTime($show->getEndTime()), 'add_show_duration' => $show->getDuration(true), 'add_show_repeats' => $show->isRepeating() ? 1 : 0));
     if ($show->isStartDateTimeInPast()) {
         $formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true));
     }
     $days = array();
     $showDays = CcShowDaysQuery::create()->filterByDbShowId($showInstance->getShowId())->find();
     foreach ($showDays as $showDay) {
         array_push($days, $showDay->getDbDay());
     }
     $displayedEndDate = new DateTime($show->getRepeatingEndDate());
     $displayedEndDate->sub(new DateInterval("P1D"));
     //end dates are stored non-inclusively.
     $displayedEndDate = $displayedEndDate->format("Y-m-d");
     $formRepeats->populate(array('add_show_repeat_type' => $show->getRepeatType(), 'add_show_day_check' => $days, 'add_show_end_date' => $displayedEndDate, 'add_show_no_end' => $show->getRepeatingEndDate() == ''));
     $formRecord->populate(array('add_show_record' => $show->isRecorded(), 'add_show_rebroadcast' => $show->isRebroadcast()));
     $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true));
     $rebroadcastsRelative = $show->getRebroadcastsRelative();
     $rebroadcastFormValues = array();
     $i = 1;
     foreach ($rebroadcastsRelative as $rebroadcast) {
         $rebroadcastFormValues["add_show_rebroadcast_date_{$i}"] = $rebroadcast['day_offset'];
         $rebroadcastFormValues["add_show_rebroadcast_time_{$i}"] = DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
         $i++;
     }
     $formRebroadcast->populate($rebroadcastFormValues);
     $rebroadcastsAbsolute = $show->getRebroadcastsAbsolute();
     $rebroadcastAbsoluteFormValues = array();
     $i = 1;
     foreach ($rebroadcastsAbsolute as $rebroadcast) {
         $rebroadcastAbsoluteFormValues["add_show_rebroadcast_date_absolute_{$i}"] = $rebroadcast['start_date'];
         $rebroadcastAbsoluteFormValues["add_show_rebroadcast_time_absolute_{$i}"] = DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
         $i++;
     }
     $formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues);
     $hosts = array();
     $showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find();
     foreach ($showHosts as $showHost) {
         array_push($hosts, $showHost->getDbHost());
     }
     $formWho->populate(array('add_show_hosts' => $hosts));
     $formStyle->populate(array('add_show_background_color' => $show->getBackgroundColor(), 'add_show_color' => $show->getColor()));
     $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
     $this->view->entries = 5;
 }
 public function uploadRecordedAction()
 {
     global $CC_CONFIG;
     $api_key = $this->_getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     //this file id is the recording for this show instance.
     $show_instance_id = $this->_getParam('showinstanceid');
     $file_id = $this->_getParam('fileid');
     $this->view->fileid = $file_id;
     $this->view->showinstanceid = $show_instance_id;
     $showCanceled = false;
     $file = StoredFile::Recall($file_id);
     //$show_instance  = $this->_getParam('show_instance');
     $show_name = null;
     try {
         $show_inst = new ShowInstance($show_instance_id);
         $show_inst->setRecordedFile($file_id);
         $show_name = $show_inst->getName();
         $show_genre = $show_inst->getGenre();
         $show_start_time = $show_inst->getShowStart();
     } catch (Exception $e) {
         //we've reached here probably because the show was
         //cancelled, and therefore the show instance does not
         //exist anymore (ShowInstance constructor threw this error).
         //We've done all we can do (upload the file and put it in
         //the library), now lets just return.
         $showCanceled = true;
     }
     if (isset($show_name)) {
         $tmpTitle = "{$show_name}-{$show_start_time}";
         $tmpTitle = str_replace(" ", "-", $tmpTitle);
     } else {
         $tmpTitle = $file->getName();
     }
     $file->setMetadataValue('MDATA_KEY_TITLE', $tmpTitle);
     $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder");
     $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', null);
     if (!$showCanceled && Application_Model_Preference::GetDoSoundCloudUpload()) {
         for ($i = 0; $i < $CC_CONFIG['soundcloud-connection-retries']; $i++) {
             $show = new Show($show_inst->getShowId());
             $description = $show->getDescription();
             $hosts = $show->getHosts();
             $tags = array_merge($hosts, array($show_name));
             try {
                 $soundcloud = new ATSoundcloud();
                 $soundcloud_id = $soundcloud->uploadTrack($file->getFilePath(), $tmpTitle, $description, $tags, $show_start_time, $show_genre);
                 $show_inst->setSoundCloudFileId($soundcloud_id);
                 break;
             } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                 $code = $e->getHttpCode();
                 if (!in_array($code, array(0, 100))) {
                     break;
                 }
             }
             sleep($CC_CONFIG['soundcloud-connection-wait']);
         }
     }
     $this->view->id = $file_id;
 }