summaryrefslogtreecommitdiffstats
path: root/lib/ui.php
blob: bd1bb8821364f989b3d0c3cd5e4f54a8c625e730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?php
/*

 Copyright (c) 2001 - 2005 Ampache.org
 All rights reserved.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
/*!
	@header UI Function Library
	This contains functions that are generic, and display information
	things like a confirmation box, etc and so forth
*/

/*!
	@function show_confirmation
	@discussion shows a confirmation of an action
	@param $next_url	Where to go next
	@param $title		The Title of the message
	@param $text		The details of the message
*/
function show_confirmation($title,$text,$next_url) {
	
	if (substr_count($next_url,conf('web_path'))) { 
		$path = $next_url;
	}
	else {
		$path = conf('web_path') . "/$next_url";
	}

	require (conf('prefix') . "/templates/show_confirmation.inc.php");

} // show_confirmation

/*!
	@function set_preferences
	@discussion legacy function...
	//FIXME: Remove References
*/
function set_preferences() { 

	get_preferences();
	return true;

} // set_preferences

/*!
	@function get_preferences
	@discussion reads this users preferences
*/
function get_preferences($username=0) {

	/* Get System Preferences first */
	$sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='0' " .
		" AND user_preference.preference = preferences.id AND preferences.type='system'";
	$db_results = mysql_query($sql, dbh());

	while ($r = mysql_fetch_object($db_results)) { 
		$results[$r->name] = $r->value;
	} // end while sys prefs

	conf($results, 1);

	unset($results);
	
	if (!$username) { $username = $_SESSION['userdata']['username']; }

	$user = new User($username);

	$sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user->id'" .
		" AND user_preference.preference=preferences.id";
	$db_results = mysql_query($sql, dbh());

	while ($r = mysql_fetch_object($db_results)) { 
		$results[$r->name] = $r->value;
	}

	unset($results['user'], $results['id']);

	conf($results, 1);

} // get_preferences

/*!
	@function flip_class
	@discussion takes an array of 2 class names
		and flips them back and forth and
		then echo's out [0]
*/
function flip_class($array=0) {

	static $classes = array();

	if ($array) { 
		$classes = $array;
	}
	else {
		$classes = array_reverse($classes);
		return $classes[0];
	}

} // flip_class

/*!
	@function clear_now_playing
	@discussion Clears the now playing information incase something has
		gotten stuck in there
*/
function clear_now_playing() { 

	$sql = "DELETE FROM now_playing";
	$db_results = mysql_query($sql, dbh());
	
	return true;

} // clear_now_playing

/*!
	@function show_tool_box
	@discussion shows the toolbox
*/
function show_tool_box ($title, $items) {

        include(conf('prefix') . "/templates/tool_box.inc");
	
}// show_tool_box

/*!
	@function show_box
	@discussion shows a generic box
*/
function show_box($title,$items) { 

	include(conf('prefix') . "/templates/show_box.inc");

} // show_box

/*!	
	@function show_menu_items
	@discussion shows menu items
*/
function show_menu_items ($high) {

        include(conf('prefix') . "/templates/menu.inc");
	
} // show_menu_items

/*!
	@function _
	@discussion checks to see if the alias _ is defined
		if it isn't it defines it as a simple return
*/
if (!function_exists('_')) { 
	function _($string) { 

		return $string;

	} // _
} // if _ isn't defined

/*!
        @function show_playlist_menu
        @discussion playlist functions
*/
function show_playlist_menu () {

        echo "<br /><span class=\"header2\">" . _("Playlist Actions") . ": <a href=\"" . conf('web_path') . "/playlist.php?action=new\">" . _("New") ."</a> | ";
        echo "<a href=\"" . conf('web_path') . "/playlist.php\"> " . _("View All") . "</a> | ";
	echo "<a href=\"" . conf('web_path') . "/playlist.php?action=show_import_playlist\"> " . _("Import") . "</a>";
        echo "</span><br /><br />";
	
} // show_playlist_menu

/*!
	@function show_admin_menu
	@discussion shows the admin menu
*/
function show_admin_menu ($admin_highlight) {
        include(conf('prefix') . "/templates/admin_menu.inc");
} // show_admin_menu

/*!
	@function access_denied
	@discussion throws an error if they try to do something
		that they aren't allowed to
*/
function access_denied() { 

	show_template('style');
	show_footer();
	echo "<br /><br /><br />";
        echo "<div class=\"fatalerror\">Error Access Denied</div>\n";
	show_footer();
	exit();

} // access_denied

/*!
	@function show_users
	@discussion shows all users (admin function)
*/
function show_users () {

        $dbh = dbh();

        // Setup the View Ojbect
        $view = new View();
        $view->import_session_view();

        // if we are returning
        if ($_REQUEST['keep_view']) { 
                $view->initialize();
        }
        // If we aren't keeping the view then initlize it
        else {
        	$sql = "SELECT username FROM user";
                $db_results = mysql_query($sql, $dbh);
                $total_items = mysql_num_rows($db_results);
                if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; }
                $view = new View($sql, 'admin/users.php','fullname',$total_items,$offset_limit); 
        } 

        $db_result = mysql_query($view->sql, $dbh);

        require(conf('prefix') . "/templates/show_users.inc");

} // show_users()


