From 4f40a59dc3b472439d14ea1d4918861fc80465e3 Mon Sep 17 00:00:00 2001 From: simond Date: Thu, 31 Jan 2002 11:43:08 +0000 Subject: [PATCH] conf.pl and administration plugin can now edit the table name too git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2315 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 3 +-- config/conf.pl | 25 +++++++++++++++++++++---- config/config_default.php | 7 +++++-- doc/db-backend.txt | 5 +++-- functions/addressbook.php | 7 +++++-- plugins/administrator/defines.php | 5 ++++- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0429fc6a..5516631a 100644 --- a/ChangeLog +++ b/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 -------------------------------- diff --git a/config/conf.pl b/config/conf.pl index 20d736f5..e376284e 100755 --- a/config/conf.pl +++ b/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 = ; + 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"; diff --git a/config/config_default.php b/config/config_default.php index 62946d20..a8c2d8ff 100644 --- a/config/config_default.php +++ b/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 diff --git a/doc/db-backend.txt b/doc/db-backend.txt index 41feffc0..325f3ad8 100644 --- a/doc/db-backend.txt +++ b/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'; diff --git a/functions/addressbook.php b/functions/addressbook.php index 61b9e7be..f0f4def4 100644 --- a/functions/addressbook.php +++ b/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; diff --git a/plugins/administrator/defines.php b/plugins/administrator/defines.php index 0ec2c17a..b405a840 100644 --- a/plugins/administrator/defines.php +++ b/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"), ); -?> \ No newline at end of file +?> -- 2.25.1