Jump to content

Mergefield on ticket email templates - The assigned admin name


Inetbiz

Recommended Posts

Can anyone help improve this so it works?

 

if (!defined("WHMCS"))    die("This file cannot be accessed directly");


function add_admin_name_email($merge_fields) {
$table = "tbltickets";
$fields = "id,admin";
$where = array("id"=>$userid);
$result = select_query($table,$fields,$where);
$data = mysql_fetch_array($result);
$id = $data['id'];
$name = $data['admin'];
$messagename = 'Support Ticket Reply';
$relid = '9';
$merge_fields = array();
$merge_fields['admin_name'] = $name;
return $merge_fields;
}


add_hook("EmailPreSend",$relid,"add_admin_name_email");

Link to comment
Share on other sites

1. Support Ticket Reply. Merge Field to express WHO is the assigned admin on ticket

2. Support Ticket Opened by Admin - Merge Field to express WHO is the assigned admin on ticket

3. Support Ticket Feedback Request - Same

4. Support Ticket Auto Close - Same

 

So that our email templates can have

 

Assigned Staff Member: {$admin}

Link to comment
Share on other sites

well, your code is far away from what you need to achieve.

 

here is how you can do it,

 

create new file inside /includes/hooks/ directory you can name it anything "getAdminFromTicket.php" or something else.

put the following code inside it

<?php

function hook_getAdminFromTicket($vars){
   $ticketsTemplates = array(
       "Support Ticket Opened by Admin",
       "Support Ticket Feedback Request",
       "Support Ticket Reply",
       "Support Ticket Auto Close Notification"
   );

   if (!in_array($vars['messagename'], $ticketsTemplates)){
       return array();
   }

   $getLastReply = full_query("SELECT * FROM `tblticketreplies` WHERE `tid`='".$vars['relid']."' AND `admin`!='' ORDER BY `id` DESC LIMIT 1");
   $getLastReply = mysql_fetch_assoc($getLastReply);
   $ticketAdmin = $getLastReply['admin'];

   if (!isset($getLastReply['admin']) || $getLastReply['admin']==''){
       $getTicket = full_query("SELECT * FROM `tbltickets` WHERE `id`='".$vars['relid']."' AND `admin`!=''LIMIT 1");
       $getTicket = mysql_fetch_assoc($getTicket);
       $ticketAdmin = $getTicket['admin'];

       if (!isset($getTicket['admin']) || $getTicket['admin']==''){
           $ticketAdmin = "Not Specified";
       }

   }

return array("ticket_admin" => $ticketAdmin);
}
add_hook("EmailPreSend", 1, "hook_getAdminFromTicket");

 

Now in the mentioned email templates you can display the assigned admin by adding this smarty tag

{$ticket_admin}

 

this will get last admin replied to ticket, if not found it will get the admin name from ticket details if no replies added by admin, otherwise it will return the value "Not Specified" and you can change this text above

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated