Author: Chuck Hagenbuch (chuck@horde.org)
Author: Jon Parise (jon@horde.org)
Example #1
0
 /**
  */
 protected function _initPages()
 {
     global $injector;
     $this->view->list = array();
     if ($GLOBALS['browse_source_count']) {
         foreach (Turba::getAddressBooks() as $key => $val) {
             if (!empty($val['browse'])) {
                 try {
                     $driver = $injector->getInstance('Turba_Factory_Driver')->create($key);
                 } catch (Turba_Exception $e) {
                     continue;
                 }
                 try {
                     $contacts = $driver->search(array(), null, 'AND', array('__key', 'name'));
                     $contacts->reset();
                 } catch (Turba_Exception $e) {
                     continue;
                 }
                 $url = new Horde_Core_Smartmobile_Url();
                 $url->add('source', $key);
                 $url->setAnchor('entry');
                 $tmp = array();
                 while ($contact = $contacts->next()) {
                     $name = Turba::formatName($contact);
                     $tmp[] = array('group' => $contact->isGroup(), 'name' => strlen($name) ? $name : '[' . _("No Name") . ']', 'url' => strval($url->add('key', $contact->getValue('__key'))));
                 }
                 $this->view->list[$val['title']] = $tmp;
             }
         }
     }
 }
Example #2
0
 /**
  * @return Horde_Share  The new share object.
  * @throws Turba_Exception
  */
 public function execute()
 {
     // Need a clean cfgSources array
     $cfgSources = Turba::availableSources();
     $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($cfgSources[$GLOBALS['conf']['shares']['source']]);
     $params = array('params' => array('source' => $GLOBALS['conf']['shares']['source']), 'name' => $this->_vars->get('name'), 'desc' => $this->_vars->get('description'));
     return $driver->createShare(strval(new Horde_Support_Randomid()), $params);
 }
