From cbcd02b0aa61595c2a163388052fa986ad72a325 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 1 Apr 2014 22:21:44 -0500
Subject: [PATCH] Add topic selection to email (channel) management

---
 include/class.email.php     |  7 +------
 include/staff/email.inc.php | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/include/class.email.php b/include/class.email.php
index 17c035328..5c0a51c59 100644
--- a/include/class.email.php
+++ b/include/class.email.php
@@ -341,17 +341,12 @@ class Email {
 
         if($errors) return false;
 
-        //Default to default priority and dept..
-        if(!$vars['priority_id'] && $cfg)
-            $vars['priority_id']=$cfg->getDefaultPriorityId();
-        if(!$vars['dept_id'] && $cfg)
-            $vars['dept_id']=$cfg->getDefaultDeptId();
-
         $sql='updated=NOW(),mail_errors=0, mail_lastfetch=NULL'.
              ',email='.db_input($vars['email']).
              ',name='.db_input(Format::striptags($vars['name'])).
              ',dept_id='.db_input($vars['dept_id']).
              ',priority_id='.db_input($vars['priority_id']).
+             ',topic_id='.db_input($vars['topic_id']).
              ',noautoresp='.db_input(isset($vars['noautoresp'])?1:0).
              ',userid='.db_input($vars['userid']).
              ',mail_active='.db_input($vars['mail_active']).
diff --git a/include/staff/email.inc.php b/include/staff/email.inc.php
index 193a53478..bd0acace9 100644
--- a/include/staff/email.inc.php
+++ b/include/staff/email.inc.php
@@ -63,6 +63,26 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
                 &nbsp;<span class="error">*&nbsp;<?php echo $errors['name']; ?>&nbsp;</span>
             </td>
         </tr>
+        <tr>
+            <td width="180">
+                New Ticket Help Topic
+            </td>
+            <td>
+                <select name="topic_id">
+                    <option value="0" selected="selected">&mdash; Empty &mdash;</option>
+                    <?php
+                    $sql='SELECT topic_id, topic FROM '.TOPIC_TABLE.' T ORDER by topic';
+                    if(($res=db_query($sql)) && db_num_rows($res)){
+                        while(list($id,$name)=db_fetch_row($res)){
+                            $selected=($info['topic_id'] && $id==$info['topic_id'])?'selected="selected"':'';
+                            echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name);
+                        }
+                    }
+                    ?>
+                </select>
+                &nbsp;<span class="error"><?php echo $errors['topic_id']; ?></span>
+            </td>
+        </tr>
         <tr>
             <td width="180">
                 New Ticket Priority
-- 
GitLab