Turba::getDefaultAddressbook PHP Method

getDefaultAddressbook() public static method

Returns the current user's default address book.
public static getDefaultAddressbook ( ) : string
return string The default address book name.
    public static function getDefaultAddressbook()
    {
        /* In case of shares select first user owned address book as default */
        if (!empty($_SESSION['turba']['has_share'])) {
            try {
                $owned_shares = self::listShares(true);
                if (count($owned_shares)) {
                    return key($owned_shares);
                }
            } catch (Exception $e) {
            }
        }
        reset($GLOBALS['cfgSources']);
        return key($GLOBALS['cfgSources']);
    }

Usage Example

Example #1
0
 * IMPORTANT: DO NOT EDIT THIS FILE! DO NOT COPY prefs.php TO prefs.local.php!
 * Local overrides ONLY MUST be placed in prefs.local.php or prefs.d/.
 * If the 'vhosts' setting has been enabled in Horde's configuration, you can
 * use prefs-servername.php.
 */
$prefGroups['addressbooks'] = array('column' => _("Address Books"), 'label' => _("Address Books"), 'desc' => _("Choose which address books to use."), 'members' => array('default_dir'));
$prefGroups['sync'] = array('column' => _("Address Books"), 'label' => _("Synchronization Preferences"), 'desc' => _("Choose which address books to use for synchronization with external devices."), 'members' => array('sync_books', 'activesync_no_multiplex'));
$prefGroups['columns'] = array('column' => _("Display Preferences"), 'label' => _("Column Preferences"), 'desc' => _("Select which fields to display in the address lists."), 'members' => array('columnselect'));
$prefGroups['display'] = array('column' => _("Display Preferences"), 'label' => _("Display"), 'desc' => _("Select view to display by default and paging preferences."), 'members' => array('initial_page', 'maxpage', 'perpage'));
$prefGroups['format'] = array('column' => _("Display Preferences"), 'label' => _("Name Format"), 'desc' => _("Select which format to display names."), 'members' => array('name_format', 'name_sort'));
// Address books use for synchronization
$_prefs['sync_books'] = array('value' => 'a:0:{}', 'type' => 'multienum', 'enum' => array(), 'desc' => _("Select the address books that should be used for synchronization with external devices:"), 'on_init' => function ($ui) {
    $enum = array();
    $sync_books = @unserialize($GLOBALS['prefs']->getValue('sync_books'));
    if (empty($sync_books)) {
        $GLOBALS['prefs']->setValue('sync_books', serialize(array(Turba::getDefaultAddressbook())));
    }
    foreach (Turba::getAddressBooks() as $key => $val) {
        if (!empty($val['map']['__uid']) && !empty($val['browse'])) {
            $enum[$key] = $val['title'];
        }
    }
    $ui->prefs['sync_books']['enum'] = $enum;
}, 'on_change' => function () {
    if ($GLOBALS['conf']['activesync']['enabled'] && !$GLOBALS['prefs']->getValue('activesync_no_multiplex')) {
        try {
            $sm = $GLOBALS['injector']->getInstance('Horde_ActiveSyncState');
            $sm->setLogger($GLOBALS['injector']->getInstance('Horde_Log_Logger'));
            $devices = $sm->listDevices($GLOBALS['registry']->getAuth());
            foreach ($devices as $device) {
                $sm->removeState(array('devId' => $device['device_id'], 'id' => Horde_Core_ActiveSync_Driver::CONTACTS_FOLDER_UID, 'user' => $GLOBALS['registry']->getAuth()));
All Usage Examples Of Turba::getDefaultAddressbook