<?php
/**
 * $Horde: turba/config/sources.php.dist,v 1.97.6.12 2005/10/17 20:51:49 jan Exp $
 *
 * This file is where you specify the sources of contacts available to users
 * at your installation.  It contains a large number of EXAMPLES.  Please
 * remove or comment out those examples that YOU DON'T NEED.  There are a
 * number of properties that you can set for each server, including:
 *
 * title:    This is the common (user-visible) name that you want displayed in
 *           the contact source drop-down box.
 *
 * type:     The types 'ldap', 'sql', 'imsp' and 'prefs' are currently
 *           supported.  Preferences-based address books are not intended for
 *           production installs unless you really know what you're doing -
 *           they are not searchable, and they won't scale well if a user has
 *           a large number of entries.
 *
 * params:   These are the connection parameters specific to the contact
 *           source.  See below for examples of how to set these.
 *
 * Special params settings:
 *
 *   charset:  The character set that the backend stores data in.  Many LDAP
 *             servers use utf-8.  Database servers typically use iso-8859-1.
 *
 *   tls:      Only applies to LDAP servers.  If true, then try to use a TLS
 *             connection to the server.
 *
 *   scope:    Only applies to LDAP servers.  Can be set to 'one' to search
 *             one level of the LDAP directory, or 'sub' to search all levels.
 *             'one' will work for most setups and should be much faster.
 *             However we default to 'sub' for backwards compatibility.
 *
 * map:      This is a list of mappings from the standard Turba attribute
 *           names (on the left) to the attribute names by which they are
 *           known in this contact source (on the right).  Turba also supports
 *           composite fields.  A composite field is defined by mapping the
 *           field name to an array containing a list of component fields and
 *           a format string (similar to a printf() format string).  Here is
 *           an example:
 *           ...
 *           'name' => array('fields' => array('firstname', 'lastname'),
 *                           'format' => '%s %s'),
 *           'firstname' => 'object_firstname',
 *           'lastname' => 'object_lastname',
 *           ...
 *
 * tabs:     All fields can be grouped into tabs with this optional entry.
 *           This list is multidimensional hash, the keys are the tab titles.
 *           Here is an example:
 *           'tabs' => array(
 *               'Names' => array('firstname', 'lastname', 'alias'),
 *               'Addresses' => array('homeAddress', 'workAddress')
 *           );
 *
 * search:   A list of Turba attribute names that can be searched for this
 *           source.
 *
 * strict:   A list of native field/attribute names that must always be
 *           matched exactly in a search.
 *
 * public:   If set to true, this source will be available to all users.  See
 *           also 'readonly' -- public=true readonly=false means writable by
 *           all users!
 *
 * readonly: If set to true, this source can only be modified by users on the
 *           'admin' list.
 *
 * admin:    A list (array) of users that are allowed to modify this source,
 *           if it's marked 'readonly'.
 *
 * export:   If set to true, this source will appear on the Export menu,
 *           allowing users to export the contacts to a CSV (etc.) file.
 *
 * Here are some example configurations:
 */

/**
 * A local address book in an SQL database.  This implements a per-user
 * address book.
 *
 * Be sure to create a turba_objects table in your Horde database from the
 * schema in turba/scripts/db/turba.sql if you use this source.
 */
$cfgSources['localsql'] = array(
    'title' => _("My Address Book"),
    'type' => 'sql',
    // The default connection details are pulled from the Horde-wide SQL
    // connection configuration.
    //
    // The old example illustrates how to use an alternate database
    // configuration.
    //
    // New Example:
    'params' => array_merge($conf['sql'], array('table' => 'turba_objects')),

    // Old Example:
    // 'params' => array(
    //     'phptype' => 'mysql',
    //     'hostspec' => 'localhost',
    //     'username' => 'horde',
    //     'password' => '*****',
    //     'database' => 'horde',
    //     'table' => 'turba_objects',
    //     'charset' => 'iso-8859-1'
    // ),
    'map' => array(
        '__key' => 'object_id',
        '__owner' => 'owner_id',
        '__type' => 'object_type',
        '__members' => 'object_members',
        '__uid' => 'object_uid',
        'name' => 'object_name',
        'email' => 'object_email',
        'alias' => 'object_alias',
        'homeAddress' => 'object_homeaddress',
        'workAddress' => 'object_workaddress',
        'homePhone' => 'object_homephone',
        'workPhone' => 'object_workphone',
        'cellPhone' => 'object_cellphone',
        'fax' => 'object_fax',
        'title' => 'object_title',
        'company' => 'object_company',
        'notes' => 'object_notes',
        'pgpPublicKey' => 'object_pgppublickey',
        'smimePublicKey' => 'object_smimepublickey',
        'freebusyUrl' => 'object_freebusyurl'
    ),
    'search' => array(
        'name',
        'email'
    ),
    'strict' => array(
        'object_id',
        'owner_id',
        'object_type',
    ),
    'public' => false,
    'readonly' => false,
    'admin' => array(),
    'export' => true
);

