X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Faddressbook.php;h=af819f15cd56823263605992907c7395db882896;hb=1814c39b2c67433775174accce117c9fe550ea31;hp=71441f3916c1d52bb640769733027ee94e2f27bc;hpb=6ad2bbe2b31a6cc3ba8231e798e2a8fe254fdb31;p=squirrelmail.git diff --git a/functions/addressbook.php b/functions/addressbook.php index 71441f39..af819f15 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -2,7 +2,7 @@ /** * functions/addressbook.php - Functions and classes for the addressbook system * - * Copyright (c) 1999-2004 The SquirrelMail Project Team + * Copyright (c) 1999-2005 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * Functions require SM_PATH and support of forms.php functions @@ -12,14 +12,28 @@ * @subpackage addressbook */ +/** + * If SM_PATH isn't defined, define it. Required to include files. + * @ignore + */ +if (!defined('SM_PATH')) { + define('SM_PATH','../'); +} + +/* make sure that display_messages.php is loaded */ +include_once(SM_PATH . 'functions/display_messages.php'); + global $addrbook_dsn, $addrbook_global_dsn; /** - Create and initialize an addressbook object. - Returns the created object -*/ + * Create and initialize an addressbook object. + * @param boolean $showerr display any address book init errors. html page header + * must be created before calling addressbook_init() with $showerr enabled. + * @param boolean $onlylocal enable only local address book backends + * @return object address book object. + */ function addressbook_init($showerr = true, $onlylocal = false) { - global $data_dir, $username, $ldap_server, $address_book_global_filename; + global $data_dir, $username, $color, $ldap_server, $address_book_global_filename; global $addrbook_dsn, $addrbook_table; global $abook_global_file, $abook_global_file_writeable; global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing; @@ -27,6 +41,9 @@ function addressbook_init($showerr = true, $onlylocal = false) { /* Create a new addressbook object */ $abook = new AddressBook; + /* Create empty error message */ + $abook_init_error=''; + /* Always add a local backend. We use *either* file-based *or* a database addressbook. If $addrbook_dsn is set, the database @@ -41,8 +58,7 @@ function addressbook_init($showerr = true, $onlylocal = false) { 'owner' => $username, 'table' => $addrbook_table)); if (!$r && $showerr) { - echo _("Error initializing addressbook database."); - exit; + $abook_init_error.=_("Error initializing addressbook database.") . "
\n" . $abook->error; } } else { /* File */ @@ -50,8 +66,8 @@ function addressbook_init($showerr = true, $onlylocal = false) { $r = $abook->add_backend('local_file', Array('filename' => $filename, 'create' => true)); if(!$r && $showerr) { - printf( _("Error opening file %s"), $filename ); - exit; + // no need to use $abook->error, because message explains error. + $abook_init_error.=sprintf( _("Error opening file %s"), $filename ); } } @@ -61,8 +77,13 @@ function addressbook_init($showerr = true, $onlylocal = false) { && trim($abook_global_file)!=''){ // Detect place of address book if (! preg_match("/[\/\\\]/",$abook_global_file)) { - // no path chars - $abook_global_filename=$data_dir . $abook_global_file; + /* no path chars, address book stored in data directory + * make sure that there is a slash between data directory + * and address book file name + */ + $abook_global_filename=$data_dir + . ((substr($data_dir, -1) != '/') ? '/' : '') + . $abook_global_file; } elseif (preg_match("/^\/|\w:/",$abook_global_file)) { // full path is set in options (starts with slash or x:) $abook_global_filename=$abook_global_file; @@ -73,9 +94,11 @@ function addressbook_init($showerr = true, $onlylocal = false) { 'name' => _("Global address book"), 'detect_writeable' => false, 'writeable'=> $abook_global_file_writeable)); + + /* global abook init error is not fatal. add error message and continue */ if (!$r && $showerr) { - echo _("Error initializing global addressbook."); - exit; + if ($abook_init_error!='') $abook_init_error.="
\n"; + $abook_init_error.=_("Error initializing global addressbook.") . "
\n" . $abook->error; } } @@ -92,37 +115,47 @@ function addressbook_init($showerr = true, $onlylocal = false) { 'writeable' => $addrbook_global_writeable, 'listing' => $addrbook_global_listing, 'table' => $addrbook_global_table)); + /* global abook init error is not fatal. add error message and continue */ + if (!$r && $showerr) { + if ($abook_init_error!='') $abook_init_error.="
\n"; + $abook_init_error.=_("Error initializing global addressbook.") . "
\n" . $abook->error; + } } /* * hook allows to include different address book backends. * plugins should extract $abook and $r from arguments * and use same add_backend commands as above functions. + * @since 1.5.1 */ $hookReturn = do_hook('abook_init', $abook, $r); $abook = $hookReturn[1]; $r = $hookReturn[2]; - if ($onlylocal) { - return $abook; - } - - /* Load configured LDAP servers (if PHP has LDAP support) */ - if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) { - reset($ldap_server); - while (list($undef,$param) = each($ldap_server)) { - if (is_array($param)) { - $r = $abook->add_backend('ldap_server', $param); - if (!$r && $showerr) { - printf( ' ' . _("Error initializing LDAP server %s:") . - "
\n", $param['host']); - echo ' ' . $abook->error; - exit; + if (! $onlylocal) { + /* Load configured LDAP servers (if PHP has LDAP support) */ + if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) { + reset($ldap_server); + while (list($undef,$param) = each($ldap_server)) { + if (is_array($param)) { + $r = $abook->add_backend('ldap_server', $param); + if (!$r && $showerr) { + if ($abook_init_error!='') $abook_init_error.="
\n"; + $abook_init_error.=sprintf(_("Error initializing LDAP server %s:") . + "
\n", $param['host']); + $abook_init_error.= $abook->error; + } } } - } - } + } // end of ldap server init + } // end of remote abook backend init + /** + * display address book init errors. + */ + if ($abook_init_error!='' && $showerr) { + error_box($abook_init_error,$color); + } /* Return the initialized object */ return $abook; } @@ -147,7 +180,7 @@ function abook_create_form($form_url,$name,$title,$button,$defdata=array()) { 'center', $color[0] ) ) - , 'center', '', 'width="100%"' ) ."\n"; + , 'center', '', 'width="90%"' ) ."\n"; address_form($name, $button, $defdata); } @@ -896,6 +929,7 @@ if((isset($addrbook_dsn) && !empty($addrbook_dsn)) || * class must follow address book class coding standards. * * see addressbook_backend class and functions/abook_*.php files. + * @since 1.5.1 */ do_hook('abook_add_class');