Fixed a couple of small bugs.
[squirrelmail.git] / functions / prefs.php
index 10e29f4aae41dbd7fe0bcd73b1e6b5626edd56f9..e71d4e0531d3ca9872372d3f207296f66925fe3d 100644 (file)
@@ -27,14 +27,14 @@ function cachePrefValues($data_dir, $username) {
         return;
     }
 
         return;
     }
 
-    /* A call to checkForPrefs here should take eliminate the need for
-    /* this to be called throughout the rest of the SquirrelMail code. 
-    checkForPrefs($data_dir, $username);
-
     /* Calculate the filename for the user's preference file */
     $filename = getHashedFile($username, $data_dir, "$username.pref");
 
     /* Calculate the filename for the user's preference file */
     $filename = getHashedFile($username, $data_dir, "$username.pref");
 
-    checkForPrefs($data_dir, $username);ยบ
+    /* A call to checkForPrefs here should take eliminate the need for
+    /* this to be called throughout the rest of the SquirrelMail code. 
+    checkForPrefs($data_dir, $username, $filename);
+
+    /* Make sure that the preference file now DOES exist. */
     if (!file_exists($filename)) {
         printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
         exit;
     if (!file_exists($filename)) {
         printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
         exit;
@@ -143,8 +143,13 @@ function setPref($data_dir, $username, $string, $value) {
 /**
  * Check for a preferences file. If one can not be found, create it.
  */
 /**
  * Check for a preferences file. If one can not be found, create it.
  */
-function checkForPrefs($data_dir, $username) {
-    $filename = getHashedFile($username, $data_dir, "$username.pref");
+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) ) {
         if (!copy($data_dir . 'default_pref', $filename)) {
             echo _("Error opening ") . $filename;
     if (!file_exists($filename) ) {
         if (!copy($data_dir . 'default_pref', $filename)) {
             echo _("Error opening ") . $filename;