-require_once('../src/validate.php');
-require_once('../functions/array.php');
-require_once('../functions/display_messages.php');
-require_once('../functions/addressbook.php');
-require_once('../functions/strings.php');
-require_once('../functions/html.php');
-
-/* Make an input field */
-function adressbook_inp_field($label, $field, $name, $size, $values, $add) {
- global $color;
- $td_str = '<INPUT NAME="' . $name . '[' . $field . ']" SIZE="' . $size . '" VALUE="';
- if (isset($values[$field])) {
- $td_str .= htmlspecialchars($values[$field]);
+/**
+ This is the path to the global site-wide addressbook.
+ It looks and feels just like a user's .abook file
+ If this is in the data directory, use "$data_dir/global.abook"
+ If not, specify the path as though it was accessed from the
+ src/ directory ("../global.abook" -> in main directory)
+
+ If you don't want a global site-wide addressbook, comment these
+ two lines out. (They are disabled by default.)
+
+ The global addressbook is unmodifiable by anyone. You must actually
+ use a shell script or whatnot to modify the contents.
+
+ global $data_dir, $address_book_global_filename;
+ $address_book_global_filename = "$data_dir/global.abook";
+
+*/
+
+global $addrbook_dsn, $addrbook_global_dsn;
+
+/**
+ Create and initialize an addressbook object.
+ Returns the created object
+*/
+function addressbook_init($showerr = true, $onlylocal = false) {
+ global $data_dir, $username, $ldap_server, $address_book_global_filename;
+ global $addrbook_dsn, $addrbook_table;
+ global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
+
+ /* Create a new addressbook object */
+ $abook = new AddressBook;
+
+ /*
+ Always add a local backend. We use *either* file-based *or* a
+ database addressbook. If $addrbook_dsn is set, the database
+ backend is used. If not, addressbooks are stores in files.
+ */
+ if (isset($addrbook_dsn) && !empty($addrbook_dsn)) {
+ /* Database */
+ if (!isset($addrbook_table) || empty($addrbook_table)) {
+ $addrbook_table = 'address';
+ }
+ $r = $abook->add_backend('database', Array('dsn' => $addrbook_dsn,
+ 'owner' => $username,
+ 'table' => $addrbook_table));
+ if (!$r && $showerr) {
+ echo _("Error initializing addressbook database.");
+ exit;
+ }
+ } else {
+ /* File */
+ $filename = getHashedFile($username, $data_dir, "$username.abook");
+ $r = $abook->add_backend('local_file', Array('filename' => $filename,
+ 'create' => true));
+ if(!$r && $showerr) {
+ printf( _("Error opening file %s"), $filename );
+ exit;
+ }
+
+ }
+
+ /* This would be for the global addressbook */
+ if (isset($address_book_global_filename)) {
+ $r = $abook->add_backend('global_file');
+ if (!$r && $showerr) {
+ echo _("Error initializing global addressbook.");
+ exit;
+ }
+ }
+
+ /* Load global addressbook from SQL if configured */
+ if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) {
+ /* Database configured */
+ if (!isset($addrbook_global_table) || empty($addrbook_global_table)) {
+ $addrbook_global_table = 'global_abook';
+ }
+ $r = $abook->add_backend('database',
+ Array('dsn' => $addrbook_global_dsn,
+ 'owner' => 'global',
+ 'name' => _("Global address book"),
+ 'writeable' => $addrbook_global_writeable,
+ 'listing' => $addrbook_global_listing,
+ 'table' => $addrbook_global_table));
+ }
+
+ /*
+ * 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.
+ */
+ $hookReturn = do_hook('abook_init', $abook, $r);
+ $abook = $hookReturn[1];
+ $r = $hookReturn[2];
+
+ if ($onlylocal) {
+ return $abook;