[ Index ]

PHP Cross Reference of MyBB 1.8.21

title

Body

[close]

/admin/modules/config/ -> report_reasons.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  $page->add_breadcrumb_item($lang->report_reasons, "index.php?module=config-report_reasons");
  18  
  19  $content_types = array('post', 'profile', 'reputation');
  20  
  21  $content_types = $plugins->run_hooks("report_content_types", $content_types);
  22  
  23  $plugins->run_hooks("admin_config_report_reasons_begin");
  24  
  25  if($mybb->input['action'] == "add")
  26  {
  27      cast_content_inputs();
  28  
  29      $plugins->run_hooks("admin_config_report_reasons_add");
  30  
  31      if($mybb->request_method == "post")
  32      {
  33          if(!trim($mybb->input['title']))
  34          {
  35              $errors[] = $lang->error_missing_title;
  36          }
  37  
  38          if($mybb->input['extra'] != 0 && $mybb->input['extra'] != 1)
  39          {
  40              $errors[] = $lang->error_missing_extra;
  41          }
  42  
  43          if(!$errors)
  44          {
  45              if($mybb->input['appliesto'] != 'all')
  46              {
  47                  $appliesto = array();
  48                  asort($content_types);
  49                  foreach($content_types as $content)
  50                  {
  51                      if($mybb->input["appliesto_{$content}"] == 1)
  52                      {
  53                          $appliesto[] = $content;
  54                      }
  55                  }
  56                  $appliesto = implode(",", $appliesto);
  57              }
  58              else
  59              {
  60                  $appliesto = 'all';
  61              }
  62  
  63              $new_reason = array(
  64                  "title" => $db->escape_string($mybb->input['title']),
  65                  "appliesto" => $db->escape_string($appliesto),
  66                  "extra" => $mybb->input['extra']
  67              );
  68              $rid = $db->insert_query("reportreasons", $new_reason);
  69  
  70              $plugins->run_hooks("admin_config_report_reasons_add_commit");
  71  
  72              $cache->update_reportreasons();
  73  
  74              // Log admin action
  75              log_admin_action($rid, $mybb->input['title']);
  76  
  77              flash_message($lang->success_reason_created, 'success');
  78              admin_redirect("index.php?module=config-report_reasons");
  79          }
  80      }
  81  
  82      $page->add_breadcrumb_item($lang->add_new_reason);
  83      $page->output_header($lang->report_reasons." - ".$lang->add_new_reason);
  84  
  85      $sub_tabs['report_reasons'] = array(
  86          'title' => $lang->report_reasons,
  87          'link' => "index.php?module=config-report_reasons"
  88      );
  89  
  90      $sub_tabs['add_new_reason'] = array(
  91          'title' => $lang->add_new_reason,
  92          'link' => "index.php?module=config-report_reasons&amp;action=add",
  93          'description' => $lang->add_new_reason_desc
  94      );
  95  
  96      $page->output_nav_tabs($sub_tabs, 'add_new_reason');
  97  
  98      $form = new Form("index.php?module=config-report_reasons&amp;action=add", "post", "add");
  99  
 100      if($errors)
 101      {
 102          $page->output_inline_error($errors);
 103      }
 104      else
 105      {
 106          $mybb->input['extra'] = 0;
 107      }
 108  
 109      $form_container = new FormContainer($lang->add_new_reason);
 110      $form_container->output_row($lang->reason_title." <em>*</em>", $lang->reason_title_desc, $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 111      $form_container->output_row($lang->applies_to." <em>*</em>", $lang->applies_to_desc, generate_content_select());
 112      $form_container->output_row($lang->requires_extra." <em>*</em>", $lang->requires_extra_desc, $form->generate_yes_no_radio('extra', $mybb->input['extra']));
 113      $form_container->end();
 114  
 115      $buttons[] = $form->generate_submit_button($lang->save_reason);
 116  
 117      $form->output_submit_wrapper($buttons);
 118      $form->end();
 119  
 120      $page->output_footer();
 121  }
 122  
 123  if($mybb->input['action'] == "edit")
 124  {
 125      $query = $db->simple_select("reportreasons", "*", "rid='".$mybb->get_input('rid', MyBB::INPUT_INT)."'");
 126      $reason = $db->fetch_array($query);
 127  
 128      if(!$reason['rid'])
 129      {
 130          flash_message($lang->error_invalid_reason, 'error');
 131          admin_redirect("index.php?module=config-report_reasons");
 132      }
 133      elseif($reason['rid'] == 1)
 134      {
 135          flash_message($lang->error_cannot_modify_reason, 'error');
 136          admin_redirect("index.php?module=config-report_reasons");
 137      }
 138  
 139      cast_content_inputs();
 140  
 141      $plugins->run_hooks("admin_config_report_reasons_edit");
 142  
 143      if($mybb->request_method == "post")
 144      {
 145          if(!trim($mybb->input['title']))
 146          {
 147              $errors[] = $lang->error_missing_title;
 148          }
 149  
 150          if($mybb->input['extra'] != 0 && $mybb->input['extra'] != 1)
 151          {
 152              $errors[] = $lang->error_missing_extra;
 153          }
 154  
 155          if(!$errors)
 156          {
 157              if($mybb->input['appliesto'] != 'all')
 158              {
 159                  $appliesto = array();
 160                  asort($content_types);
 161                  foreach($content_types as $content)
 162                  {
 163                      if($mybb->input["appliesto_{$content}"] == 1)
 164                      {
 165                          $appliesto[] = $content;
 166                      }
 167                  }
 168                  $appliesto = implode(",", $appliesto);
 169              }
 170              else
 171              {
 172                  $appliesto = 'all';
 173              }
 174  
 175              $updated_reason = array(
 176                  "title" => $db->escape_string($mybb->input['title']),
 177                  "appliesto" => $db->escape_string($appliesto),
 178                  "extra" => $mybb->input['extra']
 179              );
 180  
 181              $plugins->run_hooks("admin_config_report_reasons_edit_commit");
 182  
 183              $db->update_query("reportreasons", $updated_reason, "rid='{$reason['rid']}'");
 184  
 185              $cache->update_reportreasons();
 186  
 187              // Log admin action
 188              log_admin_action($reason['rid'], $mybb->input['title']);
 189  
 190              flash_message($lang->success_reason_updated, 'success');
 191              admin_redirect("index.php?module=config-report_reasons");
 192          }
 193      }
 194  
 195      $page->add_breadcrumb_item($lang->edit_reason);
 196      $page->output_header($lang->report_reasons." - ".$lang->edit_reason);
 197  
 198      $sub_tabs['edit_reason'] = array(
 199          'title' => $lang->edit_reason,
 200          'link' => "index.php?module=config-report_reasons&amp;action=edit&amp;rid={$reason['rid']}",
 201          'description' => $lang->edit_reason_desc
 202      );
 203  
 204      $page->output_nav_tabs($sub_tabs, 'edit_reason');
 205  
 206      $form = new Form("index.php?module=config-report_reasons&amp;action=edit&amp;rid={$reason['rid']}", "post", "add");
 207  
 208      if($errors)
 209      {
 210          $page->output_inline_error($errors);
 211      }
 212      else
 213      {
 214          $mybb->input = $reason;
 215          $appliesto = explode(",", $reason['appliesto']);
 216          foreach($appliesto as $content)
 217          {
 218              $mybb->input["appliesto_{$content}"] = 1;
 219          }
 220      }
 221  
 222      $form_container = new FormContainer($lang->add_new_reason);
 223      $form_container->output_row($lang->reason_title." <em>*</em>", $lang->reason_title_desc, $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 224      $form_container->output_row($lang->applies_to." <em>*</em>", $lang->applies_to_desc, generate_content_select());
 225      $form_container->output_row($lang->requires_extra." <em>*</em>", $lang->requires_extra_desc, $form->generate_yes_no_radio('extra', $mybb->input['extra']));
 226      $form_container->end();
 227  
 228      $buttons[] = $form->generate_submit_button($lang->save_reason);
 229  
 230      $form->output_submit_wrapper($buttons);
 231      $form->end();
 232  
 233      $page->output_footer();
 234  }
 235  
 236  if($mybb->input['action'] == "delete")
 237  {
 238      if($mybb->input['no'])
 239      {
 240          admin_redirect("index.php?module=config-report_reasons");
 241      }
 242  
 243      $query = $db->simple_select("reportreasons", "*", "rid='".$mybb->get_input('rid', MyBB::INPUT_INT)."'");
 244      $reason = $db->fetch_array($query);
 245  
 246      if(!$reason['rid'])
 247      {
 248          flash_message($lang->error_invalid_reason, 'error');
 249          admin_redirect("index.php?module=config-report_reasons");
 250      }
 251      elseif($reason['rid'] == 1)
 252      {
 253          flash_message($lang->error_cannot_delete_reason, 'error');
 254          admin_redirect("index.php?module=config-report_reasons");
 255      }
 256  
 257      $plugins->run_hooks("admin_config_report_reasons_delete");
 258  
 259      if($mybb->request_method == "post")
 260      {
 261  
 262          // Change the reason of associated reports to Other and carry over the title
 263          $updated_report = array(
 264              'reasonid' => 1,
 265              'reason' => $db->escape_string($reason['title'])
 266          );
 267          $db->update_query("reportedcontent", $updated_report, "reasonid='{$reason['rid']}'");
 268  
 269          $db->delete_query("reportreasons", "rid='{$reason['rid']}'");
 270  
 271          $plugins->run_hooks("admin_config_report_reasons_delete_commit");
 272  
 273          // Log admin action
 274          log_admin_action($reason['rid'], $reason['title']);
 275  
 276          flash_message($lang->success_reason_deleted, 'success');
 277          admin_redirect("index.php?module=config-report_reasons");
 278      }
 279      else
 280      {
 281          $page->output_confirm_action("index.php?module=config-report_reasons&amp;action=delete&amp;rid={$reason['rid']}", $lang->confirm_reason_deletion);
 282      }
 283  }
 284  
 285  if(!$mybb->input['action'])
 286  {
 287      $plugins->run_hooks("admin_config_report_reasons_start");
 288  
 289      if($mybb->request_method == "post")
 290      {
 291          if(!empty($mybb->input['disporder']))
 292          {
 293              foreach($mybb->input['disporder'] as $rid => $order)
 294              {
 295                  $db->update_query("reportreasons", array('disporder' => (int)$order), "rid='".(int)$rid."'");
 296              }
 297  
 298              $plugins->run_hooks("admin_config_report_reasons_start_commit");
 299  
 300              $cache->update_reportreasons();
 301  
 302              flash_message($lang->success_reasons_disporder_updated, 'success');
 303              admin_redirect("index.php?module=config-report_reasons");
 304          }
 305      }
 306  
 307      $page->output_header($lang->report_reasons);
 308  
 309      $sub_tabs['report_reasons'] = array(
 310          'title' => $lang->report_reasons,
 311          'link' => "index.php?module=config-report_reasons",
 312          'description' => $lang->report_reasons_desc
 313      );
 314      $sub_tabs['add_new_reason'] = array(
 315          'title' => $lang->add_new_reason,
 316          'link' => "index.php?module=config-report_reasons&amp;action=add",
 317      );
 318  
 319      $page->output_nav_tabs($sub_tabs, 'report_reasons');
 320  
 321      $form = new Form("index.php?module=config-report_reasons", "post", "reasons");
 322  
 323      $form_container = new FormContainer($lang->report_reasons);
 324      $form_container->output_row_header($lang->reason_title);
 325      $form_container->output_row_header($lang->applies_to, array("width" => "35%"));
 326      $form_container->output_row_header($lang->extra_comment, array("width" => "10%", "class" => "align_center"));
 327      $form_container->output_row_header($lang->order, array("width" => "5%", "class" => "align_center"));
 328      $form_container->output_row_header($lang->controls, array("class" => "align_center", "width" => 150));
 329  
 330      $query = $db->simple_select("reportreasons", "*", "", array('order_by' => 'disporder'));
 331      while($reasons = $db->fetch_array($query))
 332      {
 333          $reasons['title'] = $lang->parse($reasons['title']);
 334  
 335          $reasons['appliesto'] = explode(",", $reasons['appliesto']);
 336  
 337          $appliesto = array();
 338          foreach($reasons['appliesto'] as $content)
 339          {
 340              $key = "report_content_".$content;
 341              $appliesto[] = $lang->$key;
 342          }
 343          $reasons['appliesto'] = implode(", ", $appliesto);
 344  
 345          if($reasons['extra'] == 1)
 346          {
 347              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.png\" alt=\"({$lang->yes})\" title=\"{$lang->yes}\"  style=\"vertical-align: middle;\" /> ";
 348          }
 349          else
 350          {
 351              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.png\" alt=\"({$lang->no})\" title=\"{$lang->no}\"  style=\"vertical-align: middle;\" /> ";
 352          }
 353  
 354          $form_container->output_cell(htmlspecialchars_uni($reasons['title']));
 355          $form_container->output_cell(htmlspecialchars_uni($reasons['appliesto']));
 356          $form_container->output_cell("<div>{$icon}</div>", array("class" => "align_center"));
 357          $form_container->output_cell("<input type=\"text\" name=\"disporder[{$reasons['rid']}]\" value=\"{$reasons['disporder']}\" class=\"text_input align_center\" style=\"width: 80%;\" />", array("class" => "align_center"));
 358          $popup = new PopupMenu("reasons_{$reasons['rid']}", $lang->options);
 359          $popup->add_item($lang->edit_reason, "index.php?module=config-report_reasons&amp;action=edit&amp;rid={$reasons['rid']}");
 360          $popup->add_item($lang->delete_reason, "index.php?module=config-report_reasons&amp;action=delete&amp;rid={$reasons['rid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_reason_deletion}')");
 361          $form_container->output_cell($popup->fetch(), array("class" => "align_center"));
 362          $form_container->construct_row();
 363      }
 364  
 365      if($form_container->num_rows() == 0)
 366      {
 367          $form_container->construct_cell($lang->no_report_reasons, array('colspan' => 5));
 368          $form_container->construct_row();
 369      }
 370  
 371      $form_container->end();
 372  
 373      $buttons = array();
 374      $buttons[] = $form->generate_submit_button($lang->update_reasons_order);
 375      $form->output_submit_wrapper($buttons);
 376  
 377      $form->end();
 378  
 379      $page->output_footer();
 380  }
 381  
 382  function generate_content_select()
 383  {
 384      global $mybb, $lang;
 385  
 386      $checked = array('all' => '', 'custom' => '', 'none' => '');
 387      if($mybb->input['appliesto'] == 'all')
 388      {
 389          $checked['all'] = 'checked="checked"';
 390      }
 391      elseif($mybb->input['appliesto'] == '')
 392      {
 393          $checked['none'] = 'checked="checked"';
 394      }
 395      else
 396      {
 397          $checked['custom'] = 'checked="checked"';
 398      }
 399  
 400      print_selection_javascript();
 401  
 402      return "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
 403                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"appliesto\" value=\"all\" {$checked['all']} class=\"appliesto_forums_groups_check\" onclick=\"checkAction('appliesto');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_content}</strong></label></dt>
 404                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"appliesto\" value=\"custom\" {$checked['custom']} class=\"appliesto_forums_groups_check\" onclick=\"checkAction('appliesto');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_content}</strong></label></dt>
 405                      <dd style=\"margin-top: 4px;\" id=\"appliesto_forums_groups_custom\" class=\"appliesto_forums_groups\">
 406                          <table cellpadding=\"4\">
 407                              <tr>
 408                                  <td valign=\"top\"><small>{$lang->content_colon}</small></td>
 409                                  <td>".implode("<br />", generate_content_choices())."</td>
 410                              </tr>
 411                          </table>
 412                      </dd>
 413                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"appliesto\" value=\"none\" {$checked['none']} class=\"appliesto_forums_groups_check\" onclick=\"checkAction('appliesto');\" style=\"vertical-align: middle;\" /> <strong>{$lang->none}</strong></label></dt>
 414                  </dl>
 415                  <script type=\"text/javascript\">
 416                      checkAction('appliesto');
 417                  </script>";
 418  }
 419  
 420  function generate_content_choices()
 421  {
 422      global $mybb, $lang, $form, $content_types;
 423  
 424      asort($content_types);
 425  
 426      $content_choices = array();
 427      foreach($content_types as $content)
 428      {
 429          $key = "report_content_{$content}";
 430          $content_choices[] = $form->generate_check_box("appliesto_{$content}", 1, $lang->$key, array('id' => "appliesto_{$content}", 'checked' => $mybb->input["appliesto_{$content}"]));
 431      }
 432  
 433      return $content_choices;
 434  }
 435  
 436  function cast_content_inputs()
 437  {
 438      global $mybb, $content_types;
 439  
 440      asort($content_types);
 441  
 442      foreach($content_types as $content)
 443      {
 444          $key = "appliesto_{$content}";
 445          $mybb->input[$key] = $mybb->get_input($key, MyBB::INPUT_INT);
 446      }
 447  
 448      $mybb->input['extra'] = $mybb->get_input('extra', MyBB::INPUT_INT);
 449  }


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