diff --git a/include/class.filter.php b/include/class.filter.php index 60431d55c01045cc72679c77237dddf09ab86165..e53edf9b2660e7357c4fdbb801c96a1b649f848c 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -566,11 +566,47 @@ class Filter { 'sort' => (int) $sort, )); $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; + } + } + $I->save(); break; case 'I': # existing filter action if ($I = FilterAction::lookup($info)) { $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; + } + } + $I->sort = (int) $sort; $I->save(); } diff --git a/include/class.filter_action.php b/include/class.filter_action.php index 22a8a14e770cdcdccf2220b5469b7d03ca4b7eae..00be2a86011aacf0b5f2bed4b5804adcbe3fdb79 100644 --- a/include/class.filter_action.php +++ b/include/class.filter_action.php @@ -295,12 +295,17 @@ class FA_RouteDepartment extends TriggerAction { } function getConfigurationOptions() { + $depts = Dept::getDepartments(null, true, false); + return array( - 'dept_id' => new DepartmentField(array( - 'configuration' => array( - 'prompt' => __('Unchanged'), - 'data' => array('quick-add' => 'department'), - ), + 'dept_id' => new ChoiceField(array( + 'configuration' => array( + 'prompt' => __('Unchanged'), + 'data' => array('quick-add' => 'department'), + ), + 'choices' => + $depts + + array(':new:' => '— '.__('Add New').' —'), 'validators' => function($self, $clean) { if ($clean === ':new:') $self->addError(__('Select a department')); @@ -429,7 +434,8 @@ class FA_AssignTopic extends TriggerAction { } function getConfigurationOptions() { - $choices = Topic::getHelpTopics(false, Topic::DISPLAY_DISABLED); + $choices = Topic::getHelpTopics(false, false); + return array( 'topic_id' => new ChoiceField(array( 'configuration' => array('prompt' => __('Unchanged')), diff --git a/include/class.forms.php b/include/class.forms.php index 3278a128a872d7167820f3466bd83d5653c99548..d5ba6a0b053f9efd2ff89dced1a03739165bebb1 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2356,12 +2356,9 @@ class DepartmentField extends ChoiceField { global $cfg; $selected = self::getWidget(); - if($selected && $selected->value) - { - if(is_array($selected->value)) - { - foreach ($selected->value as $k => $v) - { + if($selected && $selected->value) { + if(is_array($selected->value)) { + foreach ($selected->value as $k => $v) { $current_id = $k; $current_name = $v; } @@ -2380,8 +2377,7 @@ class DepartmentField extends ChoiceField { ->values('id', 'name'); $choices = array(); - if ($depts = Dept::getDepartments(null, true, Dept::DISPLAY_DISABLED)) - { + if ($depts = Dept::getDepartments(null, true, Dept::DISPLAY_DISABLED)) { //create array w/queryset $active = array(); foreach ($active_depts as $dept) @@ -2391,8 +2387,7 @@ class DepartmentField extends ChoiceField { $active[$current_id] = $current_name; - foreach ($depts as $id => $name) - { + foreach ($depts as $id => $name) { $choices[$id] = $name; if(!array_key_exists($id, $active) && $current_id) unset($choices[$id]);