POP3 class code replaced with mail_fetch class code.
[squirrelmail.git] / functions / db_prefs.php
index 63db4a26186c6bec9112e4ea56e7fb0148db4a43..26c2ac2ef94a36bf87e08659f482b4e1fb986ab7 100644 (file)
@@ -3,14 +3,10 @@
 /**
  * db_prefs.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * This contains functions for manipulating user preferences
  * stored in a database, accessed though the Pear DB layer.
  *
  * Database:
- * ---------
  *
  * The preferences table should have three columns:
  *    user       char  \  primary
@@ -25,6 +21,8 @@
  * Configuration of databasename, username and password is done
  * by using conf.pl or the administrator plugin
  *
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage prefs
@@ -41,17 +39,11 @@ define('SMDB_MYSQL', 1);
 /** PostgreSQL */
 define('SMDB_PGSQL', 2);
 
-require_once(SM_PATH . 'config/config.php');
-if (!include_once('DB.php')) {
-    // same error also in abook_database.php
-    require_once(SM_PATH . 'functions/display_messages.php');
-    $error  = _("Could not include PEAR database functions required for the database backend.") . "<br />\n";
-    $error .= sprintf(_("Is PEAR installed, and is the include path set correctly to find %s?"),
-                        '<tt>DB.php</tt>') . "<br />\n";
-    $error .= _("Please contact your system administrator and report this error.");
-    error_box($error, $color);
-    exit;
-}
+/**
+ * don't display errors (no code execution in functions/*.php).
+ * will handle error in dbPrefs class.
+ */
+@include_once('DB.php');
 
 global $prefs_are_cached, $prefs_cache;
 
@@ -170,6 +162,16 @@ class dbPrefs {
         global $prefs_user_field, $prefs_key_field, $prefs_val_field;
         global $prefs_user_size, $prefs_key_size, $prefs_val_size;
 
+        /* test if Pear DB class is available and freak out if it is not */
+        if (! class_exists('DB')) {
+            // same error also in abook_database.php
+            $this->error  = _("Could not include PEAR database functions required for the database backend.") . "<br />\n";
+            $this->error .= sprintf(_("Is PEAR installed, and is the include path set correctly to find %s?"),
+                              '<tt>DB.php</tt>') . "<br />\n";
+            $this->error .= _("Please contact your system administrator and report this error.");
+            return false;
+        }
+
         if(isset($this->dbh)) {
             return true;
         }
@@ -214,7 +216,7 @@ class dbPrefs {
 
     /**
      * Function used to handle database connection errors
-     * @param object PEAR Error object 
+     * @param object PEAR Error object
      */
     function failQuery($res = NULL) {
         if($res == NULL) {
@@ -252,7 +254,7 @@ class dbPrefs {
 
     /**
      * Delete user's prefs setting
-     * @param string $user user name 
+     * @param string $user user name
      * @param string $key preference name
      * @return boolean
      */
@@ -296,11 +298,12 @@ class dbPrefs {
          */
         if (strlen($user) > $this->user_size) {
             $this->error = "Oversized username value."
-                ." User's preferences can't be saved. See doc/db-backend.txt troubleshooting documentation.";
+                ." Your preferences can't be saved."
+                ." See doc/db-backend.txt or contact your system administrator.";
 
             /**
-             * Debugging function. Can be used to log all issues that trigger 
-             * oversized field errors. Function should be enabled in all three 
+             * Debugging function. Can be used to log all issues that trigger
+             * oversized field errors. Function should be enabled in all three
              * strlen checks. See http://www.php.net/error-log
              */
             // error_log($user.'|'.$key.'|'.$value."\n",3,'/tmp/oversized_log');
@@ -313,7 +316,8 @@ class dbPrefs {
          */
         if (strlen($key) > $this->key_size) {
             $err_msg = "Oversized user's preference key."
-                ." Some user preferences are not saved. See doc/db-backend.txt troubleshooting documentation.";
+                ." Some preferences were not saved."
+                ." See doc/db-backend.txt or contact your system administrator.";
             // error is not fatal. Only some preference is not saved.
             trigger_error($err_msg,E_USER_WARNING);
             return false;
@@ -323,7 +327,8 @@ class dbPrefs {
          */
         if (strlen($value) > $this->val_size) {
             $err_msg = "Oversized user's preference value."
-                ." Some user preferences are not saved. See doc/db-backend.txt troubleshooting documentation.";
+                ." Some preferences were not saved."
+                ." See doc/db-backend.txt or contact your system administrator.";
             // error is not fatal. Only some preference is not saved.
             trigger_error($err_msg,E_USER_WARNING);
             return false;
@@ -538,4 +543,3 @@ function getSig($data_dir, $username, $number) {
 }
 
 // vim: et ts=4
-?>
\ No newline at end of file