/*!
	@function return_referer
	@discussion returns the script part of the 
		referer address passed by the web browser
		this is not %100 accurate
*/
function return_referer() { 

	$web_path = substr(conf('web_path'),0,strlen(conf('web_path'))-1-strlen($_SERVER['SERVER_PORT'])) . "/";
	$next = str_replace($web_path,"",$_SERVER['HTTP_REFERER']);

	// If there is more than one :// we know it's fudged
	// and just return the index
	if (substr_count($next,"://") > 1) { 
		return "index.php";
	}

	return $next;

} // return_referer

/*!
	@function show_alphabet_list
	@discussion shows the A-Z,0-9 lists for 
		albums and artist pages
*/
function show_alphabet_list ($type,$script="artist.php",$selected="false") {

        $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0");

        $style_name = "style_" . strtolower($selected);
	${$style_name} = "style=\"font-weight:bold;\"";

        echo "<div class=\"alphabet\">";
        foreach ($list as $l) {
		$style_name = "style_" . strtolower($l);
                echo "<a href=\"". conf('web_path') ."/$script?action=match&amp;match=$l\" " . ${$style_name} . ">$l</a> | \n";
        }
	
	echo " <a href=\"". conf('web_path') ."/$script?action=match&amp;match=Browse\" $style_browse>" . _("Browse") . "</a> | \n";
        if ($script == "albums.php") {
                echo " <a href=\"". conf('web_path') ."/$script?action=match&amp;match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n";
        } // if we are on the albums page
	
        echo " <a href=\"". conf('web_path') ."/$script?action=match&amp;match=Show_all\" $style_show_all>" . _("Show all") . "</a>";
	
        echo "</div>\n";
} // show_alphabet_list

/*!
	@function show_local_control
	@discussion shows the controls
		for localplay
*/
function show_local_control () {

        require_once(conf('prefix') . "/templates/show_localplay.inc");

} // show_local_control

/*!
	@function truncate_with_ellipse
	@discussion truncates a text file to specified length by adding
		thre dots (ellipse) to the end
		(Thx Nedko Arnaudov)
*/
function truncate_with_ellipse($text, $max=27) {

	/* If we want it to be shorter than three, just throw it back */
	if ($max > 3) {
		/* Make sure the functions exist before doing the iconv mojo */
		if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) {
	                if (iconv_strlen($text, conf('site_charset')) > $max) {
        	                $text = iconv_substr($text, 0, $max-3, conf('site_charset'));
	                        $text .= iconv("ISO-8859-1", conf('site_charset'), "...");
	                }
                }
		/* Do normal substr if we don't have iconv */
                else {
                        if (strlen($text) > $max) {
                                $text = substr($text,0,$max-3)."...";
                        }
                } // else no iconv
        } // else greater than 3
 
        return $text;
} // truncate_with_ellipse

/*!
	@function show_footer
	@discussion shows the footer of the page
*/
function show_footer() {
        $class = "table-header";
        echo "<br /><br /><br /><div class=\"$class\" style=\"border: solid thin black;\">&nbsp</div>";
} // show_footer

/*!
	@function show_now_playing
	@discussion shows the now playing template
*/
function show_now_playing() { 

        $dbh = dbh();
        $web_path = conf('web_path');
	$results = get_now_playing();
        require (conf('prefix') . "/templates/show_now_playing.inc");

} // show_now_playing

/*!
	@function show_user_registration
	@discussion this function is called for a new user
		registration
	@author Terry
*/
//function show_user_registration ($id, $username, $fullname, $email, $access, $type, $error) {
//FIXME: See above
function show_user_registration ($values=array()) { 

	require (conf('prefix') . "/templates/show_user_registration.inc.php");

} // show_user_registration

/*!
	@function show_edit_profile
	@discussion shows a single user profile for editing
*/
function show_edit_profile($username) { 

	$this_user = new User($username);

	require (conf('prefix') . "/templates/show_user.inc.php");
	
} // show_edit_profile

/*!
	@function show_playlist
	@discussion this shows the current playlist
*/
function show_playlist($playlist_id) { 

	/* Create the Playlist */
	$playlist = new Playlist($playlist_id);
        $song_ids = $playlist->get_songs();

        if (count($song_ids) > 0) {
                show_songs($song_ids, $playlist->id);
        }
        else {
                echo "<p>" . _("No songs in this playlist.") . "</p>\n";
        }

} // show_playlist

/*!
	@function show_play_selected
	@discussion this shows the playselected/add to playlist 
		box, which includes a little javascript
*/
function show_play_selected() { 

	require (conf('prefix') . "/templates/show_play_selected.inc.php");

} // show_play_selected

/*!
	@function get_now_playing
	@discussion gets the now playing information
*/
function get_now_playing() {

	$sql = "SELECT song_id,user_id FROM now_playing ORDER BY start_time DESC";
	$db_results = mysql_query($sql, dbh());
	while ($r = mysql_fetch_assoc($db_results)) { 
		$song = new Song($r['song_id']);
		$song->format_song();
		$np_user = new User(0,$r['user_id']);
		$results[] = array('song'=>$song,'user'=>$np_user);
	} // end while
	return $results;

} // get_now_playing

/*!
	@function show_clear
	@discussion this is a hack because of the float mojo
*/
function show_clear() { 

	echo "\n<div style=\"clear:both;\">&nbsp;</div>\n";

} // show_clear

?>