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

Quoting Original Messages

Here is a mod to quote any previous customer message in your reply.

in scp/js/scp.js, add this function anywhere:

function quoteMsg(msgID,fieldName)
{
//Akon - what's an akon? Eddie rocks.
if (! msgID) {return false}
if (! fieldName){return false}
if (document.getElementById){
fieldName.value+=\"------ Quoted Message ------\n\"+document.getElementById(msgID).textContent;
} else if (document.all){
fieldName.value+=\"------ Quoted Message ------\n\"+document.all[msgID].textContent;
}
fieldName.value+=\"\n---- End Quoted Message ----\n\";
return false;
}


then in include/staff/viewticket.inc.php CHANGE this:

<table align=\"center\" class=\"message\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0>
<tr><th><?=Format::db_daydatetime($msg_row['created'])?></th></tr>
<?if($msg_row['attachments']>0){ ?>
<tr class=\"header\"><td><?=$ticket->getAttachmentStr($msg_row['msg_id'],'M')?></td></tr>
<?}?>
<tr><td><?=Format::display($msg_row['message'])?>&nbsp;</td></tr>
</table>


to this:


<table align=\"center\" class=\"message\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
<tr><th><?=Format::db_daydatetime($msg_row['created'])?></th><th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg('<?=$msg_row['msg_id']?>','<?=Format::db_daydatetime($msg_row['created'])?>',document.reply.response);\">Quote Message In Your Reply</a></th></tr>
<?if($msg_row['attachments']>0){ ?>
<tr class=\"header\"><td colspan=\"2\"><?=$ticket->getAttachmentStr($msg_row['msg_id'],'M')?></td></tr>
<?}?>
<tr><td colspan=\"2\" id=\"<?=$msg_row['msg_id']?>\"><?=Format::display($msg_row['message'])?>&nbsp;</td></tr>
</table>


Pretty sure that's all I've changed. If it doesn't work for you, post here with your problem. Otherwise, not bad for a guy who started PHP programming just today, eh? :o

