SeanP Posted May 13, 2021 Share Posted May 13, 2021 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"); 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted May 14, 2021 Author Share Posted May 14, 2021 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": 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. 0 Quote Link to comment Share on other sites More sharing options...
Sufiyan Shaikh Posted June 20, 2021 Share Posted June 20, 2021 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? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 20, 2021 Share Posted June 20, 2021 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); 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. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted June 23, 2021 Author Share Posted June 23, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 23, 2021 Share Posted June 23, 2021 6 hours ago, SeanP said: My final hook is on the following link: https://controlc.com/ab094610 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. 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted June 24, 2021 Author Share Posted June 24, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
jayjay Posted April 28 Share Posted April 28 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! 0 Quote Link to comment Share on other sites More sharing options...
SeanP Posted April 30 Author Share Posted April 30 On 4/28/2024 at 7:09 AM, jayjay said: 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! Here is an updated link: https://controlc.com/d0ac5777 1 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.