Gazelle/sections/ajax/usersearch.php

60 lines
1.4 KiB
PHP
Raw Normal View History

2011-10-31 08:00:12 +00:00
<?
/**********************************************************************
*>>>>>>>>>>>>>>>>>>>>>>>>>>> User search <<<<<<<<<<<<<<<<<<<<<<<<<<<<*
**********************************************************************/
if (!empty($_GET['search'])) {
2013-02-22 08:00:24 +00:00
2011-10-31 08:00:12 +00:00
$_GET['username'] = $_GET['search'];
}
2013-02-22 08:00:24 +00:00
2011-10-31 08:00:12 +00:00
define('USERS_PER_PAGE', 30);
if(isset($_GET['username'])){
$_GET['username'] = trim($_GET['username']);
2012-11-17 08:00:19 +00:00
2012-10-11 08:00:15 +00:00
list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE);
2011-10-31 08:00:12 +00:00
$DB->query("SELECT SQL_CALC_FOUND_ROWS
ID,
Username,
Enabled,
PermissionID,
Donor,
Warned
FROM users_main AS um
JOIN users_info AS ui ON ui.UserID=um.ID
WHERE Username LIKE '%".db_string($_GET['username'])."%'
ORDER BY Username
LIMIT $Limit");
$Results = $DB->to_array();
$DB->query('SELECT FOUND_ROWS();');
list($NumResults) = $DB->next_record();
}
$JsonUsers = array();
foreach($Results as $Result) {
list($UserID, $Username, $Enabled, $PermissionID, $Donor, $Warned) = $Result;
$JsonUsers[] = array(
2011-11-26 08:00:20 +00:00
'userId' => (int) $UserID,
2011-10-31 08:00:12 +00:00
'username' => $Username,
2011-11-26 08:00:20 +00:00
'donor' => $Donor == 1,
2012-01-28 08:00:29 +00:00
'warned' => ($Warned!='0000-00-00 00:00:00'),
2011-10-31 08:00:12 +00:00
'enabled' => ($Enabled == 2 ? false : true),
2012-10-11 08:00:15 +00:00
'class' => Users::make_class_string($PermissionID)
2011-10-31 08:00:12 +00:00
);
}
print
json_encode(
array(
'status' => 'success',
'response' => array(
2011-11-26 08:00:20 +00:00
'currentPage' => (int) $Page,
2011-10-31 08:00:12 +00:00
'pages' => ceil($NumResults/USERS_PER_PAGE),
'results' => $JsonUsers
)
)
2012-01-28 08:00:29 +00:00
);