Jump to content

Product Addon Conditional Hook


jarod

Recommended Posts

I'm trying to display a menu to clients based on a product addon (if is active). The purpose is to allow us to activate an addon which will trigger adding a menu link in the sidebar. The problem I am facing is getting it to display more than one addon conditionally.

 

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule; 

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){	
include ('includes/_sidebar.php');
$client = Menu::context("client");
// -- Database queries
$domain = Capsule::table('tblhosting')
		->where('userid', $client->id)
           ->where('domainstatus','Active') 
		->get();
$cPaddon  = Capsule::table('tblhostingaddons')
		->where('id', '1')
		->where('status', 'Active')			
		->get();
// -- Sidebar			
	$netAccess = $primarySidebar->addChild('yourwebsites', array( 
					'label' => 'Network Access', 
					'icon' => 'fa-globe', 
				));
	// -- Sidebar panel	
	$netAccess->setBodyHtml(
		"Get to where you need to go.<br><span style='font-size:10px;color: green;'><em>Click on a domain to access</em></span>"
	);	
// Go time
foreach ($domain as $acc) {	
	foreach ($cPaddon as $cPaddons) {
			$cPanel = $acc->domain.":2083";
	}
	// -- Sidebar access links	
	$netAccess->addChild(
		$acc->domain
		."<a class='close hide'><i class='fa fa-times' aria-hidden='true'></i> Close</a>"
			."<div class='collapsed' id='collapse'>"
				//-- Access links
				.$acc->domain
				.$acc->domain."/webmail"
				.$cPanel
				.$acc->domain."/tools"
				.$acc->id

			."</div>"	
	);
}
});

 

So if a client has our hosting package and the cPanel addon it adds a link to their cPanel login page. We have other addons and I've tried duplicating this without luck.

 

How can I check against the DB for addons and display an output conditionally for more than one addon?

Edited by jarod
Link to comment
Share on other sites

I do wish you wouldn't use those abbreviations in your code (at least when posting them here) - makes it damn near impossible, for anyone other than you, to immediately see what's going on... and it drives me bloody nuts! :twisted:

 

I can quickly see 2 parts that are unnecessary - references to Carbon (as you aren't using dates) and the global $config line - they won't be causing your problem, but you don't need them.

 

however, the main part that looks wrong is...

foreach ($domain as $sdbr)

what that's trying to do is create multiple new sidebars with the same name and content - you can't do that...

 

if this is going to be a new sidebar, then you need to create it outside of the foreach - so the $netaccess line itself is fine, just get rid of the foreach.

 

as for the rest, it's too late in the day to spend time tracking back through your previous posts to try figure out what each of the abbreviations are.. it's given me a headache.

Link to comment
Share on other sites

Ok I figured this out.

 

I was struggling with this because I was using a live site! So I created a new file for the hook to modify / test on the live site.

 

if ($_SESSION['uid']=="1") {//my hook here}

 

Then I was free to do what I wanted and test it on a dummy user account, leaving client accounts unaffected while I test.

 

First, I was going off of the wrong header in tblhostingaddons.

 

Instead of

->where('id', '1')

 

I needed

->where('addonid', '1')

 

etc

 

After that it was as simple as

if ($cPaddon == true) {//my code}

etc

___

 

I'll post the entire code (please forgive the variables).

 

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule; 
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){	
include ('includes/_sidebar.php');
$client = Menu::context("client");
// -- Database queries
$domain = Capsule::table('tblhosting')
		->where('userid', $client->id)
           ->where('domainstatus','Active') 
		->get();
$cPaddon  = Capsule::table('tblhostingaddons')
		->where('addonid', '1')
		->where('status', 'Active')			
		->get();
$btwgWP  = Capsule::table('tblhostingaddons')
		->where('addonid', '2')
		->where('status', 'Active')			
		->get();
// -- Sidebar		
foreach ($domain as $sdbr) {	
	$netAccess = $primarySidebar->addChild('yourwebsites', array( 
					'label' => 'Network Access', 
					'icon' => 'fa-globe', 
				));
	// -- Sidebar panel	
	$netAccess->setBodyHtml(
		"Get to where you need to go.<br><span style='font-size:10px;color: green;'><em>Click on a domain to access</em></span>"
	);									
}	
// Go time
foreach ($domain as $acc) {	
	if ($cPaddon == true) {
			$cPanel = $aOl.$https.$acc->domain.":2083".$iO."fa-chevron-right".$iC."cPanel".$aC;
	}
	if ($btwgWP == true) {
			$btwgWPMU = $aOl.$https.$acc->domain."/edit".$iO."fa-wordpress".$iC."BTWG WordPress".$aC;
	}
	// -- Sidebar access links	
	$netAccess->addChild(
		$aO.$togl.$iO."fa-home".$iC.$acc->domain.$aC
		."<a class='close hide'><i class='fa fa-times' aria-hidden='true'></i> Close</a>"
			."<div class='collapsed' id='collapse'>"
				//-- Access links
				.$aOl.$https.$acc->domain.$iO."fa-external-link".$iC."Visit".$aC
				.$aOl.$https.$acc->domain."/webmail".$iO."fa-envelope-o".$iC."Webmail".$aC
				.$cPanel
				.$btwgWPMU
				.$aOl.$https.$acc->domain."/tools".$iO."fa-wrench".$iC."Tools".$aC
				."<a class='list-group-item' href='".$sys.$caPD.$acc->id.$iO."fa-cog".$iC."Details".$aC

			."</div>"	
	);
}
});

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