/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory(Ingo_Storage::ACTION_WHITELIST, _("Whitelist")); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $whitelist = $ingo_storage->retrieve(Ingo_Storage::ACTION_WHITELIST); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': try { Ingo::updateListFilter($this->vars->whitelist, Ingo_Storage::ACTION_WHITELIST); $notification->push(_("Changes saved."), 'horde.success'); Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } break; } /* Get the whitelist rule. */ $wl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_WHITELIST); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/whitelist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('Text'); $view->disabled = !empty($wl_rule['disable']); $view->formurl = $this->_addToken(self::url()); $view->whitelist = implode("\n", $whitelist->getWhitelist()); $page_output->addScriptFile('whitelist.js'); $page_output->addInlineJsVars(array('IngoWhitelist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->title = _("Whitelist Edit"); $this->output = $view->render('whitelist'); }
/** */ protected function _init() { global $injector, $notification; /* Redirect if forward is not available. */ $this->_assertCategory(Ingo_Storage::ACTION_FORWARD, _("Forward")); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Get the forward object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $forward = $ingo_storage->retrieve(Ingo_Storage::ACTION_FORWARD); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $fwd_id = $filters->findRuleId(Ingo_Storage::ACTION_FORWARD); $fwd_rule = $filters->getRule($fwd_id); /* Build form. */ $form = new Ingo_Form_Forward($this->vars); /* Perform requested actions. Ingo_Form_Forward does token checking * for us. */ if ($form->validate($this->vars)) { $forward->setForwardAddresses($this->vars->addresses); $forward->setForwardKeep($this->vars->keep_copy == 'on'); try { $ingo_storage->store($forward); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $fwd_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $fwd_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($fwd_rule['disable']); /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->keep_copy = $forward->getForwardKeep(); $this->vars->addresses = implode("\n", $forward->getForwardAddresses()); } /* Set form title. */ $form_title = _("Forward"); if (!empty($fwd_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'forward'); $form->setTitle($form_title); $this->header = _("Forwards Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** * AJAX action: Re-sort the filters list. * * Variables used: * - sort: (string) JSON serialized sort list of rule IDs. * * @return boolean True on success. */ public function reSortFilters() { global $injector, $notification; if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); return false; } $storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $storage->retrieve(Ingo_Storage::ACTION_FILTERS); try { $filters->sort(json_decode($this->vars->sort)); $storage->store($filters); $notification->push(_("Rule sort saved successfully."), 'horde.success'); } catch (Ingo_Exception $e) { $notification->push(_("Rule sort not saved."), 'horde.error'); return false; } try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.warning'); } return true; }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_SPAM, _("Spam filtering")); /* Get the spam object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $spam = $ingo_storage->retrieve(Ingo_Storage::ACTION_SPAM); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $spam_id = $filters->findRuleId(Ingo_Storage::ACTION_SPAM); $spam_rule = $filters->getRule($spam_id); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Spam($this->vars); $renderer = new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))); /* Perform requested actions. Ingo_Form_Spam does token checking for * us .*/ if ($form->validate($this->vars)) { $success = false; try { $spam->setSpamFolder($this->validateMbox('folder')); $success = true; } catch (Horde_Exception $e) { $notification->push($e); } $spam->setSpamLevel($this->vars->level); try { $ingo_storage->store($spam); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $spam_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $spam_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($spam_rule['disable']); /* Set default values. */ $form->folder_var->type->setFolder($spam->getSpamFolder()); if (!$form->isSubmitted()) { $this->vars->level = $spam->getSpamLevel(); $this->vars->folder = $spam->getSpamFolder(); $this->vars->actionID = ''; } /* Set form title. */ $form_title = _("Spam Filtering"); if (!empty($spam_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'spam'); $form->setTitle($form_title); $this->header = _("Spam Filtering"); Horde::startBuffer(); $form->renderActive($renderer, $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_VACATION, _("Vacation")); /* Get vacation object and rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $vacation = $ingo_storage->retrieve(Ingo_Storage::ACTION_VACATION); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $vac_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION); $vac_rule = $filters->getRule($vac_id); /* Load libraries. */ if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Vacation($this->vars, '', null, $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_VACATION)->availableCategoryFeatures(Ingo_Storage::ACTION_VACATION)); /* Perform requested actions. Ingo_Form_Vacation does token checking * for us. */ if ($form->validate($this->vars)) { $form->getInfo($this->vars, $info); $vacation->setVacationAddresses(isset($info['addresses']) ? $info['addresses'] : ''); $vacation->setVacationDays($info['days']); $vacation->setVacationExcludes($info['excludes']); $vacation->setVacationIgnorelist($info['ignorelist'] == 'on'); $vacation->setVacationReason($info['reason']); $vacation->setVacationSubject($info['subject']); $vacation->setVacationStart($info['start']); $vacation->setVacationEnd($info['end']); try { $ingo_storage->store($vacation); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $vac_rule['disable'] = false; } elseif ($this->vars->get('submitbutton') == _("Save and Disable")) { $filters->ruleDisable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $vac_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($vac_rule['disable']); /* Make sure we have at least one address. */ if (!$vacation->getVacationAddresses()) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $addresses = implode("\n", $identity->getAll('from_addr')); /* Remove empty lines. */ $addresses = trim(preg_replace('/\\n+/', "\n", $addresses)); if (empty($addresses)) { $addresses = $GLOBALS['registry']->getAuth(); } $vacation->setVacationAddresses($addresses); } /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->set('addresses', implode("\n", $vacation->getVacationAddresses())); $this->vars->set('excludes', implode("\n", $vacation->getVacationExcludes())); $this->vars->set('ignorelist', $vacation->getVacationIgnorelist()); $this->vars->set('days', $vacation->getVacationDays()); $this->vars->set('subject', $vacation->getVacationSubject()); $this->vars->set('reason', $vacation->getVacationReason()); $this->vars->set('start', $vacation->getVacationStart()); $this->vars->set('end', $vacation->getVacationEnd()); $this->vars->set('start_year', $vacation->getVacationStartYear()); $this->vars->set('start_month', $vacation->getVacationStartMonth() - 1); $this->vars->set('start_day', $vacation->getVacationStartDay() - 1); $this->vars->set('end_year', $vacation->getVacationEndYear()); $this->vars->set('end_month', $vacation->getVacationEndMonth() - 1); $this->vars->set('end_day', $vacation->getVacationEndDay() - 1); } /* Set form title. */ $form_title = _("Vacation"); if (!empty($vac_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'vacation'); $form->setTitle($form_title); $this->header = _("Vacation Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory(Ingo_Storage::ACTION_BLACKLIST, _("Blacklist")); $ingo_script = $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_BLACKLIST); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $flagonly = $ingo_script && in_array(Ingo_Storage::ACTION_FLAGONLY, $ingo_script->availableActions()); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': switch ($this->vars->action) { case 'delete': $folder = ''; break; case 'mark': $folder = Ingo::BLACKLIST_MARKER; break; case 'folder': $folder = $this->validateMbox('actionvalue'); break; default: $folder = null; break; } if (!$flagonly && $folder == Ingo::BLACKLIST_MARKER) { $notification->push("Not supported by this script generator.", 'horde.error'); } else { try { $blacklist = Ingo::updateListFilter($this->vars->blacklist, Ingo_Storage::ACTION_BLACKLIST); $blacklist->setBlacklistFolder($folder); $ingo_storage->store($blacklist); $notification->push(_("Changes saved."), 'horde.success'); Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), $e->getCode()); } } break; } /* Get the blacklist object. */ if (!isset($blacklist)) { try { $blacklist = $ingo_storage->retrieve(Ingo_Storage::ACTION_BLACKLIST); } catch (Ingo_Exception $e) { $notification->push($e); $blacklist = new Ingo_Storage_Blacklist(); } } /* Create the folder listing. */ $blacklist_folder = $blacklist->getBlacklistFolder(); $folder_list = Ingo_Flist::select($blacklist_folder, 'actionvalue'); /* Get the blacklist rule. */ $bl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_BLACKLIST); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/blacklist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->blacklist = implode("\n", $blacklist->getBlacklist()); $view->disabled = !empty($bl_rule['disable']); $view->flagonly = $flagonly; $view->folder = $blacklist_folder; $view->folderlist = $folder_list; $view->formurl = $this->_addToken(self::url()); $page_output->addScriptFile('blacklist.js'); $page_output->addInlineJsVars(array('IngoBlacklist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = _("Blacklist Edit"); $this->output = $view->render('blacklist'); }
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; /* Check rule permissions. */ $max = $injector->getInstance('Horde_Core_Perms')->hasAppPermission(Ingo_Perms::getPerm('max_rules')); if ($max === 0) { Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom 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 = $injector->getInstance('Ingo_Factory_Script')->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']; /* Get the current rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); if ($this->_assertMaxRules($max, $filters)) { Ingo_Basic_Filters::url()->redirect(); } /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ if (isset($this->vars->action)) { $rule = array('action' => $this->vars->action, 'combine' => $this->vars->combine, 'conditions' => array(), 'flags' => 0, 'id' => $this->vars->id, 'name' => $this->vars->name, 'stop' => $this->vars->stop); } else { $rule = isset($this->vars->edit) ? $filters->getRule($this->vars->edit) : $filters->getDefaultRule(); } 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_Storage::TYPE_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Storage::TYPE_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] : ''; } $rule['conditions'][] = $condition; } if ($this->vars->action) { switch ($ingo_storage->getActionInfo($this->vars->action)->type) { case 'folder': if ($actionID == 'rule_save') { try { $rule['action-value'] = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } } else { $rule['action-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; default: $rule['action-value'] = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; foreach ($flags as $val) { $rule['flags'] |= $val; } /* 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; } if (!isset($this->vars->edit)) { if ($this->_assertMaxRules($max, $filters)) { break; } $filters->addRule($rule); } else { $filters->updateRule($rule, $this->vars->edit); } $ingo_storage->store($filters); $notification->push(_("Changes saved."), 'horde.success'); try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { unset($rule['conditions'][intval($this->vars->conditionnumber)]); $rule['conditions'] = array_values($rule['conditions']); } 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_Storage::TYPE_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' => $ingo_storage->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 = $ingo_storage->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(); $current_action = false; foreach ($availActions as $val) { $action = $ingo_storage->getActionInfo($val); $actions[] = array('label' => $action->label, 'selected' => $val == $rule['action'], 'value' => $val); if ($val == $rule['action']) { $current_action = $action; } } $view->actions = $actions; /* Get the action value output. */ if ($current_action) { switch ($current_action->type) { case 'folder': $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule['action-value']); break; case 'text': case 'int': $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule['action-value']) . '" />'; break; } $view->flags = $current_action->flags && $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'); }
/** * Disable vacation * * @throws Ingo_Exception */ public function disableVacation() { /* Get vacation filter. */ $ingo_storage = $GLOBALS['injector']->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $vacation_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION); $filters->ruleDisable($vacation_id); $ingo_storage->store($filters); Ingo_Script_Util::update(); }
/** */ 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'); }