From e406c48cc28d5c9ff747435bdfb60d7a53d91867 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 11:20:28 +0200 Subject: [PATCH 01/14] Revert "Fixes #6528 Account limit incorrectly informed in dashboard" This reverts commit 224a5966d8eed3ddcc2f482704900ce4645cfd28. --- .../web/dashboard/dashlets/databasequota.php | 21 ++++++++--- interface/web/dashboard/dashlets/limits.php | 35 +++++++++++-------- .../web/dashboard/dashlets/mailquota.php | 20 ++++++++--- interface/web/dashboard/dashlets/quota.php | 19 ++++++---- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/interface/web/dashboard/dashlets/databasequota.php b/interface/web/dashboard/dashlets/databasequota.php index 4b06599d1c..5bb38be854 100644 --- a/interface/web/dashboard/dashlets/databasequota.php +++ b/interface/web/dashboard/dashlets/databasequota.php @@ -2,7 +2,7 @@ class dashlet_databasequota { - function show() { + function show($limit_to_client_id = null) { global $app; //* Loading Template @@ -23,19 +23,30 @@ class dashlet_databasequota { $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_databasequota.lng'; if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); + if ($_SESSION["s"]["user"]["typ"] != 'admin') { + $client_id = $_SESSION['s']['user']['client_id']; + } else { + $client_id = $limit_to_client_id; + } - $databases = $app->quota_lib->get_databasequota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null); + $databases = $app->quota_lib->get_databasequota_data($client_id); //print_r($databases); $has_databasequota = false; + $total_used = 0; if(is_array($databases) && !empty($databases)){ + foreach ($databases as &$db) { + $total_used += $db['used_raw'] * 1000 * 1000; + } $databases = $app->functions->htmlentities($databases); $tpl->setloop('databasequota', $databases); $has_databasequota = isset($databases[0]['used']); + + $tpl->setVar('has_databasequota', $has_databasequota); + $tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0)); + + return $tpl->grab(); } - $tpl->setVar('has_databasequota', $has_databasequota); - - return $tpl->grab(); } } diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 2251fd80c2..f34d8c150a 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -2,7 +2,7 @@ class dashlet_limits { - public function show() + public function show($limit_to_client_id = 0) { global $app, $conf; @@ -147,33 +147,35 @@ class dashlet_limits } $tpl->setVar($wb); - if ($app->auth->is_admin()) { - $user_is_admin = true; + if ($limit_to_client_id == 0) { + $client_id = $_SESSION['s']['user']['client_id']; + $user_is_admin = true; } else { - $user_is_admin = false; + $client_id = $limit_to_client_id; + $user_is_admin = false; } - $tpl->setVar('is_admin', $user_is_admin); - if ($user_is_admin == false) { - $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); - $client = $app->db->queryOneRecord("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); - } + $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); + $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $client_id); + $rows = array(); foreach ($limits as $limit) { $field = $limit['field']; + $value = $client[$field]; if ($user_is_admin) { $value = $wb['unlimited_txt']; } else { $value = $client[$field]; } + if ($value != 0 || $value == $wb['unlimited_txt']) { $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value; if (isset($limit['q_type']) && $limit['q_type'] != '') { - $usage = $this->_get_assigned_quota($limit) . " MB"; + $usage = $this->_get_assigned_quota($limit, $client_id) . " MB"; $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB"; } else { - $usage = $this->_get_limit_usage($limit); + $usage = $this->_get_limit_usage($limit, $client_id); } $percentage = ($value == '-1' || intval($value) == 0 || trim($value) == '' ? -1 : round(100 * (int)$usage / (int)$value)); $progressbar = $percentage > 100 ? 100 : $percentage; @@ -195,7 +197,7 @@ class dashlet_limits return $tpl->grab(); } - public function _get_limit_usage($limit) + public function _get_limit_usage($limit, $limit_to_client_id) { global $app; @@ -203,12 +205,15 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r'); + $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id); + // TEST to show reseller data. + //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39'); + //echo $sql; $rec = $app->db->queryOneRecord($sql, $limit['db_table']); return $rec['number']; } - public function _get_assigned_quota($limit) + public function _get_assigned_quota($limit, $limit_to_client_id) { global $app; @@ -216,7 +221,7 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r'); + $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id); $rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']); if ($limit['db_table']=='mail_user') { $quotaMB = $rec['number'] / 1048576; diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php index a9434e58ea..f097005d7f 100644 --- a/interface/web/dashboard/dashlets/mailquota.php +++ b/interface/web/dashboard/dashlets/mailquota.php @@ -2,7 +2,7 @@ class dashlet_mailquota { - function show() { + function show($limit_to_client_id = null) { global $app; //* Loading Template @@ -16,23 +16,33 @@ class dashlet_mailquota { if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - $emails = $app->quota_lib->get_mailquota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null); + if ($_SESSION["s"]["user"]["typ"] != 'admin') { + $client_id = $_SESSION['s']['user']['client_id']; + } else { + $client_id = $limit_to_client_id; + } + + $emails = $app->quota_lib->get_mailquota_data($client_id); //print_r($emails); $has_mailquota = false; + $total_used = 0; if(is_array($emails) && !empty($emails)){ foreach($emails as &$email) { $email['email'] = $app->functions->idn_decode($email['email']); + $total_used += $email['used_raw']; } unset($email); // email username is quoted in quota.lib already, so no htmlentities here to prevent double encoding //$emails = $app->functions->htmlentities($emails); $tpl->setloop('mailquota', $emails); $has_mailquota = isset($emails[0]['used']); - } - $tpl->setVar('has_mailquota', $has_mailquota); - return $tpl->grab(); + $tpl->setVar('has_mailquota', $has_mailquota); + $tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0)); + + return $tpl->grab(); + } } } diff --git a/interface/web/dashboard/dashlets/quota.php b/interface/web/dashboard/dashlets/quota.php index d0b1be998f..a70a1bf253 100644 --- a/interface/web/dashboard/dashlets/quota.php +++ b/interface/web/dashboard/dashlets/quota.php @@ -2,7 +2,7 @@ class dashlet_quota { - function show() { + function show($limit_to_client_id = null) { global $app; //* Loading Template @@ -24,7 +24,13 @@ class dashlet_quota { if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - $sites = $app->quota_lib->get_quota_data( ($_SESSION["s"]["user"]["typ"] != 'admin') ? $_SESSION['s']['user']['client_id'] : null); + if ($_SESSION["s"]["user"]["typ"] != 'admin') { + $client_id = $_SESSION['s']['user']['client_id']; + } else { + $client_id = $limit_to_client_id; + } + + $sites = $app->quota_lib->get_quota_data($client_id); //print_r($sites); $has_quota = false; @@ -32,18 +38,19 @@ class dashlet_quota { foreach($sites as &$site) { $site['domain'] = $app->functions->idn_decode($site['domain']); $site['progressbar'] = $site['hd_quota']; + $total_used += $site['used_raw'] * 1000; } unset($site); $sites = $app->functions->htmlentities($sites); $tpl->setloop('quota', $sites); $has_quota = isset($sites[0]['used']); - } - $tpl->setVar('has_quota', $has_quota); - - return $tpl->grab(); + $tpl->setVar('has_quota', $has_quota); + $tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0)); + return $tpl->grab(); + } } } -- GitLab From 9741885941b232b221fc85f690e0eb622f91dfce Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 18 Jun 2023 20:34:42 +0200 Subject: [PATCH 02/14] Rework dashlet code - Move translations more to the frontend code --- interface/lib/classes/functions.inc.php | 22 ++++++ interface/lib/classes/quota_lib.inc.php | 67 +++---------------- interface/web/dashboard/dashboard.php | 2 +- .../web/dashboard/dashlets/databasequota.php | 12 ++-- interface/web/dashboard/dashlets/limits.php | 24 +++---- .../web/dashboard/dashlets/mailquota.php | 18 +---- interface/web/dashboard/dashlets/quota.php | 13 ++-- 7 files changed, 57 insertions(+), 101 deletions(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 629da2fb0e..bca97ed301 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -287,11 +287,33 @@ class functions { * @return string - formated bytes */ public function formatBytes($size, $precision = 2) { + // 0 is a special as it would give NAN otehrwise. + if ($size == 0) { + return 0; + } + $base=log($size)/log(1024); $suffixes=array('', ' kB', ' MB', ' GB', ' TB'); return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)]; } + /** + * Function to change bytes to kB, MB, GB or TB or the translated string 'Unlimited' for -1 + * @param int $size - size in bytes + * @param int precicion - after-comma-numbers (default: 2) + * @return string - formated bytes + */ + public function formatBytesOrUnlimited($size, $precision = 2) { + global $app; + + if ($size == -1) { + return $app->lng('unlimited_txt'); + } + else { + return $this->formatBytes($size, $precision); + } + + } /** * Normalize a path and strip duplicate slashes from it diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php index 7c5b388536..7f26de8aa7 100644 --- a/interface/lib/classes/quota_lib.inc.php +++ b/interface/lib/classes/quota_lib.inc.php @@ -36,9 +36,10 @@ class quota_lib { if (!is_numeric($sites[$i]['hard'])) $sites[$i]['hard']=$sites[$i]['hard'][1]; if (!is_numeric($sites[$i]['files'])) $sites[$i]['files']=$sites[$i]['files'][1]; - $sites[$i]['used_raw'] = $sites[$i]['used']; - $sites[$i]['soft_raw'] = $sites[$i]['soft']; - $sites[$i]['hard_raw'] = $sites[$i]['hard']; + // Convert from kb to bytes, and use -1 for instead of 0 for Unlimited. + $sites[$i]['used_raw'] = $sites[$i]['used'] * 1024; + $sites[$i]['soft_raw'] = ($sites[$i]['soft'] > 0) ? $sites[$i]['soft'] * 1024 : -1; + $sites[$i]['hard_raw'] = ($sites[$i]['hard'] > 0) ? $sites[$i]['hard'] * 1024 : -1; $sites[$i]['files_raw'] = $sites[$i]['files']; $sites[$i]['used_percentage'] = ($sites[$i]['soft'] > 0 && $sites[$i]['used'] > 0 ? round($sites[$i]['used'] * 100 / $sites[$i]['soft']) : 0); @@ -53,29 +54,6 @@ class quota_lib { if($used_ratio >= 0.8) $sites[$i]['display_colour'] = '#fd934f'; if($used_ratio >= 1) $sites[$i]['display_colour'] = '#cc0000'; - if($sites[$i]['used'] > 1024) { - $sites[$i]['used'] = round($sites[$i]['used'] / 1024, 1).' MB'; - } else { - if ($sites[$i]['used'] != '') $sites[$i]['used'] .= ' KB'; - } - - if($sites[$i]['soft'] > 1024) { - $sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 1).' MB'; - } else { - $sites[$i]['soft'] .= ' KB'; - } - - if($sites[$i]['hard'] > 1024) { - $sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 1).' MB'; - } else { - $sites[$i]['hard'] .= ' KB'; - } - - if($sites[$i]['soft'] == " KB") $sites[$i]['soft'] = $app->lng('unlimited_txt'); - if($sites[$i]['hard'] == " KB") $sites[$i]['hard'] = $app->lng('unlimited_txt'); - - if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = $app->lng('unlimited_txt'); - if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = $app->lng('unlimited_txt'); /* if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B'; @@ -83,13 +61,7 @@ class quota_lib { if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B'; */ } - else { - if (empty($sites[$i]['soft'])) $sites[$i]['soft'] = -1; - if (empty($sites[$i]['hard'])) $sites[$i]['hard'] = -1; - if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = -1; - if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = -1; - } } } @@ -265,17 +237,8 @@ class quota_lib { if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f'; if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000'; - if($emails[$i]['quota'] == 0){ - $emails[$i]['quota'] = $app->lng('unlimited_txt'); - } else { - $emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 1).' MB'; - } - - - if($emails[$i]['used'] < 1544000) { - $emails[$i]['used'] = round($emails[$i]['used'] / 1024, 1).' KB'; - } else { - $emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 1).' MB'; + if($emails[$i]['quota'] == 0) { + $emails[$i]['quota'] = -1; } } } @@ -309,11 +272,11 @@ class quota_lib { for($i=0;$i 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used_raw'] * 100 / $databases[$i]['database_quota']) : 0; + $databases[$i]['database_quota_raw'] = ($databases[$i]['database_quota'] == -1) ? -1 : $databases[$i]['database_quota'] * 1000 * 1000; + $databases[$i]['used_raw'] = $size; // / 1024 / 1024; //* quota is stored as MB - calculated bytes + $databases[$i]['used_percentage'] = (($databases[$i]['database_quota'] > 0) && ($size > 0)) ? round($databases[$i]['used_raw'] * 100 / $databases[$i]['database_quota_raw']) : 0; if ($readable) { // colours @@ -326,18 +289,8 @@ class quota_lib { if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f'; if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000'; - if($databases[$i]['database_quota'] == -1) { - $databases[$i]['database_quota'] = $app->lng('unlimited_txt'); - } else { - $databases[$i]['database_quota'] = $databases[$i]['database_quota'] . ' MB'; - } - if($databases[$i]['used'] < 1544000) { - $databases[$i]['used'] = round($databases[$i]['used'] / 1024, 1).' KB'; - } else { - $databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 1).' MB'; - } } } } diff --git a/interface/web/dashboard/dashboard.php b/interface/web/dashboard/dashboard.php index d8adccd15e..71edd5c580 100644 --- a/interface/web/dashboard/dashboard.php +++ b/interface/web/dashboard/dashboard.php @@ -219,7 +219,7 @@ if($app->auth->is_admin()) { $leftcol = array(); foreach($leftcol_dashlets as $name) { if(isset($dashlet_list[$name])) { - $leftcol[]['content'] = $dashlet_list[$name]->show(); + $leftcol[]['content'] = $dashlet_list[$name]->show($_SESSION['s']['user']['client_id']); } } $app->tpl->setloop('leftcol', $leftcol); diff --git a/interface/web/dashboard/dashlets/databasequota.php b/interface/web/dashboard/dashlets/databasequota.php index 5bb38be854..6403032b54 100644 --- a/interface/web/dashboard/dashlets/databasequota.php +++ b/interface/web/dashboard/dashlets/databasequota.php @@ -23,20 +23,18 @@ class dashlet_databasequota { $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_dashlet_databasequota.lng'; if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - if ($_SESSION["s"]["user"]["typ"] != 'admin') { - $client_id = $_SESSION['s']['user']['client_id']; - } else { - $client_id = $limit_to_client_id; - } - $databases = $app->quota_lib->get_databasequota_data($client_id); + $databases = $app->quota_lib->get_databasequota_data($limit_to_client_id); //print_r($databases); $has_databasequota = false; $total_used = 0; if(is_array($databases) && !empty($databases)){ foreach ($databases as &$db) { - $total_used += $db['used_raw'] * 1000 * 1000; + $db['used'] = $app->functions->formatBytes($db['used_raw'], 0); + $db['database_quota'] = $app->functions->formatBytesOrUnlimited($db['database_quota_raw'], 0); + + $total_used += $db['used_raw']; } $databases = $app->functions->htmlentities($databases); $tpl->setloop('databasequota', $databases); diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index f34d8c150a..9befe628ca 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -146,16 +146,13 @@ class dashlet_limits include $lng_file; } $tpl->setVar($wb); - - if ($limit_to_client_id == 0) { - $client_id = $_SESSION['s']['user']['client_id']; - $user_is_admin = true; - } else { + if ($app->auth->is_admin()) { $client_id = $limit_to_client_id; - $user_is_admin = false; + } else { + $client_id = $_SESSION['s']['user']['client_id']; } - $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); +// $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $client_id); @@ -163,22 +160,23 @@ class dashlet_limits foreach ($limits as $limit) { $field = $limit['field']; $value = $client[$field]; - if ($user_is_admin) { - $value = $wb['unlimited_txt']; + if ($app->auth->is_admin() && $limit_to_client_id == 0) { + $value = -1; } else { $value = $client[$field]; } if ($value != 0 || $value == $wb['unlimited_txt']) { - $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value; + $suffix = ''; if (isset($limit['q_type']) && $limit['q_type'] != '') { - $usage = $this->_get_assigned_quota($limit, $client_id) . " MB"; - $value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB"; + $usage = $this->_get_assigned_quota($limit, $client_id); + $suffix = ' MB'; } else { $usage = $this->_get_limit_usage($limit, $client_id); } $percentage = ($value == '-1' || intval($value) == 0 || trim($value) == '' ? -1 : round(100 * (int)$usage / (int)$value)); $progressbar = $percentage > 100 ? 100 : $percentage; + $value_formatted = ($value == '-1') ? $wb['unlimited_txt'] : ($value . $suffix); $rows[] = array('field' => $field, 'field_txt' => $wb[$field.'_txt'], 'value' => $value_formatted, @@ -223,7 +221,7 @@ class dashlet_limits } $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id); $rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']); - if ($limit['db_table']=='mail_user') { + if ($limit['db_table'] == 'mail_user') { $quotaMB = $rec['number'] / 1048576; } // Mail quota is in bytes, must be converted to MB else { diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php index f097005d7f..d38fc4431a 100644 --- a/interface/web/dashboard/dashlets/mailquota.php +++ b/interface/web/dashboard/dashlets/mailquota.php @@ -16,13 +16,8 @@ class dashlet_mailquota { if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - if ($_SESSION["s"]["user"]["typ"] != 'admin') { - $client_id = $_SESSION['s']['user']['client_id']; - } else { - $client_id = $limit_to_client_id; - } - $emails = $app->quota_lib->get_mailquota_data($client_id); + $emails = $app->quota_lib->get_mailquota_data($limit_to_client_id); //print_r($emails); $has_mailquota = false; @@ -30,6 +25,8 @@ class dashlet_mailquota { if(is_array($emails) && !empty($emails)){ foreach($emails as &$email) { $email['email'] = $app->functions->idn_decode($email['email']); + $email['used'] = $app->functions->formatBytes($email['used_raw'], 0); + $email['quota'] = $app->functions->formatBytesOrUnlimited($email['quota_raw'], 0); $total_used += $email['used_raw']; } unset($email); @@ -46,12 +43,3 @@ class dashlet_mailquota { } } - - - - - - - - -?> diff --git a/interface/web/dashboard/dashlets/quota.php b/interface/web/dashboard/dashlets/quota.php index a70a1bf253..2dc695ae14 100644 --- a/interface/web/dashboard/dashlets/quota.php +++ b/interface/web/dashboard/dashlets/quota.php @@ -24,13 +24,7 @@ class dashlet_quota { if(is_file($lng_file)) include $lng_file; $tpl->setVar($wb); - if ($_SESSION["s"]["user"]["typ"] != 'admin') { - $client_id = $_SESSION['s']['user']['client_id']; - } else { - $client_id = $limit_to_client_id; - } - - $sites = $app->quota_lib->get_quota_data($client_id); + $sites = $app->quota_lib->get_quota_data($limit_to_client_id); //print_r($sites); $has_quota = false; @@ -38,7 +32,10 @@ class dashlet_quota { foreach($sites as &$site) { $site['domain'] = $app->functions->idn_decode($site['domain']); $site['progressbar'] = $site['hd_quota']; - $total_used += $site['used_raw'] * 1000; + $site['used'] = $app->functions->formatBytes($site['used_raw'], 0); + $site['hard'] = $app->functions->formatBytesOrUnlimited($site['hard_raw'], 0); + $site['soft'] = $app->functions->formatBytesOrUnlimited($site['soft_raw'], 0); + $total_used += $site['used_raw']; } unset($site); -- GitLab From 4c2c33910ffb3a4c98a022456d3fbab4a8946787 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 1 Jul 2023 23:54:32 +0200 Subject: [PATCH 03/14] Add an extra utility function is_reseller --- interface/lib/classes/auth.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interface/lib/classes/auth.inc.php b/interface/lib/classes/auth.inc.php index 3a4cc1603c..a8f1f966a7 100644 --- a/interface/lib/classes/auth.inc.php +++ b/interface/lib/classes/auth.inc.php @@ -53,6 +53,13 @@ class auth { } } + public function is_reseller() { + if($this->has_clients($_SESSION['s']['user']['userid'])) { + return true; + } else { + return false; + } + } public function has_clients($userid) { global $app, $conf; -- GitLab From eee2d2465a58f5132c0b2b483ba6c67cf90d2983 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 2 Jul 2023 00:02:36 +0200 Subject: [PATCH 04/14] Support reseller in dashboard --- interface/lib/classes/quota_lib.inc.php | 19 ++++++++++++++++--- interface/web/dashboard/dashboard.php | 10 ++++++++-- interface/web/dashboard/dashlets/limits.php | 14 ++++++-------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php index 7f26de8aa7..e38a7e117f 100644 --- a/interface/lib/classes/quota_lib.inc.php +++ b/interface/lib/classes/quota_lib.inc.php @@ -14,7 +14,12 @@ class quota_lib { //print_r($monitor_data); // select all websites or websites belonging to client - $sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".(($clientid != null)?" AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)":'') . " ORDER BY domain", $clientid); + $q = " SELECT * FROM web_domain + WHERE active = 'y' AND type = 'vhost'" + . 'AND sys_groupid ' . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" + : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") + . " ORDER BY domain"; + $sites = $app->db->queryAllRecords($q, $clientid); //print_r($sites); if(is_array($sites) && !empty($sites)){ @@ -209,7 +214,11 @@ class quota_lib { //print_r($monitor_data); // select all email accounts or email accounts belonging to client - $emails = $app->db->queryAllRecords("SELECT * FROM mail_user".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : '') . " ORDER BY email", $clientid); + $q = " SELECT * FROM mail_user" + . " WHERE sys_groupid " . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" + : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") + . " ORDER BY email"; + $emails = $app->db->queryAllRecords($q, $clientid); //print_r($emails); if(is_array($emails) && !empty($emails)) { @@ -265,7 +274,11 @@ class quota_lib { //print_r($monitor_data); // select all databases belonging to client - $databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : '') . " ORDER BY database_name", $clientid); + $q = "SELECT * FROM web_database" + . " WHERE sys_groupid " . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" + : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") + . " ORDER BY database_name"; + $databases = $app->db->queryAllRecords($q, $clientid); //print_r($databases); if(is_array($databases) && !empty($databases)){ diff --git a/interface/web/dashboard/dashboard.php b/interface/web/dashboard/dashboard.php index 71edd5c580..a78ade4e7c 100644 --- a/interface/web/dashboard/dashboard.php +++ b/interface/web/dashboard/dashboard.php @@ -214,12 +214,18 @@ if($app->auth->is_admin()) { } } +if ($app->auth->is_admin() || $app->auth->is_reseller()) { + $limit_to_client_id = null; +} +else { + $limit_to_client_id = $_SESSION['s']['user']['client_id']; +} /* Fill the left column */ $leftcol = array(); foreach($leftcol_dashlets as $name) { if(isset($dashlet_list[$name])) { - $leftcol[]['content'] = $dashlet_list[$name]->show($_SESSION['s']['user']['client_id']); + $leftcol[]['content'] = $dashlet_list[$name]->show($limit_to_client_id); } } $app->tpl->setloop('leftcol', $leftcol); @@ -228,7 +234,7 @@ $app->tpl->setloop('leftcol', $leftcol); $rightcol = array(); foreach($rightcol_dashlets as $name) { if(isset($dashlet_list[$name])) { - $rightcol[]['content'] = $dashlet_list[$name]->show(); + $rightcol[]['content'] = $dashlet_list[$name]->show($limit_to_client_id); } } $app->tpl->setloop('rightcol', $rightcol); diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 9befe628ca..e4c2705193 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -146,15 +146,13 @@ class dashlet_limits include $lng_file; } $tpl->setVar($wb); - if ($app->auth->is_admin()) { - $client_id = $limit_to_client_id; - } else { - $client_id = $_SESSION['s']['user']['client_id']; - } - -// $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); - $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $client_id); + if ($limit_to_client_id != null) { + $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $limit_to_client_id); + } + elseif ($limit_to_client_id == null && $app->auth->is_reseller()) { + $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $_SESSION['s']['user']['client_id']); + } $rows = array(); foreach ($limits as $limit) { -- GitLab From 74efda9da4df0e566485106c974ad141e38939ad Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 11:55:50 +0200 Subject: [PATCH 05/14] Do not show data from other users when viewing the client dashboard as an admin --- interface/web/dashboard/dashlets/limits.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index e4c2705193..2d2becdc25 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -148,11 +148,12 @@ class dashlet_limits $tpl->setVar($wb); if ($limit_to_client_id != null) { - $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $limit_to_client_id); + $client_id = $limit_to_client_id; } elseif ($limit_to_client_id == null && $app->auth->is_reseller()) { - $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $_SESSION['s']['user']['client_id']); + $client_id = $_SESSION['s']['user']['client_id']; } + $client = $app->db->queryOneRecord("SELECT * FROM client WHERE client_id = ?", $client_id); $rows = array(); foreach ($limits as $limit) { @@ -201,7 +202,7 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id); + $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id, array()); // TEST to show reseller data. //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39'); //echo $sql; -- GitLab From 9a27599972bf2ac7f2466178835047b9a1210f7a Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 21:35:32 +0200 Subject: [PATCH 06/14] getAuthSQL expects a string, lookup groupid of the client --- interface/web/dashboard/dashlets/limits.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 2d2becdc25..75c8b8e3f4 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -202,7 +202,8 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id, array()); + $group = $app->db->queryOneRecord("SELECT `groupid` FROM `sys_group` WHERE client_id=?", $limit_to_client_id); + $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id, $group['groupid']); // TEST to show reseller data. //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39'); //echo $sql; -- GitLab From 1c6fba63f5b598edddf5d90b417edd0bb433ebee Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 22:39:28 +0200 Subject: [PATCH 07/14] Lookup a client's group + all groups he is reselling. --- interface/web/dashboard/dashlets/limits.php | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 75c8b8e3f4..16e4436f38 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -202,15 +202,12 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $group = $app->db->queryOneRecord("SELECT `groupid` FROM `sys_group` WHERE client_id=?", $limit_to_client_id); - $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id, $group['groupid']); - // TEST to show reseller data. - //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39'); - //echo $sql; + $sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id)); + $rec = $app->db->queryOneRecord($sql, $limit['db_table']); return $rec['number']; } - + public function _get_assigned_quota($limit, $limit_to_client_id) { global $app; @@ -219,14 +216,32 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r', '', $limit_to_client_id); + $sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id)); $rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']); if ($limit['db_table'] == 'mail_user') { $quotaMB = $rec['number'] / 1048576; } // Mail quota is in bytes, must be converted to MB else { $quotaMB = $app->functions->intval($rec['number']); - } - return $quotaMB; + } + return $quotaMB; + } + + /** + * Lookup a client's group + all groups he is reselling. + * + * @return string Comma separated list of groupid's + */ + function clientid_to_groups_list($client_id) { + global $app; + + if ($client_id != null) { + // Get the clients groupid, and incase it's a reseller the groupid's of it's clients. + $group = $app->db->queryOneRecord("SELECT GROUP_CONCAT(groupid) AS groups FROM `sys_group` WHERE client_id IN (SELECT client_id FROM `client` WHERE client_id=? OR parent_client_id=?)", $client_id, $client_id); + dnl($group); + dnl($client_id); + return $group['groups']; + } + return null; } } -- GitLab From 90b9f4eba643b661a288a79332412cdd32d509e1 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 23:04:24 +0200 Subject: [PATCH 08/14] remove debug code --- interface/web/dashboard/dashlets/limits.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 16e4436f38..6cf7e9608f 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -238,8 +238,6 @@ class dashlet_limits if ($client_id != null) { // Get the clients groupid, and incase it's a reseller the groupid's of it's clients. $group = $app->db->queryOneRecord("SELECT GROUP_CONCAT(groupid) AS groups FROM `sys_group` WHERE client_id IN (SELECT client_id FROM `client` WHERE client_id=? OR parent_client_id=?)", $client_id, $client_id); - dnl($group); - dnl($client_id); return $group['groups']; } return null; -- GitLab From 139b351dd7a5837818cb590e16aa178c3ef69a03 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 29 Jul 2023 23:13:45 +0200 Subject: [PATCH 09/14] Mail is the exception with 0 == unlimited, instead of -1 --- interface/web/dashboard/dashlets/mailquota.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php index d38fc4431a..9817358745 100644 --- a/interface/web/dashboard/dashlets/mailquota.php +++ b/interface/web/dashboard/dashlets/mailquota.php @@ -26,6 +26,11 @@ class dashlet_mailquota { foreach($emails as &$email) { $email['email'] = $app->functions->idn_decode($email['email']); $email['used'] = $app->functions->formatBytes($email['used_raw'], 0); + // Mail is the exception with 0 == unlimited, instead of -1 + if ($email['quota_raw'] == 0) { + $email['quota_raw'] = -1; + } + $email['quota'] = $app->functions->formatBytesOrUnlimited($email['quota_raw'], 0); $total_used += $email['used_raw']; } -- GitLab From 90f8128af618b4e7d2c57812f0a8a9d56d7e375d Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 30 Jul 2023 14:21:20 +0200 Subject: [PATCH 10/14] Do not show percentage bar when db has no quota --- interface/web/dashboard/dashlets/databasequota.php | 4 ---- interface/web/dashboard/dashlets/templates/databasequota.htm | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/interface/web/dashboard/dashlets/databasequota.php b/interface/web/dashboard/dashlets/databasequota.php index 6403032b54..20db5eafb4 100644 --- a/interface/web/dashboard/dashlets/databasequota.php +++ b/interface/web/dashboard/dashlets/databasequota.php @@ -27,7 +27,6 @@ class dashlet_databasequota { $databases = $app->quota_lib->get_databasequota_data($limit_to_client_id); //print_r($databases); - $has_databasequota = false; $total_used = 0; if(is_array($databases) && !empty($databases)){ foreach ($databases as &$db) { @@ -38,9 +37,6 @@ class dashlet_databasequota { } $databases = $app->functions->htmlentities($databases); $tpl->setloop('databasequota', $databases); - $has_databasequota = isset($databases[0]['used']); - - $tpl->setVar('has_databasequota', $has_databasequota); $tpl->setVar('total_used', $app->functions->formatBytes($total_used, 0)); return $tpl->grab(); diff --git a/interface/web/dashboard/dashlets/templates/databasequota.htm b/interface/web/dashboard/dashlets/templates/databasequota.htm index 2676b65b35..5874c4b20a 100644 --- a/interface/web/dashboard/dashlets/templates/databasequota.htm +++ b/interface/web/dashboard/dashlets/templates/databasequota.htm @@ -14,7 +14,7 @@ {tmpl_var name='database_name'} {tmpl_var name='used'} {tmpl_var name='database_quota'} - {tmpl_if name="quota_raw" op="!=" value="-1"} + {tmpl_if name="database_quota_raw" op="!=" value="-1"}
{tmpl_var name="used_percentage"}% {tmpl_var name='used'} {tmpl_var name='of_txt'} {tmpl_var name='database_quota'} -- GitLab From c48d0caa572678845088012674b9c059373defb1 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 30 Jul 2023 15:35:12 +0200 Subject: [PATCH 11/14] Move clientid_to_groups_list function to more generic location --- interface/lib/classes/functions.inc.php | 16 ++++++++++++++++ interface/web/dashboard/dashlets/limits.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index bca97ed301..f78fb8ad8e 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -674,6 +674,22 @@ class functions { return $result; } + /** + * Lookup a client's group + all groups he is reselling. + * + * @return string Comma separated list of groupid's + */ + function clientid_to_groups_list($client_id) { + global $app; + + if ($client_id != null) { + // Get the clients groupid, and incase it's a reseller the groupid's of it's clients. + $group = $app->db->queryOneRecord("SELECT GROUP_CONCAT(groupid) AS groups FROM `sys_group` WHERE client_id IN (SELECT client_id FROM `client` WHERE client_id=? OR parent_client_id=?)", $client_id, $client_id); + return $group['groups']; + } + return null; + } + } ?> diff --git a/interface/web/dashboard/dashlets/limits.php b/interface/web/dashboard/dashlets/limits.php index 6cf7e9608f..80fa632d89 100644 --- a/interface/web/dashboard/dashlets/limits.php +++ b/interface/web/dashboard/dashlets/limits.php @@ -202,7 +202,7 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id)); + $sql .= $app->tform->getAuthSQL('r', '', '', $app->functions->clientid_to_groups_list($limit_to_client_id)); $rec = $app->db->queryOneRecord($sql, $limit['db_table']); return $rec['number']; @@ -216,7 +216,7 @@ class dashlet_limits if ($limit['db_where'] != '') { $sql .= $limit['db_where']." AND "; } - $sql .= $app->tform->getAuthSQL('r', '', '', $this->clientid_to_groups_list($limit_to_client_id)); + $sql .= $app->tform->getAuthSQL('r', '', '', $app->functions->clientid_to_groups_list($limit_to_client_id)); $rec = $app->db->queryOneRecord($sql, $limit['q_type'], $limit['db_table']); if ($limit['db_table'] == 'mail_user') { $quotaMB = $rec['number'] / 1048576; -- GitLab From a4a0e413018b6e64ea93682a0eae654d047e702d Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 30 Jul 2023 15:35:42 +0200 Subject: [PATCH 12/14] Ordering that makes more sence --- interface/web/client/client_edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php index 823a9ed3f6..7a510a6873 100644 --- a/interface/web/client/client_edit.php +++ b/interface/web/client/client_edit.php @@ -82,7 +82,7 @@ class page_action extends tform_actions { chdir('../dashboard'); $dashlet_list = array(); - $dashlets = array('databasequota.php', 'limits.php', 'mailquota.php', 'quota.php'); + $dashlets = array('quota.php', 'databasequota.php', 'mailquota.php', 'limits.php'); $current_client_id = $this->id; foreach ($dashlets as $file) { -- GitLab From 4f1a8cc467f16ca72f3dffdbba8b31d7fe07cd20 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 30 Jul 2023 15:38:30 +0200 Subject: [PATCH 13/14] Add the info tab to reseller_edit --- interface/lib/classes/quota_lib.inc.php | 24 ++++++------- interface/web/client/form/reseller.tform.php | 8 ++++- interface/web/client/reseller_edit.php | 35 +++++++++++++++++++ .../client/templates/reseller_edit_info.htm | 24 +++++++++++++ 4 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 interface/web/client/templates/reseller_edit_info.htm diff --git a/interface/lib/classes/quota_lib.inc.php b/interface/lib/classes/quota_lib.inc.php index e38a7e117f..1807a18685 100644 --- a/interface/lib/classes/quota_lib.inc.php +++ b/interface/lib/classes/quota_lib.inc.php @@ -14,11 +14,9 @@ class quota_lib { //print_r($monitor_data); // select all websites or websites belonging to client - $q = " SELECT * FROM web_domain - WHERE active = 'y' AND type = 'vhost'" - . 'AND sys_groupid ' . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" - : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") - . " ORDER BY domain"; + $q = "SELECT * FROM web_domain WHERE type = 'vhost' AND "; + $q .= $app->tform->getAuthSQL('r', '', '', $app->functions->clientid_to_groups_list($clientid)); + $q .= " ORDER BY domain"; $sites = $app->db->queryAllRecords($q, $clientid); //print_r($sites); @@ -214,10 +212,9 @@ class quota_lib { //print_r($monitor_data); // select all email accounts or email accounts belonging to client - $q = " SELECT * FROM mail_user" - . " WHERE sys_groupid " . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" - : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") - . " ORDER BY email"; + $q = "SELECT * FROM mail_user WHERE"; + $q .= $app->tform->getAuthSQL('r', '', '', $app->functions->clientid_to_groups_list($clientid)); + $q .= " ORDER BY email"; $emails = $app->db->queryAllRecords($q, $clientid); //print_r($emails); @@ -274,11 +271,10 @@ class quota_lib { //print_r($monitor_data); // select all databases belonging to client - $q = "SELECT * FROM web_database" - . " WHERE sys_groupid " . (($clientid != null) ? "= (SELECT default_group FROM sys_user WHERE client_id=?)" - : " IN (" . $_SESSION["s"]["user"]["groups"] . ")") - . " ORDER BY database_name"; - $databases = $app->db->queryAllRecords($q, $clientid); + $q = "SELECT * FROM web_database WHERE"; + $q .= $app->tform->getAuthSQL('r', '', '', $app->functions->clientid_to_groups_list($clientid)); + $q .= " ORDER BY database_name"; + $databases = $app->db->queryAllRecords($q); //print_r($databases); if(is_array($databases) && !empty($databases)){ diff --git a/interface/web/client/form/reseller.tform.php b/interface/web/client/form/reseller.tform.php index d48dea6229..6d5267bd08 100644 --- a/interface/web/client/form/reseller.tform.php +++ b/interface/web/client/form/reseller.tform.php @@ -45,7 +45,7 @@ $form["action"] = "reseller_edit.php"; $form["db_table"] = "client"; $form["db_table_idx"] = "client_id"; $form["db_history"] = "yes"; -$form["tab_default"] = "address"; +$form["tab_default"] = "info"; $form["list_default"] = "reseller_list.php"; $form["auth"] = 'yes'; @@ -80,6 +80,12 @@ while ($file = @readdir($handle)) { } } +$form["tabs"]['info'] = array( + 'title' => "Info", + 'width' => 100, + 'template' => "templates/reseller_edit_info.htm", + 'fields' => array() +); $form["tabs"]['address'] = array ( 'title' => "Address", 'width' => 100, diff --git a/interface/web/client/reseller_edit.php b/interface/web/client/reseller_edit.php index 10da3b78e1..4dc89293f9 100644 --- a/interface/web/client/reseller_edit.php +++ b/interface/web/client/reseller_edit.php @@ -72,10 +72,45 @@ class page_action extends tform_actions { } } + // Hide the info tab when creating a new client. + unset($app->tform->formDef["tabs"]['info']); + $app->tform->formDef["tab_default"] = "address"; + parent::onShowNew(); } + function onShowEdit() { + global $app, $conf; + chdir('../dashboard'); + + $dashlet_list = array(); + $dashlets = array('quota.php', 'databasequota.php', 'mailquota.php', 'limits.php'); + $current_client_id = $this->id; + + foreach ($dashlets as $file) { + if ($file != '.' && $file != '..' && !is_dir(ISPC_WEB_PATH.'/dashboard/dashlets/'.$file)) { + $dashlet_name = substr($file, 0, -4); + $dashlet_class = 'dashlet_'.$dashlet_name; + include_once ISPC_WEB_PATH.'/dashboard/dashlets/'.$file; + $dashlet_list[$dashlet_name] = new $dashlet_class; + $dashlets_html .= $dashlet_list[$dashlet_name]->show($current_client_id); + } + } + $app->tpl->setVar('dashlets', $dashlets_html); + + chdir('../client'); + + $tmp = $app->db->queryOneRecord("SELECT company_name, contact_firstname, contact_name, email FROM client WHERE client_id = ?", $current_client_id); + + $app->tpl->setVar('company_name', $tmp['company_name']); + $app->tpl->setVar('contact_name', $tmp['contact_name']); + $app->tpl->setVar('email', $tmp['email']); + + parent::onShowEdit(); + } + + function onSubmit() { global $app, $conf; diff --git a/interface/web/client/templates/reseller_edit_info.htm b/interface/web/client/templates/reseller_edit_info.htm new file mode 100644 index 0000000000..26e9258d6d --- /dev/null +++ b/interface/web/client/templates/reseller_edit_info.htm @@ -0,0 +1,24 @@ + + + + -- GitLab From 87e02a00ae94ffc5e51c230f46066a2d0872d004 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sun, 30 Jul 2023 15:38:45 +0200 Subject: [PATCH 14/14] cleanup --- interface/web/dashboard/dashlets/databasequota.php | 10 ---------- interface/web/dashboard/dashlets/mailquota.php | 1 - interface/web/dashboard/dashlets/quota.php | 11 ----------- 3 files changed, 22 deletions(-) diff --git a/interface/web/dashboard/dashlets/databasequota.php b/interface/web/dashboard/dashlets/databasequota.php index 20db5eafb4..2c488e37a6 100644 --- a/interface/web/dashboard/dashlets/databasequota.php +++ b/interface/web/dashboard/dashlets/databasequota.php @@ -42,14 +42,4 @@ class dashlet_databasequota { return $tpl->grab(); } } - } - - - - - - - - -?> diff --git a/interface/web/dashboard/dashlets/mailquota.php b/interface/web/dashboard/dashlets/mailquota.php index 9817358745..88cee26e33 100644 --- a/interface/web/dashboard/dashlets/mailquota.php +++ b/interface/web/dashboard/dashlets/mailquota.php @@ -46,5 +46,4 @@ class dashlet_mailquota { return $tpl->grab(); } } - } diff --git a/interface/web/dashboard/dashlets/quota.php b/interface/web/dashboard/dashlets/quota.php index 2dc695ae14..ce8ee91c75 100644 --- a/interface/web/dashboard/dashlets/quota.php +++ b/interface/web/dashboard/dashlets/quota.php @@ -25,7 +25,6 @@ class dashlet_quota { $tpl->setVar($wb); $sites = $app->quota_lib->get_quota_data($limit_to_client_id); - //print_r($sites); $has_quota = false; if(is_array($sites) && !empty($sites)){ @@ -49,14 +48,4 @@ class dashlet_quota { return $tpl->grab(); } } - } - - - - - - - - -?> -- GitLab