diff --git a/webgui/include/ajax/functions/AdminUsers.php b/webgui/include/ajax/functions/AdminUsers.php index 29496488302ac92969969114a72334c1469073f1..97563bf7aaca57a7ab9e4df568fce98af3d93e1a 100644 --- a/webgui/include/ajax/functions/AdminUsers.php +++ b/webgui/include/ajax/functions/AdminUsers.php @@ -82,7 +82,50 @@ function removeAdminUser($params) { if ($res !== FALSE) { $res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0])); } - + + # Get list of topups and delete summaries + if ($res !== FALSE) { + $topupList = array(); + $res = DBSelect(" + SELECT + topups_summary.TopupID + FROM + topups_summary, topups + WHERE + topups_summary.TopupID = topups.ID + AND topups.UserID = ?", + array($params[0]) + ); + + if (!is_object($res)) { + $res = FALSE; + } else { + while ($row = $res->fetchObject()) { + array_push($topupList,$row->topupid); + } + } + + if ($res !== FALSE && sizeof($topupList) > 0) { + # Remove topup summaries + foreach ($topupList as $id) { + if ($res !== FALSE) { + $res = DBDo(" + DELETE FROM + topups_summary + WHERE + TopupID = ?", + array($id) + ); + } + } + } + } + + # Remove topups + if ($res !== FALSE) { + $res = DBDo("DELETE FROM topups WHERE UserID = ?",array($params[0])); + } + # Delete user if ($res !== FALSE) { $res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0])); diff --git a/webgui/include/ajax/functions/WiSPUsers.php b/webgui/include/ajax/functions/WiSPUsers.php index 51d5bec85db37e3e05aedaa777ebe8dbf20e5486..91c42ca85e8c9652f555357e5a59efb5831de9f8 100644 --- a/webgui/include/ajax/functions/WiSPUsers.php +++ b/webgui/include/ajax/functions/WiSPUsers.php @@ -181,6 +181,49 @@ function removeWiSPUser($params) { $res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0])); } + # Get list of topups and delete summaries + if ($res !== FALSE) { + $topupList = array(); + $res = DBSelect(" + SELECT + topups_summary.TopupID + FROM + topups_summary, topups + WHERE + topups_summary.TopupID = topups.ID + AND topups.UserID = ?", + array($params[0]) + ); + + if (!is_object($res)) { + $res = FALSE; + } else { + while ($row = $res->fetchObject()) { + array_push($topupList,$row->topupid); + } + } + + if ($res !== FALSE && sizeof($topupList) > 0) { + # Remove topup summaries + foreach ($topupList as $id) { + if ($res !== FALSE) { + $res = DBDo(" + DELETE FROM + topups_summary + WHERE + TopupID = ?", + array($id) + ); + } + } + } + } + + # Remove topups + if ($res !== FALSE) { + $res = DBDo("DELETE FROM topups WHERE UserID = ?",array($params[0])); + } + # Delete user if ($res !== FALSE) { $res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));