Add support for renaming db prefs fieldnames (this doesn't add postgres support,...
authorsimond <simond@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 1 Mar 2002 09:01:35 +0000 (09:01 +0000)
committersimond <simond@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 1 Mar 2002 09:01:35 +0000 (09:01 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2525 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/conf.pl
functions/db_prefs.php
plugins/administrator/defines.php

index e43484941498f7aff841365a0c3023ace35e4d38..223a0bb44810db9c5a8c24f1beef4c13a60552d2 100755 (executable)
@@ -284,6 +284,15 @@ if ( !$edit_identity ) {
 if ( !$edit_name ) {
     $edit_name = "true";
 }
+if ( !$prefs_user_field ) {
+    $prefs_user_field = 'user';
+}
+if ( !$prefs_key_field ) {
+    $prefs_key_field = 'prefkey';
+}
+if ( !$prefs_val_field ) {
+    $prefs_val_field = 'prefval';
+}
 
 if ( $ARGV[0] eq '--install-plugin' ) {
     print "Activating plugin " . $ARGV[1] . "\n";
@@ -475,8 +484,12 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print $WHT. "Database\n" . $NRM;
         print "1.  DSN for Address Book   : $WHT$addrbook_dsn$NRM\n";
         print "2.  Table for Address Book : $WHT$addrbook_table$NRM\n";
+        print "\n";
         print "3.  DSN for Preferences    : $WHT$prefs_dsn$NRM\n";
         print "4.  Table for Preferences  : $WHT$prefs_table$NRM\n";
+        print "5.  Field for username     : $WHT$prefs_user_field$NRM\n";
+        print "6.  Field for prefs key    : $WHT$prefs_key_field$NRM\n";
+        print "7.  Field for prefs value  : $WHT$prefs_val_field$NRM\n";
         print "\n";
         print "S   Save data\n";
         print "R   Return to Main Menu\n";
@@ -590,10 +603,13 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
             if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
             elsif ( $command eq "a" ) { command8s(); }
         } elsif ( $menu == 9 ) {
-            if    ( $command == 1 ) { $addrbook_dsn   = command91(); }
-            elsif ( $command == 2 ) { $addrbook_table = command92(); }
-            elsif ( $command == 3 ) { $prefs_dsn      = command93(); }
-            elsif ( $command == 4 ) { $prefs_table    = command94(); }
+            if    ( $command == 1 ) { $addrbook_dsn     = command91(); }
+            elsif ( $command == 2 ) { $addrbook_table   = command92(); }
+            elsif ( $command == 3 ) { $prefs_dsn        = command93(); }
+            elsif ( $command == 4 ) { $prefs_table      = command94(); }
+            elsif ( $command == 5 ) { $prefs_user_field = command95(); }
+            elsif ( $command == 6 ) { $prefs_key_field  = command96(); }
+            elsif ( $command == 7 ) { $prefs_val_field  = command97(); }
         }
     }
 }
@@ -2002,7 +2018,7 @@ sub command93 {
 
 sub command94 {
     print "This is the name of the table you want to store the preferences\n";
-    print "data in, it defaults to 'address'\n";
+    print "data in, it defaults to 'userprefs'\n";
     print "\n";
     print "[$WHT$prefs_table$NRM]: $WHT";
     $new_table = <STDIN>;
@@ -2014,6 +2030,50 @@ sub command94 {
     return $new_table;
 }
 
+sub command95 {
+    print "This is the name of the field in which you want to store the\n";
+    print "username of the person the prefs are for. It default to 'user'\n";
+    print "which clashes with a reserved keyword in PostgreSQL so this\n";
+    print "will need to be changed for that database at least\n";
+    print "\n";
+    print "[$WHT$prefs_user_field$NRM]: $WHT";
+    $new_field = <STDIN>;
+    if ( $new_field eq "\n" ) {
+        $new_field = $prefs_user_field;
+    } else {
+        $new_field =~ s/[\r|\n]//g;
+    }
+    return $new_field;
+}
+
+sub command96 {
+    print "This is the name of the field in which you want to store the\n";
+    print "preferences keyword. It defaults to 'prefkey'\n";
+    print "\n";
+    print "[$WHT$prefs_key_field$NRM]: $WHT";
+    $new_field = <STDIN>;
+    if ( $new_field eq "\n" ) {
+        $new_field = $prefs_key_field;
+    } else {
+        $new_field =~ s/[\r|\n]//g;
+    }
+    return $new_field;
+}
+
+sub command97 {
+    print "This is the name of the field in which you want to store the\n";
+    print "preferences value. It defaults to 'prefval'\n";
+    print "\n";
+    print "[$WHT$prefs_val_field$NRM]: $WHT";
+    $new_field = <STDIN>;
+    if ( $new_field eq "\n" ) {
+        $new_field = $prefs_val_field;
+    } else {
+        $new_field =~ s/[\r|\n]//g;
+    }
+    return $new_field;
+}
+
 sub save_data {
     $tab = "    ";
     if ( open( CF, ">config.php" ) ) {
@@ -2134,7 +2194,11 @@ sub save_data {
         print CF "\$addrbook_dsn = '$addrbook_dsn';\n";
         print CF "\$addrbook_table = '$addrbook_table';\n\n";
         print CF "\$prefs_dsn = '$prefs_dsn';\n";
-        print CF "\$prefs_table = '$prefs_table';\n\n";
+        print CF "\$prefs_table = '$prefs_table';\n";
+        print CF "\$prefs_user_field = '$prefs_user_field';\n";
+        print CF "\$prefs_key_field = '$prefs_key_field';\n";
+        print CF "\$prefs_val_field = '$prefs_val_field';\n";
+        print CF "\n";
 
         print CF "/**\n";
         print CF " * Make sure there are no characters after the PHP closing\n";
index 1aab90ba556227a008c7fc4ca054fbc2a8f889b9..c11b2c5983aeaf01696b637ae93ffea63c9cace2 100644 (file)
@@ -16,8 +16,8 @@
  * Database:
  * ---------
  *
- * The preferences table should have tree columns:
- *    username   char  \  primary
+ * The preferences table should have three columns:
+ *    user       char  \  primary
  *    prefkey    char  /  key
  *    prefval    blob
  *
@@ -69,6 +69,9 @@ function cachePrefValues($username) {
 
 class dbPrefs {
     var $table = 'userprefs';
+    var $user_field = 'user';
+    var $key_field = 'prefkey';
+    var $val_field = 'prefval';
 
     var $dbh   = NULL;
     var $error = NULL;
@@ -86,6 +89,15 @@ class dbPrefs {
         if (!empty($prefs_table)) {
             $this->table = $prefs_table;
         }
+        if (!empty($prefs_user_field)) {
+            $this->user_field = $prefs_user_field;
+        }
+        if (!empty($prefs_key_field)) {
+            $this->key_field = $prefs_key_field;
+        }
+        if (!empty($prefs_val_field)) {
+            $this->val_field = $prefs_val_field;
+        }
         $dbh = DB::connect($prefs_dsn, true);
 
         if(DB::isError($dbh) || DB::isWarning($dbh)) {
@@ -131,9 +143,11 @@ class dbPrefs {
         if (!$this->open()) {
             return false;
         }
-        $query = sprintf("DELETE FROM %s WHERE user='%s' AND prefkey='%s'",
+        $query = sprintf("DELETE FROM %s WHERE %s='%s' AND %s='%s'",
                          $this->table,
+                         $this->user_field,
                          $this->dbh->quoteString($user),
+                         $this->key_field,
                          $this->dbh->quoteString($key));
 
         $res = $this->dbh->simpleQuery($query);
@@ -154,9 +168,12 @@ class dbPrefs {
         if (!$this->open()) {
             return false;
         }
-        $query = sprintf("REPLACE INTO %s (user,prefkey,prefval) ".
+        $query = sprintf("REPLACE INTO %s (%s, %s, %s) ".
                          "VALUES('%s','%s','%s')",
                          $this->table,
+                         $this->user_field,
+                         $this->key_field,
+                         $this->val_field,
                          $this->dbh->quoteString($user),
                          $this->dbh->quoteString($key),
                          $this->dbh->quoteString($value));
@@ -177,9 +194,12 @@ class dbPrefs {
         }
 
         $prefs_cache = array();
-        $query = sprintf("SELECT prefkey, prefval FROM %s ".
-                         "WHERE user = '%s'",
+        $query = sprintf("SELECT %s as prefkey, %s as prefval FROM %s ".
+                         "WHERE %s = '%s'",
+                         $this->key_field,
+                         $this->val_field,
                          $this->table,
+                         $this->user_field,
                          $this->dbh->quoteString($user));
         $res = $this->dbh->query($query);
         if (DB::isError($res)) {
@@ -200,10 +220,16 @@ class dbPrefs {
         if (!$this->open()) {
             return;
         }
-        $query = sprintf("SELECT * FROM %s WHERE user='%s' ".
-                         "AND prefkey LIKE 'highlight%%' ORDER BY prefkey",
+        $query = sprintf("SELECT %s, %s as prefkey, %s as prefval FROM %s WHERE %s='%s' ".
+                         "AND %s LIKE 'highlight%%' ORDER BY %s",
+                         $this->user_field,
+                         $this->key_field,
+                         $this->val_field,
                          $this->table,
-                         $this->dbh->quoteString($user));
+                         $this->user_field,
+                         $this->dbh->quoteString($user),
+                         $this->key_field,
+                         $this->key_field);
 
         $res = $this->dbh->query($query);
         if(DB::isError($res)) {
@@ -224,11 +250,14 @@ class dbPrefs {
             $hilinum++;
 
             if($oldkey != $newkey) {
-                $query = sprintf("UPDATE %s SET prefkey='%s' ".
-                                 "WHERE user ='%s' AND prefkey='%s'",
+                $query = sprintf("UPDATE %s SET %s='%s' ".
+                                 "WHERE %s ='%s' AND %s='%s'",
                                  $this->table,
+                                 $this->key_field,
                                  $this->dbh->quoteString($newkey),
+                                 $this->user_field,
                                  $this->dbh->quoteString($user),
+                                 $this->key_field,
                                  $this->dbh->quoteString($oldkey));
 
                 $res = $this->dbh->simpleQuery($query);
index 6b3abf7bf3e21c7ff2232324dc0ceb36ff29f7b9..5d41a60f9d7efd3638ace11bbfe99b511b8257f8 100644 (file)
@@ -227,6 +227,18 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"),
                                           'type' => SMOPT_TYPE_STRING,
                                           'size' => 40,
                                           'default' => 'userprefs' ),
+                 '$prefs_user_field' => array('name' => _("Preferences username field"),
+                                              'type' => SMOPT_TYPE_STRING,
+                                              'size' => 40,
+                                              'default' => 'user' ),
+                 '$prefs_key_field' => array('name' => _("Preferences key field"),
+                                             'type' => SMOPT_TYPE_STRING,
+                                             'size' => 40,
+                                             'default' => 'prefkey' ),
+                 '$prefs_val_field' => array('name' => _("Preferences value field"),
+                                             'type' => SMOPT_TYPE_STRING,
+                                             'size' => 40,
+                                             'default' => 'prefval' ),
                  /* --------------------------------------------------------*/
                  'Group7' => array( 'name' => _("Themes"),
                                     'type' => SMOPT_TYPE_TITLE ),