Jump to content

Kayako integration: ticket count on client home


bear

Recommended Posts

Decided to go for the full integration with Kayako and WHMCS (can't believe how difficult the Kayako templates are to simplify and integrate, with table upon nested table...), and I find that the one important thing in that integration is the lack of a ticket count in the clients home page, as well as the admin home, but the client home page is more important.

 

Has anyone ever made anything to check the Kayako db for a ticket count to be able to display it on the client's home page while using the full integration? I'd be interested in seeing that, if so.

Link to comment
Share on other sites

Hi there,

 

Because this isn't the first time such integration has been requested, I have taken a few minutes to create a script that will accomplish the basic integration of ticket counts in the client area page. If I see the demand for a more in depth integration and appreciation for the work below, I'll create scripts for native listing of open tickets on the client area page, and native ticket counts integration in the admin area.

 

For now...

 

CLIENT AREA:

 

- Create a PHP file in the /includes/hooks folder of your WHMCS installation, paste the following therein.

- Modify the $kayako_config_location variable to the location of your Kayako config.php file - this is very important.

 

<?php

/*
Script: Kayako support ticket counts (open/total) in WHMCS client area
Author: Victor Lugo (www.victorlugo.com)
Last edited: April 4, 2010
Version: 1.0
*/

add_hook("ClientAreaPage",1,"fixTicketCounts","");

function fixTicketCounts()
{

/************************EDIT*****************************/
$kayako_database_prefix = "sw"; //MODIFY ONLY IF DATABASE PREFIX DIFFERS FROM DEFAULT VALUE
$kayako_config_location = "/path/to/kayako/config/config.php"; //MODIFY TO KAYAKO CONFIG.PHP LOCATION
/************************EDIT*****************************/

global $smarty;

//GET THE CLIENT'S WHMCS USER ID FROM SMARTY...
$whmcs_user_id = $smarty->_tpl_vars['clientsdetails']['userid'];

//GET THE KAYAKO CONFIG.PHP FILE...
require($kayako_config_location);

//GIVE MATCHING VARIABLES TO THE DATABASE PROPERTIES... (SO THAT I STAY SANE)...
$kayako_database_hostname = $_DB["hostname"];$kayako_database_username = $_DB["username"];$kayako_database_password = $_DB["password"];$kayako_database_name = $_DB["name"];$kayako_database_users_table = $kayako_database_prefix . "users";$kayako_database_tickets_table = $kayako_database_prefix . "tickets";

//SET THE MYSQL CONNECTION TO THE KAYAKO DATABASE...
$kayako_database = mysql_connect($kayako_database_hostname, $kayako_database_username, $kayako_database_password);

//GET THE CLIENT'S KAYAKO USER ID...
$kayako_user_id = mysql_query("SELECT userid FROM $kayako_database_name.$kayako_database_users_table WHERE loginapi_userid = '$whmcs_user_id'", $kayako_database);$kayako_user_id = mysql_fetch_row($kayako_user_id);$kayako_user_id = $kayako_user_id[0];

//GET THE ROWS THAT MATCH THE CLIENT'S KAYAKO USER ID AND THAT ARE NOT CLOSED...
$result = mysql_query("SELECT * FROM $kayako_database_name.$kayako_database_tickets_table WHERE userid = '$kayako_user_id' AND ticketstatusid != '3'", $kayako_database);

//COUNT THOSE ROWS, GIVE THE RESULT A VARIABLE...
$number_open_tickets = mysql_num_rows($result);

//TRICK SMARTY, INJECT THE NEW NUMBER INTO THE VARIABLE BEFORE THE PAGE LOADS...
$smarty->_tpl_vars['clientsstats']['numactivetickets'] = $number_open_tickets;

//MUST NOT FORGET TO ALSO SET THE NUMBER OF TOTAL TICKETS (OPEN AND CLOSED)... GET THE ROWS THAT MATCH THAT CLIENT'S KAYAKO USER ID...
$result = mysql_query("SELECT * FROM $kayako_database_name.$kayako_database_tickets_table WHERE userid = '$kayako_user_id'", $kayako_database);

//COUNT THOSE ROWS, GIVE THE RESULT A VARIABLE...
$number_tickets = mysql_num_rows($result);

//TRICK SMARTY, INJECT THE NEW NUMBER OF TOTAL TICKETS INTO THE VARIABLE BEFORE THE PAGE LOADS...
$smarty->_tpl_vars['clientsstats']['numtickets'] = $number_tickets;
} 

?>

Link to comment
Share on other sites

also i get this error :

 

Warning: Cannot modify header information - headers already sent by (output started at /............../whmcs/includes/hooks/tickets.php:56) in /................../whmcs/dologin.php on line 0

Link to comment
Share on other sites

also i get this error :

 

Warning: Cannot modify header information - headers already sent by (output started at /............../whmcs/includes/hooks/tickets.php:56) in /................../whmcs/dologin.php on line 0

 

You probably have a space after the ?> in the tickets.php file. Remove it.

Link to comment
Share on other sites

I really should have updated, but Sparky had a script that allowed me to connect to Kayako and pull the counts and list the 5 most recent tickets within the client's home page. It didn't use actionhooks, so it's something that requires more effort to set up, and subsequent template updates will need to redo bits, but it works.

 

kay-ticketlist.jpg

 

I'll leave it to him if he wants to publish here, since it wasn't mine to share.

 

I did create something that would count the tickets in admin home (right at the top as before) and link to the Kayako desk to manage tickets in a new window, if anyone's interested in that. Again, it's not using actionhooks, so template edits are required.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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