33 define(
'SMDB_UNKNOWN', 0);
35 define(
'SMDB_MYSQL', 1);
37 define(
'SMDB_PGSQL', 2);
39 if (!include_once(
'DB.php')) {
41 require_once(
SM_PATH .
'functions/display_messages.php');
42 $error =
_(
"Could not include PEAR database functions required for the database backend.") .
"<br />\n";
43 $error .=
sprintf(
_(
"Is PEAR installed, and is the include path set correctly to find %s?"),
44 '<tt>DB.php</tt>') .
"<br />\n";
45 $error .=
_(
"Please contact your system administrator and report this error.");
68 if(isset($db->error)) {
69 printf(
_(
"Preference database error (%s). Exiting abnormally"),
75 if (isset($db->error)) {
76 printf(
_(
"Preference database error (%s). Exiting abnormally"),
102 'show_html_default' =>
'0');
108 if(isset($this->dbh)) {
129 $this->user_field =
'"' . $this->user_field .
'"';
140 if(DB::isError(
$dbh)) {
141 $this->error = DB::errorMessage(
$dbh);
151 printf(
_(
"Preference database error (%s). Exiting abnormally"),
154 printf(
_(
"Preference database error (%s). Exiting abnormally"),
155 DB::errorMessage($res));
176 if (isset($this->
default[$key])) {
177 $result = $this->
default[$key];
190 if (!$this->
open()) {
193 $query =
sprintf(
"DELETE FROM %s WHERE %s='%s' AND %s='%s'",
196 $this->dbh->quoteString($user),
198 $this->dbh->quoteString($key));
200 $res = $this->dbh->simpleQuery($query);
201 if(DB::isError($res)) {
211 if (!$this->
open()) {
215 $query =
sprintf(
"REPLACE INTO %s (%s, %s, %s) ".
216 "VALUES('%s','%s','%s')",
221 $this->dbh->quoteString($user),
222 $this->dbh->quoteString($key),
223 $this->dbh->quoteString($value));
225 $res = $this->dbh->simpleQuery($query);
226 if(DB::isError($res)) {
230 $this->dbh->simpleQuery(
"BEGIN TRANSACTION");
231 $query =
sprintf(
"DELETE FROM %s WHERE %s='%s' AND %s='%s'",
234 $this->dbh->quoteString($user),
236 $this->dbh->quoteString($key));
237 $res = $this->dbh->simpleQuery($query);
238 if (DB::isError($res)) {
239 $this->dbh->simpleQuery(
"ROLLBACK TRANSACTION");
242 $query =
sprintf(
"INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s')",
247 $this->dbh->quoteString($user),
248 $this->dbh->quoteString($key),
249 $this->dbh->quoteString($value));
250 $res = $this->dbh->simpleQuery($query);
251 if (DB::isError($res)) {
252 $this->dbh->simpleQuery(
"ROLLBACK TRANSACTION");
255 $this->dbh->simpleQuery(
"COMMIT TRANSACTION");
257 $query =
sprintf(
"DELETE FROM %s WHERE %s='%s' AND %s='%s'",
260 $this->dbh->quoteString($user),
262 $this->dbh->quoteString($key));
263 $res = $this->dbh->simpleQuery($query);
264 if (DB::isError($res)) {
267 $query =
sprintf(
"INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s')",
272 $this->dbh->quoteString($user),
273 $this->dbh->quoteString($key),
274 $this->dbh->quoteString($value));
275 $res = $this->dbh->simpleQuery($query);
276 if (DB::isError($res)) {
287 if (!$this->
open()) {
291 $prefs_cache = array();
292 $query =
sprintf(
"SELECT %s as prefkey, %s as prefval FROM %s ".
298 $this->dbh->quoteString($user));
299 $res = $this->dbh->query($query);
300 if (DB::isError($res)) {
304 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
318 if(isset($db->error)) {
319 printf(
_(
"Preference database error (%s). Exiting abnormally"),
324 return $db->getKey(
$username, $string, $default);
334 if(isset($db->error)) {
359 if ($set_to ===
'') {
365 if(isset($db->error)) {
369 $db->setKey(
$username, $string, $set_to);
371 assert_options(ASSERT_ACTIVE, 1);
372 assert_options(ASSERT_BAIL, 1);
373 assert (
'$set_to == $prefs_cache[$string]');
384 if(isset($db->error)) {
394 if ($number ==
"g") {
395 $key =
'___signature___';
397 $key =
sprintf(
'___sig%s___', $number);
408 if ($number ==
"g") {
409 $key =
'___signature___';
411 $key =
sprintf(
'___sig%d___', $number);