Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > osTicket 1.6.x > Mods and Customizations

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2012, 09:42 PM
backspace backspace is offline
Member
 
Join Date: Jan 2012
Posts: 35
Smile [MOD] Email job history on close

First let me say this is just a work around and just a combination of post put together. I someone who has some php experience (more than the 1 week I have ) It would be nice to have this as a email template

Please back up everything before try this I have only 1 week experience with php

Find in class.ticket.php
PHP Code:
    function getName(){
        return 
$this->fullname;
    } 
Below that add (from http://www.osticket.com/forums/showt...MessageHistory )
PHP Code:
//MOD own function added for the added %history template substitution 
    
function getMessageHistory(){ 
        
// build an array of both messages and responses (conversion history = $c) 
        //$c = array[i][2]; 
        
$i 0// start from the beginning... 

        // first we get the messages 
        
$sql ='SELECT created, message FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.db_input($this->id); 

        if((
$res=db_query($sql)) && db_num_rows($res)) 
        { 
                while(
$row=db_fetch_array($res)) 
                { 
                        
$c[$i][0]=$row['created']; 
                        
$c[$i++][1]="Message: ".$row['message']; 
                } 
        } 

        
// then we get the response history 
        
$sql ='SELECT created, response FROM '.TICKET_RESPONSE_TABLE.' WHERE ticket_id='.db_input($this->id); 

        if((
$res=db_query($sql)) && db_num_rows($res)) 
        { 
                while(
$row=db_fetch_array($res)) 
                { 
                        
$c[$i][0]=$row['created']; 
                        
$c[$i++][1]="Response: ".$row['response']; 
                } 
        } 


        
// sort the array on the date field 

        // first we need to alter the arrays from rows to columns to make array_multisort work properly... 
        
foreach($c as $k => $r
        { 
                
$create[$k] = $r[0]; 
                
$text[$k] = $r[1]; 
        } 

        
// reorder the arrays in tandem... 
        
array_multisort($createSORT_ASC$text); 


        
// turn everything into a string and return it.. (we counted $i upwards the last time and it should contain the nr of elements...) 
        
$output=''
        for(
$x=0$x <= $i$x++) 
        { 
                
$output .= $create[$x].' - '.$text[$x]."\n"
                
$output .= "-----------------------------------------------------------------\n"
        } 

        return(
$output); 
    } 
    
// end modification 
Find
PHP Code:
Close the ticket
    
function close(){
       
       
$sql'UPDATE '.TICKET_TABLE.' SET status='.db_input('closed').',staff_id=0,isoverdue=0,duedate=NULL,updated=NOW(),closed=NOW() '.
              
' WHERE ticket_id='.db_input($this->getId());
        return (
db_query($sql) && db_affected_rows())?true:false;
    } 
Replace with (from http://www.osticket.com/forums/showp...43&postcount=8 )
PHP Code:
 // ALL CHANGES IN class.ticket.php 
    
function close(){ 

        
$sql'UPDATE '.TICKET_TABLE.' SET status='.db_input('closed').',staff_id=0,isoverdue=0,duedate=NULL,updated=NOW(),closed=NOW() '
              
' WHERE ticket_id='.db_input($this->getId()); 
// NEW MOD CODE STARTS HERE 

// get dept object 
$dept = new Dept($this->getDeptId()); 

// get email object for current   
$email = new Email($this->getEmail());  
// see if the department ticket is configured for is setup for auto response on 
// new tickets.  I have some departments I don't want notification on close 
// A new attribute could be used, but I piggy backed on an existing as it suited my needs fine for now. 
if ($dept->autoRespONNewTicket()) { 

  
// small debug message that prints at the top of ticket screen so I know an email was sent 
  
print "<b>Email Sent</b>"

  
// subject for email -- totally configurable. 
    
$subj"Helpdesk Request #[" .$this->getExtId(). "] has been closed.";  

  
// I added a link in the body to the ticket for the user if they wanted to view it just after I closed it. 
  
$body"This is a notification that Request#" .$this->getExtId(). " has been closed." .$this->getMessageHistory(). " You can see request information here: http://" $_SERVER["SERVER_NAME"] . "/job/view.php?e=" $this->getEmail() . "&t=" $this->getExtId() . "."

  
// this sends out the email ensuring the "From" address is whatever is configured for the department 
  
$dept->getEmail()->send($this->getEmail(),$subj,$body); 

// NEW MOD CODE ENDS HERE 
        
return (db_query($sql) && db_affected_rows())?true:false
    } 
add %history and $this->getMessageHistory()); to $search & $replace like below
PHP Code:
 $search = array('/%id/','/%ticket/','/%email/','/%name/','/%subject/','/%location/','/%machine/','/%topic/','/%phone/','/%status/','/%priority/',
                        
'/%dept/','/%assigned_staff/','/%createdate/','/%duedate/','/%closedate/','/%url/','/%history/');
        
$replace = array($this->getId(),
                         
$this->getExtId(),
                         
$this->getEmail(),
                         
$this->getName(),
                         
$this->getSubject(),
                         
$this->getHelpTopic(),
                         
$this->getPhoneNumber(),
                         
$this->getStatus(),
                         
$this->getPriority(),
                         (
$dept?$dept->getName():''),
                         (
$staff?$staff->getName():''),
                         
Format::db_daydatetime($this->getCreateDate()),
                         
Format::db_daydatetime($this->getDueDate()),
                         
Format::db_daydatetime($this->getCloseDate()),
                         
$cfg->getBaseUrl(),
                         
$this->getMessageHistory()); // added for %history 
        
return preg_replace($search,$replace,$text);
    } 
I think I have removed all my other mods so it should be standard but no guaranties

Hope this help and some one can use it make this into a template! But it works for now good luck
Reply With Quote
  #2  
Old 03-22-2012, 05:25 PM
backspace backspace is offline
Member
 
Join Date: Jan 2012
Posts: 35
Question Date not correct

There seams to be a problem with the date it is not emailing through the corrected date.

Can someone help me correct the date, this doesn't work
PHP Code:
 $c[$i][0]=$row['created']; 
 
//   $c[$i][0]=Format::db_daydatetime($row['created']) // doesn't work
 
$c[$i++][1]="Response: ".$row['response']; 
A little help is very much appreciated
Reply With Quote


Reply

Bookmarks

Tags
close, email, job history

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:56 AM.