[ Index ]

PHP Cross Reference of MyBB 1.8.21

title

Body

[close]

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

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


2005 - 2019 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1