Source for file db_prefs.php
Documentation is available at db_prefs.php
* This contains functions for manipulating user preferences
* stored in a database, accessed though the Pear DB layer.
* The preferences table should have three columns:
* CREATE TABLE userprefs (user CHAR(128) NOT NULL DEFAULT '',
* prefkey CHAR(64) NOT NULL DEFAULT '',
* prefval BLOB NOT NULL DEFAULT '',
* primary key (user,prefkey));
* 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: db_prefs.php,v 1.31.2.9 2006/04/14 22:27:07 jervfors Exp $
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.");
global $prefs_are_cached, $prefs_cache;
global $prefs_are_cached, $prefs_cache;
printf( _("Preference database error (%s). Exiting abnormally"),
$db->fillPrefsCache($username);
printf( _("Preference database error (%s). Exiting abnormally"),
$prefs_are_cached =
true;
* Completely undocumented class - someone document it!
var $default =
Array('theme_default' =>
0,
'show_html_default' =>
'0');
global $prefs_dsn, $prefs_table;
global $prefs_user_field, $prefs_key_field, $prefs_val_field;
if (!empty($prefs_table)) {
$this->table =
$prefs_table;
if (!empty($prefs_user_field)) {
if (!empty($prefs_key_field)) {
if (!empty($prefs_val_field)) {
$dbh =
DB::connect($prefs_dsn, true);
$this->error =
DB::errorMessage($dbh);
printf(_("Preference database error (%s). Exiting abnormally"),
printf(_("Preference database error (%s). Exiting abnormally"),
function getKey($user, $key, $default =
'') {
if (isset
($prefs_cache[$key])) {
return $prefs_cache[$key];
$query =
sprintf("DELETE FROM %s WHERE %s='%s' AND %s='%s'",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key));
$res =
$this->dbh->simpleQuery($query);
unset
($prefs_cache[$key]);
function setKey($user, $key, $value) {
$query =
sprintf("REPLACE INTO %s (%s, %s, %s) ".
"VALUES('%s','%s','%s')",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key),
$this->dbh->quoteString($value));
$res =
$this->dbh->simpleQuery($query);
$this->dbh->simpleQuery("BEGIN TRANSACTION");
$query =
sprintf("DELETE FROM %s WHERE %s='%s' AND %s='%s'",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key));
$res =
$this->dbh->simpleQuery($query);
$this->dbh->simpleQuery("ROLLBACK TRANSACTION");
$query =
sprintf("INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s')",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key),
$this->dbh->quoteString($value));
$res =
$this->dbh->simpleQuery($query);
$this->dbh->simpleQuery("ROLLBACK TRANSACTION");
$this->dbh->simpleQuery("COMMIT TRANSACTION");
$query =
sprintf("DELETE FROM %s WHERE %s='%s' AND %s='%s'",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key));
$res =
$this->dbh->simpleQuery($query);
$query =
sprintf("INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s')",
$this->dbh->quoteString($user),
$this->dbh->quoteString($key),
$this->dbh->quoteString($value));
$res =
$this->dbh->simpleQuery($query);
$query =
sprintf("SELECT %s as prefkey, %s as prefval FROM %s ".
$this->dbh->quoteString($user));
$res =
$this->dbh->query($query);
while ($row =
$res->fetchRow(DB_FETCHMODE_ASSOC)) {
$prefs_cache[$row['prefkey']] =
$row['prefval'];
} /* end class dbPrefs */
* returns the value for the pref $string
function getPref($data_dir, $username, $string, $default =
'') {
printf( _("Preference database error (%s). Exiting abnormally"),
return $db->getKey($username, $string, $default);
* Remove the pref $string
function removePref($data_dir, $username, $string) {
if (isset
($prefs_cache[$string])) {
unset
($prefs_cache[$string]);
* sets the pref, $string, to $set_to
function setPref($data_dir, $username, $string, $set_to) {
if (isset
($prefs_cache[$string]) &&
($prefs_cache[$string] ==
$set_to)) {
$db->setKey($username, $string, $set_to);
$prefs_cache[$string] =
$set_to;
assert ('$set_to == $prefs_cache[$string]');
* This checks if the prefs are available
function setSig($data_dir, $username, $number, $string) {
$key =
'___signature___';
$key =
sprintf('___sig%s___', $number);
setPref($data_dir, $username, $key, $string);
function getSig($data_dir, $username, $number) {
$key =
'___signature___';
$key =
sprintf('___sig%d___', $number);
return getPref($data_dir, $username, $key);
Documentation generated on Sat, 07 Oct 2006 16:30:43 +0300 by phpDocumentor 1.3.0RC6