[ Index ]

PHP Cross Reference of MyBB 1.8.30

title

Body

[close]

/admin/modules/config/ -> settings.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->board_settings, "index.php?module=config-settings");
  18  
  19  $plugins->run_hooks("admin_config_settings_begin");
  20  
  21  // Creating a new setting group
  22  if($mybb->input['action'] == "addgroup")
  23  {
  24      $plugins->run_hooks("admin_config_settings_addgroup");
  25  
  26      if($mybb->request_method == "post")
  27      {
  28          // Validate title
  29          if(!trim($mybb->input['title']))
  30          {
  31              $errors[] = $lang->error_missing_group_title;
  32          }
  33  
  34          // Validate identifier
  35          if(!trim($mybb->input['name']))
  36          {
  37              $errors[] = $lang->error_missing_group_name;
  38          }
  39          $query = $db->simple_select("settinggroups", "title", "name='".$db->escape_string($mybb->input['name'])."'");
  40          if($db->num_rows($query) > 0)
  41          {
  42              $dup_group_title = $db->fetch_field($query, 'title');
  43              $errors[] = $lang->sprintf($lang->error_duplicate_group_name, $dup_group_title);
  44          }
  45  
  46          if(!$errors)
  47          {
  48              $new_setting_group = array(
  49                  "name" => $db->escape_string($mybb->input['name']),
  50                  "title" => $db->escape_string($mybb->input['title']),
  51                  "description" => $db->escape_string($mybb->input['description']),
  52                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
  53                  "isdefault" => 0
  54              );
  55              $gid = $db->insert_query("settinggroups", $new_setting_group);
  56  
  57              $plugins->run_hooks("admin_config_settings_addgroup_commit");
  58  
  59              // Log admin action
  60              log_admin_action($gid, $mybb->input['name']);
  61  
  62              flash_message($lang->success_setting_group_added, 'success');
  63              admin_redirect("index.php?module=config-settings&action=manage");
  64          }
  65      }
  66  
  67      $page->add_breadcrumb_item($lang->add_new_setting_group);
  68      $page->output_header($lang->board_settings." - ".$lang->add_new_setting_group);
  69  
  70      $sub_tabs['change_settings'] = array(
  71          'title' => $lang->change_settings,
  72          'link' => "index.php?module=config-settings"
  73      );
  74  
  75      $sub_tabs['add_setting'] = array(
  76          'title' => $lang->add_new_setting,
  77          'link' => "index.php?module=config-settings&amp;action=add"
  78      );
  79  
  80      $sub_tabs['add_setting_group'] = array(
  81          'title' => $lang->add_new_setting_group,
  82          'link' => "index.php?module=config-settings&amp;action=addgroup",
  83          'description' => $lang->add_new_setting_group_desc
  84      );
  85  
  86      $sub_tabs['modify_setting'] = array(
  87          'title' => $lang->modify_existing_settings,
  88          'link' => "index.php?module=config-settings&amp;action=manage"
  89      );
  90  
  91      $page->output_nav_tabs($sub_tabs, 'add_setting_group');
  92  
  93      $form = new Form("index.php?module=config-settings&amp;action=addgroup", "post", "add");
  94  
  95      if($errors)
  96      {
  97          $page->output_inline_error($errors);
  98      }
  99  
 100      $form_container = new FormContainer($lang->add_new_setting_group);
 101      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 102      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $mybb->get_input('description'), array('id' => 'description')), 'description');
 103      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $mybb->get_input('disporder'), array('id' => 'disporder', 'min' => 0)), 'disporder');
 104      $form_container->output_row($lang->name." <em>*</em>", $lang->group_name_desc, $form->generate_text_box('name', $mybb->get_input('name'), array('id' => 'name')), 'name');
 105      $form_container->end();
 106  
 107      $buttons[] = $form->generate_submit_button($lang->insert_new_setting_group);
 108      $form->output_submit_wrapper($buttons);
 109      $form->end();
 110  
 111      $page->output_footer();
 112  }
 113  
 114  // Edit setting group
 115  if($mybb->input['action'] == "editgroup")
 116  {
 117      $query = $db->simple_select("settinggroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 118      $group = $db->fetch_array($query);
 119  
 120      // Does the setting not exist?
 121      if(!$group['gid'])
 122      {
 123          flash_message($lang->error_invalid_gid2, 'error');
 124          admin_redirect("index.php?module=config-settings&action=manage");
 125      }
 126      // Prevent editing of default
 127      if($group['isdefault'] == 1)
 128      {
 129          flash_message($lang->error_cannot_edit_default, 'error');
 130          admin_redirect("index.php?module=config-settings&action=manage");
 131      }
 132  
 133      $plugins->run_hooks("admin_config_settings_editgroup");
 134  
 135      // Do edit?
 136      if($mybb->request_method == "post")
 137      {
 138          // Validate title
 139          if(!trim($mybb->input['title']))
 140          {
 141              $errors[] = $lang->error_missing_group_title;
 142          }
 143  
 144          // Validate identifier
 145          if(!trim($mybb->input['name']))
 146          {
 147              $errors[] = $lang->error_missing_group_name;
 148          }
 149          $query = $db->simple_select("settinggroups", "title", "name='".$db->escape_string($mybb->input['name'])."' AND gid != '{$group['gid']}'");
 150          if($db->num_rows($query) > 0)
 151          {
 152              $dup_group_title = $db->fetch_field($query, 'title');
 153              $errors[] = $lang->sprintf($lang->error_duplicate_group_name, $dup_group_title);
 154          }
 155  
 156          if(!$errors)
 157          {
 158              $update_setting_group = array(
 159                  "name" => $db->escape_string($mybb->input['name']),
 160                  "title" => $db->escape_string($mybb->input['title']),
 161                  "description" => $db->escape_string($mybb->input['description']),
 162                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
 163              );
 164  
 165              $plugins->run_hooks("admin_config_settings_editgroup_commit");
 166  
 167              $db->update_query("settinggroups", $update_setting_group, "gid='{$group['gid']}'");
 168  
 169              // Log admin action
 170              log_admin_action($group['gid'], $mybb->input['name']);
 171  
 172              flash_message($lang->success_setting_group_updated, 'success');
 173              admin_redirect("index.php?module=config-settings&action=manage");
 174          }
 175      }
 176  
 177      $page->add_breadcrumb_item($lang->edit_setting_group);
 178      $page->output_header($lang->board_settings." - ".$lang->edit_setting_group);
 179  
 180      $sub_tabs['edit_setting_group'] = array(
 181          'title' => $lang->edit_setting_group,
 182          'link' => "index.php?module=config-settings&amp;action=editgroup&amp;gid={$group['gid']}",
 183          'description' => $lang->edit_setting_group_desc
 184      );
 185  
 186      $page->output_nav_tabs($sub_tabs, 'edit_setting_group');
 187  
 188      $form = new Form("index.php?module=config-settings&amp;action=editgroup", "post", "editgroup");
 189  
 190      echo $form->generate_hidden_field("gid", $group['gid']);
 191  
 192      if($errors)
 193      {
 194          $group_data = $mybb->input;
 195          $page->output_inline_error($errors);
 196      }
 197      else
 198      {
 199          $group_data = $group;
 200      }
 201  
 202      $form_container = new FormContainer($lang->edit_setting_group);
 203      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $group_data['title'], array('id' => 'title')), 'title');
 204      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $group_data['description'], array('id' => 'description')), 'description');
 205      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $group_data['disporder'], array('id' => 'disporder', 'min' => 0)), 'disporder');
 206      $form_container->output_row($lang->name." <em>*</em>", $lang->group_name_desc, $form->generate_text_box('name', $group_data['name'], array('id' => 'name')), 'name');
 207      $form_container->end();
 208  
 209      $buttons[] = $form->generate_submit_button($lang->update_setting_group);
 210      $form->output_submit_wrapper($buttons);
 211      $form->end();
 212  
 213      $page->output_footer();
 214  }
 215  
 216  // Delete Setting Group
 217  if($mybb->input['action'] == "deletegroup")
 218  {
 219      $query = $db->simple_select("settinggroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 220      $group = $db->fetch_array($query);
 221  
 222      // Does the setting group not exist?
 223      if(!$group['gid'])
 224      {
 225          flash_message($lang->error_invalid_gid2, 'error');
 226          admin_redirect("index.php?module=config-settings&action=manage");
 227      }
 228      // Prevent deletion of default
 229      if($group['isdefault'] == 1)
 230      {
 231          flash_message($lang->error_cannot_edit_default, 'error');
 232          admin_redirect("index.php?module=config-settings&action=manage");
 233      }
 234  
 235      // User clicked no
 236      if($mybb->get_input('no'))
 237      {
 238          admin_redirect("index.php?module=config-settings&action=manage");
 239      }
 240  
 241      $plugins->run_hooks("admin_config_settings_deletegroup");
 242  
 243      if($mybb->request_method == "post")
 244      {
 245          // Delete the setting group and its settings
 246          $db->delete_query("settinggroups", "gid='{$group['gid']}'");
 247          $db->delete_query("settings", "gid='{$group['gid']}'");
 248  
 249          rebuild_settings();
 250  
 251          $plugins->run_hooks("admin_config_settings_deletegroup_commit");
 252  
 253          // Log admin action
 254          log_admin_action($group['gid'], $group['name']);
 255  
 256          flash_message($lang->success_setting_group_deleted, 'success');
 257          admin_redirect("index.php?module=config-settings&action=manage");
 258      }
 259      else
 260      {
 261          $page->output_confirm_action("index.php?module=config-settings&amp;action=deletegroup&amp;gid={$group['gid']}", $lang->confirm_setting_group_deletion);
 262      }
 263  }
 264  
 265  // Creating a new setting
 266  if($mybb->input['action'] == "add")
 267  {
 268      $plugins->run_hooks("admin_config_settings_add");
 269  
 270      if($mybb->request_method == "post")
 271      {
 272          if(!trim($mybb->input['title']))
 273          {
 274              $errors[] = $lang->error_missing_title;
 275          }
 276  
 277          $query = $db->simple_select("settinggroups", "gid", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 278          $gid = $db->fetch_field($query, 'gid');
 279          if(!$gid)
 280          {
 281              $errors[] = $lang->error_invalid_gid;
 282          }
 283  
 284          if(!trim($mybb->input['name']))
 285          {
 286              $errors[] = $lang->error_missing_name;
 287          }
 288          $query = $db->simple_select("settings", "title", "name='".$db->escape_string($mybb->input['name'])."'");
 289          if($db->num_rows($query) > 0)
 290          {
 291              $dup_setting_title = $db->fetch_field($query, 'title');
 292              $errors[] = $lang->sprintf($lang->error_duplicate_name, $dup_setting_title);
 293          }
 294  
 295          // do some type filtering
 296          $mybb->input['type'] = $mybb->get_input('type');
 297          if(!ctype_alnum($mybb->input['type']) || strtolower($mybb->input['type']) == "php")
 298          {
 299              $mybb->input['type'] = "";
 300          }
 301  
 302          if(!$mybb->input['type'])
 303          {
 304              $errors[] = $lang->error_invalid_type;
 305          }
 306  
 307          if(!$errors)
 308          {
 309              if($mybb->input['extra'])
 310              {
 311                  $options_code = "{$mybb->input['type']}\n{$mybb->input['extra']}";
 312              }
 313              else
 314              {
 315                  $options_code = $mybb->input['type'];
 316              }
 317  
 318              $mybb->input['name'] = str_replace("\\", '', $mybb->input['name']);
 319              $mybb->input['name'] = str_replace('$', '', $mybb->input['name']);
 320              $mybb->input['name'] = str_replace("'", '', $mybb->input['name']);
 321  
 322              if($options_code == "numeric")
 323              {
 324                  $value = $mybb->get_input('value', MyBB::INPUT_INT);
 325              }
 326              else
 327              {
 328                  $value = $db->escape_string($mybb->input['value']);
 329              }
 330  
 331              $new_setting = array(
 332                  "name" => $db->escape_string($mybb->input['name']),
 333                  "title" => $db->escape_string($mybb->input['title']),
 334                  "description" => $db->escape_string($mybb->input['description']),
 335                  "optionscode" => $db->escape_string($options_code),
 336                  "value" => $value,
 337                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
 338                  "gid" => $mybb->get_input('gid', MyBB::INPUT_INT)
 339              );
 340  
 341              $sid = $db->insert_query("settings", $new_setting);
 342              rebuild_settings();
 343  
 344              $plugins->run_hooks("admin_config_settings_add_commit");
 345  
 346              // Log admin action
 347              log_admin_action($sid, $mybb->input['title']);
 348  
 349              flash_message($lang->success_setting_added, 'success');
 350              admin_redirect("index.php?module=config-settings&action=manage");
 351          }
 352      }
 353  
 354      $page->add_breadcrumb_item($lang->add_new_setting);
 355      $page->output_header($lang->board_settings." - ".$lang->add_new_setting);
 356  
 357      $sub_tabs['change_settings'] = array(
 358          'title' => $lang->change_settings,
 359          'link' => "index.php?module=config-settings"
 360      );
 361  
 362      $sub_tabs['add_setting'] = array(
 363          'title' => $lang->add_new_setting,
 364          'link' => "index.php?module=config-settings&amp;action=add",
 365          'description' => $lang->add_new_setting_desc
 366      );
 367  
 368      $sub_tabs['add_setting_group'] = array(
 369          'title' => $lang->add_new_setting_group,
 370          'link' => "index.php?module=config-settings&amp;action=addgroup"
 371      );
 372  
 373      $sub_tabs['modify_setting'] = array(
 374          'title' => $lang->modify_existing_settings,
 375          'link' => "index.php?module=config-settings&amp;action=manage"
 376      );
 377  
 378      $page->output_nav_tabs($sub_tabs, 'add_setting');
 379  
 380      $form = new Form("index.php?module=config-settings&amp;action=add", "post", "add");
 381  
 382      if($errors)
 383      {
 384          $page->output_inline_error($errors);
 385      }
 386  
 387      $form_container = new FormContainer($lang->add_new_setting);
 388      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 389      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $mybb->get_input('description'), array('id' => 'description')), 'description');
 390  
 391      $query = $db->simple_select("settinggroups", "*", "", array('order_by' => 'disporder'));
 392      while($group = $db->fetch_array($query))
 393      {
 394          $group_lang_var = "setting_group_{$group['name']}";
 395          if(!empty($lang->$group_lang_var))
 396          {
 397              $options[$group['gid']] = htmlspecialchars_uni($lang->$group_lang_var);
 398          }
 399          else
 400          {
 401              $options[$group['gid']] = htmlspecialchars_uni($group['title']);
 402          }
 403      }
 404      $form_container->output_row($lang->group." <em>*</em>", "", $form->generate_select_box("gid", $options, $mybb->get_input('gid'), array('id' => 'gid')), 'gid');
 405      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $mybb->get_input('disporder'), array('id' => 'disporder', 'min' => 0)), 'disporder');
 406  
 407      $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $mybb->get_input('name'), array('id' => 'name')), 'name');
 408  
 409      $setting_types = array(
 410          "text" => $lang->text,
 411          "numeric" => $lang->numeric_text,
 412          "textarea" => $lang->textarea,
 413          "yesno" => $lang->yesno,
 414          "onoff" => $lang->onoff,
 415          "select" => $lang->select,
 416          "forumselect" => $lang->forum_selection_box,
 417          "forumselectsingle" => $lang->forum_selection_single,
 418          "groupselect" => $lang->group_selection_box,
 419          "groupselectsingle" => $lang->group_selection_single,
 420          "radio" => $lang->radio,
 421          "checkbox" => $lang->checkbox,
 422          "language" => $lang->language_selection_box,
 423          "adminlanguage" => $lang->adminlanguage,
 424          "cpstyle" => $lang->cpstyle,
 425          "prefixselect" => $lang->prefix_selection_box
 426          //"php" => $lang->php // Internal Use Only
 427      );
 428  
 429      $form_container->output_row($lang->type." <em>*</em>", "", $form->generate_select_box("type", $setting_types, $mybb->get_input('type'), array('id' => 'type')), 'type');
 430      $form_container->output_row($lang->extra, $lang->extra_desc, $form->generate_text_area('extra', $mybb->get_input('extra'), array('id' => 'extra')), 'extra', array(), array('id' => 'row_extra'));
 431      $form_container->output_row($lang->value, "", $form->generate_text_area('value', $mybb->get_input('value'), array('id' => 'value')), 'value');
 432      $form_container->end();
 433  
 434      $buttons[] = $form->generate_submit_button($lang->insert_new_setting);
 435      $form->output_submit_wrapper($buttons);
 436      $form->end();
 437  
 438      echo '<script type="text/javascript" src="./jscripts/peeker.js?ver=1821"></script>
 439      <script type="text/javascript">
 440          $(function() {
 441              new Peeker($("#type"), $("#row_extra"), /^(select|radio|checkbox|php)$/, false);
 442          });
 443          // Add a star to the extra row since the "extra" is required if the box is shown
 444          add_star("row_extra");
 445      </script>';
 446  
 447      $page->output_footer();
 448  }
 449  
 450  // Editing a particular setting
 451  if($mybb->input['action'] == "edit")
 452  {
 453      $query = $db->simple_select("settings", "*", "sid='".$mybb->get_input('sid', MyBB::INPUT_INT)."'");
 454      $setting = $db->fetch_array($query);
 455  
 456      // Does the setting not exist?
 457      if(!$setting['sid'])
 458      {
 459          flash_message($lang->error_invalid_sid, 'error');
 460          admin_redirect("index.php?module=config-settings");
 461      }
 462  
 463      // Prevent editing of default
 464      if($setting['isdefault'] == 1)
 465      {
 466          flash_message($lang->error_cannot_edit_default, 'error');
 467          admin_redirect("index.php?module=config-settings&action=manage");
 468      }
 469  
 470      $plugins->run_hooks("admin_config_settings_edit");
 471  
 472      $type = explode("\n", $setting['optionscode'], 2);
 473      $type = trim($type[0]);
 474      if($type == "php")
 475      {
 476          flash_message($lang->error_cannot_edit_php, 'error');
 477          admin_redirect("index.php?module=config-settings&action=manage");
 478      }
 479  
 480      if($mybb->request_method == "post")
 481      {
 482          if(!trim($mybb->input['title']))
 483          {
 484              $errors[] = $lang->error_missing_title;
 485          }
 486  
 487          if(!trim($mybb->input['name']))
 488          {
 489              $errors[] = $lang->error_missing_name;
 490          }
 491          $query = $db->simple_select("settings", "title", "name='".$db->escape_string($mybb->input['name'])."' AND sid != '{$setting['sid']}'");
 492          if($db->num_rows($query) > 0)
 493          {
 494              $dup_setting_title = $db->fetch_field($query, 'title');
 495              $errors[] = $lang->sprintf($lang->error_duplicate_name, $dup_setting_title);
 496          }
 497  
 498          // do some type filtering
 499          $mybb->input['type'] = $mybb->get_input('type');
 500          if(!ctype_alnum($mybb->input['type']) || strtolower($mybb->input['type']) == "php")
 501          {
 502              $mybb->input['type'] = "";
 503          }
 504  
 505          if(!$mybb->input['type'])
 506          {
 507              $errors[] = $lang->error_invalid_type;
 508          }
 509  
 510          if(!$errors)
 511          {
 512              if($mybb->input['extra'])
 513              {
 514                  $options_code = "{$mybb->input['type']}\n{$mybb->input['extra']}";
 515              }
 516              else
 517              {
 518                  $options_code = $mybb->input['type'];
 519              }
 520  
 521              $mybb->input['name'] = str_replace("\\", '', $mybb->input['name']);
 522              $mybb->input['name'] = str_replace('$', '', $mybb->input['name']);
 523              $mybb->input['name'] = str_replace("'", '', $mybb->input['name']);
 524  
 525              if($options_code == "numeric")
 526              {
 527                  $value = $mybb->get_input('value', MyBB::INPUT_INT);
 528              }
 529              else
 530              {
 531                  $value = $db->escape_string($mybb->input['value']);
 532              }
 533  
 534              $updated_setting = array(
 535                  "name" => $db->escape_string($mybb->input['name']),
 536                  "title" => $db->escape_string($mybb->input['title']),
 537                  "description" => $db->escape_string($mybb->input['description']),
 538                  "optionscode" => $db->escape_string($options_code),
 539                  "value" => $value,
 540                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
 541                  "gid" => $mybb->get_input('gid', MyBB::INPUT_INT)
 542              );
 543  
 544              $plugins->run_hooks("admin_config_settings_edit_commit");
 545  
 546              $db->update_query("settings", $updated_setting, "sid='{$setting['sid']}'");
 547              rebuild_settings();
 548  
 549              // Log admin action
 550              log_admin_action($setting['sid'], $mybb->input['title']);
 551  
 552              flash_message($lang->success_setting_updated, 'success');
 553              admin_redirect("index.php?module=config-settings&action=manage");
 554          }
 555      }
 556  
 557      $page->add_breadcrumb_item($lang->edit_setting);
 558      $page->output_header($lang->board_settings." - ".$lang->edit_setting);
 559  
 560      $sub_tabs['change_settings'] = array(
 561          'title' => $lang->change_settings,
 562          'link' => "index.php?module=config-settings",
 563      );
 564  
 565      $sub_tabs['add_setting'] = array(
 566          'title' => $lang->add_new_setting,
 567          'link' => "index.php?module=config-settings&amp;action=add"
 568      );
 569  
 570      $sub_tabs['add_setting_group'] = array(
 571          'title' => $lang->add_new_setting_group,
 572          'link' => "index.php?module=config-settings&amp;action=addgroup"
 573      );
 574  
 575      $sub_tabs['modify_setting'] = array(
 576          'title' => $lang->modify_existing_settings,
 577          'link' => "index.php?module=config-settings&amp;action=manage",
 578          'description' => $lang->modify_existing_settings_desc
 579      );
 580  
 581      $page->output_nav_tabs($sub_tabs, 'modify_setting');
 582  
 583      $form = new Form("index.php?module=config-settings&amp;action=edit", "post", "edit");
 584  
 585      echo $form->generate_hidden_field("sid", $setting['sid']);
 586  
 587      if($errors)
 588      {
 589          $setting_data = $mybb->input;
 590          $page->output_inline_error($errors);
 591      }
 592      else
 593      {
 594          $setting_data = $setting;
 595          $type = explode("\n", $setting['optionscode'], 2);
 596          $setting_data['type'] = trim($type[0]);
 597  
 598          if(isset($type[1]))
 599          {
 600              $setting_data['extra'] = trim($type[1]);
 601          }
 602      }
 603  
 604      $form_container = new FormContainer($lang->modify_setting);
 605      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $setting_data['title'], array('id' => 'title')), 'title');
 606      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $setting_data['description'], array('id' => 'description')), 'description');
 607  
 608      $query = $db->simple_select("settinggroups", "*", "", array('order_by' => 'disporder'));
 609      while($group = $db->fetch_array($query))
 610      {
 611          $group_lang_var = "setting_group_{$group['name']}";
 612          if(!empty($lang->$group_lang_var))
 613          {
 614              $options[$group['gid']] = htmlspecialchars_uni($lang->$group_lang_var);
 615          }
 616          else
 617          {
 618              $options[$group['gid']] = htmlspecialchars_uni($group['title']);
 619          }
 620      }
 621      $form_container->output_row($lang->group." <em>*</em>", "", $form->generate_select_box("gid", $options, $setting_data['gid'], array('id' => 'gid')), 'gid');
 622      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $setting_data['disporder'], array('id' => 'disporder', 'min' => 0)), 'disporder');
 623      $form_container->end();
 624  
 625      $form_container = new FormContainer($lang->setting_configuration, 1);
 626      $form_container->output_row($lang->name." <em>*</em>", $lang->name_desc, $form->generate_text_box('name', $setting_data['name'], array('id' => 'name')), 'name');
 627  
 628      $setting_types = array(
 629          "text" => $lang->text,
 630          "numeric" => $lang->numeric_text,
 631          "textarea" => $lang->textarea,
 632          "yesno" => $lang->yesno,
 633          "onoff" => $lang->onoff,
 634          "select" => $lang->select,
 635          "forumselect" => $lang->forum_selection_box,
 636          "forumselectsingle" => $lang->forum_selection_single,
 637          "groupselect" => $lang->group_selection_box,
 638          "groupselectsingle" => $lang->group_selection_single,
 639          "radio" => $lang->radio,
 640          "checkbox" => $lang->checkbox,
 641          "language" => $lang->language_selection_box,
 642          "adminlanguage" => $lang->adminlanguage,
 643          "cpstyle" => $lang->cpstyle,
 644          "prefixselect" => $lang->prefix_selection_box
 645          //"php" => $lang->php // Internal Use Only
 646      );
 647  
 648      $form_container->output_row($lang->type." <em>*</em>", "", $form->generate_select_box("type", $setting_types, $setting_data['type'], array('id' => 'type')), 'type');
 649      $form_container->output_row($lang->extra, $lang->extra_desc, $form->generate_text_area('extra', !empty($setting_data['extra']) ? $setting_data['extra'] : null, array('id' => 'extra')), 'extra', array(), array('id' => 'row_extra'));
 650      $form_container->output_row($lang->value, '', $form->generate_text_area('value', $setting_data['value'], array('id' => 'value')), 'value');
 651      $form_container->end();
 652  
 653      $buttons[] = $form->generate_submit_button($lang->update_setting);
 654      $form->output_submit_wrapper($buttons);
 655      $form->end();
 656  
 657      echo '<script type="text/javascript" src="./jscripts/peeker.js?ver=1821"></script>
 658      <script type="text/javascript">
 659          $(function() {
 660              new Peeker($("#type"), $("#row_extra"), /^(select|radio|checkbox|php)$/, false);
 661          });
 662          // Add a star to the extra row since the "extra" is required if the box is shown
 663          add_star("row_extra");
 664      </script>';
 665  
 666      $page->output_footer();
 667  }
 668  
 669  // Delete Setting
 670  if($mybb->input['action'] == "delete")
 671  {
 672      $query = $db->simple_select("settings", "*", "sid='".$mybb->get_input('sid', MyBB::INPUT_INT)."'");
 673      $setting = $db->fetch_array($query);
 674  
 675      // Does the setting not exist?
 676      if(empty($setting['sid']))
 677      {
 678          flash_message($lang->error_invalid_sid, 'error');
 679          admin_redirect("index.php?module=config-settings&action=manage");
 680      }
 681  
 682      // Prevent editing of default
 683      if($setting['isdefault'] == 1)
 684      {
 685          flash_message($lang->error_cannot_edit_default, 'error');
 686          admin_redirect("index.php?module=config-settings&action=manage");
 687      }
 688  
 689      // User clicked no
 690      if($mybb->get_input('no'))
 691      {
 692          admin_redirect("index.php?module=config-settings&action=manage");
 693      }
 694  
 695      $plugins->run_hooks("admin_config_settings_delete");
 696  
 697      if($mybb->request_method == "post")
 698      {
 699          // Delete the setting
 700          $db->delete_query("settings", "sid='{$setting['sid']}'");
 701  
 702          rebuild_settings();
 703  
 704          $plugins->run_hooks("admin_config_settings_delete_commit");
 705  
 706          // Log admin action
 707          log_admin_action($setting['sid'], $setting['title']);
 708  
 709          flash_message($lang->success_setting_deleted, 'success');
 710          admin_redirect("index.php?module=config-settings&action=manage");
 711      }
 712      else
 713      {
 714          $page->output_confirm_action("index.php?module=config-settings&amp;action=delete&amp;sid={$setting['sid']}", $lang->confirm_setting_deletion);
 715      }
 716  }
 717  
 718  // Modify Existing Settings
 719  if($mybb->input['action'] == "manage")
 720  {
 721      $plugins->run_hooks("admin_config_settings_manage");
 722  
 723      // Update orders
 724      if($mybb->request_method == "post")
 725      {
 726          if(is_array($mybb->input['group_disporder']))
 727          {
 728              foreach($mybb->input['group_disporder'] as $gid => $new_order)
 729              {
 730                  $gid = (int)$gid;
 731                  $update_group = array('disporder' => (int)$new_order);
 732                  $db->update_query("settinggroups", $update_group, "gid={$gid}");
 733              }
 734          }
 735  
 736          if(is_array($mybb->input['setting_disporder']))
 737          {
 738              foreach($mybb->input['setting_disporder'] as $sid => $new_order)
 739              {
 740                  $sid = (int)$sid;
 741                  $update_setting = array('disporder' => (int)$new_order);
 742                  $db->update_query("settings", $update_setting, "sid={$sid}");
 743              }
 744          }
 745  
 746          $plugins->run_hooks("admin_config_settings_manage_commit");
 747  
 748          // Log admin action
 749          log_admin_action();
 750  
 751          flash_message($lang->success_display_orders_updated, 'success');
 752          admin_redirect("index.php?module=config-settings&action=manage");
 753      }
 754  
 755      $page->add_breadcrumb_item($lang->modify_existing_settings);
 756      $page->output_header($lang->board_settings." - ".$lang->modify_existing_settings);
 757  
 758      $sub_tabs['change_settings'] = array(
 759          'title' => $lang->change_settings,
 760          'link' => "index.php?module=config-settings",
 761      );
 762  
 763      $sub_tabs['add_setting'] = array(
 764          'title' => $lang->add_new_setting,
 765          'link' => "index.php?module=config-settings&amp;action=add"
 766      );
 767  
 768      $sub_tabs['add_setting_group'] = array(
 769          'title' => $lang->add_new_setting_group,
 770          'link' => "index.php?module=config-settings&amp;action=addgroup"
 771      );
 772  
 773      $sub_tabs['modify_setting'] = array(
 774          'title' => $lang->modify_existing_settings,
 775          'link' => "index.php?module=config-settings&amp;action=manage",
 776          'description' => $lang->modify_existing_settings_desc
 777      );
 778  
 779      $page->output_nav_tabs($sub_tabs, 'modify_setting');
 780  
 781      // Cache settings
 782      $settings_cache = array();
 783      $query = $db->simple_select("settings", "sid, name, title, disporder, gid, isdefault", "", array('order_by' => 'disporder', 'order_dir' => 'asc'));
 784      while($setting = $db->fetch_array($query))
 785      {
 786          $settings_cache[$setting['gid']][] = $setting;
 787      }
 788  
 789      $form = new Form("index.php?module=config-settings&amp;action=manage", "post", "edit");
 790  
 791      $table = new Table;
 792  
 793      $table->construct_header($lang->setting_group_setting);
 794      $table->construct_header($lang->order, array('class' => 'align_center', 'style' => 'width: 5%'));
 795      $table->construct_header($lang->controls, array('class' => 'align_center', 'style' => 'width: 200px'));
 796  
 797      // Generate table
 798      $query = $db->simple_select("settinggroups", "*", "", array('order_by' => 'disporder', 'order_dir' => 'asc'));
 799      while($group = $db->fetch_array($query))
 800      {
 801          // Make setting group row
 802          // Translated?
 803          $group_lang_var = "setting_group_{$group['name']}";
 804          if(!empty($lang->$group_lang_var))
 805          {
 806              $group_title = htmlspecialchars_uni($lang->$group_lang_var);
 807          }
 808          else
 809          {
 810              $group_title = htmlspecialchars_uni($group['title']);
 811          }
 812          $table->construct_cell("<strong>{$group_title}</strong>", array('id' => "group{$group['gid']}"));
 813          $table->construct_cell($form->generate_numeric_field("group_disporder[{$group['gid']}]", $group['disporder'], array('style' => 'width: 80%; font-weight: bold', 'class' => 'align_center', 'min' => 0)));
 814          // Only show options if not a default setting group
 815          if($group['isdefault'] != 1)
 816          {
 817              $popup = new PopupMenu("group_{$group['gid']}", $lang->options);
 818              $popup->add_item($lang->edit_setting_group, "index.php?module=config-settings&amp;action=editgroup&amp;gid={$group['gid']}");
 819              $popup->add_item($lang->delete_setting_group, "index.php?module=config-settings&amp;action=deletegroup&amp;gid={$group['gid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_setting_group_deletion}')");
 820              $table->construct_cell($popup->fetch(), array('class' => 'align_center'));
 821          }
 822          else
 823          {
 824              $table->construct_cell('');
 825          }
 826          $table->construct_row(array('class' => 'alt_row', 'no_alt_row' => 1));
 827  
 828          // Make rows for each setting in the group
 829          if(isset($settings_cache[$group['gid']]) && is_array($settings_cache[$group['gid']]))
 830          {
 831              foreach($settings_cache[$group['gid']] as $setting)
 832              {
 833                  $setting_lang_var = "setting_{$setting['name']}";
 834                  if(!empty($lang->$setting_lang_var))
 835                  {
 836                      $setting_title = htmlspecialchars_uni($lang->$setting_lang_var);
 837                  }
 838                  else
 839                  {
 840                      $setting_title = htmlspecialchars_uni($setting['title']);
 841                  }
 842                  $table->construct_cell($setting_title, array('style' => 'padding-left: 40px;'));
 843                  $table->construct_cell($form->generate_numeric_field("setting_disporder[{$setting['sid']}]", $setting['disporder'], array('style' => 'width: 80%', 'class' => 'align_center', 'min' => 0)));
 844                  // Only show options if not a default setting group or is a custom setting
 845                  if($group['isdefault'] != 1 || $setting['isdefault'] != 1)
 846                  {
 847                      $popup = new PopupMenu("setting_{$setting['sid']}", $lang->options);
 848                      $popup->add_item($lang->edit_setting, "index.php?module=config-settings&amp;action=edit&amp;sid={$setting['sid']}");
 849                      $popup->add_item($lang->delete_setting, "index.php?module=config-settings&amp;action=delete&amp;sid={$setting['sid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_setting_deletion}')");
 850                      $table->construct_cell($popup->fetch(), array('class' => 'align_center'));
 851                  }
 852                  else
 853                  {
 854                      $table->construct_cell('');
 855                  }
 856                  $table->construct_row(array('no_alt_row' => 1, 'class' => "group{$group['gid']}"));
 857              }
 858          }
 859      }
 860  
 861      $table->output($lang->modify_existing_settings);
 862  
 863      $buttons[] = $form->generate_submit_button($lang->save_display_orders);
 864      $form->output_submit_wrapper($buttons);
 865      $form->end();
 866  
 867      $page->output_footer();
 868  }
 869  
 870  // Change settings for a specified group.
 871  if($mybb->input['action'] == "change")
 872  {
 873      $plugins->run_hooks("admin_config_settings_change");
 874  
 875      if($mybb->request_method == "post")
 876      {
 877          if(!is_writable(MYBB_ROOT.'inc/settings.php'))
 878          {
 879              flash_message($lang->error_chmod_settings_file, 'error');
 880              admin_redirect("index.php?module=config-settings");
 881          }
 882  
 883          // Not allowed to be hidden captcha fields
 884          $disallowed_fields = array(
 885              'username',
 886              'password',
 887              'password2',
 888              'email',
 889              'email2',
 890              'imagestring',
 891              'imagehash',
 892              'answer',
 893              'question_id',
 894              'allownotices',
 895              'hideemail',
 896              'receivepms',
 897              'pmnotice',
 898              'emailpmnotify',
 899              'invisible',
 900              'subscriptionmethod',
 901              'timezoneoffset',
 902              'dstcorrection',
 903              'language',
 904              'step',
 905              'action',
 906              'agree',
 907              'regtime',
 908              'regcheck1',
 909              'regcheck2',
 910              'regsubmit'
 911          );
 912  
 913          $is_current_hiddencaptcha_wrong = in_array($mybb->settings['hiddencaptchaimagefield'], $disallowed_fields);
 914          if(
 915              (isset($mybb->input['upsetting']['hiddencaptchaimagefield']) && in_array($mybb->input['upsetting']['hiddencaptchaimagefield'], $disallowed_fields)) ||
 916              $is_current_hiddencaptcha_wrong
 917          )
 918          {
 919              if(isset($mybb->input['upsetting']['hiddencaptchaimagefield']) && $mybb->input['upsetting']['hiddencaptchaimagefield'] != $mybb->settings['hiddencaptchaimagefield'] && !$is_current_hiddencaptcha_wrong)
 920              {
 921                  $wrong_value = $mybb->input['upsetting']['hiddencaptchaimagefield'];
 922                  $mybb->input['upsetting']['hiddencaptchaimagefield'] = $mybb->settings['hiddencaptchaimagefield'];
 923              }
 924              else
 925              {
 926                  $wrong_value = $mybb->settings['hiddencaptchaimagefield'];
 927                  $mybb->input['upsetting']['hiddencaptchaimagefield'] = 'email3';
 928              }
 929  
 930              $lang->success_settings_updated .= $lang->sprintf($lang->success_settings_updated_hiddencaptchaimage, htmlspecialchars_uni($mybb->input['upsetting']['hiddencaptchaimagefield']), htmlspecialchars_uni($wrong_value));
 931          }
 932  
 933          // Validate avatar dimension inputs
 934          $gid = (int)$mybb->input['gid'];
 935          $dimfields = array(
 936              8 => array('postmaxavatarsize'),
 937              10 => array('useravatardims', 'maxavatardims'),
 938              13 => array('memberlistmaxavatarsize')
 939          );
 940          if(in_array($gid, array_keys($dimfields)))
 941          {
 942              foreach($dimfields[$gid] as $field)
 943              {
 944                  if(isset($mybb->input['upsetting'][$field]))
 945                  {
 946                      if(preg_match("/\b\d+[|x]{1}\d+\b/i", $mybb->input['upsetting'][$field]) || ($field == 'maxavatardims' && trim($mybb->input['upsetting'][$field]) == ""))
 947                      {
 948                          // If pipe (|) is used normalize to 'x'
 949                          $mybb->input['upsetting'][$field] = str_replace('|', 'x', my_strtolower($mybb->input['upsetting'][$field]));
 950                      }
 951                      else
 952                      {
 953                          flash_message($lang->sprintf($lang->error_format_dimension, $lang->{'error_field_'.$field}), 'error');
 954                          admin_redirect("index.php?module=config-settings&action=change&gid=".$gid);
 955                      }
 956                  }
 957              }
 958          }
 959  
 960          // Validate minnamelength, maxnamelength, minpasswordlength (complex and regular) and maxpasswordlength
 961          if ($gid == 9)
 962          {
 963              if (
 964                  isset($mybb->input['upsetting']['minnamelength'], $mybb->input['upsetting']['maxnamelength']) &&
 965                  $mybb->input['upsetting']['minnamelength'] > 0 && $mybb->input['upsetting']['maxnamelength'] > 0 &&
 966                  $mybb->input['upsetting']['minnamelength'] > $mybb->input['upsetting']['maxnamelength'])
 967              {
 968                  flash_message($lang->error_field_minnamelength, 'error');
 969                  admin_redirect("index.php?module=config-settings&action=change&gid=".$gid);
 970              }
 971  
 972              if (
 973                  isset($mybb->input['upsetting']['minpasswordlength'], $mybb->input['upsetting']['maxpasswordlength']) &&
 974                  $mybb->input['upsetting']['minpasswordlength'] > 0 && $mybb->input['upsetting']['maxpasswordlength'] > 0 &&
 975                  $mybb->input['upsetting']['minpasswordlength'] > $mybb->input['upsetting']['maxpasswordlength']
 976              )
 977              {
 978                  flash_message($lang->error_field_minpasswordlength, 'error');
 979                  admin_redirect("index.php?module=config-settings&action=change&gid=".$gid);
 980              }
 981  
 982              if (
 983                  isset($mybb->input['upsetting']['minpasswordlength'], $mybb->input['upsetting']['requirecomplexpasswords']) &&
 984                  $mybb->input['upsetting']['requirecomplexpasswords'] && $mybb->input['upsetting']['minpasswordlength'] < 3
 985              )
 986              {
 987                  flash_message($lang->error_field_minpasswordlength_complex, 'error');
 988                  admin_redirect("index.php?module=config-settings&action=change&gid=".$gid);
 989              }
 990          }
 991          
 992          require_once  MYBB_ROOT.'inc/class_captcha.php';
 993          
 994          // Have we opted for a reCAPTCHA or hCaptcha and not set a public/private key in input?
 995          $set_captcha_image = false;
 996          if(isset(
 997              $mybb->input['upsetting']['captchaimage'],
 998              $mybb->input['upsetting']['recaptchaprivatekey'],
 999              $mybb->input['upsetting']['recaptchapublickey'],
1000              $mybb->input['upsetting']['recaptchascore'],
1001              $mybb->input['upsetting']['hcaptchaprivatekey'],
1002              $mybb->input['upsetting']['hcaptchapublickey']
1003          ))
1004          {
1005              $captchaimage = $mybb->input['upsetting']['captchaimage'];
1006              $recaptchaprivatekey = $mybb->input['upsetting']['recaptchaprivatekey'];
1007              $recaptchapublickey = $mybb->input['upsetting']['recaptchapublickey'];
1008              $recaptchascore = $mybb->input['upsetting']['recaptchascore'];
1009              $hcaptchaprivatekey = $mybb->input['upsetting']['hcaptchaprivatekey'];
1010              $hcaptchapublickey = $mybb->input['upsetting']['hcaptchapublickey'];
1011  
1012              if(in_array($captchaimage, array(captcha::NOCAPTCHA_RECAPTCHA, captcha::RECAPTCHA_INVISIBLE)) && (!$recaptchaprivatekey || !$recaptchapublickey))
1013              {
1014                  $set_captcha_image = true;
1015              }
1016              else if(in_array($captchaimage, array(captcha::RECAPTCHA_V3)) && (!$recaptchaprivatekey || !$recaptchapublickey || !$recaptchascore))
1017              {
1018                  $set_captcha_image = true;
1019              }
1020              else if(in_array($captchaimage, array(captcha::HCAPTCHA, captcha::HCAPTCHA_INVISIBLE)) && (!$hcaptchaprivatekey || !$hcaptchapublickey))
1021              {
1022                  $set_captcha_image = true;
1023              }
1024          }
1025  
1026          //Checking settings for reCAPTCHA or hCaptcha and public/private key not set?
1027          $captchaimage = $mybb->settings['captchaimage'];
1028          $recaptchaprivatekey = $mybb->settings['recaptchaprivatekey'];
1029          $recaptchapublickey = $mybb->settings['recaptchapublickey'];
1030          $recaptchascore = $mybb->settings['recaptchascore'];
1031          $hcaptchaprivatekey = $mybb->settings['hcaptchaprivatekey'];
1032          $hcaptchapublickey = $mybb->settings['hcaptchapublickey'];
1033  
1034          if(in_array($captchaimage, array(captcha::NOCAPTCHA_RECAPTCHA, captcha::RECAPTCHA_INVISIBLE)) && (!$recaptchaprivatekey || !$recaptchapublickey))
1035          {
1036              $set_captcha_image = true;
1037          }
1038          else if(in_array($captchaimage, array(captcha::RECAPTCHA_V3)) && (!$recaptchaprivatekey || !$recaptchapublickey || !$recaptchascore))
1039          {
1040              $set_captcha_image = true;
1041          }
1042          else if(in_array($captchaimage, array(captcha::HCAPTCHA, captcha::HCAPTCHA_INVISIBLE)) && (!$hcaptchaprivatekey || !$hcaptchapublickey))
1043          {
1044              $set_captcha_image = true;
1045          }
1046          if($set_captcha_image){
1047              $mybb->input['upsetting']['captchaimage'] = captcha::DEFAULT_CAPTCHA;
1048              $lang->success_settings_updated .= $lang->success_settings_updated_captchaimage;
1049          }
1050  
1051          // If using fulltext then enforce minimum word length given by database
1052          if(isset($mybb->input['upsetting']['minsearchword']) && $mybb->input['upsetting']['minsearchword'] > 0 && $mybb->input['upsetting']['searchtype'] == "fulltext" && $db->supports_fulltext_boolean("posts") && $db->supports_fulltext("threads"))
1053          {
1054              // Attempt to determine minimum word length from MySQL for fulltext searches
1055              $query = $db->query("SHOW VARIABLES LIKE 'ft_min_word_len';");
1056              $min_length = $db->fetch_field($query, 'Value');
1057              if(is_numeric($min_length) && $mybb->input['upsetting']['minsearchword'] < $min_length)
1058              {
1059                  $mybb->input['upsetting']['minsearchword'] = $min_length;
1060                  $lang->success_settings_updated .= $lang->success_settings_updated_minsearchword;
1061              }
1062          }
1063  
1064          // Get settings which optionscode is a forum/group select, checkbox or numeric
1065          // We cannot rely on user input to decide this
1066          $checkbox_settings = $forum_group_select = $prefix_select = array();
1067          $query = $db->simple_select('settings', 'name, optionscode', "optionscode IN('forumselect', 'groupselect', 'prefixselect') OR optionscode LIKE 'checkbox%' OR optionscode LIKE 'numeric%'");
1068  
1069          while($multisetting = $db->fetch_array($query))
1070          {
1071              $options = array();
1072  
1073              if(substr($multisetting['optionscode'], 0, 8) == 'checkbox')
1074              {
1075                  $checkbox_settings[] = $multisetting['name'];
1076  
1077                  // All checkboxes deselected = no $mybb->input['upsetting'] for them, we need to initialize it manually then, but only on pages where the setting is shown
1078                  if(empty($mybb->input['upsetting'][$multisetting['name']]) && isset($mybb->input["isvisible_{$multisetting['name']}"]))
1079                  {
1080                      $mybb->input['upsetting'][$multisetting['name']] = array();
1081                  }
1082              }
1083              elseif(substr($multisetting['optionscode'], 0, 7) == 'numeric')
1084              {
1085                  if(isset($mybb->input['upsetting'][$multisetting['name']]))
1086                  {
1087                      $type = explode("\n", $multisetting['optionscode']);
1088                      for($i=1; $i < count($type); $i++)
1089                      {
1090                          $optionsexp = explode("=", $type[$i]);
1091                          $opt = array_map('trim', $optionsexp);
1092                          if(in_array($opt[0], array('min', 'max', 'step')))
1093                          {
1094                              if($opt[0] != 'step' || $opt[1] != 'any')
1095                              {
1096                                  $opt[1] = (float)$opt[1];
1097                              }
1098                              $options[$opt[0]] = $opt[1];
1099                          }
1100                      }
1101  
1102                      $value = (float)$mybb->input['upsetting'][$multisetting['name']];
1103  
1104                      if(isset($options['min']))
1105                      {
1106                          $value = max($value, $options['min']);
1107                      }
1108  
1109                      if(isset($options['max']))
1110                      {
1111                          $value = min($value, $options['max']);
1112                      }
1113  
1114                      $mybb->input['upsetting'][$multisetting['name']] = $value;
1115                  }
1116              }
1117              else
1118              {
1119                  $forum_group_select[] = $multisetting['name'];
1120              }
1121          }
1122  
1123          // Verify for admin email that can't be empty
1124          if(isset($mybb->input['upsetting']['adminemail']) && !validate_email_format($mybb->input['upsetting']['adminemail']))
1125          {
1126              unset($mybb->input['upsetting']['adminemail']);
1127              $lang->success_settings_updated .= $lang->error_admin_email_settings_empty;
1128          }
1129  
1130          // Administrator is changing the login method.
1131          if(isset($mybb->input['upsetting']['username_method']) && (int)$mybb->input['upsetting']['username_method'] > 0)
1132          {
1133              if((int)$mybb->settings['allowmultipleemails'] == 1)
1134              {
1135                  $mybb->input['upsetting']['username_method'] = 0;
1136                  $lang->success_settings_updated .= $lang->success_settings_updated_username_method_conflict;
1137              }
1138              else
1139              {
1140                  $query = $db->simple_select('users', 'email', "email != ''", array('group_by' => 'email HAVING COUNT(email)>1'));
1141                  if($db->num_rows($query))
1142                  {
1143                      $mybb->input['upsetting']['username_method'] = 0;
1144                      $lang->success_settings_updated .= $lang->success_settings_updated_username_method;
1145                  }
1146              }
1147          }
1148  
1149          if(isset($mybb->input['upsetting']['username_method'], $mybb->input['upsetting']['allowmultipleemails']))
1150          {
1151              // Administrator is changing registration email allowance
1152              if((int)$mybb->settings['username_method'] > 0 && (int)$mybb->input['upsetting']['allowmultipleemails'] !== 0)
1153              {
1154                  $mybb->input['upsetting']['allowmultipleemails'] = 0;
1155                  $lang->success_settings_updated .= $lang->success_settings_updated_allowmultipleemails;
1156              }
1157  
1158              // Reset conflict silently, if by chance
1159              if((int)$mybb->settings['username_method'] > 0 && (int)$mybb->settings['allowmultipleemails'] == 1)
1160              {
1161                  $mybb->input['upsetting']['allowmultipleemails'] = 0;
1162              }
1163          }
1164  
1165          // reject dangerous/unsupported upload paths
1166          $fields = array(
1167              'uploadspath',
1168              'cdnpath',
1169              'avataruploadpath',
1170          );
1171  
1172          $dynamic_include_directories = array(
1173              MYBB_ROOT.'cache/',
1174              MYBB_ROOT.'inc/plugins/',
1175              MYBB_ROOT.'inc/languages/',
1176              MYBB_ROOT.'inc/tasks/',
1177          );
1178          $dynamic_include_directories_realpath = array_map('realpath', $dynamic_include_directories);
1179  
1180          foreach($fields as $field)
1181          {
1182              if(isset($mybb->input['upsetting'][$field]))
1183              {
1184                  if(
1185                      is_string($mybb->input['upsetting'][$field]) &&
1186                      strpos($mybb->input['upsetting'][$field], '://') !== false)
1187                  {
1188                      unset($mybb->input['upsetting'][$field]);
1189                      continue;
1190                  }
1191  
1192                  $realpath = realpath(mk_path_abs($mybb->input['upsetting'][$field]));
1193  
1194                  if ($realpath === false)
1195                  {
1196                      unset($mybb->input['upsetting'][$field]);
1197                      continue;
1198                  }
1199  
1200                  foreach ($dynamic_include_directories_realpath as $forbidden_realpath)
1201                  {
1202                      if ($realpath === $forbidden_realpath || strpos($realpath, $forbidden_realpath.DIRECTORY_SEPARATOR) === 0)
1203                      {
1204                          unset($mybb->input['upsetting'][$field]);
1205                          continue 2;
1206                      }
1207                  }
1208              }
1209          }
1210  
1211  
1212          if(is_array($mybb->input['upsetting']))
1213          {
1214              foreach($mybb->input['upsetting'] as $name => $value)
1215              {
1216                  if($forum_group_select && in_array($name, $forum_group_select))
1217                  {
1218                      if($value == 'all')
1219                      {
1220                          $value = -1;
1221                      }
1222                      elseif($value == 'custom')
1223                      {
1224                          if(isset($mybb->input['select'][$name]) && is_array($mybb->input['select'][$name]))
1225                          {
1226                              foreach($mybb->input['select'][$name] as &$val)
1227                              {
1228                                  $val = (int)$val;
1229                              }
1230                              unset($val);
1231  
1232                              $value = implode(',', $mybb->input['select'][$name]);
1233                          }
1234                          else
1235                          {
1236                              $value = '';
1237                          }
1238                      }
1239                      else
1240                      {
1241                          $value = '';
1242                      }
1243                  }
1244                  elseif($checkbox_settings && in_array($name, $checkbox_settings))
1245                  {
1246                      $value = '';
1247  
1248                      if(is_array($mybb->input['upsetting'][$name]))
1249                      {
1250                          $value = implode(',', $mybb->input['upsetting'][$name]);
1251                      }
1252                  }
1253  
1254                  $db->update_query("settings", array('value' => $db->escape_string($value)), "name='".$db->escape_string($name)."'");
1255              }
1256          }
1257  
1258          // Check if we need to create our fulltext index after changing the search mode
1259          if(
1260              isset($mybb->input['upsetting']['searchtype']) &&
1261              $mybb->settings['searchtype'] != $mybb->input['upsetting']['searchtype'] &&
1262              $mybb->input['upsetting']['searchtype'] == "fulltext"
1263          )
1264          {
1265              if(!$db->is_fulltext("posts") && $db->supports_fulltext_boolean("posts"))
1266              {
1267                  $db->create_fulltext_index("posts", "message");
1268              }
1269              if(!$db->is_fulltext("threads") && $db->supports_fulltext("threads"))
1270              {
1271                  $db->create_fulltext_index("threads", "subject");
1272              }
1273          }
1274  
1275          // If the delayedthreadviews setting was changed, enable or disable the tasks for it.
1276          if(isset($mybb->input['upsetting']['delayedthreadviews']) && $mybb->settings['delayedthreadviews'] != $mybb->input['upsetting']['delayedthreadviews'])
1277          {
1278              $db->update_query("tasks", array('enabled' => (int)$mybb->input['upsetting']['delayedthreadviews']), "file='threadviews'");
1279          }
1280  
1281          // Have we changed our cookie prefix? If so, update our adminsid so we're not logged out
1282          if(isset($mybb->input['upsetting']['cookieprefix']) && $mybb->input['upsetting']['cookieprefix'] != $mybb->settings['cookieprefix'])
1283          {
1284              my_unsetcookie("adminsid");
1285              $mybb->settings['cookieprefix'] = $mybb->input['upsetting']['cookieprefix'];
1286              my_setcookie("adminsid", $admin_session['sid'], '', true, "lax");
1287          }
1288  
1289          if(isset($mybb->input['upsetting']['statstopreferrer']) && $mybb->input['upsetting']['statstopreferrer'] != $mybb->settings['statstopreferrer'])
1290          {
1291              $cache->update_statistics();
1292          }
1293  
1294          $statslimit = $mybb->settings['statslimit'];
1295  
1296          rebuild_settings();
1297  
1298          if(isset($mybb->input['upsetting']['statslimit']) && $mybb->input['upsetting']['statslimit'] != $statslimit)
1299          {
1300              $cache->update_most_replied_threads();
1301              $cache->update_most_viewed_threads();
1302          }
1303  
1304          $plugins->run_hooks("admin_config_settings_change_commit");
1305  
1306          // Log admin action
1307          log_admin_action();
1308  
1309          flash_message($lang->success_settings_updated, 'success');
1310          admin_redirect("index.php?module=config-settings");
1311      }
1312  
1313      // What type of page
1314      $cache_groups = $cache_settings = array();
1315      if(isset($mybb->input['search']))
1316      {
1317          // Search
1318  
1319          // Search for settings
1320          $search = trim($mybb->input['search']);
1321          if(!empty($search))
1322          {
1323              $query = $db->query("
1324                  SELECT s.* , g.name as gname, g.title as gtitle, g.description as gdescription
1325                  FROM ".TABLE_PREFIX."settings s
1326                  LEFT JOIN ".TABLE_PREFIX."settinggroups g ON(s.gid=g.gid)
1327                  ORDER BY s.disporder
1328              ");
1329              while($setting = $db->fetch_array($query))
1330              {
1331                  $search_in = $setting['name'] . ' ' . $setting['title'] . ' ' . $setting['description'] . ' ' . $setting['gname'] . ' ' . $setting['gtitle'] . ' ' . $setting['gdescription'];
1332                  foreach(array("setting_{$setting['name']}", "setting_{$setting['name']}_desc", "setting_group_{$setting['gname']}", "setting_group_{$setting['gname']}_desc") as $search_in_lang_key)
1333                  {
1334                      if(!empty($lang->$search_in_lang_key))
1335                      {
1336                          $search_in .= ' ' . $lang->$search_in_lang_key;
1337                      }
1338                  }
1339                  if(my_stripos($search_in, $search) !== false)
1340                  {
1341                      $cache_settings[$setting['gid']][$setting['sid']] = $setting;
1342                  }
1343              }
1344          }
1345          if(!count($cache_settings))
1346          {
1347              if(isset($mybb->input['ajax_search']))
1348              {
1349                  echo json_encode(array("errors" => array($lang->error_no_settings_found)));
1350                  exit;
1351              }
1352              else
1353              {
1354                  flash_message($lang->error_no_settings_found, 'error');
1355                  admin_redirect("index.php?module=config-settings");
1356              }
1357          }
1358  
1359          // Cache groups
1360          $groups = array_keys($cache_settings);
1361          $groups = implode(',', $groups);
1362          $query = $db->simple_select("settinggroups", "*", "gid IN ({$groups})", array('order_by' => 'disporder'));
1363          while($group = $db->fetch_array($query))
1364          {
1365              $cache_groups[$group['gid']] = $group;
1366          }
1367  
1368          // Page header only if not AJAX
1369          if(!isset($mybb->input['ajax_search']))
1370          {
1371              $page->add_breadcrumb_item($lang->settings_search);
1372              $page->output_header($lang->board_settings." - {$lang->settings_search}");
1373          }
1374      }
1375      elseif(($mybb->get_input('gid')))
1376      {
1377          // Group listing
1378          // Cache groups
1379          $query = $db->simple_select("settinggroups", "*", "gid = '".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
1380          $groupinfo = $db->fetch_array($query);
1381          $cache_groups[$groupinfo['gid']] = $groupinfo;
1382  
1383          if(!$db->num_rows($query))
1384          {
1385              $page->output_error($lang->error_invalid_gid2);
1386          }
1387  
1388          // Cache settings
1389          $query = $db->simple_select("settings", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'", array('order_by' => 'disporder'));
1390          while($setting = $db->fetch_array($query))
1391          {
1392              $cache_settings[$setting['gid']][$setting['sid']] = $setting;
1393          }
1394  
1395          if(!$db->num_rows($query))
1396          {
1397              flash_message($lang->error_no_settings_found, 'error');
1398              admin_redirect("index.php?module=config-settings");
1399          }
1400  
1401          $group_lang_var = "setting_group_{$groupinfo['name']}";
1402          if(isset($lang->$group_lang_var))
1403          {
1404              $groupinfo['title'] = $lang->$group_lang_var;
1405          }
1406  
1407          // Page header
1408          $page->add_breadcrumb_item($groupinfo['title']);
1409          $page->output_header($lang->board_settings." - {$groupinfo['title']}");
1410      }
1411      else
1412      {
1413          // All settings list
1414          // Cache groups
1415          $query = $db->simple_select("settinggroups", "*", "", array('order_by' => 'disporder'));
1416          while($group = $db->fetch_array($query))
1417          {
1418              $cache_groups[$group['gid']] = $group;
1419          }
1420  
1421          if(!$db->num_rows($query))
1422          {
1423              $page->output_error($lang->error_invalid_gid2);
1424          }
1425  
1426          // Cache settings
1427          $query = $db->simple_select("settings", "*", "", array('order_by' => 'disporder'));
1428          while($setting = $db->fetch_array($query))
1429          {
1430              $cache_settings[$setting['gid']][$setting['sid']] = $setting;
1431          }
1432  
1433          // Page header
1434          $page->add_breadcrumb_item($lang->show_all_settings);
1435          $page->output_header($lang->board_settings." - {$lang->show_all_settings}");
1436      }
1437  
1438      // Build individual forms as per settings group
1439      foreach($cache_groups as $groupinfo)
1440      {
1441          $form = new Form("index.php?module=config-settings&amp;action=change", "post", "change");
1442          echo $form->generate_hidden_field("gid", $groupinfo['gid']);
1443          $buttons = array($form->generate_submit_button($lang->save_settings));
1444          $group_lang_var = "setting_group_{$groupinfo['name']}";
1445          if(isset($lang->$group_lang_var))
1446          {
1447              $groupinfo['title'] = $lang->$group_lang_var;
1448          }
1449  
1450          $form_container = new FormContainer($groupinfo['title']);
1451  
1452          if(empty($cache_settings[$groupinfo['gid']]))
1453          {
1454              $form_container->output_cell($lang->error_no_settings_found);
1455              $form_container->construct_row();
1456  
1457              $form_container->end();
1458              echo '<br />';
1459  
1460              continue;
1461          }
1462  
1463          foreach($cache_settings[$groupinfo['gid']] as $setting)
1464          {
1465              $options = "";
1466              $type = explode("\n", $setting['optionscode']);
1467              $type[0] = trim($type[0]);
1468              $element_name = "upsetting[{$setting['name']}]";
1469              $element_id = "setting_{$setting['name']}";
1470              if($type[0] == "text" || $type[0] == "")
1471              {
1472                  $setting_code = $form->generate_text_box($element_name, $setting['value'], array('id' => $element_id));
1473              }
1474              else if($type[0] == "numeric")
1475              {
1476                  $field_options = array('id' => $element_id);
1477                  if(count($type) > 1)
1478                  {
1479                      for($i=1; $i < count($type); $i++)
1480                      {
1481                          $optionsexp = explode("=", $type[$i]);
1482                          $opt = array_map('trim', $optionsexp);
1483                          if(in_array($opt[0], array('min', 'max', 'step')))
1484                          {
1485                              if($opt[0] != 'step' || $opt[1] != 'any')
1486                              {
1487                                  $opt[1] = (float)$opt[1];
1488                              }
1489                              $field_options[$opt[0]] = $opt[1];
1490                          }
1491                      }
1492                  }
1493                  $setting_code = $form->generate_numeric_field($element_name, $setting['value'], $field_options);
1494              }
1495              else if($type[0] == "textarea")
1496              {
1497                  $setting_code = $form->generate_text_area($element_name, $setting['value'], array('id' => $element_id));
1498              }
1499              else if($type[0] == "yesno")
1500              {
1501                  $setting_code = $form->generate_yes_no_radio($element_name, $setting['value'], true, array('id' => $element_id.'_yes', 'class' => $element_id), array('id' => $element_id.'_no', 'class' => $element_id));
1502              }
1503              else if($type[0] == "onoff")
1504              {
1505                  $setting_code = $form->generate_on_off_radio($element_name, $setting['value'], true, array('id' => $element_id.'_on', 'class' => $element_id), array('id' => $element_id.'_off', 'class' => $element_id));
1506              }
1507              else if($type[0] == "cpstyle")
1508              {
1509                  $dir = @opendir(MYBB_ROOT.$config['admin_dir']."/styles");
1510  
1511                  $folders = array();
1512                  while($folder = readdir($dir))
1513                  {
1514                      if($folder != "." && $folder != ".." && @file_exists(MYBB_ROOT.$config['admin_dir']."/styles/$folder/main.css"))
1515                      {
1516                          $folders[$folder] = ucfirst($folder);
1517                      }
1518                  }
1519                  closedir($dir);
1520                  ksort($folders);
1521                  $setting_code = $form->generate_select_box($element_name, $folders, $setting['value'], array('id' => $element_id));
1522              }
1523              else if($type[0] == "language")
1524              {
1525                  $languages = $lang->get_languages();
1526                  $setting_code = $form->generate_select_box($element_name, $languages, $setting['value'], array('id' => $element_id));
1527              }
1528              else if($type[0] == "adminlanguage")
1529              {
1530                  $languages = $lang->get_languages(1);
1531                  $setting_code = $form->generate_select_box($element_name, $languages, $setting['value'], array('id' => $element_id));
1532              }
1533              else if($type[0] == "passwordbox")
1534              {
1535                  $setting_code = $form->generate_password_box($element_name, $setting['value'], array('id' => $element_id));
1536              }
1537              else if($type[0] == "php")
1538              {
1539                  $setting['optionscode'] = substr($setting['optionscode'], 3);
1540                  eval("\$setting_code = \"".$setting['optionscode']."\";");
1541              }
1542              else if($type[0] == "forumselect")
1543              {
1544                  $selected_values = '';
1545                  if($setting['value'] != '' && $setting['value'] != -1)
1546                  {
1547                      $selected_values = explode(',', (string)$setting['value']);
1548  
1549                      foreach($selected_values as &$value)
1550                      {
1551                          $value = (int)$value;
1552                      }
1553                      unset($value);
1554                  }
1555  
1556                  $forum_checked = array('all' => '', 'custom' => '', 'none' => '');
1557                  if($setting['value'] == -1)
1558                  {
1559                      $forum_checked['all'] = 'checked="checked"';
1560                  }
1561                  elseif($setting['value'] != '')
1562                  {
1563                      $forum_checked['custom'] = 'checked="checked"';
1564                  }
1565                  else
1566                  {
1567                      $forum_checked['none'] = 'checked="checked"';
1568                  }
1569  
1570                  print_selection_javascript();
1571  
1572                  $setting_code = "
1573                  <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
1574                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"all\" {$forum_checked['all']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
1575                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"custom\" {$forum_checked['custom']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
1576                      <dd style=\"margin-top: 4px;\" id=\"{$element_id}_forums_groups_custom\" class=\"{$element_id}_forums_groups\">
1577                          <table cellpadding=\"4\">
1578                              <tr>
1579                                  <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
1580                                  <td>".$form->generate_forum_select('select['.$setting['name'].'][]', $selected_values, array('id' => $element_id, 'multiple' => true, 'size' => 5))."</td>
1581                              </tr>
1582                          </table>
1583                      </dd>
1584                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"none\" {$forum_checked['none']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->none}</strong></label></dt>
1585                  </dl>
1586                  <script type=\"text/javascript\">
1587                      checkAction('{$element_id}');
1588                  </script>";
1589              }
1590              else if($type[0] == "forumselectsingle")
1591              {
1592                  $selected_value = (int)$setting['value']; // No need to check if empty, int will give 0
1593                  $setting_code = $form->generate_forum_select($element_name, $selected_value, array('id' => $element_id, 'main_option' => $lang->none));
1594              }
1595              else if($type[0] == "groupselect")
1596              {
1597                  $selected_values = '';
1598                  if($setting['value'] != '' && $setting['value'] != -1)
1599                  {
1600                      $selected_values = explode(',', (string)$setting['value']);
1601  
1602                      foreach($selected_values as &$value)
1603                      {
1604                          $value = (int)$value;
1605                      }
1606                      unset($value);
1607                  }
1608  
1609                  $group_checked = array('all' => '', 'custom' => '', 'none' => '');
1610                  if($setting['value'] == -1)
1611                  {
1612                      $group_checked['all'] = 'checked="checked"';
1613                  }
1614                  elseif($setting['value'] != '')
1615                  {
1616                      $group_checked['custom'] = 'checked="checked"';
1617                  }
1618                  else
1619                  {
1620                      $group_checked['none'] = 'checked="checked"';
1621                  }
1622  
1623                  print_selection_javascript();
1624  
1625                  $setting_code = "
1626                  <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
1627                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"all\" {$group_checked['all']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
1628                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"custom\" {$group_checked['custom']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
1629                      <dd style=\"margin-top: 4px;\" id=\"{$element_id}_forums_groups_custom\" class=\"{$element_id}_forums_groups\">
1630                          <table cellpadding=\"4\">
1631                              <tr>
1632                                  <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
1633                                  <td>".$form->generate_group_select('select['.$setting['name'].'][]', $selected_values, array('id' => $element_id, 'multiple' => true, 'size' => 5))."</td>
1634                              </tr>
1635                          </table>
1636                      </dd>
1637                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"none\" {$group_checked['none']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->none}</strong></label></dt>
1638                  </dl>
1639                  <script type=\"text/javascript\">
1640                      checkAction('{$element_id}');
1641                  </script>";
1642              }
1643              else if($type[0] == "groupselectsingle")
1644              {
1645                  $selected_value = (int)$setting['value']; // No need to check if empty, int will give 0
1646                  $setting_code = $form->generate_group_select($element_name, $selected_value, array('id' => $element_id, 'main_option' => $lang->none));
1647              }
1648              else if($type[0] == "prefixselect")
1649              {
1650                  $selected_values = '';
1651                  if($setting['value'] != '' && $setting['value'] != -1)
1652                  {
1653                      $selected_values = explode(',', (string)$setting['value']);
1654                      foreach($selected_values as &$value)
1655                      {
1656                          $value = (int)$value;
1657                      }
1658                      unset($value);
1659                  }
1660                  $prefix_checked = array('all' => '', 'custom' => '', 'none' => '');
1661                  if($setting['value'] == -1)
1662                  {
1663                      $prefix_checked['all'] = 'checked="checked"';
1664                  }
1665                  elseif($setting['value'] != '')
1666                  {
1667                      $prefix_checked['custom'] = 'checked="checked"';
1668                  }
1669                  else
1670                  {
1671                      $prefix_checked['none'] = 'checked="checked"';
1672                  }
1673                  print_selection_javascript();
1674                  $setting_code = "
1675                  <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
1676                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"all\" {$prefix_checked['all']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_prefix}</strong></label></dt>
1677                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"custom\" {$prefix_checked['custom']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_prefix}</strong></label></dt>
1678                      <dd style=\"margin-top: 4px;\" id=\"{$element_id}_forums_groups_custom\" class=\"{$element_id}_forums_groups\">
1679                          <table cellpadding=\"4\">
1680                              <tr>
1681                                  <td valign=\"top\"><small>{$lang->prefix_colon}</small></td>
1682                                  <td>".$form->generate_prefix_select('select['.$setting['name'].'][]', $selected_values, array('id' => $element_id, 'multiple' => true, 'size' => 5))."</td>
1683                              </tr>
1684                          </table>
1685                      </dd>
1686                      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"{$element_name}\" value=\"none\" {$prefix_checked['none']} class=\"{$element_id}_forums_groups_check\" onclick=\"checkAction('{$element_id}');\" style=\"vertical-align: middle;\" /> <strong>{$lang->none}</strong></label></dt>
1687                  </dl>
1688                  <script type=\"text/javascript\">
1689                      checkAction('{$element_id}');
1690                  </script>";
1691              }
1692              else
1693              {
1694                  $typecount = count($type);
1695  
1696                  if($type[0] == 'checkbox')
1697                  {
1698                      $multivalue = explode(',', $setting['value']);
1699                  }
1700  
1701                  for($i = 0; $i < $typecount; $i++)
1702                  {
1703                      $optionsexp = explode("=", $type[$i]);
1704                      if(!isset($optionsexp[1]))
1705                      {
1706                          continue;
1707                      }
1708                      $title_lang = "setting_{$setting['name']}_{$optionsexp[0]}";
1709                      if(isset($lang->$title_lang))
1710                      {
1711                          $optionsexp[1] = $lang->$title_lang;
1712                      }
1713  
1714                      if($type[0] == "select")
1715                      {
1716                          $option_list[$optionsexp[0]] = htmlspecialchars_uni($optionsexp[1]);
1717                      }
1718                      else if($type[0] == "radio")
1719                      {
1720                          if($setting['value'] == $optionsexp[0])
1721                          {
1722                              $option_list[$i] = $form->generate_radio_button($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id.'_'.$i, "checked" => 1, 'class' => $element_id));
1723                          }
1724                          else
1725                          {
1726                              $option_list[$i] = $form->generate_radio_button($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id.'_'.$i, 'class' => $element_id));
1727                          }
1728                      }
1729                      else if($type[0] == "checkbox")
1730                      {
1731                          if(in_array($optionsexp[0], $multivalue))
1732                          {
1733                              $option_list[$i] = $form->generate_check_box("{$element_name}[]", $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id.'_'.$i, "checked" => 1, 'class' => $element_id));
1734                          }
1735                          else
1736                          {
1737                              $option_list[$i] = $form->generate_check_box("{$element_name}[]", $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id.'_'.$i, 'class' => $element_id));
1738                          }
1739                      }
1740                  }
1741  
1742                  if($type[0] == "select")
1743                  {
1744                      $setting_code = $form->generate_select_box($element_name, $option_list, $setting['value'], array('id' => $element_id));
1745                  }
1746                  else
1747                  {
1748                      $setting_code = implode("<br />", $option_list);
1749  
1750                      if($type[0] == 'checkbox')
1751                      {
1752                          $setting_code .= $form->generate_hidden_field("isvisible_{$setting['name']}", 1);
1753                      }
1754                  }
1755                  $option_list = array();
1756              }
1757  
1758              // Do we have a custom language variable for this title or description?
1759              $title_lang = "setting_".$setting['name'];
1760              $desc_lang = $title_lang."_desc";
1761              if(isset($lang->$title_lang))
1762              {
1763                  $setting['title'] = $lang->$title_lang;
1764              }
1765              if(isset($lang->$desc_lang))
1766              {
1767                  $setting['description'] = $lang->$desc_lang;
1768              }
1769              $form_container->output_row(htmlspecialchars_uni($setting['title']), $setting['description'], $setting_code, '', array(), array('id' => 'row_'.$element_id));
1770          }
1771          $form_container->end();
1772  
1773          $form->output_submit_wrapper($buttons);
1774          $form->end();
1775          echo '<br />';
1776      }
1777  
1778      print_setting_peekers();
1779  
1780      if(!isset($mybb->input['ajax_search']))
1781      {
1782          $page->output_footer();
1783      }
1784  }
1785  
1786  if(!$mybb->input['action'])
1787  {
1788      $plugins->run_hooks("admin_config_settings_start");
1789  
1790      $page->extra_header .= <<<EOF
1791      <script type="text/javascript">
1792      <!--
1793      lang.searching = "{$lang->searching}";
1794      lang.search_error = "{$lang->search_error}";
1795      lang.search_done = "{$lang->search_done}";
1796      // -->
1797      </script>
1798  EOF;
1799  
1800      $page->output_header($lang->board_settings);
1801      if(isset($message))
1802      {
1803          $page->output_inline_message($message);
1804      }
1805  
1806      $sub_tabs['change_settings'] = array(
1807          'title' => $lang->change_settings,
1808          'link' => "index.php?module=config-settings",
1809          'description' => $lang->change_settings_desc
1810      );
1811  
1812      $sub_tabs['add_setting'] = array(
1813          'title' => $lang->add_new_setting,
1814          'link' => "index.php?module=config-settings&amp;action=add"
1815      );
1816  
1817      $sub_tabs['add_setting_group'] = array(
1818          'title' => $lang->add_new_setting_group,
1819          'link' => "index.php?module=config-settings&amp;action=addgroup"
1820      );
1821  
1822      $sub_tabs['modify_setting'] = array(
1823          'title' => $lang->modify_existing_settings,
1824          'link' => "index.php?module=config-settings&amp;action=manage",
1825      );
1826  
1827      $page->output_nav_tabs($sub_tabs, 'change_settings');
1828  
1829      // Search form
1830      echo "<div style=\"text-align: right; margin-bottom: 3px;\">";
1831      $search = new Form("index.php", 'get', 'settings_search', 0, 'settings_search');
1832      echo $search->generate_hidden_field('module', 'config/settings');
1833      echo $search->generate_hidden_field('action', 'change');
1834      echo $search->generate_text_box('search', $lang->settings_search, array('id' => 'search', 'class' => 'search_default field150 field_small'));
1835      echo "<input type=\"submit\" class=\"search_button\" value=\"{$lang->search}\" />";
1836      $search->end();
1837      echo "</div>\n";
1838  
1839      echo '<div id="search_results">&nbsp;</div><div id="group_list">';
1840      $table = new Table;
1841      $table->construct_header($lang->setting_groups);
1842  
1843      switch($db->type)
1844      {
1845          case "pgsql":
1846          $query = $db->query("
1847              SELECT g.*, COUNT(s.sid) AS settingcount
1848              FROM ".TABLE_PREFIX."settinggroups g
1849              LEFT JOIN ".TABLE_PREFIX."settings s ON (s.gid=g.gid)
1850              WHERE g.isdefault = 1
1851              GROUP BY ".$db->build_fields_string("settinggroups", "g.")."
1852              ORDER BY g.disporder
1853          ");
1854          break;
1855          default:
1856          $query = $db->query("
1857              SELECT g.*, COUNT(s.sid) AS settingcount
1858              FROM ".TABLE_PREFIX."settinggroups g
1859              LEFT JOIN ".TABLE_PREFIX."settings s ON (s.gid=g.gid)
1860              WHERE g.isdefault = 1
1861              GROUP BY g.gid
1862              ORDER BY g.disporder
1863          ");
1864      }
1865      while($group = $db->fetch_array($query))
1866      {
1867          $group_lang_var = "setting_group_{$group['name']}";
1868          if(isset($lang->$group_lang_var))
1869          {
1870              $group_title = htmlspecialchars_uni($lang->$group_lang_var);
1871          }
1872          else
1873          {
1874              $group_title = htmlspecialchars_uni($group['title']);
1875          }
1876  
1877          $group_desc_lang_var = "setting_group_{$group['name']}_desc";
1878          if(isset($lang->$group_desc_lang_var))
1879          {
1880              $group_desc = htmlspecialchars_uni($lang->$group_desc_lang_var);
1881          }
1882          else
1883          {
1884              $group_desc = htmlspecialchars_uni($group['description']);
1885          }
1886  
1887          $table->construct_cell("<strong><a href=\"index.php?module=config-settings&amp;action=change&amp;gid={$group['gid']}\">{$group_title}</a></strong> ({$group['settingcount']} {$lang->bbsettings})<br /><small>{$group_desc}</small>");
1888          $table->construct_row();
1889      }
1890  
1891      $table->output("<span style=\"float: right;\"><small><a href=\"index.php?module=config-settings&amp;action=change\">{$lang->show_all_settings}</a></small></span>{$lang->board_settings}");
1892  
1893      // Plugin Settings
1894      switch($db->type)
1895      {
1896          case "pgsql":
1897          $query = $db->query("
1898              SELECT g.*, COUNT(s.sid) AS settingcount
1899              FROM ".TABLE_PREFIX."settinggroups g
1900              LEFT JOIN ".TABLE_PREFIX."settings s ON (s.gid=g.gid)
1901              WHERE g.isdefault <> 1
1902              GROUP BY ".$db->build_fields_string("settinggroups", "g.")."
1903              ORDER BY g.disporder
1904          ");
1905          break;
1906          default:
1907          $query = $db->query("
1908              SELECT g.*, COUNT(s.sid) AS settingcount
1909              FROM ".TABLE_PREFIX."settinggroups g
1910              LEFT JOIN ".TABLE_PREFIX."settings s ON (s.gid=g.gid)
1911              WHERE g.isdefault <> 1
1912              GROUP BY g.gid
1913              ORDER BY g.disporder
1914          ");
1915      }
1916  
1917      if($db->num_rows($query))
1918      {
1919          $table = new Table;
1920          $table->construct_header($lang->setting_groups);
1921  
1922          while($group = $db->fetch_array($query))
1923          {
1924              $group_lang_var = "setting_group_{$group['name']}";
1925              if(isset($lang->$group_lang_var))
1926              {
1927                  $group_title = htmlspecialchars_uni($lang->$group_lang_var);
1928              }
1929              else
1930              {
1931                  $group_title = htmlspecialchars_uni($group['title']);
1932              }
1933  
1934              $group_desc_lang_var = "setting_group_{$group['name']}_desc";
1935              if(isset($lang->$group_desc_lang_var))
1936              {
1937                  $group_desc = htmlspecialchars_uni($lang->$group_desc_lang_var);
1938              }
1939              else
1940              {
1941                  $group_desc = htmlspecialchars_uni($group['description']);
1942              }
1943  
1944              $table->construct_cell("<strong><a href=\"index.php?module=config-settings&amp;action=change&amp;gid={$group['gid']}\">{$group_title}</a></strong> ({$group['settingcount']} {$lang->bbsettings})<br /><small>{$group_desc}</small>");
1945              $table->construct_row();
1946          }
1947  
1948          $table->output($lang->plugin_settings);
1949      }
1950  
1951      echo '</div>';
1952  
1953      echo '
1954  <script type="text/javascript" src="./jscripts/search.js?ver=1821"></script>
1955  <script type="text/javascript">
1956  //<!--
1957  $(function(){
1958      SettingSearch.init("'.$lang->settings_search.'","'.$lang->error_ajax_unknown.'");
1959  });
1960  //-->
1961  </script>';
1962  
1963      print_setting_peekers();
1964      $page->output_footer();
1965  }
1966  
1967  /**
1968   * Print all the peekers for all of the default settings
1969   */
1970  function print_setting_peekers()
1971  {
1972      global $plugins;
1973  
1974      $peekers = array(
1975          'new Peeker($(".setting_boardclosed"), $("#row_setting_boardclosed_reason"), 1, true)',
1976          'new Peeker($(".setting_gzipoutput"), $("#row_setting_gziplevel"), 1, true)',
1977          'new Peeker($(".setting_useerrorhandling"), $("#row_setting_errorlogmedium, #row_setting_errorloglocation"), 1, true)',
1978          'new Peeker($("#setting_subforumsindex"), $("#row_setting_subforumsstatusicons"), /[^0+|]/, false)',
1979          'new Peeker($(".setting_showsimilarthreads"), $("#row_setting_similarityrating, #row_setting_similarlimit"), 1, true)',
1980          'new Peeker($(".setting_disableregs"), $("#row_setting_regtype, #row_setting_securityquestion, #row_setting_regtime, #row_setting_allowmultipleemails, #row_setting_hiddencaptchaimage, #row_setting_betweenregstime"), 0, true)',
1981          'new Peeker($(".setting_hiddencaptchaimage"), $("#row_setting_hiddencaptchaimagefield"), 1, true)',
1982          'new Peeker($("#setting_failedlogincount"), $("#row_setting_failedlogintime, #row_setting_failedlogintext"), /[^0+|]/, false)',
1983          'new Peeker($(".setting_postfloodcheck"), $("#row_setting_postfloodsecs"), 1, true)',
1984          'new Peeker($("#setting_postmergemins"), $("#row_setting_postmergefignore, #row_setting_postmergeuignore, #row_setting_postmergesep"), /[^0+|]/, false)',
1985          'new Peeker($(".setting_enablememberlist"), $("#row_setting_membersperpage, #row_setting_default_memberlist_sortby, #row_setting_default_memberlist_order, #row_setting_memberlistmaxavatarsize"), 1, true)',
1986          'new Peeker($(".setting_enablereputation"), $("#row_setting_repsperpage, #row_setting_posrep, #row_setting_neurep, #row_setting_negrep, #row_setting_postrep, #row_setting_multirep, #row_setting_maxreplength, #row_setting_minreplength"), 1, true)',
1987          'new Peeker($(".setting_enablewarningsystem"), $("#row_setting_allowcustomwarnings, #row_setting_canviewownwarning, #row_setting_maxwarningpoints, #row_setting_allowanonwarningpms"), 1, true)',
1988          'new Peeker($(".setting_enablepms"), $("#row_setting_pmsallowhtml, #row_setting_pmsallowmycode, #row_setting_pmsallowsmilies, #row_setting_pmsallowimgcode, #row_setting_pmsallowvideocode, #row_setting_pmquickreply, #row_setting_pmfloodsecs, #row_setting_showpmip, #row_setting_maxpmquotedepth"), 1, true)',
1989          'new Peeker($(".setting_smilieinserter"), $("#row_setting_smilieinsertertot, #row_setting_smilieinsertercols"), 1, true)',
1990          'new Peeker($("#setting_mail_handler"), $("#row_setting_smtp_host, #row_setting_smtp_port, #row_setting_smtp_user, #row_setting_smtp_pass, #row_setting_secure_smtp"), "smtp", false)',
1991          'new Peeker($("#setting_mail_handler"), $("#row_setting_mail_parameters"), "mail", false)',
1992          'new Peeker($("#setting_captchaimage"), $("#row_setting_recaptchapublickey, #row_setting_recaptchaprivatekey"), /(4|5|8)/, false)',
1993          'new Peeker($("#setting_captchaimage"), $("#row_setting_recaptchascore"), /(8)/, false)',
1994          'new Peeker($("#setting_captchaimage"), $("#row_setting_hcaptchapublickey, #row_setting_hcaptchaprivatekey"), /(6|7)/, false)',
1995          'new Peeker($("#setting_captchaimage"), $("#row_setting_hcaptchaprivatekey, #row_setting_hcaptchaprivatekey"), /(6|7)/, false)',
1996          'new Peeker($("#setting_captchaimage"), $("#row_setting_hcaptchatheme"), 6, false)',
1997          'new Peeker($("#setting_captchaimage"), $("#row_setting_hcaptchasize"), 6, false)',
1998          'new Peeker($(".setting_contact"), $("#row_setting_contact_guests, #row_setting_contact_badwords, #row_setting_contact_maxsubjectlength, #row_setting_contact_minmessagelength, #row_setting_contact_maxmessagelength"), 1, true)',
1999          'new Peeker($(".setting_enablepruning"), $("#row_setting_enableprunebyposts, #row_setting_pruneunactived, #row_setting_prunethreads"), 1, true)',
2000          'new Peeker($(".setting_enableprunebyposts"), $("#row_setting_prunepostcount, #row_setting_dayspruneregistered, #row_setting_prunepostcountall"), 1, true)',
2001          'new Peeker($(".setting_pruneunactived"), $("#row_setting_dayspruneunactivated"), 1, true)',
2002          'new Peeker($(".setting_statsenabled"), $("#row_setting_statscachetime, #row_setting_statslimit, #row_setting_statstopreferrer"), 1, true)',
2003          'new Peeker($(".setting_purgespammergroups_forums_groups_check"), $("#row_setting_purgespammerpostlimit, #row_setting_purgespammerbandelete, #row_setting_purgespammerapikey"), /^(?!none)/, true)',
2004          'new Peeker($(".setting_purgespammerbandelete"),$("#row_setting_purgespammerbangroup, #row_setting_purgespammerbanreason"), "ban", true)',
2005          'new Peeker($("#setting_maxloginattempts"), $("#row_setting_loginattemptstimeout"), /[^0+|]/, false)',
2006          'new Peeker($(".setting_bbcodeinserter"), $("#row_setting_partialmode, #row_setting_smilieinserter"), 1, true)',
2007          'new Peeker($(".setting_portal"), $("#row_setting_portal_announcementsfid, #row_setting_portal_showwelcome, #row_setting_portal_showpms, #row_setting_portal_showstats, #row_setting_portal_showwol, #row_setting_portal_showsearch, #row_setting_portal_showdiscussions"), 1, true)',
2008          'new Peeker($(".setting_portal_announcementsfid_forums_groups_check"), $("#row_setting_portal_numannouncements"), /^(?!none)/, true)',
2009          'new Peeker($(".setting_portal_showdiscussions"), $("#row_setting_portal_showdiscussionsnum, #row_setting_portal_excludediscussion"), 1, true)',
2010          'new Peeker($(".setting_enableattachments"), $("#row_setting_maxattachments, #row_setting_attachthumbnails"), 1, true)',
2011          'new Peeker($(".setting_attachthumbnails"), $("#row_setting_attachthumbh, #row_setting_attachthumbw"), "yes", true)',
2012          'new Peeker($(".setting_showbirthdays"), $("#row_setting_showbirthdayspostlimit"), 1, true)',
2013          'new Peeker($("#setting_betweenregstime"), $("#row_setting_maxregsbetweentime"), /[^0+|]/, false)',
2014          'new Peeker($(".setting_usecdn"), $("#row_setting_cdnurl, #row_setting_cdnpath"), 1, true)',
2015          'new Peeker($("#setting_errorlogmedium"), $("#row_setting_errorloglocation"), /^(log|both)/, false)',
2016          'new Peeker($(".setting_sigmycode"), $("#row_setting_sigcountmycode, #row_setting_sigimgcode"), 1, true)',
2017          'new Peeker($(".setting_pmsallowmycode"), $("#row_setting_pmsallowimgcode, #row_setting_pmsallowvideocode"), 1, true)',
2018          'new Peeker($(".setting_enableshowteam"), $("#row_setting_showaddlgroups, #row_setting_showgroupleaders"), 1, true)',
2019          'new Peeker($(".setting_usereferrals"), $("#row_setting_referralsperpage"), 1, true)',
2020      );
2021  
2022      $peekers = $plugins->run_hooks("admin_settings_print_peekers", $peekers);
2023  
2024      $setting_peekers = implode("\n            ", $peekers);
2025  
2026      echo '<script type="text/javascript" src="./jscripts/peeker.js?ver=1821"></script>
2027      <script type="text/javascript">
2028          $(function() {
2029              ' . $setting_peekers . '
2030          });
2031      </script>';
2032  }


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