Skip to content

Commit 323f1fc

Browse files
author
Florian Schaal
committed
db-quota: changed sql-queries for dkim to new syntax
1 parent d9443da commit 323f1fc

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

interface/web/sites/database_edit.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function onShowEnd() {
7373

7474
// Get the limits of the client
7575
$client_group_id = $_SESSION["s"]["user"]["default_group"];
76-
$client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
76+
$client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
7777

7878
// Set the webserver to the default server of the client
7979
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ($client[db_servers])");
@@ -96,10 +96,10 @@ function onShowEnd() {
9696

9797
// Get the limits of the client
9898
$client_group_id = $_SESSION["s"]["user"]["default_group"];
99-
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
99+
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
100100

101101
// Set the webserver to the default server of the client
102-
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ($client[db_servers])");
102+
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN (?)", $client[db_servers]);
103103

104104
$only_one_server = count($tmp) === 1;
105105
$app->tpl->setVar('only_one_server', $only_one_server);
@@ -150,6 +150,7 @@ function onShowEnd() {
150150
$app->tpl->setVar("edit_disabled", 1);
151151
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
152152
$app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]);
153+
$app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]);
153154
} else {
154155
$app->tpl->setVar("edit_disabled", 0);
155156
}
@@ -171,9 +172,31 @@ function onSubmit() {
171172
// When the record is updated
172173
if($this->id > 0) {
173174
// restore the server ID if the user is not admin and record is edited
174-
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".$app->functions->intval($this->id));
175+
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ?", $app->functions->intval($this->id));
175176
$this->dataRecord["server_id"] = $tmp["server_id"];
176177
unset($tmp);
178+
//* Check client quota
179+
if ($client['limit_database_quota'] >= 0) {
180+
//* get the database prefix
181+
$app->uses('getconf,tools_sites');
182+
$global_config = $app->getconf->get_global_config('sites');
183+
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
184+
//* get quota from other databases
185+
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ? AND database_name <> ?", $client_group_id, $dbname_prefix.$this->dataRecord['database_name']);
186+
$used_quota = $app->functions->intval($tmp['db_quota']);
187+
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
188+
if(($used_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
189+
$max_free_quota = floor($client['limit_database_quota'] - $used_quota);
190+
if($max_free_quota < 0) {
191+
$max_free_quota = 0;
192+
}
193+
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>";
194+
$this->dataRecord['database_quota'] = $max_free_quota;
195+
}
196+
unset($tmp);
197+
unset($global_config);
198+
unset($dbname_prefix);
199+
}
177200
// When the record is inserted
178201
} else {
179202
$client['db_servers_ids'] = explode(',', $client['db_servers']);
@@ -185,15 +208,15 @@ function onSubmit() {
185208

186209
// Check if the user may add another database
187210
if($client["limit_database"] >= 0) {
188-
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
211+
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $client_group_id);
189212
if($tmp["number"] >= $client["limit_database"]) {
190213
$app->error($app->tform->wordbook["limit_database_txt"]);
191214
}
192215
}
193216

194-
// Check client quota
195-
if ($client['limit_database_quota'] >= 0) {
196-
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = $client_group_id");
217+
//* Check client quota
218+
if ($client['limit_database_quota'] >= 0) {
219+
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ?", $client_group_id);
197220
$db_quota = $tmp['db_quota'];
198221
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]);
199222
if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) {
@@ -300,7 +323,7 @@ function onBeforeUpdate() {
300323
}
301324
*/
302325

303-
if($this->dataRecord['remote_access'] != 'y'){
326+
if(isset($this->dataRecord['remote_access']) && $this->dataRecord['remote_access'] != 'y'){
304327
$this->dataRecord['remote_ips'] = $server_config['ip_address'];
305328
$this->dataRecord['remote_access'] = 'y';
306329
} else {
@@ -387,7 +410,7 @@ function onBeforeInsert() {
387410
}
388411
*/
389412

390-
if($this->dataRecord['remote_access'] != 'y'){
413+
if(isset($this->dataRecord['remote_access']) && $this->dataRecord['remote_access'] != 'y'){
391414
$this->dataRecord['remote_ips'] = $server_config['ip_address'];
392415
$this->dataRecord['remote_access'] = 'y';
393416
} else {

0 commit comments

Comments
 (0)