Take X-Forwarded-Host HTTP header in consideration when constructing
[squirrelmail.git] / functions / abook_database.php
index 7a386e7c59f001993545e1cb98697f4ebc0b4bee..cd29624de766652b3d8c0d061c8f87256e444df7 100644 (file)
@@ -1,26 +1,20 @@
 <?php
+
 /**
  * abook_database.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
+ * @copyright &copy; 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage addressbook
  */
 
-/** Needs the DB functions */
-if (!include_once('DB.php')) {
-    // same error also in db_prefs.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;
-}
+/**
+ * Needs the DB functions
+ * Don't display errors here. Error will be set in class constructor function.
+ */
+@include_once('DB.php');
 
 /**
  * Address book in a database backend
@@ -104,6 +98,16 @@ class abook_database extends addressbook_backend {
     function abook_database($param) {
         $this->sname = _("Personal address book");
 
+        /* test if Pear DB class is available and freak out if it is not */
+        if (! class_exists('DB')) {
+            // same error also in db_prefs.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.");
+            return $this->set_error($error);
+        }
+
         if (is_array($param)) {
             if (empty($param['dsn']) ||
                 empty($param['table']) ||
@@ -179,7 +183,7 @@ class abook_database extends addressbook_backend {
      * @param string $expr search expression
      * @return array search results
      */
-    function &search($expr) {
+    function search($expr) {
         $ret = array();
         if(!$this->open()) {
             return false;
@@ -228,7 +232,7 @@ class abook_database extends addressbook_backend {
      * @param string $alias alias
      * @return array search results
      */
-    function &lookup($alias) {
+    function lookup($alias) {
         if (empty($alias)) {
             return array();
         }
@@ -266,7 +270,7 @@ class abook_database extends addressbook_backend {
      * List all addresses
      * @return array search results
      */
-    function &list_addr() {
+    function list_addr() {
         $ret = array();
         if (!$this->open()) {
             return false;
@@ -317,8 +321,7 @@ class abook_database extends addressbook_backend {
         /* See if user exist already */
         $ret = $this->lookup($userdata['nickname']);
         if (!empty($ret)) {
-            return $this->set_error(sprintf(_("User %s already exists"),
-                        '&quot;' . $ret['nickname'] . '&quot;'));
+            return $this->set_error(sprintf(_("User \"%s\" already exists"),$ret['nickname']));
         }
 
         /* Create query */
@@ -328,9 +331,9 @@ class abook_database extends addressbook_backend {
                          $this->table, $this->owner,
                          $this->dbh->quoteString($userdata['nickname']),
                          $this->dbh->quoteString($userdata['firstname']),
-                         $this->dbh->quoteString($userdata['lastname']),
+                         $this->dbh->quoteString((!empty($userdata['lastname'])?$userdata['lastname']:'')),
                          $this->dbh->quoteString($userdata['email']),
-                         $this->dbh->quoteString($userdata['label']) );
+                         $this->dbh->quoteString((!empty($userdata['label'])?$userdata['label']:'')) );
 
          /* Do the insert */
          $r = $this->dbh->simpleQuery($query);
@@ -344,8 +347,9 @@ class abook_database extends addressbook_backend {
     }
 
     /**
-     * Delete address
-     * @param string $alias alias that has to be deleted
+     * Deletes address book entries
+     * @param array $alias aliases that have to be deleted. numerical 
+     *  array with nickname values
      * @return bool
      */
     function remove($alias) {
@@ -398,8 +402,7 @@ class abook_database extends addressbook_backend {
          /* See if user exist */
         $ret = $this->lookup($alias);
         if (empty($ret)) {
-            return $this->set_error(sprintf(_("User %s does not exist"),
-                        '&qout;' . $alias . '&qout;'));
+            return $this->set_error(sprintf(_("User \"%s\" does not exist"),$alias));
         }
 
         /* Create query */
@@ -409,9 +412,9 @@ class abook_database extends addressbook_backend {
                          $this->table,
                          $this->dbh->quoteString($userdata['nickname']),
                          $this->dbh->quoteString($userdata['firstname']),
-                         $this->dbh->quoteString($userdata['lastname']),
+                         $this->dbh->quoteString((!empty($userdata['lastname'])?$userdata['lastname']:'')),
                          $this->dbh->quoteString($userdata['email']),
-                         $this->dbh->quoteString($userdata['label']),
+                         $this->dbh->quoteString((!empty($userdata['label'])?$userdata['label']:'')),
                          $this->owner,
                          $this->dbh->quoteString($alias) );
 
@@ -428,4 +431,4 @@ class abook_database extends addressbook_backend {
 } /* End of class abook_database */
 
 // vim: et ts=4
-?>
\ No newline at end of file
+?>