Jump to content

OverLoad Support Hook


Recommended Posts

Hey everyone and welcome to the SkunkWorx forum!

 

Today we are going to be looking at a hook that will create an output for your Admin Area in WHMCS for support tickets.

 

This output will provide a banner with the number of Staff Online and the number of tickets in the Awaiting Reply status which by default is how tickets requiring a response will be shown when you pull up supporttickets.php or clicking on the Awaiting Reply link from the top of the homepage.

 

This is a combination of jQuery and localAPI calls placed inside functions and their results then processed via the AdminAreaFooterOutput hook point.

 

Simply create a new file in your [highlight]includes/hooks/[/highlight] directory and name it something that will easily make it known as to what it does, in this case lets call it Overload.php.

 

Here is the code in which is copy/paste ready and you can download it following this link Overload.txt (simply rename the extension to .php):

 

<?php
/**
* This hook will check the count of tickets
* in Active Status and then using jQuery add
* a banner informing of any overload based on
* logged in admins.
*
* @package     WHMCS
* @author      WHMCS Chance
* @copyright   Copyright (c) WHMCS Limited 2005-2016
* @license     https://www.whmcs.com/license WHMCS Eula
* @link        https://www.whmcs.com/
*/

if (!defined('WHMCS')) {
   die('This hook should not be run directly');
}

function checkTicketCount() {
   $count = localAPI('gettickets', array(
       'limitnum' => '1000',
       'status' => 'Awaiting Reply'
   ));

   return $count['totalresults'];
}

function checkAdmins() {
   $getStaff = localAPI('getstaffonline');

   return $getStaff['totalresults'];
}

function showOverload() {
   $overLoad = checkTicketCount();
   $staff = checkAdmins();

   $page = $_SERVER['PHP_SELF'];
   $pos = strrpos($page, 'supporttickets.php');
   if ($pos != false) {
       if ($overLoad <= 9 && $staff <= 1) {
           $show = '<script>
           $(function() {
             $(\'<div class="alert alert-success text-center">Tickets are looking good!!!! <div style="font-size: 14px;">Staff Online: <b>'.$staff.'</b></div><div style="font-size: 14px;">Tickets: <b>'.$overLoad.'</b></div></div>\').prependTo("#contentarea");
           });
           </script>';
       } elseif ($overLoad >= 10 && $staff >= 1) {
           $show = '<script>
           $(function() {
             $(\'<div class="alert alert-danger text-center">We are in <b>OVERLOAD</b>!!!! <div style="font-size: 14px;">Staff Online: <b>'.$staff.'</b></div><div style="font-size: 14px;">Tickets: <b>'.$overLoad.'</b></div></div>\').prependTo("#contentarea");
           });
           </script>';
       }

       return $show;
   }
}

add_hook('AdminAreaFooterOutput', 1, 'showOverload');

 

Let's break this code down a little bit and I will give you some points on where to adjust the sensitivity of the hook so you can set it based on your workflow and such.

 

($overLoad <= 9 && $staff <= 1)

 

This above is what sets the limitations for the hook to show either the All Good or the Overload message which you can see in the screenshots.

 

In the first if statement this is your All Good message so here is where you would set the number of tickets to be lower as this would mean you've got things under control so to speak.

 

In the following elseif statement is the Overload message.

 

Here you would want to put a number 1 higher whatever you have set for your previous check as mentioned above.

 

The same goes for the $staff variable in the if statements as well, you would bump this up or down depending on the number of staff you have and your workflow.

 

function checkTicketCount() {
   $count = localAPI('gettickets', array(
       'limitnum' => '1000',
       'status' => 'Awaiting Reply'
   ));

   return $count['totalresults'];
}

 

In the above function, the localAPI call that is made, you can also pass in deptid as an array item and specify which departments you would like to get the tickets from as well in case you would like to only pull for the Support Department or Sales Deptarment, etc.

 

You can read more about the other variables for this API call here: GetTickets API call

 

I hope that this customization will come in handy for some of you out there looking to add a little flair to your WHMCS installation and in the process, make it more your own.

 

At the time of writing, this hook is tested with the current versions of WHMCS that fall under Active Support as listed here http://docs.whmcs.com/Long_Term_Support#WHMCS_Version_.26_LTS_Schedule]Active Support and are not guaranteed to work with prior versions of WHMCS.

 

I look for any feedback, comments and questions that you may have for me that were not answered already.

 

Thanks!

 

all_good.png

overload.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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