jarod Posted February 7, 2017 Share Posted February 7, 2017 I'm new to WHMCS 7+ and the six theme. How do I grab the current users domain name and display it in the sidebar? I've got the hook working and a new sidebar, but I've spent a few hours trying to figure out how to display the current users primary domain without luck. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 7, 2017 Author Share Posted February 7, 2017 This is what I have. It works, but not on all pages. <?php /** * Display Client's Credit Balance in Client Area * * @author WHMCMS * @link http://www.whmcms.com * @since WHMCS v6.0.0+ */ use WHMCS\View\Menu\Item as MenuItem; # Add Balance To Sidebar add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){ $filename = basename($_SERVER['REQUEST_URI'], ".php"); $parseFile = explode('.', $filename); $client = Menu::context("client"); $clientid = intval($client->id); if ($parseFile['0']!=='clientarea' || $clientid===0){ return; } $primarySidebar->addChild('Client-Balance', array( 'label' => "Available Credit", 'uri' => '#', 'order' => '1', 'icon' => 'fa-money' )); # Get Currency $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get(); # Retrieve the panel we just created. $balancePanel = $primarySidebar->getChild('Client-Balance'); // Move the panel to the end of the sorting order so it's always displayed // as the last panel in the sidebar. $balancePanel->moveToBack(); $balancePanel->setOrder(0); # Add Balance. $balancePanel->addChild('balance-amount', array( 'uri' => 'clientarea.php?action=addfunds', 'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>', 'order' => 1 )); $balancePanel->setFooterHtml( '<a href="clientarea.php?action=addfunds" class="btn btn-success btn-sm btn-block"> <i class="fa fa-plus"></i> Add Funds </a>' ); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 8, 2017 Share Posted February 8, 2017 it works, but not in the sense that it shows the domain - it's only sentq's credit sidebar hook (unaltered I think)... you can do it in a hook using only a few lines - but the problem you have is going to be defining the "primary" domain - what if the client has 10 domains... which one is primary? if you then say that you want to link it to domains with hosting, what if they have more than one hosting account - which is primary ?? you can easily add the sidebar to the domaindetails page because there you know which domain is primary (or more accurately which domain is being managed)... beyond that, you'd need to be more specific about defining which domain to show. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 8, 2017 Author Share Posted February 8, 2017 AHH... That was not what I mean to post LOL. Here's what I've actually come up with. It does display on the clientarea.php?action=productdetails&id=1 page, but doesn't anywhere else. use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) { $webAccess = $primarySidebar->addChild('webaccess', array( 'label' => 'Web Access', 'uri' => '#', 'icon' => 'fa-desktop', )); $webAccess->moveToFront(); $service = Menu::context('service'); $domain = "{$service->domain}"; $webAccess->addChild( 'domain', array( 'label' => $domain, 'order' => 3, 'icon' => 'fa-globe', 'uri' => 'https://'.$domain, ) ); $client = Menu::context('client'); $name = is_null($client) ? '' : "<strong>{$client->firstName}</strong>"; $webAccess->setBodyHtml( $webAccessAvailable ? "{$name}" : "{$name}" ); }); - - - Updated - - - I would like to display all the domain names associated with a specific product. Let's say I have product ABC which will always have a domain name attached to it, the domain assigned to that ABC product would display. I'm a little under the weather and not running on all pistons... 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 8, 2017 Share Posted February 8, 2017 I'm a little under the weather and not running on all pistons... you never want to be writing hooks under those conditions! that hook is working correctly - not in the way you want it to perhaps, but it makes sense it would only work on that productdetails page. if this sidebar needs to be on all client area pages, you may end up needing to query the database for the information you require.... it should only be a very simple query to the tblhosting table. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 8, 2017 Author Share Posted February 8, 2017 Can you provide an example or direct me to some documentation, please? I've searched the web and this forum extensively and cannot find anything that simple outputs the data in my hook to the sidebar. ty 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 8, 2017 Share Posted February 8, 2017 it's going to be something along the lines of... <?php use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){ $client = Menu::context("client"); $domains = Capsule::table('tblhosting') ->where('userid', $client->id) ->where('packageid','2') ->get(); if ($domains) { $primarySidebar->addChild('webaccess', array( 'label' => 'Web Access', 'icon' => 'fa-desktop', )); foreach ($domains as $child) { $primarySidebar->getChild('webaccess') ->addChild($child->domain, array( 'label' => $child->domain, 'icon' => 'fa-globe', 'uri' => 'https://'.$child->domain, )); } } }); i'm assuming a client can have multiple numbers of the same product, each with it's own unique domain name - the only thing you should need to change for now is the packageid (product ID) value for your specific product. if a client doesn't have this specific product, then the sidebar isn't created. 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 9, 2017 Author Share Posted February 9, 2017 Thank you for this! My final product is as such: use Carbon\Carbon; use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar){ $client = Menu::context("client"); // -- Database queries $systemurl = Capsule::table('tblconfiguration') ->where('setting','SystemURL') ->get(); $sys = ''; foreach ($systemurl as $URL) { $sys .= $URL->value . PHP_EOL; } $caPD = 'clientarea.php?action=productdetails&id='; $domain = Capsule::table('tblhosting') ->where('packageid','1') ->get(); // -- Sidebars $webAccess = $primarySidebar->addChild('webaccess', array( 'label' => 'Web Access', 'icon' => 'fa-globe', )); // -- Misc variables $aO = "<a href='"; $aOl = "<a class='list-group-item' href='https://"; $iO = "'><i class='fa "; $iC = "' aria-hidden='true'></i> "; $aC = '</a>'; foreach ($domain as $acc) { // -- Sidebar panel $webAccess->setBodyHtml( "Get to where you need to go." ); // -- Sidebar access links $webAccess->addChild( $aO.$acc->domain.$iO."fa-home fa-fw".$iC.$acc->domain.$aC ."<div class='webaccess-list'>" //-- Access link .$aOl.$acc->domain."/edit".$iO."fa-tachometer".$iC."Dashboard".$aC .$aOl.$acc->domain."/tools".$iO."fa-wrench".$iC."Tools".$aC .$aOl.$sys.$caPD.$acc->id.$iO."fa-cog fa-fw".$iC."Details".$aC ."</div>" ); } }); - - - Updated - - - Here's what the thing looks like 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 9, 2017 Share Posted February 9, 2017 you must be taking some seriously strong medication looking at those misc variables! a couple of points - you don't need to query the database to get Configuration variables, you can access them by declaring them as global (as in the thread below)... https://forum.whmcs.com/showthread.php?123874-Hook-to-add-link-to-client-nav-bar-under-Your-Account&p=497214#post497214 in fact, I think for your purpose you don't even need the variable at all because you only use it in the clientarea.php link and as it's in a sidebar, you know that it must always be a WHMCS page... so just the link without any url or https should be sufficient... homepage link is wrong too... also, you've added double font awesome icons to two of the links - they only need one, and if you remove the two "fa-fw", then the icons will align. ... it's given me an idea to try something at the weekend with this... 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 11, 2017 Author Share Posted February 11, 2017 I appreciate your feedback, Brian. Here's my updated code: include ('includes/_sidebar.php'); global $CONFIG; $client = Menu::context("client"); // -- Database queries $domain = Capsule::table('tblhosting') //->where('userid', $client->id) ->where('packageid','1') ->get(); // -- Sidebar $netAccess = $primarySidebar->addChild('yourwebsites', array( 'label' => 'Network Access', 'icon' => 'fa-globe', )); // -- Sidebar panel $netAccess->setBodyHtml( "Get to where you need to go." ); // Go time foreach ($domain as $acc) { // -- Sidebar access links $netAccess->addChild( $aO.$togl.$iO."fa-home fa-fw".$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."/edit".$iO."fa-tachometer".$iC."Dashboard".$aC .$aOl.$https.$acc->domain."/tools".$iO."fa-wrench".$iC."Tools".$aC .$aOl.$sys.$caPD.$acc->id.$iO."fa-cog".$iC."Details".$aC ."</div>" ); } Here's the _sidebar include: // -- Misc variables $sys = $CONFIG['SystemURL']; $caPD = '/clientarea.php?action=productdetails&id='; $togl = " class='link'"; $aO = "<a "; $aOl = "<a class='list-group-item' href='"; $https = 'https://'; $http = 'http://'; $iO = "'><i class='fa "; $iC = "' aria-hidden='true'></i> "; $aC = '</a>'; ?> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .pointer { cursor: pointer; } </style> <script> $("document").ready(function () {; $.each($(".link"), function(index, value){ var num = index + 1; $(value).attr("class","pointer open-"+ num); }); $.each($(".collapsed"), function(index, value){ var num = index + 1; $(value).attr("class","hide webaccess-list collapsed-"+ num); }); $.each($(".close"), function(index, value){ var num = index + 1; $(value).attr("class","pointer hide close-"+ num); }); $(".open-1").click(function() { $('.open-1').addClass("hide"); $('.open-2').removeClass("hide");$(".collapsed-2").addClass("hide"); $('.close-1') .removeClass("hide");$(".collapsed-1").removeClass("hide"); $('.close-2').addClass("hide"); }); $(".close-1").click(function() { $('.close-1').addClass("hide"); $('.open-1') .removeClass("hide");$(".collapsed-1").addClass("hide"); }); $(".open-2").click(function() { $('.open-2').addClass("hide"); $('.open-1').removeClass("hide");$(".collapsed-2").removeClass("hide"); $('.close-1').addClass("hide"); $('.close-2').removeClass("hide");$(".collapsed-1").addClass("hide"); }); $(".close-2").click(function() { $('.open-2').removeClass("hide");$(".collapsed-2").addClass("hide"); $('.close-2').addClass("hide"); }); }); </script> I was trying at creative for the variables lol. - - - Updated - - - I commented out where('userid', $client->id) so you can see this public https://btwebnetwork.com/accounts/ - - - Updated - - - HA - and removed the rouge fa-fw classes. I'm only fairly experienced with PHP Javascript, enough to be dangerous anyway, but I'm sure there are many ways I could improve the code. I'm open to suggestions. I would like it clean and tidy and minimal 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 12, 2017 Share Posted February 12, 2017 I was trying at creative for the variables lol. I think my point was if there was any need for them - not to move them to a separate include file! unless you were going to use those same variables in multiple hooks, or a massive hook, I personally wouldn't bother to use them - you gain nothing by using them, and it would make the code clearer just to code the output normally. I commented out where('userid', $client->id) so you can see this public https://btwebnetwork.com/accounts/ it's worth noting that the js part of the hook wouldn't work if 3 or more results were generated by the query - the first two could open/close, but none after that. also, you could tweak your query to check if the domain is active (e.g pointless adding a link if the account has been cancelled). and what happens if the query contains no results - it still creates the sidebar. I'm open to suggestions. I would like it clean and tidy and minimal clean and tidy is good... but it has to be readable to others if you're posting it here - i'm all for taking shortcuts - but not if you can get lost using them! 0 Quote Link to comment Share on other sites More sharing options...
jarod Posted February 13, 2017 Author Share Posted February 13, 2017 I do intend to use the variables for further development. If any of them need adjusting it's just easier to manage. Learned that was worth the hassle lol. The include also helps keep things organized. How would I check against an active domain / ? The js can be manually cloned which is no ideal imo. Any direction in consolidating this it would be appreciated. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 13, 2017 Share Posted February 13, 2017 I do intend to use the variables for further development. If any of them need adjusting it's just easier to manage. Learned that was worth the hassle lol. each to their own! The include also helps keep things organized. as above - it's giving WHMCS more chance to fail calling multiple files... How would I check against an active domain / ? as it's in the table you're querying, it's just another where to the query... $domain = Capsule::table('tblhosting') ->where('userid', $client->id) ->where('packageid','1') ->where('domainstatus','Active') ->get(); The js can be manually cloned which is no ideal imo. Any direction in consolidating this it would be appreciated. I had the whole thing rewritten in 15 mins on Saturday (in 1 file) and working fine with multiple children... but got interrupted during further tweaks and didn't save the finished working file - so when I tried it again yesterday, it wouldn't work. i'll take another look at it at the weekend (or sooner if I get the chance). 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.