From 1d9f4dafd2321befd01fcf134640c83a5ae9dab4 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 14 Aug 2014 12:30:01 -0500
Subject: [PATCH] oops: Allow filter to set help topic

---
 include/class.ticket.php | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index ab4fe10aa..d180fc262 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2309,16 +2309,6 @@ class Ticket {
                     $vars['email'], $filter->getName()));
         }
 
-        if ($vars['topicId'] && ($topic=Topic::lookup($vars['topicId']))) {
-            if ($topic_form = $topic->getForm()) {
-                $TF = $topic_form->getForm($vars);
-                $topic_form = $topic_form->instanciate();
-                $topic_form->setSource($vars);
-                if (!$TF->isValid($field_filter('topic')))
-                    $errors = array_merge($errors, $TF->errors());
-            }
-        }
-
         $id=0;
         $fields=array();
         $fields['message']  = array('type'=>'*',     'required'=>1, 'error'=>'Message required');
@@ -2344,9 +2334,6 @@ class Ticket {
         if(!Validator::process($fields, $vars, $errors) && !$errors['err'])
             $errors['err'] ='Missing or invalid data - check the errors and try again';
 
-        if ($vars['topicId'] && !$topic)
-            $errors['topicId'] = 'Invalid help topic selected';
-
         //Make sure the due date is valid
         if($vars['duedate']) {
             if(!$vars['time'] || strpos($vars['time'],':')===false)
@@ -2389,6 +2376,21 @@ class Ticket {
             }
         }
 
+        if ($vars['topicId']) {
+            if ($topic=Topic::lookup($vars['topicId'])) {
+                if ($topic_form = $topic->getForm()) {
+                    $TF = $topic_form->getForm($vars);
+                    $topic_form = $topic_form->instanciate();
+                    $topic_form->setSource($vars);
+                    if (!$TF->isValid($field_filter('topic')))
+                        $errors = array_merge($errors, $TF->errors());
+                }
+            }
+            else  {
+                $errors['topicId'] = 'Invalid help topic selected';
+            }
+        }
+
         // Any error above is fatal.
         if ($errors)
             return 0;
-- 
GitLab