You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

<?php
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
class Perms_Context
{
private static $permissionList = [];
private $previousUser;
private $previousGroupList;
private $user;
private $groupList = [];
public static function setPermissionList($allperms)
{
$permissionList = array_keys($allperms);
$shortPermList = array_map(function ($name) {
return substr($name, 7);
}, $permissionList);
self::$permissionList = $shortPermList;
}
public function __construct($user, $activate = true)
{
$tikilib = TikiLib::lib('tiki');
$this->user = $user;
$this->groupList = $tikilib->get_user_groups($user);
if ($activate) {
$this->activate();
}
}
public function overrideGroups(array $groupList)
{
$this->groupList = $groupList;
}
public function activate($globalize = false)
{
global $user, $globalperms;
$perms = Perms::getInstance();
$this->previousUser = $user;
$this->previousGroupList = $perms->getGroups();
$smarty = TikiLib::lib('smarty');
$user = $this->user;
$perms->setGroups($this->groupList);
$globalperms = Perms::get();
$globalperms->globalize(self::$permissionList, $smarty, false);
if (is_object($smarty)) {
$smarty->assign('globalperms', $globalperms);
}
}
public function activatePermanently()
{
global $user, $globalperms;
$perms = Perms::getInstance();
$smarty = TikiLib::lib('smarty');
$user = $this->user;
$perms->setGroups($this->groupList);
$globalperms = Perms::get();
$globalperms->globalize(self::$permissionList, $smarty, false);
if (is_object($smarty)) {
$smarty->assign('globalperms', $globalperms);
}
$this->previousUser = $user;
$this->previousGroupList = $perms->getGroups();
}
public function __destruct()
{
global $user, $globalperms;
$user = $this->previousUser;
$perms = Perms::getInstance();
$perms->setGroups($this->previousGroupList);
$globalperms = Perms::get();
}
}