[ Index ]

PHP Cross Reference of MyBB 1.8.19

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


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