summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-07-09 07:49:59 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-07-09 07:49:59 +0000
commitc5d6e04d114d3c4b3f31743ccd0d4a60c9ef9632 (patch)
treebc3196cb97d63079013ebfc5b183d2038ee7c9e7 /lib
parentc9170314af9139abef87629d218c7999bd3c8df3 (diff)
downloadampache-c5d6e04d114d3c4b3f31743ccd0d4a60c9ef9632.tar.gz
ampache-c5d6e04d114d3c4b3f31743ccd0d4a60c9ef9632.tar.bz2
ampache-c5d6e04d114d3c4b3f31743ccd0d4a60c9ef9632.zip
removed ID field from user table, and everything that goes with that...
Diffstat (limited to 'lib')
-rw-r--r--lib/class/catalog.class.php58
-rw-r--r--lib/class/playlist.class.php16
-rw-r--r--lib/class/stream.class.php2
-rw-r--r--lib/class/update.class.php26
-rw-r--r--lib/class/user.class.php148
-rw-r--r--lib/flag.php8
-rw-r--r--lib/general.lib.php2
-rw-r--r--lib/mpd.php6
-rw-r--r--lib/preferences.php18
-rw-r--r--lib/ui.lib.php4
-rw-r--r--lib/xmlrpc.php2
11 files changed, 171 insertions, 119 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index b8907d0a..01ca1a6f 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -891,19 +891,26 @@ class Catalog {
} // add_to_catalog
- /*!
- @function get_remote_catalog
- @discussion get a remote catalog and runs update if needed
- */
+ /**
+ * get_remote_catalog
+ * get a remote catalog and runs update if needed
+ * @package XMLRPC
+ * @catagory Client
+ * @author Karl Vollmer
+ * @todo Add support for something besides port 80
+ * @todo Add a Pub/Private Key swap in here for extra security
+ */
function get_remote_catalog($type=0) {
+ /* Make sure the xmlrpc lib is loaded */
if (!class_exists('xmlrpc_client')) {
if (conf('debug')) { log_event($_SESSION['userdata']['username'],'xmlrpc',"Unable to load XMLRPC library"); }
echo "<font class=\"error\"><b>" . _("Error") . "</b>: " . _("Unable to load XMLRPC library, make sure XML-RPC is enabled") . "<br />\n";
return false;
- }
+ } // end check for class
// first, glean out the information from the path about the server and remote path
+ // this can't contain the http
preg_match("/http:\/\/([^\/]+)\/*(.*)/", $this->path, $match);
$server = $match[1];
$path = $match[2];
@@ -914,30 +921,40 @@ class Catalog {
else {
$client = new xmlrpc_client("/$path/server.php", $server, 80);
}
-
- $f = new xmlrpcmsg('remote_server_query', array(new xmlrpcval( conf('web_path'), "string")) );
- //if (conf('debug')) { $client->setDebug(1); }
- $response = $client->send($f);
+
+ $f = new xmlrpcmsg('remote_server_query', array(new xmlrpcval( conf('web_path'), "string")) );
+
+ if (conf('debug')) { $client->setDebug(1); }
+
+ $response = $client->send($f,30);
$value = $response->value();
if ( !$response->faultCode() ) {
$data = php_xmlrpc_decode($value);
// Print out the catalogs we are going to sync
- //FIXME: We should add catalog level access control
foreach ($data as $vars) {
- $catalog_name = $vars[0];
- print("<b>Reading Remote Catalog: $catalog_name</b> [$this->path]<br />\n");
+ $catalog_name = $vars[0];
+ $count = $vars[1];
+ print("<b>Reading Remote Catalog: $catalog_name ($count Songs)</b> [$this->path]<br />\n");
}
- }
+ // Flush the output
+ flush();
+
+ } // if we didn't get an error
else {
$error_msg = _("Error connecting to") . " " . $server . " " . _("Code") . ": " . $response->faultCode() . " " . _("Reason") . ": " . $response->faultString();
- log_event($_SESSION['userdata']['username'],'xmlrpc',$error_msg);
+ if (conf('debug')) { log_event($_SESSION['userdata']['username'],'xmlrpc',$error_msg); }
echo "<p class=\"error\">$error_msg</p>";
return;
}
- $f = new xmlrpcmsg('remote_song_query', array(new xmlrpcval( 'song', "string")) );
+ $f = new xmlrpcmsg('remote_song_query');
+
+ /* Depending upon the size of the target catalog this can be a very slow/long process */
+ set_time_limit(0);
+
+ // No Timeout on this one because it can be flipping huge
$response = $client->send($f);
$value = $response->value();
@@ -956,10 +973,13 @@ class Catalog {
} // get_remote_catalog
- /*!
- @function update_remote_catalog
- @discussion actually updates from the remote data
- */
+ /**
+ * update_remote_catalog
+ * actually updates from the remote data, takes an array of songs that are base64 encoded and parses them
+ * @package XMLRPC
+ * @catagory Client
+ * @todo This should be based off of seralize
+ */
function update_remote_catalog($songs,$root_path) {
global $settings, $dbh, $artists;
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index 130537af..b17eadc6 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -30,7 +30,7 @@ class Playlist {
// Variables from DB
var $id;
var $name;
- var $owner;
+ var $user;
var $type;
var $time;
var $items;
@@ -64,13 +64,13 @@ class Playlist {
$dbh = dbh();
if ($this->id) {
- $sql = "SELECT name, owner, type, date FROM playlist" .
+ $sql = "SELECT name, user, type, date FROM playlist" .
" WHERE id = '$this->id'";
$db_results = mysql_query($sql, $dbh);
if ($r = mysql_fetch_object($db_results)) {
$this->name = $r->name;
- $this->owner = $r->owner;
+ $this->user = $r->user;
$this->type = $r->type;
$this->time = $r->date;
$this->items = array();
@@ -96,17 +96,17 @@ class Playlist {
/*!
@function create_playlist
- @discussion Creates an empty playlist, given a name, owner_id, and type.
+ @discussion Creates an empty playlist, given a name, user_id, and type.
*/
- function create_playlist($name, $owner_id, $type) {
+ function create_playlist($name, $user, $type) {
$dbh = dbh();
- if (isset($name) && isset($owner_id) && isset($type) && $this->check_type($type)) {
+ if (isset($name) && isset($user) && isset($type) && $this->check_type($type)) {
$name = sql_escape($name);
$sql = "INSERT INTO playlist" .
- " (name, owner, type)" .
- " VALUES ('$name', '$owner_id', '$type')";
+ " (name, user, type)" .
+ " VALUES ('$name', '$user', '$type')";
$db_results = mysql_query($sql, $dbh);
if ($this->id = mysql_insert_id($dbh)) {
$this->refresh_object();
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index 999dcbca..d550366c 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -49,7 +49,7 @@ class Stream {
}
$this->sess = session_id();
- $this->user_id = $_SESSION['userdata']['id'];
+ $this->user_id = $_SESSION['userdata']['username'];
} //constructor
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 5612eb0d..f077daef 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -229,13 +229,13 @@ class Update {
$version[] = array('version' => '332001', 'description' => $update_string);
- return $version;
-
$update_string = "- Removed every Instance of User->ID *Note* This update clears Now Playing.<br />" .
"- Added field allowing for Dynamic Playlists.<br />" .
"- Added required table/fields for security related IP Tracking.<br />";
- //$version[] = array('version' => '332002', 'description' => $update_string);
+ $version[] = array('version' => '332002', 'description' => $update_string);
+
+ return $version;
} // populate_version
@@ -960,8 +960,18 @@ class Update {
function update_332002() {
-// $sql = "CREATE TABLE `ip_history` (`username` VARCHAR(128), `ip` INT(11) UNSIGNED NOT NULL DEFAULT '0', " .
-// "`connections` INT(11) UNSIGNED NOT NULL DEFAULT '1', `date` INT(11) UNSIGNED NOT NULL DEFAULT '0')";
+ $sql = "CREATE TABLE `ip_history` (`username` VARCHAR(128), `ip` INT(11) UNSIGNED NOT NULL DEFAULT '0', " .
+ "`connections` INT(11) UNSIGNED NOT NULL DEFAULT '1', `date` INT(11) UNSIGNED NOT NULL DEFAULT '0')";
+ $db_results = mysql_query($sql, dbh());
+
+ $sql = "ALTER TABLE `ip_history` ADD INDEX ( `username` )";
+ $db_results = mysql_query($sql, dbh());
+
+ $sql = "ALTER TABLE `ip_history` ADD INDEX ( `date` )";
+ $db_results = mysql_query($sql, dbh());
+
+ $sql = "ALTER TABLE `session` ADD `ip` INT( 11 ) UNSIGNED AFTER `value`";
+ $db_results = mysql_query($sql, dbh());
$sql = "ALTER TABLE `object_count` CHANGE `object_type` `object_type` ENUM( 'album', 'artist', 'song', 'playlist', 'genre', 'catalog' ) NOT NULL DEFAULT 'song'";
$db_results = mysql_query($sql, dbh());
@@ -982,10 +992,10 @@ class Update {
}
/* It's time for some serious DB Clean Up. Nuke this stuff from Orbit! */
- $sql = "ALTER TABLE `catalog DROP `private`";
+ $sql = "ALTER TABLE `catalog` DROP `private`";
$db_results = mysql_query($sql, dbh());
- $sql = "ALTER TABLE `catalog` CHANGE `enabled` `enabled` TINYINT UNSIGNED NOT NULL DEFAULT '1'";
+ $sql = "ALTER TABLE `catalog` CHANGE `enabled` `enabled` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1'";
$db_results = mysql_query($sql, dbh());
/*
@@ -1158,6 +1168,8 @@ class Update {
$sql = "ALTER TABLE `user` DROP `id`";
$db_results = mysql_query($sql, dbh());
+ $this->set_version('db_version', '332002');
+
} // update_332002
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index c3736c78..70271e41 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -30,7 +30,6 @@ class User {
//Basic Componets
var $username;
- var $id=0;
var $fullname;
var $access;
var $disabled;
@@ -38,18 +37,15 @@ class User {
var $email;
var $last_seen;
- function User($username=0,$uid=0) {
+ function User($username=0) {
- if (!$username && !$uid) {
+ if (!$username) {
return true;
}
$this->username = $username;
- $this->id = $uid;
$info = $this->get_info();
$this->username = $info->username;
- $this->id = $info->id;
- $this->id = $info->id;
$this->fullname = $info->fullname;
$this->access = $info->access;
$this->disabled = $info->disabled;
@@ -70,12 +66,8 @@ class User {
*/
function get_info() {
- if ($this->username) {
- $sql = "SELECT * FROM user WHERE username='$this->username'";
- }
- else {
- $sql = "SELECT * FROM user WHERE id='$this->id'";
- }
+ $sql = "SELECT * FROM user WHERE username='$this->username'";
+
$db_results = mysql_query($sql, dbh());
return mysql_fetch_object($db_results);
@@ -89,7 +81,8 @@ class User {
*/
function get_preferences() {
- $sql = "SELECT preferences.name, preferences.description, preferences.type, user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->id' AND user_preference.preference=preferences.id AND preferences.type='user'";
+ $sql = "SELECT preferences.name, preferences.description, preferences.type, user_preference.value FROM preferences,user_preference " .
+ "WHERE user_preference.user='$this->username' AND user_preference.preference=preferences.id AND preferences.type='user'";
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_object($db_results)) {
@@ -107,7 +100,7 @@ class User {
*/
function set_preferences() {
- $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->id' " .
+ $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$this->username' " .
"AND user_preference.preference=preferences.id AND preferences.type='user'";
$db_results = mysql_query($sql, dbh());
@@ -126,7 +119,7 @@ class User {
$sql = "SELECT * FROM object_count" .
" WHERE count > 0" .
" AND object_type = '$type'" .
- " AND userid = '" . $this->id . "'" .
+ " AND userid = '" . $this->username . "'" .
" ORDER BY count DESC LIMIT " . conf('popular_threshold');
$db_result = mysql_query($sql, dbh());
@@ -189,7 +182,7 @@ class User {
*/
function is_logged_in() {
- $sql = "SELECT id FROM session WHERE username='$this->id'" .
+ $sql = "SELECT id FROM session WHERE username='$this->username'" .
" AND expire > ". time();
$db_results = mysql_query($sql,dbh());
@@ -220,37 +213,40 @@ class User {
} // has_access
- /*!
- @function update_preference
- @discussion updates a single preference if the query fails
- it attempts to insert the preference instead
- */
- function update_preference($preference_id, $value, $id=0) {
-
- if (!$id) {
- $id = $this->id;
- }
+ /**
+ * update_preference
+ * updates a single preference if the query fails
+ * it attempts to insert the preference instead
+ * @package User
+ * @catagory Class
+ * @todo Do a has_preference_access check
+ */
+ function update_preference($preference_id, $value, $username=0) {
+
+ if (!$username) {
+ $username = $this->username;
+ }
$value = sql_escape($value);
- //FIXME:
- // Do a has_access check here...
+ $sql = "UPDATE user_preference SET value='$value' WHERE user='$username' AND preference='$preference_id'";
- $sql = "UPDATE user_preference SET value='$value' WHERE user='$id' AND preference='$preference_id'";
$db_results = @mysql_query($sql, dbh());
} // update_preference
- /*!
- @function add_preference
- @discussion adds a new preference
- @param $key preference name
- @param $value preference value
- @param $id user is
- */
- function add_preference($preference_id, $value, $id=0) {
+ /**
+ * add_preference
+ * adds a new preference
+ * @package User
+ * @catagory Class
+ * @param $key preference name
+ * @param $value preference value
+ * @param $id user is
+ */
+ function add_preference($preference_id, $value, $username=0) {
- if (!$id) {
- $id = $this->id;
+ if (!$username) {
+ $username = $this->username;
}
$value = sql_escape($value);
@@ -262,7 +258,7 @@ class User {
$preference_id = $r[0];
} // end if it's not numeric
- $sql = "INSERT user_preference SET `user`='$id' , `value`='$value' , `preference`='$preference_id'";
+ $sql = "INSERT user_preference SET `user`='$username' , `value`='$value' , `preference`='$preference_id'";
$db_results = mysql_query($sql, dbh());
} // add_preference
@@ -274,7 +270,8 @@ class User {
function update_username($new_username) {
$new_username = sql_escape($new_username);
- $sql = "UPDATE user SET username='$new_username' WHERE id='$this->id'";
+ $sql = "UPDATE user SET username='$new_username' WHERE username='$this->username'";
+ $this->username = $new_username;
$db_results = mysql_query($sql, dbh());
} // update_username
@@ -286,7 +283,7 @@ class User {
function update_fullname($new_fullname) {
$new_fullname = sql_escape($new_fullname);
- $sql = "UPDATE user SET fullname='$new_fullname' WHERE id='$this->id'";
+ $sql = "UPDATE user SET fullname='$new_fullname' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
} // update_username
@@ -298,7 +295,7 @@ class User {
function update_email($new_email) {
$new_email = sql_escape($new_email);
- $sql = "UPDATE user SET email='$new_email' WHERE id='$this->id'";
+ $sql = "UPDATE user SET email='$new_email' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
} // update_email
@@ -310,44 +307,47 @@ class User {
function update_offset($new_offset) {
$new_offset = sql_escape($new_offset);
- $sql = "UPDATE user SET offset_limit='$new_offset' WHERE id='$this->id'";
+ $sql = "UPDATE user SET offset_limit='$new_offset' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
} // update_offset
- /*!
- @function update_access
- @discussion updates their access level
- */
+ /**
+ * update_access
+ * updates their access level
+ * @todo Remove References to the named version of access
+ */
function update_access($new_access) {
/* Check for all disable */
if ($new_access == 'disabled') {
- $sql = "SELECT id FROM user WHERE disabled != '1' AND id != '$this->id'";
+ $sql = "SELECT username FROM user WHERE disabled != '1' AND username != '$this->username'";
$db_results = mysql_query($sql,dbh());
if (!mysql_num_rows($db_results)) { return false; }
}
/* Prevent Only User accounts */
if ($new_access == 'user') {
- $sql = "SELECT id FROM user WHERE (access='admin' OR access='100') AND id != '$this->id'";
+ $sql = "SELECT username FROM user WHERE (access='admin' OR access='100') AND username != '$this->username'";
$db_results = mysql_query($sql, dbh());
if (!mysql_num_rows($db_results)) { return false; }
}
if ($new_access == 'enabled') {
$new_access = sql_escape($new_access);
- $sql = "UPDATE user SET disabled='0' WHERE id='$this->id'";
+ $sql = "UPDATE user SET disabled='0' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
- } elseif ($new_access == 'disabled') {
+
+ }
+ elseif ($new_access == 'disabled') {
$new_access = sql_escape($new_access);
- $sql = "UPDATE user SET disabled='1' WHERE id='$this->id'";
+ $sql = "UPDATE user SET disabled='1' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
$sql = "DELETE FROM session WHERE username='" . sql_escape($this->username) . "'";
$db_results = mysql_query($sql, dbh());
} else {
$new_access = sql_escape($new_access);
- $sql = "UPDATE user SET access='$new_access' WHERE id='$this->id'";
+ $sql = "UPDATE user SET access='$new_access' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
}
@@ -359,7 +359,7 @@ class User {
*/
function update_last_seen() {
- $sql = "UPDATE user SET last_seen='" . time() . "' WHERE id='$this->id'";
+ $sql = "UPDATE user SET last_seen='" . time() . "' WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
} // update_last_seen
@@ -372,7 +372,7 @@ class User {
function update_stats($song_id) {
$song_info = new Song($song_id);
- $user = $this->id;
+ $user = $this->username;
$dbh = dbh();
if (!$song_info->file) { return false; }
@@ -454,12 +454,11 @@ class User {
" ('$username','$fullname','$email',PASSWORD('$password'),'$access')";
$db_results = mysql_query($sql, dbh());
if (!$db_results) { return false; }
- $user_id = mysql_insert_id(dbh());
/* Populates any missing preferences, in this case all of them */
- $this->fix_preferences($user_id);
+ $this->fix_preferences($username);
- return $user_id;
+ return $username;
} // new
@@ -469,7 +468,7 @@ class User {
*/
function update_password($new_password) {
- $sql = "UPDATE user SET password=PASSWORD('$new_password') WHERE id='$this->id'";
+ $sql = "UPDATE user SET password=PASSWORD('$new_password') WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
return true;
@@ -505,16 +504,19 @@ class User {
} // format_favorites
/*!
- @function fix_preferences
- @discussion this makes sure that the specified user
- has all the correct preferences. This function
- should be run whenever a system preference is run
- it's a cop out... FIXME!
- */
+ * fix_preferences
+ * this makes sure that the specified user
+ * has all the correct preferences. This function
+ * should be run whenever a system preference is run
+ * it's a cop out... FIXME!
+ * @todo Fix it so this isn't a hack
+ * @pacakge User
+ * @catagory Class
+ */
function fix_preferences($user_id = 0) {
if (!$user_id) {
- $user_id = $this->id;
+ $user_id = $this->username;
}
/* Get All Preferences */
@@ -575,7 +577,7 @@ class User {
*/
function delete_stats() {
- $sql = "DELETE FROM object_count WHERE userid='" . $this->id . "'";
+ $sql = "DELETE FROM object_count WHERE userid='" . $this->username . "'";
$db_results = mysql_query($sql, dbh());
} // delete_stats
@@ -591,7 +593,7 @@ class User {
admin
*/
if ($this->has_access(100)) {
- $sql = "SELECT * FROM user WHERE (level='admin' OR level='100') AND id!='" . $this->id . "'";
+ $sql = "SELECT * FROM user WHERE (level='admin' OR level='100') AND username!='" . $this->username . "'";
$db_results = mysql_query($sql, dbh());
if (!mysql_num_rows($db_results)) {
return false;
@@ -599,19 +601,19 @@ class User {
} // if this is an admin check for others
// Delete their playlists
- $sql = "DELETE FROM playlist WHERE owner='$this->id'";
+ $sql = "DELETE FROM playlist WHERE user='$this->username'";
$db_results = mysql_query($sql, dbh());
// Delete any stats they have
- $sql = "DELETE FROM object_count WHERE userid='$this->id'";
+ $sql = "DELETE FROM object_count WHERE userid='$this->username'";
$db_results = mysql_query($sql, dbh());
// Delete their preferences
- $sql = "DELETE FROM preferences WHERE user='$this->id'";
+ $sql = "DELETE FROM preferences WHERE user='$this->username'";
$db_results = mysql_query($sql, dbh());
// Delete the user itself
- $sql = "DELETE FROM user WHERE id='$this->id'";
+ $sql = "DELETE FROM user WHERE username='$this->username'";
$db_results = mysql_query($sql, dbh());
return true;
diff --git a/lib/flag.php b/lib/flag.php
index 01b3ba9f..da371793 100644
--- a/lib/flag.php
+++ b/lib/flag.php
@@ -87,7 +87,7 @@ function get_flag($id)
$results = array();
$newid = array_pop($id);
$sql = "SELECT flagged.id,user.username,type,song,date,comment" .
- " FROM flagged,user WHERE flagged.user = user.id AND (flagged.song = '$newid'";
+ " FROM flagged,user WHERE flagged.user = user.username AND (flagged.song = '$newid'";
foreach($id as $num)
{
$sql .= " OR flagged.song = '$num'";
@@ -106,18 +106,18 @@ function get_flag($id)
function get_flagged_songs($user = 0)
{
$sql = "SELECT flagged.id,user.username,type,song,date,comment" .
- " FROM flagged,user WHERE flagged.user = user.id AND flagged.type <> 'notify' AND flagged.type <> 'done'";
+ " FROM flagged,user WHERE flagged.user = user.username AND flagged.type <> 'notify' AND flagged.type <> 'done'";
// If the user is not an admin, they can only see songs they've flagged
if($user)
{
if($_SESSION['userdata']['access'] === 'admin')
{
- $sql .= " AND user.id = '$user'";
+ $sql .= " AND user.username = '$user'";
}
else
{
- $sql .= " AND user.id = '".$_SESSION['userdata']['id']."'";
+ $sql .= " AND user.username = '".$_SESSION['userdata']['username']."'";
}
}
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 38afb2e8..ee32d328 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -514,7 +514,7 @@ function get_random_songs( $options, $matchlist) {
$query = "SELECT song.id FROM song WHERE $artists_where ORDER BY RAND()";
}
elseif ($options['unplayed'] == 1) {
- $uid = $_SESSION['userdata']['id'];
+ $uid = $_SESSION['userdata']['username'];
$query = "SELECT song.id FROM song LEFT JOIN object_count ON song.id = object_count.object_id " .
"WHERE ($where) AND ((object_count.object_type='song' AND userid = '$uid') OR object_count.count IS NULL ) " .
"ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " .
diff --git a/lib/mpd.php b/lib/mpd.php
index 376bbedc..232fc892 100644
--- a/lib/mpd.php
+++ b/lib/mpd.php
@@ -35,11 +35,11 @@ function addToPlaylist( $myMpd, $song_ids=array()) {
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate'];
}
- $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $GLOBALS['user']->id . "&sid=$sess_id&ds=$ds&name=." . $song->type;
+ $song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $GLOBALS['user']->username . "&sid=$sess_id&ds=$ds&name=." . $song->type;
if (is_null( $myMpd->PlAdd($song_url) ) ) {
$log_line = _("Error") . ": " . _("Could not add") . ": " . $song_url . " : " . $myMpd->errStr;
echo "<font class=\"error\">$log_line</font><br />\n";
- log_event($GLOBALS['user']->username,'add',$log_line);
+ if (conf('debug')) { log_event($GLOBALS['user']->username,'add',$log_line); }
} // if it's null
} // if we want urls
else {
@@ -48,7 +48,7 @@ function addToPlaylist( $myMpd, $song_ids=array()) {
if( is_null( $myMpd->PLAdd( $song_filename ) ) ) {
$log_line = _("Error") . ": " . _("Could not add") . ": " . $song_filename . " : " . $myMpd->errStr;
echo "<font class=\"error\">$log_line</font><br />\n";
- log_event($_SESSION['userdata']['username'],'add',$log_line);
+ if (conf('debug')) { log_event($_SESSION['userdata']['username'],'add',$log_line); }
} // end if it's null
// We still need to count if they use the file method
else {
diff --git a/lib/preferences.php b/lib/preferences.php
index 183bcf6f..a9920703 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -281,4 +281,22 @@ function create_preference_input($name,$value) {
} // create_preference_input
+/**
+ * get_preference_id
+ * This takes the name of a preference and returns it's id this is usefull for calling
+ * the user classes update_preference function
+ * @package Preferences
+ * @catagory Get
+ */
+function get_preference_id($name) {
+
+ $sql = "SELECT id FROM preferences WHERE name='" . sql_escape($name) . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ $results = mysql_fetch_assoc($db_results);
+
+ return $results['id'];
+
+} // get_preference_id
+
?>
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 1f23fd2a..126aa5d0 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -84,7 +84,7 @@ function get_preferences($username=0) {
$user = new User($username);
- $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user->id'" .
+ $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='$user->username'" .
" AND user_preference.preference=preferences.id";
$db_results = mysql_query($sql, dbh());
@@ -457,7 +457,7 @@ function get_now_playing() {
while ($r = mysql_fetch_assoc($db_results)) {
$song = new Song($r['song_id']);
$song->format_song();
- $np_user = new User(0,$r['user_id']);
+ $np_user = new User($r['user_id']);
$results[] = array('song'=>$song,'user'=>$np_user);
} // end while
return $results;
diff --git a/lib/xmlrpc.php b/lib/xmlrpc.php
index 63473dc6..a9d71bc7 100644
--- a/lib/xmlrpc.php
+++ b/lib/xmlrpc.php
@@ -41,7 +41,7 @@ function remote_server_query($m) {
$result = array();
// we only want to send the local entries
- $sql = "SELECT name FROM catalog WHERE catalog_type='local'";
+ $sql = "SELECT name,COUNT(song.id) FROM catalog LEFT JOIN song ON catalog.id = song.catalog WHERE catalog_type='local' GROUP BY catalog.id";
$db_result = mysql_query($sql, dbh());
while ( $i = mysql_fetch_row($db_result) ) {