diff --git a/include/class.dept.php b/include/class.dept.php index c2963219944c0e3966a08c3ee234da661037b74f..7c07edabeb90aa969d2041c57e34bc675c9e5ea3 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -710,6 +710,12 @@ implements TemplateVariable { $this->setFlag(self::FLAG_ASSIGN_MEMBERS_ONLY, isset($vars['assign_members_only'])); $this->setFlag(self::FLAG_DISABLE_AUTO_CLAIM, isset($vars['disable_auto_claim'])); + $filter_actions = FilterAction::objects()->filter(array('type' => 'dept', 'configuration' => '{"dept_id":'. $this->getId().'}')); + if ($filter_actions && $vars['status'] == __('Active')) + FilterAction::setFilterFlag($filter_actions, 'dept', false); + else + FilterAction::setFilterFlag($filter_actions, 'dept', true); + switch ($vars['status']) { case __('Active'): diff --git a/include/class.filter.php b/include/class.filter.php index e53edf9b2660e7357c4fdbb801c96a1b649f848c..0ea5c4ab4036e4ad4b8ea21e0c0b4a8fe9ecf029 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -146,6 +146,8 @@ class Filter { $this->ht['flags'] |= $flag; else $this->ht['flags'] &= ~$flag; + $vars['rules']= $this->getRules(); + $this->update($this->ht, $errors); } function stopOnMatch() { @@ -350,7 +352,7 @@ class Filter { } function update($vars,&$errors) { - + $vars['flags'] = $this->ht['flags']; if(!Filter::save($this->getId(),$vars,$errors)) return false; @@ -544,6 +546,29 @@ class Filter { return count($errors) == 0; } + function validate_actions($action) { + + $config = json_decode($action->ht['configuration'], true); + if ($action->ht['type'] == 'dept') { + $dept = Dept::lookup($config['dept_id']); + if (!$dept || !$dept->isActive()) { + $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Department'); + return $errors; + } + } + + if ($action->ht['type'] == 'topic') { + $topic = Topic::lookup($config['topic_id']); + if (!$topic || !$topic->isActive()) { + $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Help Topic'); + return $errors; + } + } + + return false; + + } + function save_actions($id, $vars, &$errors) { if (!is_array(@$vars['actions'])) return; @@ -568,20 +593,10 @@ class Filter { $I->setConfiguration($errors, $vars); $config = json_decode($I->ht['configuration'], true); - if ($I->ht['type'] == 'dept') { - $dept = Dept::lookup($config['dept_id']); - if (!$dept || !$dept->isActive()) { - $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Department'); - continue; - } - } - - if ($I->ht['type'] == 'topic') { - $topic = Topic::lookup($config['topic_id']); - if (!$topic || !$topic->isActive()) { - $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Help Topic'); - continue; - } + $invalid = self::validate_actions($I); + if ($invalid) { + $errors['err'] = sprintf($invalid['err']); + return; } $I->save(); @@ -592,19 +607,10 @@ class Filter { $config = json_decode($I->ht['configuration'], true); - if ($I->ht['type'] == 'dept') { - $dept = Dept::lookup($config['dept_id']); - if (!$dept || !$dept->isActive()) { - $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Department'); - continue; - } - } - if ($I->ht['type'] == 'topic') { - $topic = Topic::lookup($config['topic_id']); - if (!$topic || !$topic->isActive()) { - $errors['err'] = sprintf(__('Unable to save: Please choose an active %s'), 'Help Topic'); - continue; - } + $invalid = self::validate_actions($I); + if ($invalid) { + $errors['err'] = sprintf($invalid['err']); + return; } $I->sort = (int) $sort; diff --git a/include/class.filter_action.php b/include/class.filter_action.php index 00be2a86011aacf0b5f2bed4b5804adcbe3fdb79..081e6d251e30901b3920ec053061483cd4e9aaae 100644 --- a/include/class.filter_action.php +++ b/include/class.filter_action.php @@ -78,6 +78,15 @@ class FilterAction extends VerySimpleModel { return $this->_impl; } + function setFilterFlag($actions, $flag, $bool) { + $errors = array(); + foreach ($actions as $action) { + $filter = Filter::lookup($action->filter_id); + if ($flag == 'dept') $filter->setFlag(Filter::FLAG_INACTIVE_DEPT, $bool); + if ($flag == 'topic') $filter->setFlag(Filter::FLAG_INACTIVE_HT, $bool); + } + } + function apply(&$ticket, array $info) { return $this->getImpl()->apply($ticket, $info); } @@ -297,6 +306,13 @@ class FA_RouteDepartment extends TriggerAction { function getConfigurationOptions() { $depts = Dept::getDepartments(null, true, false); + if ($this->action->type == 'dept') { + $dept_id = json_decode($this->action->configuration, true); + $dept = Dept::lookup($dept_id['dept_id']); + if ($dept && !$dept->isActive()) + $depts[$dept->getId()] = $dept->getName(); + } + return array( 'dept_id' => new ChoiceField(array( 'configuration' => array( @@ -436,6 +452,13 @@ class FA_AssignTopic extends TriggerAction { function getConfigurationOptions() { $choices = Topic::getHelpTopics(false, false); + if ($this->action->type == 'topic') { + $topic_id = json_decode($this->action->configuration, true); + $topic = Topic::lookup($topic_id['topic_id']); + if ($topic && !$topic->isActive()) + $choices[$topic->getId()] = $topic->getName(); + } + return array( 'topic_id' => new ChoiceField(array( 'configuration' => array('prompt' => __('Unchanged')), diff --git a/include/class.topic.php b/include/class.topic.php index 75aa9180664aed39d8aa64c5edb5b8774dde7fde..5743cfa5a1ed718ad429bd03eda7841aaa34cf0d 100644 --- a/include/class.topic.php +++ b/include/class.topic.php @@ -459,6 +459,12 @@ implements TemplateVariable { $this->noautoresp = !!$vars['noautoresp']; $this->notes = Format::sanitize($vars['notes']); + $filter_actions = FilterAction::objects()->filter(array('type' => 'topic', 'configuration' => '{"topic_id":'. $this->getId().'}')); + if ($filter_actions && $vars['status'] == __('Active')) + FilterAction::setFilterFlag($filter_actions, 'topic', false); + else + FilterAction::setFilterFlag($filter_actions, 'topic', true); + switch ($vars['status']) { case __('Active'): diff --git a/include/staff/filters.inc.php b/include/staff/filters.inc.php index f758c5ebcf1209bef0f2229c9130061fd7aca9fe..7da5b73d318a285120c2f951300af495f19eaf1d 100644 --- a/include/staff/filters.inc.php +++ b/include/staff/filters.inc.php @@ -106,26 +106,6 @@ else $ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null; if($res && db_num_rows($res)): while ($row = db_fetch_array($res)) { - if ($row['topic']) { - $filter = Filter::lookup($row['id']); - if ($filter->ht['flags'] & !Filter::FLAG_INACTIVE_HT) { - $filter->setFlag(Filter::FLAG_INACTIVE_HT, true); - $vars = $filter->ht; - $vars['rules']= $filter->getRules(); - $filter->update($filter->ht, $errors); - } - } - - if ($row['dept']) { - $filter = Filter::lookup($row['id']); - if ($filter->ht['flags'] & !Filter::FLAG_INACTIVE_DEPT) { - $filter->setFlag(Filter::FLAG_INACTIVE_DEPT, true); - $vars = $filter->ht; - $vars['rules']= $filter->getRules(); - $filter->update($filter->ht, $errors); - } - } - $sel=false; if($ids && in_array($row['id'],$ids)) $sel=true; diff --git a/scp/filters.php b/scp/filters.php index 9f1a62da32fb5ee53fd7feeea81aa83202135d08..23bbe23e37ae0721eccbf43288dbfc6a77ab0e75 100644 --- a/scp/filters.php +++ b/scp/filters.php @@ -31,6 +31,8 @@ if($_POST){ if(!$filter){ $errors['err']=sprintf(__('%s: Unknown or invalid'), __('ticket filter')); }elseif($filter->update($_POST,$errors)){ + $filter->setFlag(Filter::FLAG_INACTIVE_DEPT, false); + $filter->setFlag(Filter::FLAG_INACTIVE_HT, false); $msg=sprintf(__('Successfully updated %s.'), __('this ticket filter')); }elseif(!$errors['err']){ $errors['err']=sprintf('%s %s',