Jump to content

Support pin for clients


techwthquestion

Recommended Posts

Hello

 

I am using below code to display support pin in client area 

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   // The Support PIN will be generated automatically and will change daily.
   // The Support PIN will have the format of: Day (1st and 2nd numbers), Month (3rd and 4th numbers), Client ID (5th, 6 or 7th number) and then the last 2 digits is the current year.

   $clientID = intval($_SESSION['uid']);
   $SupportPIN = date("dm".$clientID."y");
   $firstSidebar = $primarySidebar->getFirstChild();
   if ($firstSidebar) {
    $firstSidebar->setBodyHtml($SupportPIN);
   }
});
 

 


 
How can I get support pin in admin side ? 
Link to comment
Share on other sites

On 12/25/2017 at 2:59 AM, techwthquestion said:

Thank you. 

When I use 


   $firstSidebar = $primarySidebar->getFirstChild();

This remove client information from page . How can I add new box in primary sidebar and named it support pin ? 

use the following code instead, it will create new sidebar panel/block specially for the support pin:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
   // The Support PIN will be generated automatically and will change daily.
   // The Support PIN will have the format of: Day (1st and 2nd numbers), Month (3rd and 4th numbers), Client ID (5th, 6 or 7th number) and then the last 2 digits is the current year.

   $clientID = intval($_SESSION['uid']);
   $SupportPIN = date("dm".$clientID."y");
   
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
  $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
  
});

 

Link to comment
Share on other sites

what about something simple like this function, it will generate the same code during the month, all you have to do is to define the same arguments (client id, key length) in both client and admin side

function generatePinCode($clientid = 0, $length = 6){
    
    preg_match_all('!\d+!', md5(date("my" . $clientid)), $matches);
    
    $numbers = join("", $matches[0]);
    
    return substr($numbers, 0, $length);
    
}

so $SupportPIN will be changed to 

$SupportPIN = generatePinCode($clientID, 8);

 

Link to comment
Share on other sites

36 minutes ago, techwthquestion said:

Perfect !! 

And what kind of changes needed to get same code in admin side ? 


add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . date("dm" . $vars['userid'] . "y");
});

This code gives me different value 

 

apply the same function for admin area actionhook

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

 

Link to comment
Share on other sites

Yes. Everything is in one file 

 

exception 'Whoops\Exception\ErrorException' with message 'Call to undefined function generatePinCode()' in /home/xxxxxx/public_html/includes/hooks/pin.php:26
Stack trace:
#0 /home/xxxxx/public_html/vendor/whmcs/whmcs-foundation/lib/Utility/Error/Run.php(0): WHMCS\Utility\Error\Run->handleError(1, 'Call to undefin...', '/home/xxxxxx/p...', 26)
#1 [internal function]: WHMCS\Utility\Error\Run->handleShutdown()
#2 {main}

 

And this is the file 

 

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

   function generatePinCode($clientid = 0, $length = 6){
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}

$clientID = intval($_SESSION['uid']);
$SupportPIN = generatePinCode($clientID, 8);
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
  $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
});

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

Link to comment
Share on other sites

you need to move generatePinCode function outside the actionhook function, this should work in both sides (Client and Admin Area):

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

$SupportPIN = generatePinCode($_SESSION['uid'], 8);
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
  $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
});

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

function generatePinCode($clientid = 0, $length = 6){
    $clientid = intval($clientid);
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}

 

Link to comment
Share on other sites

1 hour ago, sentq said:

you need to move generatePinCode function outside the actionhook function, this should work in both sides (Client and Admin Area):


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

$SupportPIN = generatePinCode($_SESSION['uid'], 8);
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
  $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
});

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

function generatePinCode($clientid = 0, $length = 6){
    $clientid = intval($clientid);
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}

 

Thanks, this is something we are looking to use as well. I have added your code but i noticed the pin sidebar shows at all times. Anyways to restrict this to login clients only?

Thanks again and have a wonderful 2018!

Link to comment
Share on other sites

Every sidebar has a "client" context available which contains the record of the client that is logged in or null if no client is logged in. The Menu::context() method can retrieve the client record for us. We can then use this to determine if you want that PIN displayed.

For example:

$client = Menu::context('client');
if (!is_null($client)) {
	$SupportPIN = generatePinCode($_SESSION['uid'], 8);
	$primarySidebar->addChild('Support-Pin', array(
		'label' => "Support Pin",
		'uri' => '#',
		'order' => '1',
		'icon' => 'fa-ticket'
	));
	$primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
}

 

Link to comment
Share on other sites

15 minutes ago, WHMCS Marcus said:

Every sidebar has a "client" context available which contains the record of the client that is logged in or null if no client is logged in. The Menu::context() method can retrieve the client record for us. We can then use this to determine if you want that PIN displayed.

For example:


$client = Menu::context('client');
if (!is_null($client)) {
	$SupportPIN = generatePinCode($_SESSION['uid'], 8);
	$primarySidebar->addChild('Support-Pin', array(
		'label' => "Support Pin",
		'uri' => '#',
		'order' => '1',
		'icon' => 'fa-ticket'
	));
	$primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
});
}

 

Thanks Marcus, im not a code person but i have copied your code and al i got was 

Oops!

Something went wrong and we couldn't process your request.

Please go back to the previous page and try again.

Link to comment
Share on other sites

Thanks but i dont seem to understand very well your concept. Im not a coding person and the complete code would help like what Sentq provided in hist last post.

This is the code i have

	<?php
	add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
	$client = Menu::context('client');
if (!is_null($client)) {
    $SupportPIN = generatePinCode($_SESSION['uid'], 8);
    $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
    $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
	});
	add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});
	function generatePinCode($clientid = 0, $length = 6){
    $clientid = intval($clientid);
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}
	

Link to comment
Share on other sites

the complete code (including @WHMCS Marcus part) would be like below:

<?php

use WHMCS\View\Menu\Item as MenuItem;



add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

  $client = Menu::context('client');
  if (!is_null($client)) {
$SupportPIN = generatePinCode($_SESSION['uid'], 8);
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Support Pin",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-ticket'
    ));
  $primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
  }
});

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

function generatePinCode($clientid = 0, $length = 6){
    $clientid = intval($clientid);
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}

 

Link to comment
Share on other sites

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