21
Let's say that you are not using a module page, let's say that you want to create your own page in the root of your system and have 2 templates ready, one for regular users, other for privileged users.
Here is a complete example for that page:
//loads XOOPS framework, xoopsUser
include "mainfile.php";
//loads template class and prepares blocks
include_once XOOPS_ROOT_PATH . '/header.php';
//get current user id
$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
//get groups from this user, if any
$member_handler =& xoops_gethandler('member');
$groups =& $member_handler->getGroupsByUser($uid, true);
//the above method will give as an array of objects, lets get the name of each group
$usergroups = array();
foreach ($groups as $group) {
$usergroups[] = $group->getVar('name');
}
//prepare our (not cached, and not editable from admin) custom template
$tpl = new XoopsTpl();
//We have the groups names, now we will see if 'your_group' is one of them
if (in_array('your_group', $usergroups)) {
//yes it is, let us display our special page
$tpl->display(XOOPS_ROOT_PATH . '/your_group_template.html');
} else {
//sorry, you must subscribe our service first
$tpl->display(XOOPS_ROOT_PATH . '/your_nogroup_template.html');
}
//this will render this page inside your theme, with blocks and everything ;-)
include_once XOOPS_ROOT_PATH . '/footer.php';
?>