diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php
index 68cb50f1..c3529435 100644
--- a/data/web/inc/functions.mailbox.inc.php
+++ b/data/web/inc/functions.mailbox.inc.php
@@ -4323,7 +4323,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
$mailboxdata['active'] = $row['active'];
$mailboxdata['active_int'] = $row['active'];
$mailboxdata['domain'] = $row['domain'];
- $mailboxdata['relayhost'] = $row['relayhost'];
$mailboxdata['name'] = $row['name'];
$mailboxdata['local_part'] = $row['local_part'];
$mailboxdata['quota'] = $row['quota'];
diff --git a/data/web/inc/lib/ssp.class.php b/data/web/inc/lib/ssp.class.php
index c36c627c..a06e7d09 100644
--- a/data/web/inc/lib/ssp.class.php
+++ b/data/web/inc/lib/ssp.class.php
@@ -43,7 +43,7 @@ class SSP {
}
}
else {
- if(!empty($column['db'])){
+ if(!empty($column['db']) && (!isset($column['dummy']) || $column['dummy'] !== true)){
$row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ];
}
else{
@@ -115,10 +115,12 @@ class SSP {
*/
static function order ( $tableAS, $request, $columns )
{
+ $select = '';
$order = '';
if ( isset($request['order']) && count($request['order']) ) {
- $orderBy = array();
+ $selects = [];
+ $orderBy = [];
$dtColumns = self::pluck( $columns, 'dt' );
for ( $i=0, $ien=count($request['order']) ; $i<$ien ; $i++ ) {
@@ -133,17 +135,26 @@ class SSP {
$dir = $request['order'][$i]['dir'] === 'asc' ?
'ASC' :
'DESC';
-
- $orderBy[] = '`'.$tableAS.'`.`'.$column['db'].'` '.$dir;
+
+ if(isset($column['order_subquery'])) {
+ $selects[] = '('.$column['order_subquery'].') AS `'.$column['db'].'_count`';
+ $orderBy[] = '`'.$column['db'].'_count` '.$dir;
+ } else {
+ $orderBy[] = '`'.$tableAS.'`.`'.$column['db'].'` '.$dir;
+ }
}
}
+ if ( count( $selects ) ) {
+ $select = ', '.implode(', ', $selects);
+ }
+
if ( count( $orderBy ) ) {
$order = 'ORDER BY '.implode(', ', $orderBy);
}
}
- return $order;
+ return [$select, $order];
}
@@ -257,13 +268,14 @@ class SSP {
}
// Build the SQL query string from the request
+ list($select, $order) = self::order( $tablesAS, $request, $columns );
$limit = self::limit( $request, $columns );
- $order = self::order( $tablesAS, $request, $columns );
$where = self::filter( $tablesAS, $request, $columns, $bindings );
// Main query to actually get the data
$data = self::sql_exec( $db, $bindings,
"SELECT `$tablesAS`.`".implode("`, `$tablesAS`.`", self::pluck($columns, 'db'))."`
+ $select
FROM `$table` AS `$tablesAS`
$where
$order
@@ -348,8 +360,8 @@ class SSP {
}
// Build the SQL query string from the request
+ list($select, $order) = self::order( $tablesAS, $request, $columns );
$limit = self::limit( $request, $columns );
- $order = self::order( $tablesAS, $request, $columns );
$where = self::filter( $tablesAS, $request, $columns, $bindings );
// whereResult can be a simple string, or an assoc. array with a
@@ -373,6 +385,7 @@ class SSP {
// Main query to actually get the data
$data = self::sql_exec( $db, $bindings,
"SELECT `$tablesAS`.`".implode("`, `$tablesAS`.`", self::pluck($columns, 'db'))."`
+ $select
FROM `$table` AS `$tablesAS`
$join
$where
@@ -556,6 +569,9 @@ class SSP {
if ( empty($a[$i][$prop]) && $a[$i][$prop] !== 0 ) {
continue;
}
+ if ( $prop == 'db' && isset($a[$i]['dummy']) && $a[$i]['dummy'] === true ) {
+ continue;
+ }
//removing the $out array index confuses the filter method in doing proper binding,
//adding it ensures that the array data are mapped correctly
diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js
index fe6113a8..c6f57d45 100644
--- a/data/web/js/site/mailbox.js
+++ b/data/web/js/site/mailbox.js
@@ -552,7 +552,6 @@ jQuery(function($){
title: lang.stats,
data: 'stats',
searchable: false,
- orderable: false,
defaultContent: '',
render: function (data, type) {
data = data.split("/");
@@ -563,14 +562,12 @@ jQuery(function($){
title: lang.mailbox_defquota,
data: 'def_quota_for_mbox',
searchable: false,
- orderable: false,
defaultContent: ''
},
{
title: lang.mailbox_quota,
data: 'max_quota_for_mbox',
searchable: false,
- orderable: false,
defaultContent: ''
},
{
@@ -584,10 +581,9 @@ jQuery(function($){
title: lang.backup_mx,
data: 'backupmx',
searchable: false,
- orderable: false,
defaultContent: '',
- redner: function (data, type){
- return 1==value ? '' : 0==value && '';
+ render: function (data, type){
+ return 1==data ? '' : 0==data && '';
}
},
{
@@ -626,7 +622,6 @@ jQuery(function($){
title: lang.active,
data: 'active',
searchable: false,
- orderable: false,
defaultContent: '',
responsivePriority: 6,
render: function (data, type) {
diff --git a/data/web/json_api.php b/data/web/json_api.php
index 3077bf7b..0f0c23b1 100644
--- a/data/web/json_api.php
+++ b/data/web/json_api.php
@@ -528,9 +528,14 @@ if (isset($_GET['query'])) {
$primaryKey = 'domain';
$columns = [
['db' => 'domain', 'dt' => 2],
- ['db' => 'aliases', 'dt' => 3],
- ['db' => 'mailboxes', 'dt' => 4],
- ['db' => 'quota', 'dt' => 5],
+ ['db' => 'aliases', 'dt' => 3, 'order_subquery' => "SELECT COUNT(*) FROM `alias` WHERE (`domain`= `d`.`domain` OR `domain` IN (SELECT `alias_domain` FROM `alias_domain` WHERE `target_domain` = `d`.`domain`)) AND `address` NOT IN (SELECT `username` FROM `mailbox`)"],
+ ['db' => 'mailboxes', 'dt' => 4, 'order_subquery' => "SELECT COUNT(*) FROM `mailbox` WHERE `mailbox`.`domain` = `d`.`domain` AND (`mailbox`.`kind` = '' OR `mailbox`.`kind` = NULL)"],
+ ['db' => 'quota', 'dt' => 5, 'order_subquery' => "SELECT COALESCE(SUM(`mailbox`.`quota`), 0) FROM `mailbox` WHERE `mailbox`.`domain` = `d`.`domain` AND (`mailbox`.`kind` = '' OR `mailbox`.`kind` = NULL)"],
+ ['db' => 'stats', 'dt' => 6, 'dummy' => true, 'order_subquery' => "SELECT SUM(bytes) FROM `quota2` WHERE `quota2`.`username` IN (SELECT `username` FROM `mailbox` WHERE `domain` = `d`.`domain`)"],
+ ['db' => 'defquota', 'dt' => 7],
+ ['db' => 'maxquota', 'dt' => 8],
+ ['db' => 'backupmx', 'dt' => 10],
+ ['db' => 'active', 'dt' => 15],
];
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/ssp.class.php';