From e08247d60ac8afc0f6349351724ed6181a8546db Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 19 Jun 2019 10:34:09 -0600 Subject: [PATCH] Admin - show a count of how many entries a user owns in delete dialog --- admin/inc/class.admin_account.inc.php | 18 ++++ admin/lang/egw_en.lang | 1 + admin/templates/default/account.delete.xet | 13 +++ api/src/Accounts.php | 96 ++++++++++++++++++++++ 4 files changed, 128 insertions(+) diff --git a/admin/inc/class.admin_account.inc.php b/admin/inc/class.admin_account.inc.php index 2ce2bb784d..78c1414d3c 100644 --- a/admin/inc/class.admin_account.inc.php +++ b/admin/inc/class.admin_account.inc.php @@ -264,6 +264,24 @@ class admin_account { $content = array('account_id' => (int)$_GET['account_id']); } + + // Get a count of entries owned by the user + $counts = $GLOBALS['egw']->accounts->get_account_entry_counts($content['account_id']); + foreach($counts as $app => $counts) + { + $entry = Api\Link::get_registry($app, 'entries'); + if(!$entry) + { + $entry = lang('Entries'); + } + if($counts['total']) + { + $content['counts'][] = array( + 'app' => $app, + 'count' => $counts['total'] . ' '.$entry + ); + } + } //error_log(__METHOD__."() \$_GET[account_id]=$_GET[account_id], \$_GET[contact_id]=$_GET[contact_id] content=".array2string($content)); } if ($GLOBALS['egw']->acl->check('account_access',32,'admin') || diff --git a/admin/lang/egw_en.lang b/admin/lang/egw_en.lang index 53e72c2f51..4f1f2a34d4 100644 --- a/admin/lang/egw_en.lang +++ b/admin/lang/egw_en.lang @@ -401,6 +401,7 @@ enter your http proxy server port admin en Enter your HTTP proxy server port enter your smtp server hostname or ip address admin en Enter your SMTP server hostname or IP address enter your smtp server port admin en Enter your SMTP server port entry saved admin en Entry saved +entries owned by the user: admin en Entries owned by the user: error canceling timer, maybe there's none set !!! admin en Error canceling timer, maybe there's none set! error changing the password for %1 !!! admin en Error changing the password for %1 ! error connecting to imap server. %s : %s. admin en Error connecting to IMAP server. %s : %s. diff --git a/admin/templates/default/account.delete.xet b/admin/templates/default/account.delete.xet index 7bdc63fa55..6fb9266366 100644 --- a/admin/templates/default/account.delete.xet +++ b/admin/templates/default/account.delete.xet @@ -23,6 +23,19 @@ + + + + + + + + + + + + + diff --git a/api/src/Accounts.php b/api/src/Accounts.php index c7fc90cce7..abe55339b7 100644 --- a/api/src/Accounts.php +++ b/api/src/Accounts.php @@ -1037,6 +1037,102 @@ class Accounts } return False; } +/** + * Get a list of how many entries of each app the account has + * + * @param int $account_id + * + * @return array app => count + */ + public function get_account_entry_counts($account_id) + { + $owner_columns = static::get_owner_columns(); + + $selects = array(); + + foreach($owner_columns as $app => $column) + { + list($table, $column_name) = explode('.', $column['column']); + $select = array( + 'table' => $table, + 'cols' => array( + "'$app' AS app", + '"total" AS type', + 'count(' . $column['key'] . ') AS count' + ), + 'where' => array( + $column['column'] => (int)$account_id + ), + 'app' => $app + ); + switch($app) + { + case 'infolog': + $select['cols'][1] = 'info_type AS type'; + $select['append'] = ' GROUP BY info_type'; + break; + } + $selects[] = $select; + } + + $counts = array(); + foreach($GLOBALS['egw']->db->union($selects, __LINE__ , __FILE__) as $row) + { + if(!is_array($counts[$row['app']])) + { + $counts[$row['app']] = array('total' => 0); + } + $counts[$row['app']][$row['type']] = $row['count']; + if($row['type'] != 'total') + { + $counts[$row['app']]['total'] += $row['count']; + } + } + + return $counts; + } + protected function get_owner_columns() + { + $owner_columns = array(); + foreach($GLOBALS['egw_info']['apps'] as $appname => $app) + { + // Check hook + $owner_column = Link::get_registry($appname, 'owner'); + + // Try for automatically finding the modification + if(!is_array($owner_column) && !in_array($appname, array('admin', 'api','etemplate'))) + { + $tables = $GLOBALS['egw']->db->get_table_definitions($appname); + if(!is_array($tables)) + { + continue; + } + foreach($tables as $table_name => $table) + { + foreach($table['fd'] as $column_name => $column) + { + if((strpos($column_name, 'owner') !== FALSE || strpos($column_name, 'creator') !== FALSE) && + ($column['meta'] == 'account' || $column['meta'] == 'user') + ) + { + $owner_column = array( + 'key' => $table_name . '.' . $table['pk'][0], + 'column' => $table_name . '.' . $column_name, + 'type' => $column['type'] + ); + break 2; + } + } + } + } + if($owner_column) + { + $owner_columns[$appname] = $owner_column; + } + } + + return $owner_columns; + } /** * Add an account for an authenticated user