[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/ -> warnings.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  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'warnings.php');
  13  
  14  $templatelist = "warnings,warnings_warn_post,warnings_active_header,warnings_expired_header,warnings_warning,warnings_warn_existing,warnings_warn_type,warnings_warn_custom,warnings_warn_pm,warnings_view";
  15  $templatelist .= ",warnings_view_post,warnings_view_user,warnings_view_revoke,warnings_view_revoked,warnings_warn_type_result,warnings_postlink,codebuttons,warnings_warn,warnings_warn_pm_anonymous";
  16  $templatelist .= ",multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,warnings_no_warnings";
  17  
  18  require_once  "./global.php";
  19  require_once  MYBB_ROOT."inc/functions_warnings.php";
  20  require_once  MYBB_ROOT."inc/functions_modcp.php";
  21  require_once  MYBB_ROOT."inc/class_parser.php";
  22  $parser = new postParser;
  23  
  24  $lang->load("warnings");
  25  $lang->load("datahandler_warnings");
  26  
  27  if($mybb->settings['enablewarningsystem'] == 0)
  28  {
  29      error($lang->error_warning_system_disabled);
  30  }
  31  
  32  // Expire old warnings
  33  require_once  MYBB_ROOT.'inc/datahandlers/warnings.php';
  34  $warningshandler = new WarningsHandler('update');
  35  
  36  $warningshandler->expire_warnings();
  37  
  38  $mybb->input['action'] = $mybb->get_input('action');
  39  
  40  $plugins->run_hooks("warnings_start");
  41  
  42  // Actually warn a user
  43  if($mybb->input['action'] == "do_warn" && $mybb->request_method == "post")
  44  {
  45      // Verify incoming POST request
  46      verify_post_check($mybb->get_input('my_post_key'));
  47  
  48      if($mybb->usergroup['canwarnusers'] != 1)
  49      {
  50          error_no_permission();
  51      }
  52  
  53      $user = get_user($mybb->get_input('uid', MyBB::INPUT_INT));
  54  
  55      if(!$user)
  56      {
  57          error($lang->error_invalid_user);
  58      }
  59  
  60      $group_permissions = user_permissions($user['uid']);
  61  
  62      if($group_permissions['canreceivewarnings'] != 1)
  63      {
  64          error($lang->error_cant_warn_group);
  65      }
  66  
  67      if(!modcp_can_manage_user($user['uid']))
  68      {
  69          error($lang->error_cant_warn_user);
  70      }
  71  
  72      $plugins->run_hooks("warnings_do_warn_start");
  73  
  74      $warning = array(
  75          'uid' => $mybb->get_input('uid', MyBB::INPUT_INT),
  76          'notes' => $mybb->get_input('notes'),
  77          'type' => $mybb->get_input('type'),
  78          'custom_reason' => $mybb->get_input('custom_reason'),
  79          'custom_points' => $mybb->get_input('custom_points', MyBB::INPUT_INT),
  80          'expires' => $mybb->get_input('expires', MyBB::INPUT_INT),
  81          'expires_period' => $mybb->get_input('expires_period')
  82      );
  83  
  84      // Is this warning being given for a post?
  85      if($mybb->get_input('pid', MyBB::INPUT_INT))
  86      {
  87          $warning['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
  88  
  89          $post = get_post($warning['pid']);
  90  
  91          $forum_permissions = forum_permissions($post['fid']);
  92  
  93          if($forum_permissions['canview'] != 1)
  94          {
  95              error_no_permission();
  96          }
  97      }
  98  
  99      $warningshandler->set_data($warning);
 100  
 101      if($warningshandler->validate_warning())
 102      {
 103          $warninginfo = $warningshandler->insert_warning();
 104  
 105          // Are we notifying the user?
 106          if($mybb->get_input('send_pm', MyBB::INPUT_INT) == 1 && $group_permissions['canusepms'] != 0 && $mybb->settings['enablepms'] != 0)
 107          {
 108  
 109              $pm = array(
 110                  'subject' => $mybb->get_input('pm_subject'),
 111                  'message' => $mybb->get_input('pm_message'),
 112                  'touid' => $user['uid']
 113              );
 114  
 115              $sender_uid = $mybb->user['uid'];
 116              if($mybb->settings['allowanonwarningpms'] == 1 && $mybb->get_input('pm_anonymous', MyBB::INPUT_INT))
 117              {
 118                  $sender_uid = -1;
 119                  // Workaround for eliminating PHP warnings in PHP 8. Ref: https://github.com/mybb/mybb/issues/4630#issuecomment-1369144163
 120                  $pm['sender']['uid'] = -1;
 121              }
 122  
 123              // Some kind of friendly error notification
 124              if(!send_pm($pm, $sender_uid, true))
 125              {
 126                  $warningshandler->friendly_action .= $lang->redirect_warned_pmerror;
 127              }
 128          }
 129  
 130          $plugins->run_hooks("warnings_do_warn_end");
 131  
 132          $lang->redirect_warned = $lang->sprintf($lang->redirect_warned, htmlspecialchars_uni($user['username']), $warningshandler->new_warning_level, $warningshandler->friendly_action);
 133  
 134          if(!empty($post['pid']))
 135          {
 136              redirect(get_post_link($post['pid']), $lang->redirect_warned);
 137          }
 138          else
 139          {
 140              redirect(get_profile_link($user['uid']), $lang->redirect_warned);
 141          }
 142      }
 143      else
 144      {
 145          $warn_errors = $warningshandler->get_friendly_errors();
 146          $warn_errors = inline_error($warn_errors);
 147          $mybb->input['action'] = 'warn';
 148      }
 149  }
 150  
 151  // Warn a user
 152  if($mybb->input['action'] == "warn")
 153  {
 154      if($mybb->usergroup['canwarnusers'] != 1)
 155      {
 156          error_no_permission();
 157      }
 158  
 159      // Check we haven't exceeded the maximum number of warnings per day
 160      if($mybb->usergroup['maxwarningsday'] != 0)
 161      {
 162          $timecut = TIME_NOW-60*60*24;
 163          $query = $db->simple_select("warnings", "COUNT(wid) AS given_today", "issuedby='{$mybb->user['uid']}' AND dateline>'$timecut'");
 164          $given_today = $db->fetch_field($query, "given_today");
 165          if($given_today >= $mybb->usergroup['maxwarningsday'])
 166          {
 167              error($lang->sprintf($lang->warnings_reached_max_warnings_day, $mybb->usergroup['maxwarningsday']));
 168          }
 169      }
 170  
 171      $user = get_user($mybb->get_input('uid', MyBB::INPUT_INT));
 172      if(!$user)
 173      {
 174          error($lang->error_invalid_user);
 175      }
 176  
 177      if($user['uid'] == $mybb->user['uid'])
 178      {
 179          error($lang->warnings_error_cannot_warn_self);
 180      }
 181  
 182      if($user['warningpoints'] >= $mybb->settings['maxwarningpoints'])
 183      {
 184          error($lang->warnings_error_user_reached_max_warning);
 185      }
 186  
 187      $group_permissions = user_permissions($user['uid']);
 188  
 189      if($group_permissions['canreceivewarnings'] != 1)
 190      {
 191          error($lang->error_cant_warn_group);
 192      }
 193  
 194      if(!modcp_can_manage_user($user['uid']))
 195      {
 196          error($lang->error_cant_warn_user);
 197      }
 198  
 199      $post = $existing_warnings = '';
 200  
 201      // Giving a warning for a specific post
 202      if($mybb->get_input('pid', MyBB::INPUT_INT))
 203      {
 204          $post = get_post($mybb->get_input('pid', MyBB::INPUT_INT));
 205  
 206          if($post)
 207          {
 208              $thread = get_thread($post['tid']);
 209          }
 210  
 211          if(!$post || !$thread)
 212          {
 213              error($lang->warnings_error_invalid_post);
 214          }
 215  
 216          $forum_permissions = forum_permissions($thread['fid']);
 217          if($forum_permissions['canview'] != 1)
 218          {
 219              error_no_permission();
 220          }
 221  
 222          $post['subject'] = $parser->parse_badwords($post['subject']);
 223          $post['subject'] = htmlspecialchars_uni($post['subject']);
 224          $post_link = get_post_link($post['pid']);
 225          eval("\$post = \"".$templates->get("warnings_warn_post")."\";");
 226  
 227          // Fetch any existing warnings issued for this post
 228          $query = $db->query("
 229              SELECT w.*, t.title AS type_title, u.username
 230              FROM ".TABLE_PREFIX."warnings w
 231              LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
 232              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
 233              WHERE w.pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'
 234              ORDER BY w.expired ASC, w.dateline DESC
 235          ");
 236          $last_expired = -1;
 237          $warnings = '';
 238          while($warning = $db->fetch_array($query))
 239          {
 240              if($warning['expired'] != $last_expired)
 241              {
 242                  if($warning['expired'] == 0)
 243                  {
 244                      eval("\$warnings .= \"".$templates->get("warnings_active_header")."\";");
 245                  }
 246                  else
 247                  {
 248                      eval("\$warnings .= \"".$templates->get("warnings_expired_header")."\";");
 249                  }
 250              }
 251              $last_expired = $warning['expired'];
 252  
 253              $post_link = "";
 254              $warning['username'] = htmlspecialchars_uni($warning['username']);
 255              $issuedby = build_profile_link($warning['username'], $warning['issuedby']);
 256              $date_issued = my_date('relative', $warning['dateline']);
 257              if($warning['type_title'])
 258              {
 259                  $warning_type = $warning['type_title'];
 260              }
 261              else
 262              {
 263                  $warning_type = $warning['title'];
 264              }
 265              $warning_type = htmlspecialchars_uni($warning_type);
 266              if($warning['points'] > 0)
 267              {
 268                  $warning['points'] = "+{$warning['points']}";
 269              }
 270              $points = $lang->sprintf($lang->warning_points, $warning['points']);
 271              if($warning['expired'] != 1)
 272              {
 273                  if($warning['expires'] == 0)
 274                  {
 275                      $expires = $lang->never;
 276                  }
 277                  else
 278                  {
 279                      $expires = nice_time($warning['expires']-TIME_NOW);
 280                  }
 281              }
 282              else
 283              {
 284                  if($warning['daterevoked'])
 285                  {
 286                      $expires = $lang->warning_revoked;
 287                  }
 288                  else if($warning['expires'])
 289                  {
 290                      $expires = $lang->already_expired;
 291                  }
 292              }
 293              $alt_bg = alt_trow();
 294              $plugins->run_hooks("warnings_warning");
 295              eval("\$warnings .= \"".$templates->get("warnings_warning")."\";");
 296          }
 297          if($warnings)
 298          {
 299              eval("\$existing_warnings = \"".$templates->get("warnings_warn_existing")."\";");
 300          }
 301      }
 302  
 303      $plugins->run_hooks("warnings_warn_start");
 304  
 305      $type_checked = array('custom' => '');
 306      $expires_period = array('hours' => '', 'days' => '', 'weeks' => '', 'months' => '', 'never' => '');
 307      $send_pm_checked = '';
 308  
 309      // Coming here from failed do_warn?
 310      $user['username'] = htmlspecialchars_uni($user['username']);
 311      if(!empty($warn_errors))
 312      {
 313          $notes = htmlspecialchars_uni($mybb->get_input('notes'));
 314          if($mybb->get_input('type', MyBB::INPUT_INT))
 315          {
 316              $type_checked[$mybb->get_input('type', MyBB::INPUT_INT)] = "checked=\"checked\"";
 317          }
 318          $pm_subject = htmlspecialchars_uni($mybb->get_input('pm_subject'));
 319          $message = htmlspecialchars_uni($mybb->get_input('pm_message'));
 320          if(!empty($mybb->input['send_pm']))
 321          {
 322              $send_pm_checked = "checked=\"checked\"";
 323          }
 324          $custom_reason = htmlspecialchars_uni($mybb->get_input('custom_reason'));
 325          $custom_points = $mybb->get_input('custom_points', MyBB::INPUT_INT);
 326          $expires = $mybb->get_input('expires', MyBB::INPUT_INT);
 327          if($mybb->get_input('expires_period'))
 328          {
 329              $expires_period[$mybb->get_input('expires_period')] = "selected=\"selected\"";
 330          }
 331      }
 332      else
 333      {
 334          $notes = $custom_reason = $custom_points = $expires = '';
 335          $expires = 1;
 336          $custom_points = 2;
 337          $pm_subject = $lang->warning_pm_subject;
 338          $message = $lang->sprintf($lang->warning_pm_message, $user['username'], $mybb->settings['bbname']);
 339          $warn_errors = '';
 340      }
 341  
 342      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 343      add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 344      add_breadcrumb($lang->nav_add_warning);
 345  
 346      $user_link = build_profile_link($user['username'], $user['uid']);
 347  
 348      if($mybb->settings['maxwarningpoints'] < 1)
 349      {
 350          $mybb->settings['maxwarningpoints'] = 10;
 351      }
 352  
 353      if(!is_array($groupscache))
 354      {
 355          $groupscache = $cache->read("usergroups");
 356      }
 357  
 358      $current_level = round($user['warningpoints']/$mybb->settings['maxwarningpoints']*100);
 359  
 360      // Fetch warning levels
 361      $levels = array();
 362      $query = $db->simple_select("warninglevels", "*");
 363      while($level = $db->fetch_array($query))
 364      {
 365          $level['action'] = my_unserialize($level['action']);
 366          switch($level['action']['type'])
 367          {
 368              case 1:
 369                  if($level['action']['length'] > 0)
 370                  {
 371                      $ban_length = fetch_friendly_expiration($level['action']['length']);
 372                      $lang_str = "expiration_".$ban_length['period'];
 373                      $period = $lang->sprintf($lang->result_period, $ban_length['time'], $lang->$lang_str);
 374                  }
 375                  else
 376                  {
 377                      $period = $lang->result_period_perm;
 378                  }
 379                  $group_name = $groupscache[$level['action']['usergroup']]['title'];
 380                  $level['friendly_action'] = $lang->sprintf($lang->result_banned, $group_name, $period);
 381                  break;
 382              case 2:
 383                  if($level['action']['length'] > 0)
 384                  {
 385                      $period = fetch_friendly_expiration($level['action']['length']);
 386                      $lang_str = "expiration_".$period['period'];
 387                      $period = $lang->sprintf($lang->result_period, $period['time'], $lang->$lang_str);
 388                  }
 389                  else
 390                  {
 391                      $period = $lang->result_period_perm;
 392                  }
 393                  $level['friendly_action'] = $lang->sprintf($lang->result_suspended, $period);
 394                  break;
 395              case 3:
 396                  if($level['action']['length'] > 0)
 397                  {
 398                      $period = fetch_friendly_expiration($level['action']['length']);
 399                      $lang_str = "expiration_".$period['period'];
 400                      $period = $lang->sprintf($lang->result_period, $period['time'], $lang->$lang_str);
 401                  }
 402                  else
 403                  {
 404                      $period = $lang->result_period_perm;
 405                  }
 406                  $level['friendly_action'] = $lang->sprintf($lang->result_moderated, $period);
 407                  break;
 408          }
 409          $levels[$level['percentage']] = $level;
 410      }
 411      krsort($levels);
 412  
 413      $types = '';
 414  
 415      // Fetch all current warning types
 416      $query = $db->simple_select("warningtypes", "*", "", array("order_by" => "title"));
 417      while($type = $db->fetch_array($query))
 418      {
 419          if(!isset($type_checked[$type['tid']]))
 420          {
 421              $type_checked[$type['tid']] = '';
 422          }
 423          $checked = $type_checked[$type['tid']];
 424          $type['title'] = htmlspecialchars_uni($type['title']);
 425          $new_warning_level = round(($user['warningpoints']+$type['points'])/$mybb->settings['maxwarningpoints']*100);
 426          if($new_warning_level > 100)
 427          {
 428              $new_warning_level = 100;
 429          }
 430          if($type['points'] > 0)
 431          {
 432              $type['points'] = "+{$type['points']}";
 433          }
 434          $points = $lang->sprintf($lang->warning_points, $type['points']);
 435  
 436          if(is_array($levels))
 437          {
 438              foreach($levels as $level)
 439              {
 440                  if($new_warning_level >= $level['percentage'])
 441                  {
 442                      $new_level = $level;
 443                      break;
 444                  }
 445              }
 446          }
 447          $level_diff = $new_warning_level-$current_level;
 448          $result = '';
 449          if(!empty($new_level['friendly_action']))
 450          {
 451              eval("\$result = \"".$templates->get("warnings_warn_type_result")."\";");
 452          }
 453          eval("\$types .= \"".$templates->get("warnings_warn_type")."\";");
 454          unset($new_level);
 455          unset($result);
 456      }
 457  
 458      $custom_warning = '';
 459  
 460      if($mybb->settings['allowcustomwarnings'] != 0)
 461      {
 462          if(empty($types) && empty($warn_errors) || $mybb->get_input('type') == 'custom')
 463          {
 464              $type_checked['custom'] = "checked=\"checked\"";
 465          }
 466  
 467          eval("\$custom_warning = \"".$templates->get("warnings_warn_custom")."\";");
 468      }
 469  
 470      $pm_notify = '';
 471  
 472      if($group_permissions['canusepms']  != 0 && $mybb->user['receivepms'] != 0 && $mybb->settings['enablepms'] != 0)
 473      {
 474          $smilieinserter = $codebuttons = "";
 475  
 476          if($mybb->settings['bbcodeinserter'] != 0 && $mybb->settings['pmsallowmycode'] != 0 && $mybb->user['showcodebuttons'] != 0)
 477          {
 478              $codebuttons = build_mycode_inserter("message", $mybb->settings['pmsallowsmilies']);
 479              if($mybb->settings['pmsallowsmilies'] != 0)
 480              {
 481                  $smilieinserter = build_clickable_smilies();
 482              }
 483          }
 484  
 485          $anonymous_pm = '';
 486          if($mybb->settings['allowanonwarningpms'] == 1)
 487          {
 488              $checked = '';
 489              if($mybb->get_input('pm_anonymous', MyBB::INPUT_INT))
 490              {
 491                  $checked = ' checked="checked"';
 492              }
 493  
 494              eval('$anonymous_pm = "'.$templates->get('warnings_warn_pm_anonymous').'";');
 495          }
 496  
 497          eval("\$pm_notify = \"".$templates->get("warnings_warn_pm")."\";");
 498      }
 499  
 500      $plugins->run_hooks("warnings_warn_end");
 501  
 502      eval("\$warn = \"".$templates->get("warnings_warn")."\";");
 503      output_page($warn);
 504      exit;
 505  }
 506  
 507  // Revoke a warning
 508  if($mybb->input['action'] == "do_revoke" && $mybb->request_method == "post")
 509  {
 510      // Verify incoming POST request
 511      verify_post_check($mybb->get_input('my_post_key'));
 512  
 513      if($mybb->usergroup['canwarnusers'] != 1)
 514      {
 515          error_no_permission();
 516      }
 517  
 518      $warning = $warningshandler->get($mybb->input['wid']);
 519  
 520      if(!$warning)
 521      {
 522          error($lang->error_invalid_warning);
 523      }
 524      else if($warning['daterevoked'])
 525      {
 526          error($lang->warning_already_revoked);
 527      }
 528  
 529      $user = get_user($warning['uid']);
 530  
 531      $group_permissions = user_permissions($user['uid']);
 532      if($group_permissions['canreceivewarnings'] != 1)
 533      {
 534          error($lang->error_cant_warn_group);
 535      }
 536  
 537      $plugins->run_hooks("warnings_do_revoke_start");
 538  
 539      if(!trim($mybb->get_input('reason')))
 540      {
 541          $warn_errors[] = $lang->no_revoke_reason;
 542          $warn_errors = inline_error($warn_errors);
 543          $mybb->input['action'] = "view";
 544      }
 545      else
 546      {
 547          $warning_data = array(
 548              'wid' => $warning['wid'],
 549              'reason' => $mybb->get_input('reason'),
 550              'expired' => $warning['expired'],
 551              'uid' => $warning['uid'],
 552              'points' => $warning['points']
 553          );
 554  
 555          $warningshandler->set_data($warning_data);
 556  
 557          $warningshandler->update_warning();
 558  
 559          redirect("warnings.php?action=view&wid={$warning['wid']}", $lang->redirect_warning_revoked);
 560      }
 561  }
 562  
 563  // Detailed view of a warning
 564  if($mybb->input['action'] == "view")
 565  {
 566      if($mybb->usergroup['canwarnusers'] != 1)
 567      {
 568          error_no_permission();
 569      }
 570  
 571      $query = $db->query("
 572          SELECT w.*, t.title AS type_title, u.username, p.subject AS post_subject
 573          FROM ".TABLE_PREFIX."warnings w
 574          LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
 575          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
 576          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=w.pid)
 577          WHERE w.wid='".$mybb->get_input('wid', MyBB::INPUT_INT)."'
 578      ");
 579      $warning = $db->fetch_array($query);
 580  
 581      if(!$warning)
 582      {
 583          error($lang->error_invalid_warning);
 584      }
 585  
 586      $user = get_user((int)$warning['uid']);
 587      if(empty($user))
 588      {
 589          $user = array('uid' => 0, 'username' => $lang->guest);
 590      }
 591      $user['username'] = htmlspecialchars_uni($user['username']);
 592  
 593      $group_permissions = user_permissions($user['uid']);
 594      if($group_permissions['canreceivewarnings'] != 1)
 595      {
 596          error($lang->error_cant_warn_group);
 597      }
 598  
 599      $plugins->run_hooks("warnings_view_start");
 600  
 601      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 602      if(!empty($user['uid']))
 603      {
 604          add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 605          add_breadcrumb($lang->nav_warning_log, "warnings.php?uid={$user['uid']}");
 606      }
 607      else
 608      {
 609          add_breadcrumb($lang->nav_profile);
 610          add_breadcrumb($lang->nav_warning_log);
 611      }
 612      add_breadcrumb($lang->nav_view_warning);
 613  
 614      $user_link = build_profile_link($user['username'], $user['uid']);
 615  
 616      $post_link = "";
 617      if($warning['post_subject'])
 618      {
 619          $warning['post_subject'] = $parser->parse_badwords($warning['post_subject']);
 620          $warning['post_subject'] = htmlspecialchars_uni($warning['post_subject']);
 621          $post_link = get_post_link($warning['pid'])."#pid{$warning['pid']}";
 622          eval("\$warning_info = \"".$templates->get("warnings_view_post")."\";");
 623      }
 624      else
 625      {
 626          eval("\$warning_info = \"".$templates->get("warnings_view_user")."\";");
 627      }
 628  
 629      $warning['username'] = htmlspecialchars_uni($warning['username']);
 630      $issuedby = build_profile_link($warning['username'], $warning['issuedby']);
 631      $notes = nl2br(htmlspecialchars_uni($warning['notes']));
 632  
 633      $date_issued = my_date('relative', $warning['dateline']);
 634      if($warning['type_title'])
 635      {
 636          $warning_type = $warning['type_title'];
 637      }
 638      else
 639      {
 640          $warning_type = $warning['title'];
 641      }
 642      $warning_type = htmlspecialchars_uni($warning_type);
 643      if($warning['points'] > 0)
 644      {
 645          $warning['points'] = "+{$warning['points']}";
 646      }
 647  
 648      $revoked_date = '';
 649  
 650      $points = $lang->sprintf($lang->warning_points, $warning['points']);
 651      if($warning['expired'] != 1)
 652      {
 653          if($warning['expires'] == 0)
 654          {
 655              $expires = $lang->never;
 656          }
 657          else
 658          {
 659              $expires = my_date('normal', $warning['expires']); // Purposely not using nice_time here as the moderator has clicked for more details so the actual day/time should be shown
 660          }
 661          $status = $lang->warning_active;
 662      }
 663      else
 664      {
 665          if($warning['daterevoked'])
 666          {
 667              $expires = $status = $lang->warning_revoked;
 668          }
 669          else if($warning['expires'])
 670          {
 671              $revoked_date = '('.my_date('normal', $warning['expires']).')';
 672              $expires = $status = $lang->already_expired;
 673          }
 674      }
 675  
 676      if(!$warning['daterevoked'])
 677      {
 678          if(!isset($warn_errors))
 679          {
 680              $warn_errors = '';
 681          }
 682          eval("\$revoke = \"".$templates->get("warnings_view_revoke")."\";");
 683      }
 684      else
 685      {
 686          $date_revoked = my_date('relative', $warning['daterevoked']);
 687          $revoked_user = get_user($warning['revokedby']);
 688          if(!$revoked_user['username'])
 689          {
 690              $revoked_user['username'] = $lang->guest;
 691          }
 692          $revoked_user['username'] = htmlspecialchars_uni($revoked_user['username']);
 693          $revoked_by = build_profile_link($revoked_user['username'], $revoked_user['uid']);
 694          $revoke_reason = nl2br(htmlspecialchars_uni($warning['revokereason']));
 695          eval("\$revoke = \"".$templates->get("warnings_view_revoked")."\";");
 696      }
 697  
 698      $plugins->run_hooks("warnings_view_end");
 699  
 700      eval("\$warning = \"".$templates->get("warnings_view")."\";");
 701      output_page($warning);
 702  }
 703  
 704  // Showing list of warnings for a particular user
 705  if(!$mybb->input['action'])
 706  {
 707      if($mybb->usergroup['canwarnusers'] != 1)
 708      {
 709          error_no_permission();
 710      }
 711  
 712      $user = get_user($mybb->get_input('uid', MyBB::INPUT_INT));
 713      if(!$user)
 714      {
 715          error($lang->error_invalid_user);
 716      }
 717  
 718      $group_permissions = user_permissions($user['uid']);
 719      if($group_permissions['canreceivewarnings'] != 1)
 720      {
 721          error($lang->error_cant_warn_group);
 722      }
 723  
 724      $user['username'] = htmlspecialchars_uni($user['username']);
 725      $lang->nav_profile = $lang->sprintf($lang->nav_profile, $user['username']);
 726      add_breadcrumb($lang->nav_profile, get_profile_link($user['uid']));
 727      add_breadcrumb($lang->nav_warning_log);
 728  
 729      if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
 730      {
 731          $mybb->settings['postsperpage'] = 20;
 732      }
 733  
 734      // Figure out if we need to display multiple pages.
 735      $perpage = $mybb->settings['postsperpage'];
 736      $page = $mybb->get_input('page', MyBB::INPUT_INT);
 737  
 738      $query = $db->simple_select("warnings", "COUNT(wid) AS warning_count", "uid='{$user['uid']}'");
 739      $warning_count = $db->fetch_field($query, "warning_count");
 740  
 741      $pages = ceil($warning_count/$perpage);
 742  
 743      if($page > $pages || $page <= 0)
 744      {
 745          $page = 1;
 746      }
 747      if($page)
 748      {
 749          $start = ($page-1) * $perpage;
 750      }
 751      else
 752      {
 753          $start = 0;
 754          $page = 1;
 755      }
 756  
 757      $multipage = multipage($warning_count, $perpage, $page, "warnings.php?uid={$user['uid']}");
 758  
 759      if($mybb->settings['maxwarningpoints'] < 1)
 760      {
 761          $mybb->settings['maxwarningpoints'] = 10;
 762      }
 763  
 764      $warning_level = round($user['warningpoints']/$mybb->settings['maxwarningpoints']*100);
 765      if($warning_level > 100)
 766      {
 767          $warning_level = 100;
 768      }
 769  
 770      if($user['warningpoints'] > $mybb->settings['maxwarningpoints'])
 771      {
 772          $user['warningpoints'] = $mybb->settings['maxwarningpoints'];
 773      }
 774  
 775      if($warning_level > 0)
 776      {
 777          $lang->current_warning_level = $lang->sprintf($lang->current_warning_level, $warning_level, $user['warningpoints'], $mybb->settings['maxwarningpoints']);
 778      }
 779      else
 780      {
 781          $lang->current_warning_level = "";
 782      }
 783  
 784      // Fetch the actual warnings
 785      $query = $db->query("
 786          SELECT w.*, t.title AS type_title, u.username, p.subject AS post_subject
 787          FROM ".TABLE_PREFIX."warnings w
 788          LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (t.tid=w.tid)
 789          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=w.issuedby)
 790          LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=w.pid)
 791          WHERE w.uid='{$user['uid']}'
 792          ORDER BY w.expired ASC, w.dateline DESC
 793          LIMIT {$start}, {$perpage}
 794      ");
 795      $warnings = '';
 796      while($warning = $db->fetch_array($query))
 797      {
 798          if(!isset($last_expired) || $warning['expired'] != $last_expired)
 799          {
 800              if($warning['expired'] == 0)
 801              {
 802                  eval("\$warnings .= \"".$templates->get("warnings_active_header")."\";");
 803              }
 804              else
 805              {
 806                  eval("\$warnings .= \"".$templates->get("warnings_expired_header")."\";");
 807              }
 808          }
 809          $last_expired = $warning['expired'];
 810  
 811          $post_link = '';
 812          if($warning['post_subject'])
 813          {
 814              $warning['post_subject'] = $parser->parse_badwords($warning['post_subject']);
 815              $warning['post_subject'] = htmlspecialchars_uni($warning['post_subject']);
 816              $warning['post_link'] = get_post_link($warning['pid']);
 817              eval("\$post_link = \"".$templates->get("warnings_postlink")."\";");
 818          }
 819  
 820          $warning['username'] = htmlspecialchars_uni($warning['username']);
 821          $issuedby = build_profile_link($warning['username'], $warning['issuedby']);
 822          $date_issued = my_date('relative', $warning['dateline']);
 823          if($warning['type_title'])
 824          {
 825              $warning_type = $warning['type_title'];
 826          }
 827          else
 828          {
 829              $warning_type = $warning['title'];
 830          }
 831          $warning_type = htmlspecialchars_uni($warning_type);
 832          if($warning['points'] > 0)
 833          {
 834              $warning['points'] = "+{$warning['points']}";
 835          }
 836          $points = $lang->sprintf($lang->warning_points, $warning['points']);
 837          if($warning['expired'] != 1)
 838          {
 839              if($warning['expires'] == 0)
 840              {
 841                  $expires = $lang->never;
 842              }
 843              else
 844              {
 845                  $expires = nice_time($warning['expires']-TIME_NOW);
 846              }
 847          }
 848          else
 849          {
 850              if($warning['daterevoked'])
 851              {
 852                  $expires = $lang->warning_revoked;
 853              }
 854              else if($warning['expires'])
 855              {
 856                  $expires = $lang->already_expired;
 857              }
 858          }
 859          $alt_bg = alt_trow();
 860          $plugins->run_hooks("warnings_warning");
 861          eval("\$warnings .= \"".$templates->get("warnings_warning")."\";");
 862      }
 863  
 864      if(!$warnings)
 865      {
 866          eval("\$warnings = \"".$templates->get("warnings_no_warnings")."\";");
 867      }
 868  
 869      $plugins->run_hooks("warnings_end");
 870  
 871      eval("\$warnings = \"".$templates->get("warnings")."\";");
 872      output_page($warnings);
 873  }
 874  


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