add possibility to move customers to another admin/reseller, fixes #1166

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2014-11-25 12:23:30 +01:00
parent e4ceb962e9
commit b4a8418e10
4 changed files with 104 additions and 0 deletions

View File

@@ -1000,6 +1000,24 @@ if ($page == 'customers'
}
$result = Database::pexecute_first($result_stmt, $result_data);
/*
* information for moving customer
*/
$available_admins_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_ADMINS . "`
WHERE (`customers` = '-1' OR `customers` < `customers_used`)"
);
Database::pexecute($available_admins_stmt);
$admin_select = makeoption("-----", 0, true, true, true);
$admin_select_cnt = 0;
while ($available_admin = $available_admins_stmt->fetch()) {
$admin_select .= makeoption($available_admin['name']." (".$available_admin['loginname'].")", $available_admin['adminid'], null, true, true);
$admin_select_cnt++;
}
/*
* end of moving customer stuff
*/
if ($result['loginname'] != '') {
if (isset($_POST['send'])
@@ -1020,6 +1038,8 @@ if ($page == 'customers'
$password = validate($_POST['new_customer_password'], 'new password');
$gender = intval_ressource($_POST['gender']);
$move_to_admin = intval_ressource($_POST['move_to_admin']);
$diskspace = intval_ressource($_POST['diskspace']);
if (isset($_POST['diskspace_ul'])) {
$diskspace = - 1;
@@ -1498,6 +1518,17 @@ if ($page == 'customers'
$admin_update_query.= " WHERE `adminid` = '" . (int)$result['adminid'] . "'";
Database::query($admin_update_query);
$log->logAction(ADM_ACTION, LOG_INFO, "edited user '" . $result['loginname'] . "'");
/*
* move customer to another admin/reseller; #1166
*/
if ($move_to_admin > 0 && $move_to_admin != $result['adminid']) {
$move_result = moveCustomerToAdmin($id, $move_to_admin);
if ($move_result != true) {
standard_error('moveofcustomerfailed', $move_result);
}
}
$redirect_props = Array(
'page' => $page,
's' => $s

View File

@@ -252,6 +252,18 @@ return array(
'value' => array($result['perlenabled'])
)
)
),
'section_d' => array(
'title' => $lng['admin']['movetoadmin'],
'image' => 'icons/user_edit.png',
'visible' => ($admin_select_cnt > 1),
'fields' => array(
'move_to_admin' => array(
'label' => $lng['admin']['movecustomertoadmin'],
'type' => 'select',
'select_var' => $admin_select
)
)
)
)
)

View File

@@ -0,0 +1,57 @@
<?php
/**
* Function to move a given customer to a given admin/reseller
* and update all its references accordingly
*
* @param int $id customer-id
* @param int $adminid target-admin-id
*
* @return true on sucess, error-message on failure
*/
function moveCustomerToAdmin($id = 0, $adminid = 0) {
if ($id <= 0 || $adminid <= 0) {
return "no valid id's given";
}
// get current admin-id
$cAdmin_stmt = Database::prepare ( "
SELECT `adminid` FROM `" . TABLE_PANEL_CUSTOMERS . "`
WHERE `customerid` = :cid
" );
$cAdmin = Database::pexecute_first ( $cAdmin_stmt, array (
'cid' => $id
) );
// Update customer entry
$updCustomer_stmt = Database::prepare ( "
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `adminid` = :adminid WHERE `customerid` = :cid
" );
Database::pexecute ( $updCustomer_stmt, array (
'adminid' => $cAdmin ['adminid'],
'cid' => $id
) );
// Update customer-domains
$updDomains_stmt = Database::prepare ( "
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET `adminid` = :adminid WHERE `customerid` = :cid
" );
Database::pexecute ( $updDomains_stmt, array (
'adminid' => $cAdmin ['adminid'],
'cid' => $id
) );
// Update customer-tickets
$updTickets_stmt = Database::prepare ( "
UPDATE `" . TABLE_PANEL_TICKETS . "` SET `adminid` = :adminid WHERE `customerid` = :cid
" );
Database::pexecute ( $updTickets_stmt, array (
'adminid' => $cAdmin ['adminid'],
'cid' => $id
) );
// now, recalculate the resource-usage for the old and the new admin
updateCounters ( false );
return true;
}

View File

@@ -1836,3 +1836,7 @@ $lng['serversettings']['panel_password_special_char']['description'] = 'One of t
$lng['phpfpm']['use_mod_proxy']['title'] = 'Use mod_proxy / mod_proxy_fcgi';
$lng['phpfpm']['use_mod_proxy']['description'] = 'Activate to use php-fpm via mod_proxy_fcgi. Requires at least apache-2.4.9';
$lng['error']['no_phpinfo'] = 'Sorry, unable to read phpinfo()';
$lng['admin']['movetoadmin'] = 'Move customer';
$lng['admin']['movecustomertoadmin'] = 'Move customer to the selected admin/reseller<br /><small>Leave this empty for no change.<br />If the desired admin does not show up in the list, his customer-limit has been reached.</small>';
$lng['error']['moveofcustomerfailed'] = 'Moving the customer to the selected admin/reseller failed. Keep in mind that all other changes to the customer were applied successfully at this stage.<br><br>Error-message: %s';