PageRenderTime 39ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/admin/admin_user_search.php

http://torrentpier2.googlecode.com/
PHP | 1296 lines | 1116 code | 138 blank | 42 comment | 101 complexity | 743e2a588daffa0a590d7db6825ad4eb MD5 | raw file
  1. <?php
  2. // ACP Header - START
  3. if (!empty($setmodules))
  4. {
  5. $module['Users']['Search'] = basename(__FILE__);
  6. return;
  7. }
  8. require('./pagestart.php');
  9. // ACP Header - END
  10. require(INC_DIR .'functions_selects.php');
  11. $total_sql = '';
  12. if(!isset($_POST['dosearch'])&&!isset($_GET['dosearch']))
  13. {
  14. $sql = "SELECT group_id, group_name
  15. FROM ".BB_GROUPS."
  16. WHERE group_single_user = 0
  17. ORDER BY group_name ASC";
  18. if(!$result = DB()->sql_query($sql))
  19. {
  20. message_die(GENERAL_ERROR, 'Could not select group data', '', __LINE__, __FILE__, $sql);
  21. }
  22. $group_list = '';
  23. if(DB()->num_rows($result) != 0)
  24. {
  25. $template->assign_block_vars('groups_exist', array());
  26. while($row = DB()->sql_fetchrow($result))
  27. {
  28. $group_list .= '<option value="'.$row['group_id'].'">'.strip_tags(htmlspecialchars($row['group_name'])).'</option>';
  29. }
  30. }
  31. $sql = "SELECT * FROM " . BB_RANKS . "
  32. WHERE rank_special = 1
  33. ORDER BY rank_title";
  34. if ( !($result = DB()->sql_query($sql)) )
  35. {
  36. message_die(GENERAL_ERROR, 'Could not obtain ranks data', '', __LINE__, __FILE__, $sql);
  37. }
  38. $rank_select_box = '';
  39. if(DB()->num_rows($result) != 0)
  40. {
  41. $template->assign_block_vars('ranks_exist', array());
  42. while( $row = DB()->sql_fetchrow($result) )
  43. {
  44. $rank = $row['rank_title'];
  45. $rank_id = $row['rank_id'];
  46. $rank_select_box .= '<option value="' . $rank_id . '">' . $rank . '</option>';
  47. }
  48. }
  49. $language_list = language_select('', 'language_type');
  50. $timezone_list = tz_select('', 'timezone_type');
  51. $sql = "SELECT f.forum_id, f.forum_name, f.forum_parent, c.cat_id, c.cat_title
  52. FROM ( ". BB_FORUMS ." AS f INNER JOIN ". BB_CATEGORIES ." AS c ON c.cat_id = f.cat_id )
  53. ORDER BY c.cat_order, f.forum_order ASC";
  54. if(!$result = DB()->sql_query($sql))
  55. {
  56. message_die(GENERAL_ERROR, 'Could not select forum data', '', __LINE__, __FILE__, $sql);
  57. }
  58. $forums = array();
  59. if(DB()->num_rows($result) != 0)
  60. {
  61. $template->assign_block_vars('forums_exist', array());
  62. $last_cat_id = -1;
  63. $forums_list = '';
  64. while($row = DB()->sql_fetchrow($result))
  65. {
  66. if($row['cat_id'] != $last_cat_id)
  67. {
  68. $forums_list .= '<optgroup label="'.htmlCHR($row['cat_title']).'">';
  69. $last_cat_id = $row['cat_id'];
  70. }
  71. $forums_list .= '<option value="'.$row['forum_id'].'">'.(($row['forum_parent']) ? HTML_SF_SPACER : '').htmlCHR($row['forum_name']).'</option>';
  72. }
  73. }
  74. $styles_list = $bb_cfg['tpl_name'];
  75. $lastvisited = array(1, 7, 14, 30, 60, 120, 365, 500, 730, 1000);
  76. $lastvisited_list = '';
  77. foreach($lastvisited as $days)
  78. {
  79. $lastvisited_list .= '<option value="'.$days.'">'.$days.' '. ( ( $days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) .'</option>';
  80. }
  81. $template->assign_vars(array(
  82. 'TPL_ADMIN_USER_SEARCH_MAIN' => true,
  83. 'YEAR' => date("Y"),
  84. 'MONTH' => date("m"),
  85. 'DAY' => date("d"),
  86. 'GROUP_LIST' => $group_list,
  87. 'RANK_SELECT_BOX' => $rank_select_box,
  88. 'LANGUAGE_LIST' => $language_list,
  89. 'TIMEZONE_LIST' => $timezone_list,
  90. 'FORUMS_LIST' => $forums_list,
  91. 'STYLE_LIST' => $styles_list,
  92. 'LASTVISITED_LIST' => $lastvisited_list,
  93. 'S_SEARCH_ACTION' => 'admin_user_search.php',
  94. ));
  95. }
  96. else
  97. {
  98. $mode = '';
  99. // validate mode
  100. if(isset($_POST['search_username'])||isset($_GET['search_username']))
  101. {
  102. $mode = 'search_username';
  103. }
  104. elseif(isset($_POST['search_email'])||isset($_GET['search_email']))
  105. {
  106. $mode = 'search_email';
  107. }
  108. elseif(isset($_POST['search_ip'])||isset($_GET['search_ip']))
  109. {
  110. $mode = 'search_ip';
  111. }
  112. elseif(isset($_POST['search_joindate'])||isset($_GET['search_joindate']))
  113. {
  114. $mode = 'search_joindate';
  115. }
  116. elseif(isset($_POST['search_group'])||isset($_GET['search_group']))
  117. {
  118. $mode = 'search_group';
  119. }
  120. elseif(isset($_POST['search_rank'])||isset($_GET['search_rank']))
  121. {
  122. $mode = 'search_rank';
  123. }
  124. elseif(isset($_POST['search_postcount'])||isset($_GET['search_postcount']))
  125. {
  126. $mode = 'search_postcount';
  127. }
  128. elseif(isset($_POST['search_userfield'])||isset($_GET['search_userfield']))
  129. {
  130. $mode = 'search_userfield';
  131. }
  132. elseif(isset($_POST['search_lastvisited'])||isset($_GET['search_lastvisited']))
  133. {
  134. $mode = 'search_lastvisited';
  135. }
  136. elseif(isset($_POST['search_language'])||isset($_GET['search_language']))
  137. {
  138. $mode = 'search_language';
  139. }
  140. elseif(isset($_POST['search_timezone'])||isset($_GET['search_timezone']))
  141. {
  142. $mode = 'search_timezone';
  143. }
  144. elseif(isset($_POST['search_style'])||isset($_GET['search_style']))
  145. {
  146. $mode = 'search_style';
  147. }
  148. elseif(isset($_POST['search_moderators'])||isset($_GET['search_moderators']))
  149. {
  150. $mode = 'search_moderators';
  151. }
  152. elseif(isset($_POST['search_misc'])||isset($_GET['search_misc']))
  153. {
  154. $mode = 'search_misc';
  155. }
  156. // validate fields (that they exist)
  157. switch($mode)
  158. {
  159. case 'search_username':
  160. $username = ( isset($_GET['username']) ) ? $_GET['username'] : $_POST['username'];
  161. $regex = ( @$_POST['search_username_regex'] ) ? true : ( @$_GET['regex'] ) ? true : false;
  162. if(!$username)
  163. {
  164. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_USERNAME']);
  165. }
  166. break;
  167. case 'search_email':
  168. $email = ( isset($_GET['email']) ) ? $_GET['email'] : $_POST['email'];
  169. $regex = ( @$_POST['search_email_regex'] ) ? true : ( @$_GET['regex'] ) ? true : false;
  170. if(!$email)
  171. {
  172. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_EMAIL']);
  173. }
  174. break;
  175. case 'search_ip':
  176. $ip_address = ( isset($_POST['ip_address'] ) ) ? $_POST['ip_address'] : $_GET['ip_address'];
  177. if(!$ip_address)
  178. {
  179. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_IP']);
  180. }
  181. break;
  182. case 'search_joindate':
  183. $date_type = ( isset($_POST['date_type'] ) ) ? $_POST['date_type'] : $_GET['date_type'];
  184. $date_day = ( isset($_POST['date_day'] ) ) ? $_POST['date_day'] : $_GET['date_day'];
  185. $date_month = ( isset($_POST['date_month'] ) ) ? $_POST['date_month'] : $_GET['date_month'];
  186. $date_year = ( isset($_POST['date_year'] ) ) ? $_POST['date_year'] : $_GET['date_year'];
  187. if(!$date_type || !$date_day || !$date_month || !$date_year)
  188. {
  189. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_DATE']);
  190. }
  191. break;
  192. case 'search_group':
  193. $group_id = ( isset($_POST['group_id'] ) ) ? $_POST['group_id'] : $_GET['group_id'];
  194. if(!$group_id)
  195. {
  196. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_GROUP']);
  197. }
  198. break;
  199. case 'search_rank':
  200. $rank_id = ( isset($_POST['rank_id'] ) ) ? $_POST['rank_id'] : $_GET['rank_id'];
  201. if(!$rank_id)
  202. {
  203. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_RANK']);
  204. }
  205. break;
  206. case 'search_postcount':
  207. $postcount_type = ( isset($_POST['postcount_type'] ) ) ? $_POST['postcount_type'] : $_GET['postcount_type'];
  208. $postcount_value = ( isset($_POST['postcount_value'] ) ) ? $_POST['postcount_value'] : $_GET['postcount_value'];
  209. if(!$postcount_type || ( !$postcount_value && $postcount_value != 0))
  210. {
  211. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_POSTCOUNT']);
  212. }
  213. break;
  214. case 'search_userfield':
  215. $userfield_type = ( isset($_POST['userfield_type'] ) ) ? $_POST['userfield_type'] : $_GET['userfield_type'];
  216. $userfield_value = ( isset($_POST['userfield_value'] ) ) ? $_POST['userfield_value'] : $_GET['userfield_value'];
  217. $regex = ( @$_POST['search_userfield_regex'] ) ? true : ( @$_GET['regex'] ) ? true : false;
  218. if(!$userfield_type || !$userfield_value)
  219. {
  220. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_USERFIELD']);
  221. }
  222. break;
  223. case 'search_lastvisited':
  224. $lastvisited_days = ( isset($_POST['lastvisited_days'] ) ) ? $_POST['lastvisited_days'] : $_GET['lastvisited_days'];
  225. $lastvisited_type = ( isset($_POST['lastvisited_type'] ) ) ? $_POST['lastvisited_type'] : $_GET['lastvisited_type'];
  226. if(!$lastvisited_days || !$lastvisited_type)
  227. {
  228. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_LASTVISITED']);
  229. }
  230. break;
  231. case 'search_language':
  232. $language_type = ( isset($_POST['language_type'] ) ) ? $_POST['language_type'] : $_GET['language_type'];
  233. if(!$language_type)
  234. {
  235. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_LANGUAGE']);
  236. }
  237. break;
  238. case 'search_timezone':
  239. $timezone_type = ( isset($_POST['timezone_type'] ) ) ? $_POST['timezone_type'] : $_GET['timezone_type'];
  240. if(!$timezone_type && $timezone_type != 0)
  241. {
  242. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_TIMEZONE']);
  243. }
  244. break;
  245. case 'search_style':
  246. $style_type = ( isset($_POST['style_type'] ) ) ? $_POST['style_type'] : $_GET['style_type'];
  247. if(!$style_type)
  248. {
  249. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_STYLE']);
  250. }
  251. break;
  252. case 'search_moderators':
  253. $moderators_forum = ( isset($_POST['moderators_forum'] ) ) ? $_POST['moderators_forum'] : $_GET['moderators_forum'];
  254. if(!$moderators_forum)
  255. {
  256. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_MODERATORS']);
  257. }
  258. break;
  259. case 'search_misc':
  260. default:
  261. $misc = ( isset($_POST['misc'] ) ) ? $_POST['misc'] : $_GET['misc'];
  262. if(!$misc)
  263. {
  264. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID']);
  265. }
  266. }
  267. $base_url = 'admin_user_search.php?dosearch=true';
  268. $select_sql = "SELECT u.user_id, u.username, u.user_rank, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit
  269. FROM ". BB_USERS ." AS u";
  270. $lower_b = 'LOWER(';
  271. $lower_e = ')';
  272. if(@$regex)
  273. {
  274. switch(SQL_LAYER)
  275. {
  276. case 'postgres':
  277. $op = '~';
  278. break;
  279. case 'oracle':
  280. // Oracle uses a different syntax, we'll handle that a little later
  281. break;
  282. case 'mysql':
  283. case 'mysql4':
  284. $op = 'REGEXP';
  285. break;
  286. default:
  287. message_die(GENERAL_MESSAGE, $lang['SEARCH_NO_REGEXP']);
  288. }
  289. $lower_b = '';
  290. $lower_e = '';
  291. }
  292. // validate data & prepare sql
  293. switch($mode)
  294. {
  295. case 'search_username':
  296. $base_url .= '&search_username=true&username='.rawurlencode(stripslashes($username));
  297. $text = sprintf($lang['SEARCH_FOR_USERNAME'], strip_tags(htmlspecialchars(stripslashes($username))));
  298. if(!$regex)
  299. {
  300. $username = preg_replace('/\*/', '%', trim(strip_tags(strtolower($username))));
  301. if(strstr($username, '%'))
  302. {
  303. $op = 'LIKE';
  304. }
  305. else
  306. {
  307. $op = '=';
  308. }
  309. }
  310. else
  311. {
  312. $username = preg_replace('/\\\\\\\(?<!\'|"|NULL)/', '\\', $username);
  313. }
  314. if($username == '')
  315. {
  316. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_USERNAME']);
  317. }
  318. if($regex && SQL_LAYER == 'oracle')
  319. {
  320. $total_sql .= "SELECT COUNT(user_id) AS total
  321. FROM ".BB_USERS."
  322. WHERE REGEXP_LIKE(username, '".DB()->escape($username)."')
  323. AND user_id <> ".GUEST_UID;
  324. $select_sql .= " WHERE REGEXP_LIKE(u.username, '".DB()->escape($username)."')
  325. AND u.user_id <> ".GUEST_UID;
  326. }
  327. else
  328. {
  329. $total_sql .= "SELECT COUNT(user_id) AS total
  330. FROM ".BB_USERS."
  331. WHERE {$lower_b}username{$lower_e} $op '".DB()->escape($username)."'
  332. AND user_id <> ".GUEST_UID;
  333. $select_sql .= " WHERE {$lower_b}u.username{$lower_e} $op '".DB()->escape($username)."'
  334. AND u.user_id <> ".GUEST_UID;
  335. }
  336. break;
  337. case 'search_email':
  338. $base_url .= '&search_email=true&email='.rawurlencode(stripslashes($email));
  339. $text = sprintf($lang['SEARCH_FOR_EMAIL'], strip_tags(htmlspecialchars(stripslashes($email))));
  340. if(!$regex)
  341. {
  342. $email = preg_replace('/\*/', '%', trim(strip_tags(strtolower($email))));
  343. if(strstr($email, '%'))
  344. {
  345. $op = 'LIKE';
  346. }
  347. else
  348. {
  349. $op = '=';
  350. }
  351. }
  352. else
  353. {
  354. $email = preg_replace('/\\\\\\\(?<!\'|"|NULL)/', '\\', $email);
  355. }
  356. if($email == '')
  357. {
  358. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_EMAIL']);
  359. }
  360. if($regex && SQL_LAYER == 'oracle')
  361. {
  362. $total_sql .= "SELECT COUNT(user_id) AS total
  363. FROM ".BB_USERS."
  364. WHERE REGEXP_LIKE(user_email, '".DB()->escape($email)."')
  365. AND user_id <> ".GUEST_UID;
  366. $select_sql .= " WHERE REGEXP_LIKE(u.user_email, '".DB()->escape($email)."')
  367. AND u.user_id <> ".GUEST_UID;
  368. }
  369. else
  370. {
  371. $total_sql .= "SELECT COUNT(user_id) AS total
  372. FROM ".BB_USERS."
  373. WHERE {$lower_b}user_email{$lower_e} $op '".DB()->escape($email)."'
  374. AND user_id <> ".GUEST_UID;
  375. $select_sql .= " WHERE {$lower_b}u.user_email{$lower_e} $op '".DB()->escape($email)."'
  376. AND u.user_id <> ".GUEST_UID;
  377. }
  378. break;
  379. case 'search_ip':
  380. $base_url .= '&search_ip=true&ip_address='.rawurlencode(stripslashes($ip_address));
  381. // Remove any whitespace
  382. $ip_address = trim($ip_address);
  383. $text = sprintf($lang['SEARCH_FOR_IP'], strip_tags(htmlspecialchars(stripslashes($ip_address))));
  384. unset($users);
  385. $users = array();
  386. // Let's see if they entered a full valid IPv4 address
  387. if( preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address) )
  388. {
  389. // Encode the ip into hexademicals
  390. $ip = encode_ip($ip_address);
  391. // Because we will be deleting based on IP's, we will store the encoded IP alone
  392. $users[] = $ip;
  393. }
  394. // We will also support wildcards, is this an xxx.xxx.* address?
  395. elseif( preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){0,2}\.\*/', $ip_address) )
  396. {
  397. // Alright, now we do the ugly part, converting them to encoded ips
  398. // We need to deal with the three ways it can be done
  399. // xxx.*
  400. // xxx.xxx.*
  401. // xxx.xxx.xxx.*
  402. // First we will split the IP into its quads
  403. $ip_split = explode('.', $ip_address);
  404. // Now we'll work with which type of wildcard we have
  405. switch( count($ip_split) )
  406. {
  407. // xxx.xxx.xxx.*
  408. case 4:
  409. // We will encode the ip into hexademical quads
  410. $users[] = encode_ip($ip_split[0].".".$ip_split[1].".".$ip_split[2].".255");
  411. break;
  412. // xxx.xxx.*
  413. case 3:
  414. // We will encode the ip into hexademical quads again..
  415. $users[] = encode_ip($ip_split[0].".".$ip_split[1].".255.255");
  416. break;
  417. // xxx.*
  418. case 2:
  419. // We will encode the ip into hexademical quads again again....
  420. $users[] = encode_ip($ip_split[0].".255.255.255");
  421. break;
  422. }
  423. }
  424. // Lastly, let's see if they have a range in the last quad, like xxx.xxx.xxx.xxx - xxx.xxx.xxx.yyy
  425. elseif( preg_match('/^([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}(\s)*-(\s)*([0-9]{1,2}|[0-2][0-9]{0,2})(\.([0-9]{1,2}|[0-2][0-9]{0,2})){3}$/', $ip_address) )
  426. {
  427. // We will split the two ranges
  428. $range = preg_split('/[-\s]+/', $ip_address);
  429. // This is where break the start and end ips into quads
  430. $start_range = explode('.', $range[0]);
  431. $end_range = explode('.', $range[1]);
  432. // Confirm if we are in the same subnet or the last quad in the beginning range is greater than the last in the ending range
  433. if( ($start_range[0].$start_range[1].$start_range[2] != $end_range[0].$end_range[1].$end_range[2]) || ($start_range[3] > $end_range[3]) )
  434. {
  435. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_IP']);
  436. }
  437. // Ok, we need to store each IP in the range..
  438. for( $i = $start_range[3]; $i <= $end_range[3]; $i++ )
  439. {
  440. // let's put it in the big array..
  441. $users[] = encode_ip($start_range[0].".".$start_range[1 ].".".$start_range[2].".".$i);
  442. }
  443. }
  444. // This is not a valid IP based on what we want..
  445. else
  446. {
  447. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_IP']);
  448. }
  449. $ip_in_sql = $ip_like_sql = $ip_like_sql_flylast = $ip_like_sql_flyreg = '';
  450. foreach($users as $address)
  451. {
  452. // Is this IP a range?
  453. if( preg_match('/(ff){1,3}$/i', $address) )
  454. {
  455. // num.xxx.xxx.xxx
  456. if( preg_match('/[0-9a-f]{2}ffffff/i', $address) )
  457. {
  458. $ip_start = substr($address, 0, 2);
  459. }
  460. // num.num.xxx.xxx
  461. elseif( preg_match('/[0-9a-f]{4}ffff/i', $address) )
  462. {
  463. $ip_start = substr($address, 0, 4);
  464. }
  465. // num.num.num.xxx
  466. elseif( preg_match('/[0-9a-f]{6}ff/i', $address) )
  467. {
  468. $ip_start = substr($address, 0, 6);
  469. }
  470. $ip_like_sql_flylast = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_last_ip LIKE '".$ip_start."%'" : "user_last_ip LIKE '".$ip_start."%'";
  471. $ip_like_sql_flyreg = $ip_like_sql . ( $ip_like_sql != '' ) ? " OR user_reg_ip LIKE '".$ip_start."%'" : "user_reg_ip LIKE '".$ip_start."%'";
  472. $ip_like_sql .= ( $ip_like_sql != '' ) ? " OR poster_ip LIKE '".$ip_start."%'" : "poster_ip LIKE '".$ip_start."%'";
  473. }
  474. else
  475. {
  476. $ip_in_sql .= ( $ip_in_sql == '' ) ? "'$address'" : ", '$address'";
  477. }
  478. }
  479. $where_sql = '';
  480. $where_sql .= ( $ip_in_sql != '' ) ? "poster_ip IN ($ip_in_sql)": "";
  481. $where_sql .= ( $ip_like_sql != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql" : "$ip_like_sql": "";
  482. if (!$where_sql) bb_die('invalid request');
  483. // start search
  484. $no_result_search = false;
  485. $ip_users_sql = '';
  486. $sql = "SELECT poster_id
  487. FROM ".BB_POSTS."
  488. WHERE poster_id <> ".GUEST_UID."
  489. AND ($where_sql)
  490. GROUP BY poster_id";
  491. if(!$result = DB()->sql_query($sql))
  492. {
  493. message_die(GENERAL_ERROR, "Could not count users", '', __LINE__, __FILE__, $sql);
  494. }
  495. if(DB()->num_rows($result)==0)
  496. {
  497. $no_result_search = true;
  498. // message_die(GENERAL_MESSAGE, $lang['SEARCH_NO_RESULTS']);
  499. }
  500. else
  501. {
  502. $total_pages['total'] = DB()->num_rows($result);
  503. $total_sql = NULL;
  504. $ip_users_sql = '';
  505. while($row = DB()->sql_fetchrow($result))
  506. {
  507. $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['poster_id'] : ', '.$row['poster_id'];
  508. }
  509. }
  510. // fly_indiz addon [START]
  511. // user last ip
  512. $where_sql = '';
  513. $where_sql .= ( $ip_in_sql != '' ) ? "user_last_ip IN ($ip_in_sql)": "";
  514. $where_sql .= ( $ip_like_sql_flylast != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flylast" : "$ip_like_sql_flylast": "";
  515. $sql = "SELECT user_id
  516. FROM ".BB_USERS."
  517. WHERE user_id <> ".GUEST_UID."
  518. AND ($where_sql)
  519. GROUP BY user_id";
  520. if(!$result = DB()->sql_query($sql))
  521. {
  522. message_die(GENERAL_ERROR, "Could not count users", '', __LINE__, __FILE__, $sql);
  523. }
  524. if(DB()->num_rows($result)!=0)
  525. {
  526. if ($no_result_search == true) $no_result_search = false;
  527. $total_pages['total'] = DB()->num_rows($result);
  528. $total_sql = NULL;
  529. while($row = DB()->sql_fetchrow($result))
  530. {
  531. $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id'];
  532. }
  533. }
  534. // user reg ip
  535. $where_sql = '';
  536. $where_sql .= ( $ip_in_sql != '' ) ? "user_reg_ip IN ($ip_in_sql)": "";
  537. $where_sql .= ( $ip_like_sql_flyreg != '' ) ? ( $where_sql != "" ) ? " OR $ip_like_sql_flyreg" : "$ip_like_sql_flyreg": "";
  538. $sql = "SELECT user_id
  539. FROM ".BB_USERS."
  540. WHERE user_id <> ".GUEST_UID."
  541. AND ($where_sql)
  542. GROUP BY user_id";
  543. if(!$result = DB()->sql_query($sql))
  544. {
  545. message_die(GENERAL_ERROR, "Could not count users", '', __LINE__, __FILE__, $sql);
  546. }
  547. if(DB()->num_rows($result)!=0)
  548. {
  549. if ($no_result_search == true) $no_result_search = false;
  550. $total_pages['total'] = DB()->num_rows($result);
  551. $total_sql = NULL;
  552. while($row = DB()->sql_fetchrow($result))
  553. {
  554. $ip_users_sql .= ( $ip_users_sql == '' ) ? $row['user_id'] : ', '.$row['user_id'];
  555. }
  556. }
  557. if ($no_result_search == true)
  558. {
  559. message_die(GENERAL_MESSAGE, $lang['SEARCH_NO_RESULTS']);
  560. }
  561. // fly_indiz addon [END]
  562. $select_sql .= " WHERE u.user_id IN ($ip_users_sql)";
  563. break;
  564. case 'search_joindate':
  565. $base_url .= '&search_joindate=true&date_type='. rawurlencode($date_type) .'&date_day='. rawurlencode($date_day) .'&date_month='. rawurlencode($date_month) .'&date_year='. rawurlencode(stripslashes($date_year));
  566. $date_type = trim(strtolower($date_type));
  567. if($date_type != 'before' && $date_type != 'after')
  568. {
  569. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_DATE']);
  570. }
  571. $date_day = intval($date_day);
  572. if( !preg_match('/^([1-9]|[0-2][0-9]|3[0-1])$/', $date_day) )
  573. {
  574. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_DAY']);
  575. }
  576. $date_month = intval($date_month);
  577. if( !preg_match('/^(0?[1-9]|1[0-2])$/', $date_month) )
  578. {
  579. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_MONTH']);
  580. }
  581. $date_year = intval($date_year);
  582. if( !preg_match('/^(20[0-9]{2}|19[0-9]{2})$/', $date_year) )
  583. {
  584. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_YEAR']);
  585. }
  586. $text = sprintf($lang['SEARCH_FOR_DATE'], strip_tags(htmlspecialchars(stripslashes($date_type))), $date_year, $date_month, $date_day);
  587. $time = mktime(0,0,0,$date_month, $date_day, $date_year);
  588. if($date_type == 'before')
  589. {
  590. $arg = '<';
  591. }
  592. else
  593. {
  594. $arg = '>';
  595. }
  596. $total_sql .= "SELECT COUNT(user_id) AS total
  597. FROM ".BB_USERS."
  598. WHERE user_regdate $arg $time
  599. AND user_id <> ".GUEST_UID;
  600. $select_sql .= " WHERE u.user_regdate $arg $time
  601. AND u.user_id <> ".GUEST_UID;
  602. break;
  603. case 'search_group':
  604. $group_id = intval($group_id);
  605. $base_url .= '&search_group=true&group_id='. rawurlencode($group_id);
  606. if(!$group_id)
  607. {
  608. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_GROUP']);
  609. }
  610. $sql = "SELECT group_name
  611. FROM ".BB_GROUPS."
  612. WHERE group_id = $group_id
  613. AND group_single_user = 0";
  614. if(!$result = DB()->sql_query($sql))
  615. {
  616. message_die(GENERAL_ERROR, 'Could not select group data', '', __LINE__, __FILE__, $sql);
  617. }
  618. if(DB()->num_rows($result)==0)
  619. {
  620. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_GROUP']);
  621. }
  622. $group_name = DB()->sql_fetchrow($result);
  623. $text = sprintf($lang['SEARCH_FOR_GROUP'], strip_tags(htmlspecialchars($group_name['group_name'])));
  624. $total_sql .= "SELECT COUNT(u.user_id) AS total
  625. FROM ".BB_USERS." AS u, ".BB_USER_GROUP." AS ug
  626. WHERE u.user_id = ug.user_id
  627. AND ug.group_id = $group_id
  628. AND u.user_id <> ".GUEST_UID;
  629. $select_sql .= ", ".BB_USER_GROUP." AS ug
  630. WHERE u.user_id = ug.user_id
  631. AND ug.group_id = $group_id
  632. AND u.user_id <> ".GUEST_UID;
  633. break;
  634. case 'search_rank':
  635. $rank_id = intval($rank_id);
  636. $base_url .= '&search_rank=true&rank_id='. rawurlencode($rank_id);
  637. if(!$rank_id)
  638. {
  639. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_RANK']);
  640. }
  641. $sql = "SELECT rank_title
  642. FROM ".BB_RANKS."
  643. WHERE rank_id = $rank_id
  644. AND rank_special = 1";
  645. if(!$result = DB()->sql_query($sql))
  646. {
  647. message_die(GENERAL_ERROR, 'Could not select rank data', '', __LINE__, __FILE__, $sql);
  648. }
  649. if(DB()->num_rows($result)==0)
  650. {
  651. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_RANK']);
  652. }
  653. $rank_title = DB()->sql_fetchrow($result);
  654. $text = sprintf($lang['SEARCH_FOR_RANK'], strip_tags(htmlspecialchars($rank_title['rank_title'])));
  655. $total_sql .= "SELECT COUNT(user_id) AS total
  656. FROM ".BB_USERS."
  657. WHERE user_rank = $rank_id
  658. AND user_id <> ".GUEST_UID;
  659. $select_sql .= " WHERE u.user_rank = $rank_id
  660. AND u.user_id <> ".GUEST_UID;
  661. break;
  662. case 'search_postcount':
  663. $postcount_type = trim(strtolower($postcount_type));
  664. $postcount_value = trim(strtolower($postcount_value));
  665. $base_url .= '&search_postcount=true&postcount_type='. rawurlencode($postcount_type) .'&postcount_value='. rawurlencode(stripslashes($postcount_value));
  666. switch($postcount_type)
  667. {
  668. case 'greater':
  669. $postcount_value = intval($postcount_value);
  670. $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_GREATER'], $postcount_value);
  671. $total_sql .= "SELECT COUNT(user_id) AS total
  672. FROM ".BB_USERS."
  673. WHERE user_posts > $postcount_value
  674. AND user_id <> ".GUEST_UID;
  675. $select_sql .= " WHERE u.user_posts > $postcount_value
  676. AND u.user_id <> ".GUEST_UID;
  677. break;
  678. case 'lesser':
  679. $postcount_value = intval($postcount_value);
  680. $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_LESSER'], $postcount_value);
  681. $total_sql .= "SELECT COUNT(user_id) AS total
  682. FROM ".BB_USERS."
  683. WHERE user_posts < $postcount_value
  684. AND user_id <> ".GUEST_UID;
  685. $select_sql .= " WHERE u.user_posts < $postcount_value
  686. AND u.user_id <> ".GUEST_UID;
  687. break;
  688. case 'equals':
  689. // looking for a -
  690. if(strstr($postcount_value, '-'))
  691. {
  692. $range = preg_split('/[-\s]+/', $postcount_value);
  693. $range_begin = intval($range[0]);
  694. $range_end = intval($range[1]);
  695. if($range_begin > $range_end)
  696. {
  697. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_POSTCOUNT']);
  698. }
  699. $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_RANGE'], $range_begin, $range_end);
  700. $total_sql .= "SELECT COUNT(user_id) AS total
  701. FROM ".BB_USERS."
  702. WHERE user_posts >= $range_begin
  703. AND user_posts <= $range_end
  704. AND user_id <> ".GUEST_UID;
  705. $select_sql .= " WHERE u.user_posts >= $range_begin
  706. AND u.user_posts <= $range_end
  707. AND u.user_id <> ".GUEST_UID;
  708. }
  709. else
  710. {
  711. $postcount_value = intval($postcount_value);
  712. $text = sprintf($lang['SEARCH_FOR_POSTCOUNT_EQUALS'], $postcount_value);
  713. $total_sql .= "SELECT COUNT(user_id) AS total
  714. FROM ".BB_USERS."
  715. WHERE user_posts = $postcount_value
  716. AND user_id <> ".GUEST_UID;
  717. $select_sql .= " WHERE u.user_posts = $postcount_value
  718. AND u.user_id <> ".GUEST_UID;
  719. }
  720. break;
  721. default:
  722. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID']);
  723. }
  724. break;
  725. case 'search_userfield':
  726. $base_url .= '&search_userfield=true&userfield_type='. rawurlencode($userfield_type) .'&userfield_value='. rawurlencode(stripslashes($userfield_value));
  727. $text = strip_tags(htmlspecialchars(stripslashes($userfield_value)));
  728. if(!$regex)
  729. {
  730. $userfield_value = preg_replace('/\*/', '%', trim(strip_tags(strtolower($userfield_value))));
  731. if(strstr($userfield_value, '%'))
  732. {
  733. $op = 'LIKE';
  734. }
  735. else
  736. {
  737. $op = '=';
  738. }
  739. }
  740. else
  741. {
  742. $userfield_value = preg_replace('/\\\\\\\(?<!\'|"|NULL)/', '\\', $userfield_value);
  743. }
  744. if($userfield_value == '')
  745. {
  746. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_USERFIELD']);
  747. }
  748. $userfield_type = trim(strtolower($userfield_type));
  749. switch($userfield_type)
  750. {
  751. case 'icq':
  752. $text = sprintf($lang['SEARCH_FOR_USERFIELD_ICQ'],$text);
  753. $field = 'user_icq';
  754. break;
  755. case 'skype':
  756. $text = sprintf($lang['SEARCH_FOR_USERFIELD_SKYPE'],$text);
  757. $field = 'user_skype';
  758. break;
  759. case 'website':
  760. $text = sprintf($lang['SEARCH_FOR_USERFIELD_WEBSITE'],$text);
  761. $field = 'user_website';
  762. break;
  763. case 'location':
  764. $text = sprintf($lang['SEARCH_FOR_USERFIELD_LOCATION'],$text);
  765. $field = 'user_from';
  766. break;
  767. case 'interests':
  768. $text = sprintf($lang['SEARCH_FOR_USERFIELD_INTERESTS'],$text);
  769. $field = 'user_interests';
  770. break;
  771. case 'occupation':
  772. $text = sprintf($lang['SEARCH_FOR_USERFIELD_OCCUPATION'],$text);
  773. $field = 'user_occ';
  774. break;
  775. default:
  776. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID']);
  777. }
  778. if($regex && SQL_LAYER == 'oracle')
  779. {
  780. $total_sql .= "SELECT COUNT(user_id) AS total
  781. FROM ".BB_USERS."
  782. WHERE REGEXP_LIKE($field, '".DB()->escape($userfield_value)."')
  783. AND user_id <> ".GUEST_UID;
  784. $select_sql .= " WHERE REGEXP_LIKE(u.$field, '".DB()->escape($userfield_value)."')
  785. AND u.user_id <> ".GUEST_UID;
  786. }
  787. else
  788. {
  789. $total_sql .= "SELECT COUNT(user_id) AS total
  790. FROM ".BB_USERS."
  791. WHERE {$lower_b}$field{$lower_e} $op '".DB()->escape($userfield_value)."'
  792. AND user_id <> ".GUEST_UID;
  793. $select_sql .= " WHERE {$lower_b}u.$field{$lower_e} $op '".DB()->escape($userfield_value)."'
  794. AND u.user_id <> ".GUEST_UID;
  795. }
  796. break;
  797. case 'search_lastvisited':
  798. $lastvisited_type = trim(strtolower($lastvisited_type));
  799. $lastvisited_days = intval($lastvisited_days);
  800. $base_url .= '&search_lastvisited=true&lastvisited_type='. rawurlencode(stripslashes($lastvisited_type)) .'&lastvisited_days='. rawurlencode($lastvisited_days);
  801. $lastvisited_seconds = ( TIMENOW - ( ( ( $lastvisited_days * 24 ) * 60 ) * 60 ) );
  802. switch($lastvisited_type)
  803. {
  804. case 'in':
  805. $text = sprintf($lang['SEARCH_FOR_LASTVISITED_INTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ) );
  806. $total_sql .= "SELECT COUNT(user_id) AS total
  807. FROM ".BB_USERS."
  808. WHERE user_lastvisit >= $lastvisited_seconds
  809. AND user_id <> ".GUEST_UID;
  810. $select_sql .= " WHERE u.user_lastvisit >= $lastvisited_seconds
  811. AND u.user_id <> ".GUEST_UID;
  812. break;
  813. case 'after':
  814. $text = sprintf($lang['SEARCH_FOR_LASTVISITED_AFTERTHELAST'], $lastvisited_days, ( ( $lastvisited_days > 1 ) ? $lang['DAYS'] : $lang['DAY'] ));
  815. $total_sql .= "SELECT COUNT(user_id) AS total
  816. FROM ".BB_USERS."
  817. WHERE user_lastvisit < $lastvisited_seconds
  818. AND user_id <> ".GUEST_UID;
  819. $select_sql .= " WHERE u.user_lastvisit < $lastvisited_seconds
  820. AND u.user_id <> ".GUEST_UID;
  821. break;
  822. default:
  823. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_LASTVISITED']);
  824. }
  825. break;
  826. case 'search_language':
  827. $base_url .= '&search_language=true&language_type='. rawurlencode(stripslashes($language_type));
  828. $language_type = trim(strtolower(stripslashes($language_type)));
  829. if($language_type == '')
  830. {
  831. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_LANGUAGE']);
  832. }
  833. $text = sprintf($lang['SEARCH_FOR_LANGUAGE'], strip_tags(htmlspecialchars($language_type)));
  834. $total_sql .= "SELECT COUNT(user_id) AS total
  835. FROM ".BB_USERS."
  836. WHERE user_lang = '".DB()->escape($language_type)."'
  837. AND user_id <> ".GUEST_UID;
  838. $select_sql .= " WHERE u.user_lang = '".DB()->escape($language_type)."'
  839. AND u.user_id <> ".GUEST_UID;
  840. break;
  841. case 'search_timezone':
  842. $base_url .= '&search_timezone=true&timezone_type='. rawurlencode(stripslashes($timezone_type));
  843. $text = sprintf($lang['SEARCH_FOR_TIMEZONE'], strip_tags(htmlspecialchars(stripslashes($timezone_type))));
  844. $timezone_type = intval($timezone_type);
  845. $total_sql .= "SELECT COUNT(user_id) AS total
  846. FROM ".BB_USERS."
  847. WHERE user_timezone = $timezone_type
  848. AND user_id <> ".GUEST_UID;
  849. $select_sql .= " WHERE u.user_timezone = $timezone_type
  850. AND u.user_id <> ".GUEST_UID;
  851. break;
  852. case 'search_style':
  853. message_die(GENERAL_MESSAGE, 'Disabled');
  854. break;
  855. case 'search_moderators':
  856. $base_url .= '&search_moderators=true&moderators_forum='. rawurlencode(stripslashes($moderators_forum));
  857. $moderators_forum = intval($moderators_forum);
  858. $sql = "SELECT forum_name
  859. FROM ".BB_FORUMS."
  860. WHERE forum_id = ".$moderators_forum;
  861. if(!$result = DB()->sql_query($sql))
  862. {
  863. message_die(GENERAL_ERROR, 'Could not select forum data', '', __LINE__, __FILE__, $sql);
  864. }
  865. if(DB()->num_rows($result)==0)
  866. {
  867. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID_MODERATORS']);
  868. }
  869. $forum_name = DB()->sql_fetchrow($result);
  870. $text = sprintf($lang['SEARCH_FOR_MODERATORS'], htmlCHR($forum_name['forum_name']));
  871. $total_sql .= "SELECT COUNT(DISTINCT u.user_id) AS total
  872. FROM ".BB_USERS." AS u, ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa
  873. WHERE u.user_id = ug.user_id
  874. AND ug.group_id = g.group_id
  875. AND g.group_id = aa.group_id
  876. AND aa.forum_id = ". $moderators_forum ."
  877. AND aa.forum_perm & ". BF_AUTH_MOD ."
  878. AND u.user_id <> ".GUEST_UID;
  879. $select_sql .= ", ".BB_GROUPS." AS g, ".BB_USER_GROUP." AS ug, ".BB_AUTH_ACCESS." AS aa
  880. WHERE u.user_id = ug.user_id
  881. AND ug.group_id = g.group_id
  882. AND g.group_id = aa.group_id
  883. AND aa.forum_id = ". $moderators_forum ."
  884. AND aa.forum_perm & ". BF_AUTH_MOD ."
  885. AND u.user_id <> ".GUEST_UID."
  886. GROUP BY u.user_id, u.username, u.user_email, u.user_posts, u.user_regdate, u.user_level, u.user_active, u.user_lastvisit";
  887. break;
  888. case 'search_misc':
  889. default:
  890. $misc = trim(strtolower($misc));
  891. $base_url .= '&search_misc=true&misc='. rawurlencode(stripslashes($misc));
  892. switch($misc)
  893. {
  894. case 'admins':
  895. $text = $lang['SEARCH_FOR_ADMINS'];
  896. $total_sql .= "SELECT COUNT(user_id) AS total
  897. FROM ".BB_USERS."
  898. WHERE user_level = ".ADMIN."
  899. AND user_id <> ".GUEST_UID;
  900. $select_sql .= " WHERE u.user_level = ".ADMIN."
  901. AND u.user_id <> ".GUEST_UID;
  902. break;
  903. case 'mods':
  904. $text = $lang['SEARCH_FOR_MODS'];
  905. $total_sql .= "SELECT COUNT(user_id) AS total
  906. FROM ".BB_USERS."
  907. WHERE user_level = ".MOD."
  908. AND user_id <> ".GUEST_UID;
  909. $select_sql .= " WHERE u.user_level = ".MOD."
  910. AND u.user_id <> ".GUEST_UID;
  911. break;
  912. case 'banned':
  913. $text = $lang['SEARCH_FOR_BANNED'];
  914. $total_sql .= "SELECT COUNT(u.user_id) AS total
  915. FROM ".BB_USERS." AS u, ".BB_BANLIST." AS b
  916. WHERE u.user_id = b.ban_userid
  917. AND u.user_id <> ".GUEST_UID;
  918. $select_sql .= ", ".BB_BANLIST." AS b
  919. WHERE u.user_id = b.ban_userid
  920. AND u.user_id <> ".GUEST_UID;
  921. break;
  922. case 'disabled':
  923. $text = $lang['SEARCH_FOR_DISABLED'];
  924. $total_sql .= "SELECT COUNT(user_id) AS total
  925. FROM ".BB_USERS."
  926. WHERE user_active = 0
  927. AND user_id <> ".GUEST_UID;
  928. $select_sql .= " WHERE u.user_active = 0
  929. AND u.user_id <> ".GUEST_UID;
  930. break;
  931. default:
  932. message_die(GENERAL_MESSAGE, $lang['SEARCH_INVALID']);
  933. }
  934. }
  935. if(@$regex)
  936. {
  937. $base_url .= '&regex=1';
  938. }
  939. $select_sql .= " ORDER BY ";
  940. switch(strtolower(@$_GET['sort']))
  941. {
  942. case 'regdate':
  943. $sort = 'regdate';
  944. $select_sql .= 'u.user_regdate';
  945. break;
  946. case 'posts':
  947. $sort = 'posts';
  948. $select_sql .= 'u.user_posts';
  949. break;
  950. case 'user_email':
  951. $sort = 'user_email';
  952. $select_sql .= 'u.user_email';
  953. break;
  954. case 'lastvisit':
  955. $sort = 'lastvisit';
  956. $select_sql .= 'u.user_lastvisit';
  957. break;
  958. case 'username':
  959. default:
  960. $sort = 'username';
  961. $select_sql .= 'u.username';
  962. }
  963. switch(@$_GET['order'])
  964. {
  965. case 'DESC':
  966. $order = 'DESC';
  967. $o_order = 'ASC';
  968. break;
  969. default:
  970. $o_order = 'DESC';
  971. $order = 'ASC';
  972. }
  973. $select_sql .= " $order";
  974. $page = ( isset($_GET['page']) ) ? intval($_GET['page']) : intval(trim(@$_POST['page']));
  975. if($page < 1)
  976. {
  977. $page = 1;
  978. }
  979. if($page == 1)
  980. {
  981. $offset = 0;
  982. }
  983. else
  984. {
  985. $offset = ( ($page - 1) * $bb_cfg['topics_per_page']);
  986. }
  987. $limit = "LIMIT $offset, ".$bb_cfg['topics_per_page'];
  988. $select_sql .= " $limit";
  989. if(!is_null($total_sql))
  990. {
  991. if(!$result = DB()->sql_query($total_sql))
  992. {
  993. message_die(GENERAL_ERROR, "Could not count users", '', __LINE__, __FILE__, $total_sql);
  994. }
  995. $total_pages = DB()->sql_fetchrow($result);
  996. if($total_pages['total'] == 0)
  997. {
  998. message_die(GENERAL_MESSAGE, $lang['SEARCH_NO_RESULTS']);
  999. }
  1000. }
  1001. $num_pages = ceil( ( $total_pages['total'] / $bb_cfg['topics_per_page'] ) );
  1002. $pagination = '';
  1003. if($page > 1)
  1004. {
  1005. $pagination .= '<a href="'.$base_url.'&sort='.$sort.'&order='.$order.'&page='.($page - 1).'">'. $lang['PREVIOUS'] .'</a>';
  1006. }
  1007. if($page < $num_pages)
  1008. {
  1009. $pagination .= ( $pagination == '' ) ? '<a href="'.$base_url.'&sort='.$sort.'&order='.$order.'&page='. ($page + 1) .'">'.$lang['NEXT'].'</a>' : ' | <a href="'.$base_url.'&sort='.$sort.'&order='.$order.'&page='. ($page + 1) .'">'.$lang['NEXT'].'</a>';
  1010. }
  1011. if ($num_pages > 2)
  1012. {
  1013. $pagination .= '&nbsp;&nbsp;<input type="text" name="page" maxlength="5" size="2" class="post" />&nbsp;<input type="submit" name="submit" value="'.$lang['GO'].'" class="post" />';
  1014. }
  1015. $template->assign_vars(array(
  1016. 'TPL_ADMIN_USER_SEARCH_RESULTS' => true,
  1017. 'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], $page, $num_pages),
  1018. 'PAGINATION' => $pagination,
  1019. 'NEW_SEARCH' => sprintf($lang['SEARCH_USERS_NEW'],$text, $total_pages['total'], 'admin_user_search.php'),
  1020. 'U_USERNAME' => ($sort == 'username') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=username&order=$order",
  1021. 'U_EMAIL' => ($sort == 'user_email') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=user_email&order=$order",
  1022. 'U_POSTS' => ($sort == 'posts') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=posts&order=$order",
  1023. 'U_JOINDATE' => ($sort == 'regdate') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=regdate&order=$order",
  1024. 'U_LASTVISIT' => ($sort == 'lastvisit') ? "$base_url&sort=$sort&order=$o_order" : "$base_url&sort=lastvisit&order=$order",
  1025. 'S_POST_ACTION' => "$base_url&sort=$sort&order=$order"
  1026. ));
  1027. if(!$result = DB()->sql_query($select_sql))
  1028. {
  1029. message_die(GENERAL_ERROR, "Could not select user data", '', __LINE__, __FILE__, $select_sql);
  1030. }
  1031. $rowset = DB()->sql_fetchrowset($result);
  1032. $users_sql = '';
  1033. foreach($rowset as $array)
  1034. {
  1035. $users_sql .= ( $users_sql == '' ) ? $array['user_id'] : ', '.$array['user_id'];
  1036. }
  1037. $sql = "SELECT ban_userid AS user_id
  1038. FROM ". BB_BANLIST ."
  1039. WHERE ban_userid IN ($users_sql)";
  1040. if(!$result = DB()->sql_query($sql))
  1041. {
  1042. message_die(GENERAL_ERROR, "Could not select banned data", '', __LINE__, __FILE__, $sql);
  1043. }
  1044. unset($banned);
  1045. $banned = array();
  1046. while($row = DB()->sql_fetchrow($result))
  1047. {
  1048. $banned[$row['user_id']] = true;
  1049. }
  1050. for($i = 0; $i < count($rowset); $i++)
  1051. {
  1052. $row_class = !($i % 2) ? 'row1' : 'row2';
  1053. $template->assign_block_vars('userrow', array(
  1054. 'ROW_CLASS' => $row_class,
  1055. 'USER' => profile_url($rowset[$i]),
  1056. 'EMAIL' => $rowset[$i]['user_email'],
  1057. 'JOINDATE' => bb_date($rowset[$i]['user_regdate']),
  1058. 'LASTVISIT' => bb_date($rowset[$i]['user_lastvisit']),
  1059. 'POSTS' => $rowset[$i]['user_posts'],
  1060. 'BAN' => ( ( !isset($banned[$rowset[$i]['user_id']]) ) ? $lang['NOT_BANNED'] : $lang['BANNED'] ),
  1061. 'ABLED' => ( ( $rowset[$i]['user_active'] ) ? $lang['ENABLED'] : $lang['DISABLED'] ),
  1062. 'U_VIEWPOSTS' => "../search.php?search_author=1&amp;uid={$rowset[$i]['user_id']}",
  1063. 'U_MANAGE' => '../profile.php?mode=editprofile&'. POST_USERS_URL .'='.$rowset[$i]['user_id'].'&admin=1',
  1064. 'U_PERMISSIONS' => 'admin_ug_auth.php?mode=user&'. POST_USERS_URL .'='. $rowset[$i]['user_id'],
  1065. ));
  1066. }
  1067. }
  1068. print_page('admin_user_search.tpl', 'admin');