Admin - show a count of how many entries a user owns in delete dialog

This commit is contained in:
nathangray 2019-06-19 10:34:09 -06:00
parent afdee4b2eb
commit e08247d60a
4 changed files with 128 additions and 0 deletions

View File

@ -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') ||

View File

@ -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.

View File

@ -23,6 +23,19 @@
<vbox class="admin_account_delete">
<description value="Who would you like to transfer ALL records owned by the deleted user to?" class="dialogHeader2"/>
<select-account id="new_owner" empty_label="Delete all records" class="dialogHeader3"/>
<description value="Entries owned by the user:"/>
<grid id="counts">
<columns>
<column width="150"/>
<column/>
</columns>
<rows>
<row>
<select-app id="${row}[app]" readonly="true"/>
<description id="${row}[count]"/>
</row>
</rows>
</grid>
</vbox>
</template>
</overlay>

View File

@ -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