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