if (Util::extensionExists('ldap')) {
/**
 * A local address book in an LDAP directory.  This implements a public
 * (shared) address book.
 * To store freebusy information in the LDAP directory, you'll need the
 * rfc2739.schema from
 * http://www.whitemiceconsulting.com/node/42
 */
$cfgSources['localldap'] = array(
    'title' => _("Shared Directory"),
    'type' => 'ldap',
    'params' => array(
        'server' => 'ldap.example.com',
        'port' => 389,
        'tls' => false,
        'root' => 'dc=example,dc=com',
        'bind_dn' => 'cn=admin,ou=users,dc=example,dc=com',
        'bind_password' => '********',
        'sizelimit' => 200,
        'dn' => array('cn'),
        'objectclass' => array('top',
                               'person',
                               'organizationalPerson','inetOrgPerson'),
        'scope' => 'one',
        'charset' => 'iso-8859-1',
        // check if all required attributes for an entry are set and add them
        // if needed.
        'checkrequired' => false,
        // string to put in missing required attributes.
        'checkrequired_string' => ' ',
        'version' => 3
    ),
    'map' => array(
        '__key' => 'dn',
        '__uid' => 'uid',
        'name' => 'cn',
        'email' => 'mail',
        'homePhone' => 'homephone',
        'workPhone' => 'telephonenumber',
        'cellPhone' => 'mobiletelephonenumber',
        'homeAddress' => 'homepostaladdress'
        // 'freebusyUrl' => 'calFBURL'
    ),
    'search' => array(
        'name',
        'email',
        'homePhone',
        'workPhone',
        'cellPhone',
        'homeAddress'
    ),
    'strict' => array(
        'dn',
    ),
    'public' => true,
    'readonly' => false,
    'admin' => array(),
    'export' => true
);

/**
 * A personal LDAP adressbook.  This assumes that the login is
 * <username>@domain.com and that the users are stored on the same LDAP
 * server.  Thus it is possible to bind with the username and password from
 * the user.  For more info; please refer to the docs/LDAP file in the Turba
 * distribution.
 *
 * To store freebusy information in the LDAP directory, you'll need the
 * rfc2739.schema from
 * http://www.whitemiceconsulting.com/node/42
 */

// First we need to get the uid.
$uid = Auth::getBareAuth();
$basedn = 'dc=example,dc=com';
$cfgSources['personal_ldap'] = array(
    'title' => _("My Address Book"),
    'type' => 'ldap',
    'params' => array(
        'server' => 'localhost',
        'tls' => false,
        'root' => 'ou=' . $uid . ',ou=personal_addressbook,' . $basedn,
        'bind_dn' => 'uid=' . $uid . ',ou=People,' . $basedn,
        'bind_password' => Auth::getCredential('password'),
        'dn' => array('cn', 'uid'),
        'objectclass' => array('top',
                               'person',
                               'inetOrgPerson',
                               // 'calEntry',
                               'organizationalPerson'),
        'scope' => 'one',
        'charset' => 'utf-8',
        'version' => 3
    ),
    'map' => array(
        '__key' => 'dn',
        '__uid' => 'uid',
        'name' => 'cn',
        'email' => 'mail',
        'lastname' => 'sn',
        'title' => 'title',
        'company' => 'organizationname',
        'businessCategory' => 'businesscategory',
        'workAddress' => 'postaladdress',
        'workPostalCode' => 'postalcode',
        'workPhone' => 'telephonenumber',
        'fax' => 'facsimiletelephonenumber',
        'homeAddress' => 'homepostaladdress',
        'homePhone' => 'homephone',
        'cellPhone' => 'mobile',
        'notes' => 'description',
        // Evolution interopt attributes: (those that do not require the
        // evolution.schema)
        'office' => 'roomNumber',
        'department' => 'ou',
        'nickname' => 'displayName',
        'website' => 'labeledURI',

        // These are not stored on the LDAP server.
        'pgpPublicKey' => 'object_pgppublickey',
        'smimePublicKey' => 'object_smimepublickey',

        // From rfc2739.schema:
        // 'freebusyUrl' => 'calFBURL',

    ),
    'search' => array(
        'name',
        'email',
        'businessCategory',
        'title',
        'homePhone',
        'workPhone',
        'cellPhone',
        'homeAddress'
    ),
    'strict' => array(
        'dn',

    ),
    'public' => true,
    'readonly' => false,
    'admin' => array($uid),
    'export' => true
);

/**
 * Public netcenter, bigfoot, and verisign LDAP directories.
 */
$cfgSources['netcenter'] = array(
    'title' => _("Netcenter Member Directory"),
    'type' => 'ldap',
    'params' => array(
        'server' => 'memberdir.netscape.com',
        'port' => 389,
        'tls' => false,
        'root' => 'ou=member_directory,o=netcenter.com',
        'dn' => array('cn'),
        'objectclass' => 'person',
        'filter' => '',
        'scope' => 'sub',
        'charset' => 'iso-8859-1'
    ),
    'map' => array(
        '__key' => 'dn',
        'name' => 'cn',
        'email' => 'mail',
        'alias' => 'givenname'
    ),
    'search' => array(
        'name',
        'email',
        'alias'
    ),
    'strict' => array(
        'dn'
    ),
    'public' => true,
    'readonly' => true,
    'export' => false
);

$cfgSources['bigfoot'] = array(
    'title' => 'Bigfoot',
    'type' => 'ldap',
    'params' => array(
        'server' => 'ldap.bigfoot.com',
        'port' => 389,
        'tls' => false,
        'root' => '',
        'scope' => 'sub',
        'charset' => 'iso-8859-1'
    ),
    'map' => array(
        '__key' => 'dn',
        'name' => 'cn',
        'email' => 'mail',
        'alias' => 'givenname'
    ),
    'search' => array(
        'name',
        'email',
        'alias'
    ),
    'strict' => array(
        'dn'
    ),
    'public' => true,
    'readonly' => true,
    'export' => false
);

$cfgSources['verisign'] = array(
    'title' => _("Verisign Directory"),
    'type' => 'ldap',
    'params' => array(
        'server' => 'directory.verisign.com',
        'port' => 389,
        'tls' => false,
        'root' => '',
        'scope' => 'sub',
        'charset' => 'iso-8859-1'
    ),
    'map' => array(
        '__key' => 'dn',
        'name' => 'cn',
        'email' => 'mail'
    ),
    'search' => array(
        'name',
        'email'
    ),
    'strict' => array(
        'dn'
    ),
    'public' => true,
    'readonly' => true,
    'export' => false
);

// End LDAP check.
}

