var $dblist;
function User($userId) {
$this->userId = $userId;
- $sql = sprintf("SELECT UserId, Username, Password, Name, Email, UL, bEnabled
+ $sql = sprintf("SELECT User.UserId, Username, Password, Name, Email, UL, bEnabled, nBytesSoft, nBytesHard, nBytes, nDatabases, nDatabasesHard
FROM User
- WHERE UserId = '%s'",
+ NATURAL JOIN UserQuota
+ NATURAL JOIN UserStat
+ WHERE User.UserId = '%s'",
mysql_escape_string($userId));
$r = fetchRows(DBSelect($sql),'UserId');
$this->info = count($r)?array_shift($r):$r;
$this->dblist = $this->getDBList();
// $this->pass = base64_decode($this->info['Password']);
}
+ function refresh() {
+ unset($this->dblist);
+ $this->User($this->userId);
+ /*
+ $sql = sprintf("SELECT UserId, Username, Password, Name, Email, UL, bEnabled
+ FROM User
+ WHERE UserId = '%s'",
+ mysql_escape_string($this->userId));
+ $r = fetchRows(DBSelect($sql),'UserId');
+ $this->info = count($r)?array_shift($r):$r;
+ unset($this->dblist);
+ $this->getDBList();
+ */
+ }
function exists() {
return count($this->info);
}
}
function getUsername() {
return $this->exists()?$this->info['Username']:'';
+ }
+ function getBytes() {
+ if($this->exists()) {
+ $arr['nBytes'] = $this->info['nBytes'];
+ $arr['nBytesSoft'] = $this->info['nBytesSoft'];
+ $arr['nBytesHard'] = $this->info['nBytesHard'];
+ return $arr;
+ }
}
function setPassword($pwd) {
$arr['Password'] = base64_encode($pwd);
$verb = $yes?'GRANT':'REVOKE';
$prep = $yes?'TO':'FROM';
if (is_null($db)) {
- $this->dblist = $this->getDBList();
- $dbs = $this->dblist;
+ $dbs = $this->getDBList();
} else {
$dbs[] = array('Name'=>$db);
}
}
}
function getDBList() {
- $sql = sprintf("SELECT *
+ if (isset($this->dblist)) {
+ return $this->dblist;
+ } else {
+ // LEFT JOIN DBQuota ON DBQuota.DatabaseId = DBOwner.DatabaseId
+ $sql = sprintf("SELECT *
FROM DBOwner
- INNER JOIN DB ON DB.DatabaseId = DBOwner.DatabaseId
- LEFT JOIN DBQuota ON DBQuota.DatabaseId = DBOwner.DatabaseId
- WHERE UserId = '%s' AND DB.bEnabled=1",
+ NATURAL JOIN DB
+ NATURAL JOIN DBQuota
+ WHERE DBOwner.UserId = '%s' AND DB.bEnabled=1",
mysql_escape_string($this->getUserId()));
- $r = fetchRows(DBSelect($sql),'DatabaseId');
- return $r;
+// $r = fetchRows(DBSelect($sql),'DatabaseId');
+ $r = fetchRows(DBSelect($sql),'Name');
+ return $r;
+ }
}
function addDB($name) {
if (!addDB($name, $this->getUserId())) return false;
return !empty($aLogin) && is_a($aLogin, 'Login') && $aLogin->canLogin();
}
+function isImpersonating() {
+ return isSess('_UserId') && isSess('UserId');
+}
+
+function impersonate($userId=null) {
+ $wasImpersonating = isImpersonating();
+ if ($wasImpersonating) {
+ if (is_null($userId)) {
+ sess('UserId',sess('_UserId'));
+ } elseif ($userId>0) {
+ sess('UserId',$userId);
+ } else {
+ return false;
+ }
+ } elseif (isLoggedIn()) {
+ sess('_UserId',sess('UserId'));
+ sess('UserId',$userId);
+ return true;
+ } else {
+ return false;
+ }
+}
+
function isSSL() {
return $_SERVER['SERVER_PORT'] == 443;
}
return $DBId;
}
-?>
\ No newline at end of file
+?>