[ Index ]

PHP Cross Reference of MyBB 1.8.41

title

Body

[close]

/admin/modules/config/ -> warning.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  require_once  MYBB_ROOT."inc/functions_warnings.php";
  18  
  19  $page->add_breadcrumb_item($lang->warning_system, "index.php?module=config-warning");
  20  
  21  if($mybb->input['action'] == "levels" || $mybb->input['action'] == "add_type" || $mybb->input['action'] == "add_level" || !$mybb->input['action'])
  22  {
  23      $sub_tabs['manage_types'] = array(
  24          'title' => $lang->warning_types,
  25          'link' => "index.php?module=config-warning",
  26          'description' => $lang->warning_types_desc
  27      );
  28      $sub_tabs['add_type'] = array(
  29          'title'=> $lang->add_warning_type,
  30          'link' => "index.php?module=config-warning&amp;action=add_type",
  31          'description' => $lang->add_warning_type_desc
  32      );
  33      $sub_tabs['manage_levels'] = array(
  34          'title' => $lang->warning_levels,
  35          'link' => "index.php?module=config-warning&amp;action=levels",
  36          'description' => $lang->warning_levels_desc,
  37      );
  38      $sub_tabs['add_level'] = array(
  39          'title'=> $lang->add_warning_level,
  40          'link' => "index.php?module=config-warning&amp;action=add_level",
  41          'description' => $lang->add_warning_level_desc
  42      );
  43  }
  44  
  45  $plugins->run_hooks("admin_config_warning_begin");
  46  
  47  $banned_groups = array();
  48  $query = $db->simple_select("usergroups", "gid,title", "isbannedgroup=1");
  49  while($group = $db->fetch_array($query))
  50  {
  51      $banned_groups[$group['gid']] = $group['title'];
  52  }
  53  
  54  if($mybb->input['action'] == "add_level")
  55  {
  56      $plugins->run_hooks("admin_config_warning_add_level");
  57  
  58      if($mybb->request_method == "post")
  59      {
  60          if(!is_numeric($mybb->input['percentage']) || $mybb->input['percentage'] > 100 || $mybb->input['percentage'] < 0)
  61          {
  62              $errors[] = $lang->error_invalid_warning_percentage;
  63          }
  64  
  65          if(!$mybb->input['action_type'])
  66          {
  67              $errors[] = $lang->error_missing_action_type;
  68          }
  69          elseif(
  70              $mybb->input['action_type'] == 1 &&
  71              !array_key_exists($mybb->get_input('action_1_usergroup', MyBB::INPUT_INT), $banned_groups)
  72          )
  73          {
  74              $errors[] = $lang->error_invalid_ban_group;
  75          }
  76  
  77          if(!$errors)
  78          {
  79              // Ban
  80              if($mybb->input['action_type'] == 1)
  81              {
  82                  $action = array(
  83                      "type" => 1,
  84                      "usergroup" => $mybb->get_input('action_1_usergroup', MyBB::INPUT_INT),
  85                      "length" => fetch_time_length($mybb->input['action_1_time'], $mybb->input['action_1_period'])
  86                  );
  87              }
  88              // Suspend posting
  89              else if($mybb->input['action_type'] == 2)
  90              {
  91                  $action = array(
  92                      "type" => 2,
  93                      "length" => fetch_time_length($mybb->input['action_2_time'], $mybb->input['action_2_period'])
  94                  );
  95              }
  96              // Moderate posts
  97              else if($mybb->input['action_type'] == 3)
  98              {
  99                  $action = array(
 100                      "type" => 3,
 101                      "length" => fetch_time_length($mybb->input['action_3_time'], $mybb->input['action_3_period'])
 102                  );
 103              }
 104              $new_level = array(
 105                  "percentage" => $mybb->get_input('percentage', MyBB::INPUT_INT),
 106                  "action" => my_serialize($action)
 107              );
 108  
 109              $lid = $db->insert_query("warninglevels", $new_level);
 110  
 111              $plugins->run_hooks("admin_config_warning_add_level_commit");
 112  
 113              // Log admin action
 114              log_admin_action($lid, $mybb->input['percentage']);
 115  
 116              flash_message($lang->success_warning_level_created, 'success');
 117              admin_redirect("index.php?module=config-warning&action=levels");
 118          }
 119      }
 120  
 121      $page->add_breadcrumb_item($lang->add_warning_level);
 122      $page->output_header($lang->warning_levels." - ".$lang->add_warning_level);
 123  
 124      $page->output_nav_tabs($sub_tabs, 'add_level');
 125      $form = new Form("index.php?module=config-warning&amp;action=add_level", "post");
 126  
 127      $action_checked = array_fill(1, 3, null);
 128      if($errors)
 129      {
 130          $page->output_inline_error($errors);
 131          $action_checked[$mybb->input['action_type']] = "checked=\"checked\"";
 132      }
 133  
 134      $form_container = new FormContainer($lang->add_warning_level);
 135      $form_container->output_row($lang->warning_points_percentage, $lang->warning_points_percentage_desc, $form->generate_numeric_field('percentage', $mybb->get_input('percentage'), array('id' => 'percentage', 'min' => 0, 'max' => 100)), 'percentage');
 136  
 137      $periods = array(
 138          "hours" => $lang->expiration_hours,
 139          "days" => $lang->expiration_days,
 140          "weeks" => $lang->expiration_weeks,
 141          "months" => $lang->expiration_months,
 142          "never" => $lang->expiration_permanent
 143      );
 144  
 145      $actions = "<script type=\"text/javascript\">
 146  	function checkAction(id)
 147      {
 148          var checked = '';
 149  
 150          $('.'+id+'s_check').each(function(e, val)
 151          {
 152              if($(this).prop('checked') == true)
 153              {
 154                  checked = $(this).val();
 155              }
 156          });
 157          $('.'+id+'s').each(function(e)
 158          {
 159              $(this).hide();
 160          });
 161          if($('#'+id+'_'+checked))
 162          {
 163              $('#'+id+'_'+checked).show();
 164          }
 165      }
 166      </script>
 167      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 168          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"1\" {$action_checked[1]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->ban_user}</strong></label></dt>
 169          <dd style=\"margin-top: 4px;\" id=\"action_1\" class=\"actions\">
 170              <table cellpadding=\"4\">
 171                  <tr>
 172                      <td><small>{$lang->banned_group}</small></td>
 173                      <td>".$form->generate_select_box('action_1_usergroup', $banned_groups, $mybb->get_input('action_1_usergroup'))."</td>
 174                  </tr>
 175                  <tr>
 176                      <td><small>{$lang->ban_length}</small></td>
 177                      <td>".$form->generate_numeric_field('action_1_time', $mybb->get_input('action_1_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_1_period', $periods, $mybb->get_input('action_1_period'))."</td>
 178                  </tr>
 179              </table>
 180          </dd>
 181          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"2\" {$action_checked[2]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->suspend_posting_privileges}</strong></label></dt>
 182          <dd style=\"margin-top: 4px;\" id=\"action_2\" class=\"actions\">
 183              <table cellpadding=\"4\">
 184                  <tr>
 185                      <td><small>{$lang->suspension_length}</small></td>
 186                      <td>".$form->generate_numeric_field('action_2_time', $mybb->get_input('action_2_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_2_period', $periods, $mybb->get_input('action_2_period'))."</td>
 187                  </tr>
 188              </table>
 189          </dd>
 190          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"3\" {$action_checked[3]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->moderate_posts}</strong></label></dt>
 191          <dd style=\"margin-top: 4px;\" id=\"action_3\" class=\"actions\">
 192              <table cellpadding=\"4\">
 193                  <tr>
 194                      <td><small>{$lang->moderation_length}</small></td>
 195                      <td>".$form->generate_numeric_field('action_3_time', $mybb->get_input('action_3_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_3_period', $periods, $mybb->get_input('action_3_period'))."</td>
 196                  </tr>
 197              </table>
 198          </dd>
 199      </dl>
 200      <script type=\"text/javascript\">
 201      checkAction('action');
 202      </script>";
 203      $form_container->output_row($lang->action_to_be_taken, $lang->action_to_be_taken_desc, $actions);
 204      $form_container->end();
 205  
 206      $buttons[] = $form->generate_submit_button($lang->save_warning_level);
 207  
 208      $form->output_submit_wrapper($buttons);
 209      $form->end();
 210  
 211      $page->output_footer();
 212  }
 213  
 214  if($mybb->input['action'] == "edit_level")
 215  {
 216      $query = $db->simple_select("warninglevels", "*", "lid='".$mybb->get_input('lid', MyBB::INPUT_INT)."'");
 217      $level = $db->fetch_array($query);
 218  
 219      // Does the warning level not exist?
 220      if(!$level)
 221      {
 222          flash_message($lang->error_invalid_warning_level, 'error');
 223          admin_redirect("index.php?module=config-warning");
 224      }
 225  
 226      $plugins->run_hooks("admin_config_warning_edit_level");
 227  
 228      if($mybb->request_method == "post")
 229      {
 230          if(!is_numeric($mybb->input['percentage']) || $mybb->input['percentage'] > 100 || $mybb->input['percentage'] < 0)
 231          {
 232              $errors[] = $lang->error_invalid_warning_percentage;
 233          }
 234  
 235          if(!$mybb->input['action_type'])
 236          {
 237              $errors[] = $lang->error_missing_action_type;
 238          }
 239          elseif(
 240              $mybb->input['action_type'] == 1 &&
 241              !array_key_exists($mybb->get_input('action_1_usergroup', MyBB::INPUT_INT), $banned_groups)
 242          )
 243          {
 244              $errors[] = $lang->error_invalid_ban_group;
 245          }
 246  
 247          if(!$errors)
 248          {
 249              // Ban
 250              if($mybb->input['action_type'] == 1)
 251              {
 252                  $action = array(
 253                      "type" => 1,
 254                      "usergroup" => $mybb->get_input('action_1_usergroup', MyBB::INPUT_INT),
 255                      "length" => fetch_time_length($mybb->input['action_1_time'], $mybb->input['action_1_period'])
 256                  );
 257              }
 258              // Suspend posting
 259              else if($mybb->input['action_type'] == 2)
 260              {
 261                  $action = array(
 262                      "type" => 2,
 263                      "length" => fetch_time_length($mybb->input['action_2_time'], $mybb->input['action_2_period'])
 264                  );
 265              }
 266              // Moderate posts
 267              else if($mybb->input['action_type'] == 3)
 268              {
 269                  $action = array(
 270                      "type" => 3,
 271                      "length" => fetch_time_length($mybb->input['action_3_time'], $mybb->input['action_3_period'])
 272                  );
 273              }
 274              $updated_level = array(
 275                  "percentage" => $mybb->get_input('percentage', MyBB::INPUT_INT),
 276                  "action" => my_serialize($action)
 277              );
 278  
 279              $plugins->run_hooks("admin_config_warning_edit_level_commit");
 280  
 281              $db->update_query("warninglevels", $updated_level, "lid='{$level['lid']}'");
 282  
 283              // Log admin action
 284              log_admin_action($level['lid'], $mybb->input['percentage']);
 285  
 286              flash_message($lang->success_warning_level_updated, 'success');
 287              admin_redirect("index.php?module=config-warning&action=levels");
 288          }
 289      }
 290  
 291      $page->add_breadcrumb_item($lang->edit_warning_level);
 292      $page->output_header($lang->warning_levels." - ".$lang->edit_warning_level);
 293  
 294      $sub_tabs['edit_level'] = array(
 295          'link' => "index.php?module=config-warning&amp;action=edit_level&amp;lid={$level['lid']}",
 296          'title' => $lang->edit_warning_level,
 297          'description' => $lang->edit_warning_level_desc
 298      );
 299  
 300      $page->output_nav_tabs($sub_tabs, 'edit_level');
 301      $form = new Form("index.php?module=config-warning&amp;action=edit_level&amp;lid={$level['lid']}", "post");
 302  
 303      if($errors)
 304      {
 305          $page->output_inline_error($errors);
 306      }
 307      else
 308      {
 309          $mybb->input = array_merge($mybb->input, array(
 310                  "percentage" => $level['percentage'],
 311              )
 312          );
 313          $action = my_unserialize($level['action']);
 314          if($action['type'] == 1)
 315          {
 316              $mybb->input['action_1_usergroup'] = $action['usergroup'];
 317              $length = fetch_friendly_expiration($action['length']);
 318              $mybb->input['action_1_time'] = isset($length['time']) ? $length['time'] : null;
 319              $mybb->input['action_1_period'] = $length['period'];
 320          }
 321          else if($action['type'] == 2)
 322          {
 323              $length = fetch_friendly_expiration($action['length']);
 324              $mybb->input['action_2_time'] = isset($length['time']) ? $length['time'] : null;
 325              $mybb->input['action_2_period'] = $length['period'];
 326          }
 327          else if($action['type'] == 3)
 328          {
 329              $length = fetch_friendly_expiration($action['length']);
 330              $mybb->input['action_3_time'] = isset($length['time']) ? $length['time'] : null;
 331              $mybb->input['action_3_period'] = $length['period'];
 332          }
 333  
 334          $action_checked = array_fill(1, 3, null);
 335          $action_checked[$action['type']] = "checked=\"checked\"";
 336      }
 337  
 338      $form_container = new FormContainer($lang->edit_warning_level);
 339      $form_container->output_row($lang->warning_points_percentage, $lang->warning_points_percentage_desc, $form->generate_numeric_field('percentage', $mybb->input['percentage'], array('id' => 'percentage', 'min' => 0, 'max' => 100)), 'percentage');
 340  
 341      $periods = array(
 342          "hours" => $lang->expiration_hours,
 343          "days" => $lang->expiration_days,
 344          "weeks" => $lang->expiration_weeks,
 345          "months" => $lang->expiration_months,
 346          "never" => $lang->expiration_permanent
 347      );
 348  
 349      $actions = "<script type=\"text/javascript\">
 350  	function checkAction(id)
 351      {
 352          var checked = '';
 353  
 354          $('.'+id+'s_check').each(function(e, val)
 355          {
 356              if($(this).prop('checked') == true)
 357              {
 358                  checked = $(this).val();
 359              }
 360          });
 361          $('.'+id+'s').each(function(e)
 362          {
 363              $(this).hide();
 364          });
 365          if($('#'+id+'_'+checked))
 366          {
 367              $('#'+id+'_'+checked).show();
 368          }
 369      }
 370      </script>
 371      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 372          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"1\" {$action_checked[1]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->ban_user}</strong></label></dt>
 373          <dd style=\"margin-top: 4px;\" id=\"action_1\" class=\"actions\">
 374              <table cellpadding=\"4\">
 375                  <tr>
 376                      <td><small>{$lang->banned_group}</small></td>
 377                      <td>".$form->generate_select_box('action_1_usergroup', $banned_groups, $mybb->get_input('action_1_usergroup'))."</td>
 378                  </tr>
 379                  <tr>
 380                      <td><small>{$lang->ban_length}</small></td>
 381                      <td>".$form->generate_numeric_field('action_1_time', $mybb->get_input('action_1_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_1_period', $periods, $mybb->get_input('action_1_period'))."</td>
 382                  </tr>
 383              </table>
 384          </dd>
 385          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"2\" {$action_checked[2]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->suspend_posting_privileges}</strong></label></dt>
 386          <dd style=\"margin-top: 4px;\" id=\"action_2\" class=\"actions\">
 387              <table cellpadding=\"4\">
 388                  <tr>
 389                      <td><small>{$lang->suspension_length}</small></td>
 390                      <td>".$form->generate_numeric_field('action_2_time', $mybb->get_input('action_2_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_2_period', $periods, $mybb->get_input('action_2_period'))."</td>
 391                  </tr>
 392              </table>
 393          </dd>
 394          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_type\" value=\"3\" {$action_checked[3]} class=\"actions_check\" onclick=\"checkAction('action');\" style=\"vertical-align: middle;\" /> <strong>{$lang->moderate_posts}</strong></label></dt>
 395          <dd style=\"margin-top: 4px;\" id=\"action_3\" class=\"actions\">
 396              <table cellpadding=\"4\">
 397                  <tr>
 398                      <td><small>{$lang->moderation_length}</small></td>
 399                      <td>".$form->generate_numeric_field('action_3_time', $mybb->get_input('action_3_time'), array('style' => 'width: 3em;', 'min' => 0))." ".$form->generate_select_box('action_3_period', $periods, $mybb->get_input('action_3_period'))."</td>
 400                  </tr>
 401              </table>
 402          </dd>
 403      </dl>
 404      <script type=\"text/javascript\">
 405      checkAction('action');
 406      </script>";
 407      $form_container->output_row($lang->action_to_be_taken, $lang->action_to_be_taken_desc, $actions);
 408      $form_container->end();
 409  
 410      $buttons[] = $form->generate_submit_button($lang->save_warning_level);
 411  
 412      $form->output_submit_wrapper($buttons);
 413      $form->end();
 414  
 415      $page->output_footer();
 416  }
 417  
 418  if($mybb->input['action'] == "delete_level")
 419  {
 420      $query = $db->simple_select("warninglevels", "*", "lid='".$mybb->get_input('lid', MyBB::INPUT_INT)."'");
 421      $level = $db->fetch_array($query);
 422  
 423      // Does the warning level not exist?
 424      if(!$level)
 425      {
 426          flash_message($lang->error_invalid_warning_level, 'error');
 427          admin_redirect("index.php?module=config-warning");
 428      }
 429  
 430      // User clicked no
 431      if($mybb->get_input('no'))
 432      {
 433          admin_redirect("index.php?module=config-warning");
 434      }
 435  
 436      $plugins->run_hooks("admin_config_warning_delete_level");
 437  
 438      if($mybb->request_method == "post")
 439      {
 440          // Delete the level
 441          $db->delete_query("warninglevels", "lid='{$level['lid']}'");
 442  
 443          $plugins->run_hooks("admin_config_warning_delete_level_commit");
 444  
 445          // Log admin action
 446          log_admin_action($level['lid'], $level['percentage']);
 447  
 448          flash_message($lang->success_warning_level_deleted, 'success');
 449          admin_redirect("index.php?module=config-warning");
 450      }
 451      else
 452      {
 453          $page->output_confirm_action("index.php?module=config-warning&amp;action=delete_level&amp;lid={$level['lid']}", $lang->confirm_warning_level_deletion);
 454      }
 455  }
 456  
 457  if($mybb->input['action'] == "add_type")
 458  {
 459      $plugins->run_hooks("admin_config_warning_add_type");
 460  
 461      if($mybb->request_method == "post")
 462      {
 463          if(!trim($mybb->input['title']))
 464          {
 465              $errors[] = $lang->error_missing_type_title;
 466          }
 467  
 468          if(!is_numeric($mybb->input['points']) || $mybb->input['points'] > $mybb->settings['maxwarningpoints'] || $mybb->input['points'] <= 0)
 469          {
 470              $errors[] = $lang->sprintf($lang->error_missing_type_points, $mybb->settings['maxwarningpoints']);
 471          }
 472  
 473          if(!$errors)
 474          {
 475              $new_type = array(
 476                  "title" => $db->escape_string($mybb->input['title']),
 477                  "points" => $mybb->get_input('points', MyBB::INPUT_INT),
 478                  "expirationtime" =>  fetch_time_length($mybb->input['expire_time'], $mybb->input['expire_period'])
 479              );
 480  
 481              $tid = $db->insert_query("warningtypes", $new_type);
 482  
 483              $plugins->run_hooks("admin_config_warning_add_type_commit");
 484  
 485              // Log admin action
 486              log_admin_action($tid, $mybb->input['title']);
 487  
 488              flash_message($lang->success_warning_type_created, 'success');
 489              admin_redirect("index.php?module=config-warning");
 490          }
 491      }
 492      else
 493      {
 494          $mybb->input = array_merge($mybb->input, array(
 495                  "points" => "2",
 496                  "expire_time" => 1,
 497                  "expire_period" => "days"
 498              )
 499          );
 500      }
 501  
 502      $page->add_breadcrumb_item($lang->add_warning_type);
 503      $page->output_header($lang->warning_types." - ".$lang->add_warning_type);
 504  
 505      $page->output_nav_tabs($sub_tabs, 'add_type');
 506      $form = new Form("index.php?module=config-warning&amp;action=add_type", "post");
 507  
 508  
 509      if($errors)
 510      {
 511          $page->output_inline_error($errors);
 512      }
 513  
 514      $form_container = new FormContainer($lang->add_warning_type);
 515      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 516      $form_container->output_row($lang->points_to_add." <em>*</em>", $lang->points_to_add_desc, $form->generate_numeric_field('points', $mybb->get_input('points'), array('id' => 'points', 'min' => 0, 'max' => $mybb->settings['maxwarningpoints'])), 'points');
 517      $expiration_periods = array(
 518          "hours" => $lang->expiration_hours,
 519          "days" => $lang->expiration_days,
 520          "weeks" => $lang->expiration_weeks,
 521          "months" => $lang->expiration_months,
 522          "never" => $lang->expiration_never
 523      );
 524      $form_container->output_row($lang->warning_expiry, $lang->warning_expiry_desc, $form->generate_numeric_field('expire_time', $mybb->input['expire_time'], array('id' => 'expire_time', 'min' => 0))." ".$form->generate_select_box('expire_period', $expiration_periods, $mybb->input['expire_period'], array('id' => 'expire_period')), 'expire_time');
 525      $form_container->end();
 526  
 527      $buttons[] = $form->generate_submit_button($lang->save_warning_type);
 528  
 529      $form->output_submit_wrapper($buttons);
 530      $form->end();
 531  
 532      $page->output_footer();
 533  }
 534  
 535  if($mybb->input['action'] == "edit_type")
 536  {
 537      $query = $db->simple_select("warningtypes", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
 538      $type = $db->fetch_array($query);
 539  
 540      // Does the warning type not exist?
 541      if(!$type)
 542      {
 543          flash_message($lang->error_invalid_warning_type, 'error');
 544          admin_redirect("index.php?module=config-warning");
 545      }
 546  
 547      $plugins->run_hooks("admin_config_warning_edit_type");
 548  
 549      if($mybb->request_method == "post")
 550      {
 551          if(!trim($mybb->input['title']))
 552          {
 553              $errors[] = $lang->error_missing_type_title;
 554          }
 555  
 556          if(!is_numeric($mybb->input['points']) || $mybb->input['points'] > $mybb->settings['maxwarningpoints'] || $mybb->input['points'] <= 0)
 557          {
 558              $errors[] = $lang->sprintf($lang->error_missing_type_points, $mybb->settings['maxwarningpoints']);
 559          }
 560  
 561          if(!$errors)
 562          {
 563              $updated_type = array(
 564                  "title" => $db->escape_string($mybb->input['title']),
 565                  "points" => $mybb->get_input('points', MyBB::INPUT_INT),
 566                  "expirationtime" =>  fetch_time_length($mybb->input['expire_time'], $mybb->input['expire_period'])
 567              );
 568  
 569              $plugins->run_hooks("admin_config_warning_edit_type_commit");
 570  
 571              $db->update_query("warningtypes", $updated_type, "tid='{$type['tid']}'");
 572  
 573              // Log admin action
 574              log_admin_action($type['tid'], $mybb->input['title']);
 575  
 576              flash_message($lang->success_warning_type_updated, 'success');
 577              admin_redirect("index.php?module=config-warning");
 578          }
 579      }
 580      else
 581      {
 582          $expiration = fetch_friendly_expiration($type['expirationtime']);
 583          $mybb->input = array_merge($mybb->input, array(
 584                  "title" => $type['title'],
 585                  "points" => $type['points'],
 586                  "expire_time" => $expiration['time'],
 587                  "expire_period" => $expiration['period']
 588              )
 589          );
 590      }
 591  
 592      $page->add_breadcrumb_item($lang->edit_warning_type);
 593      $page->output_header($lang->warning_types." - ".$lang->edit_warning_type);
 594  
 595      $sub_tabs['edit_type'] = array(
 596          'link' => "index.php?module=config-warning&amp;action=edit_type&amp;tid={$type['tid']}",
 597          'title' => $lang->edit_warning_type,
 598          'description' => $lang->edit_warning_type_desc
 599      );
 600  
 601      $page->output_nav_tabs($sub_tabs, 'edit_type');
 602      $form = new Form("index.php?module=config-warning&amp;action=edit_type&amp;tid={$type['tid']}", "post");
 603  
 604  
 605      if($errors)
 606      {
 607          $page->output_inline_error($errors);
 608      }
 609  
 610      $form_container = new FormContainer($lang->edit_warning_type);
 611      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 612      $form_container->output_row($lang->points_to_add." <em>*</em>", $lang->points_to_add_desc, $form->generate_numeric_field('points', $mybb->input['points'], array('id' => 'points', 'min' => 0, 'max' => $mybb->settings['maxwarningpoints'])), 'points');
 613      $expiration_periods = array(
 614          "hours" => $lang->expiration_hours,
 615          "days" => $lang->expiration_days,
 616          "weeks" => $lang->expiration_weeks,
 617          "months" => $lang->expiration_months,
 618          "never" => $lang->expiration_never
 619      );
 620      $form_container->output_row($lang->warning_expiry, $lang->warning_expiry_desc, $form->generate_numeric_field('expire_time', $mybb->input['expire_time'], array('id' => 'expire_time', 'min' => 0))." ".$form->generate_select_box('expire_period', $expiration_periods, $mybb->input['expire_period'], array('id' => 'expire_period')), 'expire_time');
 621      $form_container->end();
 622  
 623      $buttons[] = $form->generate_submit_button($lang->save_warning_type);
 624  
 625      $form->output_submit_wrapper($buttons);
 626      $form->end();
 627  
 628      $page->output_footer();
 629  }
 630  
 631  if($mybb->input['action'] == "delete_type")
 632  {
 633      $query = $db->simple_select("warningtypes", "*", "tid='".$mybb->get_input('tid', MyBB::INPUT_INT)."'");
 634      $type = $db->fetch_array($query);
 635  
 636      // Does the warning type not exist?
 637      if(!$type)
 638      {
 639          flash_message($lang->error_invalid_warning_type, 'error');
 640          admin_redirect("index.php?module=config-warning");
 641      }
 642  
 643      // User clicked no
 644      if($mybb->get_input('no'))
 645      {
 646          admin_redirect("index.php?module=config-warning");
 647      }
 648  
 649      $plugins->run_hooks("admin_config_warning_delete_type");
 650  
 651      if($mybb->request_method == "post")
 652      {
 653          // Delete the type
 654          $db->delete_query("warningtypes", "tid='{$type['tid']}'");
 655  
 656          $plugins->run_hooks("admin_config_warning_delete_type_commit");
 657  
 658          // Log admin action
 659          log_admin_action($type['tid'], $type['title']);
 660  
 661          flash_message($lang->success_warning_type_deleted, 'success');
 662          admin_redirect("index.php?module=config-warning");
 663      }
 664      else
 665      {
 666          $page->output_confirm_action("index.php?module=config-warning&amp;action=delete_type&amp;tid={$type['tid']}", $lang->confirm_warning_type_deletion);
 667      }
 668  }
 669  
 670  if($mybb->input['action'] == "levels")
 671  {
 672      $plugins->run_hooks("admin_config_warning_levels");
 673  
 674      $page->output_header($lang->warning_levels);
 675  
 676      $page->output_nav_tabs($sub_tabs, 'manage_levels');
 677  
 678      $table = new Table;
 679      $table->construct_header($lang->percentage, array('width' => '5%', 'class' => 'align_center'));
 680      $table->construct_header($lang->action_to_take);
 681      $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2));
 682  
 683      $query = $db->simple_select("warninglevels", "*", "", array('order_by' => 'percentage'));
 684      while($level = $db->fetch_array($query))
 685      {
 686          $table->construct_cell("<strong>{$level['percentage']}%</strong>", array("class" => "align_center"));
 687          $action = my_unserialize($level['action']);
 688          $period = fetch_friendly_expiration($action['length']);
 689  
 690          // Get the right language for the ban period
 691          $lang_str = "expiration_".$period['period'];
 692          $period_str = $lang->$lang_str;
 693          $group_name = '';
 694  
 695          if($action['type'] == 1)
 696          {
 697              $type = "move_banned_group";
 698              $group_name = $groupscache[$action['usergroup']]['title'];
 699          }
 700          elseif($action['type'] == 2)
 701          {
 702              $type = "suspend_posting";
 703          }
 704          elseif($action['type'] == 3)
 705          {
 706              $type = "moderate_new_posts";
 707          }
 708  
 709          if($period['period'] == "never")
 710          {
 711              $type .= "_permanent";
 712  
 713              if($group_name)
 714              {
 715                  // Permanently banned? Oh noes... switch group to the first sprintf replacement...
 716                  $period['time'] = $group_name;
 717              }
 718          }
 719  
 720          // If this level is permanently in place, then $period_str and $group_name do not apply below...
 721          $type = $lang->sprintf($lang->$type, $period['time'], $period_str, $group_name);
 722  
 723          $table->construct_cell($type);
 724          $table->construct_cell("<a href=\"index.php?module=config-warning&amp;action=edit_level&amp;lid={$level['lid']}\">{$lang->edit}</a>", array("width" => 100, "class" => "align_center"));
 725          $table->construct_cell("<a href=\"index.php?module=config-warning&amp;action=delete_level&amp;lid={$level['lid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_warning_level_deletion}')\">{$lang->delete}</a>", array("width" => 100, "class" => "align_center"));
 726          $table->construct_row();
 727      }
 728  
 729      if($table->num_rows() == 0)
 730      {
 731          $table->construct_cell($lang->no_warning_levels, array('colspan' => 4));
 732          $table->construct_row();
 733      }
 734  
 735      $table->output($lang->warning_levels);
 736  
 737      $page->output_footer();
 738  }
 739  
 740  if(!$mybb->input['action'])
 741  {
 742      $plugins->run_hooks("admin_config_warning_start");
 743  
 744      $page->output_header($lang->warning_types);
 745  
 746      $page->output_nav_tabs($sub_tabs, 'manage_types');
 747  
 748      $table = new Table;
 749      $table->construct_header($lang->warning_type);
 750      $table->construct_header($lang->points, array('width' => '5%', 'class' => 'align_center'));
 751      $table->construct_header($lang->expires_after, array('width' => '25%', 'class' => 'align_center'));
 752      $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2));
 753  
 754      $query = $db->simple_select("warningtypes", "*", "", array('order_by' => 'title'));
 755      while($type = $db->fetch_array($query))
 756      {
 757          $type['name'] = htmlspecialchars_uni($type['title']);
 758          $table->construct_cell("<a href=\"index.php?module=config-warning&amp;action=edit_type&amp;tid={$type['tid']}\"><strong>{$type['name']}</strong></a>");
 759          $table->construct_cell("{$type['points']}", array("class" => "align_center"));
 760          $expiration = fetch_friendly_expiration($type['expirationtime']);
 761          $lang_str = "expiration_".$expiration['period'];
 762          if($type['expirationtime'] > 0)
 763          {
 764              $table->construct_cell("{$expiration['time']} {$lang->$lang_str}", array("class" => "align_center"));
 765          }
 766          else
 767          {
 768              $table->construct_cell($lang->never, array("class" => "align_center"));
 769          }
 770          $table->construct_cell("<a href=\"index.php?module=config-warning&amp;action=edit_type&amp;tid={$type['tid']}\">{$lang->edit}</a>", array("width" => 100, "class" => "align_center"));
 771          $table->construct_cell("<a href=\"index.php?module=config-warning&amp;action=delete_type&amp;tid={$type['tid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_warning_type_deletion}')\">{$lang->delete}</a>", array("width" => 100, "class" => "align_center"));
 772          $table->construct_row();
 773      }
 774  
 775      if($table->num_rows() == 0)
 776      {
 777          $table->construct_cell($lang->no_warning_types, array('colspan' => 5));
 778          $table->construct_row();
 779      }
 780  
 781      $table->output($lang->warning_types);
 782  
 783      $page->output_footer();
 784  }


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