Jump to content

Client sidebar


Recommended Posts

Hello,

 

Does anyone know how to detect what service group is being used in a hooks file to determine what sidebar to show.

 

<?php // hooks

use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")) {
   die("This file cannot be accessed directly");
}

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   // detect package service group (dedicated servers for example) ?

   // would I find that in the global $whmcs ?
});

 

Then does anyone know how to show which link on the sidebar is active, for example if I do the following.

 

<?php // hooks

use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")) {
   die("This file cannot be accessed directly");
}

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if ( ! is_null($primarySidebar->getChild('Service Details Actions')))
   {
       $Sidebar = $primarySidebar->getChild('Service Details Actions');

       $action = $_GET['action'];
       $service_id = $_GET['id'];
       $subaction = $_GET['subaction'];

       if($subaction == 'actions')
       {
           // set Actions link to active
       }
       else
       {
           $Sidebar->addChild('Actions',
           [
               'label' => 'Actions',
               'uri' => '/clientarea.php?action=' . $action . '&id=' . $service_id . '&subaction=actions',
           ]);            
       }

       /*
           OR
       */

       $Sidebar->addChild('Actions',
       [
           'label' => 'Actions',
           'uri' => '/clientarea.php?action=' . $action . '&id=' . $service_id . '&subaction=actions',
           '???' => ($subaction == 'actions' ? true : false),
       ]);            

   }
});

 

Any help would be amazing.

 

Thanks.

 

- - - Updated - - -

 

I'm sorry, I should have read the docs before posting, I see you can set the class using the setClass method

 

http://docs.whmcs.com/classes/classes/WHMCS.View.Menu.Item.html#method_setClass

 

So my only question would be the service type then.

Link to comment
Share on other sites

Another question, I'm busy creating a Provisioning module but its not reading the hooks file instead the module. The file is called hooks.php

 

If I add the code to the module file then it works but just refuses in the hooks.php file.

 

Btw I'm using V6.

Link to comment
Share on other sites

Never mind all, I've managed what I wanted by adding a extra field to the actions sidebar called removeme and just check if that button is there then run my action_hook.

 

<?php // hooks.php

use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")) {
   die("This file cannot be accessed directly");
}

add_hook('ClientAreaPrimarySidebar', 2, function(MenuItem $primarySidebar)
{
   if(is_null($primarySidebar->getChild('Service Details Overview')))
   {
      return;
   }

   if(is_null($primarySidebar->getChild('Service Details Actions')->getChild('Custom Module Button removeme')))
   {
       return;
   }

   $menu = $primarySidebar->getChild('Service Details Actions');
   $menu->removeChild("Custom Module Button removeme");

   $menu = $primarySidebar->getChild('Service Details Overview');
   $menu->removeChild("Information");

   $menu->addChild('Information', [
       'label' => 'Information',
       'uri' => '/clientarea.php?action=' . $_GET['action'] . '&id=' . $_GET['id'],
       'order' => 1,
   ])->setClass(( ! isset($_GET['modop']) ? 'active' : ''));

   $primarySidebar->getChild('Service Details Actions')->removeChild("Cancel");

});

 

Regarding it not reading my hooks.php file, it looks like I just add to increase the priority.

 

Hooks Debug: Hook Defined for Point: ClientAreaPrimarySidebar - Priority: 0 - Function Name: cpanel_defineSsoSidebarLinks

Hooks Debug: Hook Defined for Point: ClientAreaPrimarySidebar - Priority: 2 - Function Name: (anonymous function)

 

Hopefully all this questions/answers might help someone else

Link to comment
Share on other sites

  • 2 months later...

Hello,

Can you tell me if I set this when the menu link is accesed

"->setClass(( ! isset($_GET['modop']) ? 'active' : ''))"

why the menu remain with active class when I open another menu item (both remain active)?

Is this a way to remove class active for the first link?

Thank you!

Link to comment
Share on other sites

Hello,

Can you tell me if I set this when the menu link is accesed

"->setClass(( ! isset($_GET['modop']) ? 'active' : ''))"

why the menu remain with active class when I open another menu item (both remain active)?

Is this a way to remove class active for the first link?

Thank you!

where is your code?

Link to comment
Share on other sites

This is the php code:

 

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
if (!is_null($primarySidebar->getChild('My Account'))) {
$primarySidebar->getChild('My Account')->addChild('Arhiva SMS', array(
       'uri' => '/view_syssms.php',
       'label' => 'Arhiva SMS',
       'order' => 200,
   ))->setClass(( ! isset($_GET['modop']) ? 'active' : ''));
$primarySidebar->getChild('My Account')->addChild('Marketing', array(
       'uri' => '/marketing_email.php',
       'label' => 'Marketing',
       'order' => 201,
   ))->setClass(( ! isset($_GET['modop']) ? 'active' : '')); 
}
});

 

and it's happen like in example pictured atached

example.jpg

Link to comment
Share on other sites

This is the php code:

 

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{
if (!is_null($primarySidebar->getChild('My Account'))) {
$primarySidebar->getChild('My Account')->addChild('Arhiva SMS', array(
       'uri' => '/view_syssms.php',
       'label' => 'Arhiva SMS',
       'order' => 200,
   ))->setClass(( ! isset($_GET['modop']) ? 'active' : ''));
$primarySidebar->getChild('My Account')->addChild('Marketing', array(
       'uri' => '/marketing_email.php',
       'label' => 'Marketing',
       'order' => 201,
   ))->setClass(( ! isset($_GET['modop']) ? 'active' : '')); 
}
});

 

and it's happen like in example pictured atached

[ATTACH=CONFIG]9431[/ATTACH]

 

I've modified you code

<?php
use WHMCS\View\Menu\Item as MenuItem;

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

   $filename = basename($_SERVER['REQUEST_URI'], ".php");

   $parseFile = explode('.', $filename);

   if (!is_null($primarySidebar->getChild('My Account'))) { 

       $myAccount = $primarySidebar->getChild('My Account');
       $arhivaSMS = $myAccount->addChild('Arhiva SMS', array(
                                                   'uri' => '/view_syssms.php',
                                                   'label' => 'Arhiva SMS',
                                                   'order' => 200
                                                   ));
       if ($parseFile['0']=='view_syssms'){
           $myAccount->getChild('Arhiva SMS')->setClass('active');
       }

       $marketing  = $myAccount->addChild('Marketing', array(
                                                           'uri' => '/marketing_email.php',
                                                           'label' => 'Marketing',
                                                           'order' => 201,
                                                       ));
       if ($parseFile['0']=='marketing_email'){
           $myAccount->getChild('Marketing')->setClass('active');
       }
} 
});  

 

- - - Updated - - -

 

@kylevorster Can you please tell me, how do you add some extra Item (Link) to the actions sidebar?

here is how to add extra link inside product/service details, like in here:

http://demo.whmcs.com/clientarea.php?action=productdetails&id=313

 

<?php
use WHMCS\View\Menu\Item as MenuItem;

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

   if (!is_null($primarySidebar->getChild('Service Details Actions'))) {

       $primarySidebar->getChild('Service Details Actions')->addChild('extraLinkUnqiueName', array(
                                                   'uri' => '/LinkToSomeWhere.php',
                                                   'label' => 'Extra Link',
                                                   'order' => 100
                                                   ));

   }

});

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