<?php

$accessControl = array('Admin' => true); 
require_once '../../AccessControl.php';

$result = array(
	"Status" => "Success"
	,"Users" => array()
);

if(!empty($_POST['deleteUser'])){
    $db->Execute("DELETE FROM " . TBL_USERS . " WHERE `username`= ?", array($_POST['deleteUser'])) or die(
    json_encode(
        array("Status" => "Error", "Message" => $db->ErrorMsg())
    )
    );
    $result['Message'] = _USERS_DELETED;
}

$db->SetFetchMode(ADODB_FETCH_ASSOC);
//$q = $db->Execute("SELECT userid,username,password,name,email,profiles,created,isAdmin,active,lastlogin FROM ". TBL_USERS );
if (isset($_POST['username']) ) {
	$q = $db->Execute("SELECT * FROM ". TBL_USERS. " WHERE `username`= ?", array( $_POST['username'] ));
} else {
	$q = $db->Execute("SELECT * FROM ". TBL_USERS );
}
while($row = $q->fetchRow()){
	$row['lgpkey'] = md5($row['username']) . ":" . $row['password'];
	$row['metadata'] = json_decode($row['metadata'] , true);
	$result["Users"][] = $row;
}
$db->SetFetchMode(ADODB_FETCH_BOTH);
echo json_encode($result);
?>