MyBB Community Forums

Full Version: No Permissions Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I have a custom page which is only accessible to certain user groups, this is done by the following code in the actual file on the server, not the template:

if(!in_array($mybb->user['usergroup'], array('3','4','6','10')))
{
     error_no_permission();
} 

I would like to change the text that the users see when they try to access that page, if they are not allowed to.

I do not want to edit the default no permissions template as this will do the same for all other pages, I want the error message that users see to be unique for this page.

I tried creating a new error template called 'error_nopermission2' however, on the file itself, I do not know how to edit the code above to use the new error message. I always get problems such as 'Fatal error: Call to undefined function error_no_permission2()'.

What do you suggest?
You might consider "error('title', 'content')" which allows you to specify what goes in the box yourself. 'Content' is directly inserted into the page so you can use HTML to create a form if you want it.
Thanks, but how do I add a login box? It's the only thing I can't get to work.
You can't just call a function without declaring it first. If you want to keep that no permissions page different then first make a copy of the actual error_no_permission function and make the changes to it.

In your custom file paste this edited function of the original error_no_permission:

function error_no_permission2()
{
	global $mybb, $theme, $templates, $db, $lang, $plugins, $session;

	$time = TIME_NOW;

	$noperm_array = array (
		"nopermission" => '1',
		"location1" => 0,
		"location2" => 0
	);

	$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'", 1);
	$url = htmlspecialchars_uni("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);

	if($mybb->user['uid'])
	{
		$lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, $mybb->user['username']);
		eval("\$errorpage = \"".$templates->get("error_nopermission_loggedin")."\";");
	}
	else
	{
		eval("\$errorpage = \"".$templates->get("error_nopermission2")."\";");
	}

	error($errorpage);
}

With the above in your custom script, you can now add a error_nopermission2 template and edit it to your liking, and then just call it using error_no_permission2()
(2011-04-09, 11:02 AM)- G33K - Wrote: [ -> ]You can't just call a function without declaring it first. If you want to keep that no permissions page different then first make a copy of the actual error_no_permission function and make the changes to it.

In your custom file paste this edited function of the original error_no_permission:

function error_no_permission2()
{
	global $mybb, $theme, $templates, $db, $lang, $plugins, $session;

	$time = TIME_NOW;

	$noperm_array = array (
		"nopermission" => '1',
		"location1" => 0,
		"location2" => 0
	);

	$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'", 1);
	$url = htmlspecialchars_uni("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);

	if($mybb->user['uid'])
	{
		$lang->error_nopermission_user_username = $lang->sprintf($lang->error_nopermission_user_username, $mybb->user['username']);
		eval("\$errorpage = \"".$templates->get("error_nopermission_loggedin")."\";");
	}
	else
	{
		eval("\$errorpage = \"".$templates->get("error_nopermission2")."\";");
	}

	error($errorpage);
}

With the above in your custom script, you can now add a error_nopermission2 template and edit it to your liking, and then just call it using error_no_permission2()

Sorry, slightly confused what to do at the start.

You say 'first make a copy of the actual error_no_permission function' - how do I do that?
Any help? Thanks.
You can do it without making core edit. This is a small hack to do it:
$lang->error_nopermission_user_1 =
	$lang->error_nopermission_guest_1 = 
	"This is my custom error message to display on the no permission page.";
error_no_permission();

If you are calling this from a function, make sure you load the $lang variable from the global scope:
function foobar()
{
global $lang;
// ...
}
I am even more confused now, I rather do the core edit and have another template. I just don't get how to make the first copy - where is that file?
(2011-05-14, 09:58 AM)sharadjalota456 Wrote: [ -> ]I am even more confused now, I rather do the core edit and have another template. I just don't get how to make the first copy - where is that file?

The original error_no_permission() function is in /inc/functions.php
Thanks! Sorted Smile