fixed broken user.php
[specialops2.git] / lib / class.reguser.php
blob7163b3491f1a2a2fe4adbd9f7ef687a6a50c0512
1 <?php
2 // $Id$
4 /* Registered user, but not logged in */
5 class reguser extends anonuser
7 public $userid;
9 function __construct($userid, $prefetch = null)
11 parent::__construct();
13 $this->userid = $userid;
14 $this->attrcache = array();
16 $fields = array('`alias`', '`level`', '`timezone`', '`theme`');
17 if ( $prefetch )
18 $fields = array_merge($fields, $prefetch);
20 $this->attrcache = $GLOBALS['DB']->query('SELECT '.implode(', ', $fields).'
21 FROM `users` WHERE `userid` = '.$userid)->fetch_assoc();
22 $this->namecache[$userid] = $this->alias;
25 function __get($varname)
27 if ( !array_key_exists($varname, $this->attrcache) ) {
28 switch ( $varname ) {
29 case 'reg_ip':
30 case 'last_ip':
31 case 'last_login_ip':
32 $fieldname = 'INET_NTOA(`'.$varname.'`)';
33 break;
34 case 'password':
35 $fieldname = 'AES_DECRYPT(`'.$varname.'`, `reg_ip`)';
36 break;
37 default:
38 $fieldname = '`'.$varname.'`';
39 break;
42 $q = $GLOBALS['DB']->query('SELECT '.$fieldname.' AS `'.$varname.'` FROM `users` WHERE `userid` = '.$this->userid);
43 if ( $GLOBALS['DB']->error )
44 throw new OutOfBoundsException('MySQL error in authuser::_get('.$varname.'): '.$GLOBALS['DB']->error);
45 else
46 $this->attrcache[$varname] = $q->fetch_object()->$varname;
48 if ( array_key_exists($varname, $this->attrcache) ) {
49 return $this->attrcache[$varname];
50 } else
51 throw new OutOfBoundsException('Error in $user->_get('.$varname.' => '.$fieldname.'): attribute not available.');
54 function __set($varname, $value)
56 $this->attrcache[$varname] = $value;
57 switch ( $varname ) {
58 case 'reg_ip':
59 case 'last_ip':
60 case 'last_login_ip':
61 if ( strpos($value, ':') !== false ) {
62 $value = 'NULL';
63 break;
65 $value = 'INET_ATON(\''.$value.'\')';
66 break;
67 case 'password':
68 $value = 'AES_ENCRYPT(\''.$value.'\', `reg_ip`)';
69 break;
70 case 'points':
71 if ( $value > 20 && sqrt($value) == floor(sqrt($value))
72 && $GLOBALS['DB']->query('SELECT COUNT(*) AS `c` FROM `invites`
73 WHERE `userid` = '.$this->userid)->fetch_object()->c < 5 )
74 $GLOBALS['DB']->query('INSERT INTO `invites` VALUES (NULL, '.$this->userid.', UUID())');
75 default:
76 if ( is_int($value) )
77 break;
78 $value = '\''.$GLOBALS['DB']->escape_string($value).'\'';
79 break;
81 $GLOBALS['DB']->query('UPDATE `users` SET `'.$varname.'` = '.$value.' WHERE `userid` = '.$this->userid);
82 if ( $GLOBALS['DB']->error )
83 throw new UnexpectedValueException('MySQL error in authuser::_set('.$varname.' = '.$value.'): '.$GLOBALS['DB']->error);