Browse Source

conf.pl and administration plugin can now edit the table name too

simond 23 năm trước cách đây
mục cha
commit
389e53fa0c

+ 1 - 2
ChangeLog

@@ -14,8 +14,7 @@ Version 1.2.5 -- CVS
     distributed in packages. Conf.pl now also reports when saving fails.
   - Attachment hooks now also allow specification of generic rules like
     text/* which will be used when no specific rule is available.
-  - Fixed conf.pl to preserve any value $addrbook_dsn may have when it
-    rewrites the config.php
+  - conf.pl can now configure database backed address books.
 	
 Version 1.2.4 -- 25 January 2002
 --------------------------------

+ 21 - 4
config/conf.pl

@@ -453,7 +453,8 @@ while (($command ne "q") && ($command ne "Q")) {
       print "R   Return to Main Menu\n";
    } elsif ($menu == 9) {
       print $WHT."Database\n".$NRM;
-      print "1.  DSN for Address Book : $WHT$addrbook_dsn$NRM\n";
+      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 "S   Save data\n";
       print "R   Return to Main Menu\n";
@@ -563,7 +564,8 @@ 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(); }
+         if    ($command == 1) { $addrbook_dsn   = command91(); }
+         elsif ($command == 2) { $addrbook_table = command92(); }
       }
    }   
 }
@@ -1848,6 +1850,20 @@ sub command91 {
    return $new_dsn;
 }
 
+sub command92 {
+   print "This is the name of the table you want to store the address book\n";
+   print "data in, it defaults to 'address'\n";
+   print "\n";
+   print "[$WHT$addrbook_table$NRM]: $WHT";
+   $new_table = <STDIN>;
+   if ($new_table eq "\n") {
+      $new_table = $addrbook_table;
+   } else {
+      $new_table =~ s/[\r|\n]//g;
+   }
+   return $new_table;
+}
+
 sub save_data {
     $tab = "    ";
     if(open (CF, ">config.php"))
@@ -1988,8 +2004,9 @@ sub save_data {
            print CF "\n";
         }
 
-        print CF "global \$addrbook_dsn;\n";
-        print CF "\$addrbook_dsn = '$addrbook_dsn';\n\n";
+        print CF "\nglobal \$addrbook_dsn, \$addrbook_table;\n";
+        print CF "\$addrbook_dsn = '$addrbook_dsn';\n";
+        print CF "\$addrbook_table = '$addrbook_table';\n\n";
      
         print CF "/**\n";
         print CF " * Make sure there are no characters after the PHP closing\n";

+ 5 - 2
config/config_default.php

@@ -376,12 +376,15 @@ global $ldap_server;
  * Database-driven private addressbooks
  *   DSN (Data Source Name) for a database where the private
  *   addressbooks are stored.  See doc/db-backend.txt for more info.
- *   If it is not defined, the addressbooks are stored in files
+ *   If it is not set, the addressbooks are stored in files
  *   in the data dir.
  *   The DSN is in the format: mysql://user:pass@hostname/dbname
+ *   The table is the name of the table to use within the
+ *   specified database.
  */
-global $addrbook_dsn;
+global $addrbook_dsn, $addrbook_table;
 $addrbook_dsn = '';
+$addrbook_table = 'address';
 
 /**
  * Users may search their addressbook via either a plain HTML or Javascript

+ 3 - 2
doc/db-backend.txt

@@ -52,8 +52,9 @@ The table structure should be similar to this (for MySQL):
    );
 
 
-Next, edit config/config.php and add a DSN (Data Source Name) for the
-database. It should look something like:
+Next, edit your configuration so that the address book DSN (Data Source
+Name) is specified, this can be done using either conf.pl or via the
+administration plugin. The DSN should look something like:
 
  $addrbook_dsn = 'mysql://squirreluser:sqpassword@localhost/squirrelmail';
 

+ 5 - 2
functions/addressbook.php

@@ -51,7 +51,7 @@ if(isset($addrbook_dsn) && !empty($addrbook_dsn)) {
 */
 function addressbook_init($showerr = true, $onlylocal = false) {
     global $data_dir, $username, $ldap_server, $address_book_global_filename;
-    global $addrbook_dsn;
+    global $addrbook_dsn, $addrbook_table;
 
     /* Create a new addressbook object */
     $abook = new AddressBook;
@@ -63,9 +63,12 @@ function addressbook_init($showerr = true, $onlylocal = false) {
     */
     if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
         /* Database */
+        if (!isset($addrbook_table) || isempty($addrbook_table)) {
+            $addrbook_table = 'address';
+        }
         $r = $abook->add_backend('database', Array('dsn' => $addrbook_dsn,
                             'owner' => $username,
-                            'table' => 'address'));
+                            'table' => $addrbook_table));
         if (!$r && $showerr) {
             echo _("Error initializing addressbook database.");
             exit;

+ 4 - 1
plugins/administrator/defines.php

@@ -193,6 +193,9 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"),
                  '$addrbook_dsn' => array( 'name' => _("Address book DSN"),
                                            'type' => SMOPT_TYPE_STRING,
                                            'size' => 40 ), 
+                 '$addrbook_table' => array( 'name' => _("Address book table"),
+                                             'type' => SMOPT_TYPE_STRING,
+                                             'size' => 40 ),
                  /* --------------------------------------------------------*/
                  'Group7' => array( 'name' => _("Themes"),
                                     'type' => SMOPT_TYPE_TITLE ),
@@ -205,4 +208,4 @@ $defcfg = array( '$config_version' => array( 'name' => _("Config File Version"),
 
                );
 
-?>
+?>