From cb57dbc5015ec8c4225755bf550cbc98eae4baf3 Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Tue, 6 Jun 2017 13:41:54 -0500
Subject: [PATCH] bug fixes v2

---
 include/class.report.php | 23 ++++++++++++++++++++---
 include/class.staff.php  |  2 +-
 include/class.topic.php  |  2 +-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/include/class.report.php b/include/class.report.php
index d65fd1cc5..060112304 100644
--- a/include/class.report.php
+++ b/include/class.report.php
@@ -192,7 +192,7 @@ class OverviewReport {
             $pk = 'dept_id';
             $stats = $stats
                 ->filter(array('dept_id__in' => $thisstaff->getDepts()))
-                ->values('dept__id', 'dept__name');
+                ->values('dept__id', 'dept__name', 'dept__flags');
             $times = $times
                 ->filter(array('dept_id__in' => $thisstaff->getDepts()))
                 ->values('dept__id');
@@ -202,7 +202,7 @@ class OverviewReport {
             $header = function($row) { return Topic::getLocalNameById($row['topic_id'], $row['topic__topic']); };
             $pk = 'topic_id';
             $stats = $stats
-                ->values('topic_id', 'topic__topic')
+                ->values('topic_id', 'topic__topic', 'topic__flags')
                 ->filter(array('topic_id__gt' => 0));
             $times = $times
                 ->values('topic_id')
@@ -237,8 +237,25 @@ class OverviewReport {
 
         $rows = array();
         foreach ($stats as $R) {
+          if (isset($R['dept__flags'])) {
+            if ($R['dept__flags'] & Dept::FLAG_ARCHIVED)
+              $status = ' - '.__('Archived');
+            elseif ($R['dept__flags'] & Dept::FLAG_ACTIVE)
+              $status = '';
+            else
+              $status = ' - '.__('Disabled');
+          }
+          if (isset($R['topic__flags'])) {
+            if ($R['topic__flags'] & Topic::FLAG_ARCHIVED)
+              $status = ' - '.__('Archived');
+            elseif ($R['topic__flags'] & Topic::FLAG_ACTIVE)
+              $status = '';
+            else
+              $status = ' - '.__('Disabled');
+          }
+
             $T = $timings[$R[$pk]];
-            $rows[] = array($header($R), $R['Opened'], $R['Assigned'],
+            $rows[] = array($header($R) . $status, $R['Opened'], $R['Assigned'],
                 $R['Overdue'], $R['Closed'], $R['Reopened'],
                 number_format($T['ServiceTime'], 1),
                 number_format($T['ResponseTime'], 1));
diff --git a/include/class.staff.php b/include/class.staff.php
index 5fa529388..f5b08616d 100644
--- a/include/class.staff.php
+++ b/include/class.staff.php
@@ -1003,7 +1003,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
             $errors['role_id']=__('Role for primary department is required');
 
         $dept = Dept::lookup($vars['dept_id']);
-        if(!$dept->isActive())
+        if($dept && !$dept->isActive())
           $errors['dept_id'] = sprintf(__('%s selected must be active'), __('Department'));
 
         // Ensure we will still have an administrator with access
diff --git a/include/class.topic.php b/include/class.topic.php
index fd865acf9..39a03d4df 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -418,7 +418,7 @@ implements TemplateVariable {
             $errors['topic']=__('Topic already exists');
 
           $dept = Dept::lookup($vars['dept_id']);
-          if(!$dept->isActive())
+          if($dept && !$dept->isActive())
             $errors['dept_id'] = sprintf(__('%s selected must be active'), __('Department'));
 
         if (!is_numeric($vars['dept_id']))
-- 
GitLab