diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-10-12 20:50:26 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-10-12 20:50:26 +0000 |
commit | 959c7b7a13c51aea549523f134d6ef526e3b977c (patch) | |
tree | 73c0e633c68fc95a4225a97d4444bc6e34131fff /lib | |
parent | e8785ed7554839db296d7b8d8f9a938ed0758d70 (diff) | |
download | ampache-959c7b7a13c51aea549523f134d6ef526e3b977c.tar.gz ampache-959c7b7a13c51aea549523f134d6ef526e3b977c.tar.bz2 ampache-959c7b7a13c51aea549523f134d6ef526e3b977c.zip |
fixed up some minor formating errors, and also the preferences mojo see changelog for details
Diffstat (limited to 'lib')
-rw-r--r-- | lib/general.lib.php | 4 | ||||
-rw-r--r-- | lib/preferences.php | 77 | ||||
-rw-r--r-- | lib/stream.lib.php | 2 | ||||
-rw-r--r-- | lib/themes.php | 17 |
4 files changed, 78 insertions, 22 deletions
diff --git a/lib/general.lib.php b/lib/general.lib.php index 03b8a4e6..6e38bf0e 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -844,6 +844,10 @@ function make_bool($string) { return '0'; } + if (strlen($string) < 1) { + return '0'; + } + return settype($string,"bool"); } // make_bool diff --git a/lib/preferences.php b/lib/preferences.php index 28c26ead..e5865544 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -92,43 +92,77 @@ function update_preferences($pref_id=0) { /* Get current keys */ $sql = "SELECT id,name,type FROM preferences"; + + /* If it isn't the System Account's preferences */ if ($pref_id != '-1') { $sql .= " WHERE type='user'"; } + $db_results = mysql_query($sql, dbh()); // Collect the current possible keys - while ($r = mysql_fetch_object($db_results)) { - $results[] = array('id' => $r->id, 'name' => $r->name,'type' => $r->type); - } + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = array('id' => $r['id'], 'name' => $r['name'],'type' => $r['type']); + } // end collecting keys + /* Foreach through possible keys and assign them */ foreach ($results as $data) { /* Get the Value from POST/GET var called $data */ - //FIXME: Do this right.... $type = $data['type']; $name = $data['name']; $apply_to_all = "check_" . $data['name']; $id = $data['id']; $value = sql_escape(scrub_in($_REQUEST[$name])); - if (has_preference_access($name) AND isset($_REQUEST[$name])) { - $sql = "UPDATE user_preference SET `value`='$value' WHERE preference='$id' AND user='$pref_id'"; - $db_results = mysql_query($sql, dbh()); - - /* Check to see if this is a theme, and if so run the theme updater */ - if ($name == "theme_name" AND $pref_user->prefs['theme_name'] != $_REQUEST[$name]) { - set_theme_colors($value,$pref_id); - } // run theme updater - - } // if access - - if ($GLOBALS['user']->has_access(100) AND $_REQUEST[$apply_to_all] =='1') { - $sql = "UPDATE user_preference SET `value`='$value' WHERE preference='$id'"; - $db_results = mysql_query($sql, dbh()); - } + /* Some preferences require some extra checks to be performed */ + switch ($name) { + case 'theme_name': + // If the theme exists and it's different then our current one reset the colors + if (theme_exists($value) AND $pref_user->prefs['theme_name'] != $value) { + set_theme_colors($value,$pref_id); + } + break; + case 'sample_rate': + $value = validate_bitrate($value); + break; + default: + break; + } + + /* Run the update for this preference */ + update_preference($pref_id,$name,$id,$value); + } // end foreach preferences } // update_preferences +/** + * update_preference + * This function updates a single preference and is called by the update_preferences function + * @package Preferences + * @catagory Update + */ +function update_preference($username,$name,$pref_id,$value) { + + $apply_check = "check_" . $name; + + /* First see if they are an administrator and we are applying this to everything */ + if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$apply_check])) { + $sql = "UPDATE user_preference SET `value`,'$value' WHERE preference='$pref_id'"; + $db_results = mysql_query($sql, dbh()); + return true; + } + + /* Else make sure that the current users has the right to do this */ + if (has_preference_access($name)) { + $sql = "UPDATE user_preference SET `value`='$value' WHERE preference='$pref_id' AND user='$username'"; + $db_resutls = mysql_query($sql, dbh()); + return true; + } + + return false; + +} // update_preference + /*! @function has_preference_access @discussion makes sure that the user has sufficient @@ -138,7 +172,6 @@ function update_preferences($pref_id=0) { // This is no longer needed, we just need to check against preferences.level */ function has_preference_access($name) { - global $user; if (conf('demo_mode')) { return false; @@ -158,7 +191,9 @@ function has_preference_access($name) { $level = 1; break; } // end switch key - if ($user->has_access($level)) { + + + if ($GLOBALS['user']->has_access($level)) { return true; } diff --git a/lib/stream.lib.php b/lib/stream.lib.php index 90177c49..18b4562f 100644 --- a/lib/stream.lib.php +++ b/lib/stream.lib.php @@ -287,7 +287,7 @@ function validate_bitrate($bitrate) { $next_key = $key+1; if ($sample_rate > $rate AND $sample_rate < $valid_rate[$next_key]) { - return $sample_rate; + return $rate; } } // end foreach diff --git a/lib/themes.php b/lib/themes.php index ca4a92c7..dfe49292 100644 --- a/lib/themes.php +++ b/lib/themes.php @@ -121,4 +121,21 @@ function get_theme_author($theme_name) { return $results['author']; } // get_theme_author + +/*! + @function theme_exists + @discussion this function checks to make sure that a theme actually exists +*/ +function theme_exists($theme_name) { + + $theme_path = conf('prefix') . "/themes/" . $theme_name . "/theme.cfg.php"; + + if (!file_exists($theme_path)) { + return false; + } + + return true; + +} // theme_exists + ?> |