[ Index ]

PHP Cross Reference of MyBB 1.8.12

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


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