diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index b06a9e1ed..e5734a6b3 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -454,4 +454,69 @@ class PreferenceController extends Zend_Controller_Action } $this->_helper->json->sendJson($out); } + + public function deleteAllFilesAction() + { + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + // Only admin users should get here through ACL permissioning + // Only allow POST requests + $method = $_SERVER['REQUEST_METHOD']; + if (!($method == 'POST')) { + $this->getResponse() + ->setHttpResponseCode(405) + ->appendBody(_("Request method not accepted") . ": $method"); + return; + } + + $user = Application_Model_User::getCurrentUser(); + $playlists = $blocks = $streams = []; + + $allPlaylists = CcPlaylistQuery::create()->find(); + foreach ($allPlaylists as $p) { + $playlists[] = $p->getDbId(); + } + + $allBlocks = CcBlockQuery::create()->find(); + foreach ($allBlocks as $b) { + $blocks[] = $b->getDbId(); + } + + $allStreams = CcWebstreamQuery::create()->find(); + foreach ($allStreams as $s) { + $streams[] = $s->getDbId(); + } + + // Delete all playlists, blocks, and streams + Application_Model_Playlist::deletePlaylists($playlists, $user->getId()); + Application_Model_Block::deleteBlocks($blocks, $user->getId()); + Application_Model_Webstream::deleteStreams($streams, $user->getId()); + + try { + // Delete all the cloud files + $CC_CONFIG = Config::getConfig(); + + foreach ($CC_CONFIG["supportedStorageBackends"] as $storageBackend) { + $proxyStorageBackend = new ProxyStorageBackend($storageBackend); + $proxyStorageBackend->deleteAllCloudFileObjects(); + } + } catch(Exception $e) { + Logging::info($e->getMessage()); + } + + // Delete all files from the database + $files = CcFilesQuery::create()->find(); + foreach ($files as $file) { + $storedFile = new Application_Model_StoredFile($file, null); + $storedFile->delete(); + } + + /* TODO: delete hard copies of files? */ + + $this->getResponse() + ->setHttpResponseCode(200) + ->appendBody("OK"); + } + } diff --git a/airtime_mvc/application/forms/DangerousPreferences.php b/airtime_mvc/application/forms/DangerousPreferences.php new file mode 100644 index 000000000..28d203405 --- /dev/null +++ b/airtime_mvc/application/forms/DangerousPreferences.php @@ -0,0 +1,21 @@ +setDecorators(array( + array('ViewScript', array('viewScript' => 'form/preferences_danger.phtml')) + )); + + $clearLibrary = new Zend_Form_Element_Button('clear_library'); + $clearLibrary->setLabel(_('Delete All Tracks in Library')); + //$submit->removeDecorator('Label'); + $clearLibrary->setAttribs(array('class'=>'btn centered')); + $clearLibrary->setAttrib('onclick', 'deleteAllFiles();'); + $clearLibrary->removeDecorator('DtDdWrapper'); + + $this->addElement($clearLibrary); + } + +} diff --git a/airtime_mvc/application/forms/Preferences.php b/airtime_mvc/application/forms/Preferences.php index 3e5158413..30a11e933 100644 --- a/airtime_mvc/application/forms/Preferences.php +++ b/airtime_mvc/application/forms/Preferences.php @@ -24,6 +24,9 @@ class Application_Form_Preferences extends Zend_Form $soundcloud_pref = new Application_Form_SoundcloudPreferences(); $this->addSubForm($soundcloud_pref, 'preferences_soundcloud'); + $danger_pref = new Application_Form_DangerousPreferences(); + $this->addSubForm($danger_pref, 'preferences_danger'); + $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel(_('Save')); //$submit->removeDecorator('Label'); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 8e3dd7a59..51baf2e20 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -401,6 +401,7 @@ SQL; //or from the cloud if ($this->_file->getDbImportStatus() == CcFiles::IMPORT_STATUS_SUCCESS) { try { + Logging::info("DELETING PHYSICAL FILE " . $this->_file->getDbTrackTitle()); $this->_file->deletePhysicalFile(); } catch (Exception $e) diff --git a/airtime_mvc/application/views/scripts/form/preferences.phtml b/airtime_mvc/application/views/scripts/form/preferences.phtml index 0ffe1ea9d..cef632f57 100644 --- a/airtime_mvc/application/views/scripts/form/preferences.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences.phtml @@ -4,6 +4,18 @@ element->getSubform('preferences_general') ?> +

+ +
+ element->getSubform('preferences_soundcloud') ?> +
+ +

+
+ element->getSubform('preferences_danger') ?> +
+ +
element->submit->render() ?> diff --git a/airtime_mvc/application/views/scripts/form/preferences_danger.phtml b/airtime_mvc/application/views/scripts/form/preferences_danger.phtml new file mode 100644 index 000000000..7ea8a78d1 --- /dev/null +++ b/airtime_mvc/application/views/scripts/form/preferences_danger.phtml @@ -0,0 +1,14 @@ +
+
+ +
+

+ Warning: These functions will have permanent and lasting effects + on your Airtime station. Think carefully before using them! +

+
+ + element->getElement('clear_library')->render() ?> + +
+
diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index b80cbfe8e..8bb4c4ba9 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -1788,7 +1788,7 @@ ul.errors { width:278px; } -ul.errors li { +ul.errors li, .warning { color:#902d2d; font-size:11px; padding:2px 4px; @@ -1798,6 +1798,11 @@ ul.errors li { list-style: none; } +.warning-label { + font-size: medium; + text-align: center; +} + div.success{ color:#3B5323; font-size:11px; @@ -2255,14 +2260,9 @@ dd.radio-inline-list, .preferences dd.radio-inline-list, .stream-config dd.radio .radio-inline-list label { margin-right:12px; } -.preferences.simple-formblock dd.block-display { - width: 100%; -} - -.preferences.simple-formblock dd.block-display select, .stream-config.simple-formblock dd.block-display select { - width: 100%; -} -.preferences dd.block-display .input_select, .stream-config dd.block-display .input_select { +.preferences.simple-formblock dd.block-display, + .preferences.simple-formblock dd.block-display select, .stream-config.simple-formblock dd.block-display select, + .preferences dd.block-display .input_select, .stream-config dd.block-display .input_select { width: 100%; } .preferences dd.block-display .input_text_area, .preferences dd.block-display .input_text @@ -2284,6 +2284,15 @@ dd.radio-inline-list, .preferences dd.radio-inline-list, .stream-config dd.radio margin-bottom: 4px; } +.preferences #Logo-img-container { + margin-top: 30px; +} + +.centered { + margin: 0 auto; + display: block; +} + #show_time_info { font-size:12px; height:30px; diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index 1dffe24d2..8894020bc 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -1,18 +1,13 @@ function showErrorSections() { - if($("#soundcloud-settings .errors").length > 0) { - $("#soundcloud-settings").show(); - $(window).scrollTop($("#soundcloud-settings .errors").position().top); - } - - if($("#email-server-settings .errors").length > 0) { - $("#email-server-settings").show(); - $(window).scrollTop($("#email-server-settings .errors").position().top); - } - - if($("#livestream-settings .errors").length > 0) { - $("#livestream-settings").show(); - $(window).scrollTop($("#livestream-settings .errors").position().top); - } + var selector = $("[id$=-settings]"); + selector.each(function(i) { + var el = $(this); + var errors = el.find(".errors"); + if (errors.length > 0) { + el.show(); + $(window).scrollTop(errors.position().top); + } + }); } function setConfigureMailServerListener() { @@ -120,6 +115,14 @@ function removeLogo() { location.reload(); } +function deleteAllFiles() { + var resp = confirm($.i18n._("Are you sure you want to delete all the tracks in your library?")) + if (resp) { + $.post(baseUrl+'Preference/delete-all-files', function(json){}); + location.reload(); + } +} + $(document).ready(function() { $('.collapsible-header').live('click',function() {