From 9c076fc518814595f8c0a3e5beba20d00d8f80ac Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Thu, 18 Apr 2019 13:43:26 -0500
Subject: [PATCH] Bug fixes and enhancements for v1.11

---
 include/class.orm.php        |  1 +
 include/staff/emails.inc.php |  4 ++--
 include/staff/staff.inc.php  |  1 +
 login.php                    | 14 ++++++++++----
 scp/profile.php              |  3 ++-
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index cd30ffa97..34564f111 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -2584,6 +2584,7 @@ class SqlCompiler {
             }
         }
         $glue = $Q->ored ? ' OR ' : ' AND ';
+        $filter = array_filter($filter);
         $clause = implode($glue, $filter);
         if (($Q->negated || $parens) && count($filter) > 1)
             $clause = '(' . $clause . ')';
diff --git a/include/staff/emails.inc.php b/include/staff/emails.inc.php
index 78c296ce2..c6f09c68f 100644
--- a/include/staff/emails.inc.php
+++ b/include/staff/emails.inc.php
@@ -36,8 +36,8 @@ $showing = $pageNav->showing().' '._N('email', 'emails', $count);
 $qstr = '&amp;order='.($order=='DESC' ? 'ASC' : 'DESC');
 
 $def_dept_id = $cfg->getDefaultDeptId();
-$def_dept_name = $cfg->getDefaultDept()->getName();
-$def_priority = $cfg->getDefaultPriority()->getDesc();
+$def_dept_name = ($d = $cfg->getDefaultDept()) ? $d->getName() : '';
+$def_priority = ($c = $cfg->getDefaultPriority()) ? $c->getDesc() : '';
 ?>
 <form action="emails.php" method="POST" name="emails">
     <div class="sticky bar opaque">
diff --git a/include/staff/staff.inc.php b/include/staff/staff.inc.php
index 217daa065..f51d8ecfe 100644
--- a/include/staff/staff.inc.php
+++ b/include/staff/staff.inc.php
@@ -538,6 +538,7 @@ foreach ($staff->dept_access as $dept_access) {
 }
 
 foreach ($staff->teams as $member) {
+  if (!$member->team) continue;
   echo sprintf('joinTeam(%d, %s, %d, %s);', $member->team_id,
     JsonDataEncoder::encode($member->team->getName()),
     $member->isAlertsEnabled(),
diff --git a/login.php b/login.php
index 5c4a71312..512465c0e 100644
--- a/login.php
+++ b/login.php
@@ -90,10 +90,16 @@ elseif ($_POST && isset($_POST['lticket'])) {
 
         // We're using authentication backend so we can guard aganist brute
         // force attempts (which doesn't buy much since the link is emailed)
-        $ticket->sendAccessLink($user);
-        $msg = sprintf(__("%s - access link sent to your email!"),
-            Format::htmlchars($user->getName()->getFirst()));
-        $_POST = null;
+        if ($ticket) {
+            $ticket->sendAccessLink($user);
+            $msg = sprintf(__("%s - access link sent to your email!"),
+                Format::htmlchars($user->getName()->getFirst()));
+            $_POST = null;
+        } else {
+            $errors['err'] = sprintf('%s - %s',
+                __('Invalid email or ticket number'),
+                __('Please try again!'));
+        }
     } elseif(!$errors['err']) {
         $errors['err'] = sprintf('%s - %s', __('Invalid email or ticket number'), __('Please try again!'));
     }
diff --git a/scp/profile.php b/scp/profile.php
index 0a46875e7..193aad58a 100644
--- a/scp/profile.php
+++ b/scp/profile.php
@@ -48,7 +48,8 @@ elseif($thisstaff->onVacation() && !$warn)
     $warn=sprintf(__("<b>Welcome back %s</b>! You are listed as 'on vacation' Please let your manager know that you are back."),$thisstaff->getFirstName());
 
 $inc='profile.inc.php';
-$nav->setTabActive('dashboard');
+if ($nav)
+    $nav->setTabActive('dashboard');
 $ost->addExtraHeader('<meta name="tip-namespace" content="dashboard.my_profile" />',
     "$('#content').data('tipNamespace', 'dashboard.my_profile');");
 require_once(STAFFINC_DIR.'header.inc.php');
-- 
GitLab