From 3ee95510d0abfcf2f8f82e22a00c9456ba816dd5 Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Tue, 28 Aug 2018 10:58:41 -0500
Subject: [PATCH] Resolve PHP 7.2 Errors

---
 bootstrap.php                                        | 3 +++
 include/class.export.php                             | 4 ++--
 include/class.http.php                               | 2 +-
 include/class.nav.php                                | 4 ++--
 include/class.orm.php                                | 2 +-
 include/client/templates/thread-entries.tmpl.php     | 3 ++-
 include/pear/Mail/mimePart.php                       | 2 +-
 include/staff/profile.inc.php                        | 2 +-
 include/staff/templates/queue-subnavigation.tmpl.php | 2 +-
 include/staff/templates/thread-entries.tmpl.php      | 3 ++-
 10 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/bootstrap.php b/bootstrap.php
index 4b64227a8..2703395fa 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -314,6 +314,9 @@ define('INCLUDE_DIR',ROOT_DIR.'include/'); //Change this if include is moved out
 define('PEAR_DIR',INCLUDE_DIR.'pear/');
 define('SETUP_DIR',ROOT_DIR.'setup/');
 
+define('CLIENTINC_DIR',INCLUDE_DIR.'client/');
+define('STAFFINC_DIR',INCLUDE_DIR.'staff/');
+
 define('UPGRADE_DIR', INCLUDE_DIR.'upgrader/');
 define('I18N_DIR', INCLUDE_DIR.'i18n/');
 define('CLI_DIR', INCLUDE_DIR.'cli/');
