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

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