]> andersk Git - sql-web.git/blobdiff - lib/security.lib.php
error code color
[sql-web.git] / lib / security.lib.php
index 7557465526cf66a96010402dc94cdc699efa461e..77baf2005ceed3f8fe3293ee1b93aa20f644da42 100644 (file)
@@ -87,7 +87,7 @@ class User {
        var $dblist;
     function User($userId) {
                $this->userId = $userId;
-        $sql = sprintf("SELECT User.UserId, Username, Password, Name, Email, UL, bEnabled, nBytesSoft, nBytesHard, nBytes, nDatabases, nDatabasesHard
+        $sql = sprintf("SELECT User.UserId, Username, Password, Name, Email, UL, bEnabled, nBytesSoft, nBytesHard, nBytes, nDatabases, nDatabasesHard, IF(nBytes>nBytesHard,1,0) AS bOverQuota
                         FROM User
                                                INNER JOIN UserQuota ON User.UserId = UserQuota.UserId
                                                INNER JOIN UserStat ON User.UserId = UserStat.UserId
@@ -121,6 +121,9 @@ class User {
     function getUsername() {
         return $this->exists()?$this->info['Username']:'';
     }
+    function isOverQuota() {
+        return $this->exists()?($this->info['bOverQuota']>0?true:false):'';
+    }
     function getBytes() {
         if($this->exists()) {
                        $arr['nBytes'] = $this->info['nBytes'];
@@ -195,11 +198,12 @@ class User {
                                                mysql_escape_string($this->getUserId()));
 //                     $r = fetchRows(DBSelect($sql),'DatabaseId');
                        $r = fetchRows(DBSelect($sql),'Name');
+                       ksort($r);
                        return $r;
                }
        }
        function addDB($name) {
-               if (in_array($name, $this->getDBList())) return false;
+               if (in_array($name, array_keys($this->getDBList()))) return false;
                if (!addDB($name, $this->getUserId())) return false;
                $this->setAccess($name);
                return true;
@@ -236,8 +240,9 @@ function isImpersonating() {
 function impersonate($userId=null) {
        $wasImpersonating = isImpersonating();
        if ($wasImpersonating) {
-               if (is_null($userId)) {
+               if (is_null($userId) || empty($userId)) {
                        sess('UserId',sess('_UserId'));
+                       sess('_UserId','');
                } elseif ($userId>0) {
                        sess('UserId',$userId);
                } else {
@@ -280,6 +285,9 @@ function redirect($target=null,$secure=null) {
     $base = (is_null($target)||substr($target,0,1)=='?')?$_SERVER['REDIRECT_URL']:(dirname($_SERVER['REDIRECT_URL']).'/');
     redirectFull(is_null($target)?$base:($base.$target),$secure);
 }
+function redirectStart() {
+       redirectFull(BASE_URL,null);
+}
 function redirectFull($target,$secure) {
        redirect2((((isSSL()&&is_null($secure))||$secure==true)?'https://':'http://').$_SERVER['SERVER_NAME'].$target);
 }
This page took 0.280037 seconds and 4 git commands to generate.