20
18
* along with this program; if not, write to the Free Software
21
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
* @copyright 2001 - 2011 Ampache.org
25
* @license http://opensource.org/licenses/gpl-2.0 GPLv2
26
* @link http://www.ampache.org/
29
23
require_once '../lib/init.php';
31
25
if (!Access::check('interface','100')) {
38
32
/* Big switch statement to handle various actions */
39
33
switch ($_REQUEST['action']) {
41
/* Does this use now? */
42
delete_flagged($flag);
43
$type = 'show_flagged_songs';
44
include(conf('prefix') . '/templates/flag.inc');
46
case 'add_to_all_catalogs':
47
$catalog = new Catalog();
48
$_REQUEST['catalogs'] = $catalog->get_catalog_ids();
49
case 'add_to_catalog':
50
toggle_visible('ajax-loading');
52
if (Config::get('demo_mode')) { break; }
53
if ($_REQUEST['catalogs'] ) {
54
foreach ($_REQUEST['catalogs'] as $catalog_id) {
55
$catalog = new Catalog($catalog_id);
56
$catalog->add_to_catalog();
59
$url = Config::get('web_path') . '/admin/catalog.php';
60
$title = T_('Catalog Updated');
62
show_confirmation($title,$body,$url);
63
toggle_visible('ajax-loading');
65
case 'update_all_catalogs':
66
$_REQUEST['catalogs'] = Catalog::get_catalog_ids();
67
case 'update_catalog':
68
toggle_visible('ajax-loading');
70
/* If they are in demo mode stop here */
71
if (Config::get('demo_mode')) { break; }
73
if (isset($_REQUEST['catalogs'])) {
74
foreach ($_REQUEST['catalogs'] as $catalog_id) {
75
$catalog = new Catalog($catalog_id);
76
$catalog->verify_catalog();
79
$url = Config::get('web_path') . '/admin/catalog.php';
80
$title = T_('Catalog Updated');
82
show_confirmation($title,$body,$url);
83
toggle_visible('ajax-loading');
86
toggle_visible('ajax-loading');
88
/* Make sure they aren't in demo mode */
89
if (Config::get('demo_mode')) { access_denied(); break; }
91
if (!$_REQUEST['catalogs']) {
92
$_REQUEST['catalogs'] = Catalog::get_catalog_ids();
95
/* This runs the clean/verify/add in that order */
96
foreach ($_REQUEST['catalogs'] as $catalog_id) {
97
$catalog = new Catalog($catalog_id);
98
$catalog->clean_catalog();
100
$catalog->verify_catalog();
102
$catalog->add_to_catalog();
104
Catalog::optimize_tables();
105
$url = Config::get('web_path') . '/admin/catalog.php';
106
$title = T_('Catalog Updated');
108
show_confirmation($title,$body,$url);
109
toggle_visible('ajax-loading');
111
case 'delete_catalog':
112
/* Make sure they aren't in demo mode */
113
if (Config::get('demo_mode')) { break; }
115
if (!Core::form_verify('delete_catalog')) {
120
/* Delete the sucker, we don't need to check perms as thats done above */
121
Catalog::delete($_GET['catalog_id']);
122
$next_url = Config::get('web_path') . '/admin/catalog.php';
123
show_confirmation(T_('Catalog Deleted'), T_('The Catalog and all associated records have been deleted'),$next_url);
125
case 'show_delete_catalog':
126
$catalog_id = scrub_in($_GET['catalog_id']);
128
$next_url = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($catalog_id);
129
show_confirmation(T_('Catalog Delete'), T_('Confirm Deletion Request'),$next_url,1,'delete_catalog');
131
case 'remove_disabled':
132
if (conf('demo_mode')) { break; }
134
$song = $_REQUEST['song'];
137
$catalog->remove_songs($song);
138
$body = T_ngettext('Song Removed', 'Songs Removed', count($song));
141
$body = T_('No Songs Removed');
143
$url = Config::get('web_path') . '/admin/catalog.php';
144
$title = T_ngettext('Disabled Song Processed','Disabled Songs Processed',count($song));
145
show_confirmation($title,$body,$url);
147
case 'clean_all_catalogs':
148
$catalog = new Catalog();
149
$_REQUEST['catalogs'] = Catalog::get_catalog_ids();
150
case 'clean_catalog':
151
toggle_visible('ajax-loading');
153
/* If they are in demo mode stop them here */
154
if (Config::get('demo_mode')) { break; }
156
// Make sure they checked something
157
if (isset($_REQUEST['catalogs'])) {
158
foreach($_REQUEST['catalogs'] as $catalog_id) {
159
$catalog = new Catalog($catalog_id);
160
$catalog->clean_catalog();
161
} // end foreach catalogs
162
Catalog::optimize_tables();
165
$url = Config::get('web_path') . '/admin/catalog.php';
166
$title = T_('Catalog Cleaned');
168
show_confirmation($title,$body,$url);
169
toggle_visible('ajax-loading');
171
case 'update_catalog_settings':
173
if (Config::get('demo_mode')) { break; }
175
/* Update the catalog */
176
Catalog::update_settings($_POST);
178
$url = Config::get('web_path') . '/admin/catalog.php';
179
$title = T_('Catalog Updated');
181
show_confirmation($title,$body,$url);
184
if (Config::get('demo_mode')) { break; }
186
// First see if we need to do an add
187
if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) {
188
if ($catalog_id = Catalog::get_from_path($_POST['add_path'])) {
189
$catalog = new Catalog($catalog_id);
190
$catalog->run_add(array('subdirectory'=>$_POST['add_path']));
194
// Now check for an update
195
if ($_POST['update_path'] != '/' AND strlen($_POST['update_path'])) {
196
if ($catalog_id = Catalog::get_from_path($_POST['update_path'])) {
197
$songs = Song::get_from_path($_POST['update_path']);
198
foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); }
205
if (Config::get('demo_mode')) { break; }
209
if (!strlen($_POST['path']) || !strlen($_POST['name'])) {
210
Error::add('general', T_('Error: Name and path not specified'));
213
if (substr($_POST['path'],0,7) != 'http://' && $_POST['type'] == 'remote') {
214
Error::add('general', T_('Error: Remote selected, but path is not a URL'));
216
if ($POST['type'] == 'remote' AND (!strlen($POST['remote_username']) OR !strlen($POST['remote_password']))) {
217
Error::add('general', T_('Error: Username and Password Required for Remote Catalogs'));
220
if (!Core::form_verify('add_catalog','post')) {
225
// Make sure that there isn't a catalog with a directory above this one
226
if (Catalog::get_from_path($_POST['path'])) {
227
Error::add('general', T_('Error: Defined Path is inside an existing catalog'));
230
// If an error hasn't occured
231
if (!Error::occurred()) {
233
$catalog_id = Catalog::Create($_POST);
236
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
240
$catalog = new Catalog($catalog_id);
242
// Run our initial add
243
$catalog->run_add($_POST);
245
show_box_top(T_('Catalog Created'), 'box box_catalog_created');
246
echo "<h2>" . T_('Catalog Created') . "</h2>";
247
Error::display('general');
248
Error::display('catalog_add');
251
show_confirmation('','', Config::get('web_path').'/admin/catalog.php');
255
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
259
if (Config::get('demo_mode')) { access_denied(); break; }
261
Catalog::clear_stats();
262
$url = Config::get('web_path') . '/admin/catalog.php';
263
$title = T_('Catalog statistics cleared');
265
show_confirmation($title,$body,$url);
268
case 'show_catalogs':
269
require_once Config::get('prefix') . '/templates/show_manage_catalogs.inc.php';
271
case 'show_add_catalog':
272
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
274
case 'clear_now_playing':
275
if (Config::get('demo_mode')) { access_denied(); break; }
276
Stream::clear_now_playing();
277
show_confirmation(T_('Now Playing Cleared'), T_('All now playing data has been cleared'),Config::get('web_path') . '/admin/catalog.php');
279
case 'show_disabled':
280
/* Stop the demo hippies */
281
if (conf('demo_mode')) { break; }
283
$songs = $catalog->get_disabled();
285
require (conf('prefix') . '/templates/show_disabled_songs.inc.php');
288
echo "<div class=\"error\" align=\"center\">" . T_('No Disabled songs found') . "</div>";
291
case 'show_delete_catalog':
292
/* Stop the demo hippies */
293
if (Config::get('demo_mode')) { access_denied(); break; }
295
$catalog = new Catalog($_REQUEST['catalog_id']);
296
$nexturl = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($_REQUEST['catalog_id']);
297
show_confirmation(T_('Delete Catalog'), T_('Do you really want to delete this catalog?') . " -- $catalog->name ($catalog->path)",$nexturl,1);
299
case 'show_customize_catalog':
300
$catalog = new Catalog($_REQUEST['catalog_id']);
301
require_once Config::get('prefix') . '/templates/show_edit_catalog.inc.php';
303
case 'gather_album_art':
304
toggle_visible('ajax-loading');
307
$catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs();
309
// Itterate throught the catalogs and gather as needed
310
foreach ($catalogs as $catalog_id) {
311
$catalog = new Catalog($catalog_id);
312
require Config::get('prefix') . '/templates/show_gather_art.inc.php';
314
$catalog->get_art('',1);
316
$url = Config::get('web_path') . '/admin/catalog.php';
317
$title = T_('Album Art Search Finished');
319
show_confirmation($title,$body,$url);
35
/* Does this use now? */
36
delete_flagged($flag);
37
$type = 'show_flagged_songs';
38
require Config::get('prefix') . '/templates/flag.inc';
40
case 'add_to_all_catalogs':
41
$_REQUEST['catalogs'] = Catalog::get_catalogs();
42
case 'add_to_catalog':
43
toggle_visible('ajax-loading');
45
if (Config::get('demo_mode')) { break; }
46
if ($_REQUEST['catalogs'] ) {
47
foreach ($_REQUEST['catalogs'] as $catalog_id) {
48
$catalog = new Catalog($catalog_id);
49
$catalog->add_to_catalog();
52
$url = Config::get('web_path') . '/admin/catalog.php';
53
$title = T_('Catalog Updated');
55
show_confirmation($title, $body, $url);
56
toggle_visible('ajax-loading');
58
case 'update_all_catalogs':
59
$_REQUEST['catalogs'] = Catalog::get_catalogs();
60
case 'update_catalog':
61
toggle_visible('ajax-loading');
63
/* If they are in demo mode stop here */
64
if (Config::get('demo_mode')) { break; }
66
if (isset($_REQUEST['catalogs'])) {
67
foreach ($_REQUEST['catalogs'] as $catalog_id) {
68
$catalog = new Catalog($catalog_id);
69
$catalog->verify_catalog();
72
$url = Config::get('web_path') . '/admin/catalog.php';
73
$title = T_('Catalog Updated');
75
show_confirmation($title,$body,$url);
76
toggle_visible('ajax-loading');
79
toggle_visible('ajax-loading');
81
/* Make sure they aren't in demo mode */
82
if (Config::get('demo_mode')) { UI::access_denied(); break; }
84
if (!$_REQUEST['catalogs']) {
85
$_REQUEST['catalogs'] = Catalog::get_catalogs();
88
/* This runs the clean/verify/add in that order */
89
foreach ($_REQUEST['catalogs'] as $catalog_id) {
90
$catalog = new Catalog($catalog_id);
91
$catalog->clean_catalog();
93
$catalog->verify_catalog();
95
$catalog->add_to_catalog();
97
Dba::optimize_tables();
98
$url = Config::get('web_path') . '/admin/catalog.php';
99
$title = T_('Catalog Updated');
101
show_confirmation($title,$body,$url);
102
toggle_visible('ajax-loading');
104
case 'delete_catalog':
105
/* Make sure they aren't in demo mode */
106
if (Config::get('demo_mode')) { break; }
108
if (!Core::form_verify('delete_catalog')) {
113
/* Delete the sucker, we don't need to check perms as thats done above */
114
Catalog::delete($_GET['catalog_id']);
115
$next_url = Config::get('web_path') . '/admin/catalog.php';
116
show_confirmation(T_('Catalog Deleted'), T_('The Catalog and all associated records have been deleted'),$next_url);
118
case 'show_delete_catalog':
119
$catalog_id = scrub_in($_GET['catalog_id']);
121
$next_url = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($catalog_id);
122
show_confirmation(T_('Catalog Delete'), T_('Confirm Deletion Request'),$next_url,1,'delete_catalog');
124
case 'remove_disabled':
125
if (Config::get('demo_mode')) { break; }
127
$song = $_REQUEST['song'];
130
$catalog->remove_songs($song);
131
$body = T_ngettext('Song Removed', 'Songs Removed', count($song));
134
$body = T_('No Songs Removed');
136
$url = Config::get('web_path') . '/admin/catalog.php';
137
$title = T_ngettext('Disabled Song Processed','Disabled Songs Processed',count($song));
138
show_confirmation($title,$body,$url);
140
case 'clean_all_catalogs':
141
$catalog = new Catalog();
142
$_REQUEST['catalogs'] = Catalog::get_catalogs();
143
case 'clean_catalog':
144
toggle_visible('ajax-loading');
146
/* If they are in demo mode stop them here */
147
if (Config::get('demo_mode')) { break; }
149
// Make sure they checked something
150
if (isset($_REQUEST['catalogs'])) {
151
foreach($_REQUEST['catalogs'] as $catalog_id) {
152
$catalog = new Catalog($catalog_id);
153
$catalog->clean_catalog();
154
} // end foreach catalogs
155
Dba::optimize_tables();
158
$url = Config::get('web_path') . '/admin/catalog.php';
159
$title = T_('Catalog Cleaned');
161
show_confirmation($title,$body,$url);
162
toggle_visible('ajax-loading');
164
case 'update_catalog_settings':
166
if (Config::get('demo_mode')) { break; }
168
/* Update the catalog */
169
Catalog::update_settings($_POST);
171
$url = Config::get('web_path') . '/admin/catalog.php';
172
$title = T_('Catalog Updated');
174
show_confirmation($title,$body,$url);
177
if (Config::get('demo_mode')) { break; }
179
// First see if we need to do an add
180
if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) {
181
if ($catalog_id = Catalog::get_from_path($_POST['add_path'])) {
182
$catalog = new Catalog($catalog_id);
183
$catalog->run_add(array('subdirectory'=>$_POST['add_path']));
187
// Now check for an update
188
if ($_POST['update_path'] != '/' AND strlen($_POST['update_path'])) {
189
if ($catalog_id = Catalog::get_from_path($_POST['update_path'])) {
190
$songs = Song::get_from_path($_POST['update_path']);
191
foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); }
198
if (Config::get('demo_mode')) { break; }
202
if (!strlen($_POST['path']) || !strlen($_POST['name'])) {
203
Error::add('general', T_('Error: Name and path not specified'));
206
if (substr($_POST['path'],0,7) != 'http://' && $_POST['type'] == 'remote') {
207
Error::add('general', T_('Error: Remote selected, but path is not a URL'));
209
if ($POST['type'] == 'remote' AND (!strlen($POST['remote_username']) OR !strlen($POST['remote_password']))) {
210
Error::add('general', T_('Error: Username and Password Required for Remote Catalogs'));
213
if (!Core::form_verify('add_catalog','post')) {
218
// Make sure that there isn't a catalog with a directory above this one
219
if (Catalog::get_from_path($_POST['path'])) {
220
Error::add('general', T_('Error: Defined Path is inside an existing catalog'));
223
// If an error hasn't occured
224
if (!Error::occurred()) {
226
$catalog_id = Catalog::create($_POST);
229
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
233
$catalog = new Catalog($catalog_id);
235
// Run our initial add
236
$catalog->run_add($_POST);
238
UI::show_box_top(T_('Catalog Created'), 'box box_catalog_created');
239
echo "<h2>" . T_('Catalog Created') . "</h2>";
240
Error::display('general');
241
Error::display('catalog_add');
242
UI::show_box_bottom();
244
show_confirmation('','', Config::get('web_path').'/admin/catalog.php');
248
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
252
if (Config::get('demo_mode')) { UI::access_denied(); break; }
254
$url = Config::get('web_path') . '/admin/catalog.php';
255
$title = T_('Catalog statistics cleared');
257
show_confirmation($title, $body, $url);
260
case 'show_catalogs':
261
require_once Config::get('prefix') . '/templates/show_manage_catalogs.inc.php';
263
case 'show_add_catalog':
264
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
266
case 'clear_now_playing':
267
if (Config::get('demo_mode')) { UI::access_denied(); break; }
268
Stream::clear_now_playing();
269
show_confirmation(T_('Now Playing Cleared'), T_('All now playing data has been cleared'),Config::get('web_path') . '/admin/catalog.php');
271
case 'show_disabled':
272
/* Stop the demo hippies */
273
if (Config::get('demo_mode')) { break; }
275
$songs = Song::get_disabled();
277
require Config::get('prefix') . '/templates/show_disabled_songs.inc.php';
280
echo "<div class=\"error\" align=\"center\">" . T_('No Disabled songs found') . "</div>";
283
case 'show_delete_catalog':
284
/* Stop the demo hippies */
285
if (Config::get('demo_mode')) { UI::access_denied(); break; }
287
$catalog = new Catalog($_REQUEST['catalog_id']);
288
$nexturl = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($_REQUEST['catalog_id']);
289
show_confirmation(T_('Delete Catalog'), T_('Do you really want to delete this catalog?') . " -- $catalog->name ($catalog->path)",$nexturl,1);
291
case 'show_customize_catalog':
292
$catalog = new Catalog($_REQUEST['catalog_id']);
293
require_once Config::get('prefix') . '/templates/show_edit_catalog.inc.php';
295
case 'gather_album_art':
296
toggle_visible('ajax-loading');
299
$catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs();
301
// Iterate throught the catalogs and gather as needed
302
foreach ($catalogs as $catalog_id) {
303
$catalog = new Catalog($catalog_id);
304
require Config::get('prefix') . '/templates/show_gather_art.inc.php';
306
$catalog->gather_art();
308
$url = Config::get('web_path') . '/admin/catalog.php';
309
$title = T_('Album Art Search Finished');
311
show_confirmation($title,$body,$url);
323
315
/* Show the Footer */