Gazelle/sections/ajax/usersearch.php

59 lines
1.4 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2011-10-31 08:00:12 +00:00
/**********************************************************************
*>>>>>>>>>>>>>>>>>>>>>>>>>>> User search <<<<<<<<<<<<<<<<<<<<<<<<<<<<*
**********************************************************************/
2013-04-24 08:00:23 +00:00
if (empty($_GET['search'])) {
2013-05-14 08:00:34 +00:00
json_die("failure", "no search terms");
2013-04-24 08:00:23 +00:00
} else {
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);
2013-05-04 08:00:48 +00:00
if (isset($_GET['username'])) {
2011-10-31 08:00:12 +00:00
$_GET['username'] = trim($_GET['username']);
2013-05-16 16:15:57 +00:00
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(USERS_PER_PAGE);
2013-05-06 08:00:32 +00:00
$DB->query("
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-05-06 08:00:32 +00:00
ID,
Username,
Enabled,
PermissionID,
Donor,
2013-06-12 08:00:46 +00:00
Warned,
Avatar
2011-10-31 08:00:12 +00:00
FROM users_main AS um
2013-10-30 08:01:19 +00:00
JOIN users_info AS ui ON ui.UserID = um.ID
2011-10-31 08:00:12 +00:00
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();
2013-05-06 08:00:32 +00:00
foreach ($Results as $Result) {
2013-06-12 08:00:46 +00:00
list($UserID, $Username, $Enabled, $PermissionID, $Donor, $Warned, $Avatar) = $Result;
2011-10-31 08:00:12 +00:00
$JsonUsers[] = array(
2013-10-30 08:01:19 +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,
2013-05-29 08:00:51 +00:00
'warned' => ($Warned != '0000-00-00 00:00:00'),
2011-10-31 08:00:12 +00:00
'enabled' => ($Enabled == 2 ? false : true),
2013-06-12 08:00:46 +00:00
'class' => Users::make_class_string($PermissionID),
'avatar' => $Avatar
2011-10-31 08:00:12 +00:00
);
}
2015-01-28 08:00:26 +00:00
json_print("success", array(
2013-10-30 08:01:19 +00:00
'currentPage' => (int)$Page,
2013-05-14 08:00:34 +00:00
'pages' => ceil($NumResults / USERS_PER_PAGE),
'results' => $JsonUsers
2013-04-24 08:00:23 +00:00
));