[ Index ]

PHP Cross Reference of MyBB 1.8.24

title

Body

[close]

/admin/modules/forum/ -> management.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->forum_management, "index.php?module=forum-management");
  18  
  19  if($mybb->input['action'] == "add" || $mybb->input['action'] == "edit" || $mybb->input['action'] == "copy" || $mybb->input['action'] == "permissions" || !$mybb->input['action'])
  20  {
  21      if(!empty($mybb->input['fid']) && ($mybb->input['action'] == "management" || $mybb->input['action'] == "edit" || $mybb->input['action'] == "copy" || !$mybb->input['action']))
  22      {
  23          $sub_tabs['view_forum'] = array(
  24              'title' => $lang->view_forum,
  25              'link' => "index.php?module=forum-management&amp;fid=".$mybb->input['fid'],
  26              'description' => $lang->view_forum_desc
  27          );
  28  
  29          $sub_tabs['add_child_forum'] = array(
  30              'title' => $lang->add_child_forum,
  31              'link' => "index.php?module=forum-management&amp;action=add&amp;pid=".$mybb->input['fid'],
  32              'description' => $lang->view_forum_desc
  33          );
  34  
  35          $sub_tabs['edit_forum_settings'] = array(
  36              'title' => $lang->edit_forum_settings,
  37              'link' => "index.php?module=forum-management&amp;action=edit&amp;fid=".$mybb->input['fid'],
  38              'description' => $lang->edit_forum_settings_desc
  39          );
  40  
  41          $sub_tabs['copy_forum'] = array(
  42              'title' => $lang->copy_forum,
  43              'link' => "index.php?module=forum-management&amp;action=copy&amp;fid=".$mybb->input['fid'],
  44              'description' => $lang->copy_forum_desc
  45          );
  46      }
  47      else
  48      {
  49          $sub_tabs['forum_management'] = array(
  50              'title' => $lang->forum_management,
  51              'link' => "index.php?module=forum-management",
  52              'description' => $lang->forum_management_desc
  53          );
  54  
  55          $sub_tabs['add_forum'] = array(
  56              'title' => $lang->add_forum,
  57              'link' => "index.php?module=forum-management&amp;action=add",
  58              'description' => $lang->add_forum_desc
  59          );
  60      }
  61  }
  62  
  63  $plugins->run_hooks("admin_forum_management_begin");
  64  
  65  if($mybb->input['action'] == "copy")
  66  {
  67      $plugins->run_hooks("admin_forum_management_copy");
  68  
  69      if($mybb->request_method == "post")
  70      {
  71          $from = $mybb->get_input('from', MyBB::INPUT_INT);
  72          $to = $mybb->get_input('to', MyBB::INPUT_INT);
  73  
  74          // Find the source forum
  75          $query = $db->simple_select("forums", '*', "fid='{$from}'");
  76          $from_forum = $db->fetch_array($query);
  77          if(!$db->num_rows($query))
  78          {
  79              $errors[] = $lang->error_invalid_source_forum;
  80          }
  81  
  82          if($to == -1)
  83          {
  84              // Create a new forum
  85              if(empty($mybb->input['title']))
  86              {
  87                  $errors[] = $lang->error_new_forum_needs_name;
  88              }
  89  
  90              if($mybb->input['pid'] == -1 && $mybb->input['type'] == 'f')
  91              {
  92                  $errors[] = $lang->error_no_parent;
  93              }
  94  
  95              if(!$errors)
  96              {
  97                  if($mybb->input['pid'] < 0)
  98                  {
  99                      $mybb->input['pid'] = 0;
 100                  }
 101                  $new_forum = $from_forum;
 102                  unset($new_forum['fid'], $new_forum['threads'], $new_forum['posts'], $new_forum['lastpost'], $new_forum['lastposter'], $new_forum['lastposteruid'], $new_forum['lastposttid'], $new_forum['lastpostsubject'], $new_forum['unapprovedthreads'], $new_forum['unapprovedposts']);
 103                  $new_forum['name'] = $db->escape_string($mybb->input['title']);
 104                  $new_forum['description'] = $db->escape_string($mybb->input['description']);
 105                  $new_forum['type'] = $db->escape_string($mybb->input['type']);
 106                  $new_forum['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 107                  $new_forum['rulestitle'] = $db->escape_string($new_forum['rulestitle']);
 108                  $new_forum['rules'] = $db->escape_string($new_forum['rules']);
 109                  $new_forum['parentlist'] = '';
 110  
 111                  $to = $db->insert_query("forums", $new_forum);
 112  
 113                  // Generate parent list
 114                  $parentlist = make_parent_list($to);
 115                  $updatearray = array(
 116                      'parentlist' => $parentlist
 117                  );
 118                  $db->update_query("forums", $updatearray, "fid='{$to}'");
 119              }
 120          }
 121          elseif($mybb->input['copyforumsettings'] == 1)
 122          {
 123              // Copy settings to existing forum
 124              $query = $db->simple_select("forums", '*', "fid='{$to}'");
 125              $to_forum = $db->fetch_array($query);
 126              if(!$db->num_rows($query))
 127              {
 128                  $errors[] = $lang->error_invalid_destination_forum;
 129              }
 130  
 131              if(!$errors)
 132              {
 133                  $new_forum = $from_forum;
 134                  unset($new_forum['fid'], $new_forum['threads'], $new_forum['posts'], $new_forum['lastpost'], $new_forum['lastposter'], $new_forum['lastposteruid'], $new_forum['lastposttid'], $new_forum['lastpostsubject'], $new_forum['unapprovedthreads'], $new_forum['unapprovedposts']);
 135                  $new_forum['name'] = $db->escape_string($to_forum['name']);
 136                  $new_forum['description'] = $db->escape_string($to_forum['description']);
 137                  $new_forum['pid'] = $db->escape_string($to_forum['pid']);
 138                  $new_forum['parentlist'] = $db->escape_string($to_forum['parentlist']);
 139                  $new_forum['rulestitle'] = $db->escape_string($new_forum['rulestitle']);
 140                  $new_forum['rules'] = $db->escape_string($new_forum['rules']);
 141  
 142                  $db->update_query("forums", $new_forum, "fid='{$to}'");
 143              }
 144          }
 145  
 146          if(!$errors)
 147          {
 148              // Copy permissions
 149              if(is_array($mybb->input['copygroups']) && count($mybb->input['copygroups']) > 0)
 150              {
 151                  foreach($mybb->input['copygroups'] as $gid)
 152                  {
 153                      $groups[] = (int)$gid;
 154                  }
 155                  $groups = implode(',', $groups);
 156                  $query = $db->simple_select("forumpermissions", '*', "fid='{$from}' AND gid IN ({$groups})");
 157                  $db->delete_query("forumpermissions", "fid='{$to}' AND gid IN ({$groups})", 1);
 158                  while($permissions = $db->fetch_array($query))
 159                  {
 160                      unset($permissions['pid']);
 161                      $permissions['fid'] = $to;
 162  
 163                      $db->insert_query("forumpermissions", $permissions);
 164                  }
 165  
 166                  // Log admin action
 167                  log_admin_action($from, $from_forum['name'], $to, $new_forum['name'], $groups);
 168              }
 169              else
 170              {
 171                  // Log admin action (no group permissions)
 172                  log_admin_action($from, $from_forum['name'], $to, $new_forum['name']);
 173              }
 174  
 175              $plugins->run_hooks("admin_forum_management_copy_commit");
 176  
 177              $cache->update_forums();
 178              $cache->update_forumpermissions();
 179  
 180              flash_message($lang->success_forum_copied, 'success');
 181              admin_redirect("index.php?module=forum-management&action=edit&fid={$to}");
 182          }
 183      }
 184  
 185      $page->add_breadcrumb_item($lang->copy_forum);
 186      $page->output_header($lang->copy_forum);
 187      $page->output_nav_tabs($sub_tabs, 'copy_forum');
 188  
 189      $form = new Form("index.php?module=forum-management&amp;action=copy", "post");
 190  
 191      if($errors)
 192      {
 193          $page->output_inline_error($errors);
 194          $copy_data = $mybb->input;
 195      }
 196      else
 197      {
 198          $copy_data['type'] = "f";
 199          $copy_data['title'] = "";
 200          $copy_data['description'] = "";
 201  
 202          if(!$mybb->input['pid'])
 203          {
 204              $copy_data['pid'] = "-1";
 205          }
 206          else
 207          {
 208              $copy_data['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 209          }
 210          $copy_data['disporder'] = "1";
 211          $copy_data['from'] = $mybb->input['fid'];
 212          $copy_data['copyforumsettings'] = 0;
 213          $copy_data['pid'] = 0;
 214      }
 215  
 216      $types = array(
 217          'f' => $lang->forum,
 218          'c' => $lang->category
 219      );
 220  
 221      $create_a_options_f = array(
 222          'id' => 'forum'
 223      );
 224  
 225      $create_a_options_c = array(
 226          'id' => 'category'
 227      );
 228  
 229      if($copy_data['type'] == "f")
 230      {
 231          $create_a_options_f['checked'] = true;
 232      }
 233      else
 234      {
 235          $create_a_options_c['checked'] = true;
 236      }
 237  
 238      $usergroups = array();
 239  
 240      $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
 241      while($usergroup = $db->fetch_array($query))
 242      {
 243          $usergroups[$usergroup['gid']] = htmlspecialchars_uni($usergroup['title']);
 244      }
 245  
 246      $form_container = new FormContainer($lang->copy_forum);
 247      $form_container->output_row($lang->source_forum." <em>*</em>", $lang->source_forum_desc, $form->generate_forum_select('from', $copy_data['from'], array('id' => 'from')), 'from');
 248      $form_container->output_row($lang->destination_forum." <em>*</em>", $lang->destination_forum_desc, $form->generate_forum_select('to', $copy_data['to'], array('id' => 'to', 'main_option' => $lang->copy_to_new_forum)), 'to');
 249      $form_container->output_row($lang->copy_settings_and_properties, $lang->copy_settings_and_properties_desc, $form->generate_yes_no_radio('copyforumsettings', $copy_data['copyforumsettings']));
 250      $form_container->output_row($lang->copy_user_group_permissions, $lang->copy_user_group_permissions_desc, $form->generate_select_box('copygroups[]', $usergroups, $mybb->input['copygroups'], array('id' => 'copygroups', 'multiple' => true, 'size' => 5)), 'copygroups');
 251  
 252      $form_container->end();
 253  
 254      $form_container = new FormContainer($lang->new_forum_settings);
 255      $form_container->output_row($lang->forum_type, $lang->forum_type_desc, $form->generate_radio_button('type', 'f', $lang->forum, $create_a_options_f)."<br />\n".$form->generate_radio_button('type', 'c', $lang->category, $create_a_options_c));
 256      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $copy_data['title'], array('id' => 'title')), 'title');
 257      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $copy_data['description'], array('id' => 'description')), 'description');
 258      $form_container->output_row($lang->parent_forum." <em>*</em>", $lang->parent_forum_desc, $form->generate_forum_select('pid', $copy_data['pid'], array('id' => 'pid', 'main_option' => $lang->none)), 'pid');
 259  
 260      $form_container->end();
 261  
 262      $buttons[] = $form->generate_submit_button($lang->copy_forum);
 263      $form->output_submit_wrapper($buttons);
 264      $form->end();
 265  
 266      $page->output_footer();
 267  }
 268  
 269  if($mybb->input['action'] == "editmod")
 270  {
 271      $query = $db->simple_select("moderators", "*", "mid='".$mybb->get_input('mid', MyBB::INPUT_INT)."'");
 272      $mod_data = $db->fetch_array($query);
 273  
 274      if(!$mod_data['id'])
 275      {
 276          flash_message($lang->error_incorrect_moderator, 'error');
 277          admin_redirect("index.php?module=forum-management");
 278      }
 279  
 280      $plugins->run_hooks("admin_forum_management_editmod");
 281  
 282      if($mod_data['isgroup'])
 283      {
 284          $fieldname = "title";
 285      }
 286      else
 287      {
 288          $fieldname = "username";
 289      }
 290  
 291      if($mybb->request_method == "post")
 292      {
 293          $mid = $mybb->get_input('mid', MyBB::INPUT_INT);
 294          if(!$mid)
 295          {
 296              flash_message($lang->error_incorrect_moderator, 'error');
 297              admin_redirect("index.php?module=forum-management");
 298          }
 299  
 300          if(!$errors)
 301          {
 302              $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
 303              $forum = get_forum($fid);
 304              if($mod_data['isgroup'])
 305              {
 306                  $mod = $groupscache[$mod_data['id']];
 307              }
 308              else
 309              {
 310                  $mod = get_user($mod_data['id']);
 311              }
 312              $update_array = array(
 313                  'fid' => (int)$fid,
 314                  'caneditposts' => $mybb->get_input('caneditposts', MyBB::INPUT_INT),
 315                  'cansoftdeleteposts' => $mybb->get_input('cansoftdeleteposts', MyBB::INPUT_INT),
 316                  'canrestoreposts' => $mybb->get_input('canrestoreposts', MyBB::INPUT_INT),
 317                  'candeleteposts' => $mybb->get_input('candeleteposts', MyBB::INPUT_INT),
 318                  'cansoftdeletethreads' => $mybb->get_input('cansoftdeletethreads', MyBB::INPUT_INT),
 319                  'canrestorethreads' => $mybb->get_input('canrestorethreads', MyBB::INPUT_INT),
 320                  'candeletethreads' => $mybb->get_input('candeletethreads', MyBB::INPUT_INT),
 321                  'canviewips' => $mybb->get_input('canviewips', MyBB::INPUT_INT),
 322                  'canviewunapprove' => $mybb->get_input('canviewunapprove', MyBB::INPUT_INT),
 323                  'canviewdeleted' => $mybb->get_input('canviewdeleted', MyBB::INPUT_INT),
 324                  'canopenclosethreads' => $mybb->get_input('canopenclosethreads', MyBB::INPUT_INT),
 325                  'canstickunstickthreads' => $mybb->get_input('canstickunstickthreads', MyBB::INPUT_INT),
 326                  'canapproveunapprovethreads' => $mybb->get_input('canapproveunapprovethreads', MyBB::INPUT_INT),
 327                  'canapproveunapproveposts' => $mybb->get_input('canapproveunapproveposts', MyBB::INPUT_INT),
 328                  'canapproveunapproveattachs' => $mybb->get_input('canapproveunapproveattachs', MyBB::INPUT_INT),
 329                  'canmanagethreads' => $mybb->get_input('canmanagethreads', MyBB::INPUT_INT),
 330                  'canmanagepolls' => $mybb->get_input('canmanagepolls', MyBB::INPUT_INT),
 331                  'canpostclosedthreads' => $mybb->get_input('canpostclosedthreads', MyBB::INPUT_INT),
 332                  'canmovetononmodforum' => $mybb->get_input('canmovetononmodforum', MyBB::INPUT_INT),
 333                  'canusecustomtools' => $mybb->get_input('canusecustomtools', MyBB::INPUT_INT),
 334                  'canmanageannouncements' => $mybb->get_input('canmanageannouncements', MyBB::INPUT_INT),
 335                  'canmanagereportedposts' => $mybb->get_input('canmanagereportedposts', MyBB::INPUT_INT),
 336                  'canviewmodlog' => $mybb->get_input('canviewmodlog', MyBB::INPUT_INT)
 337              );
 338  
 339              $plugins->run_hooks("admin_forum_management_editmod_commit");
 340  
 341              $db->update_query("moderators", $update_array, "mid='".$mybb->get_input('mid', MyBB::INPUT_INT)."'");
 342  
 343              $cache->update_moderators();
 344  
 345              // Log admin action
 346              log_admin_action($fid, $forum['name'], $mid, $mod[$fieldname]);
 347  
 348              flash_message($lang->success_moderator_updated, 'success');
 349              admin_redirect("index.php?module=forum-management&fid=".$mybb->get_input('fid', MyBB::INPUT_INT)."#tab_moderators");
 350          }
 351      }
 352  
 353      if($mod_data['isgroup'])
 354      {
 355          $query = $db->simple_select("usergroups", "title", "gid='{$mod_data['id']}'");
 356          $mod_data[$fieldname] = $db->fetch_field($query, 'title');
 357      }
 358      else
 359      {
 360          $query = $db->simple_select("users", "username", "uid='{$mod_data['id']}'");
 361          $mod_data[$fieldname] = $db->fetch_field($query, 'username');
 362      }
 363  
 364      $sub_tabs = array();
 365  
 366      $sub_tabs['edit_mod'] = array(
 367          'title' => $lang->edit_mod,
 368          'link' => "index.php?module=forum-management&amp;action=editmod&amp;mid=".$mybb->input['mid'],
 369          'description' => $lang->edit_mod_desc
 370      );
 371  
 372      $page->add_breadcrumb_item($lang->forum_moderators, "index.php?module=forum-management&amp;fid={$mod_data['fid']}#tab_moderators");
 373      $page->add_breadcrumb_item($lang->edit_forum);
 374      $page->output_header($lang->edit_mod);
 375      $page->output_nav_tabs($sub_tabs, 'edit_mod');
 376  
 377      $form = new Form("index.php?module=forum-management&amp;action=editmod", "post");
 378      echo $form->generate_hidden_field("mid", $mod_data['mid']);
 379  
 380      if($errors)
 381      {
 382          $page->output_inline_error($errors);
 383          $mod_data = $mybb->input;
 384      }
 385  
 386      $form_container = new FormContainer($lang->sprintf($lang->edit_mod_for, $mod_data[$fieldname]));
 387      $form_container->output_row($lang->forum, $lang->forum_desc, $form->generate_forum_select('fid', $mod_data['fid'], array('id' => 'fid')), 'fid');
 388  
 389      $moderator_permissions = array(
 390          $form->generate_check_box('caneditposts', 1, $lang->can_edit_posts, array('checked' => $mod_data['caneditposts'], 'id' => 'caneditposts')),
 391          $form->generate_check_box('cansoftdeleteposts', 1, $lang->can_soft_delete_posts, array('checked' => $mod_data['cansoftdeleteposts'], 'id' => 'cansoftdeleteposts')),
 392          $form->generate_check_box('canrestoreposts', 1, $lang->can_restore_posts, array('checked' => $mod_data['canrestoreposts'], 'id' => 'canrestoreposts')),
 393          $form->generate_check_box('candeleteposts', 1, $lang->can_delete_posts, array('checked' => $mod_data['candeleteposts'], 'id' => 'candeleteposts')),
 394          $form->generate_check_box('cansoftdeletethreads', 1, $lang->can_soft_delete_threads, array('checked' => $mod_data['cansoftdeletethreads'], 'id' => 'cansoftdeletethreads')),
 395          $form->generate_check_box('canrestorethreads', 1, $lang->can_restore_threads, array('checked' => $mod_data['canrestorethreads'], 'id' => 'canrestorethreads')),
 396          $form->generate_check_box('candeletethreads', 1, $lang->can_delete_threads, array('checked' => $mod_data['candeletethreads'], 'id' => 'candeletethreads')),
 397          $form->generate_check_box('canviewips', 1, $lang->can_view_ips, array('checked' => $mod_data['canviewips'], 'id' => 'canviewips')),
 398          $form->generate_check_box('canviewunapprove', 1, $lang->can_view_unapprove, array('checked' => $mod_data['canviewunapprove'], 'id' => 'canviewunapprove')),
 399          $form->generate_check_box('canviewdeleted', 1, $lang->can_view_deleted, array('checked' => $mod_data['canviewdeleted'], 'id' => 'canviewdeleted')),
 400          $form->generate_check_box('canopenclosethreads', 1, $lang->can_open_close_threads, array('checked' => $mod_data['canopenclosethreads'], 'id' => 'canopenclosethreads')),
 401          $form->generate_check_box('canstickunstickthreads', 1, $lang->can_stick_unstick_threads, array('checked' => $mod_data['canstickunstickthreads'], 'id' => 'canstickunstickthreads')),
 402          $form->generate_check_box('canapproveunapprovethreads', 1, $lang->can_approve_unapprove_threads, array('checked' => $mod_data['canapproveunapprovethreads'], 'id' => 'canapproveunapprovethreads')),
 403          $form->generate_check_box('canapproveunapproveposts', 1, $lang->can_approve_unapprove_posts, array('checked' => $mod_data['canapproveunapproveposts'], 'id' => 'canapproveunapproveposts')),
 404          $form->generate_check_box('canapproveunapproveattachs', 1, $lang->can_approve_unapprove_attachments, array('checked' => $mod_data['canapproveunapproveattachs'], 'id' => 'canapproveunapproveattachs')),
 405          $form->generate_check_box('canmanagethreads', 1, $lang->can_manage_threads, array('checked' => $mod_data['canmanagethreads'], 'id' => 'canmanagethreads')),
 406          $form->generate_check_box('canmanagepolls', 1, $lang->can_manage_polls, array('checked' => $mod_data['canmanagepolls'], 'id' => 'canmanagepolls')),
 407          $form->generate_check_box('canpostclosedthreads', 1, $lang->can_post_closed_threads, array('checked' => $mod_data['canpostclosedthreads'], 'id' => 'canpostclosedthreads')),
 408          $form->generate_check_box('canmovetononmodforum', 1, $lang->can_move_to_other_forums, array('checked' => $mod_data['canmovetononmodforum'], 'id' => 'canmovetononmodforum')),
 409          $form->generate_check_box('canusecustomtools', 1, $lang->can_use_custom_tools, array('checked' => $mod_data['canusecustomtools'], 'id' => 'canusecustomtools'))
 410      );
 411      $form_container->output_row($lang->moderator_permissions, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $moderator_permissions)."</div>");
 412  
 413      $moderator_cp_permissions = array(
 414          $form->generate_check_box('canmanageannouncements', 1, $lang->can_manage_announcements, array('checked' => $mod_data['canmanageannouncements'], 'id' => 'canmanageannouncements')),
 415          $form->generate_check_box('canmanagereportedposts', 1, $lang->can_manage_reported_posts, array('checked' => $mod_data['canmanagereportedposts'], 'id' => 'canmanagereportedposts')),
 416          $form->generate_check_box('canviewmodlog', 1, $lang->can_view_mod_log, array('checked' => $mod_data['canviewmodlog'], 'id' => 'canviewmodlog'))
 417      );
 418      $form_container->output_row($lang->moderator_cp_permissions, $lang->moderator_cp_permissions_desc, "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $moderator_cp_permissions)."</div>");
 419  
 420      $form_container->end();
 421  
 422      $buttons[] = $form->generate_submit_button($lang->save_mod);
 423      $form->output_submit_wrapper($buttons);
 424      $form->end();
 425  
 426      $page->output_footer();
 427  }
 428  
 429  if($mybb->input['action'] == "clear_permission")
 430  {
 431      $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
 432      $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
 433      $gid = $mybb->get_input('gid', MyBB::INPUT_INT);
 434  
 435      // User clicked no
 436      if($mybb->input['no'])
 437      {
 438          admin_redirect("index.php?module=forum-management&fid={$fid}");
 439      }
 440  
 441      $plugins->run_hooks("admin_forum_management_clear_permission");
 442  
 443      if($mybb->request_method == "post")
 444      {
 445          if((!$fid || !$gid) && $pid)
 446          {
 447              $query = $db->simple_select("forumpermissions", "fid, gid", "pid='{$pid}'");
 448              $result = $db->fetch_array($query);
 449              $fid = $result['fid'];
 450              $gid = $result['gid'];
 451          }
 452  
 453          if($pid)
 454          {
 455              $db->delete_query("forumpermissions", "pid='{$pid}'");
 456          }
 457          else
 458          {
 459              $db->delete_query("forumpermissions", "gid='{$gid}' AND fid='{$fid}'");
 460          }
 461  
 462          $plugins->run_hooks('admin_forum_management_clear_permission_commit');
 463  
 464          $cache->update_forumpermissions();
 465  
 466          flash_message($lang->success_custom_permission_cleared, 'success');
 467          admin_redirect("index.php?module=forum-management&fid={$fid}#tab_permissions");
 468      }
 469      else
 470      {
 471          $page->output_confirm_action("index.php?module=forum-management&amp;action=clear_permission&amp;pid={$pid}&amp;gid={$gid}&amp;fid={$fid}", $lang->confirm_clear_custom_permission);
 472      }
 473  }
 474  
 475  if($mybb->input['action'] == "permissions")
 476  {
 477      $plugins->run_hooks("admin_forum_management_permissions");
 478  
 479      if($mybb->request_method == "post")
 480      {
 481          $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
 482          $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
 483          $gid = $mybb->get_input('gid', MyBB::INPUT_INT);
 484          $forum = get_forum($fid);
 485  
 486          if((!$fid || !$gid) && $pid)
 487          {
 488              $query = $db->simple_select("forumpermissions", "fid, gid", "pid='{$pid}'");
 489              $result = $db->fetch_array($query);
 490              $fid = $result['fid'];
 491              $gid = $result['gid'];
 492              $forum = get_forum($fid);
 493          }
 494  
 495          $field_list = array();
 496          $fields_array = $db->show_fields_from("forumpermissions");
 497          if(is_array($mybb->input['permissions']))
 498          {
 499              // User has set permissions for this group...
 500              foreach($fields_array as $field)
 501              {
 502                  if(strpos($field['Field'], 'can') !== false || strpos($field['Field'], 'mod') !== false)
 503                  {
 504                      if(array_key_exists($field['Field'], $mybb->input['permissions']))
 505                      {
 506                          $update_array[$db->escape_string($field['Field'])] = (int)$mybb->input['permissions'][$field['Field']];
 507                      }
 508                      else
 509                      {
 510                          $update_array[$db->escape_string($field['Field'])] = 0;
 511                      }
 512                  }
 513              }
 514          }
 515          else
 516          {
 517              // Else, we assume that the group has no permissions...
 518              foreach($fields_array as $field)
 519              {
 520                  if(strpos($field['Field'], 'can') !== false || strpos($field['Field'], 'mod') !== false)
 521                  {
 522                      $update_array[$db->escape_string($field['Field'])] = 0;
 523                  }
 524              }
 525          }
 526  
 527          if($fid && !$pid)
 528          {
 529              $update_array['fid'] = $fid;
 530              $update_array['gid'] = $mybb->get_input('gid', MyBB::INPUT_INT);
 531              $db->insert_query("forumpermissions", $update_array);
 532          }
 533  
 534          $plugins->run_hooks("admin_forum_management_permissions_commit");
 535  
 536          if(!($fid && !$pid))
 537          {
 538              $db->update_query("forumpermissions", $update_array, "pid='{$pid}'");
 539          }
 540  
 541          $cache->update_forumpermissions();
 542  
 543          // Log admin action
 544          log_admin_action($fid, $forum['name']);
 545  
 546          if($mybb->input['ajax'] == 1)
 547          {
 548              echo json_encode("<script type=\"text/javascript\">$('#row_{$gid}').html('".str_replace(array("'", "\t", "\n"), array("\\'", "", ""), retrieve_single_permissions_row($gid, $fid))."'); QuickPermEditor.init({$gid});</script>");
 549              die;
 550          }
 551          else
 552          {
 553              flash_message($lang->success_forum_permissions_saved, 'success');
 554              admin_redirect("index.php?module=forum-management&fid={$fid}#tab_permissions");
 555          }
 556      }
 557  
 558      if($mybb->input['ajax'] != 1)
 559      {
 560          $sub_tabs = array();
 561  
 562          if($mybb->input['fid'] && $mybb->input['gid'])
 563          {
 564              $sub_tabs['edit_permissions'] = array(
 565                  'title' => $lang->forum_permissions,
 566                  'link' => "index.php?module=forum-management&amp;action=permissions&amp;fid=".$mybb->input['fid']."&amp;gid=".$mybb->input['gid'],
 567                  'description' => $lang->forum_permissions_desc
 568              );
 569  
 570              $page->add_breadcrumb_item($lang->forum_permissions2, "index.php?module=forum-management&amp;fid=".$mybb->input['fid']."#tab_permissions");
 571          }
 572          else
 573          {
 574              $query = $db->simple_select("forumpermissions", "fid", "pid='".$mybb->get_input('pid', MyBB::INPUT_INT)."'");
 575              $mybb->input['fid'] = $db->fetch_field($query, "fid");
 576  
 577              $sub_tabs['edit_permissions'] = array(
 578                  'title' => $lang->forum_permissions,
 579                  'link' => "index.php?module=forum-management&amp;action=permissions&amp;pid=".$mybb->get_input('pid', MyBB::INPUT_INT),
 580                  'description' => $lang->forum_permissions_desc
 581              );
 582  
 583              $page->add_breadcrumb_item($lang->forum_permissions2, "index.php?module=forum-management&amp;fid=".$mybb->input['fid']."#tab_permissions");
 584          }
 585  
 586          $page->add_breadcrumb_item($lang->forum_permissions);
 587          $page->output_header($lang->forum_permissions);
 588          $page->output_nav_tabs($sub_tabs, 'edit_permissions');
 589      }
 590      else
 591      {
 592          echo "
 593          <div class=\"modal\" style=\"width: auto\">
 594          <script src=\"jscripts/tabs.js\" type=\"text/javascript\"></script>\n
 595          <script type=\"text/javascript\">
 596  <!--
 597  $(function() {
 598      $(\"#modal_form\").on(\"click\", \"#savePermissions\", function(e) {
 599          e.preventDefault();
 600          
 601          var datastring = $(\"#modal_form\").serialize();
 602          $.ajax({
 603              type: \"POST\",
 604              url: $(\"#modal_form\").attr('action'),
 605              data: datastring,
 606              dataType: \"json\",
 607              success: function(data) {
 608                  $(data).filter(\"script\").each(function(e) {
 609                      eval($(this).text());
 610                  });
 611                  $.modal.close();
 612              },
 613              error: function(){
 614              }
 615          });
 616      });
 617  });
 618  // -->
 619          </script>
 620          <div style=\"overflow-y: auto; max-height: 400px\">";
 621      }
 622  
 623      if($mybb->input['pid'] || ($mybb->input['gid'] && $mybb->input['fid']))
 624      {
 625          if($mybb->input['ajax'] != 1)
 626          {
 627              $form = new Form("index.php?module=forum-management&amp;action=permissions", "post");
 628          }
 629          else
 630          {
 631              $form = new Form("index.php?module=forum-management&amp;action=permissions&amp;ajax=1&amp;pid=".$mybb->get_input('pid', MyBB::INPUT_INT)."&amp;gid=".$mybb->get_input('gid', MyBB::INPUT_INT)."&amp;fid=".$mybb->get_input('gid', MyBB::INPUT_INT), "post", "modal_form");
 632          }
 633          echo $form->generate_hidden_field("usecustom", "1");
 634  
 635          if($errors)
 636          {
 637              $page->output_inline_error($errors);
 638              $permission_data = $mybb->input;
 639  
 640              $query = $db->simple_select("usergroups", "*", "gid='{$permission_data['gid']}'");
 641              $usergroup = $db->fetch_array($query);
 642  
 643              $query = $db->simple_select("forums", "*", "fid='{$permission_data['fid']}'");
 644              $forum = $db->fetch_array($query);
 645          }
 646          else
 647          {
 648              $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
 649              $gid = $mybb->get_input('gid', MyBB::INPUT_INT);
 650              $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
 651  
 652              if($pid)
 653              {
 654                  $query = $db->simple_select("forumpermissions", "*", "pid='{$pid}'");
 655              }
 656              else
 657              {
 658                  $query = $db->simple_select("forumpermissions", "*", "fid='{$fid}' AND gid='{$gid}'", array('limit' => 1));
 659              }
 660  
 661              $permission_data = $db->fetch_array($query);
 662  
 663              if(!$fid)
 664              {
 665                  $fid = $permission_data['fid'];
 666              }
 667  
 668              if(!$gid)
 669              {
 670                  $gid = $permission_data['gid'];
 671              }
 672  
 673              if(!$pid)
 674              {
 675                  $pid = $permission_data['pid'];
 676              }
 677  
 678              $query = $db->simple_select("usergroups", "*", "gid='$gid'");
 679              $usergroup = $db->fetch_array($query);
 680  
 681              $query = $db->simple_select("forums", "*", "fid='$fid'");
 682              $forum = $db->fetch_array($query);
 683  
 684              $sperms = $permission_data;
 685  
 686              $sql = build_parent_list($fid);
 687              $query = $db->simple_select("forumpermissions", "*", "$sql AND gid='$gid'");
 688              $customperms = $db->fetch_array($query);
 689  
 690              if($permission_data['pid'])
 691              {
 692                  $permission_data['usecustom'] = 1;
 693                  echo $form->generate_hidden_field("pid", $pid);
 694              }
 695              else
 696              {
 697                  echo $form->generate_hidden_field("fid", $fid);
 698                  echo $form->generate_hidden_field("gid", $gid);
 699                  if(!$customperms['pid'])
 700                  {
 701                      $permission_data = usergroup_permissions($gid);
 702                  }
 703                  else
 704                  {
 705                      $permission_data = forum_permissions($fid, 0, $gid);
 706                  }
 707              }
 708          }
 709  
 710          $groups = array(
 711              'canviewthreads' => 'viewing',
 712              'canview' => 'viewing',
 713              'canonlyviewownthreads' => 'viewing',
 714              'candlattachments' => 'viewing',
 715  
 716              'canpostthreads' => 'posting_rating',
 717              'canpostreplys' => 'posting_rating',
 718              'canonlyreplyownthreads' => 'posting_rating',
 719              'canpostattachments' => 'posting_rating',
 720              'canratethreads' => 'posting_rating',
 721  
 722              'caneditposts' => 'editing',
 723              'candeleteposts' => 'editing',
 724              'candeletethreads' => 'editing',
 725              'caneditattachments' => 'editing',
 726              'canviewdeletionnotice' => 'editing',
 727  
 728              'modposts' => 'moderate',
 729              'modthreads' => 'moderate',
 730              'modattachments' => 'moderate',
 731              'mod_edit_posts' => 'moderate',
 732  
 733              'canpostpolls' => 'polls',
 734              'canvotepolls' => 'polls',
 735              'cansearch' => 'misc',
 736          );
 737  
 738          $groups = $plugins->run_hooks("admin_forum_management_permission_groups", $groups);
 739  
 740          $tabs = array();
 741          foreach(array_unique(array_values($groups)) as $group)
 742          {
 743              $lang_group = "group_".$group;
 744              $tabs[$group] = $lang->$lang_group;
 745          }
 746  
 747          if($mybb->input['ajax'] == 1)
 748          {
 749              $page->output_tab_control($tabs, false, "tabs2");
 750          }
 751          else
 752          {
 753              $page->output_tab_control($tabs);
 754          }
 755  
 756          $field_list = array();
 757          $fields_array = $db->show_fields_from("forumpermissions");
 758          foreach($fields_array as $field)
 759          {
 760              if(strpos($field['Field'], 'can') !== false || strpos($field['Field'], 'mod') !== false)
 761              {
 762                  if(array_key_exists($field['Field'], $groups))
 763                  {
 764                      $field_list[$groups[$field['Field']]][] = $field['Field'];
 765                  }
 766                  else
 767                  {
 768                      $field_list['misc'][] = $field['Field'];
 769                  }
 770              }
 771          }
 772  
 773          foreach(array_unique(array_values($groups)) as $group)
 774          {
 775              $lang_group = "group_".$group;
 776              echo "<div id=\"tab_".$group."\">\n";
 777              $form_container = new FormContainer("\"".htmlspecialchars_uni($usergroup['title'])."\" {$lang->custom_permissions_for} \"".htmlspecialchars_uni($forum['name'])."\"");
 778              $fields = array();
 779              foreach($field_list[$group] as $field)
 780              {
 781                  $lang_field = $group."_field_".$field;
 782                  $fields[] = $form->generate_check_box("permissions[{$field}]", 1, $lang->$lang_field, array('checked' => $permission_data[$field], 'id' => $field));
 783              }
 784              $form_container->output_row("", "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $fields)."</div>");
 785              $form_container->end();
 786              echo "</div>";
 787          }
 788  
 789          if($mybb->input['ajax'] == 1)
 790          {
 791              $buttons[] = $form->generate_submit_button($lang->cancel, array('onclick' => '$.modal.close(); return false;'));
 792              $buttons[] = $form->generate_submit_button($lang->save_permissions, array('id' => 'savePermissions'));
 793              $form->output_submit_wrapper($buttons);
 794              $form->end();
 795              echo "</div>";
 796              echo "</div>";
 797          }
 798          else
 799          {
 800              $buttons[] = $form->generate_submit_button($lang->save_permissions);
 801              $form->output_submit_wrapper($buttons);
 802  
 803              $form->end();
 804          }
 805      }
 806  
 807      if($mybb->input['ajax'] != 1)
 808      {
 809          $page->output_footer();
 810      }
 811  }
 812  
 813  if($mybb->input['action'] == "add")
 814  {
 815      $plugins->run_hooks("admin_forum_management_add");
 816  
 817      if($mybb->request_method == "post")
 818      {
 819          if(!trim($mybb->input['title']))
 820          {
 821              $errors[] = $lang->error_missing_title;
 822          }
 823  
 824          $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
 825          $type = $mybb->input['type'];
 826  
 827          if($pid <= 0 && $type == "f")
 828          {
 829              $errors[] = $lang->error_no_parent;
 830          }
 831  
 832          if(!$errors)
 833          {
 834              if($pid < 0)
 835              {
 836                  $pid = 0;
 837              }
 838              $insert_array = array(
 839                  "name" => $db->escape_string($mybb->input['title']),
 840                  "description" => $db->escape_string($mybb->input['description']),
 841                  "linkto" => $db->escape_string($mybb->input['linkto']),
 842                  "type" => $db->escape_string($type),
 843                  "pid" => $pid,
 844                  "parentlist" => '',
 845                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
 846                  "active" => $mybb->get_input('active', MyBB::INPUT_INT),
 847                  "open" => $mybb->get_input('open', MyBB::INPUT_INT),
 848                  "allowhtml" => $mybb->get_input('allowhtml', MyBB::INPUT_INT),
 849                  "allowmycode" => $mybb->get_input('allowmycode', MyBB::INPUT_INT),
 850                  "allowsmilies" => $mybb->get_input('allowsmilies', MyBB::INPUT_INT),
 851                  "allowimgcode" => $mybb->get_input('allowimgcode', MyBB::INPUT_INT),
 852                  "allowvideocode" => $mybb->get_input('allowvideocode', MyBB::INPUT_INT),
 853                  "allowpicons" => $mybb->get_input('allowpicons', MyBB::INPUT_INT),
 854                  "allowtratings" => $mybb->get_input('allowtratings', MyBB::INPUT_INT),
 855                  "usepostcounts" => $mybb->get_input('usepostcounts', MyBB::INPUT_INT),
 856                  "usethreadcounts" => $mybb->get_input('usethreadcounts', MyBB::INPUT_INT),
 857                  "requireprefix" => $mybb->get_input('requireprefix', MyBB::INPUT_INT),
 858                  "password" => $db->escape_string($mybb->input['password']),
 859                  "showinjump" => $mybb->get_input('showinjump', MyBB::INPUT_INT),
 860                  "style" => $mybb->get_input('style', MyBB::INPUT_INT),
 861                  "overridestyle" => $mybb->get_input('overridestyle', MyBB::INPUT_INT),
 862                  "rulestype" => $mybb->get_input('rulestype', MyBB::INPUT_INT),
 863                  "rulestitle" => $db->escape_string($mybb->input['rulestitle']),
 864                  "rules" => $db->escape_string($mybb->input['rules']),
 865                  "defaultdatecut" => $mybb->get_input('defaultdatecut', MyBB::INPUT_INT),
 866                  "defaultsortby" => $db->escape_string($mybb->input['defaultsortby']),
 867                  "defaultsortorder" => $db->escape_string($mybb->input['defaultsortorder']),
 868              );
 869  
 870              $plugins->run_hooks("admin_forum_management_add_start");
 871  
 872              $fid = $db->insert_query("forums", $insert_array);
 873  
 874              $parentlist = make_parent_list($fid);
 875              $db->update_query("forums", array("parentlist" => $parentlist), "fid='$fid'");
 876  
 877              $inherit = $mybb->input['default_permissions'];
 878  
 879              foreach($mybb->input as $id => $permission)
 880              {
 881                  if(strpos($id, 'fields_') === false)
 882                  {
 883                      continue;
 884                  }
 885  
 886                  list(, $gid) = explode('fields_', $id);
 887  
 888                  // If it isn't an array then it came from the javascript form
 889                  if(!is_array($permission))
 890                  {
 891                      $permission = explode(',', $permission);
 892                      $permission = array_flip($permission);
 893                      foreach($permission as $name => $value)
 894                      {
 895                          $permission[$name] = 1;
 896                      }
 897                  }
 898  
 899                  foreach(array('canview','canpostthreads','canpostreplys','canpostpolls') as $name)
 900                  {
 901                      if(in_array($name, $permission)  || $permission[$name])
 902                      {
 903                          $permissions[$name][$gid] = 1;
 904                      }
 905                      else
 906                      {
 907                          $permissions[$name][$gid] = 0;
 908                      }
 909                  }
 910              }
 911  
 912              $canview = $permissions['canview'];
 913              $canpostthreads = $permissions['canpostthreads'];
 914              $canpostpolls = $permissions['canpostpolls'];
 915              $canpostattachments = $permissions['canpostattachments'];
 916              $canpostreplies = $permissions['canpostreplys'];
 917              save_quick_perms($fid);
 918  
 919              $plugins->run_hooks("admin_forum_management_add_commit");
 920  
 921              $cache->update_forums();
 922  
 923              // Log admin action
 924              log_admin_action($fid, $insert_array['name']);
 925  
 926              flash_message($lang->success_forum_added, 'success');
 927              admin_redirect("index.php?module=forum-management");
 928          }
 929      }
 930  
 931      $page->extra_header .=  "<script src=\"jscripts/quick_perm_editor.js\" type=\"text/javascript\"></script>\n";
 932  
 933      $page->add_breadcrumb_item($lang->add_forum);
 934      $page->output_header($lang->add_forum);
 935      $page->output_nav_tabs($sub_tabs, 'add_forum');
 936  
 937      $form = new Form("index.php?module=forum-management&amp;action=add", "post");
 938  
 939      if($errors)
 940      {
 941          $page->output_inline_error($errors);
 942          $forum_data = $mybb->input;
 943      }
 944      else
 945      {
 946          $forum_data['type'] = "f";
 947          $forum_data['title'] = "";
 948          $forum_data['description'] = "";
 949  
 950          if(!$mybb->input['pid'])
 951          {
 952              $forum_data['pid'] = "-1";
 953          }
 954          else
 955          {
 956              $forum_data['pid'] = $mybb->get_input('pid', MyBB::INPUT_INT);
 957          }
 958          $forum_data['disporder'] = "1";
 959          $forum_data['linkto'] = "";
 960          $forum_data['password'] = "";
 961          $forum_data['active'] = 1;
 962          $forum_data['open'] = 1;
 963          $forum_data['overridestyle'] = "";
 964          $forum_data['style'] = "";
 965          $forum_data['rulestype'] = "";
 966          $forum_data['rulestitle'] = "";
 967          $forum_data['rules'] = "";
 968          $forum_data['defaultdatecut'] = "";
 969          $forum_data['defaultsortby'] = "";
 970          $forum_data['defaultsortorder'] = "";
 971          $forum_data['allowhtml'] = "";
 972          $forum_data['allowmycode'] = 1;
 973          $forum_data['allowsmilies'] = 1;
 974          $forum_data['allowimgcode'] = 1;
 975          $forum_data['allowvideocode'] = 1;
 976          $forum_data['allowpicons'] = 1;
 977          $forum_data['allowtratings'] = 1;
 978          $forum_data['showinjump'] = 1;
 979          $forum_data['usepostcounts'] = 1;
 980          $forum_data['usethreadcounts'] = 1;
 981          $forum_data['requireprefix'] = 0;
 982      }
 983  
 984      $types = array(
 985          'f' => $lang->forum,
 986          'c' => $lang->category
 987      );
 988  
 989      $create_a_options_f = array(
 990          'id' => 'forum'
 991      );
 992  
 993      $create_a_options_c = array(
 994          'id' => 'category'
 995      );
 996  
 997      if($forum_data['type'] == "f")
 998      {
 999          $create_a_options_f['checked'] = true;
1000      }
1001      else
1002      {
1003          $create_a_options_c['checked'] = true;
1004      }
1005  
1006      $form_container = new FormContainer($lang->add_forum);
1007      $form_container->output_row($lang->forum_type, $lang->forum_type_desc, $form->generate_radio_button('type', 'f', $lang->forum, $create_a_options_f)."<br />\n".$form->generate_radio_button('type', 'c', $lang->category, $create_a_options_c));
1008      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $forum_data['title'], array('id' => 'title')), 'title');
1009      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $forum_data['description'], array('id' => 'description')), 'description');
1010      $form_container->output_row($lang->parent_forum." <em>*</em>", $lang->parent_forum_desc, $form->generate_forum_select('pid', $forum_data['pid'], array('id' => 'pid', 'main_option' => $lang->none)), 'pid');
1011      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $forum_data['disporder'], array('id' => 'disporder', 'min' => 0)), 'disporder');
1012      $form_container->end();
1013  
1014      echo "<div id=\"additional_options_link\"><strong><a href=\"#\" onclick=\"$('#additional_options_link').toggle(); $('#additional_options').fadeToggle('fast'); return false;\">{$lang->show_additional_options}</a></strong><br /><br /></div>";
1015      echo "<div id=\"additional_options\" style=\"display: none;\">";
1016      $form_container = new FormContainer("<div class=\"float_right\" style=\"font-weight: normal;\"><a href=\"#\" onclick=\"$('#additional_options_link').toggle(); $('#additional_options').fadeToggle('fast'); return false;\">{$lang->hide_additional_options}</a></div>".$lang->additional_forum_options);
1017      $form_container->output_row($lang->forum_link, $lang->forum_link_desc, $form->generate_text_box('linkto', $forum_data['linkto'], array('id' => 'linkto')), 'linkto');
1018      $form_container->output_row($lang->forum_password, $lang->forum_password_desc, $form->generate_text_box('password', $forum_data['password'], array('id' => 'password')), 'password');
1019  
1020      $access_options = array(
1021          $form->generate_check_box('active', 1, $lang->forum_is_active."<br />\n<small>{$lang->forum_is_active_desc}</small>", array('checked' => $forum_data['active'], 'id' => 'active')),
1022          $form->generate_check_box('open', 1, $lang->forum_is_open."<br />\n<small>{$lang->forum_is_open_desc}</small>", array('checked' => $forum_data['open'], 'id' => 'open'))
1023      );
1024  
1025      $form_container->output_row($lang->access_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $access_options)."</div>");
1026  
1027      $styles = array(
1028          '0' => $lang->use_default
1029      );
1030  
1031      $query = $db->simple_select("themes", "tid,name", "name!='((master))' AND name!='((master-backup))'", array('order_by' => 'name'));
1032      while($style = $db->fetch_array($query))
1033      {
1034          $styles[$style['tid']] = htmlspecialchars_uni($style['name']);
1035      }
1036  
1037      $style_options = array(
1038          $form->generate_check_box('overridestyle', 1, $lang->override_user_style, array('checked' => $forum_data['overridestyle'], 'id' => 'overridestyle')),
1039          $lang->forum_specific_style."<br />\n".$form->generate_select_box('style', $styles, $forum_data['style'], array('id' => 'style'))
1040      );
1041  
1042      $form_container->output_row($lang->style_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $style_options)."</div>");
1043  
1044      $display_methods = array(
1045          '0' => $lang->dont_display_rules,
1046          '1' => $lang->display_rules_inline,
1047          '3' => $lang->display_rules_inline_new,
1048          '2' => $lang->display_rules_link
1049      );
1050  
1051      $forum_rules = array(
1052          $lang->display_method."<br />\n".$form->generate_select_box('rulestype', $display_methods, $forum_data['rulestype'], array('checked' => $forum_data['rulestype'], 'id' => 'rulestype')),
1053          $lang->title."<br />\n".$form->generate_text_box('rulestitle', $forum_data['rulestitle'], array('checked' => $forum_data['rulestitle'], 'id' => 'rulestitle')),
1054          $lang->rules."<br />\n".$form->generate_text_area('rules', $forum_data['rules'], array('checked' => $forum_data['rules'], 'id' => 'rules'))
1055      );
1056  
1057      $form_container->output_row($lang->forum_rules, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $forum_rules)."</div>");
1058  
1059      $default_date_cut = array(
1060          0 => $lang->board_default,
1061          1 => $lang->datelimit_1day,
1062          5 => $lang->datelimit_5days,
1063          10 => $lang->datelimit_10days,
1064          20 => $lang->datelimit_20days,
1065          50 => $lang->datelimit_50days,
1066          75 => $lang->datelimit_75days,
1067          100 => $lang->datelimit_100days,
1068          365 => $lang->datelimit_lastyear,
1069          9999 => $lang->datelimit_beginning,
1070      );
1071  
1072      $default_sort_by = array(
1073          "" => $lang->board_default,
1074          "subject" => $lang->sort_by_subject,
1075          "lastpost" => $lang->sort_by_lastpost,
1076          "starter" => $lang->sort_by_starter,
1077          "started" => $lang->sort_by_started,
1078          "rating" => $lang->sort_by_rating,
1079          "replies" => $lang->sort_by_replies,
1080          "views" => $lang->sort_by_views,
1081      );
1082  
1083      $default_sort_order = array(
1084          "" => $lang->board_default,
1085          "asc" => $lang->sort_order_asc,
1086          "desc" => $lang->sort_order_desc,
1087      );
1088  
1089      $view_options = array(
1090          $lang->default_date_cut."<br />\n".$form->generate_select_box('defaultdatecut', $default_date_cut, $forum_data['defaultdatecut'], array('checked' => $forum_data['defaultdatecut'], 'id' => 'defaultdatecut')),
1091          $lang->default_sort_by."<br />\n".$form->generate_select_box('defaultsortby', $default_sort_by, $forum_data['defaultsortby'], array('checked' => $forum_data['defaultsortby'], 'id' => 'defaultsortby')),
1092          $lang->default_sort_order."<br />\n".$form->generate_select_box('defaultsortorder', $default_sort_order, $forum_data['defaultsortorder'], array('checked' => $forum_data['defaultsortorder'], 'id' => 'defaultsortorder')),
1093      );
1094  
1095      $form_container->output_row($lang->default_view_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $view_options)."</div>");
1096  
1097      $misc_options = array(
1098          $form->generate_check_box('allowhtml', 1, $lang->allow_html, array('checked' => $forum_data['allowhtml'], 'id' => 'allowhtml')),
1099          $form->generate_check_box('allowmycode', 1, $lang->allow_mycode, array('checked' => $forum_data['allowmycode'], 'id' => 'allowmycode')),
1100          $form->generate_check_box('allowsmilies', 1, $lang->allow_smilies, array('checked' => $forum_data['allowsmilies'], 'id' => 'allowsmilies')),
1101          $form->generate_check_box('allowimgcode', 1, $lang->allow_img_code, array('checked' => $forum_data['allowimgcode'], 'id' => 'allowimgcode')),
1102          $form->generate_check_box('allowvideocode', 1, $lang->allow_video_code, array('checked' => $forum_data['allowvideocode'], 'id' => 'allowvideocode')),
1103          $form->generate_check_box('allowpicons', 1, $lang->allow_post_icons, array('checked' => $forum_data['allowpicons'], 'id' => 'allowpicons')),
1104          $form->generate_check_box('allowtratings', 1, $lang->allow_thread_ratings, array('checked' => $forum_data['allowtratings'], 'id' => 'allowtratings')),
1105          $form->generate_check_box('showinjump', 1, $lang->show_forum_jump, array('checked' => $forum_data['showinjump'], 'id' => 'showinjump')),
1106          $form->generate_check_box('usepostcounts', 1, $lang->use_postcounts, array('checked' => $forum_data['usepostcounts'], 'id' => 'usepostcounts')),
1107          $form->generate_check_box('usethreadcounts', 1, $lang->use_threadcounts, array('checked' => $forum_data['usethreadcounts'], 'id' => 'usethreadcounts')),
1108          $form->generate_check_box('requireprefix', 1, $lang->require_thread_prefix, array('checked' => $forum_data['requireprefix'], 'id' => 'requireprefix'))
1109      );
1110  
1111      $form_container->output_row($lang->misc_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $misc_options)."</div>");
1112      $form_container->end();
1113      echo "</div>";
1114  
1115      $query = $db->simple_select("usergroups", "*", "", array("order" => "name"));
1116      while($usergroup = $db->fetch_array($query))
1117      {
1118          $usergroups[$usergroup['gid']] = $usergroup;
1119      }
1120  
1121      $cached_forum_perms = $cache->read("forumpermissions");
1122      $field_list = array(
1123          'canview' => $lang->permissions_canview,
1124          'canpostthreads' => $lang->permissions_canpostthreads,
1125          'canpostreplys' => $lang->permissions_canpostreplys,
1126          'canpostpolls' => $lang->permissions_canpostpolls,
1127      );
1128  
1129      $field_list2 = array(
1130          'canview' => $lang->perm_drag_canview,
1131          'canpostthreads' => $lang->perm_drag_canpostthreads,
1132          'canpostreplys' => $lang->perm_drag_canpostreplys,
1133          'canpostpolls' => $lang->perm_drag_canpostpolls,
1134      );
1135  
1136      $ids = array();
1137  
1138      $form_container = new FormContainer($lang->forum_permissions);
1139      $form_container->output_row_header($lang->permissions_group, array("class" => "align_center", 'style' => 'width: 40%'));
1140      $form_container->output_row_header($lang->overview_allowed_actions, array("class" => "align_center"));
1141      $form_container->output_row_header($lang->overview_disallowed_actions, array("class" => "align_center"));
1142  
1143      if($mybb->request_method == "post")
1144      {
1145          foreach($usergroups as $usergroup)
1146          {
1147              if(isset($mybb->input['fields_'.$usergroup['gid']]))
1148              {
1149                  $input_permissions = $mybb->input['fields_'.$usergroup['gid']];
1150                  if(!is_array($input_permissions))
1151                  {
1152                      // Convering the comma separated list from Javascript form into a variable
1153                      $input_permissions = explode(',' , $input_permissions);
1154                  }
1155                  foreach($input_permissions as $input_permission)
1156                  {
1157                      $mybb->input['permissions'][$usergroup['gid']][$input_permission] = 1;
1158                  }
1159              }
1160          }
1161      }
1162  
1163      foreach($usergroups as $usergroup)
1164      {
1165          $perms = array();
1166          if(isset($mybb->input['default_permissions']) && $mybb->input['default_permissions'][$usergroup['gid']])
1167          {
1168              if(is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
1169              {
1170                  $perms = $existing_permissions[$usergroup['gid']];
1171                  $default_checked = false;
1172              }
1173              elseif(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['fid']][$usergroup['gid']])
1174              {
1175                  $perms = $cached_forum_perms[$forum_data['fid']][$usergroup['gid']];
1176                  $default_checked = true;
1177              }
1178              else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['pid']][$usergroup['gid']])
1179              {
1180                  $perms = $cached_forum_perms[$forum_data['pid']][$usergroup['gid']];
1181                  $default_checked = true;
1182              }
1183          }
1184  
1185          if(!$perms)
1186          {
1187              $perms = $usergroup;
1188              $default_checked = true;
1189          }
1190  
1191          foreach($field_list as $forum_permission => $forum_perm_title)
1192          {
1193              if(isset($mybb->input['permissions']))
1194              {
1195                  if($mybb->input['default_permissions'][$usergroup['gid']])
1196                  {
1197                      $default_checked = true;
1198                  }
1199                  else
1200                  {
1201                      $default_checked = false;
1202                  }
1203  
1204                  if($mybb->input['permissions'][$usergroup['gid']][$forum_permission])
1205                  {
1206                      $perms_checked[$forum_permission] = 1;
1207                  }
1208                  else
1209                  {
1210                      $perms_checked[$forum_permission] = 0;
1211                  }
1212              }
1213              else
1214              {
1215                  if($perms[$forum_permission] == 1)
1216                  {
1217                      $perms_checked[$forum_permission] = 1;
1218                  }
1219                  else
1220                  {
1221                      $perms_checked[$forum_permission] = 0;
1222                  }
1223              }
1224          }
1225          $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
1226  
1227          if($default_checked)
1228          {
1229              $inherited_text = $lang->inherited_permission;
1230          }
1231          else
1232          {
1233              $inherited_text = $lang->custom_permission;
1234          }
1235  
1236          $form_container->output_cell("<strong>{$usergroup['title']}</strong><br />".$form->generate_check_box("default_permissions[{$usergroup['gid']}]", 1, "", array("id" => "default_permissions_{$usergroup['gid']}", "checked" => $default_checked, "onclick" => $default_click))." <small><label for=\"default_permissions_{$usergroup['gid']}\">{$lang->permissions_use_group_default}</label></small>");
1237  
1238          $field_select = "<div class=\"quick_perm_fields\">\n";
1239          $field_select .= "<div class=\"enabled\"><ul id=\"fields_enabled_{$usergroup['gid']}\">\n";
1240          foreach($perms_checked as $perm => $value)
1241          {
1242              if($value == 1)
1243              {
1244                  $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
1245              }
1246          }
1247          $field_select .= "</ul></div>\n";
1248          $field_select .= "<div class=\"disabled\"><ul id=\"fields_disabled_{$usergroup['gid']}\">\n";
1249          foreach($perms_checked as $perm => $value)
1250          {
1251              if($value == 0)
1252              {
1253                  $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
1254              }
1255          }
1256          $field_select .= "</ul></div></div>\n";
1257          $field_select .= $form->generate_hidden_field("fields_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, '1')), array('id' => 'fields_'.$usergroup['gid']));
1258          $field_select = str_replace("'", "\\'", $field_select);
1259          $field_select = str_replace("\n", "", $field_select);
1260  
1261          $field_select = "<script type=\"text/javascript\">
1262  //<![CDATA[
1263  document.write('".str_replace("/", "\/", $field_select)."');
1264  //]]>
1265  </script>\n";
1266  
1267          $field_selected = array();
1268          foreach($field_list as $forum_permission => $permission_title)
1269          {
1270              $field_options[$forum_permission] = $permission_title;
1271              if($perms_checked[$forum_permission])
1272              {
1273                  $field_selected[] = $forum_permission;
1274              }
1275          }
1276  
1277          $field_select .= "<noscript>".$form->generate_select_box('fields_'.$usergroup['gid'].'[]', $field_options, $field_selected, array('id' => 'fields_'.$usergroup['gid'].'[]', 'multiple' => true))."</noscript>\n";
1278          $form_container->output_cell($field_select, array('colspan' => 2));
1279  
1280          $form_container->construct_row();
1281  
1282          $ids[] = $usergroup['gid'];
1283      }
1284      $form_container->end();
1285  
1286      $buttons[] = $form->generate_submit_button($lang->save_forum);
1287      $form->output_submit_wrapper($buttons);
1288      $form->end();
1289  
1290      // Write in our JS based field selector
1291      echo "<script type=\"text/javascript\">\n<!--\n";
1292      foreach($ids as $id)
1293      {
1294          echo "$(function() { QuickPermEditor.init(".$id.") });\n";
1295      }
1296      echo "// -->\n</script>\n";
1297  
1298      $page->output_footer();
1299  }
1300  
1301  if($mybb->input['action'] == "edit")
1302  {
1303      if(!$mybb->input['fid'])
1304      {
1305          flash_message($lang->error_invalid_fid, 'error');
1306          admin_redirect("index.php?module=forum-management");
1307      }
1308  
1309      $query = $db->simple_select("forums", "*", "fid='{$mybb->input['fid']}'");
1310      $forum_data = $db->fetch_array($query);
1311      if(!$forum_data)
1312      {
1313          flash_message($lang->error_invalid_fid, 'error');
1314          admin_redirect("index.php?module=forum-management");
1315      }
1316  
1317      $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
1318  
1319      $plugins->run_hooks("admin_forum_management_edit");
1320  
1321      if($mybb->request_method == "post")
1322      {
1323          if(!trim($mybb->input['title']))
1324          {
1325              $errors[] = $lang->error_missing_title;
1326          }
1327  
1328          $pid = $mybb->get_input('pid', MyBB::INPUT_INT);
1329  
1330          if($pid == $mybb->input['fid'])
1331          {
1332              $errors[] = $lang->error_forum_parent_itself;
1333          }
1334          else
1335          {
1336              $query = $db->simple_select('forums', 'parentlist', "fid='{$pid}'");
1337              $parents = explode(',', $db->fetch_field($query, 'parentlist'));
1338              if(in_array($mybb->input['fid'], $parents))
1339              {
1340                  $errors[] = $lang->error_forum_parent_child;
1341              }
1342          }
1343  
1344          $type = $mybb->input['type'];
1345  
1346          if($pid <= 0 && $type == "f")
1347          {
1348              $errors[] = $lang->error_no_parent;
1349          }
1350  
1351          if($type == 'c' && $forum_data['type'] == 'f')
1352          {
1353              $query = $db->simple_select('threads', 'COUNT(tid) as num_threads', "fid = '{$fid}'");
1354              if($db->fetch_field($query, "num_threads") > 0)
1355              {
1356                  $errors[] = $lang->error_not_empty;
1357              }
1358          }
1359  
1360          if(!empty($mybb->input['linkto']) && empty($forum_data['linkto']))
1361          {
1362              $query = $db->simple_select('threads', 'COUNT(tid) as num_threads', "fid = '{$fid}'", array("limit" => 1));
1363              if($db->fetch_field($query, "num_threads") > 0)
1364              {
1365                  $errors[] = $lang->error_forum_link_not_empty;
1366              }
1367          }
1368  
1369          if(!$errors)
1370          {
1371              if($pid < 0)
1372              {
1373                  $pid = 0;
1374              }
1375              $update_array = array(
1376                  "name" => $db->escape_string($mybb->input['title']),
1377                  "description" => $db->escape_string($mybb->input['description']),
1378                  "linkto" => $db->escape_string($mybb->input['linkto']),
1379                  "type" => $db->escape_string($type),
1380                  "pid" => $pid,
1381                  "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT),
1382                  "active" => $mybb->get_input('active', MyBB::INPUT_INT),
1383                  "open" => $mybb->get_input('open', MyBB::INPUT_INT),
1384                  "allowhtml" => $mybb->get_input('allowhtml', MyBB::INPUT_INT),
1385                  "allowmycode" => $mybb->get_input('allowmycode', MyBB::INPUT_INT),
1386                  "allowsmilies" => $mybb->get_input('allowsmilies', MyBB::INPUT_INT),
1387                  "allowimgcode" => $mybb->get_input('allowimgcode', MyBB::INPUT_INT),
1388                  "allowvideocode" => $mybb->get_input('allowvideocode', MyBB::INPUT_INT),
1389                  "allowpicons" => $mybb->get_input('allowpicons', MyBB::INPUT_INT),
1390                  "allowtratings" => $mybb->get_input('allowtratings', MyBB::INPUT_INT),
1391                  "usepostcounts" => $mybb->get_input('usepostcounts', MyBB::INPUT_INT),
1392                  "usethreadcounts" => $mybb->get_input('usethreadcounts', MyBB::INPUT_INT),
1393                  "requireprefix" => $mybb->get_input('requireprefix', MyBB::INPUT_INT),
1394                  "password" => $db->escape_string($mybb->input['password']),
1395                  "showinjump" => $mybb->get_input('showinjump', MyBB::INPUT_INT),
1396                  "style" => $mybb->get_input('style', MyBB::INPUT_INT),
1397                  "overridestyle" => $mybb->get_input('overridestyle', MyBB::INPUT_INT),
1398                  "rulestype" => $mybb->get_input('rulestype', MyBB::INPUT_INT),
1399                  "rulestitle" => $db->escape_string($mybb->input['rulestitle']),
1400                  "rules" => $db->escape_string($mybb->input['rules']),
1401                  "defaultdatecut" => $mybb->get_input('defaultdatecut', MyBB::INPUT_INT),
1402                  "defaultsortby" => $db->escape_string($mybb->input['defaultsortby']),
1403                  "defaultsortorder" => $db->escape_string($mybb->input['defaultsortorder']),
1404              );
1405              $db->update_query("forums", $update_array, "fid='{$fid}'");
1406              if($pid != $forum_data['pid'])
1407              {
1408                  // Update the parentlist of this forum.
1409                  $db->update_query("forums", array("parentlist" => make_parent_list($fid)), "fid='{$fid}'");
1410  
1411                  // Rebuild the parentlist of all of the subforums of this forum
1412                  switch($db->type)
1413                  {
1414                      case "sqlite":
1415                      case "pgsql":
1416                          $query = $db->simple_select("forums", "fid", "','||parentlist||',' LIKE '%,$fid,%'");
1417                          break;
1418                      default:
1419                          $query = $db->simple_select("forums", "fid", "CONCAT(',',parentlist,',') LIKE '%,$fid,%'");
1420                  }
1421  
1422                  while($child = $db->fetch_array($query))
1423                  {
1424                      $db->update_query("forums", array("parentlist" => make_parent_list($child['fid'])), "fid='{$child['fid']}'");
1425                  }
1426              }
1427  
1428              $inherit = $mybb->input['default_permissions'];
1429  
1430              foreach($mybb->input as $id => $permission)
1431              {
1432                  // Make sure we're only skipping inputs that don't start with "fields_" and aren't fields_default_ or fields_inherit_
1433                  if(strpos($id, 'fields_') === false || (strpos($id, 'fields_default_') !== false || strpos($id, 'fields_inherit_') !== false))
1434                  {
1435                      continue;
1436                  }
1437  
1438                  list(, $gid) = explode('fields_', $id);
1439  
1440                  if($mybb->input['fields_default_'.$gid] == $permission && $mybb->input['fields_inherit_'.$gid] == 1)
1441                  {
1442                      $inherit[$gid] = 1;
1443                      continue;
1444                  }
1445                  $inherit[$gid] = 0;
1446  
1447                  // If it isn't an array then it came from the javascript form
1448                  if(!is_array($permission))
1449                  {
1450                      $permission = explode(',', $permission);
1451                      $permission = array_flip($permission);
1452                      foreach($permission as $name => $value)
1453                      {
1454                          $permission[$name] = 1;
1455                      }
1456                  }
1457  
1458                  foreach(array('canview','canpostthreads','canpostreplys','canpostpolls') as $name)
1459                  {
1460                      if(in_array($name, $permission) || $permission[$name])
1461                      {
1462                          $permissions[$name][$gid] = 1;
1463                      }
1464                      else
1465                      {
1466                          $permissions[$name][$gid] = 0;
1467                      }
1468                  }
1469              }
1470  
1471              $cache->update_forums();
1472  
1473              $canview = $permissions['canview'];
1474              $canpostthreads = $permissions['canpostthreads'];
1475              $canpostpolls = $permissions['canpostpolls'];
1476              $canpostattachments = $permissions['canpostattachments'];
1477              $canpostreplies = $permissions['canpostreplys'];
1478  
1479              save_quick_perms($fid);
1480  
1481              $plugins->run_hooks("admin_forum_management_edit_commit");
1482  
1483              // Log admin action
1484              log_admin_action($fid, $mybb->input['title']);
1485  
1486              flash_message($lang->success_forum_updated, 'success');
1487              admin_redirect("index.php?module=forum-management&fid={$fid}");
1488          }
1489      }
1490  
1491      $page->extra_header .=  "<script src=\"jscripts/quick_perm_editor.js\" type=\"text/javascript\"></script>\n";
1492  
1493      $page->add_breadcrumb_item($lang->edit_forum);
1494      $page->output_header($lang->edit_forum);
1495  
1496      $page->output_nav_tabs($sub_tabs, 'edit_forum_settings');
1497  
1498      $form = new Form("index.php?module=forum-management&amp;action=edit", "post");
1499      echo $form->generate_hidden_field("fid", $fid);
1500  
1501      if($errors)
1502      {
1503          $page->output_inline_error($errors);
1504          $forum_data = $mybb->input;
1505      }
1506      else
1507      {
1508          $forum_data['title'] = $forum_data['name'];
1509      }
1510  
1511      $query = $db->simple_select("usergroups", "*", "", array("order_dir" => "name"));
1512      while($usergroup = $db->fetch_array($query))
1513      {
1514          $usergroups[$usergroup['gid']] = $usergroup;
1515      }
1516  
1517      $query = $db->simple_select("forumpermissions", "*", "fid='{$fid}'");
1518      while($existing = $db->fetch_array($query))
1519      {
1520          $existing_permissions[$existing['gid']] = $existing;
1521      }
1522  
1523      $types = array(
1524          'f' => $lang->forum,
1525          'c' => $lang->category
1526      );
1527  
1528      $create_a_options_f = array(
1529          'id' => 'forum'
1530      );
1531  
1532      $create_a_options_c = array(
1533          'id' => 'category'
1534      );
1535  
1536      if($forum_data['type'] == "f")
1537      {
1538          $create_a_options_f['checked'] = true;
1539      }
1540      else
1541      {
1542          $create_a_options_c['checked'] = true;
1543      }
1544  
1545      $form_container = new FormContainer($lang->edit_forum);
1546      $form_container->output_row($lang->forum_type, $lang->forum_type_desc, $form->generate_radio_button('type', 'f', $lang->forum, $create_a_options_f)."<br />\n".$form->generate_radio_button('type', 'c', $lang->category, $create_a_options_c));
1547      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $forum_data['title'], array('id' => 'title')), 'title');
1548      $form_container->output_row($lang->description, "", $form->generate_text_area('description', $forum_data['description'], array('id' => 'description')), 'description');
1549      $form_container->output_row($lang->parent_forum." <em>*</em>", $lang->parent_forum_desc, $form->generate_forum_select('pid', $forum_data['pid'], array('id' => 'pid', 'main_option' => $lang->none)), 'pid');
1550      $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $forum_data['disporder'], array('id' => 'disporder', 'min' => 0)), 'disporder');
1551      $form_container->end();
1552  
1553      $form_container = new FormContainer($lang->additional_forum_options);
1554      $form_container->output_row($lang->forum_link, $lang->forum_link_desc, $form->generate_text_box('linkto', $forum_data['linkto'], array('id' => 'linkto')), 'linkto');
1555      $form_container->output_row($lang->forum_password, $lang->forum_password_desc, $form->generate_text_box('password', $forum_data['password'], array('id' => 'password')), 'password');
1556  
1557      $access_options = array(
1558          $form->generate_check_box('active', 1, $lang->forum_is_active."<br />\n<small>{$lang->forum_is_active_desc}</small>", array('checked' => $forum_data['active'], 'id' => 'active')),
1559          $form->generate_check_box('open', 1, $lang->forum_is_open."<br />\n<small>{$lang->forum_is_open_desc}</small>", array('checked' => $forum_data['open'], 'id' => 'open'))
1560      );
1561  
1562      $form_container->output_row($lang->access_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $access_options)."</div>");
1563  
1564      $styles = array(
1565          '0' => $lang->use_default
1566      );
1567  
1568      $query = $db->simple_select("themes", "tid,name", "name!='((master))' AND name!='((master-backup))'", array('order_by' => 'name'));
1569      while($style = $db->fetch_array($query))
1570      {
1571          $styles[$style['tid']] = $style['name'];
1572      }
1573  
1574      $style_options = array(
1575          $form->generate_check_box('overridestyle', 1, $lang->override_user_style, array('checked' => $forum_data['overridestyle'], 'id' => 'overridestyle')),
1576          $lang->forum_specific_style."<br />\n".$form->generate_select_box('style', $styles, $forum_data['style'], array('id' => 'style'))
1577      );
1578  
1579      $form_container->output_row($lang->style_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $style_options)."</div>");
1580  
1581      $display_methods = array(
1582          '0' => $lang->dont_display_rules,
1583          '1' => $lang->display_rules_inline,
1584          '3' => $lang->display_rules_inline_new,
1585          '2' => $lang->display_rules_link
1586      );
1587  
1588      $forum_rules = array(
1589          $lang->display_method."<br />\n".$form->generate_select_box('rulestype', $display_methods, $forum_data['rulestype'], array('checked' => $forum_data['rulestype'], 'id' => 'rulestype')),
1590          $lang->title."<br />\n".$form->generate_text_box('rulestitle', $forum_data['rulestitle'], array('checked' => $forum_data['rulestitle'], 'id' => 'rulestitle')),
1591          $lang->rules."<br />\n".$form->generate_text_area('rules', $forum_data['rules'], array('checked' => $forum_data['rules'], 'id' => 'rules'))
1592      );
1593  
1594      $form_container->output_row($lang->forum_rules, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $forum_rules)."</div>");
1595  
1596      $default_date_cut = array(
1597          0 => $lang->board_default,
1598          1 => $lang->datelimit_1day,
1599          5 => $lang->datelimit_5days,
1600          10 => $lang->datelimit_10days,
1601          20 => $lang->datelimit_20days,
1602          50 => $lang->datelimit_50days,
1603          75 => $lang->datelimit_75days,
1604          100 => $lang->datelimit_100days,
1605          365 => $lang->datelimit_lastyear,
1606          9999 => $lang->datelimit_beginning,
1607      );
1608  
1609      $default_sort_by = array(
1610          "" => $lang->board_default,
1611          "subject" => $lang->sort_by_subject,
1612          "lastpost" => $lang->sort_by_lastpost,
1613          "starter" => $lang->sort_by_starter,
1614          "started" => $lang->sort_by_started,
1615          "rating" => $lang->sort_by_rating,
1616          "replies" => $lang->sort_by_replies,
1617          "views" => $lang->sort_by_views,
1618      );
1619  
1620      $default_sort_order = array(
1621          "" => $lang->board_default,
1622          "asc" => $lang->sort_order_asc,
1623          "desc" => $lang->sort_order_desc,
1624      );
1625  
1626      $view_options = array(
1627          $lang->default_date_cut."<br />\n".$form->generate_select_box('defaultdatecut', $default_date_cut, $forum_data['defaultdatecut'], array('checked' => $forum_data['defaultdatecut'], 'id' => 'defaultdatecut')),
1628          $lang->default_sort_by."<br />\n".$form->generate_select_box('defaultsortby', $default_sort_by, $forum_data['defaultsortby'], array('checked' => $forum_data['defaultsortby'], 'id' => 'defaultsortby')),
1629          $lang->default_sort_order."<br />\n".$form->generate_select_box('defaultsortorder', $default_sort_order, $forum_data['defaultsortorder'], array('checked' => $forum_data['defaultsortorder'], 'id' => 'defaultsortorder')),
1630      );
1631  
1632      $form_container->output_row($lang->default_view_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $view_options)."</div>");
1633  
1634      $misc_options = array(
1635          $form->generate_check_box('allowhtml', 1, $lang->allow_html, array('checked' => $forum_data['allowhtml'], 'id' => 'allowhtml')),
1636          $form->generate_check_box('allowmycode', 1, $lang->allow_mycode, array('checked' => $forum_data['allowmycode'], 'id' => 'allowmycode')),
1637          $form->generate_check_box('allowsmilies', 1, $lang->allow_smilies, array('checked' => $forum_data['allowsmilies'], 'id' => 'allowsmilies')),
1638          $form->generate_check_box('allowimgcode', 1, $lang->allow_img_code, array('checked' => $forum_data['allowimgcode'], 'id' => 'allowimgcode')),
1639          $form->generate_check_box('allowvideocode', 1, $lang->allow_video_code, array('checked' => $forum_data['allowvideocode'], 'id' => 'allowvideocode')),
1640          $form->generate_check_box('allowpicons', 1, $lang->allow_post_icons, array('checked' => $forum_data['allowpicons'], 'id' => 'allowpicons')),
1641          $form->generate_check_box('allowtratings', 1, $lang->allow_thread_ratings, array('checked' => $forum_data['allowtratings'], 'id' => 'allowtratings')),
1642          $form->generate_check_box('showinjump', 1, $lang->show_forum_jump, array('checked' => $forum_data['showinjump'], 'id' => 'showinjump')),
1643          $form->generate_check_box('usepostcounts', 1, $lang->use_postcounts, array('checked' => $forum_data['usepostcounts'], 'id' => 'usepostcounts')),
1644          $form->generate_check_box('usethreadcounts', 1, $lang->use_threadcounts, array('checked' => $forum_data['usethreadcounts'], 'id' => 'usethreadcounts')),
1645          $form->generate_check_box('requireprefix', 1, $lang->require_thread_prefix, array('checked' => $forum_data['requireprefix'], 'id' => 'requireprefix'))
1646      );
1647  
1648      $form_container->output_row($lang->misc_options, "", "<div class=\"forum_settings_bit\">".implode("</div><div class=\"forum_settings_bit\">", $misc_options)."</div>");
1649      $form_container->end();
1650  
1651      $cached_forum_perms = $cache->read("forumpermissions");
1652      $field_list = array(
1653          'canview' => $lang->permissions_canview,
1654          'canpostthreads' => $lang->permissions_canpostthreads,
1655          'canpostreplys' => $lang->permissions_canpostreplys,
1656          'canpostpolls' => $lang->permissions_canpostpolls,
1657      );
1658  
1659      $field_list2 = array(
1660          'canview' => $lang->perm_drag_canview,
1661          'canpostthreads' => $lang->perm_drag_canpostthreads,
1662          'canpostreplys' => $lang->perm_drag_canpostreplys,
1663          'canpostpolls' => $lang->perm_drag_canpostpolls,
1664      );
1665  
1666      $ids = array();
1667  
1668      $form_container = new FormContainer($lang->sprintf($lang->forum_permissions_in, $forum_data['name']));
1669      $form_container->output_row_header($lang->permissions_group, array("class" => "align_center", 'style' => 'width: 30%'));
1670      $form_container->output_row_header($lang->overview_allowed_actions, array("class" => "align_center"));
1671      $form_container->output_row_header($lang->overview_disallowed_actions, array("class" => "align_center"));
1672      $form_container->output_row_header($lang->controls, array("class" => "align_center", 'style' => 'width: 120px', 'colspan' => 2));
1673  
1674      if($mybb->request_method == "post")
1675      {
1676          foreach($usergroups as $usergroup)
1677          {
1678              if(isset($mybb->input['fields_'.$usergroup['gid']]))
1679              {
1680                  $input_permissions = $mybb->input['fields_'.$usergroup['gid']];
1681                  if(!is_array($input_permissions))
1682                  {
1683                      // Convering the comma separated list from Javascript form into a variable
1684                      $input_permissions = explode(',' , $input_permissions);
1685                  }
1686                  foreach($input_permissions as $input_permission)
1687                  {
1688                      $mybb->input['permissions'][$usergroup['gid']][$input_permission] = 1;
1689                  }
1690              }
1691          }
1692      }
1693  
1694      foreach($usergroups as $usergroup)
1695      {
1696          $perms = array();
1697          if(isset($mybb->input['default_permissions']))
1698          {
1699              if($mybb->input['default_permissions'][$usergroup['gid']])
1700              {
1701                  if(is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
1702                  {
1703                      $perms = $existing_permissions[$usergroup['gid']];
1704                      $default_checked = false;
1705                  }
1706                  elseif(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['fid']][$usergroup['gid']])
1707                  {
1708                      $perms = $cached_forum_perms[$forum_data['fid']][$usergroup['gid']];
1709                      $default_checked = true;
1710                  }
1711                  else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['pid']][$usergroup['gid']])
1712                  {
1713                      $perms = $cached_forum_perms[$forum_data['pid']][$usergroup['gid']];
1714                      $default_checked = true;
1715                  }
1716              }
1717  
1718              if(!$perms)
1719              {
1720                  $perms = $usergroup;
1721                  $default_checked = true;
1722              }
1723          }
1724          else
1725          {
1726              if(is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
1727              {
1728                  $perms = $existing_permissions[$usergroup['gid']];
1729                  $default_checked = false;
1730              }
1731              elseif(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['fid']][$usergroup['gid']])
1732              {
1733                  $perms = $cached_forum_perms[$forum_data['fid']][$usergroup['gid']];
1734                  $default_checked = true;
1735              }
1736              else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['pid']][$usergroup['gid']])
1737              {
1738                  $perms = $cached_forum_perms[$forum_data['pid']][$usergroup['gid']];
1739                  $default_checked = true;
1740              }
1741  
1742              if(!$perms)
1743              {
1744                  $perms = $usergroup;
1745                  $default_checked = true;
1746              }
1747          }
1748  
1749          foreach($field_list as $forum_permission => $forum_perm_title)
1750          {
1751              if(isset($mybb->input['permissions']))
1752              {
1753                  if($mybb->input['permissions'][$usergroup['gid']][$forum_permission])
1754                  {
1755                      $perms_checked[$forum_permission] = 1;
1756                  }
1757                  else
1758                  {
1759                      $perms_checked[$forum_permission] = 0;
1760                  }
1761              }
1762              else
1763              {
1764                  if($perms[$forum_permission] == 1)
1765                  {
1766                      $perms_checked[$forum_permission] = 1;
1767                  }
1768                  else
1769                  {
1770                      $perms_checked[$forum_permission] = 0;
1771                  }
1772              }
1773          }
1774          $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
1775  
1776          if($default_checked)
1777          {
1778              $inherited_text = $lang->inherited_permission;
1779          }
1780          else
1781          {
1782              $inherited_text = $lang->custom_permission;
1783          }
1784  
1785          $form_container->output_cell("<strong>{$usergroup['title']}</strong> <small style=\"vertical-align: middle;\">({$inherited_text})</small>");
1786  
1787          $field_select = "<div class=\"quick_perm_fields\">\n";
1788          $field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled_{$usergroup['gid']}\">\n";
1789          foreach($perms_checked as $perm => $value)
1790          {
1791              if($value == 1)
1792              {
1793                  $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
1794              }
1795          }
1796          $field_select .= "</ul></div>\n";
1797          $field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled_{$usergroup['gid']}\">\n";
1798          foreach($perms_checked as $perm => $value)
1799          {
1800              if($value == 0)
1801              {
1802                  $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
1803              }
1804          }
1805          $field_select .= "</ul></div></div>\n";
1806          $field_select .= $form->generate_hidden_field("fields_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, '1')), array('id' => 'fields_'.$usergroup['gid']));
1807          $field_select .= $form->generate_hidden_field("fields_inherit_".$usergroup['gid'], (int)$default_checked, array('id' => 'fields_inherit_'.$usergroup['gid']));
1808          $field_select .= $form->generate_hidden_field("fields_default_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, '1')), array('id' => 'fields_default_'.$usergroup['gid']));
1809          $field_select = str_replace("'", "\\'", $field_select);
1810          $field_select = str_replace("\n", "", $field_select);
1811  
1812          $field_select = "<script type=\"text/javascript\">
1813  //<![CDATA[
1814  document.write('".str_replace("/", "\/", $field_select)."');
1815  //]]>
1816  </script>\n";
1817  
1818          $field_selected = array();
1819          foreach($field_list as $forum_permission => $permission_title)
1820          {
1821              $field_options[$forum_permission] = $permission_title;
1822              if($perms_checked[$forum_permission])
1823              {
1824                  $field_selected[] = $forum_permission;
1825              }
1826          }
1827  
1828          $field_select .= "<noscript>".$form->generate_select_box('fields_'.$usergroup['gid'].'[]', $field_options, $field_selected, array('id' => 'fields_'.$usergroup['gid'].'[]', 'multiple' => true))."</noscript>\n";
1829          $form_container->output_cell($field_select, array('colspan' => 2));
1830          
1831          if(!$default_checked)
1832          {
1833              $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;pid={$perms['pid']}\" onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&pid={$perms['pid']}&ajax=1', null, true); return false;\">{$lang->edit_permissions}</a>", array("class" => "align_center"));
1834              $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=clear_permission&amp;pid={$perms['pid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_clear_custom_permission}')\">{$lang->clear_custom_perms}</a>", array("class" => "align_center"));
1835          }
1836          else
1837          {
1838              $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;gid={$usergroup['gid']}&amp;fid={$fid}\" onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&gid={$usergroup['gid']}&fid={$fid}&ajax=1', null, true); return false;\">{$lang->set_custom_perms}</a>", array("class" => "align_center", "colspan" => 2));
1839          }
1840          
1841          $form_container->construct_row(array('id' => 'row_'.$usergroup['gid']));
1842  
1843          $ids[] = $usergroup['gid'];
1844      }
1845      $form_container->end();
1846  
1847      $buttons[] = $form->generate_submit_button($lang->save_forum);
1848      $form->output_submit_wrapper($buttons);
1849      $form->end();
1850  
1851      // Write in our JS based field selector
1852      echo "<script type=\"text/javascript\">\n<!--\n";
1853      foreach($ids as $id)
1854      {
1855          echo "$(function() { QuickPermEditor.init(".$id."); });\n";
1856      }
1857      echo "// -->\n</script>\n";
1858  
1859      $page->output_footer();
1860  }
1861  
1862  if($mybb->input['action'] == "deletemod")
1863  {
1864      $modid = $mybb->get_input('id', MyBB::INPUT_INT);
1865      $isgroup = $mybb->get_input('isgroup', MyBB::INPUT_INT);
1866      $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
1867  
1868      $query = $db->simple_select("moderators", "*", "id='{$modid}' AND isgroup = '{$isgroup}' AND fid='{$fid}'");
1869      $mod = $db->fetch_array($query);
1870  
1871      // Does the forum not exist?
1872      if(!$mod['mid'])
1873      {
1874          flash_message($lang->error_invalid_moderator, 'error');
1875          admin_redirect("index.php?module=forum-management&fid={$fid}");
1876      }
1877  
1878      // User clicked no
1879      if($mybb->input['no'])
1880      {
1881          admin_redirect("index.php?module=forum-management&fid={$fid}");
1882      }
1883  
1884      $plugins->run_hooks("admin_forum_management_deletemod");
1885  
1886      if($mybb->request_method == "post")
1887      {
1888          $mid = $mod['mid'];
1889          if($mybb->input['isgroup'])
1890          {
1891              $query = $db->query("
1892                  SELECT m.*, g.title
1893                  FROM ".TABLE_PREFIX."moderators m
1894                  LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=m.id)
1895                  WHERE m.mid='{$mid}'
1896              ");
1897          }
1898          else
1899          {
1900              $query = $db->query("
1901                  SELECT m.*, u.username, u.usergroup
1902                  FROM ".TABLE_PREFIX."moderators m
1903                  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=m.id)
1904                  WHERE m.mid='{$mid}'
1905              ");
1906          }
1907          $mod = $db->fetch_array($query);
1908  
1909          $db->delete_query("moderators", "mid='{$mid}'");
1910  
1911          $plugins->run_hooks("admin_forum_management_deletemod_commit");
1912  
1913          $cache->update_moderators();
1914  
1915          $forum = get_forum($fid);
1916  
1917          // Log admin action
1918          if($isgroup)
1919          {
1920              log_admin_action($mid, $mod['title'], $forum['fid'], $forum['name']);
1921          }
1922          else
1923          {
1924              log_admin_action($mid, $mod['username'], $forum['fid'], $forum['name']);
1925          }
1926  
1927          flash_message($lang->success_moderator_deleted, 'success');
1928          admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
1929      }
1930      else
1931      {
1932          $page->output_confirm_action("index.php?module=forum-management&amp;action=deletemod&amp;fid={$mod['fid']}&amp;uid={$mod['uid']}", $lang->confirm_moderator_deletion);
1933      }
1934  }
1935  
1936  if($mybb->input['action'] == "delete")
1937  {
1938      $query = $db->simple_select("forums", "*", "fid='{$mybb->input['fid']}'");
1939      $forum = $db->fetch_array($query);
1940  
1941      // Does the forum not exist?
1942      if(!$forum['fid'])
1943      {
1944          flash_message($lang->error_invalid_forum, 'error');
1945          admin_redirect("index.php?module=forum-management");
1946      }
1947  
1948      // User clicked no
1949      if($mybb->input['no'])
1950      {
1951          admin_redirect("index.php?module=forum-management");
1952      }
1953  
1954      $plugins->run_hooks("admin_forum_management_delete");
1955  
1956      if($mybb->request_method == "post")
1957      {
1958          $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
1959          $forum_info = get_forum($fid);
1960  
1961          $delquery = "";
1962          switch($db->type)
1963          {
1964              case "pgsql":
1965              case "sqlite":
1966                  $query = $db->simple_select("forums", "*", "','|| parentlist|| ',' LIKE '%,$fid,%'");
1967                  break;
1968              default:
1969                  $query = $db->simple_select("forums", "*", "CONCAT(',', parentlist, ',') LIKE '%,$fid,%'");
1970          }
1971          while($forum = $db->fetch_array($query))
1972          {
1973              $fids[$forum['fid']] = $fid;
1974              $delquery .= " OR fid='{$forum['fid']}'";
1975          }
1976  
1977          require_once  MYBB_ROOT.'inc/class_moderation.php';
1978          $moderation = new Moderation();
1979  
1980          // Start pagination. Limit results to 50
1981          $query = $db->simple_select("threads", "tid", "fid='{$fid}' {$delquery}", array("limit" => 50));
1982  
1983          while($tid = $db->fetch_field($query, 'tid'))
1984          {
1985              $moderation->delete_thread($tid);
1986          }
1987  
1988          // Check whether all threads have been deleted
1989          $query = $db->simple_select("threads", "tid", "fid='{$fid}' {$delquery}");
1990  
1991          if($db->num_rows($query) > 0)
1992          {
1993              $page->output_header();
1994  
1995              $form = new Form("index.php?module=forum-management", 'post');
1996  
1997              echo $form->generate_hidden_field("fid", $fid);
1998              echo $form->generate_hidden_field("action", "delete");
1999              output_auto_redirect($form, $lang->confirm_proceed_deletion);
2000  
2001              $form->end();
2002  
2003              $page->output_footer();
2004              exit;
2005          }
2006  
2007          // End pagination
2008  
2009          // Delete the forum
2010          $db->delete_query("forums", "fid='$fid'");
2011  
2012          // Delete subforums
2013          switch($db->type)
2014          {
2015              case "pgsql":
2016              case "sqlite":
2017                  $db->delete_query("forums", "','||parentlist||',' LIKE '%,$fid,%'");
2018                  break;
2019              default:
2020                  $db->delete_query("forums", "CONCAT(',',parentlist,',') LIKE '%,$fid,%'");
2021          }
2022  
2023          $db->delete_query('moderators', "fid='{$fid}' {$delquery}");
2024          $db->delete_query('forumsubscriptions', "fid='{$fid}' {$delquery}");
2025          $db->delete_query('forumpermissions', "fid='{$fid}' {$delquery}");
2026          $db->delete_query('announcements', "fid='{$fid}' {$delquery}");
2027          $db->delete_query('forumsread', "fid='{$fid}' {$delquery}");
2028  
2029          $plugins->run_hooks("admin_forum_management_delete_commit");
2030  
2031          $cache->update_forums();
2032          $cache->update_moderators();
2033          $cache->update_forumpermissions();
2034          $cache->update_forumsdisplay();
2035  
2036          // Log admin action
2037          log_admin_action($forum_info['fid'], $forum_info['name']);
2038  
2039          flash_message($lang->success_forum_deleted, 'success');
2040          admin_redirect("index.php?module=forum-management");
2041      }
2042      else
2043      {
2044          $page->output_confirm_action("index.php?module=forum-management&amp;action=delete&amp;fid={$forum['fid']}", $lang->confirm_forum_deletion);
2045      }
2046  }
2047  
2048  if(!$mybb->input['action'])
2049  {
2050      if(!isset($mybb->input['fid']))
2051      {
2052          $mybb->input['fid'] = 0;
2053      }
2054  
2055      $fid = $mybb->get_input('fid', MyBB::INPUT_INT);
2056      if($fid)
2057      {
2058          $forum = get_forum($fid);
2059      }
2060  
2061      $plugins->run_hooks("admin_forum_management_start");
2062  
2063      if($mybb->request_method == "post")
2064      {
2065          if($mybb->input['update'] == "permissions")
2066          {
2067              $inherit = array();
2068              foreach($mybb->input as $id => $permission)
2069              {
2070                  // Make sure we're only skipping inputs that don't start with "fields_" and aren't fields_default_ or fields_inherit_
2071                  if(strpos($id, 'fields_') === false || (strpos($id, 'fields_default_') !== false || strpos($id, 'fields_inherit_') !== false))
2072                  {
2073                      continue;
2074                  }
2075  
2076                  list(, $gid) = explode('fields_', $id);
2077  
2078                  if($mybb->input['fields_default_'.$gid] == $permission && $mybb->input['fields_inherit_'.$gid] == 1)
2079                  {
2080                      $inherit[$gid] = 1;
2081                      continue;
2082                  }
2083                  $inherit[$gid] = 0;
2084  
2085                  // If it isn't an array then it came from the javascript form
2086                  if(!is_array($permission))
2087                  {
2088                      $permission = explode(',', $permission);
2089                      $permission = array_flip($permission);
2090                      foreach($permission as $name => $value)
2091                      {
2092                          $permission[$name] = 1;
2093                      }
2094                  }
2095                  foreach(array('canview','canpostthreads','canpostreplys','canpostpolls') as $name)
2096                  {
2097                      if($permission[$name])
2098                      {
2099                          $permissions[$name][$gid] = 1;
2100                      }
2101                      else
2102                      {
2103                          $permissions[$name][$gid] = 0;
2104                      }
2105                  }
2106              }
2107  
2108              $canview = $permissions['canview'];
2109              $canpostthreads = $permissions['canpostthreads'];
2110              $canpostpolls = $permissions['canpostpolls'];
2111              $canpostattachments = $permissions['canpostattachments'];
2112              $canpostreplies = $permissions['canpostreplys'];
2113  
2114              save_quick_perms($fid);
2115  
2116              $plugins->run_hooks("admin_forum_management_start_permissions_commit");
2117  
2118              $cache->update_forums();
2119  
2120              // Log admin action
2121              log_admin_action('quickpermissions', $fid, $forum['name']);
2122  
2123              flash_message($lang->success_forum_permissions_updated, 'success');
2124              admin_redirect("index.php?module=forum-management&fid={$fid}#tab_permissions");
2125          }
2126          elseif($mybb->input['add'] == "moderators")
2127          {
2128              $forum = get_forum($fid);
2129              if(!$forum)
2130              {
2131                  flash_message($lang->error_invalid_forum, 'error');
2132                  admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
2133              }
2134              if(!empty($mybb->input['usergroup']))
2135              {
2136                  $isgroup = 1;
2137                  $gid = $mybb->get_input('usergroup', MyBB::INPUT_INT);
2138  
2139                  if(!$groupscache[$gid])
2140                   {
2141                       // Didn't select a valid moderator
2142                       flash_message($lang->error_moderator_not_found, 'error');
2143                       admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
2144                   }
2145  
2146                  $newmod = array(
2147                      "id" => $gid,
2148                      "name" => $groupscache[$gid]['title']
2149                  );
2150              }
2151              else
2152              {
2153                  $options = array(
2154                      'fields' => array('uid AS id', 'username AS name')
2155                  );
2156                  $newmod = get_user_by_username($mybb->input['username'], $options);
2157  
2158                  if(empty($newmod['id']))
2159                  {
2160                      flash_message($lang->error_moderator_not_found, 'error');
2161                      admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
2162                  }
2163  
2164                  $isgroup = 0;
2165              }
2166  
2167              if($newmod['id'])
2168              {
2169                  $query = $db->simple_select("moderators", "id", "id='".$newmod['id']."' AND fid='".$fid."' AND isgroup='{$isgroup}'", array('limit' => 1));
2170  
2171                  if(!$db->num_rows($query))
2172                  {
2173                      $new_mod = array(
2174                          "fid" => $fid,
2175                          "id" => $newmod['id'],
2176                          "isgroup" => $isgroup,
2177                          "caneditposts" => 1,
2178                          "cansoftdeleteposts" => 1,
2179                          "canrestoreposts" => 1,
2180                          "candeleteposts" => 1,
2181                          "cansoftdeletethreads" => 1,
2182                          "canrestorethreads" => 1,
2183                          "candeletethreads" => 1,
2184                          "canviewips" => 1,
2185                          "canviewunapprove" => 1,
2186                          "canviewdeleted" => 1,
2187                          "canopenclosethreads" => 1,
2188                          "canstickunstickthreads" => 1,
2189                          "canapproveunapprovethreads" => 1,
2190                          "canapproveunapproveposts" => 1,
2191                          "canapproveunapproveattachs" => 1,
2192                          "canmanagethreads" => 1,
2193                          "canmanagepolls" => 1,
2194                          "canpostclosedthreads" => 1,
2195                          "canmovetononmodforum" => 1,
2196                          "canusecustomtools" => 1,
2197                          "canmanageannouncements" => 1,
2198                          "canmanagereportedposts" => 1,
2199                          "canviewmodlog" => 1
2200                      );
2201  
2202                      $mid = $db->insert_query("moderators", $new_mod);
2203  
2204                      if(!$isgroup)
2205                      {
2206                          $db->update_query("users", array('usergroup' => 6), "uid='{$newmod['id']}' AND usergroup='2'");
2207                      }
2208  
2209                      $plugins->run_hooks("admin_forum_management_start_moderators_commit");
2210  
2211                      $cache->update_moderators();
2212  
2213                      // Log admin action
2214                      log_admin_action('addmod', $mid, $newmod['name'], $fid, $forum['name']);
2215  
2216                      flash_message($lang->success_moderator_added, 'success');
2217                      admin_redirect("index.php?module=forum-management&action=editmod&mid={$mid}");
2218                  }
2219                  else
2220                  {
2221                      flash_message($lang->error_moderator_already_added, 'error');
2222                      admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
2223                  }
2224              }
2225              else
2226              {
2227                  flash_message($lang->error_moderator_not_found, 'error');
2228                  admin_redirect("index.php?module=forum-management&fid={$fid}#tab_moderators");
2229              }
2230          }
2231          else
2232          {
2233              if(!empty($mybb->input['disporder']) && is_array($mybb->input['disporder']))
2234              {
2235                  foreach($mybb->input['disporder'] as $update_fid => $order)
2236                  {
2237                      $db->update_query("forums", array('disporder' => (int)$order), "fid='".(int)$update_fid."'");
2238                  }
2239  
2240                  $plugins->run_hooks("admin_forum_management_start_disporder_commit");
2241  
2242                  $cache->update_forums();
2243  
2244                  // Log admin action
2245                  log_admin_action('orders', $forum['fid'], $forum['name']);
2246  
2247                  flash_message($lang->success_forum_disporder_updated, 'success');
2248                  admin_redirect("index.php?module=forum-management&fid=".$mybb->input['fid']);
2249              }
2250          }
2251      }
2252  
2253      $page->extra_header .=  "<script src=\"jscripts/quick_perm_editor.js\" type=\"text/javascript\"></script>\n";
2254  
2255      if($fid)
2256      {
2257          $page->add_breadcrumb_item($lang->view_forum, "index.php?module=forum-management");
2258      }
2259  
2260      $page->output_header($lang->forum_management);
2261  
2262      if($fid)
2263      {
2264          $page->output_nav_tabs($sub_tabs, 'view_forum');
2265      }
2266      else
2267      {
2268          $page->output_nav_tabs($sub_tabs, 'forum_management');
2269      }
2270  
2271      $form = new Form("index.php?module=forum-management", "post", "management");
2272      echo $form->generate_hidden_field("fid", $mybb->input['fid']);
2273  
2274      if($fid)
2275      {
2276          $tabs = array(
2277              'subforums' => $lang->subforums,
2278              'permissions' => $lang->forum_permissions,
2279              'moderators' => $lang->moderators,
2280          );
2281          $tabs = $plugins->run_hooks("admin_forum_management_start_graph_tabs", $tabs);
2282          $page->output_tab_control($tabs);
2283  
2284          echo "<div id=\"tab_subforums\">\n";
2285          if(!isset($forum_cache) || !is_array($forum_cache))
2286          {
2287              cache_forums();
2288          }
2289          $form_container = new FormContainer($lang->sprintf($lang->in_forums, $forum_cache[$fid]['name']));
2290      }
2291      else
2292      {
2293          $form_container = new FormContainer($lang->manage_forums);
2294      }
2295      $form_container->output_row_header($lang->forum);
2296      $form_container->output_row_header($lang->order, array("class" => "align_center", 'width' => '6%'));
2297      $form_container->output_row_header($lang->controls, array("class" => "align_center", 'style' => 'width: 200px'));
2298  
2299      build_admincp_forums_list($form_container, $form, $fid);
2300  
2301      $submit_options = array();
2302  
2303      if($form_container->num_rows() == 0)
2304      {
2305          $form_container->output_cell($lang->no_forums, array('colspan' => 3));
2306          $form_container->construct_row();
2307          $submit_options = array('disabled' => true);
2308      }
2309  
2310      $form_container->end();
2311  
2312      $buttons[] = $form->generate_submit_button($lang->update_forum_orders, $submit_options);
2313      $buttons[] = $form->generate_reset_button($lang->reset);
2314  
2315      $form->output_submit_wrapper($buttons);
2316  
2317      if(!$fid)
2318      {
2319          $form->end();
2320      }
2321  
2322      if($fid)
2323      {
2324          echo "</div>\n";
2325          $form->end();
2326  
2327          $query = $db->simple_select("usergroups", "*", "", array("order" => "name"));
2328          while($usergroup = $db->fetch_array($query))
2329          {
2330              $usergroups[$usergroup['gid']] = $usergroup;
2331          }
2332  
2333          $query = $db->simple_select("forumpermissions", "*", "fid='{$fid}'");
2334          while($existing = $db->fetch_array($query))
2335          {
2336              $existing_permissions[$existing['gid']] = $existing;
2337          }
2338  
2339          $cached_forum_perms = $cache->read("forumpermissions");
2340          $field_list = array(
2341              'canview' => $lang->permissions_canview,
2342              'canpostthreads' => $lang->permissions_canpostthreads,
2343              'canpostreplys' => $lang->permissions_canpostreplys,
2344              'canpostpolls' => $lang->permissions_canpostpolls,
2345          );
2346  
2347          $field_list2 = array(
2348              'canview' => $lang->perm_drag_canview,
2349              'canpostthreads' => $lang->perm_drag_canpostthreads,
2350              'canpostreplys' => $lang->perm_drag_canpostreplys,
2351              'canpostpolls' => $lang->perm_drag_canpostpolls,
2352          );
2353  
2354          $ids = array();
2355  
2356          $form = new Form("index.php?module=forum-management", "post", "management");
2357          echo $form->generate_hidden_field("fid", $mybb->input['fid']);
2358          echo $form->generate_hidden_field("update", "permissions");
2359  
2360          echo "<div id=\"tab_permissions\">\n";
2361  
2362          $form_container = new FormContainer($lang->sprintf($lang->forum_permissions_in, $forum_cache[$fid]['name']));
2363          $form_container->output_row_header($lang->permissions_group, array("class" => "align_center", 'style' => 'width: 30%'));
2364          $form_container->output_row_header($lang->overview_allowed_actions, array("class" => "align_center"));
2365          $form_container->output_row_header($lang->overview_disallowed_actions, array("class" => "align_center"));
2366          $form_container->output_row_header($lang->controls, array("class" => "align_center", 'style' => 'width: 120px', 'colspan' => 2));
2367          foreach($usergroups as $usergroup)
2368          {
2369              $perms = array();
2370              if(isset($mybb->input['default_permissions']))
2371              {
2372                  if($mybb->input['default_permissions'][$usergroup['gid']])
2373                  {
2374                      if(is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
2375                      {
2376                          $perms = $existing_permissions[$usergroup['gid']];
2377                          $default_checked = false;
2378                      }
2379                      elseif(is_array($cached_forum_perms) && $cached_forum_perms[$forum['fid']][$usergroup['gid']])
2380                      {
2381                          $perms = $cached_forum_perms[$forum['fid']][$usergroup['gid']];
2382                          $default_checked = true;
2383                      }
2384                      else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum['pid']][$usergroup['gid']])
2385                      {
2386                          $perms = $cached_forum_perms[$forum['pid']][$usergroup['gid']];
2387                          $default_checked = true;
2388                      }
2389                  }
2390  
2391                  if(!$perms)
2392                  {
2393                      $perms = $usergroup;
2394                      $default_checked = true;
2395                  }
2396              }
2397              else
2398              {
2399                  if(isset($existing_permissions) && is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
2400                  {
2401                      $perms = $existing_permissions[$usergroup['gid']];
2402                      $default_checked = false;
2403                  }
2404                  elseif(is_array($cached_forum_perms) && isset($cached_forum_perms[$forum['fid']]) && $cached_forum_perms[$forum['fid']][$usergroup['gid']])
2405                  {
2406                      $perms = $cached_forum_perms[$forum['fid']][$usergroup['gid']];
2407                      $default_checked = true;
2408                  }
2409                  else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum['pid']][$usergroup['gid']])
2410                  {
2411                      $perms = $cached_forum_perms[$forum['pid']][$usergroup['gid']];
2412                      $default_checked = true;
2413                  }
2414  
2415                  if(!$perms)
2416                  {
2417                      $perms = $usergroup;
2418                      $default_checked = true;
2419                  }
2420              }
2421              foreach($field_list as $forum_permission => $forum_perm_title)
2422              {
2423                  if(isset($mybb->input['permissions']))
2424                  {
2425                      if($mybb->input['permissions'][$usergroup['gid']][$forum_permission])
2426                      {
2427                          $perms_checked[$forum_permission] = 1;
2428                      }
2429                      else
2430                      {
2431                          $perms_checked[$forum_permission] = 0;
2432                      }
2433                  }
2434                  else
2435                  {
2436                      if($perms[$forum_permission] == 1)
2437                      {
2438                          $perms_checked[$forum_permission] = 1;
2439                      }
2440                      else
2441                      {
2442                          $perms_checked[$forum_permission] = 0;
2443                      }
2444                  }
2445              }
2446              $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
2447  
2448              if($default_checked == 1)
2449              {
2450                  $inherited_text = $lang->inherited_permission;
2451              }
2452              else
2453              {
2454                  $inherited_text = $lang->custom_permission;
2455              }
2456  
2457              $form_container->output_cell("<strong>{$usergroup['title']}</strong> <small style=\"vertical-align: middle;\">({$inherited_text})</small>");
2458  
2459              $field_select = "<div class=\"quick_perm_fields\">\n";
2460              $field_select .= "<div class=\"enabled\"><ul id=\"fields_enabled_{$usergroup['gid']}\">\n";
2461              foreach($perms_checked as $perm => $value)
2462              {
2463                  if($value == 1)
2464                  {
2465                      $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
2466                  }
2467              }
2468              $field_select .= "</ul></div>\n";
2469              $field_select .= "<div class=\"disabled\"><ul id=\"fields_disabled_{$usergroup['gid']}\">\n";
2470              foreach($perms_checked as $perm => $value)
2471              {
2472                  if($value == 0)
2473                  {
2474                      $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
2475                  }
2476              }
2477              $field_select .= "</ul></div></div>\n";
2478              $field_select .= $form->generate_hidden_field("fields_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, '1')), array('id' => 'fields_'.$usergroup['gid']));
2479              $field_select .= $form->generate_hidden_field("fields_inherit_".$usergroup['gid'], (int)$default_checked, array('id' => 'fields_inherit_'.$usergroup['gid']));
2480              $field_select .= $form->generate_hidden_field("fields_default_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, '1')), array('id' => 'fields_default_'.$usergroup['gid']));
2481              $field_select = str_replace("'", "\\'", $field_select);
2482              $field_select = str_replace("\n", "", $field_select);
2483  
2484              $field_select = "<script type=\"text/javascript\">
2485  //<![CDATA[
2486  document.write('".str_replace("/", "\/", $field_select)."');
2487  //]]>
2488  </script>\n";
2489  
2490              $field_selected = array();
2491              foreach($field_list as $forum_permission => $permission_title)
2492              {
2493                  $field_options[$forum_permission] = $permission_title;
2494                  if($perms_checked[$forum_permission])
2495                  {
2496                      $field_selected[] = $forum_permission;
2497                  }
2498              }
2499  
2500              $field_select .= "<noscript>".$form->generate_select_box('fields_'.$usergroup['gid'].'[]', $field_options, $field_selected, array('id' => 'fields_'.$usergroup['gid'].'[]', 'multiple' => true))."</noscript>\n";
2501              $form_container->output_cell($field_select, array('colspan' => 2));
2502  
2503              if(!$default_checked)
2504              {
2505                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;pid={$perms['pid']}\" onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&pid={$perms['pid']}&ajax=1', null, true); return false;\">{$lang->edit_permissions}</a>", array("class" => "align_center"));
2506                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=clear_permission&amp;pid={$perms['pid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_clear_custom_permission}')\">{$lang->clear_custom_perms}</a>", array("class" => "align_center"));
2507              }
2508              else
2509              {
2510                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;gid={$usergroup['gid']}&amp;fid={$fid}\"  onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&gid={$usergroup['gid']}&fid={$fid}&ajax=1', null, true); return false;\">{$lang->set_custom_perms}</a>", array("class" => "align_center", "colspan" => 2));
2511              }
2512              $form_container->construct_row(array('id' => 'row_'.$usergroup['gid']));
2513  
2514              $ids[] = $usergroup['gid'];
2515          }
2516          $form_container->end();
2517  
2518          $buttons = array();
2519          $buttons[] = $form->generate_submit_button($lang->update_forum_permissions);
2520          $buttons[] = $form->generate_reset_button($lang->reset);
2521  
2522          $form->output_submit_wrapper($buttons);
2523  
2524          // Write in our JS based field selector
2525          echo "<script type=\"text/javascript\">\n<!--\n";
2526          foreach($ids as $id)
2527          {
2528              echo "$(function() { QuickPermEditor.init(".$id.") });\n";
2529          }
2530          echo "// -->\n</script>\n";
2531  
2532          echo "</div>\n";
2533          $form->end();
2534          echo "<div id=\"tab_moderators\">\n";
2535          $form_container = new FormContainer($lang->sprintf($lang->moderators_assigned_to, $forum_cache[$fid]['name']));
2536          $form_container->output_row_header($lang->name, array('width' => '75%'));
2537          $form_container->output_row_header($lang->controls, array("class" => "align_center", 'style' => 'width: 200px', 'colspan' => 2));
2538          $query = $db->query("
2539              SELECT m.mid, m.id, m.isgroup, u.username, g.title
2540              FROM ".TABLE_PREFIX."moderators m
2541              LEFT JOIN ".TABLE_PREFIX."users u ON (m.isgroup='0' AND m.id=u.uid)
2542              LEFT JOIN ".TABLE_PREFIX."usergroups g ON (m.isgroup='1' AND m.id=g.gid)
2543              WHERE fid='{$fid}'
2544              ORDER BY m.isgroup DESC, u.username, g.title
2545          ");
2546          while($moderator = $db->fetch_array($query))
2547          {
2548              if($moderator['isgroup'])
2549              {
2550                  $moderator['img'] = "<img src=\"styles/{$page->style}/images/icons/group.png\" alt=\"{$lang->group}\" title=\"{$lang->group}\" />";
2551                  $form_container->output_cell("{$moderator['img']} <a href=\"index.php?module=user-groups&amp;action=edit&amp;gid={$moderator['id']}\">".htmlspecialchars_uni($moderator['title'])." ({$lang->usergroup} {$moderator['id']})</a>");
2552                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=editmod&amp;mid={$moderator['mid']}\">{$lang->edit}</a>", array("class" => "align_center"));
2553                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=deletemod&amp;id={$moderator['id']}&amp;isgroup=1&amp;fid={$fid}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_moderator_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
2554              }
2555              else
2556              {
2557                  $moderator['img'] = "<img src=\"styles/{$page->style}/images/icons/user.png\" alt=\"{$lang->user}\" title=\"{$lang->user}\" />";
2558                  $form_container->output_cell("{$moderator['img']} <a href=\"index.php?module=user-users&amp;action=edit&amp;uid={$moderator['id']}\">".htmlspecialchars_uni($moderator['username'])."</a>");
2559                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=editmod&amp;mid={$moderator['mid']}\">{$lang->edit}</a>", array("class" => "align_center"));
2560                  $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=deletemod&amp;id={$moderator['id']}&amp;isgroup=0&amp;fid={$fid}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_moderator_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
2561              }
2562              $form_container->construct_row();
2563          }
2564  
2565          if($form_container->num_rows() == 0)
2566          {
2567              $form_container->output_cell($lang->no_moderators, array('colspan' => 3));
2568              $form_container->construct_row();
2569          }
2570          $form_container->end();
2571  
2572          // Users
2573          $buttons = array();
2574          $form = new Form("index.php?module=forum-management", "post", "management");
2575          echo $form->generate_hidden_field("fid", $mybb->input['fid']);
2576          echo $form->generate_hidden_field("add", "moderators");
2577  
2578          // Usergroup Moderator
2579          if(!is_array($usergroups))
2580          {
2581              $usergroups = $groupscache;
2582          }
2583  
2584          foreach($usergroups as $group)
2585          {
2586              $modgroups[$group['gid']] = $lang->usergroup." ".$group['gid'].": ".htmlspecialchars_uni($group['title']);
2587          }
2588  
2589          if(!isset($mybb->input['usergroup']))
2590          {
2591              $mybb->input['usergroup'] = '';
2592          }
2593  
2594          if(!isset($mybb->input['username']))
2595          {
2596              $mybb->input['username'] = '';
2597          }
2598  
2599          $form_container = new FormContainer($lang->add_usergroup_as_moderator);
2600          $form_container->output_row($lang->usergroup." <em>*</em>", $lang->moderator_usergroup_desc, $form->generate_select_box('usergroup', $modgroups, $mybb->input['usergroup'], array('id' => 'usergroup')), 'usergroup');
2601          $form_container->end();
2602  
2603          $buttons[] = $form->generate_submit_button($lang->add_usergroup_moderator);
2604          $form->output_submit_wrapper($buttons);
2605          $form->end();
2606          echo "<br />";
2607  
2608          $form = new Form("index.php?module=forum-management", "post", "management");
2609          echo $form->generate_hidden_field("fid", $mybb->input['fid']);
2610          echo $form->generate_hidden_field("add", "moderators");
2611          $form_container = new FormContainer($lang->add_user_as_moderator);
2612          $form_container->output_row($lang->username." <em>*</em>", $lang->moderator_username_desc, $form->generate_text_box('username', htmlspecialchars_uni($mybb->get_input('username')), array('id' => 'username')), 'username');
2613          $form_container->end();
2614  
2615          // Autocompletion for usernames
2616          echo '
2617          <link rel="stylesheet" href="../jscripts/select2/select2.css">
2618          <script type="text/javascript" src="../jscripts/select2/select2.min.js?ver=1804"></script>
2619          <script type="text/javascript">
2620          <!--
2621          $("#username").select2({
2622              placeholder: "'.$lang->search_for_a_user.'",
2623              minimumInputLength: 2,
2624              multiple: false,
2625              ajax: { // instead of writing the function to execute the request we use Select2\'s convenient helper
2626                  url: "../xmlhttp.php?action=get_users",
2627                  dataType: \'json\',
2628                  data: function (term, page) {
2629                      return {
2630                          query: term, // search term
2631                      };
2632                  },
2633                  results: function (data, page) { // parse the results into the format expected by Select2.
2634                      // since we are using custom formatting functions we do not need to alter remote JSON data
2635                      return {results: data};
2636                  }
2637              },
2638              initSelection: function(element, callback) {
2639                  var query = $(element).val();
2640                  if (query !== "") {
2641                      $.ajax("../xmlhttp.php?action=get_users&getone=1", {
2642                          data: {
2643                              query: query
2644                          },
2645                          dataType: "json"
2646                      }).done(function(data) { callback(data); });
2647                  }
2648              },
2649          });
2650  
2651          $(\'[for=username]\').on(\'click\', function(){
2652              $("#username").select2(\'open\');
2653              return false;
2654          });
2655          // -->
2656          </script>';
2657  
2658          $buttons = array($form->generate_submit_button($lang->add_user_moderator));
2659          $form->output_submit_wrapper($buttons);
2660          $form->end();
2661  
2662          echo "</div>\n";
2663  
2664          $plugins->run_hooks("admin_forum_management_start_graph");
2665      }
2666  
2667      $page->output_footer();
2668  }
2669  
2670  /**
2671   * @param DefaultFormContainer $form_container
2672   * @param DefaultForm $form
2673   * @param int $pid
2674   * @param int $depth
2675   */
2676  function build_admincp_forums_list(&$form_container, &$form, $pid=0, $depth=1)
2677  {
2678      global $mybb, $lang, $db, $sub_forums;
2679      static $forums_by_parent;
2680  
2681      if(!is_array($forums_by_parent))
2682      {
2683          $forum_cache = cache_forums();
2684  
2685          foreach($forum_cache as $forum)
2686          {
2687              $forums_by_parent[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
2688          }
2689      }
2690  
2691      if(!is_array($forums_by_parent[$pid]))
2692      {
2693          return;
2694      }
2695  
2696      foreach($forums_by_parent[$pid] as $children)
2697      {
2698          foreach($children as $forum)
2699          {
2700              $forum['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forum['name']); // Fix & but allow unicode
2701  
2702              if($forum['active'] == 0)
2703              {
2704                  $forum['name'] = "<em>".$forum['name']."</em>";
2705              }
2706  
2707              if($forum['type'] == "c" && ($depth == 1 || $depth == 2))
2708              {
2709                  $sub_forums = '';
2710                  if(isset($forums_by_parent[$forum['fid']]) && $depth == 2)
2711                  {
2712                      build_admincp_forums_list($form_container, $form, $forum['fid'], $depth+1);
2713                  }
2714                  if($sub_forums)
2715                  {
2716                      $sub_forums = "<br /><small>{$lang->sub_forums}: {$sub_forums}</small>";
2717                  }
2718  
2719                  $form_container->output_cell("<div style=\"padding-left: ".(40*($depth-1))."px;\"><a href=\"index.php?module=forum-management&amp;fid={$forum['fid']}\"><strong>{$forum['name']}</strong></a>{$sub_forums}</div>");
2720  
2721                  $form_container->output_cell($form->generate_numeric_field("disporder[{$forum['fid']}]", "{$forum['disporder']}", array('min' => 0, 'class' => 'align_center', 'style' => 'width:80%; font-weight:bold')), array("class" => "align_center"));
2722  
2723                  $popup = new PopupMenu("forum_{$forum['fid']}", $lang->options);
2724                  $popup->add_item($lang->edit_forum, "index.php?module=forum-management&amp;action=edit&amp;fid={$forum['fid']}");
2725                  $popup->add_item($lang->subforums, "index.php?module=forum-management&amp;fid={$forum['fid']}");
2726                  $popup->add_item($lang->moderators, "index.php?module=forum-management&amp;fid={$forum['fid']}#tab_moderators");
2727                  $popup->add_item($lang->permissions, "index.php?module=forum-management&amp;fid={$forum['fid']}#tab_permissions");
2728                  $popup->add_item($lang->forum_thread_prefixes, "index.php?module=config-thread_prefixes&amp;fid={$forum['fid']}");
2729                  $popup->add_item($lang->add_child_forum, "index.php?module=forum-management&amp;action=add&amp;pid={$forum['fid']}");
2730                  $popup->add_item($lang->copy_forum, "index.php?module=forum-management&amp;action=copy&amp;fid={$forum['fid']}");
2731                  $popup->add_item($lang->delete_forum, "index.php?module=forum-management&amp;action=delete&amp;fid={$forum['fid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_forum_deletion}')");
2732  
2733                  $form_container->output_cell($popup->fetch(), array("class" => "align_center"));
2734  
2735                  $form_container->construct_row();
2736  
2737                  // Does this category have any sub forums?
2738                  if($forums_by_parent[$forum['fid']])
2739                  {
2740                      build_admincp_forums_list($form_container, $form, $forum['fid'], $depth+1);
2741                  }
2742              }
2743              elseif($forum['type'] == "f" && ($depth == 1 || $depth == 2))
2744              {
2745                  if($forum['description'])
2746                  {
2747                      $forum['description'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forum['description']);
2748                         $forum['description'] = "<br /><small>".$forum['description']."</small>";
2749                     }
2750  
2751                  $sub_forums = '';
2752                  if(isset($forums_by_parent[$forum['fid']]) && $depth == 2)
2753                  {
2754                      build_admincp_forums_list($form_container, $form, $forum['fid'], $depth+1);
2755                  }
2756                  if($sub_forums)
2757                  {
2758                      $sub_forums = "<br /><small>{$lang->sub_forums}: {$sub_forums}</small>";
2759                  }
2760  
2761                  $form_container->output_cell("<div style=\"padding-left: ".(40*($depth-1))."px;\"><a href=\"index.php?module=forum-management&amp;fid={$forum['fid']}\">{$forum['name']}</a>{$forum['description']}{$sub_forums}</div>");
2762  
2763                  $form_container->output_cell($form->generate_numeric_field("disporder[{$forum['fid']}]", "{$forum['disporder']}", array('min' => 0, 'class' => 'align_center', 'style' => 'width:80%')), array("class" => "align_center"));
2764                  $popup = new PopupMenu("forum_{$forum['fid']}", $lang->options);
2765                  $popup->add_item($lang->edit_forum, "index.php?module=forum-management&amp;action=edit&amp;fid={$forum['fid']}");
2766                  $popup->add_item($lang->subforums, "index.php?module=forum-management&amp;fid={$forum['fid']}");
2767                  $popup->add_item($lang->moderators, "index.php?module=forum-management&amp;fid={$forum['fid']}#tab_moderators");
2768                  $popup->add_item($lang->permissions, "index.php?module=forum-management&amp;fid={$forum['fid']}#tab_permissions");
2769                  $popup->add_item($lang->forum_thread_prefixes, "index.php?module=config-thread_prefixes&amp;fid={$forum['fid']}");
2770                  $popup->add_item($lang->add_child_forum, "index.php?module=forum-management&amp;action=add&amp;pid={$forum['fid']}");
2771                  $popup->add_item($lang->copy_forum, "index.php?module=forum-management&amp;action=copy&amp;fid={$forum['fid']}");
2772                  $popup->add_item($lang->delete_forum, "index.php?module=forum-management&amp;action=delete&amp;fid={$forum['fid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_forum_deletion}')");
2773  
2774                  $form_container->output_cell($popup->fetch(), array("class" => "align_center"));
2775  
2776                  $form_container->construct_row();
2777  
2778                  if(isset($forums_by_parent[$forum['fid']]) && $depth == 1)
2779                  {
2780                      build_admincp_forums_list($form_container, $form, $forum['fid'], $depth+1);
2781                  }
2782              }
2783              else if($depth == 3)
2784              {
2785                  if($donecount < $mybb->settings['subforumsindex'])
2786                  {
2787                      $sub_forums .= "{$comma} <a href=\"index.php?module=forum-management&amp;fid={$forum['fid']}\">{$forum['name']}</a>";
2788                      $comma = $lang->comma;
2789                  }
2790  
2791                  // Have we reached our max visible subforums? put a nice message and break out of the loop
2792                  ++$donecount;
2793                  if($donecount == $mybb->settings['subforumsindex'])
2794                  {
2795                      if(subforums_count($forums_by_parent[$pid]) > $donecount)
2796                      {
2797                          $sub_forums .= $comma.$lang->sprintf($lang->more_subforums, (subforums_count($forums_by_parent[$pid]) - $donecount));
2798                          return;
2799                      }
2800                  }
2801              }
2802          }
2803      }
2804  }
2805  
2806  /**
2807   * @param int $gid
2808   * @param int $fid
2809   *
2810   * @return string
2811   */
2812  function retrieve_single_permissions_row($gid, $fid)
2813  {
2814      global $mybb, $lang, $cache, $db;
2815  
2816      $query = $db->simple_select("usergroups", "*", "gid='{$gid}'");
2817      $usergroup = $db->fetch_array($query);
2818  
2819      $query = $db->simple_select("forums", "*", "fid='{$fid}'");
2820      $forum_data = $db->fetch_array($query);
2821  
2822      $query = $db->simple_select("forumpermissions", "*", "fid='{$fid}'");
2823      while($existing = $db->fetch_array($query))
2824      {
2825          $existing_permissions[$existing['gid']] = $existing;
2826      }
2827  
2828      $cached_forum_perms = $cache->read("forumpermissions");
2829      $field_list = array(
2830          'canview' => $lang->permissions_canview,
2831          'canpostthreads' => $lang->permissions_canpostthreads,
2832          'canpostreplys' => $lang->permissions_canpostreplys,
2833          'canpostpolls' => $lang->permissions_canpostpolls,
2834      );
2835  
2836      $field_list2 = array(
2837          'canview' => $lang->perm_drag_canview,
2838          'canpostthreads' => $lang->perm_drag_canpostthreads,
2839          'canpostreplys' => $lang->perm_drag_canpostreplys,
2840          'canpostpolls' => $lang->perm_drag_canpostpolls,
2841      );
2842  
2843      $form = new Form('', '', "", 0, "", true);
2844      $form_container = new FormContainer();
2845  
2846      $perms = array();
2847  
2848      if(is_array($existing_permissions) && $existing_permissions[$usergroup['gid']])
2849      {
2850          $perms = $existing_permissions[$usergroup['gid']];
2851          $default_checked = false;
2852      }
2853      elseif(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['fid']][$usergroup['gid']])
2854      {
2855          $perms = $cached_forum_perms[$forum_data['fid']][$usergroup['gid']];
2856          $default_checked = true;
2857      }
2858      else if(is_array($cached_forum_perms) && $cached_forum_perms[$forum_data['pid']][$usergroup['gid']])
2859      {
2860          $perms = $cached_forum_perms[$forum_data['pid']][$usergroup['gid']];
2861          $default_checked = true;
2862      }
2863  
2864      if(!$perms)
2865      {
2866          $perms = $usergroup;
2867          $default_checked = true;
2868      }
2869  
2870      foreach($field_list as $forum_permission => $forum_perm_title)
2871      {
2872          if($perms[$forum_permission] == 1)
2873          {
2874              $perms_checked[$forum_permission] = 1;
2875          }
2876          else
2877          {
2878              $perms_checked[$forum_permission] = 0;
2879          }
2880      }
2881  
2882      $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
2883  
2884      if($default_checked == 1)
2885      {
2886          $inherited_text = $lang->inherited_permission;
2887      }
2888      else
2889      {
2890          $inherited_text = $lang->custom_permission;
2891      }
2892  
2893      $form_container->output_cell("<strong>{$usergroup['title']}</strong> <small style=\"vertical-align: middle;\">({$inherited_text})</small>");
2894  
2895      $field_select = "<div class=\"quick_perm_fields\">\n";
2896      $field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled_{$usergroup['gid']}\">\n";
2897      foreach($perms_checked as $perm => $value)
2898      {
2899          if($value == 1)
2900          {
2901              $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
2902          }
2903      }
2904      $field_select .= "</ul></div>\n";
2905      $field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled_{$usergroup['gid']}\">\n";
2906      foreach($perms_checked as $perm => $value)
2907      {
2908          if($value == 0)
2909          {
2910              $field_select .= "<li id=\"field-{$perm}\">{$field_list2[$perm]}</li>";
2911          }
2912      }
2913      $field_select .= "</ul></div></div>\n";
2914      $field_select .= $form->generate_hidden_field("fields_".$usergroup['gid'], @implode(",", @array_keys($perms_checked, 1)), array('id' => 'fields_'.$usergroup['gid']));
2915      $field_select = str_replace("\n", "", $field_select);
2916  
2917      foreach($field_list as $forum_permission => $permission_title)
2918      {
2919          $field_options[$forum_permission] = $permission_title;
2920      }
2921      $form_container->output_cell($field_select, array('colspan' => 2));
2922  
2923      if(!$default_checked)
2924      {
2925          $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;pid={$perms['pid']}\" onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&pid={$perms['pid']}&ajax=1', null, true); return false;\">{$lang->edit_permissions}</a>", array("class" => "align_center"));
2926          $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=clear_permission&amp;pid={$perms['pid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_clear_custom_permission}')\">{$lang->clear_custom_perms}</a>", array("class" => "align_center"));
2927      }
2928      else
2929      {
2930          $form_container->output_cell("<a href=\"index.php?module=forum-management&amp;action=permissions&amp;gid={$usergroup['gid']}&amp;fid={$fid}\"  onclick=\"MyBB.popupWindow('index.php?module=forum-management&action=permissions&gid={$usergroup['gid']}&fid={$fid}&ajax=1', null, true); return false;\">{$lang->set_custom_perms}</a>", array("class" => "align_center", "colspan" => 2));
2931      }
2932      $form_container->construct_row();
2933      return $form_container->output_row_cells(0, true);
2934  }
2935  


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