Comments

  • This is a greatly needed mod imho... unfortunately i am not able to replicate your success... not sure what the problem is cuz i dunno javascript very well, but i am pretty sure it is somewhere in here
    onClick=\"quoteMsg('<?=$msg_row['msg_id']?>','<?=Format::db_daydatetime($msg_row['created'])?>',document.reply.response);\">Quote Message 
    the output is something akin to...[HTML]onClick="quoteMsg('1254','Fri, May 16 2008 6:10pm',document.reply.response);">Quote Message[/HTML]giving three variables passed to the javascript function you wrote but it is only needing two variables

    any ideas where the problem is?
  • i found the problem... looks like you were useing firefox. for some reason .textContent isnt cross browser compatable. you would have to use .innerHTML but it shows all the ugly html code that way. Here is a work around that will make it cross browser compatable (this is the entire mod)...

    in scp/js/scp.js, add these functions anywhere:
    var regExp = /<\/?[^>]+>/gi;
    function ReplaceTags(xStr){
    xStr = xStr.replace(/<BR>/gi,\"\n\");
    xStr = xStr.replace(regExp,\"\");
    return xStr;
    }

    function quoteMsg(msgID,fieldName)
    {
    //Akon - what's an akon? Eddie rocks.
    if (! msgID) {return false}
    if (! fieldName){return false}
    if (document.getElementById){
    var fixedContent = ReplaceTags(document.getElementById(msgID).innerHTML);

    fieldName.value+=\"------ Quoted Message ------\n\"+fixedContent;
    } else if (document.all){
    var fixedContent = ReplaceTags(document.all[msgID].innerHTML);
    fieldName.value+=\"------ Quoted Message ------\n\"+fixedContent;
    }
    fieldName.value+=\"\n---- End Quoted Message ----\n\";
    return false;
    }


    then in include/staff/viewticket.inc.php CHANGE this:
                <table align=\"center\" class=\"message\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0>
    <tr><th><?=Format::db_daydatetime($msg_row['created'])?></th></tr>
    <?if($msg_row['attachments']>0){ ?>
    <tr class=\"header\"><td><?=$ticket->getAttachmentStr($msg_row['msg_id'],'M')?></td></tr>
    <?}?>
    <tr><td><?=Format::display($msg_row['message'])?>&nbsp;</td></tr>
    </table>
    to this
                <table align=\"center\" class=\"message\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
    <tr><th><?=Format::db_daydatetime($msg_row['created'])?></th><th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg('<?=$msg_row['msg_id']?>',document.reply.response);\">Quote Message In Your Reply</a></th></tr>
    <?if($msg_row['attachments']>0){ ?>
    <tr class=\"header\"><td colspan=\"2\"><?=$ticket->getAttachmentStr($msg_row['msg_id'],'M')?></td></tr>
    <?}?>
    <tr><td colspan=\"2\" id=\"<?=$msg_row['msg_id']?>\"><?=Format::display($msg_row['message'])?>&nbsp;</td></tr>
    </table>
    and it all should work very well indeed... thanks for the starting point :D
  • Thanks for fixing my mod! Apparently IE's DOM (as you discovered) doesn't support the textContent property. I had originally done it with innerHTML but discovered the textContent property and went with that. Since we only use FireFox in our organization and don't plan on letting clients have access to this, I wasn't too worried about it not working in IE, even though I did throw in the code to support it -- albeit incorrectly. ;)
  • thats the beauty of community support :D

    you did the heavy lifting... i just gave it a bit of polish, great mod idea and much needed too
  • IE 5.5+ has an equivalent of textContent. It's called innerText. There was also the option of using .firstChild.nodeValue, however, I wasn't able to get anything out of that past the first line break.

    So, I cleaned this up a little more. This will produce cleaner message quoting in FireFox, IE 5.5+ and (supposedly) all other browsers.

    It *should* work in IE pre 5.5 as well, but not as pretty as all the "safe" HTML encoding doesn't get translated properly, just the line breaks, ">" and "

    function ReplaceTags(xStr){
    var regExp = /<\/?[^>]+>/gi;
    xStr = xStr.replace(/<BR.*\/>/gi,\"\n\");
    xStr = xStr.replace(regExp,\"\");
    xStr = xStr.replace(/\&gt;/gi,\">\");
    xStr = xStr.replace(/\&lt;/gi,\"<\");
    return xStr;
    }

    function quoteMsg(msgID,msgDate,fieldName)
    {
    //Akon - what's an akon? Eddie rocks.
    if (! msgID) {return false}
    if (! fieldName){return false}

    if (document.getElementById){
    if (document.getElementById(msgID).textContent) {
    fieldName.value+=\"\n------ Your quoted message from \"+msgDate+\" ------\n\"+document.getElementById(msgID).textContent;
    }else{
    fieldName.value+=\"\n------ Your quoted message from \"+msgDate+\" ------\n\"+document.getElementById(msgID).innerText;
    }
    } else if (document.all){
    //for IE pre 5.5 if anyone is still using that. Not tested, but should work.
    fieldName.value+=\"\n------ Your quoted message from \"+msgDate+\" ------\n\"+ReplaceTags(document.all[msgID].innerHTML);
    }

    fieldName.value+=\"\n---- End Quoted Message ----\n\";
    return false;
    }

  • security_man;2938 said:
    giving three variables passed to the javascript function you wrote but it is only needing two variables
    I assume you're referring "fieldName". It's there so things can be quoted into the other tabbed textarea's (internal notes, transfer) in future mods -- if I continue modding this product.
  • tnx for sharing the code! really appreciated it! :D
  • made it look like an email reply

    I wanted the quote to look like an embedded email reply... and the last IE 5.5 JS kept throwing errors for me when I had the regExp inside the function.

    Result is when you click 'quote in reply' link you get something that looks like this in the textarea...
    On Thu, Jul 30 2009 12:51pm, 'Kurt M' wrote:
    >Is this thing on?
    >Well, I really need help with my problem. I think it starts like this and then
    >goes like this.
    >Thanks,
    >Kurt
    Here is my JS for scp.js
    var regExp = /<\/?[^>]+>/gi;
    function ReplaceTags(xStr){
    xStr = xStr.replace(/<BR.*\/>/gi,\"\n\");
    xStr = xStr.replace(regExp,\"\");
    xStr = xStr.replace(/&gt;/gi,\">\");
    xStr = xStr.replace(/&lt;/gi,\"<\");
    xStr = xStr.replace(/&nbsp;/gi,\" \");
    xStr = xStr.replace(/\n/gi,\"\n>\");
    return \">\"+xStr;
    }

    function quoteMsg(msgID,fieldName,userName,time)
    {
    //Akon - what's an akon? Eddie rocks.
    if (! msgID) {return false}
    if (! fieldName){return false}
    if (document.getElementById){
    var fixedContent = ReplaceTags(document.getElementById(msgID).innerHTML);

    fieldName.value+=\"On \"+time+\", '\"+userName+\"' wrote: \n\"+fixedContent;
    } else if (document.all){
    var fixedContent = ReplaceTags(document.all[msgID].innerHTML);
    fieldName.value+=\"On \"+time+\", '\"+userName+\"' wrote: \n\"+fixedContent;
    }
    fieldName.value+=\"> n\";
    return false;
    }


    and here is the corresponding viewticket.inc.php

    <table align=\"center\" class=\"message\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
    <tr><th><?=Format::db_daydatetime($msg_row['created'])?></th><th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg('<?=$msg_row['msg_id']?>',document.reply.response,'<?echo $ticket->getName();?>','<?=Format::db_daydatetime($msg_row['created'])?>');\">Quote In Your Reply</a></th></tr>
    <?if($msg_row['attachments']>0){ ?>
    <tr class=\"header\"><td colspan=\"2\"><?=$ticket->getAttachmentStr($msg_row['msg_id'],'M')?></td></tr>
    <?}?>
    <tr><td colspan=\"2\" id=\"<?=$msg_row['msg_id']?>\"><?=Format::display($msg_row['message'])?>&nbsp;</td></tr>
    </table>
  • also added quote staff responses

    There are cases where we want to reply to our own responses.. like if we forgot to add something and don't want to lose the context of the email thread. Added the same functionality for quoting message to quoting responses.

    NOTE: my call to the JS function quoteMsg() includes two extra parameters ... so if your using the original quoteMsg() function on this thread remove those params.

    <table align=\"center\" class=\"response\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0>
    <tr><th><?=Format::db_daydatetime($resp_row['created'])?>&nbsp;-&nbsp;<?=$resp_row['staff_name']?></th>
    <th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg('<?=$respID?>',document.reply.response,'<?=$resp_row['staff_name']?>','<?=Format::db_daydatetime($resp_row['created'])?>');\">Quote In Your Reply</a></th></tr>
    <?if($resp_row['attachments']>0){ ?>
    <tr class=\"header\">
    <td><?=$ticket->getAttachmentStr($respID,'R')?></td></tr>
    <?}?>
    <tr><td colspan=\"2\" id=\"<?=$respID?>\"><?=Format::display($resp_row['response'])?></td></tr>
    </table>
  • Help me please!
    I want to quote staff messages too.
    I tried to change javascript function
    function quoteMsg1(respID,fieldName,staff_name',time)
    {
    //Akon - what's an akon? Eddie rocks.

    if (document.getElementById){
    var fixedContent = ReplaceTags(document.getElementById(respID).innerHTML);

    fieldName.value+=\"On \"+time+\", '\"+userName+\"' wrote: \n\"+fixedContent;
    } else if (document.all){
    var fixedContent = ReplaceTags(document.all[respID].innerHTML);
    fieldName.value+=\"On \"+time+\", '\"+staff_name'+\"' wrote: \n\"+fixedContent;
    }
    fieldName.value+=\"> n\";
    return false;
    }

    and phpcode
    <table align=\"center\" class=\"response\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0>
    <tr><th><?=Format::db_daydatetime($resp_row['created'])?>&nbsp;-&nbsp;<?=$resp_row['staff_name']?></th><th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg1('<?=$resp_row['response_id']?>',document.reply.response,'<?echo $ticket->getName();?>','<?=Format::db_daydatetime($resp_row['created'])?>');\">Quote In Your Reply1</a></th></tr>
    <?if($resp_row['attachments']>0){ ?>
    <tr class=\"header\">
    <td><?=$ticket->getAttachmentStr($respID,'R')?></td></tr>
    <?}?>
    <tr><td> <?=Format::display($resp_row['response'])?></td></tr>
    </table>

    But it doesn`t work
  • ilm;20719 said:
    Help me please!
    I want to quote staff messages too.
    I tried to change javascript function
    function quoteMsg1(respID,fieldName,staff_name',time)
    {
    //Akon - what's an akon? Eddie rocks.

    if (document.getElementById){
    var fixedContent = ReplaceTags(document.getElementById(respID).innerHTML);

    fieldName.value+=\"On \"+time+\", '\"+userName+\"' wrote: \n\"+fixedContent;
    } else if (document.all){
    var fixedContent = ReplaceTags(document.all[respID].innerHTML);
    fieldName.value+=\"On \"+time+\", '\"+staff_name'+\"' wrote: \n\"+fixedContent;
    }
    fieldName.value+=\"> n\";
    return false;
    }

    and phpcode
    <table align=\"center\" class=\"response\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0>
    <tr><th><?=Format::db_daydatetime($resp_row['created'])?>&nbsp;-&nbsp;<?=$resp_row['staff_name']?></th><th style=\"text-align:right\"><a href=\"#reply\" onClick=\"quoteMsg1('<?=$resp_row['response_id']?>',document.reply.response,'<?echo $ticket->getName();?>','<?=Format::db_daydatetime($resp_row['created'])?>');\">Quote In Your Reply1</a></th></tr>
    <?if($resp_row['attachments']>0){ ?>
    <tr class=\"header\">
    <td><?=$ticket->getAttachmentStr($respID,'R')?></td></tr>
    <?}?>
    <tr><td> <?=Format::display($resp_row['response'])?></td></tr>
    </table>

    But it doesn`t work
    Maybe the code changed too much since recent update (ST etc.)?
  • Hi i am new to Os ticket and wish to achieve the same functionality in the newer version of OS ticket v.1.8. any ideas
  • Please don't zombie threads.  Please start a new thread in the appropriate area to your topic.  You can always link to the old versions thread in the post.

    Closing Zombie thread from 2008.
This discussion has been closed.