/**
 * A preferences-based adressbook.  This will always be private.  You can add
 * any attributes you like to the map and it will just work; you can also
 * create multiple prefs-based address books by changing the 'name' parameter.
 * This is best for address books that are expected to remain small; it's not
 * the most efficient, but it can't be beat for getting up and running
 * quickly, especially if you already have Horde preferences working.  Note
 * that it is not searchable, though - searches will simply return the whole
 * address book.
 */
$cfgSources['prefs'] = array(
    'title' => _("Private Address Book"),
    'type' => 'prefs',
    'params' => array(
        'name' => 'prefs',
        'charset' => NLS::getCharset()
    ),
    'map' => array(
        '__key' => 'id',
        '__type' => '_type',
        '__members' => '_members',
        '__uid' => 'uid',
        'name' => 'name',
        'email' => 'mail',
        'alias' => 'alias'
    ),
    'search' => array(
        'name',
        'email',
        'alias'
    ),
    'strict' => array(
        'id',
        '_type',
    ),
    'public' => false,
    'readonly' => false,
    'export' => true
);

/**
 * IMSP based address book.
 *
 * Communicates with an IMSP backend server.
 *
 * Notes:
 * You should configure the user's "main" address book here.  The name of the
 * address book is set in the 'name' element of the params array.  It is
 * configured by default to be the same as the username.  Any other address
 * books the user has access to will automatically be configured at runtime.
 *
 * In the params array, accepted values for auth_method are 'cram_md5' and
 * 'plaintext' - these must match a IMSP_Auth_ driver.
 *
 * Groups in other IMSP-aware applications are just entries with multiple
 * email addresses in the email field and a 'group' field set to flag the
 * entry as a group.  (The Cyrusoft applications, Mulberry and Silkymail both
 * use a field named 'group' set to equal 'group' to signify this).  A
 * Turba_Group is basically a List of existing Turba_Objects.  The IMSP driver
 * will map between these two structures when reading and writing groups.  The
 * only caveat is that IMSP groups that contain email addresses which do not
 * have a cooresponding contact entry will be ignored.  The group_id_field
 * should be set to the IMSP field that flags the entry as a 'group' entry and
 * the group_id_value should be set to the value given to that field.
 *
 * By default, the username and password that were used to login to Horde is
 * used to login to the IMSP server.  If these credentials are different,
 * there is a user preference in Horde to allow another username / password to
 * be entered.  The alternate credentials are always used if present.
 *
 * In the map array, since IMSP uses the 'name' attribute as a key, this is
 * what __key is mapped to ... and a dynamic field 'fullname' is added and
 * mapped to the horde 'name' field.  This is populated with the IMSP 'name'
 * field when the object is read from the server.
 *
 * If you wish to keep track of ownership of individual contacts, set
 * 'contact_ownership' = true.  Note that entries created using other clients
 * will not be created this way and will therefore have no 'owner'.  Set
 * 'contact_ownership' = false and the __owner field will be automatically
 * populated with the current username.
 */
