From de2668c655f478359abcf722b3250ceafc7bf7b4 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Sun, 27 May 2012 19:39:43 -0400
Subject: [PATCH] Add ticket PDF export (print view)

---
 include/class.ticket.php | 8 ++++++--
 scp/tickets.php          | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 130ccb6fa..59994470c 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -22,6 +22,7 @@ include_once(INCLUDE_DIR.'class.topic.php');
 include_once(INCLUDE_DIR.'class.lock.php');
 include_once(INCLUDE_DIR.'class.file.php');
 include_once(INCLUDE_DIR.'class.attachment.php');
+include_once(INCLUDE_DIR.'class.pdf.php');
 include_once(INCLUDE_DIR.'class.banlist.php');
 include_once(INCLUDE_DIR.'class.template.php');
 include_once(INCLUDE_DIR.'class.priority.php');
@@ -1551,8 +1552,11 @@ class Ticket{
     }
 
     //Print ticket... export the ticket thread as PDF.
-    function exportPDF() {
-        return false;
+    function pdfExport() {
+        $pdf = new Ticket2PDF($this, true);
+        $name='Ticket-'.$this->getExtId().'.pdf';
+        $pdf->output($name, 'I');
+        exit;
     }
 
     //online based attached files.
diff --git a/scp/tickets.php b/scp/tickets.php
index 6f40db445..801fe2425 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -464,8 +464,8 @@ if($ticket) {
     $inc = 'ticket-view.inc.php';
     if($_REQUEST['a']=='edit' && $thisstaff->canEditTickets()) 
         $inc = 'ticket-edit.inc.php';
-    elseif($_REQUEST['a'] == 'print' && !$ticket->exportPDF())
-        $errors['err'] = 'Internal error: Unable to export the ticket to PDF.';
+    elseif($_REQUEST['a'] == 'print' && !$ticket->pdfExport())
+        $errors['err'] = 'Internal error: Unable to export the ticket to PDF for print.';
 } else {
     $inc = 'tickets.inc.php';
     if($_REQUEST['a']=='open' && $thisstaff->canCreateTickets())
-- 
GitLab