From 4d9b77107e36141f8537dd9cdcf94bcae9a3abd0 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Fri, 7 Mar 2014 22:39:54 +0000
Subject: [PATCH] oops: Fix logic on auto response emails which resulted in
 auto response failing to send out.

---
 include/class.dept.php           | 6 ++++--
 include/staff/department.inc.php | 9 ++++-----
 include/staff/email.inc.php      | 8 ++++----
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/class.dept.php b/include/class.dept.php
index 38b372f8a..44bf6561e 100644
--- a/include/class.dept.php
+++ b/include/class.dept.php
@@ -152,9 +152,11 @@ class Dept {
 
     function getAutoRespEmail() {
 
-        if (!$this->autorespEmail && $this->ht['autoresp_email_id'])
-            if (!($this->autorespEmail = Email::lookup($this->ht['autoresp_email_id'])))
+        if (!$this->autorespEmail) {
+            if (!$this->ht['autoresp_email_id']
+                    || !($this->autorespEmail = Email::lookup($this->ht['autoresp_email_id'])))
                 $this->autorespEmail = $this->getEmail();
+        }
 
         return $this->autorespEmail;
     }
diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php
index c452cab26..2a001a403 100644
--- a/include/staff/department.inc.php
+++ b/include/staff/department.inc.php
@@ -86,7 +86,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
             </td>
             <td>
                 <select name="tpl_id">
-                    <option value="0">&mdash; System default &mdash;</option>
+                    <option value="0">&mdash; System Default &mdash;</option>
                     <?php
                     $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl WHERE isactive=1 ORDER by name';
                     if(($res=db_query($sql)) && db_num_rows($res)){
@@ -106,7 +106,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
             </td>
             <td>
                 <select name="sla_id">
-                    <option value="0">&mdash; System default &mdash;</option>
+                    <option value="0">&mdash; System Default &mdash;</option>
                     <?php
                     if($slas=SLA::getSLAs()) {
                         foreach($slas as $id =>$name) {
@@ -176,12 +176,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
         </tr>
         <tr>
             <td width="180">
-                Auto Response Email:
+                Auto-Response Email:
             </td>
             <td>
                 <select name="autoresp_email_id">
-                    <option value=""  disabled="disabled">Select Outgoing  Email</option>
-                    <option value="0">&mdash; Department Email (Above) &mdash;</option>
+                    <option value="0" selected="selected">&mdash; Department Email &mdash;</option>
                     <?php
                     $sql='SELECT email_id,email,name FROM '.EMAIL_TABLE.' email ORDER by name';
                     if(($res=db_query($sql)) && db_num_rows($res)){
diff --git a/include/staff/email.inc.php b/include/staff/email.inc.php
index 33ddc72c1..193a53478 100644
--- a/include/staff/email.inc.php
+++ b/include/staff/email.inc.php
@@ -69,9 +69,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
             </td>
             <td>
                 <select name="priority_id">
-                    <option value="">&mdash; Select Priority &mdash;</option>
+                    <option value="0" selected="selected">&mdash; System Default &mdash;</option>
                     <?php
-                    $sql='SELECT priority_id,priority_desc FROM '.PRIORITY_TABLE.' pri ORDER by priority_urgency DESC';
+                    $sql='SELECT priority_id, priority_desc FROM '.PRIORITY_TABLE.' pri ORDER by priority_urgency DESC';
                     if(($res=db_query($sql)) && db_num_rows($res)){
                         while(list($id,$name)=db_fetch_row($res)){
                             $selected=($info['priority_id'] && $id==$info['priority_id'])?'selected="selected"':'';
@@ -89,9 +89,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
             </td>
             <td>
                 <select name="dept_id">
-                    <option value="">&mdash; Select Department &mdash;</option>
+                    <option value="0" selected="selected">&mdash; System Default &mdash;</option>
                     <?php
-                    $sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' dept ORDER by dept_name';
+                    $sql='SELECT dept_id, dept_name FROM '.DEPT_TABLE.' dept ORDER by dept_name';
                     if(($res=db_query($sql)) && db_num_rows($res)){
                         while(list($id,$name)=db_fetch_row($res)){
                             $selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':'';
-- 
GitLab