-/**
- * Remove a preference for the current user.
- */
-function removePref($data_dir, $username, $string) {
- global $prefs_cache;
-
- cachePrefValues($data_dir, $username);
-
- if (isset($prefs_cache[$string])) {
- unset($prefs_cache[$string]);
- }
-
- savePrefValues($data_dir, $username);
-}
-
-/**
- * Set a there preference $string to $value.
- */
-function setPref($data_dir, $username, $string, $value) {
- global $prefs_cache;
-
- cachePrefValues($data_dir, $username);
- if (isset($prefs_cache[$string]) && ($prefs_cache[$string] == $value)) {
- return;
- }
-
- if ($value === '') {
- removePref($data_dir, $username, $string);
- return;
- }
-
- $prefs_cache[$string] = $value;
- savePrefValues($data_dir, $username);
-}
-
-/**
- * Check for a preferences file. If one can not be found, create it.
- */
-function checkForPrefs($data_dir, $username, $filename = '') {
- /* First, make sure we have the filename. */
- if ($filename == '') {
- $filename = getHashedFile($username, $data_dir, '$username.pref');
- }
-
- /* Then, check if the file exists. */
- if (!@file_exists($filename) ) {
- /* First, check the $data_dir for the default preference file. */
- $default_pref = $data_dir . 'default_pref';
-
- /* If it is not there, check the internal data directory. */
- if (!@file_exists($default_pref)) {
- $default_pref = '../data/default_pref';
- }
-
- /* Otherwise, report an error. */
- if (!file_exists($default_pref)) {
- echo _("Error opening ") . $default_pref . "<br>\n";
- echo _("Default preference file not found!") . "<br>\n";
- echo _("Please contact your system administrator and report this error.") . "<br>\n";
- exit;
- } else if (!@copy($default_pref, $filename)) {
- echo _("Error opening ") . $default_pref . '<br>';
- echo _("Could not create initial preference file!") . "<br>\n";
- echo _("Please contact your system administrator and report this error.") . "<br>\n";
- exit;
- }
- }
+if ( !sqsession_is_registered('prefs_are_cached') ||
+ !isset( $prefs_cache) ||
+ !is_array( $prefs_cache) ||
+ substr( phpversion(), 0, 3 ) == '4.1' ||
+ substr( phpversion(), 0, 3 ) == '4.2' ||
+ (substr( phpversion(), 0, 3 ) == '4.0' && empty($rg))) {
+ $prefs_are_cached = false;
+ $prefs_cache = array();