This is what I found at
Adding Group Permissions and starting playing around with it in some of my test modules.
$gperm_handler =& xoops_gethandler('groupperm');
$cando = $gperm_handler->checkRight($perm_name, 1, $groups, $mod_id)
if ($cando){
echo 'true';
}else{
echo 'false';
}
What I wanted to come up with was a simple class that I could check all permissions for that user through out my module. What I came up with seems to work, but I'm not that great with security and just wanted to know if this is safe way to check my modules permissions or is there another direction I should go.
//Create new object while passing what I want to check
$replayPermissions = new replayPermissions('replay_permissions');
if ($replayPermissions->canDelete()){
echo 'True';
}else{
echo 'False';
}
Class itself, just to note is only checking one type of permissions "replay_permissions" that is for module wide and not just one specific id or item.
if (!defined('XOOPS_ROOT_PATH')) {
die("XOOPS root path not defined");
}
class replayPermissions {
private $isAdmin = false;
private $view = false;
private $submit = false;
private $edit = false;
private $delete = false;
private $download = false;
private $vote = false;
private $edit_others = false;
private $delete_others = false;
function replayPermissions()
{
$this->__construct();
}
function __construct($perm_name){
global $xoopsUser;
$uid = (is_object($xoopsUser)) ? intval($xoopsUser->uid()): 0;
$groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups(): XOOPS_GROUP_ANONYMOUS;
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->getByDirname('replay');
$mid = $module->getVar('mid');
$gperm_handler =& xoops_gethandler('groupperm');
$this->isAdmin = $gperm_handler->checkRight('system_admin', $uid, $groups);
$this->view = $gperm_handler->checkRight($perm_name, 1 , $groups, $mid);
$this->submit = $gperm_handler->checkRight($perm_name, 2 , $groups, $mid);
$this->edit = $gperm_handler->checkRight($perm_name, 3 , $groups, $mid);
$this->delete = $gperm_handler->checkRight($perm_name, 4 , $groups, $mid);
$this->download = $gperm_handler->checkRight($perm_name, 5 , $groups, $mid);
$this->vote = $gperm_handler->checkRight($perm_name, 6 , $groups , $mid);
$this->edit_others = $gperm_handler->checkRight($perm_name, 7 , $groups, $mid);
$this->delete_others = $gperm_handler->checkRight($perm_name, 8 , $groups, $mid);
}
function isAdmin() {
return $this->isAdmin;
}
function canView() {
return $this->view;
}
function canSubmit() {
return $this->submit;
}
function canEdit() {
return $this->edit;
}
function canDelete() {
return $this->delete;
}
function canDownload() {
return $this->download;
}
function canVote() {
return $this->vote;
}
function canEdit_others() {
return $this->edit_others;
}
function canDelete_others() {
return $this->delete_others;
}
}