4 /* Registered user, logged in (i.e. yourself) */
5 class authuser
extends reguser
7 function __construct($prefetch)
9 $fields = array('`userid`', '`alias`', '`password`', '`level`', '`timezone`', '`theme`', '`date_format`');
11 $fields = array_merge($fields, $prefetch);
13 $this->attrcache
= $GLOBALS['DB']->query('SELECT '.implode(', ', $fields).'
14 FROM `users` WHERE `userid` = @userid')->fetch_assoc();
15 $this->namecache
[$this->attrcache
['userid']] = $this->attrcache
['alias'];
17 $this->userlinks
= array(
18 $this->attrcache
['alias'].' ('.( $this->attrcache
['level'] == LVL_DEV ?
'∞' : $this->attrcache
['level'] ).')'
19 => 'user?id='.$this->attrcache
['userid']
22 if ( $this->attrcache
['level'] >= LVL_ADMIN
)
23 $this->userlinks
['Admin Stuff'] = 'admin';
24 if ( $this->attrcache
['password'] === null )
25 $this->userlinks
['Change Password'] = 'passwd';
28 $GLOBALS['DB']->query('UPDATE `users` SET
29 `useragent` = \''.$GLOBALS['DB']->escape_string(substr($_SERVER['HTTP_USER_AGENT'], 0, 130)).'\',
30 `last_active_date` = UNIX_TIMESTAMP(),
31 `last_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
32 WHERE `userid` = @userid');
35 function __get($varname)
37 if ( defined('DEVELOPER') )
40 if ( !array_key_exists($varname, $this->attrcache
) ) {
41 if ( defined('DEVELOPER') )
42 user_error('Uncached $user::get:<pre>'.print_r(debug_backtrace(), true).'</pre>', E_USER_WARNING
);
48 $fieldname = 'INET_NTOA(`'.$varname.'`)';
51 $fieldname = 'AES_DECRYPT(`'.$varname.'`, `reg_ip`)';
54 $fieldname = '`'.$varname.'`';
58 $q = $GLOBALS['DB']->query('SELECT '.$fieldname.' AS `'.$varname.'` FROM `users` WHERE `userid` = @userid');
59 if ( $GLOBALS['DB']->error
)
60 throw new OutOfBoundsException('MySQL error in authuser::__get('.$varname.'): '.$GLOBALS['DB']->error
);
62 $this->attrcache
[$varname] = $q->fetch_object()->$varname;
64 if ( array_key_exists($varname, $this->attrcache
) ) {
65 return $this->attrcache
[$varname];
67 throw new OutOfBoundsException('Invalid attribute name $user->'.$varname);
70 function __set($varname, $value)
72 if ( defined('DEVELOPER') )
75 $this->attrcache
[$varname] = $value;
81 if ( strpos($value, ':') !== false ) {
85 $value = 'INET_ATON(\''.$value.'\')';
88 $value = 'AES_ENCRYPT(\''.$value.'\', `reg_ip`)';
91 if ( is_int(sqrt($value)) && sqrt($value) > $this->attrcache
['invites']
92 && $GLOBALS['DB']->query('SELECT COUNT(*) AS `c` FROM `invites`
93 WHERE `userid` = @userid')->fetch_object()->c
< 5
95 $GLOBALS['DB']->query('INSERT INTO `invites` VALUES (NULL, @userid, UUID())');
96 $GLOBALS['DB']->query('UPDATE `users` SET `invites` = (`invites` + 1) WHERE `userid` = @userid');
101 $value = '\''.$GLOBALS['DB']->escape_string($value).'\'';
105 $GLOBALS['DB']->query('UPDATE `users` SET `'.$varname.'` = '.$value.' WHERE `userid` = @userid');
106 if ( $GLOBALS['DB']->error
)
107 throw new UnexpectedValueException('MySQL error in authuser::__set('.$varname.' = '.$value.'): '.$GLOBALS['DB']->error
);
111 function namelink($id, $name = null)
113 if ( empty($this->namecache
[$id]) ) {
114 if ( $name === null )
115 $this->namecache
[$id] = $GLOBALS['DB']->query('SELECT `alias` FROM `users`
116 WHERE `userid` = '.$id)->fetch_object()->alias
;
118 $this->namecache
[$id] = $name;
120 return '<a href="user?id='.$id.'">'.$this->namecache
[$id].'</a>';
123 // furdate v62.44 OMEGA
124 function fdate($timestamp)
126 return ( $timestamp == 0 ?
'N/A' : date($this->attrcache
['date_format'], $timestamp) );