/** * Reads the given data from the address book and returns the results. * * @param string $key The primary key field to use. * @param mixed $ids The ids of the contacts to load. * @param string $owner Only return contacts owned by this user. * @param array $fields List of fields to return. * @param array $blobFields Array of fields containing binary data. * @param array $dateFields Array of fields containing date data. * @since 4.2.0 * * @return array Hash containing the search results. * @throws Turba_Exception */ protected function _read($key, $ids, $owner, array $fields, array $blobFields = array(), array $dateFields = array()) { $this->connect(); $results = array(); if (!is_array($ids)) { $ids = array($ids); } $count = count($fields); foreach ($ids as $id) { if (!isset($this->_contacts_cache[$id])) { continue; } $object = $this->_contacts_cache[$id]; if (!isset($object['__type']) || $object['__type'] == 'Object') { if ($count) { $result = array(); foreach ($fields as $field) { if (isset($object[$field])) { $result[$field] = $object[$field]; } } $results[] = $result; } else { $results[] = $object; } } else { $member_ids = array(); if (isset($object['member'])) { foreach ($object['member'] as $member) { if (isset($member['uid'])) { $id = Horde_Url::uriB64Encode($member['uid']); $found = false; try { $this->getObject($id); $found = true; } catch (Horde_Exception_NotFound $e) { foreach (Turba::listShares() as $share) { $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($share->getName()); try { $driver->getObject($id); $id = $share->getName() . ':' . $id; $found = true; break; } catch (Horde_Exception_NotFound $e) { continue; } } } if ($found) { $member_ids[] = $id; } continue; } $display_name = $member['display-name']; $smtp_address = $member['smtp-address']; $criteria = array('AND' => array(array('field' => 'full-name', 'op' => 'LIKE', 'test' => $display_name, 'begin' => false), array('field' => 'emails', 'op' => 'LIKE', 'test' => $smtp_address, 'begin' => false))); $fields = array('uid'); // we expect only one result here!!! $contacts = $this->_search($criteria, $fields); // and drop everything else except the first search // result $member_ids[] = $contacts[0]['__key']; } $object['__members'] = serialize($member_ids); unset($object['member']); } $results[] = $object; } } if (!$results) { throw new Horde_Exception_NotFound(); } return $results; }
/** * Lists all shares the current user has access to. * * @param integer $perms * * @return array of Turba_Share objects. */ public function listShares($perms = Horde_Perms::READ) { return Turba::listShares(true, $perms); }
/** * Add additional items to the sidebar. * * @param Horde_View_Sidebar $sidebar The sidebar object. */ public function sidebar($sidebar) { if (count($GLOBALS['addSources'])) { $sidebar->addNewButton(_("_New Contact"), Horde::url('add.php')); } $user = $GLOBALS['registry']->getAuth(); $url = Horde::url(''); $edit = Horde::url('addressbooks/edit.php'); $sidebar->containers['my'] = array('header' => array('id' => 'turba-toggle-my', 'label' => _("My Address Books"), 'collapsed' => false)); if ($GLOBALS['registry']->getAuth() && $GLOBALS['session']->get('turba', 'has_share')) { $sidebar->containers['my']['header']['add'] = array('url' => Horde::url('addressbooks/create.php'), 'label' => _("Create a new Address Book")); } $sidebar->containers['shared'] = array('header' => array('id' => 'turba-toggle-shared', 'label' => _("Shared Address Books"), 'collapsed' => true)); $shares = array(); foreach (Turba::listShares(false, Horde_Perms::SHOW) as $id => $abook) { $row = array('selected' => $id == Turba::$source, 'url' => $url->add('source', $id), 'label' => $abook->get('name'), 'edit' => $edit->add('a', $abook->getName()), 'type' => 'radiobox'); if ($abook->get('owner') && $abook->get('owner') == $user) { $sidebar->addRow($row, 'my'); if ($row['selected']) { $sidebar->containers['my']['header']['collapsed'] = false; } } else { if ($abook->get('owner')) { $row['label'] .= ' [' . $GLOBALS['registry']->convertUsername($abook->get('owner'), false) . ']'; } $sidebar->addRow($row, 'shared'); if ($row['selected']) { $sidebar->containers['shared']['header']['collapsed'] = false; } } $shares[$id] = true; } $sidebar->containers['other'] = array('header' => array('id' => 'turba-toggle-other', 'label' => _("Other Address Books"), 'collapsed' => true)); foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $abook) { if (isset($shares[$id])) { continue; } $row = array('selected' => $id == Turba::$source, 'url' => $url->add('source', $id), 'label' => $abook['title'], 'type' => 'radiobox'); $sidebar->addRow($row, 'other'); if ($row['selected']) { $sidebar->containers['other']['header']['collapsed'] = false; } } }