Skip to content

Commit

Permalink
Refactor ticket related methods/utils to use thread model.
Browse files Browse the repository at this point in the history
  • Loading branch information
protich committed Mar 5, 2013
1 parent 22eb31a commit 304dff4
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 411 deletions.
27 changes: 15 additions & 12 deletions include/class.mailfetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ function createTicket($mid) {

$errors=array();
if($ticket) {
if(!($msgid=$ticket->postMessage($vars, 'Email')))
if(!($message=$ticket->postMessage($vars, 'Email')))
return false;

} elseif (($ticket=Ticket::create($vars, $errors, 'Email'))) {
$msgid = $ticket->getLastMsgId();
$message = $ticket->getLastMessage();
} else {
//Report success if the email was absolutely rejected.
if(isset($errors['errno']) && $errors['errno'] == 403)
Expand All @@ -421,19 +421,22 @@ function createTicket($mid) {
}

//Save attachments if any.
if($msgid
if($message
&& $ost->getConfig()->allowEmailAttachments()
&& ($struct = imap_fetchstructure($this->mbox, $mid))
&& $struct->parts
&& ($struct = imap_fetchstructure($this->mbox, $mid))
&& $struct->parts
&& ($attachments=$this->getAttachments($struct))) {

foreach($attachments as $a ) {
$file = array(
'name' => $a['name'],
'type' => $a['type'],
'data' => $this->decode(imap_fetchbody($this->mbox, $mid, $a['index']), $a['encoding'])
);
$ticket->importAttachments(array($file), $msgid, 'M');
$file = array('name' => $a['name'], 'type' => $a['type']);

//Check the file type
if(!$ost->isFileTypeAllowed($file))
$file['error'] = 'Invalid file type (ext) for '.Format::htmlchars($file['name']);
else //only fetch the body if necessary TODO: Make it a callback.
$file['data'] = $this->decode(imap_fetchbody($this->mbox, $mid, $a['index']), $a['encoding']);

$message->importAttachment($file);
}
}

Expand Down
31 changes: 18 additions & 13 deletions include/class.pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class.pdf.php

class Ticket2PDF extends FPDF
{

var $includenotes = false;

var $pageOffset = 0;

var $ticket = null;

function Ticket2PDF($ticket, $psize='Letter', $notes=false) {
Expand All @@ -47,7 +47,7 @@ function Ticket2PDF($ticket, $psize='Letter', $notes=false) {
function getTicket() {
return $this->ticket;
}

//report header...most stuff are hard coded for now...
function Header() {
global $cfg;
Expand All @@ -66,7 +66,7 @@ function Header() {
$this->Cell(0, 5, 'Date & Time based on GMT '.$_SESSION['TZ_OFFSET'], 0, 1, 'R');
$this->Ln(10);
}

//Page footer baby
function Footer() {
global $thisstaff;
Expand Down Expand Up @@ -94,10 +94,10 @@ function _utf8($text) {

if(function_exists('iconv'))
return iconv('UTF-8', 'windows-1252', $text);

return utf8_encode($text);
}

function _print() {

if(!($ticket=$this->getTicket()))
Expand All @@ -107,7 +107,7 @@ function _print() {
$l = 35;
$c = $w-$l;


$this->SetFont('Arial', 'B', 11);
$this->cMargin = 0;
$this->SetFont('Arial', 'B', 11);
Expand Down Expand Up @@ -215,7 +215,11 @@ function _print() {
'R'=>array(255, 224, 179),
'N'=>array(250, 250, 210));
//Get ticket thread
if(($entries = $ticket->getThread(($this->includenotes)))) {
$types = array('M', 'R');
if($this->includenotes)
$types[] = 'N';

if(($entries = $ticket->getThreadEntries($types))) {
foreach($entries as $entry) {

$color = $colors[$entry['thread_type']];
Expand All @@ -228,18 +232,19 @@ function _print() {
$this->Cell($w/2, 7, $entry['poster'], 'TBR', 1, 'L', true);
$this->SetFont('');
$text= $entry['body'];
if($entry['attachments']
&& ($attachments = $ticket->getAttachments($entry['id'], $entry['thread_type']))) {
if($entry['attachments']
&& ($tentry=$ticket->getThreadEntry($entry['id']))
&& ($attachments = $tentry->getAttachments())) {
foreach($attachments as $attachment)
$files[]= $attachment['name'];

$text.="\nFiles Attached: [".implode(', ',$files)."]\n";
}
$this->WriteText($w*2, $text, 1);
$this->Ln(5);
}
}

}
}
}
?>
Loading

0 comments on commit 304dff4

Please sign in to comment.