Jump to content

Restrict access to certain pages


aspidagrant

Recommended Posts

As far as I know WHMCS only blocks people based on if they are logged in or out.

that's true up to a point... but once logged in, you should then have access to a lot of information that you can use to add rules to the templates.

 

you can assign clients to Client Groups - http://docs.whmcs.com/Client_Groups - and then use that setting to either allow or block them from seeing certain pages/info/products etc...

 

as an example, let's say you have some clients that you don't want to allow to become affiliates, all that you should need to do is assign them to a client group, and modify your affiliatessignup.tpl template and replace the first line...

 

{if $affiliatesystemenabled and $clientsdetails.groupid eq 1}

 

now if someone logs in who is in that client group (but not an existing affiliate already) and visits the affiliates page, then they will see the "We do not currently offer an affiliate system to our clients." page... everyone else should see the signup page.

 

to answer your specific question though, let's now assume you've put all the clients that you want to access the affiliates page into a client group... if you add the following line into affiliates.tpl (i've done it after the second {include} @ line 10)...

 

{if $clientsdetails.groupid neq 2}message for those not having access{else}

remember to add a closing {/if} at the end of the file.

 

so anyone in client group (id=2) will see the affiliates page as normal (i.e their stats if they're an affiliate already), everyone else will see the message after the if statement.

 

the array value that you will want to use is $clientsdetails.groupid - and then remember the following...

 

  • if they are not logged in, the above variable won't exist.
  • if they are logged in but not in any client group, it will equal 0
  • if they are logged in and in a client group, it will equal the id of that client group.

btw - the quick way to get the id value of a client group is to click the edit button in the client groups page in admin - the url will then show in the browser...

 

configclientgroups.php?action=edit&id=1

so if a member of the above client group was logged in, $clientsdetails.groupid would equal 1.

Link to comment
Share on other sites

@brian! - That is awesome! Thank you so much for taking your time to clearly explain that. It all worked perfectly.

 

I do have 1 more question to take it a step further:

 

If I want multiple groups to see the affiliate info, but only 1 to be excluded, how do I do that?

 

I currently have group id=2 as my affiliates:

 

{if $affiliatesystemenabled and $clientsdetails.groupid eq 2}

 

Group 4 is "client" and is the only group that should not see the affiliate group.

Link to comment
Share on other sites

it depends if it's easier for you to block groups or allow groups - you only need to do one, so choose which is easiest and write the logic accordingly.

 

if you have multiple groups to either block or allow, you can use OR in the {if} statements to group them together... for example..

 

{if $affiliatesystemenabled and ($clientsdetails.groupid eq 2 or $clientsdetails.groupid eq 3)}

so in this case, the affiliate system must be enabled and the client must be in group 2 or 3... though take care when using NEQ and multiple OR as it can get confusing as to what the logic should be!

 

one other thought that occurred to me about this last night is you could modify header.tpl to remove the "Affiliates" menu links (if you have them).

 

in the "Default" template header.tpl, there are two instances of the link - one shows when they're not logged in, and the other shows when they are...

 

if you didn't want group 4 clients to see the menu link when logged in, you could modify header.tpl by replacing..

 

<ul class="nav">
<li><a href="affiliates.php">{$LANG.affiliatestitle}</a></li>
</ul>

with...

 

{if $clientsdetails.groupid neq 4}        
<ul class="nav">
<li><a href="affiliates.php">{$LANG.affiliatestitle}</a></li>
</ul>
{/if}

so everyone not in group 4 will see the link, those in group 4 will not...

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