From bd9e9c546a35307595e0c7403ad9e8b471649244 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 18 Aug 2015 14:57:49 -0500
Subject: [PATCH] preview: Fix crash if the ticket has no thread

---
 include/staff/templates/ticket-preview.tmpl.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/staff/templates/ticket-preview.tmpl.php b/include/staff/templates/ticket-preview.tmpl.php
index 168847fc8..859bf0a89 100644
--- a/include/staff/templates/ticket-preview.tmpl.php
+++ b/include/staff/templates/ticket-preview.tmpl.php
@@ -8,6 +8,7 @@ $staff=$ticket->getStaff();
 $lock=$ticket->getLock();
 $role=$thisstaff->getRole($ticket->getDeptId());
 $error=$msg=$warn=null;
+$thread = $ticket->getThread();
 
 if($lock && $lock->getStaffId()==$thisstaff->getId())
     $warn.='&nbsp;<span class="Icon lockedTicket">'
@@ -34,12 +35,12 @@ echo '<ul class="tabs" id="ticket-preview">';
 echo '
         <li class="active"><a id="preview_tab" href="#preview"
             ><i class="icon-list-alt"></i>&nbsp;'.__('Ticket Summary').'</a></li>';
-if ($ticket->getThread()->getNumCollaborators()) {
+if ($thread && $thread->getNumCollaborators()) {
 echo sprintf('
         <li><a id="collab_tab" href="#collab"
             ><i class="icon-fixed-width icon-group
             faded"></i>&nbsp;'.__('Collaborators (%d)').'</a></li>',
-            $ticket->getThread()->getNumCollaborators());
+            $thread->getNumCollaborators());
 }
 echo '</ul>';
 echo '<div id="ticket-preview_container">';
@@ -121,7 +122,7 @@ echo '</div>'; // ticket preview content.
     <table border="0" cellspacing="" cellpadding="1">
         <colgroup><col style="min-width: 250px;"></col></colgroup>
         <?php
-        if (($collabs=$ticket->getThread()->getCollaborators())) {?>
+        if ($thread && ($collabs=$thread->getCollaborators())) {?>
         <?php
             foreach($collabs as $collab) {
                 echo sprintf('<tr><td %s><i class="icon-%s"></i>
@@ -141,7 +142,7 @@ echo '</div>'; // ticket preview content.
     echo sprintf('<span><a class="collaborators"
                             href="#tickets/%d/collaborators">%s</a></span>',
                             $ticket->getId(),
-                            $ticket->getThread()->getNumCollaborators()
+                            $thread && $thread->getNumCollaborators()
                                 ? __('Manage Collaborators') : __('Add Collaborator')
                                 );
     ?>
-- 
GitLab