checkgrant
- Ariadne >
- Library >
- Ariadne 2.2 >
- Manuals >
- Programmers Reference >
- Classes >
- Object >
- PINP Methods >
(bool) checkgrant($grant, $modifier=ARTHISTYPE)
Checks whether the current user has the specified grant.
| Argument | Description |
|---|---|
| (string) $grant | The grant needed. |
| (string) $modifier | The needed modifier on the grant. |
checkgrant() checks whether the current user has the specified grant. It will return true if the user has the grant, false otherwise.
The modifier is a string which allows you to constrain
the grant. Usually the modifier is set to the current type. The user might
for example have the grant 'edit ( ppage, pdir )' , this
means that the user may only edit objects of class 'ppage' and
'pdir'. The 'ppage' and 'pdir' parts in
this case are the modifier, and the value you use in
checkgrant() is what it is checked against.
The default value is the same as the class of the object
on which the template runs, but you could also create other modifiers, just as
you can create other grants. Just remember that when no modifier is set in the
grants assigned to the user, the modifier argument in checkgrant is ignored. So,
if the user simply has 'edit' grants, he or she may edit any kind
of object, since no modifier was specified.
Using checkgrant() to add an edit button
only when the user has the needed grant:
<pinp>
if (checkgrant("edit")) {
// do something extra, like:
</pinp>
<input type="button" name="edit" value="Edit"
onclick="edit();">
<pinp>
}
</pinp>
Using checkgrant() to show a login screen
when the user doesn't have the needed grant:
<pinp>
if (checkgrant("edit")) {
// show the normal page, e.g.:
call('view.content.html');
} else {
call("user.login.html");
}
</pinp>

