[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/tools/ -> modlog.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  $page->add_breadcrumb_item($lang->mod_logs, "index.php?module=tools-modlog");
  19  
  20  $sub_tabs['mod_logs'] = array(
  21      'title' => $lang->mod_logs,
  22      'link' => "index.php?module=tools-modlog",
  23      'description' => $lang->mod_logs_desc
  24  );
  25  $sub_tabs['prune_mod_logs'] = array(
  26      'title' => $lang->prune_mod_logs,
  27      'link' => "index.php?module=tools-modlog&amp;action=prune",
  28      'description' => $lang->prune_mod_logs_desc
  29  );
  30  
  31  $plugins->run_hooks("admin_tools_modlog_begin");
  32  
  33  if($mybb->input['action'] == 'prune')
  34  {
  35      $plugins->run_hooks("admin_tools_modlog_prune");
  36  
  37      if($mybb->request_method == 'post')
  38      {
  39          $where = 'dateline < '.(TIME_NOW-(intval($mybb->input['older_than'])*86400));
  40  
  41          // Searching for entries by a particular user
  42          if($mybb->input['uid'])
  43          {
  44              $where .= " AND uid='".intval($mybb->input['uid'])."'";
  45          }
  46  
  47          // Searching for entries in a specific module
  48          if($mybb->input['fid'] > 0)
  49          {
  50              $where .= " AND fid='".$db->escape_string($mybb->input['fid'])."'";
  51          }
  52          else
  53          {
  54              $mybb->input['fid'] = 0;
  55          }
  56  
  57          $db->delete_query("moderatorlog", $where);
  58          $num_deleted = $db->affected_rows();
  59  
  60          $plugins->run_hooks("admin_tools_modlog_prune_commit");
  61  
  62          if(!is_array($forum_cache))
  63          {
  64              $forum_cache = cache_forums();
  65          }
  66  
  67          // Log admin action
  68          log_admin_action($mybb->input['older_than'], $mybb->input['uid'], $mybb->input['fid'], $num_deleted, $forum_cache[$mybb->input['fid']]['name']);
  69  
  70          flash_message($lang->success_pruned_mod_logs, 'success');
  71          admin_redirect("index.php?module=tools-modlog");
  72      }
  73      $page->add_breadcrumb_item($lang->prune_mod_logs, "index.php?module=tools-modlog&amp;action=prune");
  74      $page->output_header($lang->prune_mod_logs);
  75      $page->output_nav_tabs($sub_tabs, 'prune_mod_logs');
  76  
  77      // Fetch filter options
  78      $sortbysel[$mybb->input['sortby']] = 'selected="selected"';
  79      $ordersel[$mybb->input['order']] = 'selected="selected"';
  80  
  81      $user_options[''] = $lang->all_moderators;
  82      $user_options['0'] = '----------';
  83  
  84      $query = $db->query("
  85          SELECT DISTINCT l.uid, u.username
  86          FROM ".TABLE_PREFIX."moderatorlog l
  87          LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
  88          ORDER BY u.username ASC
  89      ");
  90      while($user = $db->fetch_array($query))
  91      {
  92          $user_options[$user['uid']] = $user['username'];
  93      }
  94  
  95      $form = new Form("index.php?module=tools-modlog&amp;action=prune", "post");
  96      $form_container = new FormContainer($lang->prune_moderator_logs);
  97      $form_container->output_row($lang->forum, "", $form->generate_forum_select('fid', $mybb->input['fid'], array('id' => 'fid', 'main_option' => $lang->all_forums)), 'fid');
  98      $form_container->output_row($lang->forum_moderator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
  99      if(!$mybb->input['older_than'])
 100      {
 101          $mybb->input['older_than'] = '30';
 102      }
 103      $form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_text_box('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 30px')).' '.$lang->days, 'older_than');
 104      $form_container->end();
 105      $buttons[] = $form->generate_submit_button($lang->prune_moderator_logs);
 106      $form->output_submit_wrapper($buttons);
 107      $form->end();
 108  
 109      $page->output_footer();
 110  }
 111  
 112  if(!$mybb->input['action'])
 113  {
 114      $plugins->run_hooks("admin_tools_modlog_start");
 115  
 116      $page->output_header($lang->mod_logs);
 117  
 118      $page->output_nav_tabs($sub_tabs, 'mod_logs');
 119  
 120      $perpage = intval($mybb->input['perpage']);
 121      if(!$perpage)
 122      {
 123          $perpage = $mybb->settings['threadsperpage'];
 124      }
 125  
 126      $where = 'WHERE 1=1';
 127  
 128      // Searching for entries by a particular user
 129      if($mybb->input['uid'])
 130      {
 131          $where .= " AND l.uid='".intval($mybb->input['uid'])."'";
 132      }
 133  
 134      // Searching for entries in a specific forum
 135      if($mybb->input['fid'] > 0)
 136      {
 137          $where .= " AND l.fid='".intval($mybb->input['fid'])."'";
 138      }
 139  
 140      // Order?
 141      switch($mybb->input['sortby'])
 142      {
 143          case "username":
 144              $sortby = "u.username";
 145              break;
 146          case "forum":
 147              $sortby = "f.name";
 148              break;
 149          case "thread":
 150              $sortby = "t.subject";
 151              break;
 152          default:
 153              $sortby = "l.dateline";
 154      }
 155      $order = $mybb->input['order'];
 156      if($order != "asc")
 157      {
 158          $order = "desc";
 159      }
 160  
 161      $query = $db->query("
 162          SELECT COUNT(l.dateline) AS count
 163          FROM ".TABLE_PREFIX."moderatorlog l
 164          {$where}
 165      ");
 166      $rescount = $db->fetch_field($query, "count");
 167  
 168      // Figure out if we need to display multiple pages.
 169      if($mybb->input['page'] != "last")
 170      {
 171          $pagecnt = intval($mybb->input['page']);
 172      }
 173  
 174      $postcount = intval($rescount);
 175      $pages = $postcount / $perpage;
 176      $pages = ceil($pages);
 177  
 178      if($mybb->input['page'] == "last")
 179      {
 180          $pagecnt = $pages;
 181      }
 182  
 183      if($pagecnt > $pages)
 184      {
 185          $pagecnt = 1;
 186      }
 187  
 188      if($pagecnt)
 189      {
 190          $start = ($pagecnt-1) * $perpage;
 191      }
 192      else
 193      {
 194          $start = 0;
 195          $pagecnt = 1;
 196      }
 197  
 198      $table = new Table;
 199      $table->construct_header($lang->username, array('width' => '10%'));
 200      $table->construct_header($lang->date, array("class" => "align_center", 'width' => '15%'));
 201      $table->construct_header($lang->action, array("class" => "align_center", 'width' => '35%'));
 202      $table->construct_header($lang->information, array("class" => "align_center", 'width' => '30%'));
 203      $table->construct_header($lang->ipaddress, array("class" => "align_center", 'width' => '10%'));
 204  
 205      $query = $db->query("
 206          SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject
 207          FROM ".TABLE_PREFIX."moderatorlog l
 208          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
 209          LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
 210          LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid)
 211          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid)
 212          {$where}
 213          ORDER BY {$sortby} {$order}
 214          LIMIT {$start}, {$perpage}
 215      ");
 216      while($logitem = $db->fetch_array($query))
 217      {
 218          $information = '';
 219          $logitem['action'] = htmlspecialchars_uni($logitem['action']);
 220          $logitem['dateline'] = date("jS M Y, G:i", $logitem['dateline']);
 221          $trow = alt_trow();
 222          $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']);
 223          $logitem['profilelink'] = build_profile_link($username, $logitem['uid'], "_blank");
 224          if($logitem['tsubject'])
 225          {
 226              $information = "<strong>{$lang->thread}</strong> <a href=\"../".get_thread_link($logitem['tid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['tsubject'])."</a><br />";
 227          }
 228          if($logitem['fname'])
 229          {
 230              $information .= "<strong>{$lang->forum}</strong> <a href=\"../".get_forum_link($logitem['fid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['fname'])."</a><br />";
 231          }
 232          if($logitem['psubject'])
 233          {
 234              $information .= "<strong>{$lang->post}</strong> <a href=\"../".get_post_link($logitem['pid'])."#pid{$logitem['pid']}\" target=\"_blank\">".htmlspecialchars_uni($logitem['psubject'])."</a>";
 235          }
 236  
 237          if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject'])
 238          {
 239              $data = unserialize($logitem['data']);
 240              if($data['uid'])
 241              {
 242                  $information = $lang->user_info." <a href=\"../".get_profile_link($data['uid'])."\" target=\"_blank\">".htmlspecialchars_uni($data['username'])."</a>";
 243              }
 244          }
 245  
 246          $table->construct_cell($logitem['profilelink']);
 247          $table->construct_cell($logitem['dateline'], array("class" => "align_center"));
 248          $table->construct_cell($logitem['action'], array("class" => "align_center"));
 249          $table->construct_cell($information);
 250          $table->construct_cell($logitem['ipaddress'], array("class" => "align_center"));
 251          $table->construct_row();
 252      }
 253  
 254      if($table->num_rows() == 0)
 255      {
 256          $table->construct_cell($lang->no_modlogs, array("colspan" => "5"));
 257          $table->construct_row();
 258      }
 259  
 260      $table->output($lang->mod_logs);
 261  
 262      // Do we need to construct the pagination?
 263      if($rescount > $perpage)
 264      {
 265          echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-modlog&amp;perpage=$perpage&amp;uid={$mybb->input['uid']}&amp;fid={$mybb->input['fid']}&amp;sortby={$mybb->input['sortby']}&amp;order={$order}")."<br />";
 266      }
 267  
 268      // Fetch filter options
 269      $sortbysel[$mybb->input['sortby']] = "selected=\"selected\"";
 270      $ordersel[$mybb->input['order']] = "selected=\"selected\"";
 271  
 272      $user_options[''] = $lang->all_moderators;
 273      $user_options['0'] = '----------';
 274  
 275      $query = $db->query("
 276          SELECT DISTINCT l.uid, u.username
 277          FROM ".TABLE_PREFIX."moderatorlog l
 278          LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
 279          ORDER BY u.username ASC
 280      ");
 281      while($user = $db->fetch_array($query))
 282      {
 283          $selected = '';
 284          if($mybb->input['uid'] == $user['uid'])
 285          {
 286              $selected = "selected=\"selected\"";
 287          }
 288          $user_options[$user['uid']] = $user['username'];
 289      }
 290  
 291      $sort_by = array(
 292          'dateline' => $lang->date,
 293          'username' => $lang->username,
 294          'forum' => $lang->forum_name,
 295          'thread' => $lang->thread_subject
 296      );
 297  
 298      $order_array = array(
 299          'asc' => $lang->asc,
 300          'desc' => $lang->desc
 301      );
 302  
 303      $form = new Form("index.php?module=tools-modlog", "post");
 304      $form_container = new FormContainer($lang->filter_moderator_logs);
 305      $form_container->output_row($lang->forum, "", $form->generate_forum_select('fid', $mybb->input['fid'], array('id' => 'fid', 'main_option' => $lang->all_forums)), 'fid');
 306      $form_container->output_row($lang->forum_moderator, "", $form->generate_select_box('uid', $user_options, $mybb->input['uid'], array('id' => 'uid')), 'uid');
 307      $form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order');
 308      $form_container->output_row($lang->results_per_page, "", $form->generate_text_box('perpage', $perpage, array('id' => 'perpage')), 'perpage');
 309  
 310      $form_container->end();
 311      $buttons[] = $form->generate_submit_button($lang->filter_moderator_logs);
 312      $form->output_submit_wrapper($buttons);
 313      $form->end();
 314  
 315      $page->output_footer();
 316  }
 317  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1