| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
| 7 |
|
// mungled the namespaces |
| 8 |
|
// |
| 9 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
| 10 |
|
// + always (re-)tries to connect |
| 11 |
|
// |
| 12 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
| 13 |
|
// + caching mechanisms more configurable now |
| 14 |
|
// |
| 15 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
| 16 |
|
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
| 17 |
|
// |
| 18 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 19 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 20 |
|
// |
| 21 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 22 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 23 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 24 |
|
// |
| 25 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 26 |
|
// + added function 'getUserGuid()' |
| 27 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 28 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
| 29 |
|
// |
| 30 |
|
// Revision 1.5 2002/12/12 21:34:32 joko |
| 31 |
|
// + fix in 'function update': invalidate data only if it's not for caching purposes |
| 32 |
|
// |
| 33 |
|
// Revision 1.4 2002/12/06 04:10:28 joko |
| 34 |
|
// + replaced 'xyzCache' through 'xyzProxy' |
| 35 |
|
// |
| 36 |
// Revision 1.3 2002/12/04 07:42:54 jonen |
// Revision 1.3 2002/12/04 07:42:54 jonen |
| 37 |
// + changes according to backend schema change |
// + changes according to backend schema change |
| 38 |
// |
// |
| 117 |
|
|
| 118 |
|
|
| 119 |
function _loadData() { |
function _loadData() { |
| 120 |
$this->pObject = new ProxyObject($this->state[id]); |
$this->meta[data_ready] = 1; |
| 121 |
if ($this->state[id]) { |
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 122 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 123 |
|
$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 124 |
|
if ($this->getUserGuid()) { |
| 125 |
$this->data = $this->pObject->getAttributes(); |
$this->data = $this->pObject->getAttributes(); |
| 126 |
} |
} |
|
$this->meta[data_ready] = 1; |
|
| 127 |
} |
} |
| 128 |
|
|
| 129 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
| 135 |
|
|
| 136 |
$this->_save("cache"); |
$this->_save("cache"); |
| 137 |
|
|
| 138 |
//$this->pObject->flushCache(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
| 139 |
|
|
| 140 |
} |
} |
| 141 |
|
|
| 142 |
function _save($type = '') { |
function _save($type = '') { |
| 143 |
|
//print Dumper($this->data); |
| 144 |
$this->pObject->save($this->data, $type); |
$this->pObject->save($this->data, $type); |
| 145 |
$this->meta[data_ready] = 0; |
// invalidate data only if it's not for caching purposes |
| 146 |
|
if ($type != 'cache') { |
| 147 |
|
$this->meta[data_ready] = 0; |
| 148 |
|
} |
| 149 |
} |
} |
| 150 |
|
|
| 151 |
function save() { |
function save() { |
| 164 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 165 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
| 166 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 167 |
|
if($objectId) { |
| 168 |
|
connectdb(); |
| 169 |
|
$guid = $response[guid]; |
| 170 |
|
$username = $this->get('userData.username'); |
| 171 |
|
$password = $this->get('userData.password'); |
| 172 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 173 |
|
$res = send_sql($sql); |
| 174 |
|
} |
| 175 |
|
else { |
| 176 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 177 |
|
$site->session->set('register_error', 'rpc_error'); |
| 178 |
|
$site->redirect( getlink('/pub/register/') ); |
| 179 |
|
} |
| 180 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 181 |
} |
} |
| 182 |
|
|
|
function _getHKR($key) { |
|
|
$attr_arr = split('\.', $key); |
|
|
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
|
|
return $attr_hkr; |
|
|
} |
|
|
|
|
| 183 |
function get($attr) { |
function get($attr) { |
| 184 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 185 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 186 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
| 187 |
} |
} |
| 188 |
function set($attr, $val) { |
function set($attr, $val) { |
| 189 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 190 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 191 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
| 192 |
} |
} |
| 193 |
|
|
| 194 |
function isLoggedOn() { |
function isLoggedOn() { |
| 202 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 203 |
connectdb(); |
connectdb(); |
| 204 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 205 |
$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'"; |
| 206 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 207 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 208 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 211 |
//return $uservars_db; |
//return $uservars_db; |
| 212 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 213 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 214 |
|
$this->state[guid] = $row[guid]; |
| 215 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 216 |
$this->_saveState(); |
$this->_saveState(); |
| 217 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
| 218 |
return 1; |
return 1; |
| 219 |
} else { |
} else { |
| 220 |
return 0; |
return 0; |
| 235 |
} |
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
function update(&$uservars) { |
function update($vars) { |
| 239 |
$this->setPostVars($uservars); |
$this->setPostVars($vars); |
| 240 |
$data = $this->_transformInputData($uservars); |
//print Dumper($vars); |
| 241 |
|
$data = $this->_transformInputData($vars); |
| 242 |
$this->_saveData($data); |
$this->_saveData($data); |
| 243 |
} |
} |
| 244 |
|
|
| 247 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 248 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 249 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 250 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 251 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 252 |
|
$target[$key_target] = $val; |
| 253 |
|
} |
| 254 |
} |
} |
| 255 |
return $target; |
return $target; |
| 256 |
} |
} |
| 260 |
global $site; |
global $site; |
| 261 |
|
|
| 262 |
// get information about user from site |
// get information about user from site |
| 263 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
| 264 |
|
|
| 265 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
| 266 |
|
|
| 267 |
// get information about session from php |
// get information about session from php |
| 268 |
$session_id = session_id(); |
$session_id = session_id(); |
| 339 |
return $this->state[id]; |
return $this->state[id]; |
| 340 |
} |
} |
| 341 |
|
|
| 342 |
|
function getUserGuid() { |
| 343 |
|
return $this->state[guid]; |
| 344 |
|
} |
| 345 |
|
|
| 346 |
function getPostVars() { |
function getPostVars() { |
| 347 |
return $this->state[postvars]; |
return $this->state[postvars]; |
| 357 |
} |
} |
| 358 |
|
|
| 359 |
function hadTimeout() { |
function hadTimeout() { |
| 360 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 361 |
} |
} |
| 362 |
|
|
| 363 |
} |
} |