From 63fda4a405af5ae3ab9a24cc51211c2718b50e61 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 3 Jun 2014 13:51:19 -0500
Subject: [PATCH] topics: Forbid setting disabled topic as default

---
 include/class.config.php               | 8 ++++++--
 include/class.topic.php                | 6 ++++--
 include/staff/settings-tickets.inc.php | 5 +++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/class.config.php b/include/class.config.php
index e886ad749..2cdce1351 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -931,7 +931,7 @@ class OsticketConfig extends Config {
 
         if($vars['enable_captcha']) {
             if (!extension_loaded('gd'))
-                $errors['enable_captcha']='The GD extension required';
+                $errors['enable_captcha']='The GD extension is required';
             elseif(!function_exists('imagepng'))
                 $errors['enable_captcha']='PNG support required for Image Captcha';
         }
@@ -957,7 +957,11 @@ class OsticketConfig extends Config {
                 $errors['max_staff_file_uploads']='Invalid selection. Must be less than '.$maxfileuploads;
         }
 
-
+        if ($vars['default_help_topic']
+                && ($T = Topic::lookup($vars['default_help_topic']))
+                && !$T->isActive()) {
+            $errors['default_help_topic'] = 'Default help topic must be set to active';
+        }
 
         if(!Validator::process($f, $vars, $errors) || $errors)
             return false;
diff --git a/include/class.topic.php b/include/class.topic.php
index 700072c13..930b1795d 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -23,6 +23,8 @@ class Topic {
     var $page;
     var $form;
 
+    const DISPLAY_DISABLED = 2;
+
     function Topic($id) {
         $this->id=0;
         $this->load($id);
@@ -250,8 +252,6 @@ class Topic {
                 $names[$id] = $name;
             }
         }
-        if ($disabled && !$publicOnly)
-            return $names;
 
         // Apply requested filters
         $requested_names = array();
@@ -261,6 +261,8 @@ class Topic {
                 continue;
             if (!$disabled && $info['disabled'])
                 continue;
+            if ($disabled === self::DISPLAY_DISABLED && $info['disabled'])
+                $n .= " &mdash; (disabled)";
             $requested_names[$id] = $n;
         }
 
diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php
index 3be8dd7d6..a7960a02b 100644
--- a/include/staff/settings-tickets.inc.php
+++ b/include/staff/settings-tickets.inc.php
@@ -68,12 +68,13 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
             <td>
                 <select name="default_help_topic">
                     <option value="0">&mdash; None &mdash;</option><?php
-                    $topics = Topic::getHelpTopics();
+                    $topics = Topic::getHelpTopics(false, Topic::DISPLAY_DISABLED);
                     while (list($id,$topic) = each($topics)) { ?>
                         <option value="<?php echo $id; ?>"<?php echo ($config['default_help_topic']==$id)?'selected':''; ?>><?php echo $topic; ?></option>
                     <?php
                     } ?>
-                </select>
+                </select><br/>
+                <span class="error"><?php echo $errors['default_help_topic']; ?></span>
             </td>
         </tr>
         <tr>
-- 
GitLab