[ Index ]

PHP Cross Reference of MyBB 1.8.38

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->get_input('title'), array('id' => 'title')), 'title');
 111      $form_container->output_row($lang->applies_to." <em>*</em>", '', 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)
 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->edit_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>", '', 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->get_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)
 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          $cache->update_reportreasons();
 274  
 275          // Log admin action
 276          log_admin_action($reason['rid'], $reason['title']);
 277  
 278          flash_message($lang->success_reason_deleted, 'success');
 279          admin_redirect("index.php?module=config-report_reasons");
 280      }
 281      else
 282      {
 283          $page->output_confirm_action("index.php?module=config-report_reasons&amp;action=delete&amp;rid={$reason['rid']}", $lang->confirm_reason_deletion);
 284      }
 285  }
 286  
 287  if(!$mybb->input['action'])
 288  {
 289      $plugins->run_hooks("admin_config_report_reasons_start");
 290  
 291      if($mybb->request_method == "post")
 292      {
 293          if(!empty($mybb->input['disporder']))
 294          {
 295              foreach($mybb->input['disporder'] as $rid => $order)
 296              {
 297                  $db->update_query("reportreasons", array('disporder' => (int)$order), "rid='".(int)$rid."'");
 298              }
 299  
 300              $plugins->run_hooks("admin_config_report_reasons_start_commit");
 301  
 302              $cache->update_reportreasons();
 303  
 304              flash_message($lang->success_reasons_disporder_updated, 'success');
 305              admin_redirect("index.php?module=config-report_reasons");
 306          }
 307      }
 308  
 309      $page->output_header($lang->report_reasons);
 310  
 311      $sub_tabs['report_reasons'] = array(
 312          'title' => $lang->report_reasons,
 313          'link' => "index.php?module=config-report_reasons",
 314          'description' => $lang->report_reasons_desc
 315      );
 316      $sub_tabs['add_new_reason'] = array(
 317          'title' => $lang->add_new_reason,
 318          'link' => "index.php?module=config-report_reasons&amp;action=add",
 319      );
 320  
 321      $page->output_nav_tabs($sub_tabs, 'report_reasons');
 322  
 323      $form = new Form("index.php?module=config-report_reasons", "post", "reasons");
 324  
 325      $form_container = new FormContainer($lang->report_reasons);
 326      $form_container->output_row_header($lang->reason_title);
 327      $form_container->output_row_header($lang->applies_to, array("width" => "35%"));
 328      $form_container->output_row_header($lang->extra_comment, array("width" => "10%", "class" => "align_center"));
 329      $form_container->output_row_header($lang->order, array("width" => "5%", "class" => "align_center"));
 330      $form_container->output_row_header($lang->controls, array("class" => "align_center", "width" => 150));
 331  
 332      $query = $db->simple_select("reportreasons", "*", "", array('order_by' => 'disporder'));
 333      while($reasons = $db->fetch_array($query))
 334      {
 335          $reasons['title'] = $lang->parse($reasons['title']);
 336  
 337          $reasons['appliesto'] = explode(",", $reasons['appliesto']);
 338  
 339          $appliesto = array();
 340          foreach($reasons['appliesto'] as $content)
 341          {
 342              $key = "report_content_".$content;
 343              $appliesto[] = $lang->$key;
 344          }
 345          $reasons['appliesto'] = implode(", ", $appliesto);
 346  
 347          if($reasons['extra'] == 1)
 348          {
 349              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.png\" alt=\"({$lang->yes})\" title=\"{$lang->yes}\"  style=\"vertical-align: middle;\" /> ";
 350          }
 351          else
 352          {
 353              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.png\" alt=\"({$lang->no})\" title=\"{$lang->no}\"  style=\"vertical-align: middle;\" /> ";
 354          }
 355  
 356          $form_container->output_cell(htmlspecialchars_uni($reasons['title']));
 357          $form_container->output_cell(htmlspecialchars_uni($reasons['appliesto']));
 358          $form_container->output_cell("<div>{$icon}</div>", array("class" => "align_center"));
 359          $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"));
 360          $popup = new PopupMenu("reasons_{$reasons['rid']}", $lang->options);
 361          $popup->add_item($lang->edit_reason, "index.php?module=config-report_reasons&amp;action=edit&amp;rid={$reasons['rid']}");
 362          $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}')");
 363          $form_container->output_cell($popup->fetch(), array("class" => "align_center"));
 364          $form_container->construct_row();
 365      }
 366  
 367      if($form_container->num_rows() == 0)
 368      {
 369          $form_container->output_cell($lang->no_report_reasons, array('colspan' => 5));
 370          $form_container->construct_row();
 371      }
 372  
 373      $form_container->end();
 374  
 375      $buttons = array();
 376      $buttons[] = $form->generate_submit_button($lang->update_reasons_order);
 377      $form->output_submit_wrapper($buttons);
 378  
 379      $form->end();
 380  
 381      $page->output_footer();
 382  }
 383  
 384  function generate_content_select()
 385  {
 386      global $mybb, $lang;
 387  
 388      $checked = array('all' => '', 'custom' => '', 'none' => '');
 389      if($mybb->get_input('appliesto') == 'all')
 390      {
 391          $checked['all'] = 'checked="checked"';
 392      }
 393      elseif($mybb->get_input('appliesto') == '')
 394      {
 395          $checked['none'] = 'checked="checked"';
 396      }
 397      else
 398      {
 399          $checked['custom'] = 'checked="checked"';
 400      }
 401  
 402      print_selection_javascript();
 403  
 404      return "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
 405                      <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>
 406                      <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>
 407                      <dd style=\"margin-top: 4px;\" id=\"appliesto_forums_groups_custom\" class=\"appliesto_forums_groups\">
 408                          <table cellpadding=\"4\">
 409                              <tr>
 410                                  <td valign=\"top\"><small>{$lang->content_colon}</small></td>
 411                                  <td>".implode("<br />", generate_content_choices())."</td>
 412                              </tr>
 413                          </table>
 414                      </dd>
 415                      <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>
 416                  </dl>
 417                  <script type=\"text/javascript\">
 418                      checkAction('appliesto');
 419                  </script>";
 420  }
 421  
 422  function generate_content_choices()
 423  {
 424      global $mybb, $lang, $form, $content_types;
 425  
 426      asort($content_types);
 427  
 428      $content_choices = array();
 429      foreach($content_types as $content)
 430      {
 431          $key = "report_content_{$content}";
 432          $content_choices[] = $form->generate_check_box("appliesto_{$content}", 1, $lang->$key, array('id' => "appliesto_{$content}", 'checked' => $mybb->get_input("appliesto_{$content}")));
 433      }
 434  
 435      return $content_choices;
 436  }
 437  
 438  function cast_content_inputs()
 439  {
 440      global $mybb, $content_types;
 441  
 442      asort($content_types);
 443  
 444      foreach($content_types as $content)
 445      {
 446          $key = "appliesto_{$content}";
 447          $mybb->input[$key] = $mybb->get_input($key, MyBB::INPUT_INT);
 448      }
 449  
 450      $mybb->input['extra'] = $mybb->get_input('extra', MyBB::INPUT_INT);
 451  }


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