Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

advancedsearch.php 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?
  2. if (!empty($_GET['search'])) {
  3. if (preg_match('/^'.IP_REGEX.'$/', $_GET['search'])) {
  4. $_GET['ip'] = $_GET['search'];
  5. } elseif (preg_match('/^'.EMAIL_REGEX.'$/i', $_GET['search'])) {
  6. $_GET['email'] = $_GET['search'];
  7. } elseif (preg_match(USERNAME_REGEX,$_GET['search'])) {
  8. $DB->query("
  9. SELECT ID
  10. FROM users_main
  11. WHERE Username = '".db_string($_GET['search'])."'");
  12. if (list($ID) = $DB->next_record()) {
  13. header("Location: user.php?id=$ID");
  14. die();
  15. }
  16. $_GET['username'] = $_GET['search'];
  17. } else {
  18. $_GET['comment'] = $_GET['search'];
  19. }
  20. }
  21. define('USERS_PER_PAGE', 30);
  22. function wrap($String, $ForceMatch = '', $IPSearch = false) {
  23. if (!$ForceMatch) {
  24. global $Match;
  25. } else {
  26. $Match = $ForceMatch;
  27. }
  28. if ($Match == ' REGEXP ') {
  29. if (strpos($String, '\'') !== false || preg_match('/^.*\\\\$/i', $String)) {
  30. error('Regex contains illegal characters.');
  31. }
  32. } else {
  33. $String = db_string($String);
  34. }
  35. if ($Match == ' LIKE ') {
  36. // Fuzzy search
  37. // Stick in wildcards at beginning and end of string unless string starts or ends with |
  38. if (($String[0] != '|') && !$IPSearch) {
  39. $String = "%$String";
  40. } elseif ($String[0] == '|') {
  41. $String = substr($String, 1, strlen($String));
  42. }
  43. if (substr($String, -1, 1) != '|') {
  44. $String = "$String%";
  45. } else {
  46. $String = substr($String, 0, -1);
  47. }
  48. }
  49. $String = "'$String'";
  50. return $String;
  51. }
  52. function date_compare($Field, $Operand, $Date1, $Date2 = '') {
  53. $Date1 = db_string($Date1);
  54. $Date2 = db_string($Date2);
  55. $Return = array();
  56. switch ($Operand) {
  57. case 'on':
  58. $Return [] = " $Field >= '$Date1 00:00:00' ";
  59. $Return [] = " $Field <= '$Date1 23:59:59' ";
  60. break;
  61. case 'before':
  62. $Return [] = " $Field < '$Date1 00:00:00' ";
  63. break;
  64. case 'after':
  65. $Return [] = " $Field > '$Date1 23:59:59' ";
  66. break;
  67. case 'between':
  68. $Return [] = " $Field >= '$Date1 00:00:00' ";
  69. $Return [] = " $Field <= '$Date2 00:00:00' ";
  70. break;
  71. }
  72. return $Return;
  73. }
  74. function num_compare($Field, $Operand, $Num1, $Num2 = '') {
  75. if ($Num1 != 0) {
  76. $Num1 = db_string($Num1);
  77. }
  78. if ($Num2 != 0) {
  79. $Num2 = db_string($Num2);
  80. }
  81. $Return = array();
  82. switch ($Operand) {
  83. case 'equal':
  84. $Return [] = " $Field = '$Num1' ";
  85. break;
  86. case 'above':
  87. $Return [] = " $Field > '$Num1' ";
  88. break;
  89. case 'below':
  90. $Return [] = " $Field < '$Num1' ";
  91. break;
  92. case 'between':
  93. $Return [] = " $Field > '$Num1' ";
  94. $Return [] = " $Field < '$Num2' ";
  95. break;
  96. default:
  97. print_r($Return);
  98. die();
  99. }
  100. return $Return;
  101. }
  102. // Arrays, regexes, and all that fun stuff we can use for validation, form generation, etc
  103. $DateChoices = array('inarray'=>array('on', 'before', 'after', 'between'));
  104. $SingleDateChoices = array('inarray'=>array('on', 'before', 'after'));
  105. $NumberChoices = array('inarray'=>array('equal', 'above', 'below', 'between', 'buffer'));
  106. $YesNo = array('inarray'=>array('any', 'yes', 'no'));
  107. $OrderVals = array('inarray'=>array('Username', 'Ratio', 'IP', 'Email', 'Joined', 'Last Seen', 'Uploaded', 'Downloaded', 'Invites', 'Snatches'));
  108. $WayVals = array('inarray'=>array('Ascending', 'Descending'));
  109. if (count($_GET)) {
  110. $DateRegex = array('regex' => '/\d{4}-\d{2}-\d{2}/');
  111. $ClassIDs = array();
  112. $SecClassIDs = array();
  113. foreach ($Classes as $ClassID => $Value) {
  114. if ($Value['Secondary']) {
  115. $SecClassIDs[] = $ClassID;
  116. } else {
  117. $ClassIDs[] = $ClassID;
  118. }
  119. }
  120. $Val->SetFields('comment', '0', 'string', 'Comment is too long.', array('maxlength' => 512));
  121. $Val->SetFields('disabled_invites', '0', 'inarray', 'Invalid disabled_invites field', $YesNo);
  122. $Val->SetFields('joined', '0', 'inarray', 'Invalid joined field', $DateChoices);
  123. $Val->SetFields('join1', '0', 'regex', 'Invalid join1 field', $DateRegex);
  124. $Val->SetFields('join2', '0', 'regex', 'Invalid join2 field', $DateRegex);
  125. $Val->SetFields('lastactive', '0', 'inarray', 'Invalid lastactive field', $DateChoices);
  126. $Val->SetFields('lastactive1', '0', 'regex', 'Invalid lastactive1 field', $DateRegex);
  127. $Val->SetFields('lastactive2', '0', 'regex', 'Invalid lastactive2 field', $DateRegex);
  128. $Val->SetFields('ratio', '0', 'inarray', 'Invalid ratio field', $NumberChoices);
  129. $Val->SetFields('uploaded', '0', 'inarray', 'Invalid uploaded field', $NumberChoices);
  130. $Val->SetFields('downloaded', '0', 'inarray', 'Invalid downloaded field', $NumberChoices);
  131. //$Val->SetFields('snatched', '0', 'inarray', 'Invalid snatched field', $NumberChoices);
  132. $Val->SetFields('matchtype', '0', 'inarray', 'Invalid matchtype field', array('inarray' => array('strict', 'fuzzy', 'regex')));
  133. $Val->SetFields('lockedaccount', '0', 'inarray', 'Invalid locked account field', array('inarray' => array('any', 'locked', 'unlocked')));
  134. $Val->SetFields('enabled', '0', 'inarray', 'Invalid enabled field', array('inarray' => array('', 0, 1, 2)));
  135. $Val->SetFields('class', '0', 'inarray', 'Invalid class', array('inarray' => $ClassIDs));
  136. $Val->SetFields('secclass', '0', 'inarray', 'Invalid class', array('inarray' => $SecClassIDs));
  137. $Val->SetFields('donor', '0', 'inarray', 'Invalid donor field', $YesNo);
  138. $Val->SetFields('warned', '0', 'inarray', 'Invalid warned field', $YesNo);
  139. $Val->SetFields('disabled_uploads', '0', 'inarray', 'Invalid disabled_uploads field', $YesNo);
  140. $Val->SetFields('order', '0', 'inarray', 'Invalid ordering', $OrderVals);
  141. $Val->SetFields('way', '0', 'inarray', 'Invalid way', $WayVals);
  142. $Val->SetFields('passkey', '0', 'string', 'Invalid passkey', array('maxlength' => 32));
  143. $Val->SetFields('avatar', '0', 'string', 'Avatar URL too long', array('maxlength' => 512));
  144. $Val->SetFields('stylesheet', '0', 'inarray', 'Invalid stylesheet', array_unique(array_keys($Stylesheets)));
  145. $Val->SetFields('cc', '0', 'inarray', 'Invalid Country Code', array('maxlength' => 2));
  146. $Err = $Val->ValidateForm($_GET);
  147. if (!$Err) {
  148. // Passed validation. Let's rock.
  149. $RunQuery = false; // if we should run the search
  150. if (isset($_GET['matchtype']) && $_GET['matchtype'] == 'strict') {
  151. $Match = ' = ';
  152. } elseif (isset($_GET['matchtype']) && $_GET['matchtype'] == 'regex') {
  153. $Match = ' REGEXP ';
  154. } else {
  155. $Match = ' LIKE ';
  156. }
  157. $OrderTable = array(
  158. 'Username' => 'um1.Username',
  159. 'Joined' => 'ui1.JoinDate',
  160. 'Email' => 'um1.Email',
  161. 'IP' => 'um1.IP',
  162. 'Last Seen' => 'um1.LastAccess',
  163. 'Uploaded' => 'um1.Uploaded',
  164. 'Downloaded' => 'um1.Downloaded',
  165. 'Ratio' => '(um1.Uploaded / um1.Downloaded)',
  166. 'Invites' => 'um1.Invites',
  167. 'Snatches' => 'Snatches');
  168. $WayTable = array('Ascending'=>'ASC', 'Descending'=>'DESC');
  169. $Where = array();
  170. $Having = array();
  171. $Join = array();
  172. $Group = array();
  173. $Distinct = '';
  174. $Order = '';
  175. $SQL = '
  176. SQL_CALC_FOUND_ROWS
  177. um1.ID,
  178. um1.Username,
  179. um1.Uploaded,
  180. um1.Downloaded,';
  181. if ($_GET['snatched'] == 'off') {
  182. $SQL .= "'X' AS Snatches,";
  183. } else {
  184. $SQL .= "
  185. (
  186. SELECT COUNT(xs.uid)
  187. FROM xbt_snatched AS xs
  188. WHERE xs.uid = um1.ID
  189. ) AS Snatches,";
  190. }
  191. if ($_GET['invitees'] == 'off') {
  192. $SQL .= "'X' AS Invitees,";
  193. } else {
  194. $SQL .= "
  195. (
  196. SELECT COUNT(ui2.UserID)
  197. FROM users_info AS ui2
  198. WHERE um1.ID = ui2.Inviter
  199. ) AS Invitees,";
  200. }
  201. $SQL .= '
  202. um1.PermissionID,
  203. um1.Email,
  204. um1.Enabled,
  205. um1.IP,
  206. um1.Invites,
  207. ui1.DisableInvites,
  208. ui1.Warned,
  209. ui1.Donor,
  210. ui1.JoinDate,
  211. um1.LastAccess
  212. FROM users_main AS um1
  213. JOIN users_info AS ui1 ON ui1.UserID = um1.ID ';
  214. if (!empty($_GET['username'])) {
  215. $Where[] = 'um1.Username'.$Match.wrap($_GET['username']);
  216. }
  217. if (!empty($_GET['email'])) {
  218. if (isset($_GET['email_history'])) {
  219. $Distinct = 'DISTINCT ';
  220. $Join['he'] = ' JOIN users_history_emails AS he ON he.UserID = um1.ID ';
  221. $Where[] = ' he.Email '.$Match.wrap($_GET['email']);
  222. } else {
  223. $Where[] = 'um1.Email'.$Match.wrap($_GET['email']);
  224. }
  225. }
  226. if (!empty($_GET['email_cnt']) && is_number($_GET['email_cnt'])) {
  227. $Query = "
  228. SELECT UserID
  229. FROM users_history_emails
  230. GROUP BY UserID
  231. HAVING COUNT(DISTINCT Email) ";
  232. if ($_GET['emails_opt'] === 'equal') {
  233. $operator = '=';
  234. }
  235. if ($_GET['emails_opt'] === 'above') {
  236. $operator = '>';
  237. }
  238. if ($_GET['emails_opt'] === 'below') {
  239. $operator = '<';
  240. }
  241. $Query .= $operator.' '.$_GET['email_cnt'];
  242. $DB->query($Query);
  243. $Users = implode(',', $DB->collect('UserID'));
  244. if (!empty($Users)) {
  245. $Where[] = "um1.ID IN ($Users)";
  246. }
  247. }
  248. if (!empty($_GET['ip'])) {
  249. if (isset($_GET['ip_history'])) {
  250. $Distinct = 'DISTINCT ';
  251. $Join['hi'] = ' JOIN users_history_ips AS hi ON hi.UserID = um1.ID ';
  252. $Where[] = ' hi.IP '.$Match.wrap($_GET['ip'], '', true);
  253. } else {
  254. $Where[] = 'um1.IP'.$Match.wrap($_GET['ip'], '', true);
  255. }
  256. }
  257. if ($_GET['lockedaccount'] != '' && $_GET['lockedaccount'] != 'any') {
  258. $Join['la'] = '';
  259. if ($_GET['lockedaccount'] == 'unlocked') {
  260. $Join['la'] .= ' LEFT';
  261. $Where[] = ' la.UserID IS NULL';
  262. }
  263. $Join['la'] .= ' JOIN locked_accounts AS la ON la.UserID = um1.ID ';
  264. }
  265. if (!empty($_GET['cc'])) {
  266. if ($_GET['cc_op'] == 'equal') {
  267. $Where[] = "um1.ipcc = '".db_string($_GET['cc'])."'";
  268. } else {
  269. $Where[] = "um1.ipcc != '".db_string($_GET['cc'])."'";
  270. }
  271. }
  272. if (!empty($_GET['tracker_ip'])) {
  273. $Distinct = 'DISTINCT ';
  274. $Join['xfu'] = ' JOIN xbt_files_users AS xfu ON um1.ID = xfu.uid ';
  275. $Where[] = ' xfu.ip '.$Match.wrap($_GET['tracker_ip'], '', true);
  276. }
  277. // if (!empty($_GET['tracker_ip'])) {
  278. // $Distinct = 'DISTINCT ';
  279. // $Join['xs'] = ' JOIN xbt_snatched AS xs ON um1.ID = xs.uid ';
  280. // $Where[] = ' xs.IP '.$Match.wrap($_GET['ip']);
  281. // }
  282. if (!empty($_GET['comment'])) {
  283. $Where[] = 'ui1.AdminComment'.$Match.wrap($_GET['comment']);
  284. }
  285. if (strlen($_GET['invites1'])) {
  286. $Invites1 = round($_GET['invites1']);
  287. $Invites2 = round($_GET['invites2']);
  288. $Where[] = implode(' AND ', num_compare('Invites', $_GET['invites'], $Invites1, $Invites2));
  289. }
  290. if (strlen($_GET['invitees1']) && $_GET['invitees'] != 'off') {
  291. $Invitees1 = round($_GET['invitees1']);
  292. $Invitees2 = round($_GET['invitees2']);
  293. $Having[] = implode(' AND ', num_compare('Invitees', $_GET['invitees'], $Invitees1, $Invitees2));
  294. }
  295. if ($_GET['disabled_invites'] == 'yes') {
  296. $Where[] = 'ui1.DisableInvites = \'1\'';
  297. } elseif ($_GET['disabled_invites'] == 'no') {
  298. $Where[] = 'ui1.DisableInvites = \'0\'';
  299. }
  300. if ($_GET['disabled_uploads'] == 'yes') {
  301. $Where[] = 'ui1.DisableUpload = \'1\'';
  302. } elseif ($_GET['disabled_uploads'] == 'no') {
  303. $Where[] = 'ui1.DisableUpload = \'0\'';
  304. }
  305. if ($_GET['join1']) {
  306. $Where[] = implode(' AND ', date_compare('ui1.JoinDate', $_GET['joined'], $_GET['join1'], $_GET['join2']));
  307. }
  308. if ($_GET['lastactive1']) {
  309. $Where[] = implode(' AND ', date_compare('um1.LastAccess', $_GET['lastactive'], $_GET['lastactive1'], $_GET['lastactive2']));
  310. }
  311. if ($_GET['ratio1']) {
  312. $Decimals = strlen(array_pop(explode('.', $_GET['ratio1'])));
  313. if (!$Decimals) {
  314. $Decimals = 0;
  315. }
  316. $Where[] = implode(' AND ', num_compare("ROUND(Uploaded/Downloaded,$Decimals)", $_GET['ratio'], $_GET['ratio1'], $_GET['ratio2']));
  317. }
  318. if (strlen($_GET['uploaded1'])) {
  319. $Upload1 = round($_GET['uploaded1']);
  320. $Upload2 = round($_GET['uploaded2']);
  321. if ($_GET['uploaded'] != 'buffer') {
  322. $Where[] = implode(' AND ', num_compare('ROUND(Uploaded / 1024 / 1024 / 1024)', $_GET['uploaded'], $Upload1, $Upload2));
  323. } else {
  324. $Where[] = implode(' AND ', num_compare('ROUND((Uploaded / 1024 / 1024 / 1024) - (Downloaded / 1024 / 1024 / 1023))', 'between', $Upload1 * 0.9, $Upload1 * 1.1));
  325. }
  326. }
  327. if (strlen($_GET['downloaded1'])) {
  328. $Download1 = round($_GET['downloaded1']);
  329. $Download2 = round($_GET['downloaded2']);
  330. $Where[] = implode(' AND ', num_compare('ROUND(Downloaded / 1024 / 1024 / 1024)', $_GET['downloaded'], $Download1, $Download2));
  331. }
  332. if (strlen($_GET['snatched1'])) {
  333. $Snatched1 = round($_GET['snatched1']);
  334. $Snatched2 = round($_GET['snatched2']);
  335. $Having[] = implode(' AND ', num_compare('Snatches', $_GET['snatched'], $Snatched1, $Snatched2));
  336. }
  337. if ($_GET['enabled'] != '') {
  338. $Where[] = 'um1.Enabled = '.wrap($_GET['enabled'], '=');
  339. }
  340. if ($_GET['class'] != '') {
  341. $Where[] = 'um1.PermissionID = '.wrap($_GET['class'], '=');
  342. }
  343. if ($_GET['secclass'] != '') {
  344. $Join['ul'] = ' JOIN users_levels AS ul ON um1.ID = ul.UserID ';
  345. $Where[] = 'ul.PermissionID = '.wrap($_GET['secclass'], '=');
  346. }
  347. if ($_GET['donor'] == 'yes') {
  348. $Where[] = 'ui1.Donor = \'1\'';
  349. } elseif ($_GET['donor'] == 'no') {
  350. $Where[] = 'ui1.Donor = \'0\'';
  351. }
  352. if ($_GET['warned'] == 'yes') {
  353. $Where[] = 'ui1.Warned != \'0000-00-00 00:00:00\'';
  354. } elseif ($_GET['warned'] == 'no') {
  355. $Where[] = 'ui1.Warned = \'0000-00-00 00:00:00\'';
  356. }
  357. if ($_GET['disabled_ip']) {
  358. $Distinct = 'DISTINCT ';
  359. if ($_GET['ip_history']) {
  360. if (!isset($Join['hi'])) {
  361. $Join['hi'] = ' JOIN users_history_ips AS hi ON hi.UserID = um1.ID ';
  362. }
  363. $Join['hi2'] = ' JOIN users_history_ips AS hi2 ON hi2.IP = hi.IP ';
  364. $Join['um2'] = ' JOIN users_main AS um2 ON um2.ID = hi2.UserID AND um2.Enabled = \'2\' ';
  365. } else {
  366. $Join['um2'] = ' JOIN users_main AS um2 ON um2.IP = um1.IP AND um2.Enabled = \'2\' ';
  367. }
  368. }
  369. if (!empty($_GET['passkey'])) {
  370. $Where[] = 'um1.torrent_pass'.$Match.wrap($_GET['passkey']);
  371. }
  372. if (!empty($_GET['avatar'])) {
  373. $Where[] = 'ui1.Avatar'.$Match.wrap($_GET['avatar']);
  374. }
  375. if ($_GET['stylesheet'] != '') {
  376. $Where[] = 'ui1.StyleID = '.wrap($_GET['stylesheet'], '=');
  377. }
  378. if ($OrderTable[$_GET['order']] && $WayTable[$_GET['way']]) {
  379. $Order = ' ORDER BY '.$OrderTable[$_GET['order']].' '.$WayTable[$_GET['way']].' ';
  380. }
  381. //---------- Finish generating the search string
  382. $SQL = 'SELECT '.$Distinct.$SQL;
  383. $SQL .= implode(' ', $Join);
  384. if (count($Where)) {
  385. $SQL .= ' WHERE '.implode(' AND ', $Where);
  386. }
  387. if (count($Group)) {
  388. $SQL .= " GROUP BY " . implode(' ,', $Group);
  389. }
  390. if (count($Having)) {
  391. $SQL .= ' HAVING '.implode(' AND ', $Having);
  392. }
  393. $SQL .= $Order;
  394. if (count($Where) > 0 || count($Join) > 0 || count($Having) > 0) {
  395. $RunQuery = true;
  396. }
  397. list($Page, $Limit) = Format::page_limit(USERS_PER_PAGE);
  398. $SQL .= " LIMIT $Limit";
  399. } else {
  400. error($Err);
  401. }
  402. }
  403. View::show_header('User search');
  404. ?>
  405. <div class="thin">
  406. <form class="search_form" name="users" action="user.php" method="get">
  407. <input type="hidden" name="action" value="search" />
  408. <table class="layout">
  409. <tr>
  410. <td class="label nobr">Username:</td>
  411. <td width="24%">
  412. <input type="text" name="username" size="20" value="<?=display_str($_GET['username'])?>" />
  413. </td>
  414. <td class="label nobr">Joined:</td>
  415. <td width="24%">
  416. <select name="joined">
  417. <option value="on"<? if ($_GET['joined'] === 'on') { echo ' selected="selected"'; } ?>>On</option>
  418. <option value="before"<? if ($_GET['joined'] === 'before') { echo ' selected="selected"'; } ?>>Before</option>
  419. <option value="after"<? if ($_GET['joined'] === 'after') { echo ' selected="selected"'; } ?>>After</option>
  420. <option value="between"<? if ($_GET['joined'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  421. </select>
  422. <input type="text" name="join1" size="10" value="<?=display_str($_GET['join1'])?>" placeholder="YYYY-MM-DD" />
  423. <input type="text" name="join2" size="10" value="<?=display_str($_GET['join2'])?>" placeholder="YYYY-MM-DD" />
  424. </td>
  425. <td class="label nobr">Enabled:</td>
  426. <td>
  427. <select name="enabled">
  428. <option value=""<? if ($_GET['enabled'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  429. <option value="0"<? if ($_GET['enabled'] === '0') { echo ' selected="selected"'; } ?>>Unconfirmed</option>
  430. <option value="1"<? if ($_GET['enabled'] === '1') { echo ' selected="selected"'; } ?>>Enabled</option>
  431. <option value="2"<? if ($_GET['enabled'] === '2') { echo ' selected="selected"'; } ?>>Disabled</option>
  432. </select>
  433. </td>
  434. </tr>
  435. <tr>
  436. <td class="label nobr">Email address:</td>
  437. <td>
  438. <input type="text" name="email" size="20" value="<?=display_str($_GET['email'])?>" />
  439. </td>
  440. <td class="label nobr">Last active:</td>
  441. <td width="30%">
  442. <select name="lastactive">
  443. <option value="on"<? if ($_GET['lastactive'] === 'on') { echo ' selected="selected"'; } ?>>On</option>
  444. <option value="before"<? if ($_GET['lastactive'] === 'before') { echo ' selected="selected"'; } ?>>Before</option>
  445. <option value="after"<? if ($_GET['lastactive'] === 'after') { echo ' selected="selected"'; } ?>>After</option>
  446. <option value="between"<? if ($_GET['lastactive'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  447. </select>
  448. <input type="text" name="lastactive1" size="10" value="<?=display_str($_GET['lastactive1'])?>" placeholder="YYYY-MM-DD" />
  449. <input type="text" name="lastactive2" size="10" value="<?=display_str($_GET['lastactive2'])?>" placeholder="YYYY-MM-DD" />
  450. </td>
  451. <td class="label nobr">Primary class:</td>
  452. <td>
  453. <select name="class">
  454. <option value=""<? if ($_GET['class'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  455. <? foreach ($ClassLevels as $Class) {
  456. if ($Class['Secondary']) {
  457. continue;
  458. }
  459. ?>
  460. <option value="<?=$Class['ID'] ?>"<? if ($_GET['class'] === $Class['ID']) { echo ' selected="selected"'; } ?>><?=Format::cut_string($Class['Name'], 10, 1, 1).' ('.$Class['Level'].')'?></option>
  461. <? } ?>
  462. </select>
  463. </td>
  464. </tr>
  465. <tr>
  466. <td class="label tooltip nobr" title="To fuzzy search (default) for a block of addresses (e.g. 55.66.77.*), enter &quot;55.66.77.&quot; without the quotes">IP address:</td>
  467. <td>
  468. <input type="text" name="ip" size="20" value="<?=display_str($_GET['ip'])?>" />
  469. </td>
  470. <td class="label nobr">Locked Account:</td>
  471. <td>
  472. <select name="lockedaccount">
  473. <option value="any"<? if ($_GET['lockedaccount'] == 'any') { echo ' selected="selected"'; } ?>>Any</option>
  474. <option value="locked"<? if ($_GET['lockedaccount'] == 'locked') { echo ' selected="selected"'; } ?>>Locked</option>
  475. <option value="unlocked"<? if ($_GET['lockedaccount'] == 'unlocked') { echo ' selected="selected"'; } ?>>Unlocked</option>
  476. </select>
  477. </td>
  478. <td class="label nobr">Secondary class:</td>
  479. <td>
  480. <select name="secclass">
  481. <option value=""<? if ($_GET['secclass'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  482. <? $Secondaries = array();
  483. // Neither level nor ID is particularly useful when searching secondary classes, so let's do some
  484. // kung-fu to sort them alphabetically.
  485. $fnc = function($Class1, $Class2) { return strcmp($Class1['Name'], $Class2['Name']); };
  486. foreach ($ClassLevels as $Class) {
  487. if (!$Class['Secondary']) {
  488. continue;
  489. }
  490. $Secondaries[] = $Class;
  491. }
  492. usort($Secondaries, $fnc);
  493. foreach ($Secondaries as $Class) {
  494. ?>
  495. <option value="<?=$Class['ID'] ?>"<? if ($_GET['secclass'] === $Class['ID']) { echo ' selected="selected"'; } ?>><?=Format::cut_string($Class['Name'], 20, 1, 1)?></option>
  496. <? } ?>
  497. </select>
  498. </td>
  499. </tr>
  500. <tr>
  501. <td class="label nobr">Extra:</td>
  502. <td>
  503. <ul class="options_list nobullet">
  504. <li>
  505. <input type="checkbox" name="ip_history" id="ip_history"<? if ($_GET['ip_history']) { echo ' checked="checked"'; } ?> />
  506. <label for="ip_history">IP history</label>
  507. </li>
  508. <li>
  509. <input type="checkbox" name="email_history" id="email_history"<? if ($_GET['email_history']) { echo ' checked="checked"'; } ?> />
  510. <label for="email_history">Email history</label>
  511. </li>
  512. </ul>
  513. </td>
  514. <td class="label nobr">Ratio:</td>
  515. <td width="30%">
  516. <select name="ratio">
  517. <option value="equal"<? if ($_GET['ratio'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  518. <option value="above"<? if ($_GET['ratio'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  519. <option value="below"<? if ($_GET['ratio'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  520. <option value="between"<? if ($_GET['ratio'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  521. </select>
  522. <input type="text" name="ratio1" size="6" value="<?=display_str($_GET['ratio1'])?>" />
  523. <input type="text" name="ratio2" size="6" value="<?=display_str($_GET['ratio2'])?>" />
  524. </td>
  525. <td class="label nobr">Donor:</td>
  526. <td>
  527. <select name="donor">
  528. <option value=""<? if ($_GET['donor'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  529. <option value="yes"<? if ($_GET['donor'] === 'yes') { echo ' selected="selected"'; } ?>>Yes</option>
  530. <option value="no"<? if ($_GET['donor'] === 'no') { echo ' selected="selected"'; } ?>>No</option>
  531. </select>
  532. </td>
  533. </tr>
  534. <tr>
  535. <? if (check_perms('users_mod')) { ?>
  536. <td class="label nobr">Staff notes:</td>
  537. <td>
  538. <input type="text" name="comment" size="20" value="<?=display_str($_GET['comment'])?>" />
  539. </td>
  540. <? } else { ?>
  541. <td class="label nobr"></td>
  542. <td>
  543. </td>
  544. <? } ?>
  545. <td class="label tooltip nobr" title="Units are in gibibytes (the base 2 sibling of gigabytes)">Uploaded:</td>
  546. <td width="30%">
  547. <select name="uploaded">
  548. <option value="equal"<? if ($_GET['uploaded'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  549. <option value="above"<? if ($_GET['uploaded'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  550. <option value="below"<? if ($_GET['uploaded'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  551. <option value="between"<? if ($_GET['uploaded'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  552. <option value="buffer"<? if ($_GET['uploaded'] === 'buffer') { echo ' selected="selected"'; } ?>>Buffer</option>
  553. </select>
  554. <input type="text" name="uploaded1" size="6" value="<?=display_str($_GET['uploaded1'])?>" />
  555. <input type="text" name="uploaded2" size="6" value="<?=display_str($_GET['uploaded2'])?>" />
  556. </td>
  557. <td class="label nobr">Warned:</td>
  558. <td>
  559. <select name="warned">
  560. <option value=""<? if ($_GET['warned'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  561. <option value="yes"<? if ($_GET['warned'] === 'yes') { echo ' selected="selected"'; } ?>>Yes</option>
  562. <option value="no"<? if ($_GET['warned'] === 'no') { echo ' selected="selected"'; } ?>>No</option>
  563. </select>
  564. </td>
  565. </tr>
  566. <tr>
  567. <td class="label nobr"># of invites:</td>
  568. <td>
  569. <select name="invites">
  570. <option value="equal"<? if ($_GET['invites'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  571. <option value="above"<? if ($_GET['invites'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  572. <option value="below"<? if ($_GET['invites'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  573. <option value="between"<? if ($_GET['invites'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  574. </select>
  575. <input type="text" name="invites1" size="6" value="<?=display_str($_GET['invites1'])?>" />
  576. <input type="text" name="invites2" size="6" value="<?=display_str($_GET['invites2'])?>" />
  577. </td>
  578. <td class="label tooltip nobr" title="Units are in gibibytes (the base 2 sibling of gigabytes)">Downloaded:</td>
  579. <td width="30%">
  580. <select name="downloaded">
  581. <option value="equal"<? if ($_GET['downloaded'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  582. <option value="above"<? if ($_GET['downloaded'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  583. <option value="below"<? if ($_GET['downloaded'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  584. <option value="between"<? if ($_GET['downloaded'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  585. </select>
  586. <input type="text" name="downloaded1" size="6" value="<?=display_str($_GET['downloaded1'])?>" />
  587. <input type="text" name="downloaded2" size="6" value="<?=display_str($_GET['downloaded2'])?>" />
  588. </td>
  589. <td class="label tooltip nobr" title="Only display users that have a disabled account linked by IP address">
  590. <label for="disabled_ip">Disabled accounts<br />linked by IP:</label>
  591. </td>
  592. <td>
  593. <input type="checkbox" name="disabled_ip" id="disabled_ip"<? if ($_GET['disabled_ip']) { echo ' checked="checked"'; } ?> />
  594. </td>
  595. </tr>
  596. <tr>
  597. <td class="label nobr">Disabled invites:</td>
  598. <td>
  599. <select name="disabled_invites">
  600. <option value=""<? if ($_GET['disabled_invites'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  601. <option value="yes"<? if ($_GET['disabled_invites'] === 'yes') { echo ' selected="selected"'; } ?>>Yes</option>
  602. <option value="no"<? if ($_GET['disabled_invites'] === 'no') { echo ' selected="selected"'; } ?>>No</option>
  603. </select>
  604. </td>
  605. <td class="label nobr">Snatched:</td>
  606. <td width="30%">
  607. <select name="snatched">
  608. <option value="equal"<? if (isset($_GET['snatched']) && $_GET['snatched'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  609. <option value="above"<? if (isset($_GET['snatched']) && $_GET['snatched'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  610. <option value="below"<? if (isset($_GET['snatched']) && $_GET['snatched'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  611. <option value="between"<? if (isset($_GET['snatched']) && $_GET['snatched'] === 'between') { echo ' selected="selected"'; } ?>>Between</option>
  612. <option value="off"<? if (!isset($_GET['snatched']) || $_GET['snatched'] === 'off') { echo ' selected="selected"'; } ?>>Off</option>
  613. </select>
  614. <input type="text" name="snatched1" size="6" value="<?=display_str($_GET['snatched1'])?>" />
  615. <input type="text" name="snatched2" size="6" value="<?=display_str($_GET['snatched2'])?>" />
  616. </td>
  617. <td class="label nobr">Disabled uploads:</td>
  618. <td>
  619. <select name="disabled_uploads">
  620. <option value=""<? if (isset($_GET['disabled_uploads']) && $_GET['disabled_uploads'] === '') { echo ' selected="selected"'; } ?>>Any</option>
  621. <option value="yes"<? if (isset($_GET['disabled_uploads']) && $_GET['disabled_uploads'] === 'yes') { echo ' selected="selected"'; } ?>>Yes</option>
  622. <option value="no"<? if (isset($_GET['disabled_uploads']) && $_GET['disabled_uploads'] === 'no') { echo ' selected="selected"'; } ?>>No</option>
  623. </select>
  624. </td>
  625. </tr>
  626. <tr>
  627. <td width="30%" class="label nobr"># of invitees:</td>
  628. <td>
  629. <select name="invitees">
  630. <option value="equal" <?=isset($_GET['invitees']) && $_GET['invitees'] == 'equal' ? 'selected' : ''?>>Equal</option>
  631. <option value="above" <?=isset($_GET['invitees']) && $_GET['invitees'] == 'above' ? 'selected' : ''?>>Above</option>
  632. <option value="below" <?=isset($_GET['invitees']) && $_GET['invitees'] == 'below' ? 'selected' : ''?>>Below</option>
  633. <option value="between" <?=isset($_GET['invitees']) && $_GET['invitees'] == 'between' ? 'selected' : ''?>>Between</option>
  634. <option value="off" <?=!isset($_GET['invitees']) || $_GET['invitees'] == 'off' ? 'selected' : ''?>>Off</option>
  635. </select>
  636. <input type="text" name="invitees1" size="6" value="<?=display_str($_GET['invitees1'])?>" />
  637. <input type="text" name="invitees2" size="6" value="<?=display_str($_GET['invitees2'])?>" />
  638. </td>
  639. <td class="label nobr">Passkey:</td>
  640. <td>
  641. <input type="text" name="passkey" size="20" value="<?=display_str($_GET['passkey'])?>" />
  642. </td>
  643. <td class="label nobr">Tracker IP:</td>
  644. <td>
  645. <input type="text" name="tracker_ip" size="20" value="<?=display_str($_GET['tracker_ip'])?>" />
  646. </td>
  647. </tr>
  648. <tr>
  649. <td class="label tooltip nobr" title="Supports partial URL matching, e.g. entering &quot;&#124;https://whatimg.com&quot; will search for avatars hosted on https://whatimg.com">Avatar URL:</td>
  650. <td>
  651. <input type="text" name="avatar" size="20" value="<?=display_str($_GET['avatar'])?>" />
  652. </td>
  653. <td class="label nobr">Stylesheet:</td>
  654. <td>
  655. <select name="stylesheet" id="stylesheet">
  656. <option value="">Any</option>
  657. <? foreach ($Stylesheets as $Style) { ?>
  658. <option value="<?=$Style['ID']?>"<?Format::selected('stylesheet',$Style['ID'])?>><?=$Style['ProperName']?></option>
  659. <? } ?>
  660. </select>
  661. </td>
  662. <td class="label tooltip nobr" title="Two-letter codes as defined in ISO 3166-1 alpha-2">Country code:</td>
  663. <td width="30%">
  664. <select name="cc_op">
  665. <option value="equal"<? if ($_GET['cc_op'] === 'equal') { echo ' selected="selected"'; } ?>>Equals</option>
  666. <option value="not_equal"<? if ($_GET['cc_op'] === 'not_equal') { echo ' selected="selected"'; } ?>>Not equal</option>
  667. </select>
  668. <input type="text" name="cc" size="2" value="<?=display_str($_GET['cc'])?>" />
  669. </td>
  670. </tr>
  671. <tr>
  672. <td class="label nobr">Search type:</td>
  673. <td>
  674. <ul class="options_list nobullet">
  675. <li>
  676. <input type="radio" name="matchtype" id="strict_match_type" value="strict"<? if ($_GET['matchtype'] == 'strict' || !$_GET['matchtype']) { echo ' checked="checked"'; } ?> />
  677. <label class="tooltip" title="A &quot;strict&quot; search uses no wildcards in search fields, and it is analogous to &#96;grep -E &quot;&circ;SEARCHTERM&#36;&quot;&#96;" for="strict_match_type">Strict</label>
  678. </li>
  679. <li>
  680. <input type="radio" name="matchtype" id="fuzzy_match_type" value="fuzzy"<? if ($_GET['matchtype'] == 'fuzzy' || !$_GET['matchtype']) { echo ' checked="checked"'; } ?> />
  681. <label class="tooltip" title="A &quot;fuzzy&quot; search automatically prepends and appends wildcards to search strings, except for IP address searches, unless the search string begins or ends with a &quot;&#124;&quot; (pipe). It is analogous to a vanilla grep search (except for the pipe stuff)." for="fuzzy_match_type">Fuzzy</label>
  682. </li>
  683. <li>
  684. <input type="radio" name="matchtype" id="regex_match_type" value="regex"<? if ($_GET['matchtype'] == 'regex') { echo ' checked="checked"'; } ?> />
  685. <label class="tooltip" title="A &quot;regex&quot; search uses MySQL's regular expression syntax." for="regex_match_type">Regex</label>
  686. </li>
  687. </ul>
  688. </td>
  689. <td class="label nobr">Order:</td>
  690. <td class="nobr">
  691. <select name="order">
  692. <?
  693. foreach (array_shift($OrderVals) as $Cur) { ?>
  694. <option value="<?=$Cur?>"<? if (isset($_GET['order']) && $_GET['order'] == $Cur || (!isset($_GET['order']) && $Cur == 'Joined')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
  695. <? } ?>
  696. </select>
  697. <select name="way">
  698. <? foreach (array_shift($WayVals) as $Cur) { ?>
  699. <option value="<?=$Cur?>"<? if (isset($_GET['way']) && $_GET['way'] == $Cur || (!isset($_GET['way']) && $Cur == 'Descending')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
  700. <? } ?>
  701. </select>
  702. </td>
  703. <td class="label nobr"># of emails:</td>
  704. <td>
  705. <select name="emails_opt">
  706. <option value="equal"<? if ($_GET['emails_opt'] === 'equal') { echo ' selected="selected"'; } ?>>Equal</option>
  707. <option value="above"<? if ($_GET['emails_opt'] === 'above') { echo ' selected="selected"'; } ?>>Above</option>
  708. <option value="below"<? if ($_GET['emails_opt'] === 'below') { echo ' selected="selected"'; } ?>>Below</option>
  709. </select>
  710. <input type="text" name="email_cnt" size="6" value="<?=display_str($_GET['email_cnt'])?>" />
  711. </td>
  712. </tr>
  713. <tr>
  714. <td colspan="6" class="center">
  715. <input type="submit" value="Search users" />
  716. </td>
  717. </tr>
  718. </table>
  719. </form>
  720. </div>
  721. <?
  722. if ($RunQuery) {
  723. $Results = $DB->query($SQL);
  724. $DB->query('SELECT FOUND_ROWS()');
  725. list($NumResults) = $DB->next_record();
  726. $DB->set_query_id($Results);
  727. } else {
  728. $DB->query('SET @nothing = 0');
  729. $NumResults = 0;
  730. }
  731. ?>
  732. <div class="linkbox">
  733. <?
  734. $Pages = Format::get_pages($Page, $NumResults, USERS_PER_PAGE, 11);
  735. echo $Pages;
  736. ?>
  737. </div>
  738. <div class="box pad center">
  739. <h2><?=number_format($NumResults)?> results</h2>
  740. <table width="100%">
  741. <tr class="colhead">
  742. <td>Username</td>
  743. <td>Ratio</td>
  744. <td>IP address</td>
  745. <td>Email</td>
  746. <td>Joined</td>
  747. <td>Last seen</td>
  748. <td>Upload</td>
  749. <td>Download</td>
  750. <td>Downloads</td>
  751. <td>Snatched</td>
  752. <td>Invites</td>
  753. <? if (isset($_GET['invitees']) && $_GET['invitees'] != 'off') { ?>
  754. <td>Invitees</td>
  755. <? } ?>
  756. </tr>
  757. <?
  758. while (list($UserID, $Username, $Uploaded, $Downloaded, $Snatched, $Invitees, $Class, $Email, $Enabled, $IP, $Invites, $DisableInvites, $Warned, $Donor, $JoinDate, $LastAccess) = $DB->next_record()) {
  759. $IP = apc_exists('DBKEY') ? DBCrypt::decrypt($IP) : '[Encrypted]';
  760. $Email = apc_exists('DBKEY') ? DBCrypt::decrypt($Email) : '[Encrypted]';
  761. ?>
  762. <tr>
  763. <td><?=Users::format_username($UserID, true, true, true, true)?></td>
  764. <td><?=Format::get_ratio_html($Uploaded, $Downloaded)?></td>
  765. <td style="word-break: break-all;"><?=display_str($IP)?> (<?=Tools::get_country_code_by_ajax($IP)?>)</td>
  766. <td><?=display_str($Email)?></td>
  767. <td><?=time_diff($JoinDate)?></td>
  768. <td><?=time_diff($LastAccess)?></td>
  769. <td><?=Format::get_size($Uploaded)?></td>
  770. <td><?=Format::get_size($Downloaded)?></td>
  771. <? $DB->query("
  772. SELECT COUNT(ud.UserID)
  773. FROM users_downloads AS ud
  774. JOIN torrents AS t ON t.ID = ud.TorrentID
  775. WHERE ud.UserID = $UserID");
  776. list($Downloads) = $DB->next_record();
  777. $DB->set_query_id($Results);
  778. ?>
  779. <td><?=number_format((int)$Downloads)?></td>
  780. <td><?=(is_numeric($Snatched) ? number_format($Snatched) : display_str($Snatched))?></td>
  781. <td><? if ($DisableInvites) { echo 'X'; } else { echo number_format($Invites); } ?></td>
  782. <? if (isset($_GET['invitees']) && $_GET['invitees'] != 'off') { ?>
  783. <td><?=number_format($Invitees)?></td>
  784. <? } ?>
  785. </tr>
  786. <?
  787. }
  788. ?>
  789. </table>
  790. </div>
  791. <div class="linkbox">
  792. <?=$Pages?>
  793. </div>
  794. <?
  795. View::show_footer();
  796. ?>