* Admin: Allow deleting multiple accounts at once

This commit is contained in:
nathangray 2021-02-09 16:53:51 -07:00
parent 8dedc3392f
commit 1e15a6efc7
2 changed files with 44 additions and 22 deletions

View File

@ -307,25 +307,38 @@ class admin_account
);
}
else
{
if (strpos($_GET['account_id'],','))
{
$content = array('account_id' => array_map(function ($c) { return (int)$c; }, explode(',',$_GET['account_id'])));
}
else
{
$content = array('account_id' => (int)$_GET['account_id']);
}
}
//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') ||
$GLOBALS['egw_info']['user']['account_id'] == $content['account_id'])
$GLOBALS['egw_info']['user']['account_id'] == $content['account_id'] ||
(is_array($content['account_id']) && in_array($GLOBALS['egw_info']['user']['account_id'], $content['account_id']) )
)
{
Framework::window_close(lang('Permission denied!!!'));
}
if ($content['delete'])
{
$msg = '';
foreach($content['account_id'] as $account_id)
{
$cmd = new admin_cmd_delete_account(array(
'account' => $content['account_id'],
'account' => $account_id,
'new_user' => $content['new_owner'],
'is_user' => $content['account_id'] > 0,
'is_user' => $account_id > 0,
'change_apps' => $content['delete_apps']
) + (array)$content['admin_cmd']);
$msg = $cmd->run();
$msg = $cmd->run() . "\n";
}
if ($content['contact_id'])
{
Framework::refresh_opener($msg, 'addressbook', $content['contact_id'], 'delete');
@ -341,7 +354,14 @@ class admin_account
$preserve = $content;
// Get a count of entries owned by the user
if(!is_array($content['account_id']))
{
$counts = $GLOBALS['egw']->accounts->get_account_entry_counts($content['account_id']);
}
else
{
$counts = array_fill_keys(array_keys($GLOBALS['egw_info']['apps']),'-');
}
foreach ($counts as $app => $counts)
{
$entry = Api\Link::get_registry($app, 'entries');
@ -354,10 +374,10 @@ class admin_account
$content['delete_apps'][] = $app;
$sel_options['delete_apps'][] = array(
'value' => $app,
'label' => lang($app) . ': ' . $counts['total'] . ' '.$entry
'label' => lang($app) . (is_array($counts) ? (': ' . $counts['total'] . ' ' . $entry) : '')
);
}
else if ($counts['total'])
else if (is_array($counts) && $counts['total'])
{
// These ones don't support the needed hook
$content['counts'][] = array(
@ -377,6 +397,8 @@ class admin_account
$content['delete_apps'][] = $app;
}
$content['account_id'] = (array)$content['account_id'];
$tpl = new Etemplate('admin.account.delete');
$tpl->exec('admin_account::delete', $content, $sel_options, array(), $preserve, 2);
}

View File

@ -226,7 +226,7 @@ class admin_ui
'group' => ++$group,
'popup' => '615x600',
'url' => 'menuaction=admin.admin_account.delete&account_id=$id',
'allowOnMultiple' => false,
'allowOnMultiple' => true,
);
}
//error_log(__METHOD__."() actions=".array2string($actions));