]>
Commit | Line | Data |
---|---|---|
997305cf | 1 | <?php |
79ffa771 JP |
2 | /* |
3 | (c) 2005 Joe Presbrey | |
4 | */ | |
997305cf | 5 | |
8988dbad | 6 | require_once('joe/util.lib.php'); |
563559c4 | 7 | require_once('joe/mysql.lib.php'); |
997305cf | 8 | |
9c70b481 JP |
9 | function checkQuotas($userId=null) { |
10 | if (empty($userId)) { | |
11 | $sql = 'SELECT DatabaseId,Name FROM DB WHERE bEnabled=1'; | |
12 | } else { | |
6fd1f8c5 JP |
13 | if (is_array($userId)) { |
14 | $sql_userId = sprintf("UserId IN ('%s')", implode("','",array_map('mysql_escape_string',$userId))); | |
70776def | 15 | } elseif ((string)intval($userId)===(string)$userId) { |
6fd1f8c5 JP |
16 | $sql_userId = sprintf("UserId = '%s'", mysql_escape_string($userId)); |
17 | } else { | |
18 | die('userId parameter error in checkQuotas'); | |
19 | } | |
20 | $sql = sprintf("SELECT DB.DatabaseId,Name FROM DB INNER JOIN DBOwner ON DB.DatabaseId = DBOwner.DatabaseId WHERE bEnabled=1 AND %s", $sql_userId); | |
9c70b481 JP |
21 | } |
22 | $databases = fetchRows(DBSelect($sql),'Name'); | |
23 | foreach($databases as $db) { | |
24 | $DBId = $db['DatabaseId']; | |
25 | $arr['dLastCheck'] = 'NOW()'; | |
26 | $arr['nBytes'] = calcDBSize($db['Name']); | |
8988dbad | 27 | $sql = sprintf("UPDATE DB SET %s WHERE DatabaseId = '%s'", |
9c70b481 JP |
28 | buildSQLSet($arr), |
29 | mysql_escape_string($DBId)); | |
30 | DBUpdate($sql); | |
31 | } | |
32 | $sql = "UPDATE UserStat SET nBytes = ( | |
33 | SELECT SUM(nBytes) | |
34 | FROM DB | |
35 | INNER JOIN DBOwner ON DBOwner.DatabaseId = DB.DatabaseId | |
36 | WHERE DBOwner.UserId = UserStat.UserId | |
37 | AND DB.bEnabled=1 | |
38 | GROUP BY UserId | |
39 | ), dLastCheck = NOW()"; | |
6fd1f8c5 | 40 | if (!empty($userId)) $sql .= " WHERE $sql_userId"; |
9c70b481 | 41 | DBUpdate($sql); |
9840d102 JP |
42 | $sql = "UPDATE UserStat SET nDatabases = ( |
43 | SELECT COUNT(*) | |
44 | FROM DB | |
45 | INNER JOIN DBOwner ON DBOwner.DatabaseId = DB.DatabaseId | |
46 | WHERE DBOwner.UserId = UserStat.UserId | |
47 | AND DB.bEnabled=1 | |
48 | GROUP BY UserId | |
49 | ), dLastCheck = NOW()"; | |
6fd1f8c5 | 50 | if (!empty($userId)) $sql .= " WHERE $sql_userId"; |
9840d102 | 51 | DBUpdate($sql); |
9c70b481 JP |
52 | } |
53 | ||
997305cf | 54 | ?> |