Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

mcp.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 21.03 KiB


001  <?php
002  /**
003  *
004  * @package mcp
005  * @version $Id$
006  * @copyright (c) 2005 phpBB Group
007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008  *
009  */
010   
011  /**
012  * @ignore
013  */
014  define('IN_PHPBB', true);
015  $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
016  $phpEx = substr(strrchr(__FILE__, '.'), 1);
017  include($phpbb_root_path . 'common.' . $phpEx);
018  include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
019  require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
020   
021  // Start session management
022  $user->session_begin();
023  $auth->acl($user->data);
024  $user->setup('mcp');
025   
026  $module = new p_master();
027   
028  // Setting a variable to let the style designer know where he is...
029  $template->assign_var('S_IN_MCP', true);
030   
031  // Basic parameter data
032  $id = request_var('i', '');
033   
034  if (isset($_REQUEST['mode']) && is_array($_REQUEST['mode']))
035  {
036      $mode = request_var('mode', array(''));
037      list($mode, ) = each($mode);
038  }
039  else
040  {
041      $mode = request_var('mode', '');
042  }
043   
044  // Only Moderators can go beyond this point
045  if (!$user->data['is_registered'])
046  {
047      if ($user->data['is_bot'])
048      {
049          redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
050      }
051   
052      login_box('', $user->lang['LOGIN_EXPLAIN_MCP']);
053  }
054   
055  $quickmod = (isset($_REQUEST['quickmod'])) ? true : false;
056  $action = request_var('action', '');
057  $action_ary = request_var('action', array('' => 0));
058   
059  $forum_action = request_var('forum_action', '');
060  if ($forum_action !== '' && !empty($_POST['sort']))
061  {
062      $action = $forum_action;
063  }
064   
065  if (sizeof($action_ary))
066  {
067      list($action, ) = each($action_ary);
068  }
069  unset($action_ary);
070   
071  if ($mode == 'topic_logs')
072  {
073      $id = 'logs';
074      $quickmod = false;
075  }
076   
077  $post_id = request_var('p', 0);
078  $topic_id = request_var('t', 0);
079  $forum_id = request_var('f', 0);
080  $user_id = request_var('u', 0);
081  $username = utf8_normalize_nfc(request_var('username', '', true));
082   
083  if ($post_id)
084  {
085      // We determine the topic and forum id here, to make sure the moderator really has moderative rights on this post
086      $sql = 'SELECT topic_id, forum_id
087          FROM ' . POSTS_TABLE . "
088          WHERE post_id = $post_id";
089      $result = $db->sql_query($sql);
090      $row = $db->sql_fetchrow($result);
091      $db->sql_freeresult($result);
092   
093      $topic_id = (int) $row['topic_id'];
094      $forum_id = (int) ($row['forum_id']) ? $row['forum_id'] : $forum_id;
095  }
096  else if ($topic_id)
097  {
098      $sql = 'SELECT forum_id
099          FROM ' . TOPICS_TABLE . "
100          WHERE topic_id = $topic_id";
101      $result = $db->sql_query($sql);
102      $row = $db->sql_fetchrow($result);
103      $db->sql_freeresult($result);
104   
105      $forum_id = (int) $row['forum_id'];
106  }
107   
108  // If the user doesn't have any moderator powers (globally or locally) he can't access the mcp
109  if (!$auth->acl_getf_global('m_'))
110  {
111      // Except he is using one of the quickmod tools for users
112      $user_quickmod_actions = array(
113          'lock'            => 'f_user_lock',
114          'make_sticky'    => 'f_sticky',
115          'make_announce'    => 'f_announce',
116          'make_global'    => 'f_announce',
117          'make_normal'    => array('f_announce', 'f_sticky')
118      );
119   
120      $allow_user = false;
121      if ($quickmod && isset($user_quickmod_actions[$action]) && $user->data['is_registered'] && $auth->acl_gets($user_quickmod_actions[$action], $forum_id))
122      {
123          $topic_info = get_topic_data(array($topic_id));
124          if ($topic_info[$topic_id]['topic_poster'] == $user->data['user_id'])
125          {
126              $allow_user = true;
127          }
128      }
129   
130      if (!$allow_user)
131      {
132          trigger_error('NOT_AUTHORISED');
133      }
134  }
135   
136  // if the user cannot read the forum he tries to access then we won't allow mcp access either
137  if ($forum_id && !$auth->acl_get('f_read', $forum_id))
138  {
139      trigger_error('NOT_AUTHORISED');
140  }
141   
142  if ($forum_id)
143  {
144      $module->acl_forum_id = $forum_id;
145  }
146   
147  // Instantiate module system and generate list of available modules
148  $module->list_modules('mcp');
149   
150  if ($quickmod)
151  {
152      $mode = 'quickmod';
153   
154      switch ($action)
155      {
156          case 'lock':
157          case 'unlock':
158          case 'lock_post':
159          case 'unlock_post':
160          case 'make_sticky':
161          case 'make_announce':
162          case 'make_global':
163          case 'make_normal':
164          case 'fork':
165          case 'move':
166          case 'delete_post':
167          case 'delete_topic':
168              $module->load('mcp', 'main', 'quickmod');
169              exit_handler();
170          break;
171   
172          case 'topic_logs':
173              $module->set_active('logs', 'topic_logs');
174          break;
175   
176          case 'merge_topic':
177              $module->set_active('main', 'forum_view');
178          break;
179   
180          case 'split':
181          case 'merge':
182              $module->set_active('main', 'topic_view');
183          break;
184   
185          default:
186              trigger_error("$action not allowed as quickmod");
187      }
188  }
189  else
190  {
191      // Select the active module
192      $module->set_active($id, $mode);
193  }
194   
195  // Hide some of the options if we don't have the relevant information to use them
196  if (!$post_id)
197  {
198      $module->set_display('main', 'post_details', false);
199      $module->set_display('warn', 'warn_post', false);
200  }
201   
202  if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts')
203  {
204      $module->set_display('queue', 'approve_details', false);
205  }
206   
207  if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed')
208  {
209      $module->set_display('reports', 'report_details', false);
210  }
211   
212  if (!$topic_id)
213  {
214      $module->set_display('main', 'topic_view', false);
215      $module->set_display('logs', 'topic_logs', false);
216  }
217   
218  if (!$forum_id)
219  {
220      $module->set_display('main', 'forum_view', false);
221      $module->set_display('logs', 'forum_logs', false);
222  }
223   
224  if (!$user_id && $username == '')
225  {
226      $module->set_display('notes', 'user_notes', false);
227      $module->set_display('warn', 'warn_user', false);
228  }
229   
230  // Load and execute the relevant module
231  $module->load_active();
232   
233  // Assign data to the template engine for the list of modules
234  $module->assign_tpl_vars(append_sid("{$phpbb_root_path}mcp.$phpEx"));
235   
236  // Generate urls for letting the moderation control panel being accessed in different modes
237  $template->assign_vars(array(
238      'U_MCP'            => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main'),
239      'U_MCP_FORUM'    => ($forum_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=forum_view&amp;f=$forum_id") : '',
240      'U_MCP_TOPIC'    => ($forum_id && $topic_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;t=$topic_id") : '',
241      'U_MCP_POST'    => ($forum_id && $topic_id && $post_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;t=$topic_id&amp;p=$post_id") : '',
242  ));
243   
244  // Generate the page, do not display/query online list
245  $module->display($module->get_page_title(), false);
246   
247  /**
248  * Functions used to generate additional URL paramters
249  */
250  function _module__url($mode, &$module_row)
251  {
252      return extra_url();
253  }
254   
255  function _module_notes_url($mode, &$module_row)
256  {
257      if ($mode == 'front')
258      {
259          return '';
260      }
261   
262      global $user_id;
263      return ($user_id) ? "&amp;u=$user_id" : '';
264  }
265   
266  function _module_warn_url($mode, &$module_row)
267  {
268      if ($mode == 'front' || $mode == 'list')
269      {
270          global $forum_id;
271   
272          return ($forum_id) ? "&amp;f=$forum_id" : '';
273      }
274   
275      if ($mode == 'warn_post')
276      {
277          global $forum_id, $post_id;
278   
279          $url_extra = ($forum_id) ? "&amp;f=$forum_id" : '';
280          $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
281   
282          return $url_extra;
283      }
284      else
285      {
286          global $user_id;
287   
288          return ($user_id) ? "&amp;u=$user_id" : '';
289      }
290  }
291   
292  function _module_main_url($mode, &$module_row)
293  {
294      return extra_url();
295  }
296   
297  function _module_logs_url($mode, &$module_row)
298  {
299      return extra_url();
300  }
301   
302  function _module_ban_url($mode, &$module_row)
303  {
304      return extra_url();
305  }
306   
307  function _module_queue_url($mode, &$module_row)
308  {
309      return extra_url();
310  }
311   
312  function _module_reports_url($mode, &$module_row)
313  {
314      return extra_url();
315  }
316   
317  function extra_url()
318  {
319      global $forum_id, $topic_id, $post_id, $user_id;
320   
321      $url_extra = '';
322      $url_extra .= ($forum_id) ? "&amp;f=$forum_id" : '';
323      $url_extra .= ($topic_id) ? "&amp;t=$topic_id" : '';
324      $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
325      $url_extra .= ($user_id) ? "&amp;u=$user_id" : '';
326   
327      return $url_extra;
328  }
329   
330  /**
331  * Get simple topic data
332  */
333  function get_topic_data($topic_ids, $acl_list = false, $read_tracking = false)
334  {
335      global $auth, $db, $config, $user;
336      static $rowset = array();
337   
338      $topics = array();
339   
340      if (!sizeof($topic_ids))
341      {
342          return array();
343      }
344   
345      // cache might not contain read tracking info, so we can't use it if read
346      // tracking information is requested
347      if (!$read_tracking)
348      {
349          $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
350          $topic_ids = array_diff($topic_ids, array_keys($rowset));
351      }
352      else
353      {
354          $cache_topic_ids = array();
355      }
356   
357      if (sizeof($topic_ids))
358      {
359          $sql_array = array(
360              'SELECT'    => 't.*, f.*',
361   
362              'FROM'        => array(
363                  TOPICS_TABLE    => 't',
364              ),
365   
366              'LEFT_JOIN'    => array(
367                  array(
368                      'FROM'    => array(FORUMS_TABLE => 'f'),
369                      'ON'    => 'f.forum_id = t.forum_id'
370                  )
371              ),
372   
373              'WHERE'        => $db->sql_in_set('t.topic_id', $topic_ids)
374          );
375   
376          if ($read_tracking && $config['load_db_lastread'])
377          {
378              $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
379   
380              $sql_array['LEFT_JOIN'][] = array(
381                  'FROM'    => array(TOPICS_TRACK_TABLE => 'tt'),
382                  'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
383              );
384   
385              $sql_array['LEFT_JOIN'][] = array(
386                  'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
387                  'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
388              );
389          }
390   
391          $sql = $db->sql_build_query('SELECT', $sql_array);
392          $result = $db->sql_query($sql);
393      
394          while ($row = $db->sql_fetchrow($result))
395          {
396              if (!$row['forum_id'])
397              {
398                  // Global Announcement?
399                  $row['forum_id'] = request_var('f', 0);
400              }
401   
402              $rowset[$row['topic_id']] = $row;
403   
404              if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
405              {
406                  continue;
407              }
408   
409              $topics[$row['topic_id']] = $row;
410          }
411          $db->sql_freeresult($result);
412      }
413   
414      foreach ($cache_topic_ids as $id)
415      {
416          if (!$acl_list || $auth->acl_gets($acl_list, $rowset[$id]['forum_id']))
417          {
418              $topics[$id] = $rowset[$id];
419          }
420      }
421   
422      return $topics;
423  }
424   
425  /**
426  * Get simple post data
427  */
428  function get_post_data($post_ids, $acl_list = false, $read_tracking = false)
429  {
430      global $db, $auth, $config, $user;
431   
432      $rowset = array();
433   
434      if (!sizeof($post_ids))
435      {
436          return array();
437      }
438   
439      $sql_array = array(
440          'SELECT'    => 'p.*, u.*, t.*, f.*',
441   
442          'FROM'        => array(
443              USERS_TABLE        => 'u',
444              POSTS_TABLE        => 'p',
445              TOPICS_TABLE    => 't',
446          ),
447   
448          'LEFT_JOIN'    => array(
449              array(
450                  'FROM'    => array(FORUMS_TABLE => 'f'),
451                  'ON'    => 'f.forum_id = t.forum_id'
452              )
453          ),
454   
455          'WHERE'        => $db->sql_in_set('p.post_id', $post_ids) . '
456              AND u.user_id = p.poster_id
457              AND t.topic_id = p.topic_id',
458      );
459   
460      if ($read_tracking && $config['load_db_lastread'])
461      {
462          $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
463   
464          $sql_array['LEFT_JOIN'][] = array(
465              'FROM'    => array(TOPICS_TRACK_TABLE => 'tt'),
466              'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
467          );
468   
469          $sql_array['LEFT_JOIN'][] = array(
470              'FROM'    => array(FORUMS_TRACK_TABLE => 'ft'),
471              'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
472          );
473      }
474   
475      $sql = $db->sql_build_query('SELECT', $sql_array);
476      $result = $db->sql_query($sql);
477      unset($sql_array);
478   
479      while ($row = $db->sql_fetchrow($result))
480      {
481          if (!$row['forum_id'])
482          {
483              // Global Announcement?
484              $row['forum_id'] = request_var('f', 0);
485          }
486   
487          if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
488          {
489              continue;
490          }
491   
492          if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
493          {
494              // Moderators without the permission to approve post should at least not see them. ;)
495              continue;
496          }
497   
498          $rowset[$row['post_id']] = $row;
499      }
500      $db->sql_freeresult($result);
501   
502      return $rowset;
503  }
504   
505  /**
506  * Get simple forum data
507  */
508  function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false)
509  {
510      global $auth, $db, $user, $config;
511   
512      $rowset = array();
513   
514      if (!is_array($forum_id))
515      {
516          $forum_id = array($forum_id);
517      }
518   
519      if (!sizeof($forum_id))
520      {
521          return array();
522      }
523   
524      if ($read_tracking && $config['load_db_lastread'])
525      {
526          $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
527              AND ft.forum_id = f.forum_id)';
528          $read_tracking_select = ', ft.mark_time';
529      }
530      else
531      {
532          $read_tracking_join = $read_tracking_select = '';
533      }
534   
535      $sql = "SELECT f.* $read_tracking_select
536          FROM " . FORUMS_TABLE . " f$read_tracking_join
537          WHERE " . $db->sql_in_set('f.forum_id', $forum_id);
538      $result = $db->sql_query($sql);
539   
540      while ($row = $db->sql_fetchrow($result))
541      {
542          if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
543          {
544              continue;
545          }
546   
547          if ($auth->acl_get('m_approve', $row['forum_id']))
548          {
549              $row['forum_topics'] = $row['forum_topics_real'];
550          }
551   
552          $rowset[$row['forum_id']] = $row;
553      }
554      $db->sql_freeresult($result);
555   
556      return $rowset;
557  }
558   
559  /**
560  * sorting in mcp
561  *
562  * @param string $where_sql should either be WHERE (default if ommited) or end with AND or OR
563  */
564  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')
565  {
566      global $db, $user, $auth, $template;
567   
568      $sort_days = request_var('st', 0);
569      $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0;
570   
571      switch ($mode)
572      {
573          case 'viewforum':
574              $type = 'topics';
575              $default_key = 't';
576              $default_dir = 'd';
577   
578              $sql = 'SELECT COUNT(topic_id) AS total
579                  FROM ' . TOPICS_TABLE . "
580                  $where_sql forum_id = $forum_id
581                      AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
582                      AND topic_last_post_time >= $min_time";
583   
584              if (!$auth->acl_get('m_approve', $forum_id))
585              {
586                  $sql .= 'AND topic_approved = 1';
587              }
588          break;
589   
590          case 'viewtopic':
591              $type = 'posts';
592              $default_key = 't';
593              $default_dir = 'a';
594   
595              $sql = 'SELECT COUNT(post_id) AS total
596                  FROM ' . POSTS_TABLE . "
597                  $where_sql topic_id = $topic_id
598                      AND post_time >= $min_time";
599   
600              if (!$auth->acl_get('m_approve', $forum_id))
601              {
602                  $sql .= 'AND post_approved = 1';
603              }
604          break;
605   
606          case 'unapproved_posts':
607              $type = 'posts';
608              $default_key = 't';
609              $default_dir = 'd';
610              $where_sql .= ($topic_id) ? ' topic_id = ' . $topic_id . ' AND' : '';
611   
612              $sql = 'SELECT COUNT(post_id) AS total
613                  FROM ' . POSTS_TABLE . "
614                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . '
615                      AND post_approved = 0';
616   
617              if ($min_time)
618              {
619                  $sql .= ' AND post_time >= ' . $min_time;
620              }
621          break;
622   
623          case 'unapproved_topics':
624              $type = 'topics';
625              $default_key = 't';
626              $default_dir = 'd';
627   
628              $sql = 'SELECT COUNT(topic_id) AS total
629                  FROM ' . TOPICS_TABLE . "
630                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . '
631                      AND topic_approved = 0';
632   
633              if ($min_time)
634              {
635                  $sql .= ' AND topic_time >= ' . $min_time;
636              }
637          break;
638   
639          case 'reports':
640          case 'reports_closed':
641              $type = 'reports';
642              $default_key = 't';
643              $default_dir = 'd';
644              $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
645   
646              if ($topic_id)
647              {
648                  $where_sql .= ' p.topic_id = ' . $topic_id;
649              }
650              else if ($forum_id)
651              {
652                  $where_sql .= ' p.forum_id = ' . $forum_id;
653              }
654              else
655              {
656                  $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list('!m_report'), true, true);
657              }
658   
659              if ($mode == 'reports')
660              {
661                  $where_sql .= ' AND r.report_closed = 0';
662              }
663              else
664              {
665                  $where_sql .= ' AND r.report_closed = 1';
666              }
667   
668              $sql = 'SELECT COUNT(r.report_id) AS total
669                  FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
670                  $where_sql
671                      AND p.post_id = r.post_id
672                      $limit_time_sql";
673          break;
674   
675          case 'viewlogs':
676              $type = 'logs';
677              $default_key = 't';
678              $default_dir = 'd';
679   
680              $sql = 'SELECT COUNT(log_id) AS total
681                  FROM ' . LOG_TABLE . "
682                  $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_')) . '
683                      AND log_time >= ' . $min_time . '
684                      AND log_type = ' . LOG_MOD;
685          break;
686      }
687   
688      $sort_key = request_var('sk', $default_key);
689      $sort_dir = request_var('sd', $default_dir);
690      $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
691   
692      switch ($type)
693      {
694          case 'topics':
695              $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
696              $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
697   
698              $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views');
699              $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
700          break;
701   
702          case 'posts':
703              $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
704              $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
705              $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
706              $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
707          break;
708   
709          case 'reports':
710              $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
711              $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']);
712              $sort_by_sql = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.post_time', 't' => 'r.report_time', 's' => 'p.post_subject');
713          break;
714   
715          case 'logs':
716              $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
717              $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
718   
719              $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
720              $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
721          break;
722      }
723   
724      if (!isset($sort_by_sql[$sort_key]))
725      {
726          $sort_key = $default_key;
727      }
728   
729      $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
730   
731      $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
732      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);
733   
734      $template->assign_vars(array(
735          'S_SELECT_SORT_DIR'        => $s_sort_dir,
736          'S_SELECT_SORT_KEY'        => $s_sort_key,
737          'S_SELECT_SORT_DAYS'    => $s_limit_days)
738      );
739   
740      if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts')) || $where_sql != 'WHERE')
741      {
742          $result = $db->sql_query($sql);
743          $total = (int) $db->sql_fetchfield('total');
744          $db->sql_freeresult($result);
745      }
746      else
747      {
748          $total = -1;
749      }
750  }
751   
752  /**
753  * Validate ids
754  *
755  * @param    array    &$ids            The relevant ids to check
756  * @param    string    $table            The table to find the ids in
757  * @param    string    $sql_id            The ids relevant column name
758  * @param    array    $acl_list        A list of permissions the user need to have
759  * @param    mixed    $singe_forum    Limit to one forum id (int) or the first forum found (true)
760  *
761  * @return    mixed    False if no ids were able to be retrieved, true if at least one id left.
762  *                    Additionally, this value can be the forum_id assigned if $single_forum was set.
763  *                    Therefore checking the result for with !== false is the best method.
764  */
765  function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false)
766  {
767      global $db, $auth;
768   
769      if (!is_array($ids) || empty($ids))
770      {
771          return false;
772      }
773   
774      $sql = "SELECT $sql_id, forum_id FROM $table
775          WHERE " . $db->sql_in_set($sql_id, $ids);
776      $result = $db->sql_query($sql);
777   
778      $ids = array();
779      $forum_id = false;
780   
781      while ($row = $db->sql_fetchrow($result))
782      {
783          if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id']))
784          {
785              continue;
786          }
787   
788          if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list))
789          {
790              continue;
791          }
792   
793          // Limit forum? If not, just assign the id.
794          if ($single_forum === false)
795          {
796              $ids[] = $row[$sql_id];
797              continue;
798          }
799   
800          // Limit forum to a specific forum id?
801          // This can get really tricky, because we do not want to create a failure on global topics. :)
802          if ($row['forum_id'])
803          {
804              if ($single_forum !== true && $row['forum_id'] == (int) $single_forum)
805              {
806                  $forum_id = (int) $single_forum;
807              }
808              else if ($forum_id === false)
809              {
810                  $forum_id = $row['forum_id'];
811              }
812   
813              if ($row['forum_id'] == $forum_id)
814              {
815                  $ids[] = $row[$sql_id];
816              }
817          }
818          else
819          {
820              // Always add a global topic
821              $ids[] = $row[$sql_id];
822          }
823      }
824      $db->sql_freeresult($result);
825   
826      if (!sizeof($ids))
827      {
828          return false;
829      }
830   
831      // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id)
832   
833      return ($single_forum === false) ? true : (int) $forum_id;
834  }
835   
836  ?>