| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
| 7 |
|
// + caching mechanisms more configurable now |
| 8 |
|
// |
| 9 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
| 10 |
|
// + now utilizing Data::Driver::Proxy and Data::Deep |
| 11 |
|
// |
| 12 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 13 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 14 |
|
// |
| 15 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 16 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 17 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 18 |
|
// |
| 19 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 20 |
|
// + added function 'getUserGuid()' |
| 21 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 22 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
| 23 |
|
// |
| 24 |
|
// Revision 1.5 2002/12/12 21:34:32 joko |
| 25 |
|
// + fix in 'function update': invalidate data only if it's not for caching purposes |
| 26 |
|
// |
| 27 |
|
// Revision 1.4 2002/12/06 04:10:28 joko |
| 28 |
|
// + replaced 'xyzCache' through 'xyzProxy' |
| 29 |
|
// |
| 30 |
|
// Revision 1.3 2002/12/04 07:42:54 jonen |
| 31 |
|
// + changes according to backend schema change |
| 32 |
|
// |
| 33 |
// Revision 1.2 2002/12/03 16:47:22 joko |
// Revision 1.2 2002/12/03 16:47:22 joko |
| 34 |
// - function preLogout() |
// - function preLogout() |
| 35 |
// + function preLogout($autologout = 0) |
// + function preLogout($autologout = 0) |
| 111 |
|
|
| 112 |
|
|
| 113 |
function _loadData() { |
function _loadData() { |
| 114 |
$this->pObject = new ProxyObject($this->state[id]); |
$this->meta[data_ready] = 1; |
| 115 |
if ($this->state[id]) { |
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 116 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 117 |
|
$this->pObject = mkObject('Data::Driver::Proxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ) ) ); |
| 118 |
|
if ($this->getUserGuid()) { |
| 119 |
$this->data = $this->pObject->getAttributes(); |
$this->data = $this->pObject->getAttributes(); |
| 120 |
} |
} |
|
$this->meta[data_ready] = 1; |
|
| 121 |
} |
} |
| 122 |
|
|
| 123 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
| 129 |
|
|
| 130 |
$this->_save("cache"); |
$this->_save("cache"); |
| 131 |
|
|
| 132 |
//$this->pObject->flushCache(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
| 133 |
|
|
| 134 |
} |
} |
| 135 |
|
|
| 136 |
function _save($type = '') { |
function _save($type = '') { |
| 137 |
|
//print Dumper($this->data); |
| 138 |
$this->pObject->save($this->data, $type); |
$this->pObject->save($this->data, $type); |
| 139 |
$this->meta[data_ready] = 0; |
// invalidate data only if it's not for caching purposes |
| 140 |
|
if ($type != 'cache') { |
| 141 |
|
$this->meta[data_ready] = 0; |
| 142 |
|
} |
| 143 |
} |
} |
| 144 |
|
|
| 145 |
function save() { |
function save() { |
| 158 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 159 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
| 160 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 161 |
|
if($objectId) { |
| 162 |
|
connectdb(); |
| 163 |
|
$guid = $response[guid]; |
| 164 |
|
$username = $this->get('userData.username'); |
| 165 |
|
$password = $this->get('userData.password'); |
| 166 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 167 |
|
$res = send_sql($sql); |
| 168 |
|
} |
| 169 |
|
else { |
| 170 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 171 |
|
$site->session->set('register_error', 'rpc_error'); |
| 172 |
|
$site->redirect( getlink('/pub/register/') ); |
| 173 |
|
} |
| 174 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 175 |
} |
} |
| 176 |
|
|
|
function _getHKR($key) { |
|
|
$attr_arr = split('\.', $key); |
|
|
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
|
|
return $attr_hkr; |
|
|
} |
|
|
|
|
| 177 |
function get($attr) { |
function get($attr) { |
| 178 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 179 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 180 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
| 181 |
} |
} |
| 182 |
function set($attr, $val) { |
function set($attr, $val) { |
| 183 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 184 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 185 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
| 186 |
} |
} |
| 187 |
|
|
| 188 |
function isLoggedOn() { |
function isLoggedOn() { |
| 196 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 197 |
connectdb(); |
connectdb(); |
| 198 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 199 |
$sql = "SELECT user_oid, uname, pass FROM td_users WHERE uname='$user'"; |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
| 200 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 201 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 202 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 205 |
//return $uservars_db; |
//return $uservars_db; |
| 206 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 207 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 208 |
|
$this->state[guid] = $row[guid]; |
| 209 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 210 |
$this->_saveState(); |
$this->_saveState(); |
| 211 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
| 212 |
return 1; |
return 1; |
| 213 |
} else { |
} else { |
| 214 |
return 0; |
return 0; |
| 229 |
} |
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
function update(&$uservars) { |
function update($vars) { |
| 233 |
$this->setPostVars($uservars); |
$this->setPostVars($vars); |
| 234 |
$data = $this->_transformInputData($uservars); |
//print Dumper($vars); |
| 235 |
|
$data = $this->_transformInputData($vars); |
| 236 |
$this->_saveData($data); |
$this->_saveData($data); |
| 237 |
} |
} |
| 238 |
|
|
| 241 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 242 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 243 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 244 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 245 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 246 |
|
$target[$key_target] = $val; |
| 247 |
|
} |
| 248 |
} |
} |
| 249 |
return $target; |
return $target; |
| 250 |
} |
} |
| 254 |
global $site; |
global $site; |
| 255 |
|
|
| 256 |
// get information about user from site |
// get information about user from site |
| 257 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
| 258 |
|
|
| 259 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
| 260 |
|
|
| 261 |
// get information about session from php |
// get information about session from php |
| 262 |
$session_id = session_id(); |
$session_id = session_id(); |
| 288 |
function getAccountSum() { |
function getAccountSum() { |
| 289 |
// store additional user-data to state |
// store additional user-data to state |
| 290 |
if (!$this->state[accountSum]) { |
if (!$this->state[accountSum]) { |
| 291 |
$this->state[accountSum] = $this->get("financeInfo.accountSum"); |
$this->state[accountSum] = $this->get("account.amount"); |
| 292 |
$this->_saveState(); |
$this->_saveState(); |
| 293 |
} |
} |
| 294 |
return $this->state[accountSum]; |
return $this->state[accountSum]; |
| 297 |
function getAccountCurrency() { |
function getAccountCurrency() { |
| 298 |
// store additional user-data to state |
// store additional user-data to state |
| 299 |
if (!$this->state[accountCurrency]) { |
if (!$this->state[accountCurrency]) { |
| 300 |
$this->state[accountCurrency] = $this->get("financeInfo.currency"); |
$this->state[accountCurrency] = $this->get("account.currency"); |
| 301 |
$this->_saveState(); |
$this->_saveState(); |
| 302 |
} |
} |
| 303 |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
| 333 |
return $this->state[id]; |
return $this->state[id]; |
| 334 |
} |
} |
| 335 |
|
|
| 336 |
|
function getUserGuid() { |
| 337 |
|
return $this->state[guid]; |
| 338 |
|
} |
| 339 |
|
|
| 340 |
function getPostVars() { |
function getPostVars() { |
| 341 |
return $this->state[postvars]; |
return $this->state[postvars]; |
| 351 |
} |
} |
| 352 |
|
|
| 353 |
function hadTimeout() { |
function hadTimeout() { |
| 354 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
} |
} |