diff --git a/include/class.export.php b/include/class.export.php
index 85f021328..4fc1bbf7b 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -26,8 +26,8 @@ class Export {
 
     static function dumpQuery($sql, $headers, $how='csv', $options=array()) {
         $exporters = array(
-            'csv' => CsvResultsExporter,
-            'json' => JsonResultsExporter
+            'csv' => 'CsvResultsExporter',
+            'json' => 'JsonResultsExporter'
         );
         $exp = new $exporters[$how]($sql, $headers, $options);
         return $exp->dump();
diff --git a/include/class.http.php b/include/class.http.php
index b8205f5c9..b008eb6a7 100644
--- a/include/class.http.php
+++ b/include/class.http.php
@@ -42,7 +42,7 @@ class Http {
         if ($charset)
             $ct .= "; charset=$charset";
         header($ct);
-        if ($content) {
+        if (is_string($content)) {
             header('Content-Length: '.strlen($content)."\r\n\r\n");
             print $content;
             exit;
diff --git a/include/class.nav.php b/include/class.nav.php
index 02abcc028..6cc44bd84 100644
--- a/include/class.nav.php
+++ b/include/class.nav.php
@@ -139,7 +139,7 @@ class StaffNav {
             $this->tabs['tickets'] = array('desc'=>__('Tickets'),'href'=>'tickets.php','title'=>__('Ticket Queue'));
 
             $this->tabs['kbase'] = array('desc'=>__('Knowledgebase'),'href'=>'kb.php','title'=>__('Knowledgebase'));
-            if (count($this->getRegisteredApps()))
+            if (!is_null($this->getRegisteredApps()))
                 $this->tabs['apps']=array('desc'=>__('Applications'),'href'=>'apps.php','title'=>__('Applications'));
         }
 
@@ -218,7 +218,7 @@ class AdminNav extends StaffNav{
             $tabs['manage']=array('desc'=>__('Manage'),'href'=>'helptopics.php','title'=>__('Manage Options'));
             $tabs['emails']=array('desc'=>__('Emails'),'href'=>'emails.php','title'=>__('Email Settings'));
             $tabs['staff']=array('desc'=>__('Agents'),'href'=>'staff.php','title'=>__('Manage Agents'));
-            if (count($this->getRegisteredApps()))
+            if (!is_null($this->getRegisteredApps()))
                 $tabs['apps']=array('desc'=>__('Applications'),'href'=>'apps.php','title'=>__('Applications'));
             $this->tabs=$tabs;
         }
diff --git a/include/class.orm.php b/include/class.orm.php
index 1325bbab7..45160c018 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -1715,7 +1715,7 @@ implements ArrayAccess {
         throw new Exception(__('QuerySet is read-only'));
     }
 
-    function count() {
+    function count($mode=COUNT_NORMAL) {
         $this->asArray();
         return count($this->storage);
     }
diff --git a/include/client/templates/thread-entries.tmpl.php b/include/client/templates/thread-entries.tmpl.php
index 938432109..f54fa4f6b 100644
--- a/include/client/templates/thread-entries.tmpl.php
+++ b/include/client/templates/thread-entries.tmpl.php
@@ -2,6 +2,7 @@
 $events = $events
     ->filter(array('state__in' => array('created', 'closed', 'reopened', 'edited', 'collab')))
     ->order_by('id');
+$eventCount = count($events);
 $events = new IteratorIterator($events->getIterator());
 $events->rewind();
 $event = $events->current();
@@ -50,7 +51,7 @@ while ($event) {
 }
 
 // This should never happen
-if (count($entries) + count($events) == 0) {
+if (count($entries) + $eventCount == 0) {
     echo '<p><em>'.__('No entries have been posted to this thread.').'</em></p>';
 }
 ?>
diff --git a/include/pear/Mail/mimePart.php b/include/pear/Mail/mimePart.php
index 6ac85a2f8..8588cd2b1 100644
--- a/include/pear/Mail/mimePart.php
+++ b/include/pear/Mail/mimePart.php
@@ -311,7 +311,7 @@ class Mail_mimePart
     {
         $encoded =& $this->encoded;
 
-        if (count($this->subparts)) {
+        if (!is_null($this->subparts)){
             $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
             $eol = $this->eol;
 
diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php
index 78bab30bf..a8a4a2a56 100644
--- a/include/staff/profile.inc.php
+++ b/include/staff/profile.inc.php
@@ -209,7 +209,7 @@ if ($avatar->isChangeable()) { ?>
 
                   foreach($options as $k=>$v) {
                       echo sprintf('<option value="%s" %s>%s</option>',
-                                $k,($staff->default_from_name==$k)?'selected="selected"':'',$v);
+                                $k,($staff->default_from_name && $staff->default_from_name==$k)?'selected="selected"':'',$v);
                   }
                   ?>
                 </select>
diff --git a/include/staff/templates/queue-subnavigation.tmpl.php b/include/staff/templates/queue-subnavigation.tmpl.php
index fa33b7b72..6fac6a5d0 100644
--- a/include/staff/templates/queue-subnavigation.tmpl.php
+++ b/include/staff/templates/queue-subnavigation.tmpl.php
@@ -3,7 +3,7 @@
 // $q - <CustomQueue> object for this navigation entry
 // $children - <Array<CustomQueue>> all direct children of this queue
 $queue = $q;
-$hasChildren = count($children) > 0;
+$hasChildren = $children && (count($children) > 0);
 $selected = $_REQUEST['queue'] == $q->getId();
 global $thisstaff;
 ?>
diff --git a/include/staff/templates/thread-entries.tmpl.php b/include/staff/templates/thread-entries.tmpl.php
index 9b267bbae..c32417cd5 100644
--- a/include/staff/templates/thread-entries.tmpl.php
+++ b/include/staff/templates/thread-entries.tmpl.php
@@ -10,6 +10,7 @@ $cmp = function ($a, $b) use ($sort) {
 };
 
 $events = $events->order_by($sort);
+$eventCount = count($events);
 $events = new IteratorIterator($events->getIterator());
 $events->rewind();
 $event = $events->current();
@@ -62,7 +63,7 @@ foreach (Attachment::objects()->filter(array(
         $event = $events->current();
     }
     // This should never happen
-    if (count($entries) + count($events) == 0) {
+    if (count($entries) + $eventCount == 0) {
         echo '<p><em>'.__('No entries have been posted to this thread.').'</em></p>';
     }
     ?>
-- 
GitLab