function _check_max() { $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_events') !== true && $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) { Horde::permissionDeniedError('kronolith', 'max_events', sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))); return false; } return true; }
if (!$prefs->isLocked('thread_view_bodies')) { $actions[] = Horde::link($url->add('bodies', 1), _("View bodies")) . _("View bodies") . '</a>'; } $threads = $messages->getThreadsUi($threads_list, $col_headers, $view_bodies, $threads_template); break; } /* Set up the main template tags. */ Horde::startBuffer(); $notification->notify(array('listeners' => 'status')); $view->notify = Horde::endBuffer(); $view->actions = $actions; $view->threads = $threads; $view->rss = Horde::url('rss/messages.php', true, -1)->add(array('scope' => $scope, 'message_id' => $message_id, 'forum_id' => $forum_id)); /* Display an edit-dialogue if the thread is not locked and we can edit messages in them. */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { Horde::permissionDeniedError('agora', null); $view->form = sprintf(_("You don't have permission to post messages in forum %s."), $forum['forum_name']); } elseif ($message['locked']) { $view->form = _("Thread locked."); } else { $reply = $messages->replyMessage($message); $vars = Horde_Variables::getDefaultVariables(); $vars->set('forum_id', $forum_id); $vars->set('message_parent_id', $message_id); $vars->set('message_subject', $reply['message_subject']); $vars->set('message_body_old', $reply['body']); $form = $messages->getForm($vars, sprintf(_("Post a Reply to \"%s\""), $reply['message_subject'])); Horde::startBuffer(); $form->renderActive(null, null, Horde::url('messages/edit.php'), 'post', null, false); $view->form = Horde::endBuffer(); }
/** * 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; }
/** */ protected function _init() { global $injector, $notification, $page_output, $prefs, $session; /* Get the list of filter rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); /* Load the Ingo_Script factory. */ $factory = $injector->getInstance('Ingo_Factory_Script'); /* Get permissions. */ $edit_allowed = Ingo::hasSharePermission(Horde_Perms::EDIT); $delete_allowed = Ingo::hasSharePermission(Horde_Perms::DELETE); /* Token checking. */ $actionID = $this->_checkToken(array('rule_copy', 'rule_delete', 'rule_disable', 'rule_enable')); /* Default to no mailbox filtering. */ $mbox_search = null; /* Perform requested actions. */ switch ($actionID) { case 'mbox_search': if (isset($this->vars->searchfield)) { $mbox_search = array('exact' => $this->vars->get('searchexact', 1), 'query' => $this->vars->searchfield); } break; case 'rule_copy': case 'rule_delete': case 'rule_disable': case 'rule_enable': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } $success = false; switch ($actionID) { case 'rule_delete': if (!$delete_allowed) { $notification->push(_("You do not have permission to delete filter rules."), 'horde.error'); self::url()->redirect(); } if (($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) && $ingo_storage->deleteRule($tmp)) { $notification->push(sprintf(_("Rule \"%s\" deleted."), $tmp->name), 'horde.success'); $success = true; } break; case 'rule_copy': switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'max_rules', _("You are not allowed to create or edit custom rules.")); break 2; case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_rules)); break 2; } if (($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) && $ingo_storage->copyRule($tmp)) { $notification->push(sprintf(_("Rule \"%s\" copied."), $tmp->name), 'horde.success'); $success = true; } break; case 'rule_disable': case 'rule_enable': if ($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) { $tmp->disable = $actionID === 'rule_disable'; $ingo_storage->updateRule($tmp); $notification->push(sprintf($actionID === 'rule_disable' ? _("Rule \"%s\" disabled.") : _("Rule \"%s\" enabled."), $tmp->name), 'horde.success'); $success = true; } break; } /* Save changes */ if ($success) { try { $factory->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); } } break; case 'settings_save': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } $prefs->setValue('show_filter_msg', $this->vars->show_filter_msg); $prefs->setValue('filter_seen', $this->vars->filter_seen); $notification->push(_("Settings successfully updated."), 'horde.success'); break; case 'apply_filters': $factory->perform(); break; } /* Common URLs. */ $filters_url = $this->_addToken(self::url()); $rule_url = Ingo_Basic_Rule::url(); $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/filters')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->canapply = $factory->canPerform(); $view->deleteallowed = $delete_allowed; $view->editallowed = $edit_allowed; $view->formurl = $filters_url; $view->can_copy = $edit_allowed && !$ingo_storage->maxRules(); $display = array(); $filters = Ingo_Storage_FilterIterator_Match::create($ingo_storage, $session->get('ingo', 'script_categories')); foreach ($filters as $rule) { $copyurl = $delurl = $editurl = null; $entry = array(); $url = $filters_url->copy()->add('uid', $rule->uid); switch (get_class($rule)) { case 'Ingo_Rule_System_Blacklist': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Blacklist::url(); $entry['filterimg'] = 'blacklist.png'; break; case 'Ingo_Rule_System_Whitelist': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Whitelist::url(); $entry['filterimg'] = 'whitelist.png'; break; case 'Ingo_Rule_System_Vacation': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Vacation::url(); $entry['filterimg'] = 'vacation.png'; break; case 'Ingo_Rule_System_Forward': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Forward::url(); $entry['filterimg'] = 'forward.png'; break; case 'Ingo_Rule_System_Spam': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Spam::url(); $entry['filterimg'] = 'spam.png'; break; default: if (!is_null($mbox_search)) { if ($mbox_search['exact']) { if (strcasecmp($filter['action-value'], $mbox_search['query']) !== 0) { continue 2; } } elseif (stripos($filter['action-value'], $mbox_search['query']) === false) { continue 2; } } $editurl = $rule_url->copy()->add(array('edit' => $rule->uid)); $delurl = $url->copy()->add('actionID', 'rule_delete'); $copyurl = $url->copy()->add('actionID', 'rule_copy'); break; } /* Create description. */ if (!$edit_allowed) { $entry['descriplink'] = htmlspecialchars($rule->name); } elseif (!empty($rule->conditions)) { $entry['descriplink'] = Horde::linkTooltip($editurl, sprintf(_("Edit %s"), $rule->name), null, null, null, $rule->description()) . htmlspecialchars($rule->name) . '</a>'; } else { $entry['descriplink'] = Horde::link($editurl, sprintf(_("Edit %s"), $rule->name)) . htmlspecialchars($rule->name) . '</a>'; } /* Create delete link. */ if ($delete_allowed && !is_null($delurl)) { $entry['dellink'] = Horde::link($delurl, sprintf(_("Delete %s"), $rule->name), null, null, "return window.confirm('" . addslashes(_("Are you sure you want to delete this rule?")) . "');"); } /* Create copy link. */ if ($view->can_copy && !is_null($copyurl)) { $entry['copylink'] = Horde::link($copyurl, sprintf(_("Copy %s"), $rule->name)); } /* Create disable/enable link. */ if (!$rule->disable) { $entry['disabled'] = true; if ($edit_allowed) { $entry['disablelink'] = Horde::link($url->copy()->add('actionID', 'rule_disable'), sprintf(_("Disable %s"), $rule->name)); } } elseif ($edit_allowed) { $entry['enablelink'] = Horde::link($url->copy()->add('actionID', 'rule_enable'), sprintf(_("Enable %s"), $rule->name)); } $display[$rule->uid] = $entry; } $view->filter = $display; $view->mbox_search = $mbox_search; if ($edit_allowed && is_null($mbox_search)) { if ($factory->hasFeature('on_demand')) { $view->settings = true; $view->flags = $prefs->getValue('filter_seen'); $view->show_filter_msg = $prefs->getValue('show_filter_msg'); } $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptPackage('Horde_Core_Script_Package_Sortable'); } $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('filters.js'); $page_output->ajax = true; $topbar = $injector->getInstance('Horde_View_Topbar'); $topbar->search = true; $topbar->searchAction = self::url(); $topbar->searchLabel = _("Mailbox Search"); $topbar->searchParameters = array('actionID' => 'mbox_search', 'searchexact' => 0, 'page' => 'filters'); $this->header = _("Filter Rules"); $this->output = $view->render('filters'); }
/** * @param mixed $max * @param Ingo_Storage_Filters $filters */ protected function _assertMaxRules($max, $filters) { if ($max !== true && $max <= count($filters->getFilterList())) { Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $max)); return true; } return false; }
* Copyright 2002-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you did not * did not receive this file, see http://www.horde.org/licenses/bsdl.php. * * @author Mike Cochrane <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('trean'); /* Deal with any action task. */ $actionID = Horde_Util::getFormData('actionID'); switch ($actionID) { case 'add_bookmark': /* Check permissions. */ if (Trean::hasPermission('max_bookmarks') !== true && Trean::hasPermission('max_bookmarks') <= $trean_gateway->countBookmarks()) { Horde::permissionDeniedError('trean', 'max_bookmarks', sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))); Horde::url('browse.php', true)->redirect(); } /* Create a new bookmark. */ $properties = array('bookmark_url' => Horde_Util::getFormData('url'), 'bookmark_title' => Horde_Util::getFormData('title'), 'bookmark_description' => Horde_Util::getFormData('description'), 'bookmark_tags' => Horde_Util::getFormData('treanBookmarkTags')); try { $bookmark = $trean_gateway->newBookmark($properties, !empty($conf['content_index']['enabled'])); } catch (Exception $e) { $notification->push(sprintf(_("There was an error adding the bookmark: %s"), $e->getMessage()), 'horde.error'); } if (Horde_Util::getFormData('popup')) { echo Horde::wrapInlineScript(array('window.close();')); } elseif (Horde_Util::getFormData('iframe')) { $notification->push(_("Bookmark Added"), 'horde.success'); $page_output->header(); $notification->notify();
* * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Chuck Hagenbuch <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('kronolith'); if (Kronolith::showAjaxView()) { Horde::url('', true)->setAnchor('event')->redirect(); } /* Check permissions. */ $url = Horde::url($prefs->getValue('defaultview') . '.php', true)->add(array('month' => Horde_Util::getFormData('month'), 'year' => Horde_Util::getFormData('year'))); $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_events') !== true && $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) { Horde::permissionDeniedError('kronolith', 'max_events', sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))); $url->redirect(); } $display_resource = $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS); $calendar_id = Horde_Util::getFormData('calendar', empty($display_resource) ? 'internal_' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT) : 'resource_' . $display_resource[0]); if ($calendar_id == 'internal_' || $calendar_id == 'resource_') { $url->redirect(); } $event = Kronolith::getDriver()->getEvent(); $session->set('kronolith', 'attendees', $event->attendees); $session->set('kronolith', 'resources', $event->getResources()); $date = Horde_Util::getFormData('datetime'); if ($date) { $event->start = new Horde_Date($date); } else { $date = Horde_Util::getFormData('date', date('Ymd')) . '000600';
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom rules.")); Ingo_Basic_Filters::url()->redirect(); case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_rules)); Ingo_Basic_Filters::url()->redirect(); } if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* Load the Ingo_Script:: driver. */ $ingo_script_factory = $injector->getInstance('Ingo_Factory_Script'); $ingo_script = $ingo_script_factory->create(Ingo::RULE_FILTER); /* Redirect if no rules are available. */ $availActions = $ingo_script->availableActions(); if (empty($availActions)) { $notification->push(_("Individual rules are not supported in the current filtering driver."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* This provides the $ingo_fields array. */ $config = new Horde_Registry_LoadConfig('ingo', 'fields.php', 'ingo_fields'); $ingo_fields = $config->config['ingo_fields']; /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ switch ($this->vars->action) { case 'Ingo_Rule_User_Discard': case 'Ingo_Rule_User_FlagOnly': case 'Ingo_Rule_User_Keep': case 'Ingo_Rule_User_Move': case 'Ingo_Rule_User_MoveKeep': case 'Ingo_Rule_User_Notify': case 'Ingo_Rule_User_Redirect': case 'Ingo_Rule_User_RedirectKeep': case 'Ingo_Rule_User_Reject': $rule = new $this->vars->action(); $rule->combine = $this->vars->combine; $rule->name = $this->vars->name; $rule->stop = $this->vars->stop; $rule->uid = $this->vars->edit; break; default: $rule = isset($this->vars->edit) ? $ingo_storage->getRuleByUid($this->vars->edit) : new Ingo_Rule_User(); break; } if (!$rule) { $notification->push(_("Filter not found."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } if ($ingo_script->hasFeature('case_sensitive')) { $casesensitive = $this->vars->case; } foreach (array_filter(isset($this->vars->field) ? $this->vars->field : array()) as $key => $val) { $condition = array(); $f_label = null; if ($val == Ingo::USER_HEADER) { $condition['field'] = empty($this->vars->userheader[$key]) ? '' : $this->vars->userheader[$key]; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } else { $condition['field'] = $val; $f_label = $ingo_fields[$val]['label']; $condition['type'] = $ingo_fields[$val]['type']; } $condition['match'] = isset($this->vars->match[$key]) ? $this->vars->match[$key] : ''; if ($actionID == 'rule_save' && empty($this->vars->value[$key]) && !in_array($condition['match'], array('exists', 'not exist'))) { $notification->push(sprintf(_("You cannot create empty conditions. Please fill in a value for \"%s\"."), is_null($f_label) ? $condition['field'] : $f_label), 'horde.error'); $actionID = null; } $condition['value'] = isset($this->vars->value[$key]) ? $this->vars->value[$key] : ''; if (isset($casesensitive)) { $condition['case'] = isset($casesensitive[$key]) ? $casesensitive[$key] : ''; } $tmp = $rule->conditions; $tmp[] = $condition; $rule->conditions = $tmp; } if ($this->vars->action) { switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: switch ($actionID) { case 'rule_save': try { $rule->value = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } break; default: $rule->value = $this->vars->actionvalue; if (!$this->vars->actionvalue && isset($this->vars->actionvalue_new)) { $page_output->addInlineScript(array('IngoNewFolder.setNewFolder("actionvalue", ' . Horde_Serialize::serialize($this->vars->actionvalue_new, Horde_Serialize::JSON) . ')'), true); } break; } break; default: $rule->value = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; $tmp = $rule->flags; foreach ($flags as $val) { $tmp |= $val; } $rule->flags = $tmp; /* Run through action handlers. */ switch ($actionID) { case 'rule_save': if (empty($rule->conditions)) { $notification->push(_("You need to select at least one field to match."), 'horde.error'); break; } $ingo_storage->updateRule($rule); $notification->push(_("Changes saved."), 'horde.success'); try { $ingo_script_factory->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { $tmp = $rule->conditions; unset($tmp[intval($this->vars->conditionnumber)]); $rule->conditions = array_values($tmp); } break; } /* Add new, blank condition. */ $rule->conditions[] = array(); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/rule')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->avail_types = $ingo_script->availableTypes(); $view->edit = $this->vars->edit; $view->fields = $ingo_fields; $view->formurl = $this->_addToken(self::url()); $view->rule = $rule; $view->special = $ingo_script->specialTypes(); $view->userheader = !empty($conf['rules']['userheader']); $filter = array(); $lastcond = count($rule->conditions) - 1; /* Display the conditions. */ foreach ($rule->conditions as $cond_num => $condition) { $tmp = array('cond_num' => intval($cond_num), 'field' => isset($condition['field']) ? $condition['field'] : '', 'lastfield' => $lastcond == $cond_num); if ($view->userheader && isset($condition['type']) && $condition['type'] == Ingo_Rule_User::TEST_HEADER && !isset($ingo_fields[$tmp['field']])) { $tmp['userheader'] = $tmp['field']; } if ($tmp['lastfield']) { $filter[] = $tmp; continue; } /* Create the match listing. */ if (!isset($condition['field']) || $condition['field'] == Ingo::USER_HEADER || !isset($ingo_fields[$condition['field']]['tests'])) { $avail_tests = $ingo_script->availableTests(); } else { $avail_tests = $ingo_fields[$condition['field']]['tests']; } $tmp['matchtest'] = array(); $selected_test = empty($condition['match']) ? null : $condition['match']; foreach ($avail_tests as $test) { if (is_null($selected_test)) { $selected_test = $test; } $tmp['matchtest'][] = array('label' => $rule->getTestInfo($test)->label, 'selected' => isset($condition['match']) && $test == $condition['match'], 'value' => $test); } if (!in_array($selected_test, array('exists', 'not exist'))) { $tmp['match_value'] = isset($condition['value']) ? $condition['value'] : ''; } $testOb = $rule->getTestInfo(!empty($condition['match']) ? $condition['match'] : 'contains'); switch ($testOb->type) { case 'text': if ($ingo_script->hasFeature('case_sensitive')) { $tmp['case_sensitive'] = !empty($condition['case']); } break; } $filter[] = $tmp; } $view->filter = $filter; /* Get the action select output. */ $actions = array(); foreach ($availActions as $val) { $ob = new $val(); $actions[] = array('label' => $ob->label, 'selected' => $ob instanceof $rule, 'value' => $val); } $view->actions = $actions; /* Get the action value output. */ switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule->value); break; case Ingo_Rule_User::TYPE_TEXT: $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule->value) . '" />'; break; } $view->flags = $rule->flags && Ingo_Rule_User::FLAG_AVAILABLE && $ingo_script->hasFeature('imap_flags'); $view->stop = $ingo_script->hasFeature('stop_script'); $page_output->addScriptFile('rule.js'); $page_output->addInlineJsVars(array('IngoRule.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = $rule->name; $this->output = $view->render('rule'); }
/** * Process a modification to the current layout. * * @param string $action TODO * @param integer $row TODO * @param integer $col TODO * @param string $url TODO * * @throws Horde_Exception */ public function handle($action, $row, $col, $url = null) { switch ($action) { case 'moveUp': case 'moveDown': case 'moveLeft': case 'moveRight': case 'expandUp': case 'expandDown': case 'expandLeft': case 'expandRight': case 'shrinkLeft': case 'shrinkRight': case 'shrinkUp': case 'shrinkDown': case 'removeBlock': try { call_user_func(array($this, $action), $row, $col); $this->_updated = true; } catch (Horde_Exception $e) { $GLOBALS['notification']->push($e); } break; // Save the changes made to a block. // Save the changes made to a block. case 'save': // Save the changes made to a block and continue editing. // Save the changes made to a block and continue editing. case 'save-resume': // Get requested block type. list($newapp, $newtype) = explode(':', Horde_Util::getFormData('app')); // Is this a new block? $new = false; if ($this->isEmpty($row, $col) || !$this->rowExists($row) || !$this->colExists($col)) { // Check permissions. $max_blocks = $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_blocks'); if ($max_blocks !== true && $max_blocks <= count($this)) { Horde::permissionDeniedError('horde', 'max_blocks', sprintf(Horde_Core_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks)); break; } $new = true; // Make sure there is somewhere to put it. $this->addBlock($row, $col); } // Or an existing one? $exists = false; $changed = false; if (!$new) { // Get target block info. $info = $this->getBlockInfo($row, $col); $exists = $this->isBlock($row, $col); // Has a different block been selected? if ($exists && ($info['app'] != $newapp || $info['block'] != $newtype)) { $changed = true; } } if ($new || $changed) { // Change app or type. $info = array('app' => $newapp, 'block' => $newtype); $params = $this->_collection->getParams($newapp, $newtype); foreach ($params as $newparam) { $info['params'][$newparam] = $this->_collection->getDefaultValue($newapp, $newtype, $newparam); } $this->setBlockInfo($row, $col, $info); } elseif ($exists) { // Change values. $this->setBlockInfo($row, $col, array('params' => Horde_Util::getFormData('params', array()))); } $this->_updated = true; if ($action == 'save') { break; } // Make a block the current block for editing. // Make a block the current block for editing. case 'edit': $this->_currentBlock = array($row, $col); $url = null; break; } if (!empty($url)) { $url = new Horde_Url($url); $url->unique()->redirect(); } }
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(); }
} require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('nag'); $vars = Horde_Variables::getDefaultVariables(); /* Redirect to the task list if no action has been requested. */ $actionID = $vars->get('actionID'); if (is_null($actionID)) { Horde::url('list.php', true)->redirect(); } /* Run through the action handlers. */ switch ($actionID) { case 'add_task': /* Check permissions. */ $perms = $injector->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_tasks') !== true && $perms->hasAppPermission('max_tasks') <= Nag::countTasks()) { Horde::permissionDeniedError('nag', 'max_tasks', sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks'))); Horde::url('list.php', true)->redirect(); } if (!$vars->exists('tasklist_id')) { $vars->set('tasklist_id', Nag::getDefaultTasklist(Horde_Perms::EDIT)); } if ($parent = Horde_Util::getFormData('parent_task')) { $vars->set('parent', $parent); } $form = new Nag_Form_Task($vars, _("New Task")); break; case 'modify_task': $task_id = $vars->get('task'); $tasklist_id = $vars->get('tasklist'); try { $share = $nag_shares->getShare($tasklist_id);
/** * Recipiet checks to do if this is a user-generated compose message. * * @param Horde_Mail_Rfc822_List $email The e-mail list to send to. * * @throws IMP_Compose_Exception */ protected function _prepSendMessageAssert(Horde_Mail_Rfc822_List $email) { global $injector; $email_count = count($email); $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->accessCompose(IMP_Imap::ACCESS_COMPOSE_TIMELIMIT, $email_count)) { Horde::permissionDeniedError('imp', 'max_timelimit'); throw new IMP_Compose_Exception(sprintf(ngettext("You are not allowed to send messages to more than %d recipient within %d hours.", "You are not allowed to send messages to more than %d recipients within %d hours.", $imp_imap->max_compose_timelimit), $imp_imap->max_compose_timelimit, $injector->getInstance('IMP_Sentmail')->limit_period)); } /* Count recipients if necessary. We need to split email groups * because the group members count as separate recipients. */ if (!$imp_imap->accessCompose(IMP_Imap::ACCESS_COMPOSE_RECIPIENTS, $email_count)) { Horde::permissionDeniedError('imp', 'max_recipients'); throw new IMP_Compose_Exception(sprintf(ngettext("You are not allowed to send messages to more than %d recipient.", "You are not allowed to send messages to more than %d recipients.", $imp_imap->max_compose_recipients), $imp_imap->max_compose_recipients)); } }
/** */ protected function _init() { global $injector, $notification, $page_output, $prefs, $session; /* Get the list of filter rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); /* Load the Ingo_Script factory. */ $factory = $injector->getInstance('Ingo_Factory_Script'); /* Get permissions. */ $edit_allowed = Ingo::hasSharePermission(Horde_Perms::EDIT); $delete_allowed = Ingo::hasSharePermission(Horde_Perms::DELETE); /* Permissions. */ $perms = $injector->getInstance('Horde_Core_Perms'); /* Token checking. */ $actionID = $this->_checkToken(array('rule_copy', 'rule_delete', 'rule_disable', 'rule_enable')); /* Default to no mailbox filtering. */ $mbox_search = null; /* Perform requested actions. */ switch ($actionID) { case 'mbox_search': if (isset($this->vars->searchfield)) { $mbox_search = array('exact' => $this->vars->get('searchexact', 1), 'query' => $this->vars->searchfield); } break; case 'rule_copy': case 'rule_delete': case 'rule_disable': case 'rule_enable': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } switch ($actionID) { case 'rule_delete': if (!$delete_allowed) { $notification->push(_("You do not have permission to delete filter rules."), 'horde.error'); self::url()->redirect(); } $tmp = $filters->getFilter($this->vars->rulenumber); if ($filters->deleteRule($this->vars->rulenumber)) { $notification->push(sprintf(_("Rule \"%s\" deleted."), $tmp['name']), 'horde.success'); } break; case 'rule_copy': $max = $perms->hasAppPermission(Ingo_Perms::getPerm('max_rules')); if ($max === 0) { Horde::permissionDeniedError('ingo', 'max_rules', _("You are not allowed to create or edit custom rules.")); break 2; } elseif ($max !== true && $max <= count($filters->getFilterList())) { Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $max)); break 2; } $tmp = $filters->getFilter($this->vars->rulenumber); if ($filters->copyRule($this->vars->rulenumber)) { $notification->push(sprintf(_("Rule \"%s\" copied."), $tmp['name']), 'horde.success'); } break; case 'rule_disable': $tmp = $filters->getFilter($this->vars->rulenumber); $filters->ruleDisable($this->vars->rulenumber); $notification->push(sprintf(_("Rule \"%s\" disabled."), $tmp['name']), 'horde.success'); break; case 'rule_enable': $tmp = $filters->getFilter($this->vars->rulenumber); $filters->ruleEnable($this->vars->rulenumber); $notification->push(sprintf(_("Rule \"%s\" enabled."), $tmp['name']), 'horde.success'); break; } /* Save changes */ $ingo_storage->store($filters); try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); } break; case 'settings_save': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } $prefs->setValue('show_filter_msg', $this->vars->show_filter_msg); $prefs->setValue('filter_seen', $this->vars->filter_seen); $notification->push(_("Settings successfully updated."), 'horde.success'); break; case 'apply_filters': $factory->perform(); break; } /* Get the list of rules now. */ $filter_list = $filters->getFilterList(); /* Common URLs. */ $filters_url = $this->_addToken(self::url()); $rule_url = Ingo_Basic_Rule::url(); $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/filters')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->canapply = $factory->canPerform(); $view->deleteallowed = $delete_allowed; $view->editallowed = $edit_allowed; $view->formurl = $filters_url; if (count($filter_list)) { $display = array(); $s_categories = $session->get('ingo', 'script_categories'); $view->can_copy = $edit_allowed && (($max_rules = $perms->hasAppPermission(Ingo_Perms::getPerm('max_rules'))) === true || $max_rules > count($filter_list)); foreach ($filter_list as $rule_number => $filter) { /* Non-display categories. */ if (!in_array($filter['action'], $s_categories)) { $display[$rule_number] = false; continue; } $copyurl = $delurl = $editurl = $name = null; $entry = array(); $url = $filters_url->copy()->add('rulenumber', $rule_number); switch ($filter['action']) { case Ingo_Storage::ACTION_BLACKLIST: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Blacklist::url(); $entry['filterimg'] = 'blacklist.png'; $name = _("Blacklist"); break; case Ingo_Storage::ACTION_WHITELIST: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Whitelist::url(); $entry['filterimg'] = 'whitelist.png'; $name = _("Whitelist"); break; case Ingo_Storage::ACTION_VACATION: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Vacation::url(); $entry['filterimg'] = 'vacation.png'; $name = _("Vacation"); break; case Ingo_Storage::ACTION_FORWARD: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Forward::url(); $entry['filterimg'] = 'forward.png'; $name = _("Forward"); break; case Ingo_Storage::ACTION_SPAM: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Spam::url(); $entry['filterimg'] = 'spam.png'; $name = _("Spam Filter"); break; default: if (!is_null($mbox_search)) { if ($mbox_search['exact']) { if (strcasecmp($filter['action-value'], $mbox_search['query']) !== 0) { continue 2; } } elseif (stripos($filter['action-value'], $mbox_search['query']) === false) { continue 2; } } $editurl = $rule_url->copy()->add(array('edit' => $rule_number)); $delurl = $url->copy()->add('actionID', 'rule_delete'); $copyurl = $url->copy()->add('actionID', 'rule_copy'); $name = $filter['name']; break; } /* Create description. */ if (!$edit_allowed) { $entry['descriplink'] = htmlspecialchars($name); } elseif (!empty($filter['conditions'])) { $entry['descriplink'] = Horde::linkTooltip($editurl, sprintf(_("Edit %s"), $name), null, null, null, $ingo_storage->ruleDescription($filter)) . htmlspecialchars($name) . '</a>'; } else { $entry['descriplink'] = Horde::link($editurl, sprintf(_("Edit %s"), $name)) . htmlspecialchars($name) . '</a>'; } /* Create delete link. */ if ($delete_allowed && !is_null($delurl)) { $entry['dellink'] = Horde::link($delurl, sprintf(_("Delete %s"), $name), null, null, "return window.confirm('" . addslashes(_("Are you sure you want to delete this rule?")) . "');"); } /* Create copy link. */ if ($view->can_copy && !is_null($copyurl)) { $entry['copylink'] = Horde::link($copyurl, sprintf(_("Copy %s"), $name)); } /* Create disable/enable link. */ if (empty($filter['disable'])) { $entry['disabled'] = true; if ($edit_allowed) { $entry['disablelink'] = Horde::link($url->copy()->add('actionID', 'rule_disable'), sprintf(_("Disable %s"), $name)); } } elseif ($edit_allowed) { $entry['enablelink'] = Horde::link($url->copy()->add('actionID', 'rule_enable'), sprintf(_("Enable %s"), $name)); } $display[$rule_number] = $entry; } $view->filter = $display; $view->mbox_search = $mbox_search; } if ($edit_allowed && is_null($mbox_search)) { if ($factory->hasFeature('on_demand')) { $view->settings = true; $view->flags = $prefs->getValue('filter_seen'); $view->show_filter_msg = $prefs->getValue('show_filter_msg'); } $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptPackage('Horde_Core_Script_Package_Sortable'); } $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('filters.js'); $topbar = $injector->getInstance('Horde_View_Topbar'); $topbar->search = true; $topbar->searchAction = self::url(); $topbar->searchLabel = _("Mailbox Search"); $topbar->searchParameters = array('actionID' => 'mbox_search', 'searchexact' => 0, 'page' => 'filters'); $this->header = _("Filter Rules"); $this->output = $view->render('filters'); }
/** * Additonal checks to do if this is a user-generated compose message. * * @param Horde_Mail_Rfc822_List $email The e-mail list to send to. * @param Horde_Mime_Headers $headers The object holding this message's * headers. * @param Horde_Mime_Part $message The object that contains the text * to send. * * @throws IMP_Compose_Exception */ protected function _prepSendMessageAssert(Horde_Mail_Rfc822_List $email, Horde_Mime_Headers $headers = null, Horde_Mime_Part $message = null) { global $injector; $email_count = count($email); $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if (!$imp_imap->accessCompose(IMP_Imap::ACCESS_COMPOSE_TIMELIMIT, $email_count)) { Horde::permissionDeniedError('imp', 'max_timelimit'); throw new IMP_Compose_Exception(sprintf(ngettext("You are not allowed to send messages to more than %d recipient within %d hours.", "You are not allowed to send messages to more than %d recipients within %d hours.", $imp_imap->max_compose_timelimit), $imp_imap->max_compose_timelimit, $injector->getInstance('IMP_Sentmail')->limit_period)); } /* Count recipients if necessary. We need to split email groups * because the group members count as separate recipients. */ if (!$imp_imap->accessCompose(IMP_Imap::ACCESS_COMPOSE_RECIPIENTS, $email_count)) { Horde::permissionDeniedError('imp', 'max_recipients'); throw new IMP_Compose_Exception(sprintf(ngettext("You are not allowed to send messages to more than %d recipient.", "You are not allowed to send messages to more than %d recipients.", $imp_imap->max_compose_recipients), $imp_imap->max_compose_recipients)); } /* Pass to hook to allow alteration of message details. */ if (!is_null($message)) { try { $injector->getInstance('Horde_Core_Hooks')->callHook('pre_sent', 'imp', array($message, $headers, $this)); } catch (Horde_Exception_HookNotSet $e) { } } }
$next_step = $data->cleanup(); } else { $notification->push(_("This file format is not supported."), 'horde.error'); $next_step = Horde_Data::IMPORT_FILE; } } } /* We have a final result set. */ if (is_array($next_step)) { /* Create a Mnemo storage instance. */ $memo_storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create($storage->get('target')); $max_memos = $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes'); $num_memos = Mnemo::countMemos(); foreach ($next_step as $row) { if ($max_memos !== true && $num_memos >= $max_memos) { Horde::permissionDeniedError('mnemo', 'max_notes', sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes'))); break; } /* Check if we need to convert from iCalendar data into an array. */ if ($row instanceof Horde_Icalendar_vnote) { $row = $storage->fromiCalendar($row); } foreach ($app_fields as $field => $null) { if (!isset($row[$field])) { $row[$field] = ''; } } /* Default the tags if there isn't one. */ if (empty($row['tags'])) { $row['tags'] = ''; }
} } /* 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': $time_fields[$field] = 'date'; break;
$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(); $notification->notify(array('listeners' => 'status')); $form->renderActive($form->getRenderer(), $vars, Horde::url('add.php'), 'post');
/** * Create this mailbox on the server. * * @param array $opts Additional options: * - special_use: (array) An array of special-use attributes to attempt * to add to the mailbox. * DEFAULT: NONE * - subscribe: (boolean) Override preference value of subscribe. * * @return boolean True on success. * @throws Horde_Exception */ public function create(array $opts = array()) { global $injector, $notification, $prefs; if ($this->exists) { return true; } $imp_imap = $this->imp_imap; /* Check permissions. */ if (!$imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX)) { Horde::permissionDeniedError('imp', 'create_mboxes', _("You are not allowed to create mailboxes.")); return false; } if (!$imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX)) { Horde::permissionDeniedError('imp', 'max_create_mboxes', sprintf(_("You are not allowed to create more than %d mailboxes."), $imp_imap->max_create_mboxes)); return false; } /* Special use flags. */ $special_use = isset($opts['special_use']) ? $opts['special_use'] : array(); /* Attempt to create the mailbox. */ try { $imp_imap->createMailbox($this->_mbox, array('special_use' => $special_use)); } catch (IMP_Imap_Exception $e) { if ($e->getCode() == $e::USEATTR) { unset($opts['special_use']); return $this->create($opts); } $e->notify(sprintf(_("The mailbox \"%s\" was not created. This is what the server said"), $this->display) . ': ' . $e->getMessage()); return false; } $notification->push(sprintf(_("The mailbox \"%s\" was successfully created."), $this->display), 'horde.success'); /* Subscribe, if requested. */ if (!isset($opts['subscribe']) && $prefs->getValue('subscribe') || !empty($opts['subscribe'])) { try { $imp_imap->subscribeMailbox($this->_mbox, true); } catch (IMP_Imap_Exception $e) { } } /* Update the mailbox tree. */ $injector->getInstance('IMP_Ftree')->insert($this->_mbox); return true; }
/** * Allows other Horde apps to post messages. * * The forum name is constructed by just the $forum_name variable under the * data root 'agora.forums.<app>'. It is up to the apps themselves to make * sure that the forum name is unique. * * If the forum does not exist, it will be automatically created by Agora. * * @access private * * @param string $scope The application which is posting this message. * @param string $forum_name The unique name for the forum. * @param string $callback A callback method of the specified application * that gets called to make sure that posting to * this forum is allowed. * @param array $params Any parameters for the forum message posting. * <pre> * message_id - An existing message to edit * message_parent_id - The ID of the parent message * title - Posting title * </pre> * @param string $url If specified, the form gets submitted to this URL * instead of the current page. * @param array $variables A hash with all variables of a submitted form * generated by this method. * * @return mixed Returns either the rendered Horde_Form for posting a message * or PEAR_Error object on error, or true in case of a * successful post. */ public function postMessage($scope, $forum_name, $callback, $params = array(), $url = null, $variables = null) { global $registry; /* Check if posting messages is allowed. */ $check = $registry->callByPackage($scope, $callback, array($forum_name)); if ($check instanceof PEAR_Error || !$check) { return ''; } /* Create a separate notification queue. */ $queue = Horde_Notification::singleton('agoraPostMessage'); $queue->attach('status'); /* Set up the forums object. */ $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope); /* Set up form variables. */ $vars = Horde_Variables::getDefaultVariables(); if (is_array($variables)) { foreach ($variables as $varname => $value) { $vars->add($varname, $value); } } $formname = $vars->get('formname'); /* Check if the forum exists and fetch the ID. */ $params['forum_id'] = $forums->getForumId($forum_name); if ($params['forum_id'] === null) { $vars->set('new_forum', $forum_name); } else { $vars->set('forum_id', $params['forum_id']); } /* Set up the messages control object. */ $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $params['forum_id']); if ($messages instanceof PEAR_Error) { $queue->push(_("Could not post the message: ") . $messages->getMessage(), 'horde.error'); Horde::startBuffer(); $queue->notify(array('listeners' => 'status')); return Horde::endBuffer(); } /* Check post permissions. */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { Horde::permissionDeniedError('agora', null); return PEAR::raiseError(sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id'])); } if (isset($params['message_id'])) { $message = $messages->getMessage($params['message_id']); if (!$formname) { $vars = new Horde_Variables($message); $vars->set('message_subject', $message['message_subject']); $vars->set('message_body', $message['body']); } $editing = true; } else { $editing = false; $params['message_id'] = null; } /* Set a default title if one not specified. */ if (!isset($params['title'])) { $params['title'] = $editing ? _("Edit Message") : _("Post a New Message"); } /* Get the form object. */ $form = $messages->getForm($vars, $params['title'], $editing, is_null($params['forum_id'])); /* Validate the form. */ if ($form->validate($vars)) { $form->getInfo($vars, $info); if (isset($info['new_forum'])) { $forum_info = $this->prepareFormData($scope, false, array('forum_name' => $info['new_forum']), $callback); if ($forum_info instanceof PEAR_Error) { return $forum_info; } $info['forum_id'] = $m_params['forum_id'] = $forums->saveForum($forum_info); $result = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $info['forum_id']); if ($result instanceof PEAR_Error) { return $result; } } /* Try and store this message and get back a new message_id */ $message_id = $messages->saveMessage($info); if ($message_id instanceof PEAR_Error) { $queue->push(_("Could not post the message: ") . $message_id->getMessage(), 'horde.error'); } else { $queue->push(_("Message posted."), 'horde.success'); $count = $messages->countMessages(); $registry->callByPackage($scope, $callback, array($forum_name, 'messages', $count)); Horde::startBuffer(); $queue->notify(array('listeners' => 'status')); return Horde::endBuffer(); } } /* Replying to a previous post? */ if (isset($params['message_parent_id']) && !$form->isSubmitted()) { $message = $messages->replyMessage($params['message_parent_id']); if (!$message instanceof PEAR_Error) { $vars->set('message_parent_id', $params['message_parent_id']); $vars->set('message_subject', $message['message_subject']); $vars->set('message_body', $message['body']); } else { /* Bad parent message id, offer to do a regular post. */ $vars->set('message_parent_id', ''); } } if (!$url) { $url = Horde::selfUrl(true, false, true); } Horde::startBuffer(); $form->renderActive(null, $vars, $url, 'post', null, false); return Horde::endBuffer(); }
/** * Save a new or update an existing event from the AJAX event detail view. * * Request parameters used: * - event: The event id. * - cal: The calendar id. * - targetcalendar: If moving events, the targetcalendar to move to. * - as_new: Save an existing event as a new event. * - recur_edit: If editing an instance of a recurring event series, * how to apply the edit [current|future|all]. * - rstart: If editing an instance of a recurring event series, * the original start datetime of this instance. * - rend: If editing an instance of a recurring event series, * the original ending datetime of this instance. * - sendupdates: Should updates be sent to attendees? * - cstart: Start time of the client cache. * - cend: End time of the client cache. */ public function saveEvent() { global $injector, $notification, $registry; $result = $this->_signedResponse($this->vars->targetcalendar); if (!($kronolith_driver = $this->_getDriver($this->vars->targetcalendar))) { return $result; } if ($this->vars->as_new) { unset($this->vars->event); } if (!$this->vars->event) { $perms = $injector->getInstance('Horde_Core_Perms'); if ($perms->hasAppPermission('max_events') !== true && $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) { Horde::permissionDeniedError('kronolith', 'max_events', sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events'))); return $result; } } if ($this->vars->event && $this->vars->cal && $this->vars->cal != $this->vars->targetcalendar) { if (strpos($kronolith_driver->calendar, '\\')) { list($target, $user) = explode('\\', $kronolith_driver->calendar, 2); } else { $target = $kronolith_driver->calendar; $user = $registry->getAuth(); } $kronolith_driver = $this->_getDriver($this->vars->cal); // Only delete the event from the source calendar if this user has // permissions to do so. try { $sourceShare = Kronolith::getInternalCalendar($kronolith_driver->calendar); $share = Kronolith::getInternalCalendar($target); if ($sourceShare->hasPermission($registry->getAuth(), Horde_Perms::DELETE) && ($user == $registry->getAuth() && $share->hasPermission($registry->getAuth(), Horde_Perms::EDIT) || $user != $registry->getAuth() && $share->hasPermission($registry->getAuth(), Kronolith::PERMS_DELEGATE))) { $kronolith_driver->move($this->vars->event, $target); $kronolith_driver = $this->_getDriver($this->vars->targetcalendar); } } catch (Exception $e) { $notification->push(sprintf(_("There was an error moving the event: %s"), $e->getMessage()), 'horde.error'); return $result; } } if ($this->vars->as_new) { $event = $kronolith_driver->getEvent(); } else { try { // Note that when this is a new event, $this->vars->event will // be empty, so this will create a new event. $event = $kronolith_driver->getEvent($this->vars->event); } catch (Horde_Exception_NotFound $e) { $notification->push(_("The requested event was not found."), 'horde.error'); return $result; } catch (Exception $e) { $notification->push($e); return $result; } } if (!$event->hasPermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit this event."), 'horde.warning'); return $result; } $removed_attendees = $old_attendees = array(); if ($this->vars->recur_edit && $this->vars->recur_edit != 'all') { switch ($this->vars->recur_edit) { case 'current': $attributes = new stdClass(); $attributes->rstart = $this->vars->rstart; $attributes->rend = $this->vars->rend; $this->_addException($event, $attributes); // Create a copy of the original event so we can read in the // new form values for the exception. We also MUST reset the // recurrence property even though we won't be using it, since // clone() does not do a deep copy. Otherwise, the original // event's recurrence will become corrupt. $newEvent = clone $event; $newEvent->recurrence = new Horde_Date_Recurrence($event->start); $newEvent->readForm($event); // Create an exception event from the new properties. $exception = $this->_copyEvent($event, $newEvent, $attributes); $exception->start = $newEvent->start; $exception->end = $newEvent->end; // Save the new exception. $attributes->cstart = $this->vars->cstart; $attributes->cend = $this->vars->cend; $result = $this->_saveEvent($exception, $event, $attributes); break; case 'future': $instance = new Horde_Date($this->vars->rstart, $event->timezone); $exception = clone $instance; $exception->mday--; if ($event->end->compareDate($exception) > 0) { // Same as 'all' since this is the first recurrence. $this->vars->recur_edit = 'all'; return $this->saveEvent(); } else { $event->recurrence->setRecurEnd($exception); $newEvent = $kronolith_driver->getEvent(); $newEvent->readForm(); $newEvent->uid = null; $result = $this->_saveEvent($newEvent, $event, $this->vars, true); } } } else { try { $old_attendees = $event->attendees; $event->readForm(); $removed_attendees = array_diff(array_keys($old_attendees), array_keys($event->attendees)); $result = $this->_saveEvent($event); } catch (Exception $e) { $notification->push($e); return $result; } } if ($result !== true && $this->vars->sendupdates) { $type = $event->status == Kronolith::STATUS_CANCELLED ? Kronolith::ITIP_CANCEL : Kronolith::ITIP_REQUEST; Kronolith::sendITipNotifications($event, $notification, $type); } // Send a CANCEL iTip for attendees that have been removed, but only if // the entire event isn't being marked as cancelled (which would be // caught above). if (!empty($removed_attendees)) { $to_cancel = array(); foreach ($removed_attendees as $email) { $to_cancel[$email] = $old_attendees[$email]; } $cancelEvent = clone $event; Kronolith::sendITipNotifications($cancelEvent, $notification, Kronolith::ITIP_CANCEL, null, null, $to_cancel); } Kronolith::notifyOfResourceRejection($event); return $result; }
* Shoud we allow comments? */ switch ($profile['user_comments']) { case 'never': $allow_comments = false; $comments_reason = sprintf(_("User %s does not wish to be commented."), $user); break; case 'authenticated': $allow_comments = $GLOBALS['registry']->isAuthenticated(); if ($allow_comments) { if ($friends_driver->isBlacklisted($GLOBALS['registry']->getAuth())) { $allow_comments = false; $comments_reason = sprintf(_("You are on %s blacklist."), $user); } } else { Horde::permissionDeniedError('folks', null); $comments_reason = _("Only authenticated users can post comments."); } break; case 'friends': $allow_comments = $friends_driver->isFriend($GLOBALS['registry']->getAuth()); $comments_reason = _("Only authenticated users can post comments."); break; default: $allow_comments = true; if ($GLOBALS['registry']->isAuthenticated() && $friends_driver->isBlacklisted($GLOBALS['registry']->getAuth())) { $allow_comments = false; $comments_reason = sprintf(_("You are on %s blacklist."), $user); } break; }