From 00a3be21b1175efb4b467405065f5d10158ccdef Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Wed, 1 Aug 2018 09:59:32 -0500
Subject: [PATCH] Help Topic Inline Save Fix:

This commit adds a validation for Help Topics that are saved using Inline Edit. In the event that a Ticket has a disabled Help Topic assigned to it, we want to display the name of the Help Topic, but we want to make sure that value cannot be saved.

In addition, it makes sure that if the Help Topic is disabled, it is the only disabled Help Topic that shows up in the list.
---
 include/class.ticket.php | 8 ++++++--
 include/class.topic.php  | 5 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 49513b52d..4a84e7757 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1006,12 +1006,16 @@ implements RestrictedAccess, Threadable, Searchable {
                         ));
             break;
         case 'topic':
+            $current = array();
+            if ($topic = $this->getTopic())
+                $current = array($topic->getId());
+            $choices = Topic::getHelpTopics(false, $topic ? (Topic::DISPLAY_DISABLED) : false, true, $current);
             return ChoiceField::init(array(
                         'id' => $fid,
                         'name' => "{$fid}_id",
                         'label' => __('Help Topic'),
                         'default' => $this->getTopicId(),
-                        'choices' => Topic::getHelpTopics(false, Topic::DISPLAY_DISABLED)
+                        'choices' => $choices
                         ));
             break;
         case 'source':
@@ -3338,7 +3342,7 @@ implements RestrictedAccess, Threadable, Searchable {
                     }
                 }
 
-                if (!$this->save())
+                if (!$errors && !$this->save())
                     $errors['field'] =  __('Unable to update field');
             }
         }
diff --git a/include/class.topic.php b/include/class.topic.php
index 8ef9de212..75c06b7df 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -329,7 +329,7 @@ implements TemplateVariable, Searchable {
             $this->flags &= ~$flag;
     }
 
-    static function getHelpTopics($publicOnly=false, $disabled=false, $localize=true) {
+    static function getHelpTopics($publicOnly=false, $disabled=false, $localize=true, $whitelist=array()) {
       global $cfg;
       static $topics, $names = array();
 
@@ -385,7 +385,8 @@ implements TemplateVariable, Searchable {
           $info = $topics[$id];
           if ($publicOnly && !$info['public'])
               continue;
-          if (!$disabled && $info['disabled'])
+          //if topic is disabled + we're not getting all topics OR topic is not in whitelist
+          if ($info['disabled'] && (!$disabled || ($whitelist && !in_array($id, $whitelist))))
               continue;
           if ($disabled === self::DISPLAY_DISABLED && $info['disabled'])
               $n .= " - ".__("(disabled)");
-- 
GitLab