From cd836235415f07a4d425c8a255957c0742d64dec Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 7 Feb 2014 13:44:45 -0600
Subject: [PATCH] staff ticket: Auto select singular help topic

If the system has only one help topic automatically select the help topic
and display any associated custom form.
---
 include/staff/ticket-open.inc.php | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index aa15ff449..fa4b0ee15 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -117,12 +117,21 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
                         $('#dynamic-form').load(
                             'ajax.php/form/help-topic/' + this.value);
                         ">
-                    <option value="" selected >&mdash; Select Help Topic &mdash;</option>
                     <?php
-                    if($topics=Topic::getHelpTopics()) {
+                    if ($topics=Topic::getHelpTopics()) {
+                        if (count($topics) == 1)
+                            $selected = 'selected="selected"';
+                        else { ?>
+                <option value="" selected >&mdash; Select Help Topic &mdash;</option>
+<?php                   }
                         foreach($topics as $id =>$name) {
-                            echo sprintf('<option value="%d" %s>%s</option>',
-                                    $id, ($info['topicId']==$id)?'selected="selected"':'',$name);
+                            echo sprintf('<option value="%d" %s %s>%s</option>',
+                                $id, ($info['topicId']==$id)?'selected="selected"':'',
+                                $selected, $name);
+                        }
+                        if (count($topics) == 1 && !$form) {
+                            $T = Topic::lookup($id);
+                            $form = DynamicForm::lookup($T->ht['form_id']);
                         }
                     }
                     ?>
-- 
GitLab