. * */ /* * update_preferences * grabs the current keys that should be added * and then runs throught $_REQUEST looking for those * values and updates them for this user */ function update_preferences($pref_id=0) { /* Get current keys */ $sql = "SELECT `id`,`name`,`type` FROM `preference`"; /* If it isn't the System Account's preferences */ if ($pref_id != '-1') { $sql .= " WHERE `catagory` != 'system'"; } $db_results = Dba::read($sql); $results = array(); // Collect the current possible keys while ($r = Dba::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 */ $name = $data['name']; $apply_to_all = 'check_' . $data['name']; $new_level = 'level_' . $data['name']; $id = $data['id']; $value = scrub_in($_REQUEST[$name]); /* Some preferences require some extra checks to be performed */ switch ($name) { case 'transcode_bitrate': $value = Stream::validate_bitrate($value); break; default: break; } if (preg_match('/_pass$/', $name)) { if ($value == '******') { unset($_REQUEST[$name]); } else { if (preg_match('/md5_pass$/', $name)) { $value = md5($value); } } } /* Run the update for this preference only if it's set */ if (isset($_REQUEST[$name])) { Preference::update($id, $pref_id, $value, $_REQUEST[$apply_to_all]); } if (Access::check('interface', '100') && $_REQUEST[$new_level]) { Preference::update_level($id, $_REQUEST[$new_level]); } } // end foreach preferences // Now that we've done that we need to invalidate the cached preverences Preference::clear_from_session(); } // update_preferences /** * 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; } // update_preference /** * create_preference_input * takes the key and then creates the correct type of input for updating it */ function create_preference_input($name, $value) { if (!Preference::has_access($name)) { if ($value == '1') { echo "Enabled"; } elseif ($value == '0') { echo "Disabled"; } else { if (preg_match('/_pass$/', $name) || preg_match('/_api_key$/', $name)) { echo "******"; } else { echo $value; } } return; } // if we don't have access to it switch ($name) { case 'display_menu': case 'download': case 'quarantine': case 'upload': case 'access_list': case 'lock_songs': case 'xml_rpc': case 'force_http_play': case 'no_symlinks': case 'use_auth': case 'access_control': case 'allow_stream_playback': case 'allow_democratic_playback': case 'allow_localplay_playback': case 'demo_mode': case 'condPL': case 'rio_track_stats': case 'rio_global_stats': case 'direct_link': case 'ajax_load': case 'now_playing_per_user': case 'show_played_times': case 'song_page_title': case 'subsonic_backend': case 'plex_backend': case 'webplayer_flash': case 'webplayer_html5': case 'allow_personal_info_now': case 'allow_personal_info_recent': case 'allow_personal_info_time': case 'allow_personal_info_agent': case 'ui_fixed': case 'autoupdate': case 'webplayer_confirmclose': case 'webplayer_pausetabs': case 'stream_beautiful_url': case 'share': case 'share_social': case 'broadcast_by_default': case 'album_group': case 'topmenu': case 'demo_clear_sessions': case 'show_donate': case 'allow_upload': case 'upload_subdir': case 'upload_user_artist': case 'upload_allow_edit': case 'daap_backend': case 'upnp_backend': case 'album_release_type': case 'home_moment_albums': case 'home_moment_videos': case 'home_recently_played': case 'home_now_playing': case 'browser_notify': case 'allow_video': case 'geolocation': case 'webplayer_aurora': case 'upload_allow_remove': case 'webdav_backend': case 'notify_email': case 'libitem_contextmenu': case 'upload_catalog_pattern': case 'catalogfav_gridview': case 'browse_filter': case 'sidebar_light': $is_true = ''; $is_false = ''; if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } echo "\n"; break; case 'upload_catalog': show_catalog_select('upload_catalog', $value, '', true); break; case 'play_type': $is_localplay = ''; $is_democratic = ''; $is_web_player = ''; $is_stream = ''; if ($value == 'localplay') { $is_localplay = 'selected="selected"'; } elseif ($value == 'democratic') { $is_democratic = 'selected="selected"'; } elseif ($value == 'web_player') { $is_web_player = 'selected="selected"'; } else { $is_stream = "selected=\"selected\""; } echo "\n"; break; case 'playlist_type': $var_name = $value . "_type"; ${$var_name} = "selected=\"selected\""; echo "\n"; break; case 'lang': $languages = get_languages(); echo '\n"; break; case 'localplay_controller': $controllers = Localplay::get_controllers(); echo "\n"; break; case 'localplay_level': $is_user = ''; $is_admin = ''; $is_manager = ''; if ($value == '25') { $is_user = 'selected="selected"'; } elseif ($value == '100') { $is_admin = 'selected="selected"'; } elseif ($value == '50') { $is_manager = 'selected="selected"'; } echo "\n"; break; case 'theme_name': $themes = get_themes(); echo "\n"; break; case 'theme_color': // This include a two-step configuration (first change theme and save, then change theme color and save) $theme_cfg = get_theme(AmpConfig::get('theme_name')); if ($theme_cfg !== null) { echo "\n"; } break; case 'playlist_method': ${$value} = ' selected="selected"'; echo "\n"; break; case 'transcode': ${$value} = ' selected="selected"'; echo "\n"; break; case 'show_lyrics': $is_true = ''; $is_false = ''; if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } echo "\n"; break; case 'album_sort': $is_sort_year_asc = ''; $is_sort_year_desc = ''; $is_sort_name_asc = ''; $is_sort_name_desc = ''; $is_sort_default = ''; if ($value == 'year_asc') { $is_sort_year_asc = 'selected="selected"'; } elseif ($value == 'year_desc') { $is_sort_year_desc = 'selected="selected"'; } elseif ($value == 'name_asc') { $is_sort_name_asc = 'selected="selected"'; } elseif ($value == 'name_desc') { $is_sort_name_desc = 'selected="selected"'; } else { $is_sort_default = 'selected="selected"'; } echo "\n"; break; case 'disabled_custom_metadata_fields': $ids = explode(',', $value); $options = array(); $fieldRepository = new \Lib\Metadata\Repository\MetadataField(); foreach ($fieldRepository->findAll() as $field) { $selected = in_array($field->getId(), $ids) ? ' selected="selected"' : ''; $options[] = ''; } echo ''; break; case 'lastfm_grant_link': case 'librefm_grant_link': // construct links for granting access Ampache application to Last.fm and Libre.fm $plugin_name = ucfirst(str_replace('_grant_link', '', $name)); $plugin = new Plugin($plugin_name); $url = $plugin->_plugin->url; $api_key = rawurlencode(AmpConfig::get('lastfm_api_key')); $callback = rawurlencode(AmpConfig::get('web_path') . '/preferences.php?tab=plugins&action=grant&plugin=' . $plugin_name); echo "" . UI::get_icon('plugin', sprintf(T_("Click to grant %s access to Ampache"), $plugin_name)) . ''; break; default: if (preg_match('/_pass$/', $name)) { echo ''; } else { echo ''; } break; } } // create_preference_input