Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[MOD] Quote Original Message in Reply through Template

Montclair wrote a great mod for quoting messages in replies, however, I wanted it done automatically through the email templates. What I ended up doing was creating another "variable" %quote in the email template for reply. In class.ticket.php i added the following at line 600, just below

$body = str_replace("%message",$response,$body);

Here is the code I added

$ticket_number = $msgid;
$sql2 = 'SELECT `message` FROM `ost_ticket_message` WHERE `msg_id` LIKE $ticket_number LIMIT 0, 1 ';
$services= mysql_query("SELECT message FROM ".TICKET_MESSAGE_TABLE." WHERE msg_id LIKE '$ticket_number'");
list($original_message) = db_fetch_row($services);
$body = str_replace("%quote", $original_message,$body);

Comments

  • For assignment notifications?

    This works great for replies - we also would like to include it in the 'Assigned to you' ticket notification...I tried to put the same code in the right spot in class.tickets.php, but no luck...thoughts?
  • Here is what I put in Assign: staff

    Insert:
    		$sql='SELECT message FROM ost_ticket_message WHERE ticket_id='.$this->getId().' ORDER BY created ASC LIMIT 1'; 
    if(($resp=db_query($sql)) && db_num_rows($resp) && list($startermessage)=db_fetch_row($resp)){
    $startermessage = $startermessage;
    }

    if ($startermessage=='Ticket created by staff'):
    $sql='SELECT response FROM ost_ticket_response WHERE ticket_id='.$this->getId().' ORDER BY created ASC LIMIT 1';
    if(($resp=db_query($sql)) && db_num_rows($resp) && list($startermessage)=db_fetch_row($resp)){
    $startermessage = $startermessage;
    }
    endif;


    Above:
                    $sql='SELECT assigned_alert_subj,assigned_alert_body FROM '.EMAIL_TEMPLATE_TABLE.
    ' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId);
    if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){


    and add:
                        $body = str_replace(\"%thread\", $startermessage,$body); //Previous versions used message.


    under:
                        $body = str_replace(\"%message\", $message,$body); //Previous versions used message.


    %thread is the variable to use in your template.
  • Wow, that worked GREAT! Thank you so much!!!
  • Works great. Please work these variables into the next release!
  • I used the %quote in the Ticket Response/Reply email template and it quotes the reply correctly but it also actually says "%quote" in the response email to the user. like:

    Thank you, staff name

    %quote

    Original text here

    can it be fixed?
  • hi!
    I did as slm4996 said.
    But it quotes only the first message of the ticket.
    What shall i do to quote all the messages of the ticket as it made in kayako?
  • Getting all the thread messages

    The code below fills three variables: %quote, %quotedate and %thread. The first two are for just the last message posted, and the last one contains the full thread. With some help from the posts above.

    Add to class.ticket.php about line 760 just before the "//Figure out the signature..." part:


    // get message poster name
    $sql='SELECT name FROM '.TICKET_TABLE.' WHERE ticket_id='.$this->getId().' LIMIT 1';
    if (($resp=db_query($sql)) && db_num_rows($resp) && list($messagename)=db_fetch_row($resp))
    { $messagename = $messagename; }

    // get all thread messages and responses
    $fullthread = '';
    $sql='SELECT msg_id,message,created FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.$this->getId().' ORDER BY created DESC';
    $resp=db_query($sql);
    if (db_num_rows($resp) > 0)
    {
    // get all the messages
    while (list($threadmsgid,$threadmsg,$threadmsgdate) = db_fetch_row($resp))
    {
    // and all the responses for each message
    $sql2='SELECT staff_name,response,created FROM '.TICKET_RESPONSE_TABLE.' WHERE ticket_id='.$this->getId().' AND msg_id='.$threadmsgid.' ORDER BY created DESC';
    $resp2=db_query($sql2);
    if (db_num_rows($resp2) > 0)
    {
    while (list($responsestaffname,$responseresponse,$responsecreated) = db_fetch_row($resp2))
    {
    // don't want the very first or last responses
    if (strpos($responseresponse,\"Your ticket #\") === false && // yes, 3 equal signs apparently
    strpos($responseresponse,$response) === false)
    {
    // output each reponse
    $fullthread .= '--------------------------------------------------------'.\"\r\n\";
    $fullthread .= 'On '.$responsecreated.', '.$responsestaffname.' wrote:'.\"\r\n\";
    $fullthread .= $responseresponse;
    $fullthread .= \"\r\n\";
    $fullthread .= \"\r\n\";
    }
    }
    }

    // output each message
    $fullthread .= '--------------------------------------------------------'.\"\r\n\";
    $fullthread .= 'On '.$threadmsgdate.', '.$messagename.' wrote:'.\"\r\n\";
    $fullthread .= $threadmsg;
    $fullthread .= \"\r\n\";
    $fullthread .= \"\r\n\";
    }
    }
    $body = str_replace(\"%thread\", $fullthread,$body);
  • Getting this to work with OST 1.7

    Hi everyone,
    I am trying to get this working with my OST 1.7 install. have my class.ticket.php file ready to edit but there is no reference to "//figure out..." so I dont know exactly where to place the code. I tried inserting the code directly at line 760 and my whole OST install died (until I reverted to the old class.ticket.php file). Any help on how I can get this working with the latest version of OST?
  • Code position

    I'm not sure if I have the latest version, but the code I've posted above goes int class.ticket.php after the lines:


    $dept=$this->getDept();
    if(!$dept || !($tplId=$dept->getTemplateId()))
    $tplId=$cfg->getDefaultTemplateId();

    //Send Response to client...based on the template...
    //TODO: check department level templates...if set.
    $sql='SELECT ticket_reply_subj,ticket_reply_body FROM '.EMAIL_TEMPLATE_TABLE.
    ' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId);
    if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){

    $body=$this->replaceTemplateVars($body);
    $subj=$this->replaceTemplateVars($subj);
    $body = str_replace('%response',$response,$body);
    //$body = str_replace('%message',$response,$body); //Previously used!


    and before the lines:


    //Figure out the signature to use...if any.
    switch(strtolower($signature)):
    case 'mine';
    $signature=$thisuser->getSignature();
    break;
    case 'dept':
    $signature=($dept && $dept->isPublic())?$dept->getSignature():''; //make sure it is public
    break;
    case 'none';
    default:
    $signature='';
    break;
    endswitch;
    $body = str_replace(\"%signature\",$signature,$body);

    //Email attachment when attached AND if emailed attachments are allowed!
    $file=null;
  • does not work

    unfortunately my class file looks nothing like that. I have attached my file (I had to zip it so it would upload), if it's not too much trouble, could you please take a look at the file and let me know where you think I should insert it. This would be greatly appreciated. Thank you!

    Mark
    class.ticket.zip
    15K
  • sorry

    I'm not using this anymore or working on it so sorry you'll have to figure it out yourself. I've attached the old file I had - hope it helps. Be sure to post a fix if you do figure it out for future readers.
    class.ticket.php.zip
    14K
Sign In or Register to comment.