jarod Posted July 3, 2017 Share Posted July 3, 2017 (edited) 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 July 3, 2017 by jarod 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 3, 2017 Share Posted July 3, 2017 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! 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. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 3, 2017 Author Share Posted July 3, 2017 I've made the suggested edits in my hook and cleaned up the code above so you don't go nuts lol. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 3, 2017 Author Share Posted July 3, 2017 foreach ($domain as $sdbr) This keeps the sidebar from displaying if you aren't logged in. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted July 3, 2017 Author Share Posted July 3, 2017 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>" ); } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 3, 2017 Share Posted July 3, 2017 This keeps the sidebar from displaying if you aren't logged in. there are other simpler ways to check if a client is logged in or not - but i'm glad you got it working in the end. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.