[ Index ]

PHP Cross Reference of MyBB 1.8.27

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


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