summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/tmpplaylist.class.php (renamed from lib/class/tmp_playlist.class.php)39
-rw-r--r--lib/class/user.class.php14
-rw-r--r--lib/gettext.php14
-rw-r--r--lib/init.php3
-rw-r--r--templates/header.inc.php5
-rw-r--r--templates/show_playlist_bar.inc.php25
6 files changed, 99 insertions, 1 deletions
diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmpplaylist.class.php
index 30b66ecc..562132fc 100644
--- a/lib/class/tmp_playlist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -74,6 +74,30 @@ class tmpPlaylist {
} // _get_info
/**
+ * get_from_session
+ * This returns a playlist object based on the session that is passed to us
+ * this is used by the load_playlist on user for the most part
+ */
+ public static function get_from_session($session_id) {
+
+ $session_id = Dba::escape($session_id);
+
+ $sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
+ $db_results = Dba::query($sql);
+
+ $results = Dba::fetch_row($db_results);
+
+ if (!$results['0']) {
+ $results['0'] = tmpPlaylist::create($session_id,'user','song','0');
+ }
+
+ $playlist = new tmpPlaylist($results['0']);
+
+ return $playlist;
+
+ } // get_from_session
+
+ /**
* get_items
* This returns an array of all object_ids currently in this tmpPlaylist
*/
@@ -163,6 +187,21 @@ class tmpPlaylist {
} // get_vote_url
+ /**
+ * count_items
+ * This returns a count of the total number of tracks that are in this tmp playlist
+ */
+ public function count_items() {
+
+ $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
+ $db_results = Dba::query($sql);
+
+ $results = Dba::fetch_row($db_results);
+
+ return $results['0'];
+
+ } // count_items
+
/**
* create
* This function initializes a new tmpPlaylist it is assoicated with the current
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index c446e4d6..990a27ce 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -83,6 +83,20 @@ class User {
} // _get_info
/**
+ * load_playlist
+ * This is called once per page load it makes sure that this session
+ * has a tmp_playlist, creating it if it doesn't, then sets $this->playlist
+ * as a tmp_playlist object that can be fiddled with later on
+ */
+ public function load_playlist() {
+
+ $session_id = session_id();
+
+ $this->playlist = tmpPlaylist::get_from_session($session_id);
+
+ } // load_playlist
+
+ /**
* get_from_username
* This returns a built user from a username. This is a
* static function so it doesn't require an instance
diff --git a/lib/gettext.php b/lib/gettext.php
index ed929241..0052a247 100644
--- a/lib/gettext.php
+++ b/lib/gettext.php
@@ -49,5 +49,19 @@ function load_gettext() {
} // load_gettext
+/**
+ * __
+ * This function does the same as _ on the supplied
+ * string, but also does a str_replace on the supplied
+ * vars
+ */
+function __($string,$subject,$replace) {
+
+ $translated = _($string);
+ $result = str_replace($subject,$replace,$translated);
+ return $result;
+
+} // __
+
?>
diff --git a/lib/init.php b/lib/init.php
index 68a6db21..3a72f40a 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -225,6 +225,9 @@ else {
// Load the Preferences from the database
init_preferences();
+// We need to create the tmp playlist for our user
+$GLOBALS['user']->load_playlist();
+
/* Add in some variables for ajax done here because we need the user */
Config::set('ajax_url',Config::get('web_path') . '/server/ajax.server.php',1);
diff --git a/templates/header.inc.php b/templates/header.inc.php
index 3ce776bf..08cbaa6c 100644
--- a/templates/header.inc.php
+++ b/templates/header.inc.php
@@ -64,12 +64,15 @@ if (Config::get('use_rss')) { ?>
</a>
</div><!--End topbarleft -->
<div id="topbarright">
+ <?php show_box_top(); ?>
<a href="http://www.ampache.org/index.php">Ampache v.<?php echo Config::get('version'); ?></a><br />
<b><?php echo _('You are currently logged in as') . " " . $GLOBALS['user']->fullname; ?></b>
+ <div id="topbar-playlist"><?php require_once Config::get('prefix') . '/templates/show_playlist_bar.inc.php'; ?></div>
+ <?php show_box_bottom(); ?>
</div> <!-- End topbarright -->
</div><!-- End topbar -->
<div id="sidebar"><!-- This is the sidebar -->
- <?php require_once(Config::get('prefix') . '/templates/sidebar.inc.php'); ?>
+ <?php require_once Config::get('prefix') . '/templates/sidebar.inc.php'; ?>
</div><!-- End sidebar -->
<div id="content">
<!-- I hate IE... -->
diff --git a/templates/show_playlist_bar.inc.php b/templates/show_playlist_bar.inc.php
new file mode 100644
index 00000000..cfff9e58
--- /dev/null
+++ b/templates/show_playlist_bar.inc.php
@@ -0,0 +1,25 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2007 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 v2
+ as published by the Free Software Foundation.
+
+ 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.
+
+*/
+$web_path = Config::get('web_path');
+
+// Get the count of the number of items in their playlist
+?>
+<div><?php echo __('There are currently %count% items in your playlist','%count%',$GLOBALS['user']->playlist->count_items()); ?></div>