~ubuntu-branches/ubuntu/karmic/ampache/karmic

« back to all changes in this revision

Viewing changes to admin/catalog.php

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2008-05-15 18:44:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080515184423-n47i81yk2s99iuci
Tags: 3.4-2
Included some upstream gather album art fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/*
3
3
 
4
 
 Copyright (c) 2001 - 2006 Ampache.org
 
4
 Copyright (c) Ampache.org
5
5
 All rights reserved.
6
6
 
7
7
 This program is free software; you can redistribute it and/or
8
 
 modify it under the terms of the GNU General Public License
9
 
 as published by the Free Software Foundation; either version 2
10
 
 of the License, or (at your option) any later version.
 
8
 modify it under the terms of the GNU General Public License v2
 
9
 as published by the Free Software Foundation.
11
10
 
12
11
 This program is distributed in the hope that it will be useful,
13
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
21
20
*/
22
21
 
23
22
 
24
 
/*!
25
 
        @header Admin Catalog
26
 
        This document handles actions for catalog creation and passes them off to the catalog class
27
 
*/
28
 
 
29
 
require('../lib/init.php');
30
 
 
31
 
if (!$GLOBALS['user']->has_access(100)) {
 
23
require_once '../lib/init.php';
 
24
 
 
25
if (!Access::check('interface','100')) {
32
26
        access_denied();
 
27
        exit; 
33
28
}
34
29
 
35
 
 
36
 
/* Set any vars we are going to need */
37
 
$catalog = new Catalog($_REQUEST['catalog_id']);
38
 
 
39
 
show_template('header');
 
30
show_header(); 
40
31
 
41
32
/* Big switch statement to handle various actions */
42
33
switch ($_REQUEST['action']) {
49
40
                $catalog = new Catalog();
50
41
                $_REQUEST['catalogs'] = $catalog->get_catalog_ids();
51
42
        case 'add_to_catalog':
52
 
                if (conf('demo_mode')) { break; }
 
43
                toggle_visible('ajax-loading'); 
 
44
                ob_end_flush(); 
 
45
                if (Config::get('demo_mode')) { break; }
53
46
                if ($_REQUEST['catalogs'] ) {
54
47
                        foreach ($_REQUEST['catalogs'] as $catalog_id) {
55
 
                                echo "<div class=\"confirmation-box\">";
56
48
                                $catalog = new Catalog($catalog_id);
57
49
                                $catalog->add_to_catalog();
58
 
                                echo "</div>";
59
50
                        }
60
51
                }
61
 
                $url    = conf('web_path') . '/admin/index.php';
 
52
                $url    = Config::get('web_path') . '/admin/index.php';
62
53
                $title  = _('Catalog Updated');
63
54
                $body   = '';
64
55
                show_confirmation($title,$body,$url);
 
56
                toggle_visible('ajax-loading'); 
65
57
        break;
66
58
        case 'update_all_catalogs':
67
 
                $catalog = new Catalog();
68
 
                $_REQUEST['catalogs'] = $catalog->get_catalog_ids();
 
59
                $_REQUEST['catalogs'] = Catalog::get_catalog_ids();
69
60
        case 'update_catalog':
 
61
                toggle_visible('ajax-loading'); 
 
62
                ob_end_flush(); 
70
63
                /* If they are in demo mode stop here */
71
 
                if (conf('demo_mode')) { break; }
 
64
                if (Config::get('demo_mode')) { break; }
72
65
 
73
66
                if (isset($_REQUEST['catalogs'])) {
74
67
                        foreach ($_REQUEST['catalogs'] as $catalog_id) {
75
 
                                echo "<div class=\"confirmation-box\">";
76
 
                                $catalog = new Catalog($catalog_id);
77
 
                                $catalog->verify_catalog($catalog_id->id);
78
 
                                echo "</div>\n";
 
68
                                $catalog = new Catalog($catalog_id); 
 
69
                                $catalog->verify_catalog($catalog_id);
79
70
                        }
80
71
                }
81
 
                $url    = conf('web_path') . '/admin/index.php';
 
72
                $url    = Config::get('web_path') . '/admin/index.php';
82
73
                $title  = _('Catalog Updated');
83
74
                $body   = '';
84
75
                show_confirmation($title,$body,$url);
 
76
                toggle_visible('ajax-loading'); 
85
77
        break;
86
78
        case 'full_service':
87
 
                $catalog = new Catalog();
 
79
                toggle_visible('ajax-loading'); 
 
80
                ob_end_flush(); 
88
81
                /* Make sure they aren't in demo mode */
89
 
                if (conf('demo_mode')) { break; } 
 
82
                if (Config::get('demo_mode')) { access_denied(); break; } 
90
83
 
91
84
                if (!$_REQUEST['catalogs']) { 
92
 
                        $_REQUEST['catalogs'] = $catalog->get_catalog_ids();
 
85
                        $_REQUEST['catalogs'] = Catalog::get_catalog_ids();
93
86
                }
94
87
 
95
88
                /* This runs the clean/verify/add in that order */
96
89
                foreach ($_REQUEST['catalogs'] as $catalog_id) { 
97
 
                        echo "<div class=\"confirmation-box\">";
98
90
                        $catalog = new Catalog($catalog_id);
99
 
                        $catalog->clean_catalog();
100
 
                        $catalog->count = 0;
101
 
                        $catalog->verify_catalog();
102
 
                        $catalog->count = 0;
103
 
                        $catalog->add_to_catalog();
104
 
                        echo "</div>";
 
91
                        $catalog->clean_catalog($catalog_id);
 
92
                        $catalog->count = 0;
 
93
                        $catalog->verify_catalog($catalog_id);
 
94
                        $catalog->count = 0;
 
95
                        $catalog->add_to_catalog($catalog_id);
105
96
                }               
106
 
                $url    = conf('web_path') . '/admin/index.php';
 
97
                $url    = Config::get('web_path') . '/admin/index.php';
107
98
                $title  = _('Catalog Updated');
108
99
                $body   = '';
109
100
                show_confirmation($title,$body,$url);
 
101
                toggle_visible('ajax-loading'); 
110
102
        break;
111
103
        case 'delete_catalog':
112
104
                /* Make sure they aren't in demo mode */
113
 
                if (conf('demo_mode')) { break; }
 
105
                if (Config::get('demo_mode')) { break; }
114
106
        
115
107
                /* Delete the sucker, we don't need to check perms as thats done above */
116
 
                $catalog = new Catalog($_REQUEST['catalog_id']);
117
 
                $catalog->delete_catalog();
118
 
                $next_url = conf('web_path') . '/admin/index.php';
119
 
                show_confirmation(_('Catalog Deleted'),_('The Catalog and all associated records has been deleted'),$nexturl);
 
108
                Catalog::delete($_REQUEST['catalog_id']); 
 
109
                $next_url = Config::get('web_path') . '/admin/index.php';
 
110
                show_confirmation(_('Catalog Deleted'),_('The Catalog and all associated records have been deleted'),$nexturl);
120
111
        break;
121
112
        case 'remove_disabled':
122
113
                if (conf('demo_mode')) { break; }
123
114
 
124
 
                $songs = $_REQUEST['items'];
 
115
                $song = $_REQUEST['song'];
125
116
 
126
 
                if (count($songs)) { 
127
 
                        $catalog->remove_songs($songs);
 
117
                if (count($song)) { 
 
118
                        $catalog->remove_songs($song);
128
119
                        $body = _('Songs Removed');
129
120
                }
130
121
                else {
136
127
        break;
137
128
        case 'clean_all_catalogs':
138
129
                $catalog = new Catalog(); 
139
 
                $_REQUEST['catalogs'] = $catalog->get_catalog_ids();
 
130
                $_REQUEST['catalogs'] = Catalog::get_catalog_ids();
140
131
        case 'clean_catalog':
 
132
                toggle_visible('ajax-loading'); 
 
133
                ob_end_flush(); 
141
134
                /* If they are in demo mode stop them here */
142
 
                if (conf('demo_mode')) { break; }
 
135
                if (Config::get('demo_mode')) { break; }
143
136
        
144
137
                // Make sure they checked something
145
138
                if (isset($_REQUEST['catalogs'])) {     
146
139
                        foreach($_REQUEST['catalogs'] as $catalog_id) { 
147
 
                                echo "<div class=\"confirmation-box\">";
148
140
                                $catalog = new Catalog($catalog_id);
149
141
                                $catalog->clean_catalog(0,1);
150
 
                                echo "</div>";
151
142
                        } // end foreach catalogs
152
143
                }
153
144
                
154
 
                $url    = conf('web_path') . '/admin/index.php';
 
145
                $url    = Config::get('web_path') . '/admin/index.php';
155
146
                $title  = _('Catalog Cleaned');
156
147
                $body   = '';
157
148
                show_confirmation($title,$body,$url);
 
149
                toggle_visible('ajax-loading'); 
158
150
        break;
159
151
        case 'update_catalog_settings':
160
152
                /* No Demo Here! */
161
 
                if (conf('demo_mode')) { break; }
 
153
                if (Config::get('demo_mode')) { break; }
162
154
 
163
155
                /* Update the catalog */
164
 
                $catalog = new Catalog();
165
 
                $catalog->update_settings($_REQUEST);
 
156
                Catalog::update_settings($_REQUEST);
166
157
                
167
 
                $url    = conf('web_path') . '/admin/index.php';
 
158
                $url    = Config::get('web_path') . '/admin/index.php';
168
159
                $title  = _('Catalog Updated');
169
160
                $body   = '';
170
161
                show_confirmation($title,$body,$url);
171
162
        break;
172
 
        // FIXME!
173
163
        case 'add_catalog':
174
164
                /* Wah Demo! */
175
 
                if (conf('demo_mode')) { break; }
 
165
                if (Config::get('demo_mode')) { break; }
 
166
 
 
167
                ob_end_flush(); 
 
168
 
 
169
                if (!strlen($_REQUEST['path']) || !strlen($_REQUEST['name'])) { 
 
170
                        Error::add('general','Error Name and path not specified'); 
 
171
                } 
 
172
 
 
173
                if (substr($_REQUEST['path'],0,7) != 'http://' && $_REQUEST['type'] == 'remote') { 
 
174
                        Error::add('general','Error Remote selected, but path is not a URL'); 
 
175
                } 
176
176
                
177
 
                if ($_REQUEST['path'] AND $_REQUEST['name']) { 
178
 
                        /* Throw all of the album art types into an array */
179
 
                        $art = array('id3'=>$_REQUEST['art_id3v2'],'amazon'=>$_REQUEST['art_amazon'],'folder'=>$_REQUEST['art_folder']);
180
 
 
181
 
                        /* Enclose it in a purrty box! */
182
 
                        echo "<div class=\"confirmation-box\">";
 
177
                if ($_REQUEST['type'] == 'remote' && !strlen($_REQUEST['key'])) { 
 
178
                        Error::add('general','Error Remote Catalog specified, but no key provided'); 
 
179
                } 
 
180
 
 
181
                // If an error hasn't occured
 
182
                if (!Error::$state) { 
 
183
 
 
184
                        $catalog_id = Catalog::Create($_REQUEST); 
 
185
 
 
186
                        if (!$catalog_id) { 
 
187
                                require Config::get('prefix') . '/templates/show_add_catalog.inc.php'; 
 
188
                                break; 
 
189
                        } 
 
190
 
 
191
                        $catalog = new Catalog($catalog_id); 
183
192
                        
184
 
                        /* Create the Catalog */
185
 
                        $catalog->new_catalog($_REQUEST['path'],
186
 
                                        $_REQUEST['name'],
187
 
                                        $_REQUEST['key'],
188
 
                                        $_REQUEST['rename_pattern'],
189
 
                                        $_REQUEST['sort_pattern'],
190
 
                                        $_REQUEST['type'],
191
 
                                        $_REQUEST['gather_art'],
192
 
                                        $_REQUEST['parse_m3u'],
193
 
                                        $art);
194
 
 
195
 
                        echo "</div>\n";
196
 
 
197
 
                        $url = conf('web_path') . '/admin/index.php';
198
 
                        $title = _('Catalog Created');
199
 
                        $body  = _('Catalog Created and Songs Indexed');
200
 
                        show_confirmation($title,$body,$url);
 
193
                        // Run our initial add
 
194
                        $catalog->run_add($_REQUEST); 
 
195
 
 
196
                        show_box_top(); 
 
197
                        echo "<h2>" .  _('Catalog Created') . "</h2>";
 
198
                        Error::display('general'); 
 
199
                        Error::display('catalog_add'); 
 
200
                        show_box_bottom(); 
 
201
 
 
202
                        show_confirmation('','','/admin/index.php'); 
 
203
 
201
204
                }
202
205
                else {
203
 
                        $error = "Please complete the form.";
204
 
                        include(conf('prefix') . '/templates/show_add_catalog.inc.php');
 
206
                        require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
205
207
                }
206
208
        break;
207
209
        case 'clear_stats':
208
 
                if (conf('demo_mode')) { break; }
 
210
                if (Config::get('demo_mode')) { access_denied(); break; }
209
211
                
210
 
                clear_catalog_stats();
211
 
                $url    = conf('web_path') . '/admin/index.php';
 
212
                Catalog::clear_stats(); 
 
213
                $url    = Config::get('web_path') . '/admin/index.php';
212
214
                $title  = _('Catalog statistics cleared');
213
215
                $body   = '';
214
216
                show_confirmation($title,$body,$url);
215
217
        break;
 
218
        case 'show_catalogs': 
 
219
                $catalog_ids = Catalog::get_catalogs(); 
 
220
                Browse::set_type('catalog'); 
 
221
                Browse::set_static_content(1); 
 
222
                Browse::save_objects($catalog_ids); 
 
223
                Browse::show_objects($catalog_ids); 
 
224
        break;
216
225
        case 'show_add_catalog':
217
 
                include(conf('prefix') . '/templates/show_add_catalog.inc.php');
 
226
                require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
218
227
        break;
219
228
        case 'clear_now_playing':
220
 
                if (conf('demo_mode')) { break; }
221
 
                clear_now_playing();
222
 
                show_confirmation(_('Now Playing Cleared'),_('All now playing data has been cleared'),conf('web_path') . '/admin/index.php');
223
 
        break;
224
 
        case 'show_clear_stats':
225
 
                /* Demo Bad! */
226
 
                if (conf('demo_mode')) { break; }
227
 
 
228
 
                $url    = conf('web_path') . '/admin/catalog.php?action=clear_stats';
229
 
                $body   = _('Do you really want to clear the statistics for this catalog?');
230
 
                $title  = _('Clear Catalog Stats'); 
231
 
                show_confirmation($title,$body,$url,1);
 
229
                if (Config::get('demo_mode')) { access_denied(); break; }
 
230
                Stream::clear_now_playing();
 
231
                show_confirmation(_('Now Playing Cleared'),_('All now playing data has been cleared'),Config::get('web_path') . '/admin/index.php');
232
232
        break;
233
233
        case 'show_disabled':
234
234
                if (conf('demo_mode')) { break; }
235
235
                
236
236
                $songs = $catalog->get_disabled();
237
237
                if (count($songs)) { 
238
 
                        require (conf('prefix') . '/templates/show_disabled_songs.inc');
 
238
                        require (conf('prefix') . '/templates/show_disabled_songs.inc.php');
239
239
                }
240
240
                else {
241
241
                        echo "<div class=\"error\" align=\"center\">" . _('No Disabled songs found') . "</div>";
243
243
        break;
244
244
        case 'show_delete_catalog':
245
245
                /* Stop the demo hippies */
246
 
                if (conf('demo_mode')) { break; }
 
246
                if (Config::get('demo_mode')) { access_denied(); break; } 
 
247
 
247
248
                $catalog = new Catalog($_REQUEST['catalog_id']);        
248
 
                $nexturl = conf('web_path') . '/admin/catalog.php?action=delete_catalog&amp;catalog_id=' . scrub_out($_REQUEST['catalog_id']);
 
249
                $nexturl = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&amp;catalog_id=' . scrub_out($_REQUEST['catalog_id']);
249
250
                show_confirmation(_('Delete Catalog'),_('Do you really want to delete this catalog?') . " -- $catalog->name ($catalog->path)",$nexturl,1);
250
251
        break;
251
252
        case 'show_customize_catalog':
252
 
                include(conf('prefix') . '/templates/show_edit_catalog.inc.php');
 
253
                $catalog = new Catalog($_REQUEST['catalog_id']); 
 
254
                require_once Config::get('prefix') . '/templates/show_edit_catalog.inc.php';
253
255
        break;
254
256
        case 'gather_album_art':
255
 
                flush();
256
 
                $catalogs = $catalog->get_catalogs();
257
 
                foreach ($catalogs as $data) { 
258
 
                        echo "<div class=\"confirmation-box\"><b>" . _('Starting Album Art Search') . ". . .</b><br /><br />\n";
259
 
                        echo _('Searched') . ": <span id=\"count_art_" . $data->id . "\">" . _('None') . "</span><br />";
260
 
                        $data->get_album_art(0,1);
261
 
                        echo "<b>" . _('Album Art Search Finished') . ". . .</b></div>\n";
 
257
                toggle_visible('ajax-loading'); 
 
258
                ob_end_flush(); 
 
259
 
 
260
                $catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs();
 
261
 
 
262
                // Itterate throught the catalogs and gather as needed
 
263
                foreach ($catalogs as $catalog_id) { 
 
264
                        $catalog = new Catalog($catalog_id);
 
265
                        require Config::get('prefix') . '/templates/show_gather_art.inc.php'; 
 
266
                        flush(); 
 
267
                        $catalog->get_album_art('',1);
262
268
                }
263
 
                $url    = conf('web_path') . '/admin/index.php';
 
269
                $url    = Config::get('web_path') . '/admin/index.php';
264
270
                $title  = _('Album Art Search Finished');
265
271
                $body   = '';
266
272
                show_confirmation($title,$body,$url);