Home Archives 2012 May

Monthly Archives: May 2012

We have recently installed osticket 1.6 for support ticket system.

One of the features that osTicket 1.6 does not have is the ability for the staffs to reply on a ticket thought email.

Think that you are on vacations and a customer creates a ticket that you receive on your smartphone and the answer is something that you can send it right away.

Well with a little hack this can be done so i am posting here the solution.
This technique only works if you enable piping.

on /api/pipe.php
osTicket 1.6 code Line 93


$ticket=null;
if(preg_match ("[[#][0-9]{1,10}]",$var['subject'],$regs)) {
$extid=trim(preg_replace("/[^0-9]/", "", $regs[0]));
$ticket= new Ticket(Ticket::getIdByExtId($extid));
//Allow mismatched emails?? For now hell NO.
if(!is_object($ticket) || strcasecmp($ticket->getEmail(),$var['email']))
$ticket=null;
}
$errors=array();
$msgid=0;
if(!$ticket){ //New tickets...
$ticket=Ticket::create($var,$errors,'email');
if(!is_object($ticket) || $errors){
api_exit(EX_DATAERR,'Ticket create Failed '.implode("n",$errors)."nn");
}
$msgid=$ticket->getLastMsgId();
}else{
$message=$var['message'];
//Strip quoted reply...TODO: figure out how mail clients do it without special tag..
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var['message'],$tag))
list($message)=split($tag,$var['message']);
//post message....postMessage does the cleanup.
if(!($msgid=$ticket->postMessage($message,'Email',$var['mid'],$var['header']))) {
api_exit(EX_DATAERR,"Unable to post message nn $messagen");
}
}

Replace with new code

$ticket=null;
$response_stuff=0;
$staff_id=0;
if(preg_match ("[[#][0-9]{1,10}]",$var['subject'],$regs)) {
$extid=trim(preg_replace("/[^0-9]/", "", $regs[0]));
$ticket= new Ticket(Ticket::getIdByExtId($extid));
//Allow mismatched emails?? For now hell NO.
if(!is_object($ticket) || strcasecmp($ticket->getEmail(),$var['email'])){
//$ticket=null;
$sql="SELECT username,staff_id FROM " . STAFF_TABLE . " WHERE email='" . $var['email'] . "' ";
$query=db_query($sql);
while($row = mysql_fetch_array($query)) {
$senderUsername = $row['username'];
$staff_id=$row['staff_id'];
}

if (!$senderUsername){
$ticket=null;
}
else
{
$response_stuff=1;
}
}
}
$errors=array();
$msgid=0;
if(!$ticket){ //New tickets…
$ticket=Ticket::create($var,$errors,’email’);
if(!is_object($ticket) || $errors){
api_exit(EX_DATAERR,’Ticket create Failed ‘.implode(“n”,$errors).”nn”);
}
$msgid=$ticket->getLastMsgId();
}else{
$message=$var['message'];
//Strip quoted reply…TODO: figure out how mail clients do it without special tag..
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var['message'],$tag))
list($message)=split($tag,$var['message']);
//post message….postMessage does the cleanup.
if($response_stuff==1){
if(!($ticket->postResponse($ticket->getMessageId(),$message,’none’,false,true,$staff_id))){
api_exit(EX_DATAERR,”Unable to post message nn $messagen”);
}
}
else
{
if(!($msgid=$ticket->postMessage($message,’Email’,$var['mid'],$var['header']))) {
api_exit(EX_DATAERR,”Unable to post message nn $messagen”);
}
}
}

on /include/class.ticket.php
add this function


function getMessageId(){
$cur_mes_id=0;
$sql ='SELECT max(msg_id) FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.db_input($this->getId());
if(($res=db_query($sql)) && db_num_rows($res))
list($cur_mes_id)=db_fetch_row($res);
return $cur_mes_id;
}

and add this on function postResponse

function postResponse($msgid,$response,$signature='none',$attachment=false,$canalert=true,$_staff_id=0){
global $thisuser,$cfg;
//global $cfg;
if($_staff_id!=0){
$ip="0.0.0.0";
$thisuser=new Staff($_staff_id);
}
else
{
$ip=$thisuser->getIP();
}

if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;

$sql= ‘INSERT INTO ‘.TICKET_RESPONSE_TABLE.’ SET created=NOW()’.
‘,ticket_id=’.db_input($this->getId()).
‘,msg_id=’.db_input($msgid).
‘,response=’.db_input(Format::striptags($response)).
‘,staff_id=’.db_input($thisuser->getId()).
‘,staff_name=’.db_input($thisuser->getName()).
‘,ip_address=’.db_input($ip);

the rest are the same…..

Connect with us

FROM THE BLOG

0 348
We added a new option for our heavy users - clients that need more than 20 tracks. Premium Accounts are designed for users that do...