Esempio n. 1
0
 /**
  * set_user_preferences
  * This sets up a (or all) user(s) to use democratic play. This sets
  * their play method and playlist method (clear on send) If no user is
  * passed it does it for everyone and also locks down the ability to
  * change to admins only
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public static function set_user_preferences($user = null)
 {
     //FIXME: Code in single user stuff
     $preference_id = Preference::id_from_name('play_type');
     Preference::update_level($preference_id, '75');
     Preference::update_all($preference_id, 'democratic');
     $allow_demo = Preference::id_from_name('allow_democratic_playback');
     Preference::update_all($allow_demo, '1');
     $play_method = Preference::id_from_name('playlist_method');
     Preference::update_all($play_method, 'clear');
     return true;
 }
Esempio n. 2
0
/**
 * update_preference
 * This function updates a single preference and is called by the update_preferences function
 */
function update_preference($user_id, $name, $pref_id, $value)
{
    $apply_check = "check_" . $name;
    $level_check = "level_" . $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])) {
        Preference::update_all($pref_id, $value);
        return true;
    }
    /* Check and see if they are an admin and the level def is set */
    if ($GLOBALS['user']->has_access(100) and make_bool($_REQUEST[$level_check])) {
        Preference::update_level($pref_id, $_REQUEST[$level_check]);
    }
    /* Else make sure that the current users has the right to do this */
    if (Preference::has_access($name)) {
        $sql = "UPDATE `user_preference` SET `value` = ? WHERE `preference` = ? AND `user` = ?";
        Dba::write($sql, array($value, $pref_id, $user_id));
        return true;
    }
    return false;
}