// Check that IMSP is configured in Horde but fall through if there is no
// configuration at all - in case we aren't using up to date Horde install.
// (In that case, be sure to change the params array below to suit your needs.
//UNCOMMENTIFIMSPif (!empty($GLOBALS['conf']['imsp']['enabled']) ||
//UNCOMMENTIFIMSP    !isset($GLOBALS['conf']['imsp']['enabled'])) {
//UNCOMMENTIFIMSP
//UNCOMMENTIFIMSP    // First, get the user name
//UNCOMMENTIFIMSP    $uid = $GLOBALS['prefs']->getValue('imsp_auth_user');
//UNCOMMENTIFIMSP    $pass = $GLOBALS['prefs']->getValue('imsp_auth_pass');
//UNCOMMENTIFIMSP    if (!strlen($uid)) {
//UNCOMMENTIFIMSP        $uid = Auth::getAuth();
//UNCOMMENTIFIMSP        if (preg_match('/(^.*)@/', $uid, $matches)) {
//UNCOMMENTIFIMSP            $uid = $matches[1];
//UNCOMMENTIFIMSP        }
//UNCOMMENTIFIMSP        $pass = Auth::getCredential('password');
//UNCOMMENTIFIMSP    }
//UNCOMMENTIFIMSP
//UNCOMMENTIFIMSP    $cfgSources['imsp'] = array(
//UNCOMMENTIFIMSP        'title' => _("IMSP"),
//UNCOMMENTIFIMSP        'type' => 'imsp',
//UNCOMMENTIFIMSP        'params' => array(
//UNCOMMENTIFIMSP            'server'   => $GLOBALS['conf']['imsp']['server'],
//UNCOMMENTIFIMSP            'port'     => $GLOBASL['conf']['imsp']['port'],
//UNCOMMENTIFIMSP            'auth_method' => $GLOBALS['conf']['imsp']['auth_method'],
//UNCOMMENTIFIMSP            'username' => $uid,
//UNCOMMENTIFIMSP            'password' => $pass,
//UNCOMMENTIFIMSP            'name' => $uid,
//UNCOMMENTIFIMSP            'group_id_field' => 'group',
//UNCOMMENTIFIMSP            'group_id_value' => 'group',
//UNCOMMENTIFIMSP            'contact_ownership' => false
//UNCOMMENTIFIMSP            ),
//UNCOMMENTIFIMSP        'map' => array(
//UNCOMMENTIFIMSP            '__key' => 'name',
//UNCOMMENTIFIMSP            '__type' => '__type',
//UNCOMMENTIFIMSP            '__members' => '__members',
//UNCOMMENTIFIMSP            '__owner' => '__owner',
//UNCOMMENTIFIMSP            '__uid' => '__uid',
//UNCOMMENTIFIMSP            'name' => 'fullname',
//UNCOMMENTIFIMSP            'email' => 'email',
//UNCOMMENTIFIMSP            'alias' => 'alias',
//UNCOMMENTIFIMSP            'company' => 'company',
//UNCOMMENTIFIMSP            'notes' => 'notes',
//UNCOMMENTIFIMSP            'workPhone' => 'phone-work',
//UNCOMMENTIFIMSP            'fax' => 'fax',
//UNCOMMENTIFIMSP            'homePhone' => 'phone-home',
//UNCOMMENTIFIMSP            'cellPhone' => 'cellphone',
//UNCOMMENTIFIMSP            'freebusyUrl' => 'freebusyUrl'
//UNCOMMENTIFIMSP            ),
//UNCOMMENTIFIMSP        'search' => array(
//UNCOMMENTIFIMSP            'name',
//UNCOMMENTIFIMSP            'email',
//UNCOMMENTIFIMSP            'alias',
//UNCOMMENTIFIMSP            'company',
//UNCOMMENTIFIMSP            'homePhone'
//UNCOMMENTIFIMSP            ),
//UNCOMMENTIFIMSP        'strict' => array(),
//UNCOMMENTIFIMSP        'public' => false,
//UNCOMMENTIFIMSP        'readonly' => false,
//UNCOMMENTIFIMSP        'export' => true
//UNCOMMENTIFIMSP        );
//UNCOMMENTIFIMSP
//UNCOMMENTIFIMSP    /**
//UNCOMMENTIFIMSP     * Get any other address books this user might be privy to.
//UNCOMMENTIFIMSP     */
//UNCOMMENTIFIMSP    require_once 'Net/IMSP/Utils.php';
//UNCOMMENTIFIMSP    $result = Net_IMSP_Utils::getAllBooks($cfgSources['imsp']);
//UNCOMMENTIFIMSP    if (!is_a($result, 'PEAR_Error')) {
//UNCOMMENTIFIMSP        for ($i = 0; $i < count($result); $i++) {
//UNCOMMENTIFIMSP            // Make sure we didn't define this source explicitly.
//UNCOMMENTIFIMSP            $dup = false;
//UNCOMMENTIFIMSP            foreach ($cfgSources as $thisSource) {
//UNCOMMENTIFIMSP                if (($thisSource['type'] == 'imsp') &&
//UNCOMMENTIFIMSP                    ($thisSource['params']['name'] == $result[$i]['params']['name'])) {
//UNCOMMENTIFIMSP                    $dup = true;
//UNCOMMENTIFIMSP                }
//UNCOMMENTIFIMSP            }
//UNCOMMENTIFIMSP            if (!$dup) {
//UNCOMMENTIFIMSP                $cfgSources[sprintf('imsp%d', $i + 1)] = $result[$i];
//UNCOMMENTIFIMSP            }
//UNCOMMENTIFIMSP        }
//UNCOMMENTIFIMSP    } else {
//UNCOMMENTIFIMSP        $notification->push($result);
//UNCOMMENTIFIMSP    }
//UNCOMMENTIFIMSP}

