X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fabook_database.php;h=0964a85273a5b1463431e8eb75d75f511a43cd4c;hb=d72176b0e0e023cd6d149e1a24ac7a15e8290e01;hp=cd40858692ff3aa288bd4f1a4139295fb055e620;hpb=91be236255fceea4fd5880946d416539a8f4c4a4;p=squirrelmail.git diff --git a/functions/abook_database.php b/functions/abook_database.php index cd408586..0964a852 100644 --- a/functions/abook_database.php +++ b/functions/abook_database.php @@ -4,7 +4,7 @@ ** abook_database.php ** ** Backend for personal addressbook stored in a database, - ** accessed using the DB-casses in PEAR. + ** accessed using the DB-classes in PEAR. ** ** IMPORTANT: The PEAR modules must be in the include path ** for this class to work. @@ -27,15 +27,15 @@ ** $Id$ **/ - require_once("DB.php"); + require_once('DB.php'); class abook_database extends addressbook_backend { - var $btype = "local"; - var $bname = "database"; + var $btype = 'local'; + var $bname = 'database'; - var $dsn = ""; - var $table = ""; - var $owner = ""; + var $dsn = ''; + var $table = ''; + var $owner = ''; var $dbh = false; var $writeable = true; @@ -44,7 +44,7 @@ // Constructor function abook_database($param) { - $this->sname = _('Personal address book'); + $this->sname = _("Personal address book"); if(is_array($param)) { if(empty($param['dsn']) || @@ -83,7 +83,7 @@ $dbh = DB::connect($this->dsn, true); if(DB::isError($dbh) || DB::isWarning($dbh)) - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($dbh))); $this->dbh = $dbh; @@ -108,18 +108,18 @@ if(is_array($expr)) return; // Make regexp from glob'ed expression - $expr = ereg_replace('\?', '_', $expr); - $expr = ereg_replace('\*'. '%', $expr); + $expr = str_replace('?', '_', $expr); + $expr = str_replace('*', '%', $expr); $expr = $this->dbh->quoteString($expr); $expr = "%$expr%"; - $query = sprintf('SELECT * FROM %s WHERE owner=\'%s\' AND ' . - '(firstname LIKE \'%s\' OR lastname LIKE \'%s\')', + $query = sprintf("SELECT * FROM %s WHERE owner='%s' AND " . + "(firstname LIKE '%s' OR lastname LIKE '%s')", $this->table, $this->owner, $expr, $expr); $res = $this->dbh->query($query); if(DB::isError($res)) - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($res))); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { @@ -145,13 +145,13 @@ if(!$this->open()) return false; - $query = sprintf('SELECT * FROM %s WHERE owner=\'%s\' AND nickname=\'%s\'', + $query = sprintf("SELECT * FROM %s WHERE owner='%s' AND nickname='%s'", $this->table, $this->owner, $alias); $res = $this->dbh->query($query); if(DB::isError($res)) - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($res))); if ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { @@ -174,13 +174,13 @@ if(!$this->open()) return false; - $query = sprintf(;SELECT * FROM %s WHERE owner=\'%s\';, + $query = sprintf("SELECT * FROM %s WHERE owner='%s'", $this->table, $this->owner); $res = $this->dbh->query($query); if(DB::isError($res)) - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($res))); while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { @@ -199,7 +199,7 @@ // Add address function add($userdata) { if(!$this->writeable) - return $this->set_error(_('Addressbook is read-only')); + return $this->set_error(_("Addressbook is read-only")); if(!$this->open()) return false; @@ -207,11 +207,11 @@ // See if user exist already $ret = $this->lookup($userdata['nickname']); if(!empty($ret)) - return $this->set_error(sprintf(_('User \'%s\' already exist'), + return $this->set_error(sprintf(_("User '%s' already exist"), $ret['nickname'])); // Create query - $query = sprintf('INSERT INTO %s (owner, nickname, firstname, ' . + $query = sprintf("INSERT INTO %s (owner, nickname, firstname, " . "lastname, email, label) VALUES('%s','%s','%s'," . "'%s','%s','%s')", $this->table, $this->owner, @@ -226,25 +226,25 @@ if($r == DB_OK) return true; // Fail - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($r))); } // Delete address function remove($alias) { if(!$this->writeable) - return $this->set_error(_('Addressbook is read-only')); + return $this->set_error(_("Addressbook is read-only")); if(!$this->open()) return false; // Create query - $query = sprintf('DELETE FROM %s WHERE owner=\'%s\' AND (', + $query = sprintf("DELETE FROM %s WHERE owner='%s' AND (", $this->table, $this->owner); $sepstr = ''; while(list($undef, $nickname) = each($alias)) { - $query .= sprintf('%s nickname=\'%s\' ', $sepstr, + $query .= sprintf("%s nickname='%s' ", $sepstr, $this->dbh->quoteString($nickname)); $sepstr = 'OR'; } @@ -255,14 +255,14 @@ if($r == DB_OK) return true; // Fail - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($r))); } // Modify address function modify($alias, $userdata) { if(!$this->writeable) - return $this->set_error(_('Addressbook is read-only')); + return $this->set_error(_("Addressbook is read-only")); if(!$this->open()) return false; @@ -270,7 +270,7 @@ // See if user exist $ret = $this->lookup($alias); if(empty($ret)) - return $this->set_error(sprintf(_('User \'%s\' does not exist'), + return $this->set_error(sprintf(_("User '%s' does not exist"), $alias)); // Create query @@ -291,7 +291,7 @@ if($r == DB_OK) return true; // Fail - return $this->set_error(sprintf(_('Database error: %s'), + return $this->set_error(sprintf(_("Database error: %s"), DB::errorMessage($r))); } } // End of class abook_database