[ Index ]

PHP Cross Reference of MyBB 1.8.32

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


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