From b4a8418e105d3b337de1edee8e99a67a5a5aa626 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Tue, 25 Nov 2014 12:23:30 +0100 Subject: [PATCH] add possibility to move customers to another admin/reseller, fixes #1166 Signed-off-by: Michael Kaufmann (d00p) --- admin_customers.php | 31 ++++++++++ .../customer/formfield.customer_edit.php | 12 ++++ .../froxlor/function.moveCustomerToAdmin.php | 57 +++++++++++++++++++ lng/english.lng.php | 4 ++ 4 files changed, 104 insertions(+) create mode 100644 lib/functions/froxlor/function.moveCustomerToAdmin.php diff --git a/admin_customers.php b/admin_customers.php index ccbb7078..8172faf7 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -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 diff --git a/lib/formfields/admin/customer/formfield.customer_edit.php b/lib/formfields/admin/customer/formfield.customer_edit.php index 475bcf28..6d829598 100644 --- a/lib/formfields/admin/customer/formfield.customer_edit.php +++ b/lib/formfields/admin/customer/formfield.customer_edit.php @@ -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 + ) + ) ) ) ) diff --git a/lib/functions/froxlor/function.moveCustomerToAdmin.php b/lib/functions/froxlor/function.moveCustomerToAdmin.php new file mode 100644 index 00000000..8e3ad1d7 --- /dev/null +++ b/lib/functions/froxlor/function.moveCustomerToAdmin.php @@ -0,0 +1,57 @@ + $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; +} diff --git a/lng/english.lng.php b/lng/english.lng.php index 81cb82dd..5477d122 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -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
Leave this empty for no change.
If the desired admin does not show up in the list, his customer-limit has been reached.
'; +$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.

Error-message: %s';