getExtendedPermission() публичный статический Метод

Gets extended permissions on an address book.
public static getExtendedPermission ( Turba_Driver $addressBook, string $permission ) : mixed
$addressBook Turba_Driver The address book to get extended permissions for.
$permission string What extended permission to get.
Результат mixed The requested extended permissions value, or true if it doesn't exist.
Пример #1
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;
 }
Пример #2
0
        $notification->push(_("This file format is not supported."), 'horde.error');
        $next_step = Horde_Data::IMPORT_FILE;
    }
}
/* Loop through the action handlers. */
switch ($vars->actionID) {
    case Horde_Data::IMPORT_FILE:
        try {
            $driver = $injector->getInstance('Turba_Factory_Driver')->create($vars->dest);
        } catch (Horde_Exception $e) {
            $notification->push($e, 'horde.error');
            $error = true;
            break;
        }
        /* 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, $driver->title));
            $error = true;
        } else {
            $data->storage->set('target', $vars->dest);
            $data->storage->set('purge', $vars->purge);
        }
        break;
    case Horde_Data::IMPORT_MAPPED:
    case Horde_Data::IMPORT_DATETIME:
        foreach ($cfgSources[$data->storage->get('target')]['map'] as $field => $null) {
            if (substr($field, 0, 2) != '__' && !is_array($null)) {
                switch ($attributes[$field]['type']) {
                    case 'monthyear':
                    case 'monthdayyear':
Пример #3
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;
                 }
                 $max_contacts = Turba::getExtendedPermission($targetDriver, 'max_contacts');
                 if ($max_contacts !== true && $max_contacts <= count($targetDriver)) {
                     Horde::permissionDeniedError('turba', 'max_contacts', sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title']));
                     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 {
                         $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);
                         } 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');
                 $targetKey = $vars->get('targetList');
                 if (empty($targetKey)) {
                     break;
                 }
                 if (!$vars->exists('targetNew') || $vars->get('targetNew') == '') {
                     list($targetSource, $targetKey) = explode(':', $targetKey, 2);
                     if (!isset($cfgSources[$targetSource])) {
                         break;
                     }
                     try {
                         $targetDriver = $factory->create($targetSource);
                     } catch (Turba_Exception $e) {
                         $notification->push($e, 'horde.error');
                         break;
                     }
                     try {
                         $target = $targetDriver->getObject($targetKey);
                     } catch (Horde_Exception $e) {
                         $notification->push($e);
                         break;
                     }
                 } else {
                     $targetSource = $vars->get('targetAddressbook');
                     try {
                         $targetDriver = $factory->create($targetSource);
                     } catch (Turba_Exception $e) {
                         $notification->push($e, 'horde.error');
                         break;
                     }
                 }
                 if (!empty($target) && $target->isGroup()) {
                     // Adding contact to an existing list.
                     if (is_array($keys)) {
                         $errorCount = 0;
                         foreach ($keys as $sourceKey) {
                             list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                             try {
                                 $target->addMember($objectKey, $objectSource);
                             } catch (Turba_Exception $e) {
                                 $notification->push($e, 'horde.error');
                                 $errorCount++;
                             }
                         }
                         if (!$errorCount) {
                             $notification->push(sprintf(_("Successfully added %d contact(s) to list."), count($keys)), 'horde.success');
                         } elseif ($errorCount == count($keys)) {
                             $notification->push(sprintf(_("Error adding %d contact(s) to list."), count($keys)), 'horde.error');
                         } else {
                             $notification->push(sprintf(_("Error adding %d of %d requested contact(s) to list."), $errorCount, count($keys)), 'horde.error');
                         }
                         $target->store();
                     }
                 } else {
                     // 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']));
                         break;
                     }
                     // Adding contact to a new list.
                     $newList = array('__owner' => $targetDriver->getContactOwner(), '__type' => 'Group', 'name' => $targetKey);
                     try {
                         $targetKey = $targetDriver->add($newList);
                     } catch (Turba_Exception $e) {
                         $notification->push(_("There was an error creating a new list."), 'horde.error');
                         $targetKey = null;
                     }
                     if ($targetKey) {
                         try {
                             $target = $targetDriver->getObject($targetKey);
                             if ($target->isGroup()) {
                                 $notification->push(sprintf(_("Successfully created the contact list \"%s\"."), $newList['name']), 'horde.success');
                                 if (is_array($keys)) {
                                     $errorCount = 0;
                                     foreach ($keys as $sourceKey) {
                                         list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                                         try {
                                             $target->addMember($objectKey, $objectSource);
                                         } catch (Turba_Exception $e) {
                                             $notification->push($e, 'horde.error');
                                             ++$errorCount;
                                         }
                                     }
                                     if (!$errorCount) {
                                         $notification->push(sprintf(_("Successfully added %d contact(s) to list."), count($keys)), 'horde.success');
                                     } elseif ($errorCount == count($keys)) {
                                         $notification->push(sprintf(_("Error adding %d contact(s) to list."), count($keys)), 'horde.error');
                                     } else {
                                         $notification->push(sprintf(_("Error adding %d of %d requested contact(s) to list."), $errorCount, count($keys)), 'horde.error');
                                     }
                                     $target->store();
                                 }
                             }
                         } catch (Turba_Exception $e) {
                         }
                     }
                 }
                 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();
 }