/* Begin Kolab sources. */
if (!empty($GLOBALS['conf']['kolab']['enabled'])) {

    /* A global address book for a Kolab Server.  This is typically a
     * read-only public directory, stored in the default Kolab LDAP server.
     * The user accessing this should have read permissions to the shared
     * directory in LDAP. */
    $cfgSources['kolab_global'] = array(
        'title' => _("Global Address Book"),
        'type' => 'ldap',
        'params' => array(
            'server' => $GLOBALS['conf']['kolab']['ldap']['server'],
            'port' => $GLOBALS['conf']['kolab']['ldap']['port'],
            'tls' => false,
            'root' => $GLOBALS['conf']['kolab']['ldap']['basedn'],
            'sizelimit' => 200,
            'dn' => array('cn'),
            'objectclass' => array(
                'top',
                'inetOrgPerson'
            ),
            'scope' => 'one',
            'charset' => 'iso-8859-1',
            'version' => 3,
            'bind_dn' => $GLOBALS['conf']['kolab']['ldap']['binddn'],
            'bind_password' => $GLOBALS['conf']['kolab']['ldap']['bindpw'],
        ),
        'map' => array(
            '__key'             => 'dn',
            'name'              => 'cn',
            'firstname'         => 'givenName',
            'lastname'          => 'sn',
            'email'             => 'mail',
            'alias'             => 'alias',
            'title'             => 'title',
            'company'           => 'o',
            'workStreet'        => 'street',
            'workCity'          => 'l',
            'workProvince'      => 'st',
            'workPostalCode'    => 'postalCode',
            'workCountry'       => 'c',
            'homePhone'         => 'homePhone',
            'workPhone'         => 'telephoneNumber',
            'cellPhone'         => 'mobile',
            'fax'               => 'fax',
            'notes'             => 'description',
        ),
        'search' => array(
            'name',
            'firstname',
            'lastname',
            'email',
            'title',
            'company',
            'workAddress',
            'workCity',
            'workProvince',
            'workPostalCode',
            'workCountry',
            'homePhone',
            'workPhone',
            'cellPhone',
            'fax',
            'notes',
        ),
        'strict' => array(
            'dn',
        ),
        'public' => true,
        'readonly' => true,
        'admin' => array(),
        'export' => true
    );

    /**
     * A local address book for a Kolab user.  This is stored in a specially
     * flagged 'Contacts' folder within the users Cyrus IMAP mailbox.  By
     * default this folder can only be accessed by its owner, however it can
     * be shared via Cyrus ACLs.
     */

    // We need to sync our (dummy) share list for Turba, and as Turba does not
    // use Horde_Share we can't rely on a _horde_hook_share_init() call, so we
    // perform the same task here.
    require_once 'Horde/Kolab.php';
    $dummy = null;
    Kolab::synchroniseShares($dummy, 'turba');

    // TODO: auto-generate a $cfgSources[] entry for every contact folder that
    // the user has access to, setting 'title' to the name of the specific
    // folder.
    $cfgSources['kolab_local'] = array(
        'title' => 'My Contacts',
        'type' => 'kolab',
        'params' => array(
            'share' => Auth::getAuth(),
        ),
        'map' => array(
            '__key'             => 'uid',
            '__owner'           => 'owner',
            '__uid'             => 'uid',
            'name'              => 'full-name',
            'firstname'         => 'given-name',
            'lastname'          => 'last-name',
            'title'             => 'job-title',
            'company'           => 'organization',
            'notes'             => 'body',
            'website'           => 'web-page',
            'nickname'          => 'nick-name',
            'email'             => 'smtp-address',
            'homeStreet'        => 'home-street',
            'homeCity'          => 'home-locality',
            'homeProvince'      => 'home-region',
            'homePostalCode'    => 'home-postal-code',
            'homeCountry'       => 'home-country',
            'workStreet'        => 'business-street',
            'workCity'          => 'business-locality',
            'workProvince'      => 'business-region',
            'workPostalCode'    => 'business-postal-code',
            'workCountry'       => 'business-country',
            'homePhone'         => 'home1',
            'workPhone'         => 'business1',
            'cellPhone'         => 'mobile',
            'fax'               => 'businessfax',
        ),
        'search' => array(
            'name',
            'firstname',
            'lastname',
            'email',
            'title',
            'company',
            'homeStreet',
            'homeCity',
            'homeProvince',
            'homePostalCode',
            'homeCountry',
            'workStreet',
            'workCity',
            'workProvince',
            'workPostalCode',
            'workCountry',
            'homePhone',
            'workPhone',
            'cellPhone',
            'fax',
            'notes',
            'website',
            'nickname',
        ),
        'strict' => array(
            '__uid'
        ),
        'public' => false,
        'readonly' => false,
        'admin' => array(),
        'export' => true
    );

    // End Kolab sources.
}
