From c19e9d5eb039befa5f7b73ec3e5d44e69c73b54a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 10 Aug 2015 12:22:41 -0500
Subject: [PATCH] dept: Fix crash rendering list if no default email set

---
 include/staff/departments.inc.php |  2 +-
 include/staff/emails.inc.php      | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/staff/departments.inc.php b/include/staff/departments.inc.php
index 6e5f35c2b..6e3076fc9 100644
--- a/include/staff/departments.inc.php
+++ b/include/staff/departments.inc.php
@@ -91,7 +91,7 @@ $showing = $pageNav->showing().' '._N('department', 'departments', $count);
                 ->limit($pageNav->getLimit())
                 ->offset($pageNav->getStart());
             $defaultId=$cfg->getDefaultDeptId();
-            $defaultEmailId = $cfg->getDefaultEmail()->getId();
+            $defaultEmailId = $cfg->getDefaultEmailId();
             $defaultEmailAddress = (string) $cfg->getDefaultEmail();
             foreach ($depts as $dept) {
                 $id = $dept->getId();
diff --git a/include/staff/emails.inc.php b/include/staff/emails.inc.php
index a64186b5f..cad6b890a 100644
--- a/include/staff/emails.inc.php
+++ b/include/staff/emails.inc.php
@@ -89,7 +89,7 @@ $def_priority = $cfg->getDefaultPriority()->getDesc();
             foreach ($emails as $email) {
                 $id = $email->getId();
                 $sel=false;
-                if ($ids && in_array($email, $ids))
+                if ($ids && in_array($id, $ids))
                     $sel=true;
                 $default=($id==$defaultId);
                 ?>
@@ -97,11 +97,13 @@ $def_priority = $cfg->getDefaultPriority()->getDesc();
                 <td width=7px>
                   <input type="checkbox" class="ckb" name="ids[]"
                     value="<?php echo $id; ?>"
-                    <?php echo $sel ? 'checked="checked"' : ''; ?>
-                    <?php echo $default?'disabled="disabled"':''; ?>>
+                    <?php echo $sel ? 'checked="checked" ' : ''; ?>
+                    <?php echo $default?'disabled="disabled" ':''; ?>>
                 </td>
                 <td><span class="ltr"><a href="emails.php?id=<?php echo $id; ?>"><?php
-                    echo Format::htmlchars((string) $email); ?></a></span></td>
+                    echo Format::htmlchars((string) $email); ?></a></span>
+                <?php echo ($default) ?' <small>'.__('(Default)').'</small>' : ''; ?>
+                </td>
                 <td><?php echo $email->priority ?: $def_priority; ?></td>
                 <td><a href="departments.php?id=<?php $email->dept_id ?: $def_dept_id; ?>"><?php
                     echo $email->dept ?: $def_dept_name; ?></a></td>
-- 
GitLab