[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/tools/ -> warninglog.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->warning_logs, "index.php?module=tools-warninglog");
  19  
  20  $plugins->run_hooks("admin_tools_warninglog_begin");
  21  
  22  // Revoke a warning
  23  if($mybb->input['action'] == "do_revoke" && $mybb->request_method == "post")
  24  {
  25      $plugins->run_hooks("admin_tools_warninglog_do_revoke");
  26  
  27      $query = $db->simple_select("warnings", "*", "wid='".intval($mybb->input['wid'])."'");
  28      $warning = $db->fetch_array($query);
  29  
  30      if(!$warning['wid'])
  31      {
  32          flash_message($lang->error_invalid_warning, 'error');
  33          admin_redirect("index.php?module=tools-warninglog");
  34      }
  35      else if($warning['daterevoked'])
  36      {
  37          flash_message($lang->error_already_revoked, 'error');
  38          admin_redirect("index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
  39      }
  40  
  41      $user = get_user($warning['uid']);
  42  
  43      if(!trim($mybb->input['reason']))
  44      {
  45          $warn_errors[] = $lang->error_no_revoke_reason;
  46          $mybb->input['action'] = "view";
  47      }
  48      else
  49      {
  50          // Warning is still active, lower users point count
  51          if($warning['expired'] != 1)
  52          {
  53              $new_warning_points = $user['warningpoints']-$warning['points'];
  54              if($new_warning_points < 0)
  55              {
  56                  $new_warning_points = 0;
  57              }
  58  
  59              // Update user
  60              $updated_user = array(
  61                  "warningpoints" => $new_warning_points
  62              );
  63              $db->update_query("users", $updated_user, "uid='{$warning['uid']}'");
  64          }
  65  
  66          // Update warning
  67          $updated_warning = array(
  68              "expired" => 1,
  69              "daterevoked" => TIME_NOW,
  70              "revokedby" => $mybb->user['uid'],
  71              "revokereason" => $db->escape_string($mybb->input['reason'])
  72          );
  73          $db->update_query("warnings", $updated_warning, "wid='{$warning['wid']}'");
  74  
  75          $plugins->run_hooks("admin_tools_warninglog_do_revoke_commit");
  76  
  77          flash_message($lang->redirect_warning_revoked, 'success');
  78          admin_redirect("index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
  79      }
  80  }
  81  
  82  // Detailed view of a warning
  83  if($mybb->input['action'] == "view")
  84  {
  85      $plugins->run_hooks("admin_tools_warninglog_view");
  86  
  87      $query = $db->query("
  88          SELECT w.*, t.title AS type_title, u.username, p.subject AS post_subject
  89          FROM ".TABLE_PREFIX."warnings w
  90          LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
  91          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
  92          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=w.pid)
  93          WHERE w.wid='".intval($mybb->input['wid'])."'
  94      ");
  95      $warning = $db->fetch_array($query);
  96  
  97      if(!$warning['wid'])
  98      {
  99          flash_message($lang->error_invalid_warning, 'error');
 100          admin_redirect("index.php?module=tools-warninglog");
 101      }
 102  
 103      $user = get_user(intval($warning['uid']));
 104  
 105      $page->add_breadcrumb_item($lang->warning_details, "index.php?module=tools-warninglog&amp;action=view&amp;wid={$warning['wid']}");
 106  
 107      $page->output_header($lang->warning_details);
 108  
 109      $user_link = build_profile_link($user['username'], $user['uid'], "_blank");
 110  
 111      if(is_array($warn_errors))
 112      {
 113          $page->output_inline_error($warn_errors);
 114          $mybb->input['reason'] = htmlspecialchars_uni($mybb->input['reason']);
 115      }
 116  
 117      $table = new Table;
 118  
 119      $post_link = "";
 120      if($warning['post_subject'])
 121      {
 122          if(!is_object($parser))
 123          {
 124              require_once  MYBB_ROOT."inc/class_parser.php";
 125              $parser = new postParser;
 126          }
 127  
 128          $warning['post_subject'] = $parser->parse_badwords($warning['post_subject']);
 129          $warning['post_subject'] = htmlspecialchars_uni($warning['post_subject']);
 130          $post_link = get_post_link($warning['pid']);
 131          $table->construct_cell("<strong>{$lang->warned_user}</strong><br /><br />{$user_link}");
 132          $table->construct_cell("<strong>{$lang->post}</strong><br /><br /><a href=\"{$mybb->settings['bburl']}/{$post_link}\" target=\"_blank\">{$warning['post_subject']}</a>");
 133          $table->construct_row();
 134      }
 135      else
 136      {
 137          $table->construct_cell("<strong>{$lang->warned_user}</strong><br /><br />{$user_link}", array('colspan' => 2));
 138          $table->construct_row();
 139      }
 140  
 141      $issuedby = build_profile_link($warning['username'], $warning['issuedby'], "_blank");
 142      $notes = nl2br(htmlspecialchars_uni($warning['notes']));
 143  
 144      $date_issued = my_date($mybb->settings['dateformat'], $warning['dateline']).", ".my_date($mybb->settings['timeformat'], $warning['dateline']);
 145      if($warning['type_title'])
 146      {
 147          $warning_type = $warning['type_title'];
 148      }
 149      else
 150      {
 151          $warning_type = $warning['title'];
 152      }
 153      $warning_type = htmlspecialchars_uni($warning_type);
 154      if($warning['points'] > 0)
 155      {
 156          $warning['points'] = "+{$warning['points']}";
 157      }
 158  
 159      $points = $lang->sprintf($lang->warning_points, $warning['points']);
 160      if($warning['expired'] != 1)
 161      {
 162          if($warning['expires'] == 0)
 163          {
 164              $expires = $lang->never;
 165          }
 166          else
 167          {
 168              $expires = my_date($mybb->settings['dateformat'], $warning['expires']).", ".my_date($mybb->settings['timeformat'], $warning['expires']);
 169          }
 170          $status = $lang->warning_active;
 171      }
 172      else
 173      {
 174          if($warning['daterevoked'])
 175          {
 176              $expires = $status = $lang->warning_revoked;
 177          }
 178          else if($warning['expires'])
 179          {
 180              $expires = $status = $lang->already_expired;
 181          }
 182      }
 183  
 184      $table->construct_cell("<strong>{$lang->warning}</strong><br /><br />{$warning_type} {$points}", array('width' => '50%'));
 185      $table->construct_cell("<strong>{$lang->date_issued}</strong><br /><br />{$date_issued}", array('width' => '50%'));
 186      $table->construct_row();
 187  
 188      $table->construct_cell("<strong>{$lang->issued_by}</strong><br /><br />{$issuedby}", array('width' => '50%'));
 189      $table->construct_cell("<strong>{$lang->expires}</strong><br /><br />{$expires}", array('width' => '50%'));
 190      $table->construct_row();
 191  
 192      $table->construct_cell("<strong>{$lang->warning_note}</strong><br /><br />{$notes}", array('colspan' => 2));
 193      $table->construct_row();
 194  
 195      $table->output("<div class=\"float_right\" style=\"font-weight: normal;\">{$status}</div>".$lang->warning_details);
 196  
 197      if(!$warning['daterevoked'])
 198      {
 199          $form = new Form("index.php?module=tools-warninglog", "post");
 200          $form_container = new FormContainer($lang->revoke_warning);
 201          echo $form->generate_hidden_field('action', 'do_revoke');
 202          echo $form->generate_hidden_field('wid', $warning['wid']);
 203          $form_container->output_row("", $lang->revoke_warning_desc, $form->generate_text_area('reason', $mybb->input['reason'], array('id' => 'reason')), 'reason');
 204  
 205          $form_container->end();
 206          $buttons[] = $form->generate_submit_button($lang->revoke_warning);
 207          $form->output_submit_wrapper($buttons);
 208          $form->end();
 209      }
 210      else
 211      {
 212          $date_revoked = my_date($mybb->settings['dateformat'], $warning['daterevoked']).", ".my_date($mybb->settings['timeformat'], $warning['daterevoked']);
 213          $revoked_user = get_user($warning['revokedby']);
 214          $revoked_by = build_profile_link($revoked_user['username'], $revoked_user['uid'], "_blank");
 215          $revoke_reason = nl2br(htmlspecialchars_uni($warning['revokereason']));
 216  
 217          $revoke_table = new Table;
 218          $revoke_table->construct_cell("<strong>{$lang->revoked_by}</strong><br /><br />{$revoked_by}", array('width' => '50%'));
 219          $revoke_table->construct_cell("<strong>{$lang->date_revoked}</strong><br /><br />{$date_revoked}", array('width' => '50%'));
 220          $revoke_table->construct_row();
 221  
 222          $revoke_table->construct_cell("<strong>{$lang->reason}</strong><br /><br />{$revoke_reason}", array('colspan' => 2));
 223          $revoke_table->construct_row();
 224  
 225          $revoke_table->output($lang->warning_is_revoked);
 226      }
 227  
 228      $page->output_footer();
 229  }
 230  
 231  if(!$mybb->input['action'])
 232  {
 233      $plugins->run_hooks("admin_tools_warninglog_start");
 234  
 235      $page->output_header($lang->warning_logs);
 236  
 237      $sub_tabs['warning_logs'] = array(
 238          'title' => $lang->warning_logs,
 239          'link' => "index.php?module=tools-warninglog",
 240          'description' => $lang->warning_logs_desc
 241      );
 242  
 243      $page->output_nav_tabs($sub_tabs, 'warning_logs');
 244  
 245      // Filter options
 246      $where_sql = '';
 247      if($mybb->input['filter']['username'])
 248      {
 249          $search['username'] = $db->escape_string($mybb->input['filter']['username']);
 250          $query = $db->simple_select("users", "uid", "username='{$search['username']}'");
 251          $mybb->input['filter']['uid'] = $db->fetch_field($query, "uid");
 252      }
 253      if($mybb->input['filter']['uid'])
 254      {
 255          $search['uid'] = intval($mybb->input['filter']['uid']);
 256          $where_sql .= " AND w.uid='{$search['uid']}'";
 257          if(!isset($mybb->input['search']['username']))
 258          {
 259              $user = get_user($mybb->input['search']['uid']);
 260              $mybb->input['search']['username'] = $user['username'];
 261          }
 262      }
 263      if($mybb->input['filter']['mod_username'])
 264      {
 265          $search['mod_username'] = $db->escape_string($mybb->input['filter']['mod_username']);
 266          $query = $db->simple_select("users", "uid", "username='{$search['mod_username']}'");
 267          $mybb->input['filter']['mod_uid'] = $db->fetch_field($query, "uid");
 268      }
 269      if($mybb->input['filter']['mod_uid'])
 270      {
 271          $search['mod_uid'] = intval($mybb->input['filter']['mod_uid']);
 272          $where_sql .= " AND w.issuedby='{$search['mod_uid']}'";
 273          if(!isset($mybb->input['search']['mod_username']))
 274          {
 275              $mod_user = get_user($mybb->input['search']['uid']);
 276              $mybb->input['search']['mod_username'] = $mod_user['username'];
 277          }
 278      }
 279      if($mybb->input['filter']['reason'])
 280      {
 281          $search['reason'] = $db->escape_string_like($mybb->input['filter']['reason']);
 282          $where_sql .= " AND (w.notes LIKE '%{$search['reason']}%' OR t.title LIKE '%{$search['reason']}%' OR w.title LIKE '%{$search['reason']}%')";
 283      }
 284      $sortbysel = array();
 285      switch($mybb->input['filter']['sortby'])
 286      {
 287          case "username":
 288              $sortby = "u.username";
 289              $sortbysel['username'] = ' selected="selected"';
 290              break;
 291          case "expires":
 292              $sortby = "w.expires";
 293              $sortbysel['expires'] = ' selected="selected"';
 294              break;
 295          case "issuedby":
 296              $sortby = "i.username";
 297              $sortbysel['issuedby'] = ' selected="selected"';
 298              break;
 299          default: // "dateline"
 300              $sortby = "w.dateline";
 301              $sortbysel['dateline'] = ' selected="selected"';
 302      }
 303      $order = $mybb->input['filter']['order'];
 304      $ordersel = array();
 305      if($order != "asc")
 306      {
 307          $order = "desc";
 308          $ordersel['desc'] = ' selected="selected"';
 309      }
 310      else
 311      {
 312          $ordersel['asc'] = ' selected="selected"';
 313      }
 314  
 315      // Expire any warnings past their expiration date
 316      expire_warnings();
 317  
 318      // Pagination stuff
 319      $sql = "
 320          SELECT COUNT(wid) as count
 321          FROM
 322              ".TABLE_PREFIX."warnings w
 323              LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
 324          WHERE 1=1
 325              {$where_sql}
 326      ";
 327      $query = $db->query($sql);
 328      $total_warnings = $db->fetch_field($query, 'count');
 329      $view_page = 1;
 330      if(isset($mybb->input['page']) && intval($mybb->input['page']) > 0)
 331      {
 332          $view_page = intval($mybb->input['page']);
 333      }
 334      $per_page = 20;
 335      if(isset($mybb->input['filter']['per_page']) && intval($mybb->input['filter']['per_page']) > 0)
 336      {
 337          $per_page = intval($mybb->input['filter']['per_page']);
 338      }
 339      $start = ($view_page-1) * $per_page;
 340      // Build the base URL for pagination links
 341      $url = 'index.php?module=tools-warninglog';
 342      if(is_array($mybb->input['filter']) && count($mybb->input['filter']))
 343      {
 344          foreach($mybb->input['filter'] as $field => $value)
 345          {
 346              $value = urlencode($value);
 347              $url .= "&amp;filter[{$field}]={$value}";
 348          }
 349      }
 350  
 351      // The actual query
 352      $sql = "
 353          SELECT
 354              w.wid, w.title as custom_title, w.points, w.dateline, w.issuedby, w.expires, w.expired, w.daterevoked, w.revokedby,
 355              t.title,
 356              u.uid, u.username, u.usergroup, u.displaygroup,
 357              i.uid as mod_uid, i.username as mod_username, i.usergroup as mod_usergroup, i.displaygroup as mod_displaygroup
 358          FROM ".TABLE_PREFIX."warnings w
 359          LEFT JOIN ".TABLE_PREFIX."users u on (w.uid=u.uid)
 360              LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
 361              LEFT JOIN ".TABLE_PREFIX."users i ON (i.uid=w.issuedby)
 362          WHERE 1=1
 363              {$where_sql}
 364          ORDER BY {$sortby} {$order}
 365          LIMIT {$start}, {$per_page}
 366      ";
 367      $query = $db->query($sql);
 368  
 369  
 370      $table = new Table;
 371      $table->construct_header($lang->warned_user, array('width' => '15%'));
 372      $table->construct_header($lang->warning, array("class" => "align_center", 'width' => '25%'));
 373      $table->construct_header($lang->date_issued, array("class" => "align_center", 'width' => '20%'));
 374      $table->construct_header($lang->expires, array("class" => "align_center", 'width' => '20%'));
 375      $table->construct_header($lang->issued_by, array("class" => "align_center", 'width' => '15%'));
 376      $table->construct_header($lang->options, array("class" => "align_center", 'width' => '5%'));
 377  
 378      while($row = $db->fetch_array($query))
 379      {
 380          if(!$row['username'])
 381          {
 382              $row['username'] = $lang->guest;
 383          }
 384  
 385          $trow = alt_trow();
 386          $username = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
 387          if(!$row['uid'])
 388          {
 389              $username_link = $username;
 390          }
 391          else
 392          {
 393              $username_link = build_profile_link($username, $row['uid'], "_blank");
 394          }
 395          $mod_username = format_name($row['mod_username'], $row['mod_usergroup'], $row['mod_displaygroup']);
 396          $mod_username_link = build_profile_link($mod_username, $row['mod_uid'], "_blank");
 397          $issued_date = my_date($mybb->settings['dateformat'], $row['dateline']).' '.my_date($mybb->settings['timeformat'], $row['dateline']);
 398          $revoked_text = '';
 399          if($row['daterevoked'] > 0)
 400          {
 401              $revoked_date = my_date($mybb->settings['dateformat'], $row['daterevoked']).' '.my_date($mybb->settings['timeformat'], $row['daterevoked']);
 402              $revoked_text = "<br /><small><strong>{$lang->revoked}</strong> {$revoked_date}</small>";
 403          }
 404          if($row['expires'] > 0)
 405          {
 406              $expire_date = my_date($mybb->settings['dateformat'], $row['expires']).' '.my_date($mybb->settings['timeformat'], $row['expires']);
 407          }
 408          else
 409          {
 410              $expire_date = $lang->never;
 411          }
 412          $title = $row['title'];
 413          if(empty($row['title']))
 414          {
 415              $title = $row['custom_title'];
 416          }
 417          $title = htmlspecialchars_uni($title);
 418          if($row['points'] > 0)
 419          {
 420              $points = '+'.$row['points'];
 421          }
 422  
 423          $table->construct_cell($username_link);
 424          $table->construct_cell("{$title} ({$points})");
 425          $table->construct_cell($issued_date, array("class" => "align_center"));
 426          $table->construct_cell($expire_date.$revoked_text, array("class" => "align_center"));
 427          $table->construct_cell($mod_username_link);
 428          $table->construct_cell("<a href=\"index.php?module=tools-warninglog&amp;action=view&amp;wid={$row['wid']}\">{$lang->view}</a>", array("class" => "align_center"));
 429          $table->construct_row();
 430      }
 431  
 432      if($table->num_rows() == 0)
 433      {
 434          $table->construct_cell($lang->no_warning_logs, array("colspan" => "6"));
 435          $table->construct_row();
 436      }
 437  
 438      $table->output($lang->warning_logs);
 439  
 440      // Do we need to construct the pagination?
 441      if($total_warnings > $per_page)
 442      {
 443          echo draw_admin_pagination($view_page, $per_page, $total_warnings, $url)."<br />";
 444      }
 445  
 446      $sort_by = array(
 447          'expires' => $lang->expiry_date,
 448          'dateline' => $lang->issued_date,
 449          'username' => $lang->warned_user,
 450          'issuedby' => $lang->issued_by
 451      );
 452  
 453      $order_array = array(
 454          'asc' => $lang->asc,
 455          'desc' => $lang->desc
 456      );
 457  
 458      $form = new Form("index.php?module=tools-warninglog", "post");
 459      $form_container = new FormContainer($lang->filter_warning_logs);
 460      $form_container->output_row($lang->filter_warned_user, "", $form->generate_text_box('filter[username]', $mybb->input['filter']['username'], array('id' => 'filter_username')), 'filter_username');
 461      $form_container->output_row($lang->filter_issued_by, "", $form->generate_text_box('filter[mod_username]', $mybb->input['filter']['mod_username'], array('id' => 'filter_mod_username')), 'filter_mod_username');
 462      $form_container->output_row($lang->filter_reason, "", $form->generate_text_box('filter[reason]', $mybb->input['filter']['reason'], array('id' => 'filter_reason')), 'filter_reason');
 463      $form_container->output_row($lang->sort_by, "", $form->generate_select_box('filter[sortby]', $sort_by, $mybb->input['filter']['sortby'], array('id' => 'filter_sortby'))." {$lang->in} ".$form->generate_select_box('filter[order]', $order_array, $order, array('id' => 'filter_order'))." {$lang->order}", 'filter_order');
 464      $form_container->output_row($lang->results_per_page, "", $form->generate_text_box('filter[per_page]', $per_page, array('id' => 'filter_per_page')), 'filter_per_page');
 465  
 466      $form_container->end();
 467      $buttons[] = $form->generate_submit_button($lang->filter_warning_logs);
 468      $form->output_submit_wrapper($buttons);
 469      $form->end();
 470  
 471      $page->output_footer();
 472  }
 473  ?>


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