[ Index ]

PHP Cross Reference of MyBB 1.8.30

title

Body

[close]

/admin/modules/config/ -> mod_tools.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->mod_tools, "index.php?module=config-mod_tools");
  18  
  19  $plugins->run_hooks("admin_config_mod_tools_begin");
  20  
  21  if($mybb->input['action'] == "delete_post_tool")
  22  {
  23      $query = $db->simple_select("modtools", "*", "tid='{$mybb->input['tid']}'");
  24      $tool = $db->fetch_array($query);
  25  
  26      // Does the post tool not exist?
  27      if(!$tool['tid'])
  28      {
  29          flash_message($lang->error_invalid_post_tool, 'error');
  30          admin_redirect("index.php?module=config-mod_tools&action=post_tools");
  31      }
  32  
  33      // User clicked no
  34      if($mybb->get_input('no'))
  35      {
  36          admin_redirect("index.php?module=config-mod_tools&action=post_tools");
  37      }
  38  
  39      $plugins->run_hooks("admin_config_mod_tools_delete_post_tool");
  40  
  41      if($mybb->request_method == 'post')
  42      {
  43          // Delete the type
  44          $db->delete_query('modtools', "tid='{$tool['tid']}'");
  45  
  46          $plugins->run_hooks("admin_config_mod_tools_delete_post_tool_commit");
  47  
  48          // Log admin action
  49          log_admin_action($tool['tid'], $tool['name']);
  50          $cache->update_forumsdisplay();
  51  
  52          flash_message($lang->success_post_tool_deleted, 'success');
  53          admin_redirect("index.php?module=config-mod_tools&action=post_tools");
  54      }
  55      else
  56      {
  57          $page->output_confirm_action("index.php?module=config-mod_tools&amp;action=post_tools&amp;tid={$type['tid']}", $lang->confirm_post_tool_deletion);
  58      }
  59  }
  60  
  61  if($mybb->input['action'] == "delete_thread_tool")
  62  {
  63      $query = $db->simple_select("modtools", "*", "tid='{$mybb->input['tid']}'");
  64      $tool = $db->fetch_array($query);
  65  
  66      // Does the post tool not exist?
  67      if(!$tool['tid'])
  68      {
  69          flash_message($lang->error_invalid_thread_tool, 'error');
  70          admin_redirect("index.php?module=config-mod_tools");
  71      }
  72  
  73      // User clicked no
  74      if($mybb->get_input('no'))
  75      {
  76          admin_redirect("index.php?module=config-mod_tools");
  77      }
  78  
  79      $plugins->run_hooks("admin_config_mod_tools_delete_thread_tool");
  80  
  81      if($mybb->request_method == 'post')
  82      {
  83          // Delete the type
  84          $db->delete_query('modtools', "tid='{$tool['tid']}'");
  85  
  86          $plugins->run_hooks("admin_config_mod_tools_delete_thread_tool_commit");
  87  
  88          // Log admin action
  89          log_admin_action($tool['tid'], $tool['name']);
  90          $cache->update_forumsdisplay();
  91  
  92          flash_message($lang->success_thread_tool_deleted, 'success');
  93          admin_redirect("index.php?module=config-mod_tools");
  94      }
  95      else
  96      {
  97          $page->output_confirm_action("index.php?module=config-mod_tools&amp;action=delete_thread_tool&amp;tid={$tool['tid']}", $lang->confirm_thread_tool_deletion);
  98      }
  99  }
 100  
 101  if($mybb->input['action'] == "post_tools")
 102  {
 103      $plugins->run_hooks("admin_config_mod_tools_post_tools");
 104  
 105      $page->add_breadcrumb_item($lang->post_tools);
 106      $page->output_header($lang->mod_tools." - ".$lang->post_tools);
 107  
 108      $sub_tabs['thread_tools'] = array(
 109          'title' => $lang->thread_tools,
 110          'link' => "index.php?module=config-mod_tools"
 111      );
 112      $sub_tabs['add_thread_tool'] = array(
 113          'title'=> $lang->add_thread_tool,
 114          'link' => "index.php?module=config-mod_tools&amp;action=add_thread_tool"
 115      );
 116      $sub_tabs['post_tools'] = array(
 117          'title' => $lang->post_tools,
 118          'link' => "index.php?module=config-mod_tools&amp;action=post_tools",
 119          'description' => $lang->post_tools_desc
 120      );
 121      $sub_tabs['add_post_tool'] = array(
 122          'title'=> $lang->add_post_tool,
 123          'link' => "index.php?module=config-mod_tools&amp;action=add_post_tool"
 124      );
 125  
 126      $page->output_nav_tabs($sub_tabs, 'post_tools');
 127  
 128      $table = new Table;
 129      $table->construct_header($lang->title);
 130      $table->construct_header($lang->controls, array('class' => "align_center", 'colspan' => 2));
 131  
 132      $query = $db->simple_select('modtools', 'tid, name, description, type', "type='p'", array('order_by' => 'name'));
 133      while($tool = $db->fetch_array($query))
 134      {
 135          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=edit_post_tool&amp;tid={$tool['tid']}\"><strong>".htmlspecialchars_uni($tool['name'])."</strong></a><br /><small>".htmlspecialchars_uni($tool['description'])."</small>");
 136          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=edit_post_tool&amp;tid={$tool['tid']}\">{$lang->edit}</a>", array('width' => 100, 'class' => "align_center"));
 137          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=delete_post_tool&amp;tid={$tool['tid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_post_tool_deletion}')\">{$lang->delete}</a>", array('width' => 100, 'class' => "align_center"));
 138          $table->construct_row();
 139      }
 140  
 141      if($table->num_rows() == 0)
 142      {
 143          $table->construct_cell($lang->no_post_tools, array('colspan' => 3));
 144          $table->construct_row();
 145      }
 146  
 147      $table->output($lang->post_tools);
 148  
 149      $page->output_footer();
 150  }
 151  
 152  if($mybb->input['action'] == "edit_thread_tool")
 153  {
 154      $query = $db->simple_select("modtools", "COUNT(tid) as tools", "tid = '{$mybb->input['tid']}' AND type='t'");
 155      if($db->fetch_field($query, "tools") < 1)
 156      {
 157          flash_message($lang->error_invalid_thread_tool, 'error');
 158          admin_redirect("index.php?module=config-mod_tools");
 159      }
 160  
 161      $plugins->run_hooks("admin_config_mod_tools_edit_thread_tool");
 162  
 163      if($mybb->request_method == 'post')
 164      {
 165          if(trim($mybb->input['title']) == "")
 166          {
 167              $errors[] = $lang->error_missing_title;
 168          }
 169  
 170          if(trim($mybb->input['description']) == "")
 171          {
 172              $errors[] = $lang->error_missing_description;
 173          }
 174  
 175          if($mybb->input['forum_type'] == 2)
 176          {
 177              $forum_checked[1] = '';
 178              $forum_checked[2] = "checked=\"checked\"";
 179  
 180              if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1)
 181              {
 182                  $errors[] = $lang->error_no_forums_selected;
 183              }
 184          }
 185          else
 186          {
 187              $forum_checked[1] = "checked=\"checked\"";
 188              $forum_checked[2] = '';
 189  
 190              $mybb->input['forum_1_forums'] = '';
 191          }
 192  
 193          if($mybb->input['group_type'] == 2)
 194          {
 195              $group_checked[1] = '';
 196              $group_checked[2] = "checked=\"checked\"";
 197  
 198              if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1)
 199              {
 200                  $errors[] = $lang->error_no_groups_selected;
 201              }
 202          }
 203          else
 204          {
 205              $group_checked[1] = "checked=\"checked\"";
 206              $group_checked[2] = '';
 207  
 208              $mybb->input['group_1_groups'] = '';
 209          }
 210  
 211          if($mybb->input['approvethread'] != '' && $mybb->input['approvethread'] != 'approve' && $mybb->input['approvethread'] != 'unapprove' && $mybb->input['approvethread'] != 'toggle')
 212          {
 213              $mybb->input['approvethread'] = '';
 214          }
 215  
 216          if($mybb->input['softdeletethread'] != '' && $mybb->input['softdeletethread'] != 'softdelete' && $mybb->input['softdeletethread'] != 'restore' && $mybb->input['softdeletethread'] != 'toggle')
 217          {
 218              $mybb->input['softdeletethread'] = '';
 219          }
 220  
 221          if($mybb->input['openthread'] != '' && $mybb->input['openthread'] != 'open' && $mybb->input['openthread'] != 'close' && $mybb->input['openthread'] != 'toggle')
 222          {
 223              $mybb->input['openthread'] = '';
 224          }
 225  
 226          if($mybb->input['stickthread'] != '' && $mybb->input['stickthread'] != 'stick' && $mybb->input['stickthread'] != 'unstick' && $mybb->input['stickthread'] != 'toggle')
 227          {
 228              $mybb->input['stickthread'] = '';
 229          }
 230  
 231          if($mybb->input['move_type'] == 2)
 232          {
 233              $move_checked[1] = '';
 234              $move_checked[2] = "checked=\"checked\"";
 235  
 236              if(!$mybb->input['move_1_forum'])
 237              {
 238                  $errors[] = $lang->error_no_move_forum_selected;
 239              }
 240              else
 241              {
 242                  // Check that the destination forum is not a category
 243                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('move_1_forum', MyBB::INPUT_INT)."'");
 244                  if($db->fetch_field($query, "type") == "c")
 245                  {
 246                      $errors[] = $lang->error_forum_is_category;
 247                  }
 248              }
 249  
 250              if($mybb->input['move_2_redirect'] != 1 && $mybb->input['move_2_redirect'] != 0)
 251              {
 252                  $mybb->input['move_2_redirect'] = 0;
 253              }
 254  
 255              if(!isset($mybb->input['move_3_redirecttime']))
 256              {
 257                  $mybb->input['move_3_redirecttime'] = '';
 258              }
 259          }
 260          else
 261          {
 262              $move_checked[1] = "checked=\"checked\"";
 263              $move_checked[2] = '';
 264  
 265              $mybb->input['move_1_forum'] = '';
 266              $mybb->input['move_2_redirect'] = 0;
 267              $mybb->input['move_3_redirecttime'] = '';
 268          }
 269  
 270          if($mybb->input['copy_type'] == 2)
 271          {
 272              $copy_checked[1] = '';
 273              $copy_checked[2] = "checked=\"checked\"";
 274  
 275              if(!$mybb->input['copy_1_forum'])
 276              {
 277                  $errors[] = $lang->error_no_copy_forum_selected;
 278              }
 279              else
 280              {
 281                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('copy_1_forum', MyBB::INPUT_INT)."'");
 282                  if($db->fetch_field($query, "type") == "c")
 283                  {
 284                      $errors[] = $lang->error_forum_is_category;
 285                  }
 286              }
 287          }
 288          else
 289          {
 290              $copy_checked[1] = "checked=\"checked\"";
 291              $copy_checked[2] = '';
 292  
 293              $mybb->input['copy_1_forum'] = '';
 294          }
 295  
 296          if(!$errors)
 297          {
 298              $thread_options = array(
 299                  'confirmation' => $mybb->get_input('confirmation', MyBB::INPUT_INT),
 300                  'deletethread' => $mybb->get_input('deletethread', MyBB::INPUT_INT),
 301                  'mergethreads' => $mybb->get_input('mergethreads', MyBB::INPUT_INT),
 302                  'deletepoll' => $mybb->get_input('deletepoll', MyBB::INPUT_INT),
 303                  'removeredirects' => $mybb->get_input('removeredirects', MyBB::INPUT_INT),
 304                  'removesubscriptions' => $mybb->get_input('removesubscriptions', MyBB::INPUT_INT),
 305                  'recountrebuild' => $mybb->get_input('recountrebuild', MyBB::INPUT_INT),
 306                  'approvethread' => $mybb->input['approvethread'],
 307                  'softdeletethread' => $mybb->input['softdeletethread'],
 308                  'openthread' => $mybb->input['openthread'],
 309                  'stickthread' => $mybb->input['stickthread'],
 310                  'movethread' => $mybb->get_input('move_1_forum', MyBB::INPUT_INT),
 311                  'movethreadredirect' => $mybb->get_input('move_2_redirect', MyBB::INPUT_INT),
 312                  'movethreadredirectexpire' => $mybb->get_input('move_3_redirecttime', MyBB::INPUT_INT),
 313                  'copythread' => $mybb->get_input('copy_1_forum', MyBB::INPUT_INT),
 314                  'newsubject' => $mybb->input['newsubject'],
 315                  'addreply' => $mybb->input['newreply'],
 316                  'replysubject' => $mybb->input['newreplysubject'],
 317                  'pm_subject' => $mybb->input['pm_subject'],
 318                  'pm_message' => $mybb->input['pm_message'],
 319                  'threadprefix' => $mybb->get_input('threadprefix', MyBB::INPUT_INT)
 320              );
 321  
 322              $args = array(
 323                  'thread_options' => &$thread_options,
 324              );
 325  
 326              $plugins->run_hooks("admin_config_mod_tools_edit_thread_tool_options", $args);
 327  
 328              $update_tool['type'] = 't';
 329              $update_tool['threadoptions'] = $db->escape_string(my_serialize($thread_options));
 330              $update_tool['name'] = $db->escape_string($mybb->input['title']);
 331              $update_tool['description'] = $db->escape_string($mybb->input['description']);
 332              $update_tool['forums'] = '';
 333              $update_tool['groups'] = '';
 334  
 335              if($mybb->input['forum_type'] == 2)
 336              {
 337                  if(is_array($mybb->input['forum_1_forums']))
 338                  {
 339                      $checked = array();
 340  
 341                      foreach($mybb->input['forum_1_forums'] as $fid)
 342                      {
 343                          $checked[] = (int)$fid;
 344                      }
 345  
 346                      $update_tool['forums'] = implode(',', $checked);
 347                  }
 348              }
 349              else
 350              {
 351                  $update_tool['forums'] = "-1";
 352              }
 353  
 354              if($mybb->input['group_type'] == 2)
 355              {
 356                  if(is_array($mybb->input['group_1_groups']))
 357                  {
 358                      $checked = array();
 359  
 360                      foreach($mybb->input['group_1_groups'] as $gid)
 361                      {
 362                          $checked[] = (int)$gid;
 363                      }
 364  
 365                      $update_tool['groups'] = implode(',', $checked);
 366                  }
 367              }
 368              else
 369              {
 370                  $update_tool['groups'] = "-1";
 371              }
 372  
 373              $plugins->run_hooks("admin_config_mod_tools_edit_thread_tool_commit");
 374  
 375              $db->update_query("modtools", $update_tool, "tid='{$mybb->input['tid']}'");
 376  
 377              // Log admin action
 378              log_admin_action($mybb->input['tid'], $mybb->input['title']);
 379              $cache->update_forumsdisplay();
 380  
 381              flash_message($lang->success_mod_tool_updated, 'success');
 382              admin_redirect("index.php?module=config-mod_tools");
 383          }
 384      }
 385  
 386      $page->add_breadcrumb_item($lang->edit_thread_tool);
 387      $page->output_header($lang->mod_tools." - ".$lang->edit_thread_tool);
 388  
 389      $sub_tabs['edit_thread_tool'] = array(
 390          "title" => $lang->edit_thread_tool,
 391          "description" => $lang->edit_thread_tool_desc,
 392          "link" => "index.php?module=config-mod_tools"
 393      );
 394  
 395      $page->output_nav_tabs($sub_tabs, 'edit_thread_tool');
 396  
 397      $form = new Form("index.php?module=config-mod_tools&amp;action=edit_thread_tool", 'post');
 398      echo $form->generate_hidden_field("tid", $mybb->input['tid']);
 399  
 400      if($errors)
 401      {
 402          $page->output_inline_error($errors);
 403      }
 404      else
 405      {
 406          $query = $db->simple_select("modtools", "*", "tid = '{$mybb->input['tid']}'");
 407          $modtool = $db->fetch_array($query);
 408          $thread_options = my_unserialize($modtool['threadoptions']);
 409  
 410          $mybb->input['title'] = $modtool['name'];
 411          $mybb->input['description'] = $modtool['description'];
 412          $mybb->input['forum_1_forums'] = explode(",", $modtool['forums']);
 413          $mybb->input['group_1_groups'] = explode(",", $modtool['groups']);
 414  
 415          if(!$modtool['forums'] || $modtool['forums'] == -1)
 416          {
 417              $forum_checked[1] = "checked=\"checked\"";
 418              $forum_checked[2] = '';
 419          }
 420          else
 421          {
 422              $forum_checked[1] = '';
 423              $forum_checked[2] = "checked=\"checked\"";
 424          }
 425  
 426          if(!$modtool['groups'] || $modtool['groups'] == -1)
 427          {
 428              $group_checked[1] = "checked=\"checked\"";
 429              $group_checked[2] = '';
 430          }
 431          else
 432          {
 433              $group_checked[1] = '';
 434              $group_checked[2] = "checked=\"checked\"";
 435          }
 436  
 437          $mybb->input['confirmation'] = $thread_options['confirmation'];
 438          $mybb->input['approvethread'] = $thread_options['approvethread'];
 439          $mybb->input['softdeletethread'] = $thread_options['softdeletethread'];
 440          $mybb->input['openthread'] = $thread_options['openthread'];
 441          $mybb->input['stickthread'] = $thread_options['stickthread'];
 442          $mybb->input['move_1_forum'] = $thread_options['movethread'];
 443          $mybb->input['move_2_redirect'] = $thread_options['movethreadredirect'];
 444          $mybb->input['move_3_redirecttime'] = $thread_options['movethreadredirectexpire'];
 445  
 446          if(!$thread_options['movethread'])
 447          {
 448              $move_checked[1] = "checked=\"checked\"";
 449              $move_checked[2] = '';
 450          }
 451          else
 452          {
 453              $move_checked[1] = '';
 454              $move_checked[2] = "checked=\"checked\"";
 455          }
 456  
 457          if(!$thread_options['copythread'])
 458          {
 459              $copy_checked[1] = "checked=\"checked\"";
 460              $copy_checked[2] = '';
 461          }
 462          else
 463          {
 464              $copy_checked[1] = '';
 465              $copy_checked[2] = "checked=\"checked\"";
 466          }
 467  
 468          $mybb->input['copy_1_forum'] = $thread_options['copythread'];
 469          $mybb->input['deletethread'] = $thread_options['deletethread'];
 470          $mybb->input['mergethreads'] = $thread_options['mergethreads'];
 471          $mybb->input['deletepoll'] = $thread_options['deletepoll'];
 472          $mybb->input['removeredirects'] = $thread_options['removeredirects'];
 473          $mybb->input['removesubscriptions'] = $thread_options['removesubscriptions'];
 474          $mybb->input['recountrebuild'] = $thread_options['recountrebuild'];
 475          $mybb->input['threadprefix'] = $thread_options['threadprefix'];
 476          $mybb->input['newsubject'] = $thread_options['newsubject'];
 477          $mybb->input['newreply'] = $thread_options['addreply'];
 478          $mybb->input['newreplysubject'] = $thread_options['replysubject'];
 479          $mybb->input['pm_subject'] = $thread_options['pm_subject'];
 480          $mybb->input['pm_message'] = $thread_options['pm_message'];
 481      }
 482  
 483      $form_container = new FormContainer($lang->general_options);
 484      $form_container->output_row($lang->name." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 485      $form_container->output_row($lang->short_description." <em>*</em>", '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 486  
 487      $actions = "<script type=\"text/javascript\">
 488  	function checkAction(id)
 489      {
 490          var checked = '';
 491  
 492          $('.'+id+'s_check').each(function(e, val)
 493          {
 494              if($(this).prop('checked') == true)
 495              {
 496                  checked = $(this).val();
 497              }
 498          });
 499          $('.'+id+'s').each(function(e)
 500          {
 501              $(this).hide();
 502          });
 503          if($('#'+id+'_'+checked))
 504          {
 505              $('#'+id+'_'+checked).show();
 506          }
 507      }
 508  </script>
 509      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 510      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
 511          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
 512          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
 513              <table cellpadding=\"4\">
 514                  <tr>
 515                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
 516                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
 517                  </tr>
 518              </table>
 519          </dd>
 520      </dl>
 521      <script type=\"text/javascript\">
 522      checkAction('forum');
 523      </script>";
 524      $form_container->output_row($lang->available_in_forums." <em>*</em>", '', $actions);
 525  
 526      $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 527      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
 528          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
 529          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
 530              <table cellpadding=\"4\">
 531                  <tr>
 532                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
 533                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
 534                  </tr>
 535              </table>
 536          </dd>
 537      </dl>
 538      <script type=\"text/javascript\">
 539      checkAction('group');
 540      </script>";
 541      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $actions);
 542      $form_container->output_row($lang->show_confirmation." <em>*</em>", '', $form->generate_yes_no_radio('confirmation', $mybb->input['confirmation'], array('style' => 'width: 2em;')));
 543      $form_container->end();
 544  
 545      $approve_unapprove = array(
 546          '' => $lang->no_change,
 547          'approve' => $lang->approve,
 548          'unapprove' => $lang->unapprove,
 549          'toggle' => $lang->toggle
 550      );
 551  
 552      $open_close = array(
 553          '' => $lang->no_change,
 554          'open' => $lang->open,
 555          'close' => $lang->close,
 556          'toggle' => $lang->toggle
 557      );
 558  
 559      $stick_unstick = array(
 560          '' => $lang->no_change,
 561          'stick' => $lang->stick,
 562          'unstick' => $lang->unstick,
 563          'toggle' => $lang->toggle
 564      );
 565  
 566      $form_container = new FormContainer($lang->thread_moderation);
 567      $form_container->output_row($lang->approve_unapprove." <em>*</em>", '', $form->generate_select_box('approvethread', $approve_unapprove, $mybb->input['approvethread'], array('id' => 'approvethread')), 'approvethread');
 568      $form_container->output_row($lang->open_close_thread." <em>*</em>", '', $form->generate_select_box('openthread', $open_close, $mybb->input['openthread'], array('id' => 'openthread')), 'openthread');
 569      $form_container->output_row($lang->stick_unstick_thread." <em>*</em>", '', $form->generate_select_box('stickthread', $stick_unstick, $mybb->input['stickthread'], array('id' => 'stickthread')), 'stickthread');
 570  
 571  
 572      $actions = "
 573      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 574      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"1\" {$move_checked[1]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_move_thread}</strong></label></dt>
 575          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"2\" {$move_checked[2]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->move_thread}</strong></label></dt>
 576          <dd style=\"margin-top: 4px;\" id=\"move_2\" class=\"moves\">
 577              <table cellpadding=\"4\">
 578                  <tr>
 579                      <td><small>{$lang->forum_to_move_to}</small></td>
 580                      <td>".$form->generate_forum_select('move_1_forum', $mybb->input['move_1_forum'])."</td>
 581                  </tr>
 582                  <tr>
 583                      <td><small>{$lang->leave_redirect}</small></td>
 584                      <td>".$form->generate_yes_no_radio('move_2_redirect', $mybb->input['move_2_redirect'], array('style' => 'width: 2em;'))."</td>
 585                  </tr>
 586                  <tr>
 587                      <td><small>{$lang->delete_redirect_after}</small></td>
 588                      <td>".$form->generate_numeric_field('move_3_redirecttime', $mybb->input['move_3_redirecttime'], array('style' => 'width: 3em;', 'min' => 0))." {$lang->days}</td>
 589                  </tr>
 590              </table>
 591          </dd>
 592      </dl>
 593      <script type=\"text/javascript\">
 594      checkAction('move');
 595      </script>";
 596      $form_container->output_row($lang->move_thread." <em>*</em>", $lang->move_thread_desc, $actions);
 597  
 598      $actions = "
 599      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 600      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"1\" {$copy_checked[1]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_copy_thread}</strong></label></dt>
 601          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"2\" {$copy_checked[2]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->copy_thread}</strong></label></dt>
 602          <dd style=\"margin-top: 4px;\" id=\"copy_2\" class=\"copys\">
 603              <table cellpadding=\"4\">
 604                  <tr>
 605                      <td><small>{$lang->forum_to_copy_to}</small></td>
 606                      <td>".$form->generate_forum_select('copy_1_forum', $mybb->input['copy_1_forum'])."</td>
 607                  </tr>
 608              </table>
 609          </dd>
 610      </dl>
 611      <script type=\"text/javascript\">
 612      checkAction('copy');
 613      </script>";
 614      $form_container->output_row($lang->copy_thread." <em>*</em>", '', $actions);
 615  
 616      $softdelete_restore = array(
 617          '' => $lang->no_change,
 618          'restore' => $lang->restore,
 619          'softdelete' => $lang->softdelete,
 620          'toggle' => $lang->toggle
 621      );
 622  
 623      $form_container->output_row($lang->softdelete_restore_thread." <em>*</em>", '', $form->generate_select_box('softdeletethread', $softdelete_restore, $mybb->input['softdeletethread'], array('id' => 'softdeletethread')), 'softdeletethread');
 624      $form_container->output_row($lang->delete_thread." <em>*</em>", '', $form->generate_yes_no_radio('deletethread', $mybb->input['deletethread'], array('style' => 'width: 2em;')));
 625      $form_container->output_row($lang->merge_thread." <em>*</em>", $lang->merge_thread_desc, $form->generate_yes_no_radio('mergethreads', $mybb->input['mergethreads'], array('style' => 'width: 2em;')));
 626      $form_container->output_row($lang->delete_poll." <em>*</em>", '', $form->generate_yes_no_radio('deletepoll', $mybb->input['deletepoll'], array('style' => 'width: 2em;')));
 627      $form_container->output_row($lang->delete_redirects." <em>*</em>", '', $form->generate_yes_no_radio('removeredirects', $mybb->input['removeredirects'], array('style' => 'width: 2em;')));
 628      $form_container->output_row($lang->remove_subscriptions." <em>*</em>", '', $form->generate_yes_no_radio('removesubscriptions', $mybb->input['removesubscriptions'], array('style' => 'width: 2em;')));
 629      $form_container->output_row($lang->recount_rebuild." <em>*</em>", '', $form->generate_yes_no_radio('recountrebuild', $mybb->input['recountrebuild'], array('style' => 'width: 2em;')));
 630  
 631      $threadprefixes = build_prefixes();
 632      if(!empty($threadprefixes))
 633      {
 634          $thread_prefixes = array(
 635              '-1' => $lang->no_change,
 636              '0' => $lang->no_prefix
 637          );
 638  
 639          foreach($threadprefixes as $prefix)
 640          {
 641              $thread_prefixes[$prefix['pid']] = $prefix['prefix'];
 642          }
 643  
 644          $form_container->output_row($lang->apply_thread_prefix." <em>*</em>", '', $form->generate_select_box('threadprefix', $thread_prefixes, array($mybb->get_input('threadprefix', MyBB::INPUT_INT)), array('id' => 'threadprefix')), 'threadprefix');
 645      }
 646  
 647      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
 648      $form_container->output_row($lang->new_subject." <em>*</em>", $lang->new_subject_desc, $form->generate_text_box('newsubject', $mybb->input['newsubject'], array('id' => 'newsubject')));
 649      $form_container->end();
 650  
 651      $form_container = new FormContainer($lang->add_new_reply);
 652      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
 653      $form_container->output_row($lang->add_new_reply, $lang->add_new_reply_desc, $form->generate_text_area('newreply', $mybb->input['newreply'], array('id' => 'newreply')), 'newreply');
 654      $form_container->output_row($lang->reply_subject, $lang->reply_subject_desc, $form->generate_text_box('newreplysubject', $mybb->input['newreplysubject'], array('id' => 'newreplysubject')), 'newreplysubject');
 655      $form_container->end();
 656  
 657      $form_container = new FormContainer($lang->send_private_message);
 658      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
 659      $form_container->output_row($lang->private_message_message, $lang->private_message_message_desc, $form->generate_text_area('pm_message', $mybb->input['pm_message'], array('id' => 'pm_message')), 'pm_message');
 660      $form_container->output_row($lang->private_message_subject, $lang->private_message_subject_desc, $form->generate_text_box('pm_subject', $mybb->input['pm_subject'], array('id' => 'pm_subject')), 'pm_subject');
 661      $form_container->end();
 662  
 663      $plugins->run_hooks("admin_config_mod_tools_edit_thread_tool_end");
 664  
 665      $buttons[] = $form->generate_submit_button($lang->save_thread_tool);
 666  
 667      $form->output_submit_wrapper($buttons);
 668      $form->end();
 669  
 670      $page->output_footer();
 671  }
 672  
 673  if($mybb->input['action'] == "add_thread_tool")
 674  {
 675      $plugins->run_hooks("admin_config_mod_tools_add_thread_tool");
 676  
 677      if($mybb->request_method == 'post')
 678      {
 679          if(trim($mybb->input['title']) == "")
 680          {
 681              $errors[] = $lang->error_missing_title;
 682          }
 683  
 684          if(trim($mybb->input['description']) == "")
 685          {
 686              $errors[] = $lang->error_missing_description;
 687          }
 688  
 689          if($mybb->input['forum_type'] == 2)
 690          {
 691              $forum_checked[1] = '';
 692              $forum_checked[2] = "checked=\"checked\"";
 693  
 694              if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1)
 695              {
 696                  $errors[] = $lang->error_no_forums_selected;
 697              }
 698          }
 699          else
 700          {
 701              $forum_checked[1] = "checked=\"checked\"";
 702              $forum_checked[2] = '';
 703  
 704              $mybb->input['forum_1_forums'] = '';
 705          }
 706  
 707          if($mybb->input['group_type'] == 2)
 708          {
 709              $group_checked[1] = '';
 710              $group_checked[2] = "checked=\"checked\"";
 711  
 712              if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1)
 713              {
 714                  $errors[] = $lang->error_no_groups_selected;
 715              }
 716          }
 717          else
 718          {
 719              $group_checked[1] = "checked=\"checked\"";
 720              $group_checked[2] = '';
 721  
 722              $mybb->input['group_1_groups'] = '';
 723          }
 724  
 725          if($mybb->input['approvethread'] != '' && $mybb->input['approvethread'] != 'approve' && $mybb->input['approvethread'] != 'unapprove' && $mybb->input['approvethread'] != 'toggle')
 726          {
 727              $mybb->input['approvethread'] = '';
 728          }
 729  
 730          if($mybb->input['softdeletethread'] != '' && $mybb->input['softdeletethread'] != 'restore' && $mybb->input['softdeletethread'] != 'softdelete' && $mybb->input['softdeletethread'] != 'toggle')
 731          {
 732              $mybb->input['softdeletethread'] = '';
 733          }
 734  
 735          if($mybb->input['openthread'] != '' && $mybb->input['openthread'] != 'open' && $mybb->input['openthread'] != 'close' && $mybb->input['openthread'] != 'toggle')
 736          {
 737              $mybb->input['openthread'] = '';
 738          }
 739  
 740          if($mybb->input['stickthread'] != '' && $mybb->input['stickthread'] != 'stick' && $mybb->input['stickthread'] != 'unstick' && $mybb->input['stickthread'] != 'toggle')
 741          {
 742              $mybb->input['stickthread'] = '';
 743          }
 744  
 745          if(!isset($mybb->input['threadprefix']))
 746          {
 747              $mybb->input['threadprefix'] = '';
 748          }
 749  
 750          if($mybb->input['move_type'] == 2)
 751          {
 752              $move_checked[1] = '';
 753              $move_checked[2] = "checked=\"checked\"";
 754  
 755              if(!$mybb->input['move_1_forum'])
 756              {
 757                  $errors[] = $lang->error_no_move_forum_selected;
 758              }
 759              else
 760              {
 761                  // Check that the destination forum is not a category
 762                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('move_1_forum', MyBB::INPUT_INT)."'");
 763                  if($db->fetch_field($query, "type") == "c")
 764                  {
 765                      $errors[] = $lang->error_forum_is_category;
 766                  }
 767              }
 768          }
 769          else
 770          {
 771              $move_checked[1] = "checked=\"checked\"";
 772              $move_checked[2] = '';
 773  
 774              $mybb->input['move_1_forum'] = '';
 775              $mybb->input['move_2_redirect'] = 0;
 776              $mybb->input['move_3_redirecttime'] = '';
 777          }
 778  
 779          if($mybb->input['copy_type'] == 2)
 780          {
 781              $copy_checked[1] = '';
 782              $copy_checked[2] = "checked=\"checked\"";
 783  
 784              if(!$mybb->input['copy_1_forum'])
 785              {
 786                  $errors[] = $lang->error_no_copy_forum_selected;
 787              }
 788              else
 789              {
 790                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('copy_1_forum', MyBB::INPUT_INT)."'");
 791                  if($db->fetch_field($query, "type") == "c")
 792                  {
 793                      $errors[] = $lang->error_forum_is_category;
 794                  }
 795              }
 796          }
 797          else
 798          {
 799              $copy_checked[1] = "checked=\"checked\"";
 800              $copy_checked[2] = '';
 801  
 802              $mybb->input['copy_1_forum'] = '';
 803          }
 804  
 805          if(!$errors)
 806          {
 807              $thread_options = array(
 808                  'confirmation' => $mybb->get_input('confirmation', MyBB::INPUT_INT),
 809                  'deletethread' => $mybb->get_input('deletethread', MyBB::INPUT_INT),
 810                  'mergethreads' => $mybb->get_input('mergethreads', MyBB::INPUT_INT),
 811                  'deletepoll' => $mybb->get_input('deletepoll', MyBB::INPUT_INT),
 812                  'removeredirects' => $mybb->get_input('removeredirects', MyBB::INPUT_INT),
 813                  'removesubscriptions' => $mybb->get_input('removesubscriptions', MyBB::INPUT_INT),
 814                  'recountrebuild' => $mybb->get_input('recountrebuild', MyBB::INPUT_INT),
 815                  'approvethread' => $mybb->input['approvethread'],
 816                  'softdeletethread' => $mybb->input['softdeletethread'],
 817                  'openthread' => $mybb->input['openthread'],
 818                  'stickthread' => $mybb->input['stickthread'],
 819                  'movethread' => $mybb->get_input('move_1_forum', MyBB::INPUT_INT),
 820                  'movethreadredirect' => $mybb->get_input('move_2_redirect', MyBB::INPUT_INT),
 821                  'movethreadredirectexpire' => $mybb->get_input('move_3_redirecttime', MyBB::INPUT_INT),
 822                  'copythread' => $mybb->get_input('copy_1_forum', MyBB::INPUT_INT),
 823                  'newsubject' => $mybb->input['newsubject'],
 824                  'addreply' => $mybb->input['newreply'],
 825                  'replysubject' => $mybb->input['newreplysubject'],
 826                  'pm_subject' => $mybb->input['pm_subject'],
 827                  'pm_message' => $mybb->input['pm_message'],
 828                  'threadprefix' => $mybb->input['threadprefix'],
 829              );
 830  
 831              $args = array(
 832                  'thread_options' => &$thread_options,
 833              );
 834  
 835              $plugins->run_hooks("admin_config_mod_tools_add_thread_tool_options", $args);
 836  
 837              $new_tool['type'] = 't';
 838              $new_tool['threadoptions'] = $db->escape_string(my_serialize($thread_options));
 839              $new_tool['name'] = $db->escape_string($mybb->input['title']);
 840              $new_tool['description'] = $db->escape_string($mybb->input['description']);
 841              $new_tool['forums'] = '';
 842              $new_tool['groups'] = '';
 843              $new_tool['postoptions'] = '';
 844  
 845              if($mybb->input['forum_type'] == 2)
 846              {
 847                  if(is_array($mybb->input['forum_1_forums']))
 848                  {
 849                      $checked = array();
 850  
 851                      foreach($mybb->input['forum_1_forums'] as $fid)
 852                      {
 853                          $checked[] = (int)$fid;
 854                      }
 855  
 856                      $new_tool['forums'] = implode(',', $checked);
 857                  }
 858              }
 859              else
 860              {
 861                  $new_tool['forums'] = "-1";
 862              }
 863  
 864              if($mybb->input['group_type'] == 2)
 865              {
 866                  if(is_array($mybb->input['group_1_groups']))
 867                  {
 868                      $checked = array();
 869  
 870                      foreach($mybb->input['group_1_groups'] as $gid)
 871                      {
 872                          $checked[] = (int)$gid;
 873                      }
 874  
 875                      $new_tool['groups'] = implode(',', $checked);
 876                  }
 877              }
 878              else
 879              {
 880                  $new_tool['groups'] = "-1";
 881              }
 882  
 883              if($mybb->get_input('threadprefix', MyBB::INPUT_INT) >= 0)
 884              {
 885                  $thread_options['threadprefix'] = $mybb->get_input('threadprefix', MyBB::INPUT_INT);
 886              }
 887  
 888              $tid = $db->insert_query("modtools", $new_tool);
 889  
 890              $plugins->run_hooks("admin_config_mod_tools_add_thread_tool_commit");
 891  
 892              // Log admin action
 893              log_admin_action($tid, $mybb->input['title']);
 894              $cache->update_forumsdisplay();
 895  
 896              flash_message($lang->success_mod_tool_created, 'success');
 897              admin_redirect("index.php?module=config-mod_tools");
 898          }
 899      }
 900  
 901      $page->add_breadcrumb_item($lang->add_new_thread_tool);
 902      $page->output_header($lang->mod_tools." - ".$lang->add_new_thread_tool);
 903  
 904      $sub_tabs['thread_tools'] = array(
 905          'title' => $lang->thread_tools,
 906          'link' => "index.php?module=config-mod_tools"
 907      );
 908      $sub_tabs['add_thread_tool'] = array(
 909          'title'=> $lang->add_new_thread_tool,
 910          'link' => "index.php?module=config-mod_tools&amp;action=add_thread_tool",
 911          'description' => $lang->add_thread_tool_desc
 912      );
 913      $sub_tabs['post_tools'] = array(
 914          'title' => $lang->post_tools,
 915          'link' => "index.php?module=config-mod_tools&amp;action=post_tools",
 916      );
 917      $sub_tabs['add_post_tool'] = array(
 918          'title'=> $lang->add_new_post_tool,
 919          'link' => "index.php?module=config-mod_tools&amp;action=add_post_tool"
 920      );
 921  
 922      $page->output_nav_tabs($sub_tabs, 'add_thread_tool');
 923  
 924      $form = new Form("index.php?module=config-mod_tools&amp;action=add_thread_tool", 'post');
 925  
 926      if($errors)
 927      {
 928          $page->output_inline_error($errors);
 929      }
 930      else
 931      {
 932          $mybb->input['title'] = '';
 933          $mybb->input['description'] = '';
 934          $mybb->input['forum_1_forums'] = '';
 935          $forum_checked[1] = "checked=\"checked\"";
 936          $forum_checked[2] = '';
 937          $mybb->input['group_1_groups'] = '';
 938          $group_checked[1] = "checked=\"checked\"";
 939          $group_checked[2] = '';
 940          $mybb->input['confirmation'] = '0';
 941          $mybb->input['approvethread'] = '';
 942          $mybb->input['softdeletethread'] = '';
 943          $mybb->input['openthread'] = '';
 944          $mybb->input['stickthread'] = '';
 945          $mybb->input['move_1_forum'] = '';
 946          $mybb->input['move_2_redirect'] = '0';
 947          $mybb->input['move_3_redirecttime'] = '';
 948          $move_checked[1] = "checked=\"checked\"";
 949          $move_checked[2] = '';
 950          $copy_checked[1] = "checked=\"checked\"";
 951          $copy_checked[2] = '';
 952          $mybb->input['copy_1_forum'] = '';
 953          $mybb->input['deletethread'] = '0';
 954          $mybb->input['mergethreads'] = '0';
 955          $mybb->input['deletepoll'] = '0';
 956          $mybb->input['removeredirects'] = '0';
 957          $mybb->input['removesubscriptions'] = '0';
 958          $mybb->input['recountrebuild'] = '0';
 959          $mybb->input['threadprefix'] = '-1';
 960          $mybb->input['newsubject'] = '{subject}';
 961          $mybb->input['newreply'] = '';
 962          $mybb->input['newreplysubject'] = '{subject}';
 963          $mybb->input['pm_subject'] = '';
 964          $mybb->input['pm_message'] = '';
 965      }
 966  
 967      $form_container = new FormContainer($lang->general_options);
 968      $form_container->output_row($lang->name." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 969      $form_container->output_row($lang->short_description." <em>*</em>", '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 970  
 971      $actions = "<script type=\"text/javascript\">
 972  	function checkAction(id)
 973      {
 974          var checked = '';
 975  
 976          $('.'+id+'s_check').each(function(e, val)
 977          {
 978              if($(this).prop('checked') == true)
 979              {
 980                  checked = $(this).val();
 981              }
 982          });
 983          $('.'+id+'s').each(function(e)
 984          {
 985              $(this).hide();
 986          });
 987          if($('#'+id+'_'+checked))
 988          {
 989              $('#'+id+'_'+checked).show();
 990          }
 991      }
 992  </script>
 993      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 994      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
 995          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
 996          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
 997              <table cellpadding=\"4\">
 998                  <tr>
 999                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
1000                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
1001                  </tr>
1002              </table>
1003          </dd>
1004      </dl>
1005      <script type=\"text/javascript\">
1006      checkAction('forum');
1007      </script>";
1008      $form_container->output_row($lang->available_in_forums." <em>*</em>", '', $actions);
1009  
1010      $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1011      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
1012          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
1013          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
1014              <table cellpadding=\"4\">
1015                  <tr>
1016                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
1017                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
1018                  </tr>
1019              </table>
1020          </dd>
1021      </dl>
1022      <script type=\"text/javascript\">
1023      checkAction('group');
1024      </script>";
1025      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $actions);
1026      $form_container->output_row($lang->show_confirmation." <em>*</em>", '', $form->generate_yes_no_radio('confirmation', $mybb->input['confirmation'], array('style' => 'width: 2em;')));
1027      $form_container->end();
1028  
1029      $approve_unapprove = array(
1030          '' => $lang->no_change,
1031          'approve' => $lang->approve,
1032          'unapprove' => $lang->unapprove,
1033          'toggle' => $lang->toggle
1034      );
1035  
1036      $open_close = array(
1037          '' => $lang->no_change,
1038          'open' => $lang->open,
1039          'close' => $lang->close,
1040          'toggle' => $lang->toggle
1041      );
1042  
1043      $stick_unstick = array(
1044          '' => $lang->no_change,
1045          'stick' => $lang->stick,
1046          'unstick' => $lang->unstick,
1047          'toggle' => $lang->toggle
1048      );
1049  
1050      $form_container = new FormContainer($lang->thread_moderation);
1051      $form_container->output_row($lang->approve_unapprove." <em>*</em>", '', $form->generate_select_box('approvethread', $approve_unapprove, $mybb->input['approvethread'], array('id' => 'approvethread')), 'approvethread');
1052      $form_container->output_row($lang->open_close_thread." <em>*</em>", '', $form->generate_select_box('openthread', $open_close, $mybb->input['openthread'], array('id' => 'openthread')), 'openthread');
1053      $form_container->output_row($lang->stick_unstick_thread." <em>*</em>", '', $form->generate_select_box('stickthread', $stick_unstick, $mybb->input['stickthread'], array('id' => 'stickthread')), 'stickthread');
1054  
1055  
1056      $actions = "
1057      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1058      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"1\" {$move_checked[1]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_move_thread}</strong></label></dt>
1059          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"2\" {$move_checked[2]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->move_thread}</strong></label></dt>
1060          <dd style=\"margin-top: 4px;\" id=\"move_2\" class=\"moves\">
1061              <table cellpadding=\"4\">
1062                  <tr>
1063                      <td><small>{$lang->forum_to_move_to}</small></td>
1064                      <td>".$form->generate_forum_select('move_1_forum', $mybb->input['move_1_forum'])."</td>
1065                  </tr>
1066                  <tr>
1067                      <td><small>{$lang->leave_redirect}</small></td>
1068                      <td>".$form->generate_yes_no_radio('move_2_redirect', $mybb->input['move_2_redirect'], array('style' => 'width: 2em;'))."</td>
1069                  </tr>
1070                  <tr>
1071                      <td><small>{$lang->delete_redirect_after}</small></td>
1072                      <td>".$form->generate_numeric_field('move_3_redirecttime', $mybb->input['move_3_redirecttime'], array('style' => 'width: 3em;', 'min' => 0))." {$lang->days}</td>
1073                  </tr>
1074              </table>
1075          </dd>
1076      </dl>
1077      <script type=\"text/javascript\">
1078      checkAction('move');
1079      </script>";
1080      $form_container->output_row($lang->move_thread." <em>*</em>", $lang->move_thread_desc, $actions);
1081  
1082      $actions = "
1083      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1084      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"1\" {$copy_checked[1]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_copy_thread}</strong></label></dt>
1085          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"2\" {$copy_checked[2]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->copy_thread}</strong></label></dt>
1086          <dd style=\"margin-top: 4px;\" id=\"copy_2\" class=\"copys\">
1087              <table cellpadding=\"4\">
1088                  <tr>
1089                      <td><small>{$lang->forum_to_copy_to}</small></td>
1090                      <td>".$form->generate_forum_select('copy_1_forum', $mybb->input['copy_1_forum'])."</td>
1091                  </tr>
1092              </table>
1093          </dd>
1094      </dl>
1095      <script type=\"text/javascript\">
1096      checkAction('copy');
1097      </script>";
1098      $form_container->output_row($lang->copy_thread." <em>*</em>", '', $actions);
1099  
1100      $softdelete_restore = array(
1101          '' => $lang->no_change,
1102          'restore' => $lang->restore,
1103          'softdelete' => $lang->softdelete,
1104          'toggle' => $lang->toggle
1105      );
1106  
1107      $form_container->output_row($lang->softdelete_restore_thread." <em>*</em>", '', $form->generate_select_box('softdeletethread', $softdelete_restore, $mybb->input['softdeletethread'], array('id' => 'softdeletethread')), 'softdeletethread');
1108      $form_container->output_row($lang->delete_thread." <em>*</em>", '', $form->generate_yes_no_radio('deletethread', $mybb->input['deletethread'], array('style' => 'width: 2em;')));
1109      $form_container->output_row($lang->merge_thread." <em>*</em>", $lang->merge_thread_desc, $form->generate_yes_no_radio('mergethreads', $mybb->input['mergethreads'], array('style' => 'width: 2em;')));
1110      $form_container->output_row($lang->delete_poll." <em>*</em>", '', $form->generate_yes_no_radio('deletepoll', $mybb->input['deletepoll'], array('style' => 'width: 2em;')));
1111      $form_container->output_row($lang->delete_redirects." <em>*</em>", '', $form->generate_yes_no_radio('removeredirects', $mybb->input['removeredirects'], array('style' => 'width: 2em;')));
1112      $form_container->output_row($lang->remove_subscriptions." <em>*</em>", '', $form->generate_yes_no_radio('removesubscriptions', $mybb->input['removesubscriptions'], array('style' => 'width: 2em;')));
1113      $form_container->output_row($lang->recount_rebuild." <em>*</em>", '', $form->generate_yes_no_radio('recountrebuild', $mybb->input['recountrebuild'], array('style' => 'width: 2em;')));
1114  
1115      $threadprefixes = build_prefixes();
1116      if(!empty($threadprefixes))
1117      {
1118          $thread_prefixes = array(
1119              '-1' => $lang->no_change,
1120              '0' => $lang->no_prefix
1121          );
1122  
1123          foreach($threadprefixes as $prefix)
1124          {
1125              $thread_prefixes[$prefix['pid']] = $prefix['prefix'];
1126          }
1127  
1128          $form_container->output_row($lang->apply_thread_prefix." <em>*</em>", '', $form->generate_select_box('threadprefix', $thread_prefixes, $mybb->input['threadprefix'], array('id' => 'threadprefix')), 'threadprefix');
1129      }
1130  
1131      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1132      $form_container->output_row($lang->new_subject." <em>*</em>", $lang->new_subject_desc, $form->generate_text_box('newsubject', $mybb->input['newsubject'], array('id' => 'newsubject')));
1133      $form_container->end();
1134  
1135      $form_container = new FormContainer($lang->add_new_reply);
1136      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1137      $form_container->output_row($lang->add_new_reply, $lang->add_new_reply_desc, $form->generate_text_area('newreply', $mybb->input['newreply'], array('id' => 'newreply')), 'newreply');
1138      $form_container->output_row($lang->reply_subject, $lang->reply_subject_desc, $form->generate_text_box('newreplysubject', $mybb->input['newreplysubject'], array('id' => 'newreplysubject')), 'newreplysubject');
1139      $form_container->end();
1140  
1141      $form_container = new FormContainer($lang->send_private_message);
1142      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1143      $form_container->output_row($lang->private_message_message, $lang->private_message_message_desc, $form->generate_text_area('pm_message', $mybb->input['pm_message'], array('id' => 'pm_message')), 'pm_message');
1144      $form_container->output_row($lang->private_message_subject, $lang->private_message_subject_desc, $form->generate_text_box('pm_subject', $mybb->input['pm_subject'], array('id' => 'pm_subject')), 'pm_subject');
1145      $form_container->end();
1146  
1147      $plugins->run_hooks("admin_config_mod_tools_add_thread_tool_end");
1148  
1149      $buttons[] = $form->generate_submit_button($lang->save_thread_tool);
1150  
1151      $form->output_submit_wrapper($buttons);
1152      $form->end();
1153  
1154      $page->output_footer();
1155  }
1156  
1157  if($mybb->input['action'] == "edit_post_tool")
1158  {
1159      $query = $db->simple_select("modtools", "COUNT(tid) as tools", "tid = '{$mybb->input['tid']}' AND type='p'");
1160      if($db->fetch_field($query, "tools") < 1)
1161      {
1162          flash_message($lang->error_invalid_post_tool, 'error');
1163          admin_redirect("index.php?module=config-mod_tools&action=post_tools");
1164      }
1165  
1166      $plugins->run_hooks("admin_config_mod_tools_edit_post_tool");
1167  
1168      if($mybb->request_method == 'post')
1169      {
1170          if(trim($mybb->input['title']) == "")
1171          {
1172              $errors[] = $lang->error_missing_title;
1173          }
1174  
1175          if(trim($mybb->input['description']) == "")
1176          {
1177              $errors[] = $lang->error_missing_description;
1178          }
1179  
1180          if($mybb->input['forum_type'] == 2)
1181          {
1182              if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1)
1183              {
1184                  $errors[] = $lang->error_no_forums_selected;
1185              }
1186          }
1187          else
1188          {
1189              $mybb->input['forum_1_forums'] = '';
1190          }
1191  
1192          if($mybb->input['group_type'] == 2)
1193          {
1194              if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1)
1195              {
1196                  $errors[] = $lang->error_no_groups_selected;
1197              }
1198          }
1199          else
1200          {
1201              $mybb->input['group_1_groups'] = '';
1202          }
1203      
1204          if($mybb->input['approvethread'] != '' && $mybb->input['approvethread'] != 'approve' && $mybb->input['approvethread'] != 'unapprove' && $mybb->input['approvethread'] != 'toggle')
1205          {
1206              $mybb->input['approvethread'] = '';
1207          }
1208  
1209          if($mybb->input['softdeletethread'] != '' && $mybb->input['softdeletethread'] != 'softdelete' && $mybb->input['softdeletethread'] != 'restore' && $mybb->input['softdeletethread'] != 'toggle')
1210          {
1211              $mybb->input['softdeletethread'] = '';
1212          }
1213  
1214          if($mybb->input['openthread'] != '' && $mybb->input['openthread'] != 'open' && $mybb->input['openthread'] != 'close' && $mybb->input['openthread'] != 'toggle')
1215          {
1216              $mybb->input['openthread'] = '';
1217          }
1218  
1219          if($mybb->input['stickthread'] != '' && $mybb->input['stickthread'] != 'stick' && $mybb->input['stickthread'] != 'unstick' && $mybb->input['stickthread'] != 'toggle')
1220          {
1221              $mybb->input['stickthread'] = '';
1222          }
1223  
1224          if($mybb->input['move_type'] == 2)
1225          {
1226              if(!$mybb->input['move_1_forum'])
1227              {
1228                  $errors[] = $lang->error_no_move_forum_selected;
1229              }
1230              else
1231              {
1232                  // Check that the destination forum is not a category
1233                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('move_1_forum', MyBB::INPUT_INT)."'");
1234                  if($db->fetch_field($query, "type") == "c")
1235                  {
1236                      $errors[] = $lang->error_forum_is_category;
1237                  }
1238              }
1239          }
1240          else
1241          {
1242              $mybb->input['move_1_forum'] = '';
1243              $mybb->input['move_2_redirect'] = 0;
1244              $mybb->input['move_3_redirecttime'] = '';
1245          }
1246  
1247          if($mybb->input['copy_type'] == 2)
1248          {
1249              if(!$mybb->input['copy_1_forum'])
1250              {
1251                  $errors[] = $lang->error_no_copy_forum_selected;
1252              }
1253              else
1254              {
1255                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('copy_1_forum', MyBB::INPUT_INT)."'");
1256                  if($db->fetch_field($query, "type") == "c")
1257                  {
1258                      $errors[] = $lang->error_forum_is_category;
1259                  }
1260              }
1261          }
1262          else
1263          {
1264              $mybb->input['copy_1_forum'] = '';
1265          }
1266  
1267          if($mybb->input['approveposts'] != '' && $mybb->input['approveposts'] != 'approve' && $mybb->input['approveposts'] != 'unapprove' && $mybb->input['approveposts'] != 'toggle')
1268          {
1269              $mybb->input['approveposts'] = '';
1270          }
1271  
1272          if($mybb->input['softdeleteposts'] != '' && $mybb->input['softdeleteposts'] != 'approve' && $mybb->input['softdeleteposts'] != 'unapprove' && $mybb->input['softdeleteposts'] != 'toggle')
1273          {
1274              $mybb->input['softdeleteposts'] = '';
1275          }
1276  
1277          if($mybb->input['splitposts'] < -2)
1278          {
1279              $mybb->input['splitposts'] = -1;
1280          }
1281  
1282          if($mybb->input['splitpostsclose'] == 1)
1283          {
1284              $mybb->input['splitpostsclose'] = 'close';
1285          }
1286          else
1287          {
1288              $mybb->input['splitpostsclose'] = '';
1289          }
1290  
1291          if($mybb->input['splitpostsstick'] == 1)
1292          {
1293              $mybb->input['splitpostsstick'] = 'stick';
1294          }
1295          else
1296          {
1297              $mybb->input['splitpostsstick'] = '';
1298          }
1299  
1300          if($mybb->input['splitpostsunapprove'] == 1)
1301          {
1302              $mybb->input['splitpostsunapprove'] = 'unapprove';
1303          }
1304          else
1305          {
1306              $mybb->input['splitpostsunapprove'] = '';
1307          }
1308  
1309          if(!$errors)
1310          {
1311              $thread_options = array(
1312                  'confirmation' => $mybb->get_input('confirmation', MyBB::INPUT_INT),
1313                  'deletethread' => $mybb->get_input('deletethread', MyBB::INPUT_INT),
1314                  'softdeletethread' => $mybb->input['softdeletethread'],
1315                  'approvethread' => $mybb->input['approvethread'],
1316                  'openthread' => $mybb->input['openthread'],
1317                  'stickthread' => $mybb->input['stickthread'],
1318                  'movethread' => $mybb->get_input('move_1_forum', MyBB::INPUT_INT),
1319                  'movethreadredirect' => $mybb->get_input('move_2_redirect', MyBB::INPUT_INT),
1320                  'movethreadredirectexpire' => $mybb->get_input('move_3_redirecttime', MyBB::INPUT_INT),
1321                  'copythread' => $mybb->get_input('copy_1_forum', MyBB::INPUT_INT),
1322                  'newsubject' => $mybb->input['newsubject'],
1323                  'addreply' => $mybb->input['newreply'],
1324                  'replysubject' => $mybb->input['newreplysubject'],
1325                  'pm_subject' => $mybb->input['pm_subject'],
1326                  'pm_message' => $mybb->input['pm_message'],
1327                  'threadprefix' => $mybb->get_input('threadprefix', MyBB::INPUT_INT)
1328              );
1329  
1330              if(stripos($mybb->input['splitpostsnewsubject'], '{subject}') === false)
1331              {
1332                  $mybb->input['splitpostsnewsubject'] = '{subject}'.$mybb->input['splitpostsnewsubject'];
1333              }
1334  
1335              $post_options = array(
1336                  'deleteposts' => $mybb->get_input('deleteposts', MyBB::INPUT_INT),
1337                  'softdeleteposts' => $mybb->input['softdeleteposts'],
1338                  'mergeposts' =>$mybb->get_input('mergeposts', MyBB::INPUT_INT),
1339                  'approveposts' => $mybb->input['approveposts'],
1340                  'splitposts' => $mybb->get_input('splitposts', MyBB::INPUT_INT),
1341                  'splitpostsclose' => $mybb->input['splitpostsclose'],
1342                  'splitpostsstick' => $mybb->input['splitpostsstick'],
1343                  'splitpostsunapprove' => $mybb->input['splitpostsunapprove'],
1344                  'splitthreadprefix' => $mybb->get_input('splitthreadprefix', MyBB::INPUT_INT),
1345                  'splitpostsnewsubject' => $mybb->input['splitpostsnewsubject'],
1346                  'splitpostsaddreply' => $mybb->input['splitpostsaddreply'],
1347                  'splitpostsreplysubject' => $mybb->input['splitpostsreplysubject']
1348              );
1349  
1350              $args = array(
1351                  'thread_options' => &$thread_options,
1352                  'post_options' => &$post_options,
1353              );
1354  
1355              $plugins->run_hooks("admin_config_mod_tools_edit_post_tool_options", $args);
1356  
1357              $update_tool['type'] = 'p';
1358              $update_tool['threadoptions'] = $db->escape_string(my_serialize($thread_options));
1359              $update_tool['postoptions'] = $db->escape_string(my_serialize($post_options));
1360              $update_tool['name'] = $db->escape_string($mybb->input['title']);
1361              $update_tool['description'] = $db->escape_string($mybb->input['description']);
1362              $update_tool['forums'] = '';
1363              $update_tool['groups'] = '';
1364  
1365              if($mybb->input['forum_type'] == 2)
1366              {
1367                  if(is_array($mybb->input['forum_1_forums']))
1368                  {
1369                      $checked = array();
1370  
1371                      foreach($mybb->input['forum_1_forums'] as $fid)
1372                      {
1373                          $checked[] = (int)$fid;
1374                      }
1375  
1376                      $update_tool['forums'] = implode(',', $checked);
1377                  }
1378              }
1379              else
1380              {
1381                  $update_tool['forums'] = "-1";
1382              }
1383  
1384              if($mybb->input['group_type'] == 2)
1385              {
1386                  if(is_array($mybb->input['group_1_groups']))
1387                  {
1388                      $checked = array();
1389  
1390                      foreach($mybb->input['group_1_groups'] as $gid)
1391                      {
1392                          $checked[] = (int)$gid;
1393                      }
1394  
1395                      $update_tool['groups'] = implode(',', $checked);
1396                  }
1397              }
1398              else
1399              {
1400                  $update_tool['groups'] = "-1";
1401              }
1402  
1403              $plugins->run_hooks("admin_config_mod_tools_edit_post_tool_commit");
1404  
1405              $db->update_query("modtools", $update_tool, "tid = '{$mybb->input['tid']}'");
1406  
1407              // Log admin action
1408              log_admin_action($mybb->input['tid'], $mybb->input['title']);
1409              $cache->update_forumsdisplay();
1410  
1411              flash_message($lang->success_mod_tool_updated, 'success');
1412              admin_redirect("index.php?module=config-mod_tools&action=post_tools");
1413          }
1414      }
1415  
1416      $page->add_breadcrumb_item($lang->edit_post_tool);
1417      $page->output_header($lang->mod_tools." - ".$lang->edit_post_tool);
1418  
1419      $sub_tabs['edit_post_tool'] = array(
1420          "title" => $lang->edit_post_tool,
1421          "description" => $lang->edit_post_tool_desc,
1422          "link" => "index.php?module=config-mod_tools"
1423      );
1424  
1425      $page->output_nav_tabs($sub_tabs, 'edit_post_tool');
1426  
1427      $form = new Form("index.php?module=config-mod_tools&amp;action=edit_post_tool", 'post');
1428      echo $form->generate_hidden_field("tid", $mybb->input['tid']);
1429  
1430      if($errors)
1431      {
1432          $page->output_inline_error($errors);
1433      }
1434      else
1435      {
1436          $query = $db->simple_select("modtools", "*", "tid = '{$mybb->input['tid']}'");
1437          $modtool = $db->fetch_array($query);
1438          $thread_options = my_unserialize($modtool['threadoptions']);
1439          $post_options = my_unserialize($modtool['postoptions']);
1440  
1441          $mybb->input['title'] = $modtool['name'];
1442          $mybb->input['description'] = $modtool['description'];
1443          $mybb->input['forum_1_forums'] = explode(",", $modtool['forums']);
1444          $mybb->input['group_1_groups'] = explode(",", $modtool['groups']);
1445  
1446          if(!$modtool['forums'] || $modtool['forums'] == -1)
1447          {
1448              $forum_checked[1] = "checked=\"checked\"";
1449              $forum_checked[2] = '';
1450          }
1451          else
1452          {
1453              $forum_checked[1] = '';
1454              $forum_checked[2] = "checked=\"checked\"";
1455          }
1456  
1457          if(!$modtool['groups'] || $modtool['groups'] == -1)
1458          {
1459              $group_checked[1] = "checked=\"checked\"";
1460              $group_checked[2] = '';
1461          }
1462          else
1463          {
1464              $group_checked[1] = '';
1465              $group_checked[2] = "checked=\"checked\"";
1466          }
1467  
1468          $mybb->input['confirmation'] = $thread_options['confirmation'];
1469          $mybb->input['approvethread'] = $thread_options['approvethread'];
1470          $mybb->input['softdeletethread'] = $thread_options['softdeletethread'];
1471          $mybb->input['openthread'] = $thread_options['openthread'];
1472          $mybb->input['stickthread'] = $thread_options['stickthread'];
1473          $mybb->input['move_1_forum'] = $thread_options['movethread'];
1474          $mybb->input['move_2_redirect'] = $thread_options['movethreadredirect'];
1475          $mybb->input['move_3_redirecttime'] = $thread_options['movethreadredirectexpire'];
1476  
1477          if(!$thread_options['movethread'])
1478          {
1479              $move_checked[1] = "checked=\"checked\"";
1480              $move_checked[2] = '';
1481          }
1482          else
1483          {
1484              $move_checked[1] = '';
1485              $move_checked[2] = "checked=\"checked\"";
1486          }
1487  
1488          if(!$thread_options['copythread'])
1489          {
1490              $copy_checked[1] = "checked=\"checked\"";
1491              $copy_checked[2] = '';
1492          }
1493          else
1494          {
1495              $copy_checked[1] = '';
1496              $copy_checked[2] = "checked=\"checked\"";
1497          }
1498  
1499          $mybb->input['copy_1_forum'] = $thread_options['copythread'];
1500          $mybb->input['deletethread'] = $thread_options['deletethread'];
1501          $mybb->input['threadprefix'] = $thread_options['threadprefix'];
1502          $mybb->input['newsubject'] = $thread_options['newsubject'];
1503          $mybb->input['newreply'] = $thread_options['addreply'];
1504          $mybb->input['newreplysubject'] = $thread_options['replysubject'];
1505          $mybb->input['pm_subject'] = $thread_options['pm_subject'];
1506          $mybb->input['pm_message'] = $thread_options['pm_message'];
1507  
1508          if($post_options['splitposts'] == '-1')
1509          {
1510              $do_not_split_checked = ' selected="selected"';
1511              $split_same_checked = '';
1512          }
1513          else if($post_options['splitposts'] == '-2')
1514          {
1515              $do_not_split_checked = '';
1516              $split_same_checked = ' selected="selected"';
1517          }
1518  
1519          $mybb->input['softdeleteposts'] = $post_options['softdeleteposts'];
1520          $mybb->input['deleteposts'] = $post_options['deleteposts'];
1521          $mybb->input['mergeposts'] = $post_options['mergeposts'];
1522          $mybb->input['approveposts'] = $post_options['approveposts'];
1523  
1524          if($post_options['splitpostsclose'] == 'close')
1525          {
1526              $mybb->input['splitpostsclose'] = '1';
1527          }
1528          else
1529          {
1530              $mybb->input['splitpostsclose'] = '0';
1531          }
1532  
1533          if($post_options['splitpostsstick'] == 'stick')
1534          {
1535              $mybb->input['splitpostsstick'] = '1';
1536          }
1537          else
1538          {
1539              $mybb->input['splitpostsstick'] = '0';
1540          }
1541  
1542          if($post_options['splitpostsunapprove'] == 'unapprove')
1543          {
1544              $mybb->input['splitpostsunapprove'] = '1';
1545          }
1546          else
1547          {
1548              $mybb->input['splitpostsunapprove'] = '0';
1549          }
1550  
1551          $mybb->input['splitposts'] = $post_options['splitposts'];
1552          $mybb->input['splitthreadprefix'] = $post_options['splitthreadprefix'];
1553          $mybb->input['splitpostsnewsubject'] = $post_options['splitpostsnewsubject'];
1554          $mybb->input['splitpostsaddreply'] = $post_options['splitpostsaddreply'];
1555          $mybb->input['splitpostsreplysubject'] = $post_options['splitpostsreplysubject'];
1556      }
1557  
1558      $form_container = new FormContainer($lang->general_options);
1559      $form_container->output_row($lang->name." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
1560      $form_container->output_row($lang->short_description." <em>*</em>", '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
1561  
1562      $actions = "<script type=\"text/javascript\">
1563  	function checkAction(id)
1564      {
1565          var checked = '';
1566  
1567          $('.'+id+'s_check').each(function(e, val)
1568          {
1569              if($(this).prop('checked') == true)
1570              {
1571                  checked = $(this).val();
1572              }
1573          });
1574          $('.'+id+'s').each(function(e)
1575          {
1576              $(this).hide();
1577          });
1578          if($('#'+id+'_'+checked))
1579          {
1580              $('#'+id+'_'+checked).show();
1581          }
1582      }
1583  </script>
1584      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1585      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
1586          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
1587          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
1588              <table cellpadding=\"4\">
1589                  <tr>
1590                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
1591                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
1592                  </tr>
1593              </table>
1594          </dd>
1595      </dl>
1596      <script type=\"text/javascript\">
1597      checkAction('forum');
1598      </script>";
1599      $form_container->output_row($lang->available_in_forums." <em>*</em>", '', $actions);
1600  
1601      $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1602      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
1603          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
1604          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
1605              <table cellpadding=\"4\">
1606                  <tr>
1607                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
1608                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
1609                  </tr>
1610              </table>
1611          </dd>
1612      </dl>
1613      <script type=\"text/javascript\">
1614      checkAction('group');
1615      </script>";
1616      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $actions);
1617      $form_container->output_row($lang->show_confirmation." <em>*</em>", '', $form->generate_yes_no_radio('confirmation', $mybb->input['confirmation'], array('style' => 'width: 2em;')));
1618      $form_container->end();
1619  
1620      $approve_unapprove = array(
1621          '' => $lang->no_change,
1622          'approve' => $lang->approve,
1623          'unapprove' => $lang->unapprove,
1624          'toggle' => $lang->toggle
1625      );
1626  
1627      $form_container = new FormContainer($lang->inline_post_moderation);
1628  
1629      $softdelete_restore = array(
1630          '' => $lang->no_change,
1631          'restore' => $lang->restore,
1632          'softdelete' => $lang->softdelete,
1633          'toggle' => $lang->toggle
1634      );
1635  
1636      $form_container->output_row($lang->softdelete_restore_posts." <em>*</em>", '', $form->generate_select_box('softdeleteposts', $softdelete_restore, $mybb->input['softdeleteposts'], array('id' => 'softdeleteposts')), 'softdeleteposts');
1637      $form_container->output_row($lang->delete_posts." <em>*</em>", '', $form->generate_yes_no_radio('deleteposts', $mybb->input['deleteposts']));
1638      $form_container->output_row($lang->merge_posts." <em>*</em>", $lang->merge_posts_desc, $form->generate_yes_no_radio('mergeposts', $mybb->input['mergeposts']));
1639      $form_container->output_row($lang->approve_unapprove_posts." <em>*</em>", '', $form->generate_select_box('approveposts', $approve_unapprove, $mybb->input['approveposts'], array('id' => 'approveposts')), 'approveposts');
1640      $form_container->end();
1641  
1642      $selectoptions = "<option value=\"-1\"{$do_not_split_checked}>{$lang->do_not_split}</option>\n";
1643      $selectoptions .= "<option value=\"-2\"{$split_same_checked} style=\"border-bottom: 1px solid #000;\">{$lang->split_to_same_forum}</option>\n";
1644  
1645      $form_container = new FormContainer($lang->split_posts);
1646      $form_container->output_row($lang->split_posts2." <em>*</em>", '', $form->generate_forum_select('splitposts', $mybb->input['splitposts']));
1647      $form_container->output_row($lang->close_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsclose', $mybb->input['splitpostsclose']));
1648      $form_container->output_row($lang->stick_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsstick', $mybb->input['splitpostsstick']));
1649      $form_container->output_row($lang->unapprove_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsunapprove', $mybb->input['splitpostsunapprove']));
1650  
1651      $splitthreadprefix = build_prefixes();
1652      if(!empty($splitthreadprefix))
1653      {
1654          $split_thread_prefixes = array(
1655              '0' => $lang->no_prefix
1656          );
1657  
1658          foreach($splitthreadprefix as $prefix)
1659          {
1660              $split_thread_prefixes[$prefix['pid']] = $prefix['prefix'];
1661          }
1662  
1663          $form_container->output_row($lang->split_thread_prefix." <em>*</em>", '', $form->generate_select_box('splitthreadprefix', $split_thread_prefixes, array($mybb->get_input('splitthreadprefix', MyBB::INPUT_INT)), array('id' => 'splitthreadprefix')), 'splitthreadprefix');
1664      }
1665  
1666      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1667      $form_container->output_row($lang->split_thread_subject, $lang->split_thread_subject_desc, $form->generate_text_box('splitpostsnewsubject', $mybb->input['splitpostsnewsubject'], array('id' => 'splitpostsnewsubject ')), 'newreplysubject');
1668      $form_container->output_row($lang->add_new_split_reply, $lang->add_new_split_reply_desc, $form->generate_text_area('splitpostsaddreply', $mybb->input['splitpostsaddreply'], array('id' => 'splitpostsaddreply')), 'splitpostsaddreply');
1669      $form_container->output_row($lang->split_reply_subject, $lang->split_reply_subject_desc, $form->generate_text_box('splitpostsreplysubject', $mybb->input['splitpostsreplysubject'], array('id' => 'splitpostsreplysubject')), 'splitpostsreplysubject');
1670      $form_container->end();
1671  
1672      $open_close = array(
1673          '' => $lang->no_change,
1674          'open' => $lang->open,
1675          'close' => $lang->close,
1676          'toggle' => $lang->toggle
1677      );
1678  
1679      $stick_unstick = array(
1680          '' => $lang->no_change,
1681          'stick' => $lang->stick,
1682          'unstick' => $lang->unstick,
1683          'toggle' => $lang->toggle
1684      );
1685  
1686      $form_container = new FormContainer($lang->thread_moderation);
1687      $form_container->output_row($lang->approve_unapprove." <em>*</em>", '', $form->generate_select_box('approvethread', $approve_unapprove, $mybb->input['approvethread'], array('id' => 'approvethread')), 'approvethread');
1688      $form_container->output_row($lang->open_close_thread." <em>*</em>", '', $form->generate_select_box('openthread', $open_close, $mybb->input['openthread'], array('id' => 'openthread')), 'openthread');
1689      $form_container->output_row($lang->stick_unstick_thread." <em>*</em>", '', $form->generate_select_box('stickthread', $stick_unstick, $mybb->input['stickthread'], array('id' => 'stickthread')), 'stickthread');
1690  
1691  
1692      $actions = "
1693      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1694      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"1\" {$move_checked[1]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_move_thread}</strong></label></dt>
1695          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"2\" {$move_checked[2]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->move_thread}</strong></label></dt>
1696          <dd style=\"margin-top: 4px;\" id=\"move_2\" class=\"moves\">
1697              <table cellpadding=\"4\">
1698                  <tr>
1699                      <td><small>{$lang->forum_to_move_to}</small></td>
1700                      <td>".$form->generate_forum_select('move_1_forum', $mybb->input['move_1_forum'])."</td>
1701                  </tr>
1702                  <tr>
1703                      <td><small>{$lang->leave_redirect}</small></td>
1704                      <td>".$form->generate_yes_no_radio('move_2_redirect', $mybb->input['move_2_redirect'])."</td>
1705                  </tr>
1706                  <tr>
1707                      <td><small>{$lang->delete_redirect_after}</small></td>
1708                      <td>".$form->generate_numeric_field('move_3_redirecttime', $mybb->input['move_3_redirecttime'], array('style' => 'width: 3em;', 'min' => 0))." {$lang->days}</td>
1709                  </tr>
1710              </table>
1711          </dd>
1712      </dl>
1713      <script type=\"text/javascript\">
1714      checkAction('move');
1715      </script>";
1716      $form_container->output_row($lang->move_thread." <em>*</em>", $lang->move_thread_desc, $actions);
1717  
1718      $actions = "
1719      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
1720      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"1\" {$copy_checked[1]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_copy_thread}</strong></label></dt>
1721          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"2\" {$copy_checked[2]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->copy_thread}</strong></label></dt>
1722          <dd style=\"margin-top: 4px;\" id=\"copy_2\" class=\"copys\">
1723              <table cellpadding=\"4\">
1724                  <tr>
1725                      <td><small>{$lang->forum_to_copy_to}</small></td>
1726                      <td>".$form->generate_forum_select('copy_1_forum', $mybb->input['copy_1_forum'])."</td>
1727                  </tr>
1728              </table>
1729          </dd>
1730      </dl>
1731      <script type=\"text/javascript\">
1732      checkAction('copy');
1733      </script>";
1734      $form_container->output_row($lang->copy_thread." <em>*</em>", '', $actions);
1735      $form_container->output_row($lang->softdelete_restore_thread." <em>*</em>", '', $form->generate_select_box('softdeletethread', $softdelete_restore, $mybb->input['softdeletethread'], array('id' => 'softdeletethread')), 'softdeletethread');
1736      $form_container->output_row($lang->delete_thread." <em>*</em>", '', $form->generate_yes_no_radio('deletethread', $mybb->input['deletethread']));
1737  
1738      $threadprefixes = build_prefixes();
1739      if(!empty($threadprefixes))
1740      {
1741          $thread_prefixes = array(
1742              '-1' => $lang->no_change,
1743              '0' => $lang->no_prefix
1744          );
1745  
1746          foreach($threadprefixes as $prefix)
1747          {
1748              $thread_prefixes[$prefix['pid']] = $prefix['prefix'];
1749          }
1750  
1751          $form_container->output_row($lang->apply_thread_prefix." <em>*</em>", '', $form->generate_select_box('threadprefix', $thread_prefixes, array($mybb->get_input('threadprefix', MyBB::INPUT_INT)), array('id' => 'threadprefix')), 'threadprefix');
1752      }
1753  
1754      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1755      $form_container->output_row($lang->new_subject." <em>*</em>", $lang->new_subject_desc, $form->generate_text_box('newsubject', $mybb->input['newsubject']));
1756      $form_container->end();
1757  
1758      $form_container = new FormContainer($lang->add_new_reply);
1759      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1760      $form_container->output_row($lang->add_new_reply, $lang->add_new_reply_desc, $form->generate_text_area('newreply', $mybb->input['newreply']), 'newreply');
1761      $form_container->output_row($lang->reply_subject, $lang->reply_subject_desc, $form->generate_text_box('newreplysubject', $mybb->input['newreplysubject'], array('id' => 'newreplysubject')), 'newreplysubject');
1762      $form_container->end();
1763  
1764      $form_container = new FormContainer($lang->send_private_message);
1765      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
1766      $form_container->output_row($lang->private_message_message, $lang->private_message_message_desc, $form->generate_text_area('pm_message', $mybb->input['pm_message'], array('id' => 'pm_message')), 'pm_message');
1767      $form_container->output_row($lang->private_message_subject, $lang->private_message_subject_desc, $form->generate_text_box('pm_subject', $mybb->input['pm_subject'], array('id' => 'pm_subject')), 'pm_subject');
1768      $form_container->end();
1769  
1770      $plugins->run_hooks("admin_config_mod_tools_edit_post_tool_end");
1771  
1772      $buttons[] = $form->generate_submit_button($lang->save_post_tool);
1773  
1774      $form->output_submit_wrapper($buttons);
1775      $form->end();
1776  
1777      $page->output_footer();
1778  }
1779  
1780  if($mybb->input['action'] == "add_post_tool")
1781  {
1782      $plugins->run_hooks("admin_config_mod_tools_add_post_tool");
1783  
1784      if($mybb->request_method == 'post')
1785      {
1786          if(trim($mybb->input['title']) == "")
1787          {
1788              $errors[] = $lang->error_missing_title;
1789          }
1790  
1791          if(trim($mybb->input['description']) == "")
1792          {
1793              $errors[] = $lang->error_missing_description;
1794          }
1795  
1796          if($mybb->input['forum_type'] == 2)
1797          {
1798              $forum_checked[1] = '';
1799              $forum_checked[2] = "checked=\"checked\"";
1800  
1801              if(is_array($mybb->input['forum_1_forums']) && count($mybb->input['forum_1_forums']) < 1)
1802              {
1803                  $errors[] = $lang->error_no_forums_selected;
1804              }
1805          }
1806          else
1807          {
1808              $forum_checked[1] = "checked=\"checked\"";
1809              $forum_checked[2] = '';
1810  
1811              $mybb->input['forum_1_forums'] = '';
1812          }
1813  
1814          if($mybb->input['group_type'] == 2)
1815          {
1816              $group_checked[1] = '';
1817              $group_checked[2] = "checked=\"checked\"";
1818  
1819              if(is_array($mybb->input['group_1_groups']) && count($mybb->input['group_1_groups']) < 1)
1820              {
1821                  $errors[] = $lang->error_no_groups_selected;
1822              }
1823          }
1824          else
1825          {
1826              $group_checked[1] = "checked=\"checked\"";
1827              $group_checked[2] = '';
1828  
1829              $mybb->input['group_1_groups'] = '';
1830          }
1831  
1832          if($mybb->input['approvethread'] != '' && $mybb->input['approvethread'] != 'approve' && $mybb->input['approvethread'] != 'unapprove' && $mybb->input['approvethread'] != 'toggle')
1833          {
1834              $mybb->input['approvethread'] = '';
1835          }
1836  
1837          if($mybb->input['softdeletethread'] != '' && $mybb->input['softdeletethread'] != 'softdelete' && $mybb->input['softdeletethread'] != 'restore' && $mybb->input['softdeletethread'] != 'toggle')
1838          {
1839              $mybb->input['softdeletethread'] = '';
1840          }
1841  
1842          if($mybb->input['openthread'] != '' && $mybb->input['openthread'] != 'open' && $mybb->input['openthread'] != 'close' && $mybb->input['openthread'] != 'toggle')
1843          {
1844              $mybb->input['openthread'] = '';
1845          }
1846  
1847          if($mybb->input['stickthread'] != '' && $mybb->input['stickthread'] != 'stick' && $mybb->input['stickthread'] != 'unstick' && $mybb->input['stickthread'] != 'toggle')
1848          {
1849              $mybb->input['stickthread'] = '';
1850          }
1851  
1852          if(!$mybb->get_input('threadprefix', MyBB::INPUT_INT))
1853          {
1854              $mybb->input['threadprefix'] = '';
1855          }
1856  
1857          if($mybb->input['move_type'] == 2)
1858          {
1859              $move_checked[1] = '';
1860              $move_checked[2] = "checked=\"checked\"";
1861  
1862              if(!$mybb->input['move_1_forum'])
1863              {
1864                  $errors[] = $lang->error_no_move_forum_selected;
1865              }
1866              else
1867              {
1868                  // Check that the destination forum is not a category
1869                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('move_1_forum', MyBB::INPUT_INT)."'");
1870                  if($db->fetch_field($query, "type") == "c")
1871                  {
1872                      $errors[] = $lang->error_forum_is_category;
1873                  }
1874              }
1875          }
1876          else
1877          {
1878              $move_checked[1] = "checked=\"checked\"";
1879              $move_checked[2] = '';
1880  
1881              $mybb->input['move_1_forum'] = '';
1882              $mybb->input['move_2_redirect'] = 0;
1883              $mybb->input['move_3_redirecttime'] = '';
1884          }
1885  
1886          if($mybb->input['copy_type'] == 2)
1887          {
1888              $copy_checked[1] = '';
1889              $copy_checked[2] = "checked=\"checked\"";
1890  
1891              if(!$mybb->input['copy_1_forum'])
1892              {
1893                  $errors[] = $lang->error_no_copy_forum_selected;
1894              }
1895              else
1896              {
1897                  $query = $db->simple_select("forums", "type", "fid = '".$mybb->get_input('copy_1_forum', MyBB::INPUT_INT)."'");
1898                  if($db->fetch_field($query, "type") == "c")
1899                  {
1900                      $errors[] = $lang->error_forum_is_category;
1901                  }
1902              }
1903          }
1904          else
1905          {
1906              $copy_checked[1] = 'checked=\"checked\"';
1907              $copy_checked[2] = '';
1908  
1909              $mybb->input['copy_1_forum'] = '';
1910          }
1911  
1912          if($mybb->input['approveposts'] != '' && $mybb->input['approveposts'] != 'approve' && $mybb->input['approveposts'] != 'unapprove' && $mybb->input['approveposts'] != 'toggle')
1913          {
1914              $mybb->input['approveposts'] = '';
1915          }
1916  
1917          if($mybb->input['softdeleteposts'] != '' && $mybb->input['softdeleteposts'] != 'softdelete' && $mybb->input['softdeleteposts'] != 'restore' && $mybb->input['softdeleteposts'] != 'toggle')
1918          {
1919              $mybb->input['softdeleteposts'] = '';
1920          }
1921  
1922          if($mybb->input['splitposts'] < -2)
1923          {
1924              $mybb->input['splitposts'] = -1;
1925          }
1926  
1927          if($mybb->input['splitpostsclose'] == 1)
1928          {
1929              $mybb->input['splitpostsclose'] = 'close';
1930          }
1931          else
1932          {
1933              $mybb->input['splitpostsclose'] = '';
1934          }
1935  
1936          if($mybb->input['splitpostsstick'] == 1)
1937          {
1938              $mybb->input['splitpostsstick'] = 'stick';
1939          }
1940          else
1941          {
1942              $mybb->input['splitpostsstick'] = '';
1943          }
1944  
1945          if($mybb->input['splitpostsunapprove'] == 1)
1946          {
1947              $mybb->input['splitpostsunapprove'] = 'unapprove';
1948          }
1949          else
1950          {
1951              $mybb->input['splitpostsunapprove'] = '';
1952          }
1953  
1954          if(!$mybb->get_input('splitthreadprefix', MyBB::INPUT_INT))
1955          {
1956              $mybb->input['splitthreadprefix'] = '';
1957          }
1958  
1959          if(!$errors)
1960          {
1961              $thread_options = array(
1962                  'confirmation' => $mybb->get_input('confirmation', MyBB::INPUT_INT),
1963                  'deletethread' => $mybb->get_input('deletethread', MyBB::INPUT_INT),
1964                  'softdeletethread' => $mybb->input['softdeletethread'],
1965                  'approvethread' => $mybb->input['approvethread'],
1966                  'openthread' => $mybb->input['openthread'],
1967                  'stickthread' => $mybb->input['stickthread'],
1968                  'movethread' => $mybb->get_input('move_1_forum', MyBB::INPUT_INT),
1969                  'movethreadredirect' => $mybb->get_input('move_2_redirect', MyBB::INPUT_INT),
1970                  'movethreadredirectexpire' => $mybb->get_input('move_3_redirecttime', MyBB::INPUT_INT),
1971                  'copythread' => $mybb->get_input('copy_1_forum', MyBB::INPUT_INT),
1972                  'newsubject' => $mybb->input['newsubject'],
1973                  'addreply' => $mybb->input['newreply'],
1974                  'replysubject' => $mybb->input['newreplysubject'],
1975                  'pm_subject' => $mybb->input['pm_subject'],
1976                  'pm_message' => $mybb->input['pm_message'],
1977                  'threadprefix' => $mybb->get_input('threadprefix', MyBB::INPUT_INT)
1978              );
1979  
1980              if(stripos($mybb->input['splitpostsnewsubject'], '{subject}') === false)
1981              {
1982                  $mybb->input['splitpostsnewsubject'] = '{subject}'.$mybb->input['splitpostsnewsubject'];
1983              }
1984  
1985              $post_options = array(
1986                  'deleteposts' => $mybb->get_input('deleteposts', MyBB::INPUT_INT),
1987                  'softdeleteposts' => $mybb->input['softdeleteposts'],
1988                  'mergeposts' => $mybb->get_input('mergeposts', MyBB::INPUT_INT),
1989                  'approveposts' => $mybb->input['approveposts'],
1990                  'splitposts' => $mybb->get_input('splitposts', MyBB::INPUT_INT),
1991                  'splitpostsclose' => $mybb->input['splitpostsclose'],
1992                  'splitpostsstick' => $mybb->input['splitpostsstick'],
1993                  'splitpostsunapprove' => $mybb->input['splitpostsunapprove'],
1994                  'splitthreadprefix' => $mybb->get_input('splitthreadprefix', MyBB::INPUT_INT),
1995                  'splitpostsnewsubject' => $mybb->input['splitpostsnewsubject'],
1996                  'splitpostsaddreply' => $mybb->input['splitpostsaddreply'],
1997                  'splitpostsreplysubject' => $mybb->input['splitpostsreplysubject']
1998              );
1999  
2000              $args = array(
2001                  'thread_options' => &$thread_options,
2002                  'post_options' => &$post_options,
2003              );
2004  
2005              $plugins->run_hooks("admin_config_mod_tools_add_post_tool_options", $args);
2006  
2007              $new_tool['type'] = 'p';
2008              $new_tool['threadoptions'] = $db->escape_string(my_serialize($thread_options));
2009              $new_tool['postoptions'] = $db->escape_string(my_serialize($post_options));
2010              $new_tool['name'] = $db->escape_string($mybb->input['title']);
2011              $new_tool['description'] = $db->escape_string($mybb->input['description']);
2012              $new_tool['forums'] = '';
2013              $new_tool['groups'] = '';
2014  
2015              if($mybb->input['forum_type'] == 2)
2016              {
2017                  if(is_array($mybb->input['forum_1_forums']))
2018                  {
2019                      $checked = array();
2020  
2021                      foreach($mybb->input['forum_1_forums'] as $fid)
2022                      {
2023                          $checked[] = (int)$fid;
2024                      }
2025  
2026                      $new_tool['forums'] = implode(',', $checked);
2027                  }
2028              }
2029              else
2030              {
2031                  $new_tool['forums'] = "-1";
2032              }
2033  
2034              if($mybb->input['group_type'] == 2)
2035              {
2036                  if(is_array($mybb->input['group_1_groups']))
2037                  {
2038                      $checked = array();
2039  
2040                      foreach($mybb->input['group_1_groups'] as $gid)
2041                      {
2042                          $checked[] = (int)$gid;
2043                      }
2044  
2045                      $new_tool['groups'] = implode(',', $checked);
2046                  }
2047              }
2048              else
2049              {
2050                  $new_tool['groups'] = "-1";
2051              }
2052  
2053              $tid = $db->insert_query("modtools", $new_tool);
2054  
2055              $plugins->run_hooks("admin_config_mod_tools_add_post_tool_commit");
2056  
2057              // Log admin action
2058              log_admin_action($tid, $mybb->input['title']);
2059              $cache->update_forumsdisplay();
2060  
2061              flash_message($lang->success_mod_tool_created, 'success');
2062              admin_redirect("index.php?module=config-mod_tools&action=post_tools");
2063          }
2064      }
2065  
2066      $page->add_breadcrumb_item($lang->add_new_post_tool);
2067      $page->output_header($lang->mod_tools." - ".$lang->add_new_post_tool);
2068  
2069      $sub_tabs['thread_tools'] = array(
2070          'title' => $lang->thread_tools,
2071          'link' => "index.php?module=config-mod_tools"
2072      );
2073      $sub_tabs['add_thread_tool'] = array(
2074          'title'=> $lang->add_new_thread_tool,
2075          'link' => "index.php?module=config-mod_tools&amp;action=add_thread_tool"
2076      );
2077      $sub_tabs['post_tools'] = array(
2078          'title' => $lang->post_tools,
2079          'link' => "index.php?module=config-mod_tools&amp;action=post_tools",
2080      );
2081      $sub_tabs['add_post_tool'] = array(
2082          'title'=> $lang->add_new_post_tool,
2083          'link' => "index.php?module=config-mod_tools&amp;action=add_post_tool",
2084          'description' => $lang->add_post_tool_desc
2085      );
2086  
2087      $page->output_nav_tabs($sub_tabs, 'add_post_tool');
2088  
2089      $form = new Form("index.php?module=config-mod_tools&amp;action=add_post_tool", 'post');
2090  
2091      if($errors)
2092      {
2093          $page->output_inline_error($errors);
2094      }
2095      else
2096      {
2097          $mybb->input['title'] = '';
2098          $mybb->input['description'] = '';
2099          $mybb->input['forum_1_forums'] = '';
2100          $forum_checked[1] = "checked=\"checked\"";
2101          $forum_checked[2] = '';
2102          $mybb->input['group_1_groups'] = '';
2103          $group_checked[1] = "checked=\"checked\"";
2104          $group_checked[2] = '';
2105          $mybb->input['confirmation'] = '0';
2106          $mybb->input['approvethread'] = '';
2107          $mybb->input['softdeletethread'] = '';
2108          $mybb->input['openthread'] = '';
2109          $mybb->input['stickthread'] = '';
2110          $mybb->input['move_1_forum'] = '';
2111          $mybb->input['move_2_redirect'] = '0';
2112          $mybb->input['move_3_redirecttime'] = '';
2113          $move_checked[1] = "checked=\"checked\"";
2114          $move_checked[2] = '';
2115          $copy_checked[1] = "checked=\"checked\"";
2116          $copy_checked[2] = '';
2117          $mybb->input['copy_1_forum'] = '';
2118          $mybb->input['deletethread'] = '0';
2119          $mybb->input['threadprefix'] = '-1';
2120          $mybb->input['newsubject'] = '{subject}';
2121          $mybb->input['newreply'] = '';
2122          $mybb->input['newreplysubject'] = '{subject}';
2123          $do_not_split_checked = ' selected="selected"';
2124          $split_same_checked = '';
2125          $mybb->input['deleteposts'] = '0';
2126          $mybb->input['mergeposts'] = '0';
2127          $mybb->input['approveposts'] = '';
2128          $mybb->input['softdeleteposts'] = '';
2129          $mybb->input['splitposts'] = '-1';
2130          $mybb->input['splitpostsclose'] = '0';
2131          $mybb->input['splitpostsstick'] = '0';
2132          $mybb->input['splitpostsunapprove'] = '0';
2133          $mybb->input['splitthreadprefix'] = '0';
2134          $mybb->input['splitpostsnewsubject'] = '{subject}';
2135          $mybb->input['splitpostsaddreply'] = '';
2136          $mybb->input['splitpostsreplysubject'] = '{subject}';
2137      }
2138  
2139      $form_container = new FormContainer($lang->general_options);
2140      $form_container->output_row($lang->name." <em>*</em>", '', $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
2141      $form_container->output_row($lang->short_description." <em>*</em>", '', $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
2142  
2143      $actions = "<script type=\"text/javascript\">
2144  	function checkAction(id)
2145      {
2146          var checked = '';
2147  
2148          $('.'+id+'s_check').each(function(e, val)
2149          {
2150              if($(this).prop('checked') == true)
2151              {
2152                  checked = $(this).val();
2153              }
2154          });
2155          $('.'+id+'s').each(function(e)
2156          {
2157              $(this).hide();
2158          });
2159          if($('#'+id+'_'+checked))
2160          {
2161              $('#'+id+'_'+checked).show();
2162          }
2163      }
2164  </script>
2165      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
2166      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
2167          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
2168          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
2169              <table cellpadding=\"4\">
2170                  <tr>
2171                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
2172                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
2173                  </tr>
2174              </table>
2175          </dd>
2176      </dl>
2177      <script type=\"text/javascript\">
2178      checkAction('forum');
2179      </script>";
2180      $form_container->output_row($lang->available_in_forums." <em>*</em>", '', $actions);
2181  
2182      $actions = "<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
2183      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
2184          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
2185          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
2186              <table cellpadding=\"4\">
2187                  <tr>
2188                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
2189                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
2190                  </tr>
2191              </table>
2192          </dd>
2193      </dl>
2194      <script type=\"text/javascript\">
2195      checkAction('group');
2196      </script>";
2197      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $actions);
2198      $form_container->output_row($lang->show_confirmation." <em>*</em>", '', $form->generate_yes_no_radio('confirmation', $mybb->input['confirmation'], array('style' => 'width: 2em;')));
2199      $form_container->end();
2200  
2201      $approve_unapprove = array(
2202          '' => $lang->no_change,
2203          'approve' => $lang->approve,
2204          'unapprove' => $lang->unapprove,
2205          'toggle' => $lang->toggle
2206      );
2207  
2208      $form_container = new FormContainer($lang->inline_post_moderation);
2209  
2210      $softdelete_restore = array(
2211          '' => $lang->no_change,
2212          'restore' => $lang->restore,
2213          'softdelete' => $lang->softdelete,
2214          'toggle' => $lang->toggle
2215      );
2216  
2217      $form_container->output_row($lang->softdelete_restore_posts." <em>*</em>", '', $form->generate_select_box('softdeleteposts', $softdelete_restore, $mybb->input['softdeleteposts'], array('id' => 'softdeleteposts')), 'softdeleteposts');
2218      $form_container->output_row($lang->delete_posts." <em>*</em>", '', $form->generate_yes_no_radio('deleteposts', $mybb->input['deleteposts']));
2219      $form_container->output_row($lang->merge_posts." <em>*</em>", $lang->merge_posts_desc, $form->generate_yes_no_radio('mergeposts', $mybb->input['mergeposts']));
2220      $form_container->output_row($lang->approve_unapprove_posts." <em>*</em>", '', $form->generate_select_box('approveposts', $approve_unapprove, $mybb->input['approveposts'], array('id' => 'approveposts')), 'approveposts');
2221      $form_container->end();
2222  
2223      $selectoptions = "<option value=\"-1\"{$do_not_split_checked}>{$lang->do_not_split}</option>\n";
2224      $selectoptions .= "<option value=\"-2\"{$split_same_checked} style=\"border-bottom: 1px solid #000;\">{$lang->split_to_same_forum}</option>\n";
2225  
2226      $form_container = new FormContainer($lang->split_posts);
2227      $form_container->output_row($lang->split_posts2." <em>*</em>", '', $form->generate_forum_select('splitposts', $mybb->input['splitposts']));
2228      $form_container->output_row($lang->close_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsclose', $mybb->input['splitpostsclose']));
2229      $form_container->output_row($lang->stick_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsstick', $mybb->input['splitpostsstick']));
2230      $form_container->output_row($lang->unapprove_split_thread." <em>*</em>", '', $form->generate_yes_no_radio('splitpostsunapprove', $mybb->input['splitpostsunapprove']));
2231  
2232      $splitthreadprefix = build_prefixes();
2233      if(!empty($splitthreadprefix))
2234      {
2235          $split_thread_prefixes = array(
2236              '0' => $lang->no_prefix
2237          );
2238  
2239          foreach($splitthreadprefix as $prefix)
2240          {
2241              $split_thread_prefixes[$prefix['pid']] = $prefix['prefix'];
2242          }
2243  
2244          $form_container->output_row($lang->split_thread_prefix." <em>*</em>", '', $form->generate_select_box('splitthreadprefix', $split_thread_prefixes, array($mybb->get_input('splitthreadprefix', MyBB::INPUT_INT)), array('id' => 'splitthreadprefix')), 'splitthreadprefix');
2245      }
2246  
2247      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
2248      $form_container->output_row($lang->split_thread_subject, $lang->split_thread_subject_desc, $form->generate_text_box('splitpostsnewsubject', $mybb->input['splitpostsnewsubject'], array('id' => 'splitpostsnewsubject ')), 'newreplysubject');
2249      $form_container->output_row($lang->add_new_split_reply, $lang->add_new_split_reply_desc, $form->generate_text_area('splitpostsaddreply', $mybb->input['splitpostsaddreply'], array('id' => 'splitpostsaddreply')), 'splitpostsaddreply');
2250      $form_container->output_row($lang->split_reply_subject, $lang->split_reply_subject_desc, $form->generate_text_box('splitpostsreplysubject', $mybb->input['splitpostsreplysubject'], array('id' => 'splitpostsreplysubject')), 'splitpostsreplysubject');
2251      $form_container->end();
2252  
2253      $open_close = array(
2254          '' => $lang->no_change,
2255          'open' => $lang->open,
2256          'close' => $lang->close,
2257          'toggle' => $lang->toggle
2258      );
2259  
2260      $stick_unstick = array(
2261          '' => $lang->no_change,
2262          'stick' => $lang->stick,
2263          'unstick' => $lang->unstick,
2264          'toggle' => $lang->toggle
2265      );
2266  
2267  
2268      $form_container = new FormContainer($lang->thread_moderation);
2269      $form_container->output_row($lang->approve_unapprove." <em>*</em>", '', $form->generate_select_box('approvethread', $approve_unapprove, $mybb->input['approvethread'], array('id' => 'approvethread')), 'approvethread');
2270      $form_container->output_row($lang->open_close_thread." <em>*</em>", '', $form->generate_select_box('openthread', $open_close, $mybb->input['openthread'], array('id' => 'openthread')), 'openthread');
2271      $form_container->output_row($lang->stick_unstick_thread." <em>*</em>", '', $form->generate_select_box('stickthread', $stick_unstick, $mybb->input['stickthread'], array('id' => 'stickthread')), 'stickthread');
2272  
2273  
2274      $actions = "
2275      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
2276      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"1\" {$move_checked[1]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_move_thread}</strong></label></dt>
2277          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"move_type\" value=\"2\" {$move_checked[2]} class=\"moves_check\" onclick=\"checkAction('move');\" style=\"vertical-align: middle;\" /> <strong>{$lang->move_thread}</strong></label></dt>
2278          <dd style=\"margin-top: 4px;\" id=\"move_2\" class=\"moves\">
2279              <table cellpadding=\"4\">
2280                  <tr>
2281                      <td><small>{$lang->forum_to_move_to}</small></td>
2282                      <td>".$form->generate_forum_select('move_1_forum', $mybb->input['move_1_forum'])."</td>
2283                  </tr>
2284                  <tr>
2285                      <td><small>{$lang->leave_redirect}</small></td>
2286                      <td>".$form->generate_yes_no_radio('move_2_redirect', $mybb->input['move_2_redirect'])."</td>
2287                  </tr>
2288                  <tr>
2289                      <td><small>{$lang->delete_redirect_after}</small></td>
2290                      <td>".$form->generate_numeric_field('move_3_redirecttime', $mybb->input['move_3_redirecttime'], array('style' => 'width: 3em;', 'min' => 0))." {$lang->days}</td>
2291                  </tr>
2292              </table>
2293          </dd>
2294      </dl>
2295      <script type=\"text/javascript\">
2296      checkAction('move');
2297      </script>";
2298      $form_container->output_row($lang->move_thread." <em>*</em>", $lang->move_thread_desc, $actions);
2299  
2300      $actions = "
2301      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
2302      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"1\" {$copy_checked[1]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->do_not_copy_thread}</strong></label></dt>
2303          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"copy_type\" value=\"2\" {$copy_checked[2]} class=\"copys_check\" onclick=\"checkAction('copy');\" style=\"vertical-align: middle;\" /> <strong>{$lang->copy_thread}</strong></label></dt>
2304          <dd style=\"margin-top: 4px;\" id=\"copy_2\" class=\"copys\">
2305              <table cellpadding=\"4\">
2306                  <tr>
2307                      <td><small>{$lang->forum_to_copy_to}</small></td>
2308                      <td>".$form->generate_forum_select('copy_1_forum', $mybb->input['copy_1_forum'])."</td>
2309                  </tr>
2310              </table>
2311          </dd>
2312      </dl>
2313      <script type=\"text/javascript\">
2314      checkAction('copy');
2315      </script>";
2316      $form_container->output_row($lang->copy_thread." <em>*</em>", '', $actions);
2317      $form_container->output_row($lang->softdelete_restore_thread." <em>*</em>", '', $form->generate_select_box('softdeletethread', $softdelete_restore, $mybb->input['softdeletethread'], array('id' => 'softdeletethread')), 'softdeletethread');
2318      $form_container->output_row($lang->delete_thread." <em>*</em>", '', $form->generate_yes_no_radio('deletethread', $mybb->input['deletethread']));
2319  
2320      $threadprefixes = build_prefixes();
2321      if(!empty($threadprefixes))
2322      {
2323          $thread_prefixes = array(
2324              '-1' => $lang->no_change,
2325              '0' => $lang->no_prefix
2326          );
2327  
2328          foreach($threadprefixes as $prefix)
2329          {
2330              $thread_prefixes[$prefix['pid']] = $prefix['prefix'];
2331          }
2332  
2333          $form_container->output_row($lang->apply_thread_prefix." <em>*</em>", '', $form->generate_select_box('threadprefix', $thread_prefixes, $mybb->input['threadprefix'], array('id' => 'threadprefix')), 'threadprefix');
2334      }
2335  
2336      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
2337      $form_container->output_row($lang->new_subject." <em>*</em>", $lang->new_subject_desc, $form->generate_text_box('newsubject', $mybb->input['newsubject']));
2338      $form_container->end();
2339  
2340      $form_container = new FormContainer($lang->add_new_reply);
2341      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
2342      $form_container->output_row($lang->add_new_reply, $lang->add_new_reply_desc, $form->generate_text_area('newreply', $mybb->input['newreply'], array('id' => 'newreply')), 'newreply');
2343      $form_container->output_row($lang->reply_subject, $lang->reply_subject_desc, $form->generate_text_box('newreplysubject', $mybb->input['newreplysubject'], array('id' => 'newreplysubject')), 'newreplysubject');
2344      $form_container->end();
2345  
2346      $form_container = new FormContainer($lang->send_private_message);
2347      $form_container->output_row($lang->subject_message_replacements, $lang->subject_message_replacements_desc);
2348      $form_container->output_row($lang->private_message_message, $lang->private_message_message_desc, $form->generate_text_area('pm_message', $mybb->get_input('pm_message'), array('id' => 'pm_message')), 'pm_message');
2349      $form_container->output_row($lang->private_message_subject, $lang->private_message_subject_desc, $form->generate_text_box('pm_subject', $mybb->get_input('pm_subject'), array('id' => 'pm_subject')), 'pm_subject');
2350      $form_container->end();
2351  
2352      $plugins->run_hooks("admin_config_mod_tools_add_post_tool_end");
2353  
2354      $buttons[] = $form->generate_submit_button($lang->save_post_tool);
2355  
2356      $form->output_submit_wrapper($buttons);
2357      $form->end();
2358  
2359      $page->output_footer();
2360  }
2361  
2362  if(!$mybb->input['action'])
2363  {
2364      $plugins->run_hooks("admin_config_mod_tools_start");
2365  
2366      $page->output_header($lang->mod_tools." - ".$lang->thread_tools);
2367  
2368      $sub_tabs['thread_tools'] = array(
2369          'title' => $lang->thread_tools,
2370          'link' => "index.php?module=config-mod_tools",
2371          'description' => $lang->thread_tools_desc
2372      );
2373      $sub_tabs['add_thread_tool'] = array(
2374          'title'=> $lang->add_new_thread_tool,
2375          'link' => "index.php?module=config-mod_tools&amp;action=add_thread_tool"
2376      );
2377      $sub_tabs['post_tools'] = array(
2378          'title' => $lang->post_tools,
2379          'link' => "index.php?module=config-mod_tools&amp;action=post_tools",
2380      );
2381      $sub_tabs['add_post_tool'] = array(
2382          'title'=> $lang->add_new_post_tool,
2383          'link' => "index.php?module=config-mod_tools&amp;action=add_post_tool"
2384      );
2385  
2386      $page->output_nav_tabs($sub_tabs, 'thread_tools');
2387  
2388      $table = new Table;
2389      $table->construct_header($lang->title);
2390      $table->construct_header($lang->controls, array('class' => "align_center", 'colspan' => 2));
2391  
2392      $query = $db->simple_select('modtools', 'tid, name, description, type', "type='t'", array('order_by' => 'name'));
2393      while($tool = $db->fetch_array($query))
2394      {
2395          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=edit_thread_tool&amp;tid={$tool['tid']}\"><strong>".htmlspecialchars_uni($tool['name'])."</strong></a><br /><small>".htmlspecialchars_uni($tool['description'])."</small>");
2396          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=edit_thread_tool&amp;tid={$tool['tid']}\">{$lang->edit}</a>", array('width' => 100, 'class' => "align_center"));
2397          $table->construct_cell("<a href=\"index.php?module=config-mod_tools&amp;action=delete_thread_tool&amp;tid={$tool['tid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_thread_tool_deletion}')\">{$lang->delete}</a>", array('width' => 100, 'class' => "align_center"));
2398          $table->construct_row();
2399      }
2400  
2401      if($table->num_rows() == 0)
2402      {
2403          $table->construct_cell($lang->no_thread_tools, array('colspan' => 3));
2404          $table->construct_row();
2405      }
2406  
2407      $table->output($lang->thread_tools);
2408  
2409      $page->output_footer();
2410  }


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