PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/mcp.php

https://github.com/prototech/phpbb
PHP | 834 lines | 627 code | 140 blank | 67 comment | 123 complexity | e6c6c9c2c35163a32efa9be085d1f561 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package mcp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
  15. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  16. include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
  17. include(PHPBB_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT);
  18. require(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
  19. // Start session management
  20. phpbb::$user->session_begin();
  21. phpbb::$acl->init(phpbb::$user->data);
  22. phpbb::$user->setup('mcp');
  23. $module = new p_master();
  24. // Setting a variable to let the style designer know where he is...
  25. phpbb::$template->assign_var('S_IN_MCP', true);
  26. // Basic parameter data
  27. $id = request_var('i', '');
  28. $mode = request_var('mode', array(''));
  29. if (!empty($mode))
  30. {
  31. $mode = key($mode);
  32. }
  33. else
  34. {
  35. $mode = request_var('mode', '');
  36. }
  37. // Only Moderators can go beyond this point
  38. if (!phpbb::$user->is_registered)
  39. {
  40. if (phpbb::$user->is_bot)
  41. {
  42. redirect(append_sid(PHPBB_ROOT_PATH . 'index.' . PHP_EXT));
  43. }
  44. login_box('', phpbb::$user->lang['LOGIN_EXPLAIN_MCP']);
  45. }
  46. $quickmod = phpbb_request::is_set('quickmod');
  47. $action = request_var('action', '');
  48. $action_ary = request_var('action', array('' => 0));
  49. $forum_action = request_var('forum_action', '');
  50. if (sizeof($action_ary))
  51. {
  52. $action = key($action_ary);
  53. }
  54. else if (!empty($forum_action) && phpbb_request::variable('sort', false, false, phpbb_request::POST))
  55. {
  56. $action = $forum_action;
  57. }
  58. unset($action_ary);
  59. if ($mode == 'topic_logs')
  60. {
  61. $id = 'logs';
  62. $quickmod = false;
  63. }
  64. $post_id = request_var('p', 0);
  65. $topic_id = request_var('t', 0);
  66. $forum_id = request_var('f', 0);
  67. $user_id = request_var('u', 0);
  68. $username = utf8_normalize_nfc(request_var('username', '', true));
  69. if ($post_id)
  70. {
  71. // We determine the topic and forum id here, to make sure the moderator really has moderative rights on this post
  72. $sql = 'SELECT topic_id, forum_id
  73. FROM ' . POSTS_TABLE . "
  74. WHERE post_id = $post_id";
  75. $result = phpbb::$db->sql_query($sql);
  76. $row = phpbb::$db->sql_fetchrow($result);
  77. phpbb::$db->sql_freeresult($result);
  78. $topic_id = (int) $row['topic_id'];
  79. $forum_id = (int) ($row['forum_id']) ? $row['forum_id'] : $forum_id;
  80. }
  81. else if ($topic_id)
  82. {
  83. $sql = 'SELECT forum_id
  84. FROM ' . TOPICS_TABLE . "
  85. WHERE topic_id = $topic_id";
  86. $result = phpbb::$db->sql_query($sql);
  87. $row = phpbb::$db->sql_fetchrow($result);
  88. phpbb::$db->sql_freeresult($result);
  89. $forum_id = (int) $row['forum_id'];
  90. }
  91. // If the user doesn't have any moderator powers (globally or locally) he can't access the mcp
  92. if (!phpbb::$acl->acl_getf_global('m_'))
  93. {
  94. // Except he is using one of the quickmod tools for users
  95. $user_quickmod_actions = array(
  96. 'lock' => 'f_user_lock',
  97. 'make_sticky' => 'f_sticky',
  98. 'make_announce' => 'f_announce',
  99. 'make_global' => 'f_announce',
  100. 'make_normal' => array('f_announce', 'f_sticky')
  101. );
  102. $allow_user = false;
  103. if ($quickmod && isset($user_quickmod_actions[$action]) && phpbb::$user->is_registered && phpbb::$acl->acl_gets($user_quickmod_actions[$action], $forum_id))
  104. {
  105. $topic_info = get_topic_data(array($topic_id));
  106. if ($topic_info[$topic_id]['topic_poster'] == phpbb::$user->data['user_id'])
  107. {
  108. $allow_user = true;
  109. }
  110. }
  111. if (!$allow_user)
  112. {
  113. trigger_error('NOT_AUTHORISED');
  114. }
  115. }
  116. // if the user cannot read the forum he tries to access then we won't allow mcp access either
  117. if ($forum_id && !phpbb::$acl->acl_get('f_read', $forum_id))
  118. {
  119. trigger_error('NOT_AUTHORISED');
  120. }
  121. if ($forum_id)
  122. {
  123. $module->acl_forum_id = $forum_id;
  124. }
  125. // Instantiate module system and generate list of available modules
  126. $module->list_modules('mcp');
  127. if ($quickmod)
  128. {
  129. $mode = 'quickmod';
  130. switch ($action)
  131. {
  132. case 'lock':
  133. case 'unlock':
  134. case 'lock_post':
  135. case 'unlock_post':
  136. case 'make_sticky':
  137. case 'make_announce':
  138. case 'make_global':
  139. case 'make_normal':
  140. case 'fork':
  141. case 'move':
  142. case 'delete_post':
  143. case 'delete_topic':
  144. $module->load('mcp', 'main', 'quickmod');
  145. return;
  146. break;
  147. case 'topic_logs':
  148. // Reset start parameter if we jumped from the quickmod dropdown
  149. if (request_var('start', 0))
  150. {
  151. phpbb_request::overwrite('start', 0, phpbb_request::GET);
  152. phpbb_request::overwrite('start', 0, phpbb_request::REQUEST);
  153. }
  154. $module->set_active('logs', 'topic_logs');
  155. break;
  156. case 'merge_topic':
  157. $module->set_active('main', 'forum_view');
  158. break;
  159. case 'split':
  160. case 'merge':
  161. $module->set_active('main', 'topic_view');
  162. break;
  163. default:
  164. trigger_error("$action not allowed as quickmod", E_USER_ERROR);
  165. break;
  166. }
  167. }
  168. else
  169. {
  170. // Select the active module
  171. $module->set_active($id, $mode);
  172. }
  173. // Hide some of the options if we don't have the relevant information to use them
  174. if (!$post_id)
  175. {
  176. $module->set_display('main', 'post_details', false);
  177. $module->set_display('warn', 'warn_post', false);
  178. }
  179. if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts')
  180. {
  181. $module->set_display('queue', 'approve_details', false);
  182. }
  183. if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed')
  184. {
  185. $module->set_display('reports', 'report_details', false);
  186. }
  187. if (!$topic_id)
  188. {
  189. $module->set_display('main', 'topic_view', false);
  190. $module->set_display('logs', 'topic_logs', false);
  191. }
  192. if (!$forum_id)
  193. {
  194. $module->set_display('main', 'forum_view', false);
  195. $module->set_display('logs', 'forum_logs', false);
  196. }
  197. if (!$user_id && $username == '')
  198. {
  199. $module->set_display('notes', 'user_notes', false);
  200. $module->set_display('warn', 'warn_user', false);
  201. }
  202. // Load and execute the relevant module
  203. $module->load_active();
  204. // Assign data to the template engine for the list of modules
  205. $module->assign_tpl_vars(append_sid(PHPBB_ROOT_PATH . 'mcp.' . PHP_EXT));
  206. // Generate urls for letting the moderation control panel being accessed in different modes
  207. phpbb::$template->assign_vars(array(
  208. 'U_MCP' => append_sid('mcp', 'i=main'),
  209. 'U_MCP_FORUM' => ($forum_id) ? append_sid('mcp', "i=main&amp;mode=forum_view&amp;f=$forum_id") : '',
  210. 'U_MCP_TOPIC' => ($forum_id && $topic_id) ? append_sid('mcp', "i=main&amp;mode=topic_view&amp;t=$topic_id") : '',
  211. 'U_MCP_POST' => ($forum_id && $topic_id && $post_id) ? append_sid('mcp', "i=main&amp;mode=post_details&amp;t=$topic_id&amp;p=$post_id") : '',
  212. ));
  213. // Generate the page, do not display/query online list
  214. $module->display($module->get_page_title(), false);
  215. /**
  216. * Functions used to generate additional URL paramters
  217. */
  218. function _module__url($mode, &$module_row)
  219. {
  220. return extra_url();
  221. }
  222. function _module_notes_url($mode, &$module_row)
  223. {
  224. if ($mode == 'front')
  225. {
  226. return '';
  227. }
  228. global $user_id;
  229. return ($user_id) ? "&amp;u=$user_id" : '';
  230. }
  231. function _module_warn_url($mode, &$module_row)
  232. {
  233. if ($mode == 'front' || $mode == 'list')
  234. {
  235. global $forum_id;
  236. return ($forum_id) ? "&amp;f=$forum_id" : '';
  237. }
  238. if ($mode == 'warn_post')
  239. {
  240. global $forum_id, $post_id;
  241. $url_extra = ($forum_id) ? "&amp;f=$forum_id" : '';
  242. $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
  243. return $url_extra;
  244. }
  245. else
  246. {
  247. global $user_id;
  248. return ($user_id) ? "&amp;u=$user_id" : '';
  249. }
  250. }
  251. function _module_main_url($mode, &$module_row)
  252. {
  253. return extra_url();
  254. }
  255. function _module_logs_url($mode, &$module_row)
  256. {
  257. return extra_url();
  258. }
  259. function _module_ban_url($mode, &$module_row)
  260. {
  261. return extra_url();
  262. }
  263. function _module_queue_url($mode, &$module_row)
  264. {
  265. return extra_url();
  266. }
  267. function _module_reports_url($mode, &$module_row)
  268. {
  269. return extra_url();
  270. }
  271. function extra_url()
  272. {
  273. global $forum_id, $topic_id, $post_id, $user_id;
  274. $url_extra = '';
  275. $url_extra .= ($forum_id) ? "&amp;f=$forum_id" : '';
  276. $url_extra .= ($topic_id) ? "&amp;t=$topic_id" : '';
  277. $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
  278. $url_extra .= ($user_id) ? "&amp;u=$user_id" : '';
  279. return $url_extra;
  280. }
  281. /**
  282. * Get simple topic data
  283. */
  284. function get_topic_data($topic_ids, $acl_list = false, $read_tracking = false)
  285. {
  286. static $rowset = array();
  287. $topics = array();
  288. if (!sizeof($topic_ids))
  289. {
  290. return array();
  291. }
  292. // cache might not contain read tracking info, so we can't use it if read
  293. // tracking information is requested
  294. if (!$read_tracking)
  295. {
  296. $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
  297. $topic_ids = array_diff($topic_ids, array_keys($rowset));
  298. }
  299. else
  300. {
  301. $cache_topic_ids = array();
  302. }
  303. if (sizeof($topic_ids))
  304. {
  305. $sql_array = array(
  306. 'SELECT' => 't.*, f.*',
  307. 'FROM' => array(
  308. TOPICS_TABLE => 't',
  309. ),
  310. 'LEFT_JOIN' => array(
  311. array(
  312. 'FROM' => array(FORUMS_TABLE => 'f'),
  313. 'ON' => 'f.forum_id = t.forum_id'
  314. )
  315. ),
  316. 'WHERE' => phpbb::$db->sql_in_set('t.topic_id', $topic_ids)
  317. );
  318. if ($read_tracking && phpbb::$config['load_db_lastread'])
  319. {
  320. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
  321. $sql_array['LEFT_JOIN'][] = array(
  322. 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
  323. 'ON' => 'tt.user_id = ' . phpbb::$user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
  324. );
  325. $sql_array['LEFT_JOIN'][] = array(
  326. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  327. 'ON' => 'ft.user_id = ' . phpbb::$user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
  328. );
  329. }
  330. $sql = phpbb::$db->sql_build_query('SELECT', $sql_array);
  331. $result = phpbb::$db->sql_query($sql);
  332. while ($row = phpbb::$db->sql_fetchrow($result))
  333. {
  334. if (!$row['forum_id'])
  335. {
  336. // Global Announcement?
  337. $row['forum_id'] = request_var('f', 0);
  338. }
  339. $rowset[$row['topic_id']] = $row;
  340. if ($acl_list && !phpbb::$acl->acl_gets($acl_list, $row['forum_id']))
  341. {
  342. continue;
  343. }
  344. $topics[$row['topic_id']] = $row;
  345. }
  346. phpbb::$db->sql_freeresult($result);
  347. }
  348. foreach ($cache_topic_ids as $id)
  349. {
  350. if (!$acl_list || phpbb::$acl->acl_gets($acl_list, $rowset[$id]['forum_id']))
  351. {
  352. $topics[$id] = $rowset[$id];
  353. }
  354. }
  355. return $topics;
  356. }
  357. /**
  358. * Get simple post data
  359. */
  360. function get_post_data($post_ids, $acl_list = false, $read_tracking = false)
  361. {
  362. $rowset = array();
  363. if (!sizeof($post_ids))
  364. {
  365. return array();
  366. }
  367. $sql_array = array(
  368. 'SELECT' => 'p.*, u.*, t.*, f.*',
  369. 'FROM' => array(
  370. USERS_TABLE => 'u',
  371. POSTS_TABLE => 'p',
  372. TOPICS_TABLE => 't',
  373. ),
  374. 'LEFT_JOIN' => array(
  375. array(
  376. 'FROM' => array(FORUMS_TABLE => 'f'),
  377. 'ON' => 'f.forum_id = t.forum_id'
  378. )
  379. ),
  380. 'WHERE' => phpbb::$db->sql_in_set('p.post_id', $post_ids) . '
  381. AND u.user_id = p.poster_id
  382. AND t.topic_id = p.topic_id',
  383. );
  384. if ($read_tracking && phpbb::$config['load_db_lastread'])
  385. {
  386. $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
  387. $sql_array['LEFT_JOIN'][] = array(
  388. 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
  389. 'ON' => 'tt.user_id = ' . phpbb::$user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
  390. );
  391. $sql_array['LEFT_JOIN'][] = array(
  392. 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
  393. 'ON' => 'ft.user_id = ' . phpbb::$user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
  394. );
  395. }
  396. $sql = phpbb::$db->sql_build_query('SELECT', $sql_array);
  397. $result = phpbb::$db->sql_query($sql);
  398. unset($sql_array);
  399. while ($row = phpbb::$db->sql_fetchrow($result))
  400. {
  401. if (!$row['forum_id'])
  402. {
  403. // Global Announcement?
  404. $row['forum_id'] = request_var('f', 0);
  405. }
  406. if ($acl_list && !phpbb::$acl->acl_gets($acl_list, $row['forum_id']))
  407. {
  408. continue;
  409. }
  410. if (!$row['post_approved'] && !phpbb::$acl->acl_get('m_approve', $row['forum_id']))
  411. {
  412. // Moderators without the permission to approve post should at least not see them. ;)
  413. continue;
  414. }
  415. $rowset[$row['post_id']] = $row;
  416. }
  417. phpbb::$db->sql_freeresult($result);
  418. return $rowset;
  419. }
  420. /**
  421. * Get simple forum data
  422. */
  423. function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false)
  424. {
  425. $rowset = array();
  426. if (!is_array($forum_id))
  427. {
  428. $forum_id = array($forum_id);
  429. }
  430. if (!sizeof($forum_id))
  431. {
  432. return array();
  433. }
  434. if ($read_tracking && phpbb::$config['load_db_lastread'])
  435. {
  436. $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . phpbb::$user->data['user_id'] . '
  437. AND ft.forum_id = f.forum_id)';
  438. $read_tracking_select = ', ft.mark_time';
  439. }
  440. else
  441. {
  442. $read_tracking_join = $read_tracking_select = '';
  443. }
  444. $sql = "SELECT f.* $read_tracking_select
  445. FROM " . FORUMS_TABLE . " f$read_tracking_join
  446. WHERE " . phpbb::$db->sql_in_set('f.forum_id', $forum_id);
  447. $result = phpbb::$db->sql_query($sql);
  448. while ($row = phpbb::$db->sql_fetchrow($result))
  449. {
  450. if ($acl_list && !phpbb::$acl->acl_gets($acl_list, $row['forum_id']))
  451. {
  452. continue;
  453. }
  454. if (phpbb::$acl->acl_get('m_approve', $row['forum_id']))
  455. {
  456. $row['forum_topics'] = $row['forum_topics_real'];
  457. }
  458. $rowset[$row['forum_id']] = $row;
  459. }
  460. phpbb::$db->sql_freeresult($result);
  461. return $rowset;
  462. }
  463. /**
  464. * sorting in mcp
  465. *
  466. * @param string $where_sql should either be WHERE (default if ommited) or end with AND or OR
  467. */
  468. function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, &$sort_order_sql, &$total, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE')
  469. {
  470. $sort_days = request_var('st', 0);
  471. $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0;
  472. switch ($mode)
  473. {
  474. case 'viewforum':
  475. $type = 'topics';
  476. $default_key = 't';
  477. $default_dir = 'd';
  478. $sql = 'SELECT COUNT(topic_id) AS total
  479. FROM ' . TOPICS_TABLE . "
  480. $where_sql forum_id = $forum_id
  481. AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
  482. AND topic_last_post_time >= $min_time";
  483. if (!phpbb::$acl->acl_get('m_approve', $forum_id))
  484. {
  485. $sql .= 'AND topic_approved = 1';
  486. }
  487. break;
  488. case 'viewtopic':
  489. $type = 'posts';
  490. $default_key = 't';
  491. $default_dir = 'a';
  492. $sql = 'SELECT COUNT(post_id) AS total
  493. FROM ' . POSTS_TABLE . "
  494. $where_sql topic_id = $topic_id
  495. AND post_time >= $min_time";
  496. if (!phpbb::$acl->acl_get('m_approve', $forum_id))
  497. {
  498. $sql .= 'AND post_approved = 1';
  499. }
  500. break;
  501. case 'unapproved_posts':
  502. $type = 'posts';
  503. $default_key = 't';
  504. $default_dir = 'd';
  505. $where_sql .= ($topic_id) ? ' topic_id = ' . $topic_id . ' AND' : '';
  506. $sql = 'SELECT COUNT(post_id) AS total
  507. FROM ' . POSTS_TABLE . "
  508. $where_sql " . phpbb::$db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
  509. AND post_approved = 0';
  510. if ($min_time)
  511. {
  512. $sql .= ' AND post_time >= ' . $min_time;
  513. }
  514. break;
  515. case 'unapproved_topics':
  516. $type = 'topics';
  517. $default_key = 't';
  518. $default_dir = 'd';
  519. $sql = 'SELECT COUNT(topic_id) AS total
  520. FROM ' . TOPICS_TABLE . "
  521. $where_sql " . phpbb::$db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
  522. AND topic_approved = 0';
  523. if ($min_time)
  524. {
  525. $sql .= ' AND topic_time >= ' . $min_time;
  526. }
  527. break;
  528. case 'reports':
  529. case 'reports_closed':
  530. $type = 'reports';
  531. $default_key = 't';
  532. $default_dir = 'd';
  533. $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
  534. if ($topic_id)
  535. {
  536. $where_sql .= ' p.topic_id = ' . $topic_id;
  537. }
  538. else if ($forum_id)
  539. {
  540. $where_sql .= ' p.forum_id = ' . $forum_id;
  541. }
  542. else
  543. {
  544. $where_sql .= ' ' . phpbb::$db->sql_in_set('p.forum_id', get_forum_list(array('!f_read', '!m_report')), true, true);
  545. }
  546. if ($mode == 'reports')
  547. {
  548. $where_sql .= ' AND r.report_closed = 0';
  549. }
  550. else
  551. {
  552. $where_sql .= ' AND r.report_closed = 1';
  553. }
  554. $sql = 'SELECT COUNT(r.report_id) AS total
  555. FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
  556. $where_sql
  557. AND p.post_id = r.post_id
  558. $limit_time_sql";
  559. break;
  560. case 'viewlogs':
  561. $type = 'logs';
  562. $default_key = 't';
  563. $default_dir = 'd';
  564. $sql = 'SELECT COUNT(log_id) AS total
  565. FROM ' . LOG_TABLE . "
  566. $where_sql " . phpbb::$db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_'))) . '
  567. AND log_time >= ' . $min_time . '
  568. AND log_type = ' . LOG_MOD;
  569. break;
  570. }
  571. $sort_key = request_var('sk', $default_key);
  572. $sort_dir = request_var('sd', $default_dir);
  573. $sort_dir_text = array('a' => phpbb::$user->lang['ASCENDING'], 'd' => phpbb::$user->lang['DESCENDING']);
  574. switch ($type)
  575. {
  576. case 'topics':
  577. $limit_days = array(0 => phpbb::$user->lang['ALL_TOPICS'], 1 => phpbb::$user->lang['1_DAY'], 7 => phpbb::$user->lang['7_DAYS'], 14 => phpbb::$user->lang['2_WEEKS'], 30 => phpbb::$user->lang['1_MONTH'], 90 => phpbb::$user->lang['3_MONTHS'], 180 => phpbb::$user->lang['6_MONTHS'], 365 => phpbb::$user->lang['1_YEAR']);
  578. $sort_by_text = array('a' => phpbb::$user->lang['AUTHOR'], 't' => phpbb::$user->lang['POST_TIME'], 'tt' => phpbb::$user->lang['TOPIC_TIME'], 'r' => phpbb::$user->lang['REPLIES'], 's' => phpbb::$user->lang['SUBJECT'], 'v' => phpbb::$user->lang['VIEWS']);
  579. $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => ((phpbb::$acl->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views');
  580. $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
  581. break;
  582. case 'posts':
  583. $limit_days = array(0 => phpbb::$user->lang['ALL_POSTS'], 1 => phpbb::$user->lang['1_DAY'], 7 => phpbb::$user->lang['7_DAYS'], 14 => phpbb::$user->lang['2_WEEKS'], 30 => phpbb::$user->lang['1_MONTH'], 90 => phpbb::$user->lang['3_MONTHS'], 180 => phpbb::$user->lang['6_MONTHS'], 365 => phpbb::$user->lang['1_YEAR']);
  584. $sort_by_text = array('a' => phpbb::$user->lang['AUTHOR'], 't' => phpbb::$user->lang['POST_TIME'], 's' => phpbb::$user->lang['SUBJECT']);
  585. $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
  586. $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
  587. break;
  588. case 'reports':
  589. $limit_days = array(0 => phpbb::$user->lang['ALL_REPORTS'], 1 => phpbb::$user->lang['1_DAY'], 7 => phpbb::$user->lang['7_DAYS'], 14 => phpbb::$user->lang['2_WEEKS'], 30 => phpbb::$user->lang['1_MONTH'], 90 => phpbb::$user->lang['3_MONTHS'], 180 => phpbb::$user->lang['6_MONTHS'], 365 => phpbb::$user->lang['1_YEAR']);
  590. $sort_by_text = array('a' => phpbb::$user->lang['AUTHOR'], 'r' => phpbb::$user->lang['REPORTER'], 'p' => phpbb::$user->lang['POST_TIME'], 't' => phpbb::$user->lang['REPORT_TIME'], 's' => phpbb::$user->lang['SUBJECT']);
  591. $sort_by_sql = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.post_time', 't' => 'r.report_time', 's' => 'p.post_subject');
  592. break;
  593. case 'logs':
  594. $limit_days = array(0 => phpbb::$user->lang['ALL_ENTRIES'], 1 => phpbb::$user->lang['1_DAY'], 7 => phpbb::$user->lang['7_DAYS'], 14 => phpbb::$user->lang['2_WEEKS'], 30 => phpbb::$user->lang['1_MONTH'], 90 => phpbb::$user->lang['3_MONTHS'], 180 => phpbb::$user->lang['6_MONTHS'], 365 => phpbb::$user->lang['1_YEAR']);
  595. $sort_by_text = array('u' => phpbb::$user->lang['SORT_USERNAME'], 't' => phpbb::$user->lang['SORT_DATE'], 'i' => phpbb::$user->lang['SORT_IP'], 'o' => phpbb::$user->lang['SORT_ACTION']);
  596. $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  597. $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
  598. break;
  599. }
  600. if (!isset($sort_by_sql[$sort_key]))
  601. {
  602. $sort_key = $default_key;
  603. }
  604. $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  605. $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
  606. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url);
  607. phpbb::$template->assign_vars(array(
  608. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  609. 'S_SELECT_SORT_KEY' => $s_sort_key,
  610. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  611. ));
  612. if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts')) || $where_sql != 'WHERE')
  613. {
  614. $result = phpbb::$db->sql_query($sql);
  615. $total = (int) phpbb::$db->sql_fetchfield('total');
  616. phpbb::$db->sql_freeresult($result);
  617. }
  618. else
  619. {
  620. $total = -1;
  621. }
  622. }
  623. /**
  624. * Validate ids
  625. *
  626. * @param array &$ids The relevant ids to check
  627. * @param string $table The table to find the ids in
  628. * @param string $sql_id The ids relevant column name
  629. * @param array $acl_list A list of permissions the user need to have
  630. * @param mixed $singe_forum Limit to one forum id (int) or the first forum found (true)
  631. *
  632. * @return mixed False if no ids were able to be retrieved, true if at least one id left.
  633. * Additionally, this value can be the forum_id assigned if $single_forum was set.
  634. * Therefore checking the result for with !== false is the best method.
  635. */
  636. function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false)
  637. {
  638. if (!is_array($ids) || empty($ids))
  639. {
  640. return false;
  641. }
  642. $sql = "SELECT $sql_id, forum_id FROM $table
  643. WHERE " . phpbb::$db->sql_in_set($sql_id, $ids);
  644. $result = phpbb::$db->sql_query($sql);
  645. $ids = array();
  646. $forum_id = false;
  647. while ($row = phpbb::$db->sql_fetchrow($result))
  648. {
  649. if ($acl_list && $row['forum_id'] && !phpbb::$acl->acl_gets($acl_list, $row['forum_id']))
  650. {
  651. continue;
  652. }
  653. if ($acl_list && !$row['forum_id'] && !phpbb::$acl->acl_getf_global($acl_list))
  654. {
  655. continue;
  656. }
  657. // Limit forum? If not, just assign the id.
  658. if ($single_forum === false)
  659. {
  660. $ids[] = $row[$sql_id];
  661. continue;
  662. }
  663. // Limit forum to a specific forum id?
  664. // This can get really tricky, because we do not want to create a failure on global topics. :)
  665. if ($row['forum_id'])
  666. {
  667. if ($single_forum !== true && $row['forum_id'] == (int) $single_forum)
  668. {
  669. $forum_id = (int) $single_forum;
  670. }
  671. else if ($forum_id === false)
  672. {
  673. $forum_id = $row['forum_id'];
  674. }
  675. if ($row['forum_id'] == $forum_id)
  676. {
  677. $ids[] = $row[$sql_id];
  678. }
  679. }
  680. else
  681. {
  682. // Always add a global topic
  683. $ids[] = $row[$sql_id];
  684. }
  685. }
  686. phpbb::$db->sql_freeresult($result);
  687. if (!sizeof($ids))
  688. {
  689. return false;
  690. }
  691. // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id)
  692. return ($single_forum === false) ? true : (int) $forum_id;
  693. }
  694. ?>