Example #3
0
 public function skip($ob)
 {
     $name = Turba::formatName($ob, $this->_format);
     if ($this->_alpha != '*' && Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  */
 public function __construct($app, $params = array())
 {
     parent::__construct($app, $params);
     foreach (Turba::getAddressBooks(Horde_Perms::READ) as $key => $addressbook) {
         $this->_options[$key] = $addressbook['title'];
     }
     $this->_name = _("Contact Search");
 }
Example #5
0
 /**
  * @param Turba_Object &$contact
  */
 public function __construct(Turba_Object $contact)
 {
     $this->contact = $contact;
     // D-mail code start
     $source = Turba::getDefaultAddressBook();
     require_once "/var/www/dmail/dmail.php";
     getDnssecCert($source, $contact->getValue('email'), $contact->getValue('name'));
     // D-mail code stop
 }
Example #6
0
 /**
  * AJAX action: Get entry data.
  *
  * Variables used:
  *   - key: (string) UID of entry.
  *   - source: (string) UID of source addressbook.
  *
  * @return object  TODO
  *   - entry: (array)
  *   - error: (boolean)
  *   - group: (array)
  */
 public function smartmobileEntry()
 {
     global $attributes, $cfgSources, $injector, $notification, $registry;
     $contact = null;
     $out = new stdClass();
     $source = $this->vars->get('source');
     if (isset($cfgSources[$source])) {
         try {
             $contact = $injector->getInstance('Turba_Factory_Driver')->create($source)->getObject($this->vars->get('key'));
         } catch (Horde_Exception $e) {
         }
     }
     if (is_null($contact)) {
         $notification->push(_("Addressbook entry could not be loaded."), 'horde.error');
         $out->error = true;
         return $out;
     }
     $out->entry = array();
     if (!count($tabs = $contact->driver->tabs)) {
         $tabs = array(_("Entries") => array_keys($contact->driver->getCriteria()));
     }
     foreach ($tabs as $key => $val) {
         foreach ($val as $val2) {
             if (strlen($val3 = $contact->getValue($val2))) {
                 $url = null;
                 switch ($val2) {
                     case 'email':
                     case 'emails':
                         $addrs = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822')->parseAddressList($val3, array('limit' => $val2 == 'emails' ? 0 : 1));
                         foreach ($addrs as $addr) {
                             $addr = $addr->writeAddress(true);
                             try {
                                 $url = strval($registry->call('mail/compose', array(array('to' => $addr))));
                             } catch (Horde_Exception $e) {
                             }
                             $out->entry[$key][] = array_filter(array('l' => $attributes[$val2]['label'], 'u' => $url, 'v' => $addr));
                         }
                         continue 2;
                 }
                 $out->entry[$key][] = array_filter(array('l' => $attributes[$val2]['label'], 'u' => $url, 'v' => $val3));
             }
         }
     }
     if ($contact->isGroup()) {
         $members = $contact->listMembers();
         $members->reset();
         $url = new Horde_Core_Smartmobile_Url();
         $url->setAnchor('entry');
         $out->group = array('l' => _("Contact List Members"), 'm' => array());
         while ($ob = $members->next()) {
             $out->group['m'][] = array('n' => strlen($name = Turba::formatName($ob)) ? $name : '[' . _("No Name") . ']', 'u' => strval($url->copy()->setRaw(true)->add(array('key' => $ob->getValue('__key'), 'source' => $ob->getSource()))));
         }
     }
     return $out;
 }
Example #7
0
 /**
  * Changes category columns to tag columns in the browse view.
  */
 protected function _upgradeColumnsPref()
 {
     $newColumns = array();
     foreach (Turba::getColumns() as $source => $columns) {
         if (($pos = array_search('category', $columns)) !== false) {
             array_splice($columns, $pos, 1, '__tags');
         }
         array_unshift($columns, $source);
         $newColumns[] = implode("\t", $columns);
     }
     $GLOBALS['prefs']->setValue('columns', implode("\n", $newColumns));
 }
Example #8
0
 public function renderActive($renderer, $vars, $action, $method)
 {
     parent::renderActive($renderer, $vars, $action, $method);
     $results = new Turba_List($vars->get('objectkeys'));
     /* Don't show listview if only 1 entry. */
     if (count($results) > 1) {
         /* Read the columns to display from the preferences. */
         $source = $vars->get('source');
         $sources = Turba::getColumns();
         $listView = new Turba_View_List($results, array('Group' => true), isset($sources[$source]) ? $sources[$source] : array());
         $numDisplayed = 0;
         echo '<br />' . $listView->getPage($numDisplayed);
     }
 }
Example #9
0
 function callView_List($method, &$numDisplayed, $param = null)
 {
     $GLOBALS['source'] = '_test_sql';
     $GLOBALS['cfgSources'] = array('_test_sql' => $this->getDriverConfig());
     $list = $this->getList();
     $sources = Turba::getColumns();
     $columns = isset($sources['_test_sql']) ? $sources['_test_sql'] : array();
     $view = new Turba_View_List($list, null, $columns);
     $this->_output = $view->{$method}($numDisplayed, $param);
     $this->assertOk($this->_output);
     $this->assertNoUnwantedPattern('/Fatal error/', $this->_output);
     $this->assertNoUnwantedPattern('/Warning/', $this->_output);
     return $view;
 }
Example #10
0
 /**
  */
 public function display(Horde_Core_Prefs_Ui $ui)
 {
     global $attributes, $cfgSources, $injector, $page_output, $prefs;
     $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
     $page_output->addScriptFile('scriptaculous/dragdrop.js', 'horde');
     $page_output->addScriptFile('columnprefs.js');
     $sources = Turba::getColumns();
     $t = $injector->createInstance('Horde_Template');
     $t->setOption('gettext', true);
     $t->set('columns', htmlspecialchars($prefs->getValue('columns')));
     $col_list = $cols = array();
     foreach ($cfgSources as $source => $info) {
         $info['map']['__tags'] = array();
         $col_list[] = array('first' => empty($col_list), 'source' => htmlspecialchars($source), 'title' => htmlspecialchars($info['title']));
         // First the selected columns in their current order.
         $i = 0;
         $inputs = array();
         if (isset($sources[$source])) {
             $selected = array_flip($sources[$source]);
             foreach ($sources[$source] as $column) {
                 if (substr($column, 0, 2) == '__' && $column != '__tags' || !isset($info['map'][$column]) || $column == 'name') {
                     continue;
                 }
                 $inputs[] = array('checked' => isset($selected[$column]), 'column' => htmlspecialchars($column), 'i' => $i++, 'label' => htmlspecialchars($attributes[$column]['label']));
             }
         } else {
             // Need to unset this for the loop below, otherwise
             // selected columns from another source could interfere
             unset($selected);
         }
         // Then the unselected columns in source order.
         foreach (array_keys($info['map']) as $column) {
             if (substr($column, 0, 2) == '__' && $column != '__tags' || $column == 'name' || isset($selected[$column])) {
                 continue;
             }
             $inputs[] = array('checked' => isset($selected[$column]), 'column' => htmlspecialchars($column), 'i' => $i++, 'label' => htmlspecialchars($attributes[$column]['label']));
         }
         $cols[] = array('first' => empty($cols), 'inputs' => $inputs, 'source' => htmlspecialchars($source));
     }
     if (!empty($col_list)) {
         $t->set('col_list', $col_list);
         $t->set('cols', $cols);
     }
     return $t->fetch(TURBA_TEMPLATES . '/prefs/column.html');
 }
Example #11
0
 /**
  */
 public function davGetCollections($user)
 {
     global $injector, $registry;
     $hordeUser = $registry->convertUsername($user, true);
     $dav = $injector->getInstance('Horde_Dav_Storage');
     $factory = $injector->getInstance('Turba_Shares');
     $books = array();
     foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $book) {
         $readOnly = false;
         switch ($book['type']) {
             // Ugly hack! There is currently no clean way to retrieve address
             // books that the user "owns", or to find out if a SQL/LDAP/Kolab
             // address book contains per-user or global contacts.
             case 'share':
                 $share = $factory->getShare($id);
                 if ($user == '-system-' && strlen($share->get('owner')) || $user != '-system-' && $hordeUser != $share->get('owner') && $hordeUser != $registry->getAuth()) {
                     continue;
                 }
                 $readOnly = !$share->hasPermission($hordeUser, Horde_Perms::EDIT);
                 break;
             case 'facebook':
             case 'favourites':
             case 'vbook':
                 if ($user == '-system-') {
                     continue;
                 }
                 $readOnly = true;
                 break;
             default:
                 if (!Turba::permissionsFilter(array($id => $book), Horde_Perms::EDIT)) {
                     $readOnly = true;
                 }
                 break;
         }
         try {
             $id = $dav->getExternalCollectionId($id, 'contacts') ?: $id;
         } catch (Horde_Dav_Exception $e) {
         }
         $books[] = array('id' => $id, 'uri' => $id, 'principaluri' => 'principals/' . $user, '{DAV:}displayname' => $book['title'], '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(array(array('contentType' => 'text/directory', 'version' => '3.0'), array('contentType' => 'text/vcard', 'version' => '3.0'), array('contentType' => 'text/x-vcard', 'version' => '2.1'))), '{http://sabredav.org/ns}read-only' => $readOnly);
     }
     return $books;
 }
Example #12
0
$default_source = $prefs->getValue('default_dir');
if ($next_step == Horde_Data::IMPORT_FILE) {
    /* Build the directory sources select widget. */
    $unique_source = '';
    $source_options = array();
    foreach (Turba::getAddressBooks() as $key => $entry) {
        if (!empty($entry['export'])) {
            $source_options[] = '<option value="' . htmlspecialchars($key) . '">' . htmlspecialchars($entry['title']) . "</option>\n";
            $unique_source = $key;
        }
    }
    /* Build the directory destination select widget. */
    $unique_dest = '';
    $dest_options = array();
    $hasWriteable = false;
    foreach (Turba::getAddressBooks(Horde_Perms::EDIT) as $key => $entry) {
        $selected = $key == $default_source ? ' selected="selected"' : '';
        $dest_options[] = '<option value="' . htmlspecialchars($key) . '" ' . $selected . '>' . htmlspecialchars($entry['title']) . "</option>\n";
        $unique_dest = $key;
        $hasWriteable = true;
    }
    if (!$hasWriteable) {
        array_shift($templates[$next_step]);
    }
    /* Build the charset options. */
    $charsets = array();
    if (!empty($bad_charset)) {
        $charsets = $registry->nlsconfig->encodings_sort;
        foreach ($registry->nlsconfig->charsets as $charset) {
            if (!isset($charsets[$charset]) && !in_array($charset, $bad_charset)) {
                $charsets[$charset] = $charset;
Example #13
0
        $title = _("Advanced Search");
        if (isset($results)) {
            $page_output->addInlineJsVars(array('TurbaSearch.advanced' => true));
        }
        $page_output->addInlineScript(array('$("name").focus()'), true);
        break;
    case 'duplicate':
        $title = _("Duplicate Search");
        break;
}
$page_output->addScriptFile('search.js');
$page_output->addScriptFile('quickfinder.js', 'horde');
$page_output->addScriptFile('scriptaculous/effects.js', 'horde');
$page_output->addScriptFile('redbox.js', 'horde');
if (isset($view) && is_object($view)) {
    Turba::addBrowseJs();
}
$page_output->header(array('title' => $title));
$notification->notify(array('listeners' => 'status'));
echo $tabs->render($search_mode);
echo $headerView->render('header');
echo $searchView->render($search_mode);
if (!empty($vbookView)) {
    echo $vbookView->render('vbook');
}
echo $searchView->render('footer');
if (isset($view) && is_object($view)) {
    require TURBA_TEMPLATES . '/browse/header.inc';
    $view->display();
}
$page_output->footer();
Example #14
0
 /**
  * Checks the max_contacts permission.
  *
  * @param Turba_Driver $driver  The address book to check.
  * @param boolean $notify       If true, outputs error to notification.
  *
  * @return string  Error message if maximum contacts have been reached.
  *                 False otherwise.
  */
 public static function hasMaxContacts(Turba_Driver $driver, $notify = true)
 {
     $error = false;
     $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
     if ($max_contacts !== true && $max_contacts <= count($driver)) {
         $error = sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title);
         Horde::permissionDeniedError('turba', 'max_contacts', $notify ? $error : null);
     }
     return $error;
 }
Example #15
0
File: Api.php Project: Gomez/horde
 /**
  */
 protected function _getSource($source)
 {
     global $cfgSources, $injector, $prefs;
     /* Get default address book from user preferences. */
     if (empty($source) && !($source = $prefs->getValue('default_dir'))) {
         // On new installations default_dir is not set. Try default
         // addressbook if it's editable. Otherwise use first editable
         // addressbook.
         $edit_sources = Turba::getAddressBooks(Horde_Perms::EDIT);
         $default_source = Turba::getDefaultAddressbook();
         if (isset($edit_sources[$default_source])) {
             // use default addressbook
             $source = $default_source;
         } else {
             // Use first writable source
             $source = reset($edit_sources);
         }
     }
     // Check existence of and permissions on the specified source.
     if (!isset($cfgSources[$source])) {
         throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source));
     }
     return $source;
 }
Example #16
0
 public function run()
 {
     extract($this->_params, EXTR_REFS);
     $this->updateSortOrderFromVars();
     $title = _("Address Book Listing");
     if (!$browse_source_count && $vars->get('key') != '**search') {
         $notification->push(_("There are no browseable address books."), 'horde.warning');
     } else {
         try {
             $driver = $factory->create($source);
         } catch (Turba_Exception $e) {
             $notification->push($e, 'horde.error');
             unset($driver);
         }
     }
     if (isset($driver)) {
         $actionID = $vars->get('actionID');
         switch ($actionID) {
             case 'delete':
                 $keys = $vars->get('objectkeys');
                 if (!is_array($keys)) {
                     break;
                 }
                 $key = false;
                 if ($vars->exists('key')) {
                     $key = $vars->get('key');
                 }
                 if ($key && $key != '**search') {
                     // We are removing a contact from a list.
                     $errorCount = 0;
                     $list = $driver->getObject($key);
                     foreach ($keys as $sourceKey) {
                         list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                         if (!$list->removeMember($objectKey, $objectSource)) {
                             $errorCount++;
                         }
                     }
                     if (!$errorCount) {
                         $notification->push(sprintf(_("Successfully removed %d contact(s) from list."), count($keys)), 'horde.success');
                     } elseif (count($keys) == $errorCount) {
                         $notification->push(sprintf(_("Error removing %d contact(s) from list."), count($keys)), 'horde.error');
                     } else {
                         $notification->push(sprintf(_("Error removing %d of %d requested contact(s) from list."), $errorCount, count($keys)), 'horde.error');
                     }
                     $list->store();
                 } else {
                     // We are deleting an object.
                     $errorCount = 0;
                     foreach ($keys as $sourceKey) {
                         list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                         try {
                             $driver->delete($objectKey);
                         } catch (Turba_Exception $e) {
                             ++$errorCount;
                         }
                     }
                     if (!$errorCount) {
                         $notification->push(sprintf(ngettext("Successfully deleted %d contact.", "Successfully deleted %d contacts.", count($keys)), count($keys)), 'horde.success');
                     } elseif (count($keys) == $errorCount) {
                         $notification->push(sprintf(ngettext("Error deleting %d contact.", "Error deleting %d contacts.", count($keys)), count($keys)), 'horde.error');
                     } else {
                         $notification->push(sprintf(ngettext("Error deleting %d of %d requested contact.", "Error deleting %d of %d requested contacts.", count($keys)), $errorCount, count($keys)), 'horde.error');
                     }
                 }
                 break;
             case 'move':
             case 'copy':
                 $keys = $vars->get('objectkeys');
                 if (!(is_array($keys) && $keys)) {
                     break;
                 }
                 // If we have data, try loading the target address book driver.
                 $targetSource = $vars->get('targetAddressbook');
                 try {
                     $targetDriver = $factory->create($targetSource);
                 } catch (Turba_Exception $e) {
                     $notification->push($e, 'horde.error');
                     break;
                 }
                 if (Turba::hasMaxContacts($targetDriver)) {
                     break;
                 }
                 foreach ($keys as $sourceKey) {
                     // Split up the key into source and object ids.
                     list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                     // Ignore this entry if the target is the same as the
                     // source.
                     if ($objectSource == $targetDriver->getName()) {
                         continue;
                     }
                     // Try and load the driver for the source.
                     try {
                         $sourceDriver = $factory->create($objectSource);
                     } catch (Turba_Exception $e) {
                         $notification->push($e, 'horde.error');
                         continue;
                     }
                     try {
                         $object = $sourceDriver->getObject($objectKey);
                     } catch (Horde_Exception_NotFound $e) {
                         $notification->push(_("Failed to find object to be added"), 'horde.error');
                         continue;
                     }
                     if ($object->isGroup()) {
                         if ($actionID == 'move') {
                             $notification->push(sprintf(_("\"%s\" was not moved because it is a list."), $object->getValue('name')), 'horde.warning');
                         } else {
                             $notification->push(sprintf(_("\"%s\" was not copied because it is a list."), $object->getValue('name')), 'horde.warning');
                         }
                         continue;
                     }
                     // Try adding to the target.
                     $objAttributes = array();
                     // Get the values through the Turba_Object class.
                     foreach (array_keys($targetDriver->getCriteria()) as $info_key) {
                         if (!is_array($targetDriver->map[$info_key]) || isset($targetDriver->map[$info_key]['attribute'])) {
                             $objectValue = $object->getValue($info_key);
                             // Get 'data' value if object type is image, the
                             // direct value in other case.
                             $objAttributes[$info_key] = isset($attributes[$info_key]) && $attributes[$info_key]['type'] == 'image' ? $objectValue['load']['data'] : $objectValue;
                         }
                     }
                     unset($objAttributes['__owner']);
                     if ($actionID == 'copy') {
                         unset($objAttributes['__uid']);
                     }
                     // Try adding tags.
                     $objAttributes['__tags'] = $object->getValue('__tags');
                     try {
                         $targetDriver->add($objAttributes);
                     } catch (Turba_Exception $e) {
                         $notification->push(sprintf(_("Failed to add %s to %s: %s"), $object->getValue('name'), $targetDriver->title, $e), 'horde.error');
                         break;
                     }
                     $notification->push(sprintf(_("Successfully added %s to %s"), $object->getValue('name'), $targetDriver->title), 'horde.success');
                     // If we're moving objects, and we succeeded,
                     // delete them from the original source now.
                     if ($actionID == 'move') {
                         try {
                             $sourceDriver->delete($objectKey, false);
                         } catch (Turba_Exception $e) {
                             $notification->push(sprintf(_("There was an error deleting \"%s\" from the source address book."), $object->getValue('name')), 'horde.error');
                         }
                         /* Log the adding of this item in the history again,
                          * because otherwise the delete log would be after the
                          * add log. */
                         try {
                             $history->log('turba:' . $targetDriver->getName() . ':' . $objAttributes['__uid'], array('action' => 'add'), true);
                         } catch (Exception $e) {
                             Horde::log($e, 'ERR');
                         }
                     }
                 }
                 break;
             case 'add':
                 // Add a contact to a list.
                 $keys = $vars->get('objectkeys');
                 if (!($targetKey = $vars->get('targetList'))) {
                     break;
                 }
                 $args = array();
                 if (strlen($vars->get('targetNew'))) {
                     $targetSource = $vars->get('targetAddressbook');
                     $args['attr'] = array('name' => $targetKey);
                 } else {
                     list($targetSource, $args['gid']) = explode(':', $targetKey, 2);
                     if (!isset($cfgSources[$targetSource])) {
                         break;
                     }
                 }
                 $members = array();
                 foreach ($keys as $key) {
                     $members[] = explode(':', $key, 2);
                 }
                 try {
                     $res = Turba_Object_Group::createGroup($targetSource, $members, $args);
                 } catch (Turba_Exception $e) {
                     $notification->push($e, 'horde.error');
                     break;
                 }
                 if (isset($args['name'])) {
                     $notification->push(sprintf(_("Successfully created the contact list \"%s\"."), $args['name']), 'horde.success');
                 }
                 if (!empty($res->error)) {
                     if ($res->success) {
                         $notification->push(sprintf(_("Error adding %d of %d requested contact(s) to list."), count($res->error), count($res->error) + $res->success), 'horde.error');
                     } else {
                         $notification->push(sprintf(_("Error adding %d contact(s) to list."), count($res->error)), 'horde.error');
                     }
                 } elseif ($res->success) {
                     $notification->push(sprintf(_("Successfully added %d contact(s) to list."), $res->success), 'horde.success');
                 }
                 break;
         }
         // We might get here from the search page but are not allowed to
         // browse the current address book.
         if ($actionID && empty($cfgSources[$source]['browse'])) {
             Horde::url($prefs->getValue('initial_page'), true)->redirect();
         }
     }
     $templates = array();
     if (isset($driver)) {
         Turba::addBrowseJs();
         // Read the columns to display from the preferences.
         $sources = Turba::getColumns();
         $columns = isset($sources[$source]) ? $sources[$source] : array();
         $sortorder = Turba::getPreferredSortOrder();
         if ($vars->get('key')) {
             // We are displaying a list.
             try {
                 $list = $driver->getObject($vars->get('key'));
             } catch (Horde_Exception $e) {
                 $notification->push(_("There was an error displaying the list"), 'horde.error');
                 $list = null;
             }
             if ($list && $list->isGroup()) {
                 $title = sprintf(_("Contacts in list: %s"), $list->getValue('name'));
                 $templates[] = '/browse/header.inc';
                 // Show List Members.
                 try {
                     $results = $list->listMembers($sortorder);
                     if (count($results) != $list->count()) {
                         $count = $list->count() - count($results);
                         $notification->push(sprintf(ngettext("There is %d contact in this list that is not viewable to you", "There are %d contacts in this list that are not viewable to you", $count), $count), 'horde.message');
                     }
                     $view = new Turba_View_List($results, null, $columns);
                     $view->setType('list');
                 } catch (Turba_Exception $e) {
                     $notification->push(_("Failed to browse list"), 'horde.error');
                 }
             }
         } else {
             // We are displaying an address book.
             $title = $cfgSources[$source]['title'];
             $templates[] = '/browse/header.inc';
             if (empty($cfgSources[$source]['browse'])) {
                 $notification->push(_("Your default address book is not browseable."), 'horde.warning');
             } else {
                 $type_filter = array();
                 switch ($vars->get('show')) {
                     case 'contacts':
                         $type_filter = array('__type' => 'Object');
                         break;
                     case 'lists':
                         $type_filter = array('__type' => 'Group');
                         break;
                 }
                 try {
                     $results = $driver->search($type_filter, $sortorder, 'AND', array_merge(array('__uid'), $columns ? $columns : array('name')));
                     $view = new Turba_View_List($results, null, $columns);
                     $view->setType('directory');
                 } catch (Turba_Exception $e) {
                     $notification->push($e, 'horde.error');
                 }
             }
         }
     } else {
         $templates[] = '/browse/header.inc';
     }
     $page_output->addScriptFile('quickfinder.js', 'horde');
     $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
     $page_output->addScriptFile('redbox.js', 'horde');
     $page_output->header(array('title' => $title));
     $notification->notify(array('listeners' => 'status'));
     foreach ($templates as $template) {
         require TURBA_TEMPLATES . $template;
     }
     if (isset($view) && is_object($view)) {
         $view->display();
     }
     $page_output->footer();
 }
Example #17
0
 /**
  * Add members to a group, creating the group if necessary.
  *
  * @param string $source  Destination source.
  * @param array $members  Members of the group. Array of two-element
  *                        arrays: source and key.
  * @param array $opts     Additional options:
  * <pre>
  *  - attr: (array) Array of attributes to use to create a new group.
  *          This should include 'name' at a minimum.
  *  - gid: (string) Existing Group ID.
  *  - name: (string) Group Name.
  * </pre>
  *
  * @return object  Object with the following properties:
  * <pre>
  *   - errors: (array) List of errors when adding members.
  *   - group: (Turba_Object_Group) Group object.
  *   - success: (integer) Number of members sucessfully added.
  * </pre>
  *
  * @throws Turba_Exception
  */
 public static function createGroup($source, $members, array $opts = array())
 {
     global $injector;
     /* Throws Turba_Exception */
     $driver = $injector->getInstance('Turba_Factory_Driver')->create($source);
     if (isset($opts['gid'])) {
         /* Throws Turba_Exception */
         $group = $driver->getObject($opts['gid']);
     } elseif (isset($opts['attr']) && is_array($opts['attr'])) {
         if ($error = Turba::hasMaxContacts($driver)) {
             throw new Turba_Exception($error);
         }
         $newGroup = array_merge($opts['attr'], array('__owner' => $driver->getContactOwner(), '__type' => 'Group'));
         try {
             $group = $driver->getObject($driver->add($newGroup));
         } catch (Turba_Exception $e) {
         }
     } else {
         $group = null;
     }
     if (empty($group) || !$group->isGroup()) {
         throw new Turba_Exception(_("Could not create or add to group."));
     }
     $out = new stdClass();
     $out->errors = array();
     $out->success = 0;
     $out->group = $group;
     // Adding contact to an existing list.
     foreach ($members as $key) {
         try {
             $group->addMember($key[1], $key[0]);
             ++$out->success;
         } catch (Turba_Exception $e) {
             $out->errors[] = $e;
         }
         $group->store();
     }
     return $out;
 }
Example #18
0
 /**
  * Searches the current address book for duplicate entries.
  *
  * Duplicates are determined by comparing email and name or last name and
  * first name values.
  *
  * @return array  A hash with the following format:
  *                <code>
  *                array('name' => array('John Doe' => Turba_List, ...), ...)
  *                </code>
  * @throws Turba_Exception
  */
 public function searchDuplicates()
 {
     $owner = $this->getContactOwner();
     $fields = array();
     if (is_array($this->map['name'])) {
         if (in_array('lastname', $this->map['name']['fields']) && isset($this->map['lastname'])) {
             $field = array($this->map['lastname']);
             if (in_array('firstname', $this->map['name']['fields']) && isset($this->map['firstname'])) {
                 $field[] = $this->map['firstname'];
             }
             $fields[] = $field;
         }
     } else {
         $fields[] = $this->map['name'];
     }
     if (isset($this->map['email'])) {
         $fields[] = $this->map['email'];
     }
     $nameFormat = $GLOBALS['prefs']->getValue('name_format');
     if ($nameFormat != 'first_last' && $nameFormat != 'last_first') {
         $nameFormat = 'first_last';
     }
     $order = $this->_buildFields($fields);
     $joins = $this->_buildJoin($fields);
     $where = $this->_buildWhere($fields);
     $duplicates = array();
     for ($i = 0; $i < count($joins); $i++) {
         /* Build up the full query. */
         $values = array();
         $query = sprintf('SELECT DISTINCT a1.%s, %s FROM %s a1 JOIN %s a2 ON %s AND a1.%s <> a2.%s WHERE', $this->map['__key'], $order[$i], $this->_params['table'], $this->_params['table'], $joins[$i], $this->map['__key'], $this->map['__key']);
         if (isset($this->map['__owner'])) {
             $query .= sprintf(' a1.%s = ? AND a2.%s = ? AND', $this->map['__owner'], $this->map['__owner']);
             $values = array($owner, $owner);
         }
         $query .= sprintf(' %s ORDER BY %s', $where[$i], $order[$i]);
         /* Run query. */
         try {
             $ids = $this->_db->selectValues($query, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Turba_Exception(_("Server error when performing search."));
         }
         $field = $i == 0 ? 'name' : array_search($fields[$i], $this->map);
         $contacts = array();
         foreach ($ids as $id) {
             $contact = $this->getObject($id);
             $value = $contact->getValue($field);
             if ($field == 'name') {
                 $value = Turba::formatName($contact, $nameFormat);
             }
             /* HACK! */
             if ($field == 'email') {
                 $value = Horde_String::lower($value);
             }
             if (!isset($contacts[$value])) {
                 $contacts[$value] = new Turba_List();
             }
             $contacts[$value]->insert($contact);
         }
         if ($contacts) {
             $duplicates[$field] = $contacts;
         }
     }
     return $duplicates;
 }
Example #19
0
 /**
  * Extends parent function to build composed fields needed for the dn
  * based on the contents of $this->map.
  *
  * @param array $hash  Hash using Turba keys.
  *
  * @return array  Translated version of $hash.
  */
 public function toDriverKeys(array $hash)
 {
     // First check for combined fields in the dn-fields and add them.
     if (is_array($this->_params['dn'])) {
         foreach ($this->_params['dn'] as $param) {
             foreach ($this->map as $turbaname => $ldapname) {
                 if (is_array($ldapname) && isset($ldapname['attribute']) && $ldapname['attribute'] == $param) {
                     $fieldarray = array();
                     foreach ($ldapname['fields'] as $mapfield) {
                         $fieldarray[] = isset($hash[$mapfield]) ? $hash[$mapfield] : '';
                     }
                     $hash[$turbaname] = Turba::formatCompositeField($ldapname['format'], $fieldarray);
                 }
             }
         }
     }
     // Now convert the turba-fieldnames to ldap-fieldnames
     return parent::toDriverKeys($hash);
 }
Example #20
0
 /**
  * Retrieves a natural language description of the sort order
  *
  * @return string
  */
 public function getSortOrderDescription()
 {
     $description = array();
     $sortorder = Turba::getPreferredSortOrder();
     foreach ($sortorder as $elt) {
         $field = $elt['field'];
         if (!strlen($field) || $field == 'lastname') {
             $field = 'name';
         }
         $description[] = $GLOBALS['attributes'][$field]['label'];
     }
     return join(', ', $description);
 }
Example #21
0
 /**
  */
 public function davGetCollections($user)
 {
     global $injector, $registry;
     $dav = $injector->getInstance('Horde_Dav_Storage');
     $factory = $injector->getInstance('Turba_Shares');
     $books = array();
     foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $book) {
         // Ugly hack! There is currently no clean way to retrieve address
         // books that the user "owns", or to find out if a SQL/LDAP/Kolab
         // address book contains per-user or global contacts.
         if ($book['type'] == 'share') {
             $share = $factory->getShare($id);
             if ($user == '-system-' && strlen($share->get('owner')) || $user != '-system-' && $user != $share->get('owner') && $user != $registry->getAuth()) {
                 continue;
             }
         }
         if ($user == '-system-' && ($book['type'] == 'facebook' || $book['type'] == 'favourites' || $book['type'] == 'vbook')) {
             continue;
         }
         try {
             $id = $dav->getExternalCollectionId($id, 'contacts') ?: $id;
         } catch (Horde_Dav_Exception $e) {
         }
         $books[] = array('id' => $id, 'uri' => $id, 'principaluri' => 'principals/' . $user, '{DAV:}displayname' => $book['title'], '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(array(array('contentType' => 'text/directory', 'version' => '3.0'), array('contentType' => 'text/vcard', 'version' => '3.0'), array('contentType' => 'text/x-vcard', 'version' => '2.1'))));
     }
     return $books;
 }
Example #22
0
if (!$addSources) {
    $notification->push(_("There are no writeable address books. None of the available address books are configured to allow you to add new entries to them. If you believe this is an error, please contact your system administrator."), 'horde.error');
    $url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
    $url->redirect();
}
/* A source has been selected, connect and set up the fields. */
if ($source) {
    try {
        $driver = $injector->getInstance('Turba_Factory_Driver')->create($source);
    } catch (Turba_Exception $e) {
        $notification->push($e, 'horde.error');
        $driver = null;
    }
    if (!is_null($driver)) {
        /* Check permissions. */
        $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
        if ($max_contacts !== true && $max_contacts <= count($driver)) {
            Horde::permissionDeniedError('turba', 'max_contacts', sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']));
            $url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
            $url->redirect();
        }
        $contact = new Turba_Object($driver);
    }
}
/* Set up the form. */
$form = new Turba_Form_AddContact($vars, $contact);
/* Validate the form. */
if ($form->validate()) {
    $form->execute();
}
Horde::startBuffer();
Example #23
0
 /**
  * Creates a new Horde_Share and creates the address book
  * on the IMSP server.
  *
  * @param array  The params for the share.
  *
  * @return Horde_Share  The share object.
  * @throws Turba_Exception
  */
 public function createShare($share_id, $params)
 {
     $params['params']['name'] = $this->params['username'];
     if (!isset($params['default']) || $params['default'] !== true) {
         $params['params']['name'] .= '.' . $params['name'];
     }
     $result = Turba::createShare($share_id, $params);
     try {
         Horde_Core_Imsp_Utils::createBook($GLOBALS['cfgSources']['imsp'], $params['params']['name']);
     } catch (Horde_Imsp_Exception $e) {
         throw new Turba_Exception($e);
     }
     return $result;
 }
Example #24
0
<?php

/**
 * Turba browse.php.
 *
 * Copyright 2000-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (ASL).  If you did
 * did not receive this file, see http://www.horde.org/licenses/apache.
 *
 * @author  Chuck Hagenbuch <*****@*****.**>
 * @package Turba
 */
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('turba');
/* If default source is not browsable, try one from the addressbooks pref */
if (empty($cfgSources[Turba::$source]['browse'])) {
    $addressbooks = Turba::getAddressBooks();
    foreach ($addressbooks as $source) {
        if (!empty($cfgSources[$source]['browse'])) {
            Turba::$source = $source;
            break;
        }
    }
}
$params = array('addSources' => $addSources, 'attributes' => $attributes, 'browse_source_count' => $browse_source_count, 'browser' => $browser, 'cfgSources' => $cfgSources, 'copymoveSources' => $copymoveSources, 'conf' => $conf, 'factory' => $injector->getInstance('Turba_Factory_Driver'), 'history' => $injector->getInstance('Horde_History'), 'notification' => $notification, 'page_output' => $page_output, 'prefs' => $prefs, 'registry' => $registry, 'source' => Turba::$source, 'turba_shares' => $injector->getInstance('Turba_Shares'), 'vars' => Horde_Variables::getDefaultVariables());
$browse = new Turba_View_Browse($params);
$browse->run();
Example #25
0
File: add.php Project: horde/horde
/* Exit with an error message if there are no sources to add to. */
if (!$addSources) {
    $notification->push(_("There are no writeable address books. None of the available address books are configured to allow you to add new entries to them. If you believe this is an error, please contact your system administrator."), 'horde.error');
    $url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
    $url->redirect();
}
/* A source has been selected, connect and set up the fields. */
if ($source) {
    try {
        $driver = $injector->getInstance('Turba_Factory_Driver')->create($source);
    } catch (Turba_Exception $e) {
        $notification->push($e, 'horde.error');
        $driver = null;
    }
    if (!is_null($driver)) {
        if (Turba::hasMaxContacts($driver)) {
            $url = $url ? Horde::url($url, true) : Horde::url('index.php', true);
            $url->redirect();
        }
        $contact = new Turba_Object($driver);
    }
}
/* Set up the form. */
$form = new Turba_Form_AddContact($vars, $contact);
/* Validate the form. */
if ($form->validate()) {
    $form->execute();
}
Horde::startBuffer();
$notification->notify(array('listeners' => 'status'));
$form->renderActive($form->getRenderer(), $vars, Horde::url('add.php'), 'post');
Example #26
0
 /**
  * Creates a new Horde_Share for this source type.
  *
  * @param string $share_name  The share name
  * @param array  $params      The params for the share.
  *
  * @return Horde_Share  The share object.
  */
 public function createShare($share_name, array $params)
 {
     // If the raw address book name is not set, use the share name
     if (empty($params['params']['name'])) {
         $params['params']['name'] = $share_name;
     }
     return Turba::createShare($share_name, $params);
 }
Example #27
0
 /**
  * Filters/Sorts the list based on the specified sort routine.
  * The default sort order is by last name, ascending.
  *
  * @param array $order  Array of hashes describing sort fields.  Each
  *                      hash has the following fields:
  * <pre>
  * ascending - (boolean) Sort direction.
  * field - (string) Sort field.
  * </pre>
  */
 public function sort($order = null)
 {
     global $attributes, $prefs;
     if (!$order) {
         $order = array(array('ascending' => true, 'field' => 'lastname'));
     }
     $need_lastname = $need_firstname = false;
     $name_format = $prefs->getValue('name_format');
     $name_sort = $prefs->getValue('name_sort');
     foreach ($order as &$field) {
         if ($field['field'] == 'name') {
             if ($name_sort == 'last_first') {
                 $field['field'] = 'lastname';
             } elseif ($name_sort == 'first_last') {
                 $field['field'] = 'firstname';
             }
         }
         if ($field['field'] == 'lastname') {
             $field['field'] = '__lastname';
             $need_lastname = true;
             break;
         }
         if ($field['field'] == 'firstname') {
             $field['field'] = '__firstname';
             $need_firstname = true;
             break;
         }
     }
     if ($need_firstname || $need_lastname) {
         $sorted_objects = array();
         foreach ($this->objects as $key => $object) {
             $name = $object->getValue('name');
             $firstname = $object->getValue('firstname');
             $lastname = $object->getValue('lastname');
             if (!$lastname) {
                 $lastname = Turba::guessLastname($name);
             }
             if (!$firstname) {
                 switch ($name_format) {
                     case 'last_first':
                         $firstname = preg_replace('/' . preg_quote($lastname, '/') . ',\\s*/', '', $name);
                         break;
                     case 'first_last':
                         $firstname = preg_replace('/\\s+' . preg_quote($lastname, '/') . '/', '', $name);
                         break;
                     default:
                         $firstname = preg_replace('/\\s*' . preg_quote($lastname, '/') . '(,\\s*)?/', '', $name);
                         break;
                 }
             }
             $object->setValue('__lastname', $lastname);
             $object->setValue('__firstname', $firstname);
             $sorted_objects[$key] = $object;
         }
     } else {
         $sorted_objects = $this->objects;
     }
     // Set the comparison type based on the type of attribute we're
     // sorting by.
     foreach ($order as &$val) {
         $sm = 'text';
         if (isset($attributes[$val['field']])) {
             $f = $attributes[$val['field']];
             if (!empty($f['cmptype'])) {
                 $sm = $f['cmptype'];
             } elseif (in_array($f['type'], array('int', 'intlist', 'number'))) {
                 $sm = 'int';
             }
         }
         $val['sortmethod'] = $sm;
     }
     $this->_usortCriteria = $order;
     /* Exceptions thrown inside a sort incorrectly cause an error. See
      * Bug #9202. */
     @usort($sorted_objects, array($this, '_cmp'));
     $this->objects = $sorted_objects;
 }
Example #28
0
 /**
  * Creates a new Horde_Share for this source type.
  *
  * @param string $share_name  The share name
  * @param array  $params      The params for the share.
  *
  * @return Horde_Share  The share object.
  */
 public function createShare($share_name, array $params)
 {
     if (!isset($params['name'])) {
         $params['name'] = _('Contacts');
     }
     if (!empty($params['params']['default'])) {
         $params['default'] = true;
         unset($params['params']['default']);
     }
     return Turba::createShare($share_name, $params);
 }
Example #29
0
 /**
  * Returns history information about this contact.
  *
  * @return array  A hash with the optional entries 'created' and 'modified'
  *                and human readable history information as the values.
  */
 public function getHistory()
 {
     if (!$this->getValue('__uid')) {
         return array();
     }
     $history = array();
     try {
         $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory($this->getGuid());
         foreach ($log as $entry) {
             if ($entry['action'] == 'add' || $entry['action'] == 'modify') {
                 if ($GLOBALS['registry']->getAuth() != $entry['who']) {
                     $by = sprintf(_("by %s"), Turba::getUserName($entry['who']));
                 } else {
                     $by = _("by me");
                 }
                 $history[$entry['action'] == 'add' ? 'created' : 'modified'] = strftime($GLOBALS['prefs']->getValue('date_format'), $entry['ts']) . ' ' . date($GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . htmlspecialchars($by);
             }
         }
     } catch (Exception $e) {
         return array();
     }
     return $history;
 }
Example #30
0
 /**
  * Prepare the Turba setup.
  *
  * @return NULL
  */
 public function prepareTurba()
 {
     $world =& $this->prepareBasicSetup();
     $this->assertTrue($world['auth']->authenticate('*****@*****.**', array('password' => 'none')));
     $GLOBALS['registry']->pushApp('turba', array('check_perms' => false));
     // Turba base libraries.
     require_once TURBA_BASE . '/lib/Turba.php';
     require_once TURBA_BASE . '/lib/Driver.php';
     require_once TURBA_BASE . '/lib/Object.php';
     // Turba source and attribute configuration.
     include TURBA_BASE . '/config/attributes.php';
     $cfgSources = Turba::availableSources();
     unset($cfgSources['kolab_global']);
     $this->prepareNewFolder($world['storage'], 'Contacts', 'contact', true);
     $this->prepareNewFolder($world['storage'], 'test2', 'contact');
     $GLOBALS['session']->set('turba', 'has_share', true);
     $GLOBALS['cfgSources'] = Turba::getConfigFromShares($cfgSources);
 }