[ Index ]

PHP Cross Reference of MyBB 1.8.39

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


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