{
protected $sessid="";
protected $user="";
- protected $roles;
- protected $rights;
- protected $flags;
+ protected $roles=array();
+ protected $rights=array();
+ protected $flags=array();
/**construct the session object, check validity*/
public function __construct($trans)
{
global $db,$session;
- $this->roles=array();
- $this->rights=array();
- $this->flags=array();
$sid=$trans->getHeader("SessionId");
$res=$db->select("session","sessionid,uname","sessionid=".$db->escapeString($sid));
if(count($res)>0){
$this->sessid=$sid;
$this->user=$res[0]["uname"];
$this->initRights();
- $this->initFlags();
}
$session=$this;
}
$session=new DummyWebSession;
}
- /**internal: retrieve and remember the rights of this user*/
+ /**internal: retrieve and remember the rights, roles, and flags of this user*/
protected function initRights()
{
global $db;
+ //get roles
$res=$db->select("userrole","role","uname=".$db->escapeString($this->user));
for($i=0;$i<count($res);$i++){
$this->roles[]=$res[$i][0];
- $res2=$db->select("roleright","rightname","rolename=".$db->escapeString($res[$i][0]));
- for($j=0;$j<count($res2);$j++)
- $this->rights[]=$res2[$j][0];
}
- }
-
- /**internal: retrieve and remember the flags of this user*/
- protected function initFlags()
- {
- global $db;
- #user flags
- $this->flags=array();
+ //get rights
+ $res=$db->select("roleright","rightname","rolename IN ".$db->escapeStringList($this->roles));
+ for($j=0;$j<count($res);$j++)
+ $this->rights[]=$res[$j][0];
+ //get flags
+ //user flags
$res=$db->select("user","uname,flags","uname=".$db->escapeString($this->user));
if(count($res)>0)
- $this->flags=explode(" ",$res[0]['flags']);
- #role flags
- $res=$db->select("userrole","role","uname=".$db->escapeString($this->user));
- for($i=0;$i<count($res);$i++){
- $res2=$db->select("role","flags","rolename=".$db->escapeString($res[$i][0]));
- if(count($res2)>0){
- foreach(explode(" ",$res2[0][0]) as $f)
- if(!in_array($f,$this->flags))
- $this->flags[]=$f;
- }
- }
+ foreach(explode(" ",$res[0]['flags']) as $f)
+ if(!in_array($f,$this->flags))
+ $this->flags[]=$f;
+ //role flags
+ $res=$db->select("role","flags","rolename IN ".$db->escapeStringList($this->roles));
+ for($j=0;$j<count($res);$j++)
+ foreach(explode(" ",$res[$j][0]) as $f)
+ if(!in_array($f,$this->flags))
+ $this->flags[]=$f;
}
/**returns all rights of this user*/
{
public function __construct()
{
+ //DO NOT call parent constructor:
+ // it would try to verify the session and deny us access
global $db;
- //there is no real user for web (so far)
- $this->user="(web)";
- //fake web role, web pages check for it
- $this->roles=array("_web");
- $this->flags=array("_web");
- //get rights
- $this->rights=array();
- $res2=$db->select("roleright","rightname","rolename='_web'");
- for($j=0;$j<count($res2);$j++)
- $this->rights[]=$res2[$j][0];
- //get flags
- $res2=$db->select("role","flags","rolename='_web'");
- if(count($res2)>0){
- foreach(explode(" ",$res2[0][0]) as $f)
- if(!in_array($f,$this->flags))
- $this->flags[]=$f;
- }
+ //there is often no real user for web (so we enforce it)
+ $this->user="_web";
+ //fake web role and flag, some objects check for it
+ $this->roles[]="_web";
+ $this->flags[]="_web";
+ //load rights, roles, etc.
+ $this->initRights();
}
}