Jump to content

Add Funds Restricted by User


SeanP

Recommended Posts

I need to restrict the Add Funds page to a select list of users.  I found the following hook written by Brian!, and modified it:

 

I would like to display some sort of Access Denied page, with a link to open a support ticket requesting access, instead of just redirecting the user.  What is the easiest way display a message and link on the Add Funds page, if the client does not have access?

<?php

# Allow Access To Add Funds Page Hook
# Written by brian! 

function allow_access_to_add_funds($vars) {
	
	$client = Menu::context('client');
	$afusers = array(5);
	if (!in_array($client->id,$afusers)) {
		header("Location: index.php");
		die;
	}
}
add_hook("ClientAreaPageAddFunds", 1, "allow_access_to_add_funds");

 

Link to comment
Share on other sites

I got it working.  First add a new Custom Client Field called "Enable Add Funds" with a field type of "Tick Box".  Make sure to set it as "Admin Only":

enable_addfunds.jpg.cfc793ef15da63dbff3477658ba91aca.jpg

 

Create a hook file under includes/hooks called "restrictaddfunds.php" with the code in it from the following link:

https://controlc.com/1bf20031

 

Now you can enable add funds on a client by client basis.

Link to comment
Share on other sites

  • 1 month later...

  

On 5/14/2021 at 4:27 AM, SeanP said:

I would like to display some sort of Access Denied page, with a link to open a support ticket requesting access, instead of just redirecting the user. 

 

I tried your hook but it simply don't load the page rather than showing message to open a support ticket.
Is that how it is working for you?

Link to comment
Share on other sites

if all you want is to show a message, then the quickest way would be to return the variable below inside your IF statement rather than the header/die in the hook above and that disables the page...

return array ("addfundsdisabled" => true);

JRmQiaj.png

the default message itself could be changed using Language Overrides.

another solution would be to manipulate the $errormessage variableif you wanted a more specific message for your situation.... though if this were me, i'd also be removing the sidebar/navbar links to the addfunds page for this user.

Link to comment
Share on other sites

My final hook is on the following link:

https://controlc.com/ab094610

It doesn't show any links for Add Funds and does not allow clients to access the Add Funds page, if the "Enable Add Funds" custom field is not checked for their account.  It also displays the Credit Balance and Add Funds link in the sidebar, if the custom field is enabled for the client.

Link to comment
Share on other sites

15 hours ago, brian! said:

you could probably save some lines by using $vars['templatefile'] to get the template name rather than trying to determine it by filtering on the URL action values.... would also allow you to post the code here directly.

I agree that would probably be a better approach.  Thanks.

Link to comment
Share on other sites

  • 2 years later...
On 24/06/2021 at 7:26 AM, SeanP said:

I agree that would probably be a better approach.  Thanks.

Hey Sean! Any chance you could re-share the code? It seems like the link died, probably too optimistic to think it would work 3 years later 😄

Thanks!

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