diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index e3001cffc..f0bb211c8 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -25,7 +25,8 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('preference')) ->add(new Zend_Acl_Resource('recorder')) ->add(new Zend_Acl_Resource('showbuilder')) - ->add(new Zend_Acl_Resource('auth')); + ->add(new Zend_Acl_Resource('auth')) + ->add(new Zend_Acl_Resource('usersettings')); /** Creating permissions */ $ccAcl->allow('G', 'index') @@ -34,11 +35,10 @@ $ccAcl->allow('G', 'index') ->allow('G', 'nowplaying') ->allow('G', 'api') ->allow('G', 'auth') - //->allow('G', 'plupload', array('upload-recorded')) ->allow('G', 'recorder') ->allow('G', 'schedule') ->allow('G', 'dashboard') - //->allow('H', 'plupload', array('plupload', 'upload', 'index')) + ->allow('H', 'usersettings') ->allow('H', 'plupload') ->allow('H', 'library') ->allow('H', 'search') diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index cfe93182e..bebedaa0c 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -1,6 +1,6 @@ addActionContext('status', 'json') ->addActionContext('register-component', 'json') ->addActionContext('update-liquidsoap-status', 'json') - ->addActionContext('library-init', 'json') ->addActionContext('live-chat', 'json') ->addActionContext('update-file-system-mount', 'json') ->addActionContext('handle-watched-dir-missing', 'json') @@ -64,7 +63,7 @@ class ApiController extends Zend_Controller_Action $jsonStr = json_encode(array("version"=>Application_Model_Preference::GetAirtimeVersion())); echo $jsonStr; } - + /** * Sets up and send init values used in the Calendar. * This is only being used by schedule.js at the moment. @@ -72,16 +71,16 @@ class ApiController extends Zend_Controller_Action public function calendarInitAction(){ $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); - + if(is_null(Zend_Auth::getInstance()->getStorage()->read())) { header('HTTP/1.0 401 Unauthorized'); print 'You are not allowed to access this resource.'; return; } - + $this->view->calendarInit = array( - "timestamp" => time(), - "timezoneOffset" => date("Z"), + "timestamp" => time(), + "timezoneOffset" => date("Z"), "timeScale" => Application_Model_Preference::GetCalendarTimeScale(), "timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(), "weekStartDay" => Application_Model_Preference::GetWeekStartDay() @@ -178,9 +177,9 @@ class ApiController extends Zend_Controller_Action * Retrieve the currently playing show as well as upcoming shows. * Number of shows returned and the time interval in which to * get the next shows can be configured as GET parameters. - * + * * TODO: in the future, make interval length a parameter instead of hardcode to 48 - * + * * Possible parameters: * type - Can have values of "endofday" or "interval". If set to "endofday", * the function will retrieve shows from now to end of day. @@ -199,19 +198,19 @@ class ApiController extends Zend_Controller_Action $date = new Application_Model_DateHelper; $utcTimeNow = $date->getUtcTimestamp(); $utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day - + $request = $this->getRequest(); $type = $request->getParam('type'); if($type == "endofday") { // make GetNextShows use end of day $utcTimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc(); } - + $limit = $request->getParam('limit'); if($limit == "" || !is_numeric($limit)) { $limit = "5"; } - + $result = array("env"=>APPLICATION_ENV, "schedulerTime"=>gmdate("Y-m-d H:i:s"), "currentShow"=>Application_Model_Show::GetCurrentShow($utcTimeNow), @@ -219,7 +218,7 @@ class ApiController extends Zend_Controller_Action "timezone"=> date("T"), "timezoneOffset"=> date("Z"), "AIRTIME_API_VERSION"=>AIRTIME_API_VERSION); //used by caller to determine if the airtime they are running or widgets in use is out of date. - + //Convert from UTC to localtime for user. Application_Model_Show::ConvertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp")); Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp")); @@ -233,7 +232,7 @@ class ApiController extends Zend_Controller_Action exit; } } - + public function weekInfoAction() { if (Application_Model_Preference::GetAllow3rdPartyApi()){ @@ -244,7 +243,7 @@ class ApiController extends Zend_Controller_Action $date = new Application_Model_DateHelper; $dayStart = $date->getWeekStartDate(); $utcDayStart = Application_Model_DateHelper::ConvertToUtcDateTimeString($dayStart); - + $dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); $result = array(); @@ -252,9 +251,9 @@ class ApiController extends Zend_Controller_Action $utcDayEnd = Application_Model_DateHelper::GetDayEndTimestamp($utcDayStart); $shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd); $utcDayStart = $utcDayEnd; - + Application_Model_Show::ConvertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp")); - + $result[$dow[$i]] = $shows; } $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; //used by caller to determine if the airtime they are running or widgets in use is out of date. @@ -373,8 +372,8 @@ class ApiController extends Zend_Controller_Action $now = new DateTime($today_timestamp); $end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); - - $this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), + + $this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), Application_Model_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), $excludeInstance=NULL, $onlyRecord=TRUE); @@ -405,7 +404,7 @@ class ApiController extends Zend_Controller_Action $upload_dir = ini_get("upload_tmp_dir"); $tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir); $tempFileName = basename($tempFilePath); - + $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; $result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName); if (isset($result)){ @@ -456,19 +455,19 @@ class ApiController extends Zend_Controller_Action } if (isset($show_name)) { - + $show_name = str_replace(" ", "-", $show_name); - + //2011-12-09-19-28-00-ofirrr-256kbps $filename = $file->getName(); - + //replace the showname in the filepath incase it has been edited since the show started recording //(some old bug) $filename_parts = explode("-", $filename); $new_name = array_slice($filename_parts, 0, 6); $new_name[] = $show_name; $new_name[] = $filename_parts[count($filename_parts)-1]; - + $tmpTitle = implode("-", $new_name); } else { @@ -533,7 +532,7 @@ class ApiController extends Zend_Controller_Action } $this->view->stor = Application_Model_MusicDir::getStorDir()->getDirectory(); - + $watchedDirs = Application_Model_MusicDir::getWatchedDirs(); $watchedDirsPath = array(); foreach($watchedDirs as $wd){ @@ -573,7 +572,7 @@ class ApiController extends Zend_Controller_Action $filepath = str_replace("//", "/", $filepath); $file = Application_Model_StoredFile::RecallByFilepath($filepath); - + if (is_null($file)) { $file = Application_Model_StoredFile::Insert($md); } @@ -737,10 +736,10 @@ class ApiController extends Zend_Controller_Action $this->view->msg = Application_Model_MusicDir::setStorDir($path); } - + public function getStreamSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -752,10 +751,10 @@ class ApiController extends Zend_Controller_Action $this->view->msg = Application_Model_StreamSetting::getStreamSetting(); } - + public function statusAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); $getDiskInfo = $request->getParam('diskinfo') == "true"; @@ -767,7 +766,7 @@ class ApiController extends Zend_Controller_Action exit; } */ - + $status = array( "platform"=>Application_Model_Systemstatus::GetPlatformInfo(), "airtime_version"=>Application_Model_Preference::GetAirtimeVersion(), @@ -778,11 +777,11 @@ class ApiController extends Zend_Controller_Action "media_monitor"=>Application_Model_Systemstatus::GetMediaMonitorStatus() ) ); - + if ($getDiskInfo){ $status["partitions"] = Application_Model_Systemstatus::GetDiskInfo(); } - + $this->view->status = $status; } @@ -795,40 +794,21 @@ class ApiController extends Zend_Controller_Action Application_Model_ServiceRegister::Register($component, $remoteAddr); } - + public function updateLiquidsoapStatusAction(){ $request = $this->getRequest(); - + $msg = $request->getParam('msg'); $stream_id = $request->getParam('stream_id'); $boot_time = $request->getParam('boot_time'); - + Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time); } - - /** - * Sets up and send init values used in the Library. - * This is being used by library.js - */ - public function libraryInitAction(){ - $this->view->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); - - if(is_null(Zend_Auth::getInstance()->getStorage()->read())) { - header('HTTP/1.0 401 Unauthorized'); - print 'You are not allowed to access this resource.'; - return; - } - - $this->view->libraryInit = array( - "numEntries"=>Application_Model_Preference::GetLibraryNumEntries() - ); - } - + // handles addition/deletion of mount point which watched dirs reside public function updateFileSystemMountAction(){ global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -841,16 +821,16 @@ class ApiController extends Zend_Controller_Action $params = $request->getParams(); $added_list = empty($params['added_dir'])?array():explode(',',$params['added_dir']); $removed_list = empty($params['removed_dir'])?array():explode(',',$params['removed_dir']); - + // get all watched dirs $watched_dirs = Application_Model_MusicDir::getWatchedDirs(null,null); - + foreach( $added_list as $ad){ foreach( $watched_dirs as $dir ){ $dirPath = $dir->getDirectory(); - + $ad .= '/'; - + // if mount path itself was watched if($dirPath == $ad){ Application_Model_MusicDir::addWatchedDir($dirPath, false); @@ -883,7 +863,7 @@ class ApiController extends Zend_Controller_Action // is new mount point within the watched dir? // pyinotify doesn't notify anyhing in this case, so we walk through all files within // this watched dir in DB and mark them deleted. - // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to + // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to // compare agaisnt all files in cc_files table else if(substr($rd, 0, strlen($dirPath)) === $dirPath ){ $watchDir = Application_Model_MusicDir::getDirByPath($rd); @@ -902,13 +882,13 @@ class ApiController extends Zend_Controller_Action } } } - + } - + // handles case where watched dir is missing public function handleWatchedDirMissingAction(){ global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -917,7 +897,7 @@ class ApiController extends Zend_Controller_Action print 'You are not allowed to access this resource.'; exit; } - + $dir = base64_decode($request->getParam('dir')); Application_Model_MusicDir::removeWatchedDir($dir, false); } diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 1b2f9dfe4..0c838693d 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -47,7 +47,7 @@ class LibraryController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorderResize.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); @@ -79,6 +79,10 @@ class LibraryController extends Zend_Controller_Action $file = Application_Model_StoredFile::Recall($id); + if (isset($this->pl_sess->id) && $screen == "playlist") { + $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "copy"); + } + $menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); if ($user->isAdmin()) { @@ -282,14 +286,4 @@ class LibraryController extends Zend_Controller_Action $this->view->error_msg = $file->getSoundCloudErrorMsg(); } } - - /** - * Stores the number of entries user chose to show in the Library - * to the pref db - */ - public function setNumEntriesAction() { - $request = $this->getRequest(); - $numEntries = $request->getParam('numEntries'); - Application_Model_Preference::SetLibraryNumEntries($numEntries); - } } diff --git a/airtime_mvc/application/controllers/NowplayingController.php b/airtime_mvc/application/controllers/NowplayingController.php index 1926d596c..bc02662bf 100644 --- a/airtime_mvc/application/controllers/NowplayingController.php +++ b/airtime_mvc/application/controllers/NowplayingController.php @@ -15,25 +15,25 @@ class NowplayingController extends Zend_Controller_Action public function indexAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + //nowplayingdatagrid.js requires this variable, so that datePicker widget can be offset to server time instead of client time $this->view->headScript()->appendScript("var timezoneOffset = ".date("Z")."; //in seconds"); $this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowplayingdatagrid.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowview.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $refer_sses = new Zend_Session_Namespace('referrer'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); - + if ($request->isPost()) { $form = new Application_Form_RegisterAirtime(); - + $values = $request->getPost(); if ($values["Publicise"] != 1 && $form->isValid($values)){ Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); @@ -49,10 +49,10 @@ class NowplayingController extends Zend_Controller_Action Application_Model_Preference::SetEmail($values["Email"]); Application_Model_Preference::SetStationWebSite($values["StationWebSite"]); Application_Model_Preference::SetPublicise($values["Publicise"]); - + $form->Logo->receive(); $imagePath = $form->Logo->getFileName(); - + Application_Model_Preference::SetStationCountry($values["Country"]); Application_Model_Preference::SetStationCity($values["City"]); Application_Model_Preference::SetStationDescription($values["Description"]); @@ -75,10 +75,10 @@ class NowplayingController extends Zend_Controller_Action //popup if previous page was login if($refer_sses->referrer == 'login' && Application_Model_Nowplaying::ShouldShowPopUp() && !Application_Model_Preference::GetSupportFeedback() && $user->isAdmin()){ - + $form = new Application_Form_RegisterAirtime(); - - + + $logo = Application_Model_Preference::GetStationLogo(); if($logo){ $this->view->logoImg = $logo; @@ -94,7 +94,7 @@ class NowplayingController extends Zend_Controller_Action $viewType = $this->_request->getParam('view'); $dateString = $this->_request->getParam('date'); $this->view->entries = Application_Model_Nowplaying::GetDataGridData($viewType, $dateString); - + } /* public function livestreamAction() @@ -107,16 +107,16 @@ class NowplayingController extends Zend_Controller_Action public function dayViewAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + //nowplayingdatagrid.js requires this variable, so that datePicker widget can be offset to server time instead of client time $this->view->headScript()->appendScript("var timezoneOffset = ".date("Z")."; //in seconds"); $this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/nowplayingdatagrid.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/nowplaying/dayview.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); } @@ -127,7 +127,7 @@ class NowplayingController extends Zend_Controller_Action Application_Model_Preference::SetRemindMeDate(); die(); } - + public function donotshowregistrationpopupAction() { // unset session diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 64032d84a..b40de9d35 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -30,6 +30,12 @@ class PlaylistController extends Zend_Controller_Action if (isset($this->pl_sess->id)) { $pl = new Application_Model_Playlist($this->pl_sess->id); + + $modified = $this->_getParam('modified', null); + if ($pl->getLastModified("U") !== $modified) { + $this->createFullResponse($pl); + throw new PlaylistOutDatedException("You are viewing an older version of {$pl->getName()}"); + } } return $pl; } @@ -46,11 +52,14 @@ class PlaylistController extends Zend_Controller_Action private function createUpdateResponse($pl) { + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); + $this->view->pl = $pl; $this->view->html = $this->view->render('playlist/update.phtml'); $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); $this->view->description = $pl->getDescription(); + $this->view->modified = $pl->getLastModified("U"); unset($this->view->pl); } @@ -58,6 +67,9 @@ class PlaylistController extends Zend_Controller_Action private function createFullResponse($pl = null) { if (isset($pl)) { + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); + $this->view->pl = $pl; $this->view->id = $pl->getId(); $this->view->html = $this->view->render('playlist/index.phtml'); @@ -68,10 +80,33 @@ class PlaylistController extends Zend_Controller_Action } } + private function playlistOutdated($pl, $e) + { + $this->view->error = $e->getMessage(); + } + + private function playlistNotFound() + { + $this->view->error = "Playlist not found"; + + Logging::log("Playlist not found"); + $this->changePlaylist(null); + $this->createFullResponse(null); + } + + private function playlistUnknownError($e) + { + $this->view->error = "Something went wrong."; + + Logging::log("{$e->getFile()}"); + Logging::log("{$e->getLine()}"); + Logging::log("{$e->getMessage()}"); + } + public function indexAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -81,18 +116,19 @@ class PlaylistController extends Zend_Controller_Action $this->_helper->viewRenderer->setResponseSegment('spl'); try { - $pl = $this->getPlaylist(); + if (isset($this->pl_sess->id)) { + $pl = new Application_Model_Playlist($this->pl_sess->id); + $this->view->pl = $pl; - if (isset($pl)) { - $this->view->pl = $pl; + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); } } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } } @@ -119,20 +155,15 @@ class PlaylistController extends Zend_Controller_Action } try { - $pl = $this->getPlaylist(); + $pl = new Application_Model_Playlist($id); + $this->createFullResponse($pl); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist {$id} not found"); - $this->changePlaylist(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); - $this->changePlaylist(null); + $this->playlistUnknownError($e); } - - $this->createFullResponse($pl); } public function deleteAction() @@ -150,23 +181,18 @@ class PlaylistController extends Zend_Controller_Action } else { Logging::log("Not deleting currently active playlist"); + $pl = new Application_Model_Playlist($this->pl_sess->id); } Application_Model_Playlist::DeletePlaylists($ids); - $pl = $this->getPlaylist(); + $this->createFullResponse($pl); } - catch(PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $pl = null; + catch (PlaylistNotFoundException $e) { + $this->playlistNotFound(); } - catch(Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + catch (Exception $e) { + $this->playlistUnknownError($e); } - - $this->createFullResponse($pl); } public function addItemsAction() @@ -176,24 +202,20 @@ class PlaylistController extends Zend_Controller_Action $afterItem = $this->_getParam('afterItem', null); $addType = $this->_getParam('type', 'after'); - Logging::log("type is ".$addType); - try { $pl = $this->getPlaylist(); $pl->addAudioClips($ids, $afterItem, $addType); + $this->createUpdateResponse($pl); + } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } - - $this->createUpdateResponse($pl); } public function moveItemsAction() @@ -201,46 +223,44 @@ class PlaylistController extends Zend_Controller_Action $ids = $this->_getParam('ids'); $ids = (!is_array($ids)) ? array($ids) : $ids; $afterItem = $this->_getParam('afterItem', null); + $modified = $this->_getParam('modified'); try { $pl = $this->getPlaylist(); $pl->moveAudioClips($ids, $afterItem); + $this->createUpdateResponse($pl); + } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } - - $this->createUpdateResponse($pl); } public function deleteItemsAction() { $ids = $this->_getParam('ids'); $ids = (!is_array($ids)) ? array($ids) : $ids; + $modified = $this->_getParam('modified'); try { $pl = $this->getPlaylist(); $pl->delAudioClips($ids); + $this->createUpdateResponse($pl); + } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } - - $this->createUpdateResponse($pl); } public function setCueAction() @@ -253,21 +273,22 @@ class PlaylistController extends Zend_Controller_Action $pl = $this->getPlaylist(); $response = $pl->changeClipLength($id, $cueIn, $cueOut); - $this->view->response = $response; - - if(!isset($response["error"])) { + if (!isset($response["error"])) { + $this->view->response = $response; $this->createUpdateResponse($pl); } + else { + $this->view->cue_error = $response["error"]; + } + } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } } @@ -281,21 +302,22 @@ class PlaylistController extends Zend_Controller_Action $pl = $this->getPlaylist(); $response = $pl->changeFadeInfo($id, $fadeIn, $fadeOut); - $this->view->response = $response; - if (!isset($response["error"])) { $this->createUpdateResponse($pl); + $this->view->response = $response; + } + else { + $this->view->fade_error = $response["error"]; } } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); + } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } } @@ -309,15 +331,14 @@ class PlaylistController extends Zend_Controller_Action $fades = $pl->getFadeInfo($pl->getSize()-1); $this->view->fadeOut = $fades[1]; } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); + } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } } @@ -335,15 +356,14 @@ class PlaylistController extends Zend_Controller_Action $pl = $this->getPlaylist(); $pl->setPlaylistfades($fadeIn, $fadeOut); } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); + } catch (PlaylistNotFoundException $e) { - Logging::log("Playlist not found"); - $this->changePlaylist(null); - $this->createFullResponse(null); + $this->playlistNotFound(); } catch (Exception $e) { - Logging::log("{$e->getFile()}"); - Logging::log("{$e->getLine()}"); - Logging::log("{$e->getMessage()}"); + $this->playlistUnknownError($e); } } @@ -351,33 +371,42 @@ class PlaylistController extends Zend_Controller_Action { $name = $this->_getParam('name', 'Unknown Playlist'); - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; + try { + $pl = $this->getPlaylist(); + $pl->setName($name); + $this->view->playlistName = $name; + $this->view->modified = $pl->getLastModified("U"); + } + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); + } + catch (PlaylistNotFoundException $e) { + $this->playlistNotFound(); + } + catch (Exception $e) { + $this->playlistUnknownError($e); } - $pl->setName($name); - - $this->view->playlistName = $name; } public function setPlaylistDescriptionAction() { - $description = $this->_getParam('description', false); - $pl = $this->getPlaylist(); - if($pl === false){ - $this->view->playlist_error = true; - return false; - } + $description = $this->_getParam('description', ""); - if($description != false) { + try { + $pl = $this->getPlaylist(); $pl->setDescription($description); + $this->view->description = $pl->getDescription(); + $this->view->modified = $pl->getLastModified("U"); } - else { - $description = $pl->getDescription(); + catch (PlaylistOutDatedException $e) { + $this->playlistOutdated($pl, $e); + } + catch (PlaylistNotFoundException $e) { + $this->playlistNotFound(); + } + catch (Exception $e) { + $this->playlistUnknownError($e); } - - $this->view->playlistDescription = $description; } } diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index b297700b0..4d2018bba 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -20,7 +20,7 @@ class PreferenceController extends Zend_Controller_Action public function indexAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -59,7 +59,7 @@ class PreferenceController extends Zend_Controller_Action public function supportSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -119,7 +119,7 @@ class PreferenceController extends Zend_Controller_Action public function directoryConfigAction() { global $CC_CONFIG; - + if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -136,7 +136,7 @@ class PreferenceController extends Zend_Controller_Action public function streamSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -206,10 +206,10 @@ class PreferenceController extends Zend_Controller_Action $values['output_sound_device'] = $form->getValue('output_sound_device'); } - + $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata'); $values['output_sound_device_type'] = $form->getValue('output_sound_device_type'); - $values['streamFormat'] = $form->getValue('streamFormat'); + $values['streamFormat'] = $form->getValue('streamFormat'); } if(!$error){ diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index e0b326e55..86678e8ba 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -15,12 +15,9 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('move-show', 'json') ->addActionContext('resize-show', 'json') ->addActionContext('delete-show', 'json') - ->addActionContext('schedule-show', 'json') - ->addActionContext('schedule-show-dialog', 'json') ->addActionContext('show-content-dialog', 'json') ->addActionContext('clear-show', 'json') ->addActionContext('get-current-playlist', 'json') - ->addActionContext('find-playlists', 'json') ->addActionContext('remove-group', 'json') ->addActionContext('edit-show', 'json') ->addActionContext('add-show', 'json') @@ -43,8 +40,6 @@ class ScheduleController extends Zend_Controller_Action $baseUrl = $request->getBaseUrl(); $this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); //full-calendar-functions.js requires this variable, so that datePicker widget can be offset to server time instead of client time $this->view->headScript()->appendScript("var timezoneOffset = ".date("Z")."; //in seconds"); @@ -264,37 +259,6 @@ class ScheduleController extends Zend_Controller_Action $this->view->items = $menu; } - public function scheduleShowAction() - { - $showInstanceId = $this->sched_sess->showInstanceId; - $search = $this->_getParam('search', null); - $plId = $this->_getParam('plId'); - - if($search == "") { - $search = null; - } - - $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $user = new Application_Model_User($userInfo->id); - try{ - $show = new Application_Model_ShowInstance($showInstanceId); - }catch(Exception $e){ - $this->view->show_error = true; - return false; - } - - if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST),$show->getShowId())) { - $show->scheduleShow(array($plId)); - } - - $this->view->showContent = $show->getShowContent(); - $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->percentFilled = $show->getPercentScheduled(); - - $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); - unset($this->view->showContent); - } - public function clearShowAction() { $showInstanceId = $this->_getParam('id'); @@ -336,27 +300,6 @@ class ScheduleController extends Zend_Controller_Action $this->view->entries = $range; } - public function findPlaylistsAction() - { - $post = $this->getRequest()->getPost(); - try{ - $show = new Application_Model_ShowInstance($this->sched_sess->showInstanceId); - }catch(Exception $e){ - $this->view->show_error = true; - return false; - } - - $playlists = $show->searchPlaylistsForShow($post); - foreach( $playlists['aaData'] as &$data){ - // calling two functions to format time to 1 decimal place - $sec = Application_Model_Playlist::playlistTimeToSeconds($data['length']); - $data['length'] = Application_Model_Playlist::secondsToPlaylistTime($sec); - } - - //for datatables - die(json_encode($playlists)); - } - public function removeGroupAction() { $showInstanceId = $this->sched_sess->showInstanceId; @@ -383,44 +326,6 @@ class ScheduleController extends Zend_Controller_Action unset($this->view->showContent); } - public function scheduleShowDialogAction() - { - $showInstanceId = $this->_getParam('id'); - $this->sched_sess->showInstanceId = $showInstanceId; - - try{ - $show = new Application_Model_ShowInstance($showInstanceId); - }catch(Exception $e){ - $this->view->show_error = true; - return false; - } - - $start_timestamp = $show->getShowInstanceStart(); - $end_timestamp = $show->getShowInstanceEnd(); - - $dateInfo_s = getDate(strtotime(Application_Model_DateHelper::ConvertToLocalDateTimeString($start_timestamp))); - $dateInfo_e = getDate(strtotime(Application_Model_DateHelper::ConvertToLocalDateTimeString($end_timestamp))); - - $this->view->showContent = $show->getShowContent(); - $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->showName = $show->getName(); - $this->view->showLength = $show->getShowLength(); - $this->view->percentFilled = $show->getPercentScheduled(); - - $this->view->s_wday = $dateInfo_s['weekday']; - $this->view->s_month = $dateInfo_s['month']; - $this->view->s_day = $dateInfo_s['mday']; - $this->view->e_wday = $dateInfo_e['weekday']; - $this->view->e_month = $dateInfo_e['month']; - $this->view->e_day = $dateInfo_e['mday']; - $this->view->startTime = sprintf("%02d:%02d", $dateInfo_s['hours'], $dateInfo_s['minutes']); - $this->view->endTime = sprintf("%02d:%02d", $dateInfo_e['hours'], $dateInfo_e['minutes']); - - $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); - $this->view->dialog = $this->view->render('schedule/schedule-show-dialog.phtml'); - unset($this->view->showContent); - } - public function showContentDialogAction() { $showInstanceId = $this->_getParam('id'); diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index ba1d683f8..8f10ad4bd 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -83,8 +83,8 @@ class ShowbuilderController extends Zend_Controller_Action public function scheduleAddAction() { $request = $this->getRequest(); - $mediaItems = $request->getParam("mediaIds", null); - $scheduledIds = $request->getParam("schedIds", null); + $mediaItems = $request->getParam("mediaIds", array()); + $scheduledIds = $request->getParam("schedIds", array()); try { $scheduler = new Application_Model_Scheduler(); @@ -102,14 +102,12 @@ class ShowbuilderController extends Zend_Controller_Action Logging::log("{$e->getFile()}"); Logging::log("{$e->getLine()}"); } - - $this->view->data = $json; } public function scheduleRemoveAction() { $request = $this->getRequest(); - $items = $request->getParam("items", null); + $items = $request->getParam("items", array()); try { $scheduler = new Application_Model_Scheduler(); @@ -151,8 +149,6 @@ class ShowbuilderController extends Zend_Controller_Action Logging::log("{$e->getFile()}"); Logging::log("{$e->getLine()}"); } - - $this->view->data = $json; } public function scheduleReorderAction() { diff --git a/airtime_mvc/application/controllers/UsersettingsController.php b/airtime_mvc/application/controllers/UsersettingsController.php new file mode 100644 index 000000000..c088bfcdd --- /dev/null +++ b/airtime_mvc/application/controllers/UsersettingsController.php @@ -0,0 +1,49 @@ +_helper->getHelper('AjaxContext'); + $ajaxContext->addActionContext('get-library-datatable', 'json') + ->addActionContext('set-library-datatable', 'json') + ->addActionContext('get-timeline-datatable', 'json') + ->addActionContext('set-timeline-datatable', 'json') + ->initContext(); + } + + public function setLibraryDatatableAction() { + + $request = $this->getRequest(); + $settings = $request->getParam("settings"); + + $data = serialize($settings); + Application_Model_Preference::SetValue("library_datatable", $data, true); + } + + public function getLibraryDatatableAction() { + + $data = Application_Model_Preference::GetValue("library_datatable", true); + if ($data != "") { + $this->view->settings = unserialize($data); + } + } + + public function setTimelineDatatableAction() { + + $request = $this->getRequest(); + $settings = $request->getParam("settings"); + + $data = serialize($settings); + Application_Model_Preference::SetValue("timeline_datatable", $data, true); + } + + public function getTimelineDatatableAction() { + + $data = Application_Model_Preference::GetValue("timeline_datatable", true); + if ($data != "") { + $this->view->settings = unserialize($data); + } + } +} \ No newline at end of file diff --git a/airtime_mvc/application/layouts/scripts/builder.phtml b/airtime_mvc/application/layouts/scripts/builder.phtml index e9313cd03..3efba392c 100644 --- a/airtime_mvc/application/layouts/scripts/builder.phtml +++ b/airtime_mvc/application/layouts/scripts/builder.phtml @@ -22,7 +22,7 @@