00001 <?php
00006 include_once("core/system/JBaseObject.class.php");
00007 include_once("core/utils/JSession.class.php");
00008
00009
00010 define(JCONTEXT_SESSION_VAR, "james-jcontext");
00011 define(GLOBAL_GROUP, "GG");
00012
00024 class JContext extends JBaseObject
00025 {
00026 var $logged;
00027 var $uid;
00028 var $gid;
00029 var $moduleStack;
00030
00031
00032 var $roleId;
00033 var $anonymous;
00034
00042 function JContext()
00043 {
00044 $this->SetLogged(false);
00045 }
00046
00059 function &GetInstance()
00060 {
00061 static $ob;
00062
00063 if (! isset($ob))
00064 {
00065
00066 if (JSession::ExistsVar(JCONTEXT_SESSION_VAR))
00067 {
00068 $ob = JSession::GetVar(JCONTEXT_SESSION_VAR);
00069 }
00070 else
00071 {
00072 $ob = new JContext();
00073 $ob->_UpdateSession();
00074 }
00075
00076
00077
00078
00079
00080 register_shutdown_function(array(&$ob, _UpdateSession));
00081 }
00082 return $ob;
00083 }
00084
00088 function _UpdateSession()
00089 {
00090 JSession::SetVar(JCONTEXT_SESSION_VAR, $this);
00091 }
00092
00097 function IsLogged()
00098 {
00099 return $this->logged;
00100 }
00101
00106 function SetLogged($logged)
00107 {
00108 $this->logged = $logged;
00109 if (!$logged)
00110 {
00111 $this->uid = 0;
00112 $this->gid = 0;
00113 $this->moduleStack = array();
00114 $this->roleid = 0;
00115 $this->anonymous = false;
00116 }
00117 }
00118
00123 function GetActiveUserId()
00124 {
00125 return $this->uid;
00126 }
00127
00132 function SetActiveUserId($uid)
00133 {
00134 $this->uid = $uid;
00135 }
00136
00141 function GetActiveGroupId()
00142 {
00143 return $this->gid;
00144 }
00145
00150 function SetActiveGroupId($gid)
00151 {
00152 $this->gid = $gid;
00153 }
00154
00159 function GetActiveModuleId()
00160 {
00161 if (count($this->modulestack) > 0)
00162 {
00163
00164 $value = $this->modulestack[count($this->modulestack)-1];
00165
00166
00167 return $value["mid"];
00168 }
00169 else
00170 return null;
00171 }
00172
00178 function PushActiveModule($mid, $rmgId=0)
00179 {
00180 $value["mid"] = $mid;
00181 $value["rmgid"] = $rmgId;
00182
00183 $this->modulestack[] = $value;
00184 }
00185
00190 function PopActiveModule()
00191 {
00192 $value = array_pop($this->modulestack);
00193
00194 if ($value == null)
00195 return $value;
00196 else
00197 return $value["mid"];
00198 }
00199
00204 function GetActiveRmgId()
00205 {
00206 if (count($this->modulestack) > 0)
00207 {
00208
00209 $value = $this->modulestack[count($this->modulestack)-1];
00210
00211
00212 return $value["rmgid"];
00213 }
00214 else
00215 return null;
00216 }
00217
00222 function GetActiveRoleId()
00223 {
00224 return $this->roleid;
00225 }
00226
00231 function SetActiveRoleId($rid)
00232 {
00233 $this->roleid = $rid;
00234 }
00235
00240 function IsAnonymous()
00241 {
00242 return $this->anonymous;
00243 }
00244
00249 function SetAnonymous($anon)
00250 {
00251 $this->anonymous = $anon;
00252 }
00253
00258 function IsGlobalGroup()
00259 {
00260 return $this->gid == GLOBAL_GROUP;
00261 }
00262 }
00263 ?>