Newer
Older
<?php
include_once("include/db.php");
# Return list of users
function getAdminUsers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users.ID',
'Username' => 'users.Username',
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM users",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
if (!isset($sth)) {
return $res;
}
$item['ID'] = $row->id;
$item['Username'] = $row->username;
$item['Disabled'] = $row->disabled;
return array($resultArray,$numResults);
function getAdminUser($params) {
$res = DBSelect("SELECT ID, Username, Disabled FROM users WHERE ID = ?",array($params[0]));
if (!is_object($res)) {
return $res;
}
$resultArray = array();
$row = $res->fetchObject();
$resultArray['ID'] = $row->id;
$resultArray['Username'] = $row->username;
$resultArray['Disabled'] = $row->disabled;
function removeAdminUser($params) {
# Begin transaction
DBBegin();
# Delete user information, if any
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
# Delete user attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
}
# Remove user from groups
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 (sizeof($topupList) > 0 && $res !== FALSE) {
# 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]));
}
# Commit and return if successful
# Else rollback database
} else {
DBRollback();
}
return NULL;
}
function createAdminUser($params) {
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
return $res;
}
return NULL;
}
function updateAdminUser($params) {
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
return $res;
}
return NULL;
}