[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/user/ -> groups.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  // Array of usergroup permission fields and their default values.
  12  $usergroup_permissions = array(
  13      "isbannedgroup" => 0,
  14      "canview" => 1,
  15      "canviewthreads" => 1,
  16      "canviewprofiles" => 1,
  17      "candlattachments" => 1,
  18      "canviewboardclosed" => 1,
  19      "canpostthreads" => 1,
  20      "canpostreplys" => 1,
  21      "canpostattachments" => 1,
  22      "canratethreads" => 1,
  23      "modposts" => 0,
  24      "modthreads" => 0,
  25      "modattachments" => 0,
  26      "mod_edit_posts" => 0,
  27      "caneditposts" => 1,
  28      "candeleteposts" => 1,
  29      "candeletethreads" => 1,
  30      "caneditattachments" => 1,
  31      "canviewdeletionnotice" => 1,
  32      "canpostpolls" => 1,
  33      "canvotepolls" => 1,
  34      "canundovotes" => 0,
  35      "canusepms" => 1,
  36      "cansendpms" => 1,
  37      "cantrackpms" => 1,
  38      "candenypmreceipts" => 1,
  39      "pmquota" => 100,
  40      "maxpmrecipients" => 5,
  41      "cansendemail" => 1,
  42      "cansendemailoverride" => 0,
  43      "maxemails" => 4,
  44      "emailfloodtime" => 5,
  45      "canviewmemberlist" => 1,
  46      "canviewcalendar" => 1,
  47      "canaddevents" => 1,
  48      "canbypasseventmod" => 0,
  49      "canmoderateevents" => 0,
  50      "canviewonline" => 1,
  51      "canviewwolinvis" => 0,
  52      "canviewonlineips" => 0,
  53      "cancp" => 0,
  54      "issupermod" => 0,
  55      "cansearch" => 1,
  56      "canusercp" => 1,
  57      "canuploadavatars" => 1,
  58      "canratemembers" => 1,
  59      "canchangename" => 0,
  60      "canbeinvisible" => 1,
  61      "canbereported" => 0,
  62      "canchangewebsite" => 1,
  63      "showforumteam" => 0,
  64      "usereputationsystem" => 1,
  65      "cangivereputations" => 1,
  66      "candeletereputations" => 1,
  67      "reputationpower" => 1,
  68      "maxreputationsday" => 5,
  69      "maxreputationsperuser" => 0,
  70      "maxreputationsperthread" => 0,
  71      "candisplaygroup" => 0,
  72      "attachquota" => 5000,
  73      "cancustomtitle" => 0,
  74      "canwarnusers" => 0,
  75      "canreceivewarnings" => 1,
  76      "maxwarningsday" => 0,
  77      "canmodcp" => 0,
  78      "showinbirthdaylist" => 0,
  79      "canoverridepm" => 0,
  80      "canusesig" => 0,
  81      "canusesigxposts" => 0,
  82      "signofollow" => 0,
  83      "edittimelimit" => 0,
  84      "maxposts" => 0,
  85      "showmemberlist" => 1,
  86      "canmanageannounce" => 0,
  87      "canmanagemodqueue" => 0,
  88      "canmanagereportedcontent" => 0,
  89      "canviewmodlogs" => 0,
  90      "caneditprofiles" => 0,
  91      "canbanusers" => 0,
  92      "canviewwarnlogs" => 0,
  93      "canuseipsearch" => 0
  94  );
  95  
  96  // Disallow direct access to this file for security reasons
  97  if(!defined("IN_MYBB"))
  98  {
  99      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
 100  }
 101  
 102  $page->add_breadcrumb_item($lang->user_groups, "index.php?module=user-groups");
 103  
 104  if($mybb->input['action'] == "add" || !$mybb->input['action'])
 105  {
 106      $sub_tabs['manage_groups'] = array(
 107          'title' => $lang->manage_user_groups,
 108          'link' => "index.php?module=user-groups",
 109          'description' => $lang->manage_user_groups_desc
 110      );
 111      $sub_tabs['add_group'] = array(
 112          'title' => $lang->add_user_group,
 113          'link' => "index.php?module=user-groups&amp;action=add",
 114          'description' => $lang->add_user_group_desc
 115      );
 116  }
 117  
 118  $plugins->run_hooks("admin_user_groups_begin");
 119  
 120  if($mybb->input['action'] == "approve_join_request")
 121  {
 122      $query = $db->simple_select("joinrequests", "*", "rid='".$mybb->input['rid']."'");
 123      $request = $db->fetch_array($query);
 124  
 125      if(!$request)
 126      {
 127          flash_message($lang->error_invalid_join_request, 'error');
 128          admin_redirect("index.php?module=user-groups");
 129      }
 130  
 131      if(!verify_post_check($mybb->get_input('my_post_key')))
 132      {
 133          flash_message($lang->invalid_post_verify_key2, 'error');
 134          admin_redirect("index.php?module=user-groups&action=join_requests&gid={$request['gid']}");
 135      }
 136  
 137      $plugins->run_hooks("admin_user_groups_approve_join_request");
 138  
 139      // Add the user to the group
 140      join_usergroup($request['uid'], $request['gid']);
 141  
 142      // Delete the join request
 143      $db->delete_query("joinrequests", "rid='{$request['rid']}'");
 144  
 145      $plugins->run_hooks("admin_user_groups_approve_join_request_commit");
 146  
 147      flash_message($lang->success_join_request_approved, "success");
 148      admin_redirect("index.php?module=user-groups&action=join_requests&gid={$request['gid']}");
 149  }
 150  
 151  if($mybb->input['action'] == "deny_join_request")
 152  {
 153      $query = $db->simple_select("joinrequests", "*", "rid='".$mybb->input['rid']."'");
 154      $request = $db->fetch_array($query);
 155  
 156      if(!$request)
 157      {
 158          flash_message($lang->error_invalid_join_request, 'error');
 159          admin_redirect("index.php?module=user-groups");
 160      }
 161  
 162      if(!verify_post_check($mybb->get_input('my_post_key')))
 163      {
 164          flash_message($lang->invalid_post_verify_key2, 'error');
 165          admin_redirect("index.php?module=user-groups&action=join_requests&gid={$request['gid']}");
 166      }
 167  
 168      $plugins->run_hooks("admin_user_groups_deny_join_request");
 169  
 170      // Delete the join request
 171      $db->delete_query("joinrequests", "rid='{$request['rid']}'");
 172  
 173      $plugins->run_hooks("admin_user_groups_deny_join_request_commit");
 174  
 175      flash_message($lang->success_join_request_denied, "success");
 176      admin_redirect("index.php?module=user-groups&action=join_requests&gid={$request['gid']}");
 177  }
 178  
 179  if($mybb->input['action'] == "join_requests")
 180  {
 181      $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 182      $group = $db->fetch_array($query);
 183  
 184      if(!$group || $group['type'] != 4)
 185      {
 186          flash_message($lang->error_invalid_user_group, 'error');
 187          admin_redirect("index.php?module=user-groups");
 188      }
 189  
 190      $plugins->run_hooks("admin_user_groups_join_requests_start");
 191  
 192      if($mybb->request_method == "post" && is_array($mybb->input['users']))
 193      {
 194          $uid_in = implode(",", array_map('intval', $mybb->input['users']));
 195  
 196          if(isset($mybb->input['approve']))
 197          {
 198              foreach($mybb->input['users'] as $uid)
 199              {
 200                  $uid = (int)$uid;
 201                  join_usergroup($uid, $group['gid']);
 202              }
 203              // Log admin action
 204              log_admin_action("approve", $group['title'], $group['gid']);
 205              $message = $lang->success_selected_requests_approved;
 206          }
 207          else
 208          {
 209              // Log admin action
 210              log_admin_action("deny", $group['title'], $group['gid']);
 211              $message = $lang->success_selected_requests_denied;
 212          }
 213  
 214          $plugins->run_hooks("admin_user_groups_join_requests_commit");
 215  
 216          // Go through and delete the join requests from the database
 217          $db->delete_query("joinrequests", "uid IN ({$uid_in}) AND gid='{$group['gid']}'");
 218  
 219          $plugins->run_hooks("admin_user_groups_join_requests_commit_end");
 220  
 221          flash_message($message, 'success');
 222          admin_redirect("index.php?module=user-groups&action=join_requests&gid={$group['gid']}");
 223      }
 224  
 225      $page->add_breadcrumb_item($lang->join_requests_for.' '.htmlspecialchars_uni($group['title']));
 226      $page->output_header($lang->join_requests_for.' '.htmlspecialchars_uni($group['title']));
 227  
 228      $sub_tabs = array();
 229      $sub_tabs['join_requests'] = array(
 230          'title' => $lang->group_join_requests,
 231          'link' => "index.php?module=user-groups&action=join_requests&gid={$group['gid']}",
 232          'description' => $lang->group_join_requests_desc
 233      );
 234  
 235      $page->output_nav_tabs($sub_tabs, 'join_requests');
 236  
 237      $query = $db->simple_select("joinrequests", "COUNT(*) AS num_requests", "gid='{$group['gid']}'");
 238      $num_requests = $db->fetch_field($query, "num_requests");
 239  
 240      $per_page = 20;
 241      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 242      if($pagenum)
 243      {
 244          $start = ($pagenum - 1) * $per_page;
 245          $pages = ceil($num_requests / $per_page);
 246          if($pagenum > $pages)
 247          {
 248              $start = 0;
 249              $pagenum = 1;
 250          }
 251      }
 252      else
 253      {
 254          $start = 0;
 255          $pagenum = 1;
 256      }
 257  
 258      // Do we need to construct the pagination?
 259      $pagination = '';
 260      if($num_requests > $per_page)
 261      {
 262          $pagination = draw_admin_pagination($pagenum, $per_page, $num_requests, "index.php?module=user-groups&amp;action=join_requests&gid={$group['gid']}");
 263          echo $pagination;
 264      }
 265  
 266      $form = new Form("index.php?module=user-groups&amp;action=join_requests&gid={$group['gid']}", "post");
 267      $table = new Table;
 268      $table->construct_header($form->generate_check_box("allbox", 1, "", array('class' => 'checkall')), array('width' => 1));
 269      $table->construct_header($lang->users);
 270      $table->construct_header($lang->reason);
 271      $table->construct_header($lang->date_requested, array("class" => 'align_center', "width" => 200));
 272      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 200));
 273  
 274      $query = $db->query("
 275          SELECT j.*, u.username
 276          FROM ".TABLE_PREFIX."joinrequests j
 277          INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=j.uid)
 278          WHERE j.gid='{$group['gid']}'
 279          ORDER BY dateline ASC
 280          LIMIT {$start}, {$per_page}
 281      ");
 282  
 283      while($request = $db->fetch_array($query))
 284      {
 285          $table->construct_cell($form->generate_check_box("users[]", $request['uid'], ""));
 286          $table->construct_cell("<strong>".build_profile_link(htmlspecialchars_uni($request['username']), $request['uid'], "_blank")."</strong>");
 287          $table->construct_cell(htmlspecialchars_uni($request['reason']));
 288          $table->construct_cell(my_date('relative', $request['dateline']), array('class' => 'align_center'));
 289  
 290          $popup = new PopupMenu("join_{$request['rid']}", $lang->options);
 291          $popup->add_item($lang->approve, "index.php?module=user-groups&action=approve_join_request&amp;rid={$request['rid']}&amp;my_post_key={$mybb->post_code}");
 292          $popup->add_item($lang->deny, "index.php?module=user-groups&action=deny_join_request&amp;rid={$request['rid']}&amp;my_post_key={$mybb->post_code}");
 293  
 294          $table->construct_cell($popup->fetch(), array('class' => "align_center"));
 295          $table->construct_row();
 296      }
 297  
 298      if($table->num_rows() == 0)
 299      {
 300          $table->construct_cell($lang->no_join_requests, array("colspan" => 6));
 301          $table->construct_row();
 302      }
 303  
 304      $table->output($lang->join_requests_for.' '.htmlspecialchars_uni($group['title']));
 305      echo $pagination;
 306  
 307      $buttons[] = $form->generate_submit_button($lang->approve_selected_requests, array('name' => 'approve'));
 308      $buttons[] = $form->generate_submit_button($lang->deny_selected_requests, array('name' => 'deny'));
 309      $form->output_submit_wrapper($buttons);
 310      $form->end();
 311  
 312      $page->output_footer();
 313  }
 314  if($mybb->input['action'] == "add_leader" && $mybb->request_method == "post")
 315  {
 316      $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 317      $group = $db->fetch_array($query);
 318  
 319      if(!$group)
 320      {
 321          flash_message($lang->error_invalid_user_group, 'error');
 322          admin_redirect("index.php?module=user-group");
 323      }
 324  
 325      $plugins->run_hooks("admin_user_groups_add_leader");
 326  
 327      $user = get_user_by_username($mybb->input['username'], array('fields' => 'username'));
 328      if(!$user)
 329      {
 330          $errors[] = $lang->error_invalid_username;
 331      }
 332      else
 333      {
 334          // Is this user already a leader of this group?
 335          $query = $db->simple_select("groupleaders", "uid", "uid='{$user['uid']}' AND gid='{$group['gid']}'");
 336          $existing_leader = $db->fetch_field($query, "uid");
 337          if($existing_leader)
 338          {
 339              $errors[] = $lang->error_already_leader;
 340          }
 341      }
 342  
 343      // No errors, insert
 344      if(!$errors)
 345      {
 346          $new_leader = array(
 347              "gid" => $group['gid'],
 348              "uid" => $user['uid'],
 349              "canmanagemembers" => $mybb->get_input('canmanagemembers', MyBB::INPUT_INT),
 350              "canmanagerequests" => $mybb->get_input('canmanagerequests', MyBB::INPUT_INT),
 351              "caninvitemembers" => $mybb->get_input('caninvitemembers', MyBB::INPUT_INT)
 352          );
 353  
 354          $makeleadermember = $mybb->get_input('makeleadermember', MyBB::INPUT_INT);
 355          if($makeleadermember == 1)
 356          {
 357              join_usergroup($user['uid'], $group['gid']);
 358          }
 359  
 360          $plugins->run_hooks("admin_user_groups_add_leader_commit");
 361  
 362          $db->insert_query("groupleaders", $new_leader);
 363  
 364          $cache->update_groupleaders();
 365  
 366          // Log admin action
 367          log_admin_action($user['uid'], $user['username'], $group['gid'], $group['title']);
 368  
 369          $username = htmlspecialchars_uni($user['username']);
 370          flash_message("{$username} ".$lang->success_user_made_leader, 'success');
 371          admin_redirect("index.php?module=user-groups&action=leaders&gid={$group['gid']}");
 372      }
 373      else
 374      {
 375          // Errors, show leaders page
 376          $mybb->input['action'] = "leaders";
 377      }
 378  }
 379  
 380  // Show a listing of group leaders
 381  if($mybb->input['action'] == "leaders")
 382  {
 383      $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 384      $group = $db->fetch_array($query);
 385  
 386      if(!$group)
 387      {
 388          flash_message($lang->error_invalid_user_group, 'error');
 389          admin_redirect("index.php?module=user-groups");
 390      }
 391  
 392      $plugins->run_hooks("admin_user_groups_leaders");
 393  
 394      $page->add_breadcrumb_item($lang->group_leaders_for.' '.htmlspecialchars_uni($group['title']));
 395      $page->output_header($lang->group_leaders_for.' '.htmlspecialchars_uni($group['title']));
 396  
 397      $sub_tabs = array();
 398      $sub_tabs['group_leaders'] = array(
 399          'title' => $lang->manage_group_leaders,
 400          'link' => "index.php?module=user-groups&action=leaders&gid={$group['gid']}",
 401          'description' => $lang->manage_group_leaders_desc
 402      );
 403  
 404      $page->output_nav_tabs($sub_tabs, 'group_leaders');
 405  
 406      $table = new Table;
 407      $table->construct_header($lang->user);
 408      $table->construct_header($lang->can_manage_members, array("class" => 'align_center', "width" => 200));
 409      $table->construct_header($lang->can_manage_join_requests, array("class" => 'align_center', "width" => 200));
 410      $table->construct_header($lang->can_invite_members, array("class" => 'align_center', "width" => 200));
 411      $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2, "width" => 200));
 412  
 413      $query = $db->query("
 414          SELECT g.*, u.username
 415          FROM ".TABLE_PREFIX."groupleaders g
 416          INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=g.uid)
 417          WHERE g.gid='{$group['gid']}'
 418          ORDER BY u.username ASC
 419      ");
 420      while($leader = $db->fetch_array($query))
 421      {
 422          $leader['username'] = htmlspecialchars_uni($leader['username']);
 423          if($leader['canmanagemembers'])
 424          {
 425              $canmanagemembers = $lang->yes;
 426          }
 427          else
 428          {
 429              $canmanagemembers = $lang->no;
 430          }
 431  
 432          if($leader['canmanagerequests'])
 433          {
 434              $canmanagerequests = $lang->yes;
 435          }
 436          else
 437          {
 438              $canmanagerequests = $lang->no;
 439          }
 440  
 441          if($leader['caninvitemembers'])
 442          {
 443              $caninvitemembers = $lang->yes;
 444          }
 445          else
 446          {
 447              $caninvitemembers = $lang->no;
 448          }
 449  
 450          $table->construct_cell("<strong>".build_profile_link($leader['username'], $leader['uid'], "_blank")."</strong>");
 451          $table->construct_cell($canmanagemembers, array("class" => "align_center"));
 452          $table->construct_cell($canmanagerequests, array("class" => "align_center"));
 453          $table->construct_cell($caninvitemembers, array("class" => "align_center"));
 454          $table->construct_cell("<a href=\"index.php?module=user-groups&amp;action=edit_leader&lid={$leader['lid']}\">{$lang->edit}</a>", array("width" => 100, "class" => "align_center"));
 455          $table->construct_cell("<a href=\"index.php?module=user-groups&amp;action=delete_leader&amp;lid={$leader['lid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_group_leader_deletion}')\">{$lang->delete}</a>", array("width" => 100, "class" => "align_center"));
 456          $table->construct_row();
 457      }
 458  
 459      if($table->num_rows() == 0)
 460      {
 461          $table->construct_cell($lang->no_assigned_leaders, array("colspan" => 5));
 462          $table->construct_row();
 463      }
 464  
 465      $table->output($lang->group_leaders_for.' '.htmlspecialchars_uni($group['title']));
 466  
 467      $form = new Form("index.php?module=user-groups&amp;action=add_leader&amp;gid={$group['gid']}", "post");
 468  
 469      if($errors)
 470      {
 471          $page->output_inline_error($errors);
 472      }
 473      else
 474      {
 475          $mybb->input = array_merge($mybb->input, array(
 476                  "canmanagemembers" => 1,
 477                  "canmanagerequests" => 1,
 478                  "caninvitemembers" => 1,
 479                  "makeleadermember" => 0
 480              )
 481          );
 482      }
 483  
 484      $form_container = new FormContainer($lang->add_group_leader.' '.htmlspecialchars_uni($group['title']));
 485      $form_container->output_row($lang->username." <em>*</em>", "", $form->generate_text_box('username', htmlspecialchars_uni($mybb->get_input('username')), array('id' => 'username')), 'username');
 486      $form_container->output_row($lang->can_manage_group_members, $lang->can_manage_group_members_desc, $form->generate_yes_no_radio('canmanagemembers', $mybb->input['canmanagemembers']));
 487      $form_container->output_row($lang->can_manage_group_join_requests, $lang->can_manage_group_join_requests_desc, $form->generate_yes_no_radio('canmanagerequests', $mybb->input['canmanagerequests']));
 488      $form_container->output_row($lang->can_invite_group_members, $lang->can_invite_group_members_desc, $form->generate_yes_no_radio('caninvitemembers', $mybb->input['caninvitemembers']));
 489      $form_container->output_row($lang->make_user_member, $lang->make_user_member_desc, $form->generate_yes_no_radio('makeleadermember', $mybb->input['makeleadermember']));
 490      $form_container->end();
 491  
 492      // Autocompletion for usernames
 493      echo '
 494      <link rel="stylesheet" href="../jscripts/select2/select2.css">
 495      <script type="text/javascript" src="../jscripts/select2/select2.min.js?ver=1804"></script>
 496      <script type="text/javascript">
 497      <!--
 498      $("#username").select2({
 499          placeholder: "'.$lang->search_for_a_user.'",
 500          minimumInputLength: 2,
 501          multiple: false,
 502          ajax: { // instead of writing the function to execute the request we use Select2\'s convenient helper
 503              url: "../xmlhttp.php?action=get_users",
 504              dataType: \'json\',
 505              data: function (term, page) {
 506                  return {
 507                      query: term // search term
 508                  };
 509              },
 510              results: function (data, page) { // parse the results into the format expected by Select2.
 511                  // since we are using custom formatting functions we do not need to alter remote JSON data
 512                  return {results: data};
 513              }
 514          },
 515          initSelection: function(element, callback) {
 516              var query = $(element).val();
 517              if (query !== "") {
 518                  $.ajax("../xmlhttp.php?action=get_users&getone=1", {
 519                      data: {
 520                          query: query
 521                      },
 522                      dataType: "json"
 523                  }).done(function(data) { callback(data); });
 524              }
 525          }
 526      });
 527      // -->
 528      </script>';
 529  
 530      $buttons[] = $form->generate_submit_button($lang->save_group_leader);
 531      $form->output_submit_wrapper($buttons);
 532      $form->end();
 533  
 534      $page->output_footer();
 535  }
 536  
 537  if($mybb->input['action'] == "delete_leader")
 538  {
 539      $query = $db->query("
 540          SELECT l.*, u.username
 541          FROM ".TABLE_PREFIX."groupleaders l
 542          INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
 543          WHERE l.lid='".$mybb->get_input('lid', MyBB::INPUT_INT)."'");
 544      $leader = $db->fetch_array($query);
 545  
 546      if(!$leader)
 547      {
 548          flash_message($lang->error_invalid_group_leader, 'error');
 549          admin_redirect("index.php?module=user-groups");
 550      }
 551  
 552      $query = $db->simple_select("usergroups", "*", "gid='{$leader['gid']}'");
 553      $group = $db->fetch_array($query);
 554  
 555      // User clicked no
 556      if($mybb->get_input('no'))
 557      {
 558          admin_redirect("index.php?module=user-groups");
 559      }
 560  
 561      $plugins->run_hooks("admin_user_groups_delete_leader");
 562  
 563      if($mybb->request_method == "post")
 564      {
 565          $plugins->run_hooks("admin_user_groups_delete_leader_commit");
 566  
 567          // Delete the leader
 568          $db->delete_query("groupleaders", "lid='{$leader['lid']}'");
 569  
 570          $plugins->run_hooks("admin_user_groups_delete_leader_commit_end");
 571  
 572          $cache->update_groupleaders();
 573  
 574          // Log admin action
 575          log_admin_action($leader['uid'], $leader['username'], $group['gid'], $group['title']);
 576  
 577          flash_message($lang->success_group_leader_deleted, 'success');
 578          admin_redirect("index.php?module=user-groups&action=leaders&gid={$group['gid']}");
 579      }
 580      else
 581      {
 582          $page->output_confirm_action("index.php?module=user-groups&amp;action=delete_leader&amp;lid={$leader['lid']}", $lang->confirm_group_leader_deletion);
 583      }
 584  }
 585  
 586  if($mybb->input['action'] == "edit_leader")
 587  {
 588      $query = $db->query("
 589          SELECT l.*, u.username
 590          FROM ".TABLE_PREFIX."groupleaders l
 591          INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
 592          WHERE l.lid='".$mybb->get_input('lid', MyBB::INPUT_INT)."'
 593      ");
 594      $leader = $db->fetch_array($query);
 595  
 596      if(!$leader)
 597      {
 598          flash_message($lang->error_invalid_group_leader, 'error');
 599          admin_redirect("index.php?module=user-groups");
 600      }
 601  
 602      $query = $db->simple_select("usergroups", "*", "gid='{$leader['gid']}'");
 603      $group = $db->fetch_array($query);
 604  
 605      $plugins->run_hooks("admin_user_groups_edit_leader");
 606  
 607      if($mybb->request_method == "post")
 608      {
 609          $updated_leader = array(
 610              "canmanagemembers" => $mybb->get_input('canmanagemembers', MyBB::INPUT_INT),
 611              "canmanagerequests" => $mybb->get_input('canmanagerequests', MyBB::INPUT_INT),
 612              "caninvitemembers" => $mybb->get_input('caninvitemembers', MyBB::INPUT_INT)
 613          );
 614  
 615          $plugins->run_hooks("admin_user_groups_edit_leader_commit");
 616  
 617          $db->update_query("groupleaders", $updated_leader, "lid={$leader['lid']}");
 618  
 619          $cache->update_groupleaders();
 620  
 621          // Log admin action
 622          log_admin_action($leader['uid'], $leader['username'], $group['gid'], $group['title']);
 623  
 624          flash_message($lang->success_group_leader_updated, 'success');
 625          admin_redirect("index.php?module=user-groups&action=leaders&gid={$group['gid']}");
 626      }
 627  
 628      if(!$errors)
 629      {
 630          $mybb->input = array_merge($mybb->input, $leader);
 631      }
 632  
 633      $page->add_breadcrumb_item($lang->group_leaders_for.' '.htmlspecialchars_uni($group['title']), "index.php?module=user-groups&action=leaders&gid={$group['gid']}");
 634      $leader['username'] = htmlspecialchars_uni($leader['username']);
 635      $page->add_breadcrumb_item($lang->edit_leader." {$leader['username']}");
 636  
 637      $page->output_header($lang->edit_group_leader);
 638  
 639      $sub_tabs = array();
 640      $sub_tabs['group_leaders'] = array(
 641          'title' => $lang->edit_group_leader,
 642          'link' => "index.php?module=user-groups&action=edit_leader&lid={$leader['lid']}",
 643          'description' => $lang->edit_group_leader_desc
 644      );
 645  
 646      $page->output_nav_tabs($sub_tabs, 'group_leaders');
 647  
 648      $form = new Form("index.php?module=user-groups&amp;action=edit_leader&amp;lid={$leader['lid']}", "post");
 649  
 650      $form_container = new FormContainer($lang->edit_group_leader);
 651      $form_container->output_row($lang->username." <em>*</em>", "", $leader['username']);
 652  
 653      $form_container->output_row($lang->can_manage_group_members, $lang->can_manage_group_members_desc, $form->generate_yes_no_radio('canmanagemembers', $mybb->input['canmanagemembers']));
 654      $form_container->output_row($lang->can_manage_group_join_requests, $lang->can_manage_group_join_requests_desc, $form->generate_yes_no_radio('canmanagerequests', $mybb->input['canmanagerequests']));
 655      $form_container->output_row($lang->can_invite_group_members, $lang->can_invite_group_members_desc, $form->generate_yes_no_radio('caninvitemembers', $mybb->input['caninvitemembers']));
 656      $buttons[] = $form->generate_submit_button($lang->save_group_leader);
 657  
 658      $form_container->end();
 659      $form->output_submit_wrapper($buttons);
 660      $form->end();
 661  
 662      $page->output_footer();
 663  }
 664  
 665  if($mybb->input['action'] == "add")
 666  {
 667      $plugins->run_hooks("admin_user_groups_add");
 668  
 669      if($mybb->request_method == "post")
 670      {
 671          if(!trim($mybb->input['title']))
 672          {
 673              $errors[] = $lang->error_missing_title;
 674          }
 675  
 676          if(my_strpos($mybb->input['namestyle'], "{username}") === false)
 677          {
 678              $errors[] = $lang->error_missing_namestyle_username;
 679          }
 680  
 681          if(!$errors)
 682          {
 683              if($mybb->get_input('stars') < 1)
 684              {
 685                  $mybb->input['stars'] = 0;
 686              }
 687  
 688              if(!$mybb->get_input('starimage'))
 689              {
 690                  $mybb->input['starimage'] = "images/star.png";
 691              }
 692  
 693              $new_usergroup = array(
 694                  "type" => 2,
 695                  "title" => $db->escape_string($mybb->input['title']),
 696                  "description" => $db->escape_string($mybb->input['description']),
 697                  "namestyle" => $db->escape_string($mybb->input['namestyle']),
 698                  "usertitle" => $db->escape_string($mybb->input['usertitle']),
 699                  "stars" => $mybb->get_input('stars', MyBB::INPUT_INT),
 700                  "starimage" => $db->escape_string($mybb->input['starimage']),
 701                  "disporder" => 0
 702              );
 703  
 704              // Set default permissions
 705              if($mybb->input['copyfrom'] == 0)
 706              {
 707                  $new_usergroup = array_merge($new_usergroup, $usergroup_permissions);
 708              }
 709              // Copying permissions from another group
 710              else
 711              {
 712                  $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('copyfrom', MyBB::INPUT_INT)."'");
 713                  $existing_usergroup = $db->fetch_array($query);
 714                  foreach(array_keys($usergroup_permissions) as $field)
 715                  {
 716                      $new_usergroup[$field] = $existing_usergroup[$field];
 717                  }
 718              }
 719  
 720              $plugins->run_hooks("admin_user_groups_add_commit");
 721  
 722              $gid = $db->insert_query("usergroups", $new_usergroup);
 723  
 724              $plugins->run_hooks("admin_user_groups_add_commit_end");
 725  
 726              // Are we copying permissions? If so, copy all forum permissions too
 727              if($mybb->input['copyfrom'] > 0)
 728              {
 729                  $query = $db->simple_select("forumpermissions", "*", "gid='".$mybb->get_input('copyfrom', MyBB::INPUT_INT)."'");
 730                  while($forum_permission = $db->fetch_array($query))
 731                  {
 732                      unset($forum_permission['pid']);
 733                      $forum_permission['gid'] = $gid;
 734                      $db->insert_query("forumpermissions", $forum_permission);
 735                  }
 736              }
 737  
 738              // Update the caches
 739              $cache->update_usergroups();
 740              $cache->update_forumpermissions();
 741  
 742              // Log admin action
 743              log_admin_action($gid, $mybb->input['title']);
 744  
 745              $groups = $cache->read('usergroups');
 746              $grouptitles = array_column($groups, 'title');
 747  
 748              $message = $lang->success_group_created;
 749              if(in_array($mybb->input['title'], $grouptitles) && count(array_keys($grouptitles, $mybb->input['title'])) > 1)
 750              {
 751                  $message = $lang->sprintf($lang->success_group_created_duplicate_title, htmlspecialchars_uni($mybb->input['title']));
 752              }
 753  
 754              flash_message($message, 'success');
 755              admin_redirect("index.php?module=user-groups&action=edit&gid={$gid}");
 756          }
 757      }
 758  
 759      $page->add_breadcrumb_item($lang->add_user_group);
 760      $page->output_header($lang->add_user_group);
 761  
 762      $page->output_nav_tabs($sub_tabs, 'add_group');
 763      $form = new Form("index.php?module=user-groups&amp;action=add", "post");
 764  
 765      if($errors)
 766      {
 767          $page->output_inline_error($errors);
 768      }
 769      else
 770      {
 771          $mybb->input = array_merge($mybb->input, array(
 772                  "namestyle" => "{username}"
 773              )
 774          );
 775      }
 776  
 777      $form_container = new FormContainer($lang->add_user_group);
 778      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 779      $form_container->output_row($lang->short_description, "", $form->generate_text_box('description', $mybb->get_input('description'), array('id' => 'description')), 'description');
 780      $form_container->output_row($lang->username_style, $lang->username_style_desc, $form->generate_text_box('namestyle', $mybb->get_input('namestyle'), array('id' => 'namestyle')), 'namestyle');
 781      $form_container->output_row($lang->user_title, $lang->user_title_desc, $form->generate_text_box('usertitle', $mybb->get_input('usertitle'), array('id' => 'usertitle')), 'usertitle');
 782  
 783      $options[0] = $lang->do_not_copy_permissions;
 784      $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
 785      while($usergroup = $db->fetch_array($query))
 786      {
 787          $options[$usergroup['gid']] = htmlspecialchars_uni($usergroup['title']);
 788      }
 789      $form_container->output_row($lang->copy_permissions_from, $lang->copy_permissions_from_desc, $form->generate_select_box('copyfrom', $options, $mybb->get_input('copyfrom'), array('id' => 'copyfrom')), 'copyfrom');
 790  
 791      $form_container->end();
 792      $buttons[] = $form->generate_submit_button($lang->save_user_group);
 793      $form->output_submit_wrapper($buttons);
 794  
 795      $form->end();
 796      $page->output_footer();
 797  }
 798  
 799  if($mybb->input['action'] == "edit")
 800  {
 801      $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
 802      $usergroup = $db->fetch_array($query);
 803  
 804      if(!$usergroup)
 805      {
 806          flash_message($lang->error_invalid_user_group, 'error');
 807          admin_redirect("index.php?module=user-group");
 808      }
 809      else
 810      {
 811          if(preg_match("#<((m[^a])|(b[^diloru>])|(s[^aemptu >]))(\s*[^>]*)>#si", $mybb->get_input('namestyle')))
 812          {
 813              $errors[] = $lang->error_disallowed_namestyle_username;
 814              $mybb->input['namestyle'] = $usergroup['namestyle'];
 815          }
 816      }
 817  
 818      $plugins->run_hooks("admin_user_groups_edit");
 819  
 820      if($mybb->request_method == "post")
 821      {
 822          if(!trim($mybb->get_input('title')))
 823          {
 824              $errors[] = $lang->error_missing_title;
 825          }
 826  
 827          if(my_strpos($mybb->get_input('namestyle'), "{username}") === false)
 828          {
 829              $errors[] = $lang->error_missing_namestyle_username;
 830          }
 831  
 832          if($mybb->get_input('moderate') == 1 && $mybb->get_input('invite') == 1)
 833          {
 834              $errors[] = $lang->error_cannot_have_both_types;
 835          }
 836  
 837          if(!$errors)
 838          {
 839              if($mybb->get_input('joinable') == 1)
 840              {
 841                  if($mybb->get_input('moderate') == 1)
 842                  {
 843                      $mybb->input['type'] = "4";
 844                  }
 845                  elseif($mybb->get_input('invite') == 1)
 846                  {
 847                      $mybb->input['type'] = "5";
 848                  }
 849                  else
 850                  {
 851                      $mybb->input['type'] = "3";
 852                  }
 853              }
 854              else
 855              {
 856                  $mybb->input['type'] = "2";
 857              }
 858  
 859              if($usergroup['type'] == 1)
 860              {
 861                  $mybb->input['type'] = 1;
 862              }
 863  
 864              if($mybb->get_input('stars') < 1)
 865              {
 866                  $mybb->input['stars'] = 0;
 867              }
 868  
 869              $updated_group = array(
 870                  "type" => $mybb->get_input('type', MyBB::INPUT_INT),
 871                  "title" => $db->escape_string($mybb->input['title']),
 872                  "description" => $db->escape_string($mybb->input['description']),
 873                  "namestyle" => $db->escape_string($mybb->input['namestyle']),
 874                  "usertitle" => $db->escape_string($mybb->input['usertitle']),
 875                  "stars" => $mybb->get_input('stars', MyBB::INPUT_INT),
 876                  "starimage" => $db->escape_string($mybb->input['starimage']),
 877                  "image" => $db->escape_string($mybb->input['image']),
 878                  "isbannedgroup" => $mybb->get_input('isbannedgroup', MyBB::INPUT_INT),
 879                  "canview" => $mybb->get_input('canview', MyBB::INPUT_INT),
 880                  "canviewthreads" => $mybb->get_input('canviewthreads', MyBB::INPUT_INT),
 881                  "canviewprofiles" => $mybb->get_input('canviewprofiles', MyBB::INPUT_INT),
 882                  "candlattachments" => $mybb->get_input('candlattachments', MyBB::INPUT_INT),
 883                  "canviewboardclosed" => $mybb->get_input('canviewboardclosed', MyBB::INPUT_INT),
 884                  "canpostthreads" => $mybb->get_input('canpostthreads', MyBB::INPUT_INT),
 885                  "canpostreplys" => $mybb->get_input('canpostreplys', MyBB::INPUT_INT),
 886                  "canpostattachments" => $mybb->get_input('canpostattachments', MyBB::INPUT_INT),
 887                  "canratethreads" => $mybb->get_input('canratethreads', MyBB::INPUT_INT),
 888                  "modposts" => $mybb->get_input('modposts', MyBB::INPUT_INT),
 889                  "modthreads" => $mybb->get_input('modthreads', MyBB::INPUT_INT),
 890                  "mod_edit_posts" => $mybb->get_input('mod_edit_posts', MyBB::INPUT_INT),
 891                  "modattachments" => $mybb->get_input('modattachments', MyBB::INPUT_INT),
 892                  "caneditposts" => $mybb->get_input('caneditposts', MyBB::INPUT_INT),
 893                  "candeleteposts" => $mybb->get_input('candeleteposts', MyBB::INPUT_INT),
 894                  "candeletethreads" => $mybb->get_input('candeletethreads', MyBB::INPUT_INT),
 895                  "caneditattachments" => $mybb->get_input('caneditattachments', MyBB::INPUT_INT),
 896                  "canviewdeletionnotice" => $mybb->get_input('canviewdeletionnotice', MyBB::INPUT_INT),
 897                  "canpostpolls" => $mybb->get_input('canpostpolls', MyBB::INPUT_INT),
 898                  "canvotepolls" => $mybb->get_input('canvotepolls', MyBB::INPUT_INT),
 899                  "canundovotes" => $mybb->get_input('canundovotes', MyBB::INPUT_INT),
 900                  "canusepms" => $mybb->get_input('canusepms', MyBB::INPUT_INT),
 901                  "cansendpms" => $mybb->get_input('cansendpms', MyBB::INPUT_INT),
 902                  "cantrackpms" => $mybb->get_input('cantrackpms', MyBB::INPUT_INT),
 903                  "candenypmreceipts" => $mybb->get_input('candenypmreceipts', MyBB::INPUT_INT),
 904                  "pmquota" => $mybb->get_input('pmquota', MyBB::INPUT_INT),
 905                  "maxpmrecipients" => $mybb->get_input('maxpmrecipients', MyBB::INPUT_INT),
 906                  "cansendemail" => $mybb->get_input('cansendemail', MyBB::INPUT_INT),
 907                  "cansendemailoverride" => $mybb->get_input('cansendemailoverride', MyBB::INPUT_INT),
 908                  "maxemails" => $mybb->get_input('maxemails', MyBB::INPUT_INT),
 909                  "emailfloodtime" => $mybb->get_input('emailfloodtime', MyBB::INPUT_INT),
 910                  "canviewmemberlist" => $mybb->get_input('canviewmemberlist', MyBB::INPUT_INT),
 911                  "canviewcalendar" => $mybb->get_input('canviewcalendar', MyBB::INPUT_INT),
 912                  "canaddevents" => $mybb->get_input('canaddevents', MyBB::INPUT_INT),
 913                  "canbypasseventmod" => $mybb->get_input('canbypasseventmod', MyBB::INPUT_INT),
 914                  "canmoderateevents" => $mybb->get_input('canmoderateevents', MyBB::INPUT_INT),
 915                  "canviewonline" => $mybb->get_input('canviewonline', MyBB::INPUT_INT),
 916                  "canviewwolinvis" => $mybb->get_input('canviewwolinvis', MyBB::INPUT_INT),
 917                  "canviewonlineips" => $mybb->get_input('canviewonlineips', MyBB::INPUT_INT),
 918                  "cancp" => $mybb->get_input('cancp', MyBB::INPUT_INT),
 919                  "issupermod" => $mybb->get_input('issupermod', MyBB::INPUT_INT),
 920                  "cansearch" => $mybb->get_input('cansearch', MyBB::INPUT_INT),
 921                  "canusercp" => $mybb->get_input('canusercp', MyBB::INPUT_INT),
 922                  "canuploadavatars" => $mybb->get_input('canuploadavatars', MyBB::INPUT_INT),
 923                  "canchangename" => $mybb->get_input('canchangename', MyBB::INPUT_INT),
 924                  "canbereported" => $mybb->get_input('canbereported', MyBB::INPUT_INT),
 925                  "canbeinvisible" => $mybb->get_input('canbeinvisible', MyBB::INPUT_INT),
 926                  "canchangewebsite" => $mybb->get_input('canchangewebsite', MyBB::INPUT_INT),
 927                  "showforumteam" => $mybb->get_input('showforumteam', MyBB::INPUT_INT),
 928                  "usereputationsystem" => $mybb->get_input('usereputationsystem', MyBB::INPUT_INT),
 929                  "cangivereputations" => $mybb->get_input('cangivereputations', MyBB::INPUT_INT),
 930                  "candeletereputations" => $mybb->get_input('candeletereputations', MyBB::INPUT_INT),
 931                  "reputationpower" => $mybb->get_input('reputationpower', MyBB::INPUT_INT),
 932                  "maxreputationsday" => $mybb->get_input('maxreputationsday', MyBB::INPUT_INT),
 933                  "maxreputationsperuser" => $mybb->get_input('maxreputationsperuser', MyBB::INPUT_INT),
 934                  "maxreputationsperthread" => $mybb->get_input('maxreputationsperthread', MyBB::INPUT_INT),
 935                  "attachquota" => $mybb->get_input('attachquota', MyBB::INPUT_INT),
 936                  "cancustomtitle" => $mybb->get_input('cancustomtitle', MyBB::INPUT_INT),
 937                  "canwarnusers" => $mybb->get_input('canwarnusers', MyBB::INPUT_INT),
 938                  "canreceivewarnings" =>$mybb->get_input('canreceivewarnings', MyBB::INPUT_INT),
 939                  "maxwarningsday" => $mybb->get_input('maxwarningsday', MyBB::INPUT_INT),
 940                  "canmodcp" => $mybb->get_input('canmodcp', MyBB::INPUT_INT),
 941                  "showinbirthdaylist" => $mybb->get_input('showinbirthdaylist', MyBB::INPUT_INT),
 942                  "canoverridepm" => $mybb->get_input('canoverridepm', MyBB::INPUT_INT),
 943                  "canusesig" => $mybb->get_input('canusesig', MyBB::INPUT_INT),
 944                  "canusesigxposts" => $mybb->get_input('canusesigxposts', MyBB::INPUT_INT),
 945                  "signofollow" => $mybb->get_input('signofollow', MyBB::INPUT_INT),
 946                  "edittimelimit" => $mybb->get_input('edittimelimit', MyBB::INPUT_INT),
 947                  "maxposts" => $mybb->get_input('maxposts', MyBB::INPUT_INT),
 948                  "showmemberlist" => $mybb->get_input('showmemberlist', MyBB::INPUT_INT),
 949                  "canmanageannounce" => $mybb->get_input('canmanageannounce', MyBB::INPUT_INT),
 950                  "canmanagemodqueue" => $mybb->get_input('canmanagemodqueue', MyBB::INPUT_INT),
 951                  "canmanagereportedcontent" => $mybb->get_input('canmanagereportedcontent', MyBB::INPUT_INT),
 952                  "canviewmodlogs" => $mybb->get_input('canviewmodlogs', MyBB::INPUT_INT),
 953                  "caneditprofiles" => $mybb->get_input('caneditprofiles', MyBB::INPUT_INT),
 954                  "canbanusers" => $mybb->get_input('canbanusers', MyBB::INPUT_INT),
 955                  "canviewwarnlogs" => $mybb->get_input('canviewwarnlogs', MyBB::INPUT_INT),
 956                  "canuseipsearch" => $mybb->get_input('canuseipsearch', MyBB::INPUT_INT)
 957              );
 958  
 959              // Only update the candisplaygroup setting if not a default user group
 960              if($usergroup['type'] != 1)
 961              {
 962                  $updated_group['candisplaygroup'] = $mybb->get_input('candisplaygroup', MyBB::INPUT_INT);
 963              }
 964  
 965              $plugins->run_hooks("admin_user_groups_edit_commit");
 966  
 967              $db->update_query("usergroups", $updated_group, "gid='{$usergroup['gid']}'");
 968  
 969              // Update the caches
 970              $cache->update_usergroups();
 971              $cache->update_forumpermissions();
 972  
 973              // Log admin action
 974              log_admin_action($usergroup['gid'], $mybb->input['title']);
 975  
 976              $groups = $cache->read('usergroups');
 977              $grouptitles = array_column($groups, 'title');
 978  
 979              $message = $lang->success_group_updated;
 980              if(in_array($mybb->input['title'], $grouptitles) && count(array_keys($grouptitles, $mybb->input['title'])) > 1)
 981              {
 982                  $message = $lang->sprintf($lang->success_group_updated_duplicate_title, htmlspecialchars_uni($mybb->input['title']));
 983              }
 984  
 985              flash_message($message, 'success');
 986              admin_redirect("index.php?module=user-groups");
 987          }
 988      }
 989  
 990      $page->add_breadcrumb_item($lang->edit_user_group);
 991      $page->output_header($lang->edit_user_group);
 992  
 993      $sub_tabs = array();
 994      $sub_tabs['edit_group'] = array(
 995          'title' => $lang->edit_user_group,
 996          'description' => $lang->edit_user_group_desc
 997      );
 998  
 999      $form = new Form("index.php?module=user-groups&amp;action=edit&amp;gid={$usergroup['gid']}", "post");
1000  
1001      $page->output_nav_tabs($sub_tabs, 'edit_group');
1002  
1003      // If we have any error messages, show them
1004      if($errors)
1005      {
1006          $page->output_inline_error($errors);
1007      }
1008      else
1009      {
1010          if($usergroup['type'] == "3")
1011          {
1012              $usergroup['joinable'] = 1;
1013              $usergroup['moderate'] = 0;
1014              $usergroup['invite'] = 0;
1015          }
1016          elseif($usergroup['type'] == "4")
1017          {
1018              $usergroup['joinable'] = 1;
1019              $usergroup['moderate'] = 1;
1020              $usergroup['invite'] = 0;
1021          }
1022          elseif($usergroup['type'] == "5")
1023          {
1024              $usergroup['joinable'] = 1;
1025              $usergroup['moderate'] = 0;
1026              $usergroup['invite'] = 1;
1027          }
1028          else
1029          {
1030              $usergroup['joinable'] = 0;
1031              $usergroup['moderate'] = 0;
1032              $usergroup['invite'] = 0;
1033          }
1034          $mybb->input = array_merge($mybb->input, $usergroup);
1035      }
1036      $tabs = array(
1037          "general" => $lang->general,
1038          "forums_posts" => $lang->forums_posts,
1039          "users_permissions" => $lang->users_permissions,
1040          "misc" => $lang->misc,
1041          "modcp" => $lang->mod_cp
1042      );
1043      $tabs = $plugins->run_hooks("admin_user_groups_edit_graph_tabs", $tabs);
1044      $page->output_tab_control($tabs);
1045  
1046      echo "<div id=\"tab_general\">
1047      <script type=\"text/javascript\">
1048          $(function(){
1049              $('input[name=\"moderate\"]').parents(\".group_settings_bit\").addClass(\"joinable_dependent\");
1050              $('input[name=\"invite\"]').parents(\".group_settings_bit\").addClass(\"joinable_dependent\");
1051              if($('input[name=\"joinable\"]').prop(\"checked\") == false){
1052                  $(\".joinable_dependent\").hide();
1053              }
1054              $('input[name=\"joinable\"]').on('change', function() {
1055                  $(\".joinable_dependent\").slideToggle();
1056              })
1057          });
1058      </script>";
1059      $form_container = new FormContainer($lang->general);
1060      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
1061      $form_container->output_row($lang->short_description, "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
1062      $form_container->output_row($lang->username_style, $lang->username_style_desc, $form->generate_text_box('namestyle', $mybb->input['namestyle'], array('id' => 'namestyle')), 'namestyle');
1063      $form_container->output_row($lang->user_title, $lang->user_title_desc, $form->generate_text_box('usertitle', $mybb->input['usertitle'], array('id' => 'usertitle')), 'usertitle');
1064  
1065      $stars = "<table cellpadding=\"3\"><tr><td>".$form->generate_numeric_field('stars', $mybb->input['stars'], array('class' => 'field50', 'id' => 'stars', 'min' => 0))."</td><td>".$form->generate_text_box('starimage', $mybb->input['starimage'], array('id' => 'starimage'))."</td></tr>";
1066      $stars .= "<tr><td><small>{$lang->stars}</small></td><td><small>{$lang->star_image}</small></td></tr></table>";
1067      $form_container->output_row($lang->user_stars, $lang->user_stars_desc, $stars, "stars");
1068  
1069      $form_container->output_row($lang->group_image, $lang->group_image_desc, $form->generate_text_box('image', $mybb->input['image'], array('id' => 'image')), 'image');
1070  
1071      $general_options = array();
1072      $general_options[] = $form->generate_check_box("showmemberlist", 1, $lang->member_list, array("checked" => $mybb->input['showmemberlist']));
1073      if($usergroup['gid'] != "1" && $usergroup['gid'] != "5")
1074      {
1075          $general_options[] = $form->generate_check_box("showforumteam", 1, $lang->forum_team, array("checked" => $mybb->input['showforumteam']));
1076      }
1077      $general_options[] =    $form->generate_check_box("isbannedgroup", 1, $lang->is_banned_group, array("checked" => $mybb->input['isbannedgroup']));
1078  
1079      $form_container->output_row($lang->general_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $general_options)."</div>");
1080  
1081      if($usergroup['type'] != 1)
1082      {
1083          $public_options = array(
1084              $form->generate_check_box("joinable", 1, $lang->user_joinable, array("checked" => $mybb->input['joinable'])),
1085              $form->generate_check_box("moderate", 1, $lang->moderate_join_requests, array("checked" => $mybb->input['moderate'])),
1086              $form->generate_check_box("invite", 1, $lang->invite_only, array("checked" => $mybb->input['invite'])),
1087              $form->generate_check_box("candisplaygroup", 1, $lang->can_set_as_display_group, array("checked" => $mybb->input['candisplaygroup'])),
1088              );
1089          $form_container->output_row($lang->publicly_joinable_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $public_options)."</div>");
1090      }
1091  
1092      $admin_options = array(
1093          $form->generate_check_box("issupermod", 1, $lang->is_super_mod, array("checked" => $mybb->input['issupermod'])),
1094          $form->generate_check_box("canmodcp", 1, $lang->can_access_mod_cp, array("checked" => $mybb->input['canmodcp'])),
1095          $form->generate_check_box("cancp", 1, $lang->can_access_admin_cp, array("checked" => $mybb->input['cancp']))
1096      );
1097      $form_container->output_row($lang->moderation_administration_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $admin_options)."</div>");
1098  
1099      $form_container->end();
1100      echo "</div>";
1101  
1102      //
1103      // FORUMS AND POSTS
1104      //
1105      echo "<div id=\"tab_forums_posts\">";
1106      $form_container = new FormContainer($lang->forums_posts);
1107  
1108      $viewing_options = array(
1109          $form->generate_check_box("canview", 1, $lang->can_view_board, array("checked" => $mybb->input['canview'])),
1110          $form->generate_check_box("canviewthreads", 1, $lang->can_view_threads, array("checked" => $mybb->input['canviewthreads'])),
1111          $form->generate_check_box("cansearch", 1, $lang->can_search_forums, array("checked" => $mybb->input['cansearch'])),
1112          $form->generate_check_box("canviewprofiles", 1, $lang->can_view_profiles, array("checked" => $mybb->input['canviewprofiles'])),
1113          $form->generate_check_box("candlattachments", 1, $lang->can_download_attachments, array("checked" => $mybb->input['candlattachments'])),
1114          $form->generate_check_box("canviewboardclosed", 1, $lang->can_view_board_closed, array("checked" => $mybb->input['canviewboardclosed']))
1115      );
1116      $form_container->output_row($lang->viewing_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $viewing_options)."</div>");
1117  
1118      $posting_options = array(
1119          $form->generate_check_box("canpostthreads", 1, $lang->can_post_threads, array("checked" => $mybb->input['canpostthreads'])),
1120          $form->generate_check_box("canpostreplys", 1, $lang->can_post_replies, array("checked" => $mybb->input['canpostreplys'])),
1121          $form->generate_check_box("canratethreads", 1, $lang->can_rate_threads, array("checked" => $mybb->input['canratethreads'])),
1122          "{$lang->max_posts_per_day}<br /><small class=\"input\">{$lang->max_posts_per_day_desc}</small><br />".$form->generate_numeric_field('maxposts', $mybb->input['maxposts'], array('id' => 'maxposts', 'class' => 'field50', 'min' => 0))
1123      );
1124      $form_container->output_row($lang->posting_rating_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $posting_options)."</div>");
1125  
1126      $moderator_options = array(
1127          $form->generate_check_box("modposts", 1, $lang->mod_new_posts, array("checked" => $mybb->input['modposts'])),
1128          $form->generate_check_box("modthreads", 1, $lang->mod_new_threads, array("checked" => $mybb->input['modthreads'])),
1129          $form->generate_check_box("modattachments", 1, $lang->mod_new_attachments, array("checked" => $mybb->input['modattachments'])),
1130          $form->generate_check_box("mod_edit_posts", 1, $lang->mod_after_edit, array("checked" => $mybb->input['mod_edit_posts']))
1131      );
1132      $form_container->output_row($lang->moderation_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $moderator_options)."</div>");
1133  
1134      $poll_options = array(
1135          $form->generate_check_box("canpostpolls", 1, $lang->can_post_polls, array("checked" => $mybb->input['canpostpolls'])),
1136          $form->generate_check_box("canvotepolls", 1, $lang->can_vote_polls, array("checked" => $mybb->input['canvotepolls'])),
1137          $form->generate_check_box("canundovotes", 1, $lang->can_undo_votes, array("checked" => $mybb->input['canundovotes']))
1138      );
1139      $form_container->output_row($lang->poll_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $poll_options)."</div>");
1140  
1141      $attachment_options = array(
1142          $form->generate_check_box("canpostattachments", 1, $lang->can_post_attachments, array("checked" => $mybb->input['canpostattachments'])),
1143          "{$lang->attach_quota}<br /><small class=\"input\">{$lang->attach_quota_desc}</small><br />".$form->generate_numeric_field('attachquota', $mybb->input['attachquota'], array('id' => 'attachquota', 'class' => 'field50', 'min' => 0)). "KB"
1144      );
1145      $form_container->output_row($lang->attachment_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $attachment_options)."</div>");
1146  
1147      // Remove these options if the group being editied is Guest (GID=1)
1148      if($usergroup['gid'] != 1)
1149      {
1150          $editing_options = array(
1151              $form->generate_check_box("caneditposts", 1, $lang->can_edit_posts, array("checked" => $mybb->input['caneditposts'])),
1152              $form->generate_check_box("candeleteposts", 1, $lang->can_delete_posts, array("checked" => $mybb->input['candeleteposts'])),
1153              $form->generate_check_box("candeletethreads", 1, $lang->can_delete_threads, array("checked" => $mybb->input['candeletethreads'])),
1154              $form->generate_check_box("caneditattachments", 1, $lang->can_edit_attachments, array("checked" => $mybb->input['caneditattachments'])),
1155              $form->generate_check_box("canviewdeletionnotice", 1, $lang->can_view_deletion_notices, array("checked" => $mybb->input['canviewdeletionnotice'])),
1156              "{$lang->edit_time_limit}<br /><small class=\"input\">{$lang->edit_time_limit_desc}</small><br />".$form->generate_numeric_field('edittimelimit', $mybb->input['edittimelimit'], array('id' => 'edittimelimit', 'class' => 'field50', 'min' => 0))
1157          );
1158          $form_container->output_row($lang->editing_deleting_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $editing_options)."</div>");
1159      }
1160  
1161      $form_container->end();
1162      echo "</div>";
1163  
1164      //
1165      // USERS AND PERMISSIONS
1166      //
1167      echo "<div id=\"tab_users_permissions\">";
1168      $form_container = new FormContainer($lang->users_permissions);
1169  
1170      $account_options = array(
1171          $form->generate_check_box("canbereported", 1, $lang->can_be_reported, array("checked" => $mybb->input['canbereported'])),
1172          $form->generate_check_box("canbeinvisible", 1, $lang->can_be_invisible, array("checked" => $mybb->input['canbeinvisible'])),
1173          $form->generate_check_box("canusercp", 1, $lang->can_access_usercp, array("checked" => $mybb->input['canusercp'])),
1174          $form->generate_check_box("canchangename", 1, $lang->can_change_username, array("checked" => $mybb->input['canchangename'])),
1175          $form->generate_check_box("cancustomtitle", 1, $lang->can_use_usertitles, array("checked" => $mybb->input['cancustomtitle'])),
1176          $form->generate_check_box("canuploadavatars", 1, $lang->can_upload_avatars, array("checked" => $mybb->input['canuploadavatars'])),
1177          $form->generate_check_box("canusesig", 1, $lang->can_use_signature, array("checked" => $mybb->input['canusesig'])),
1178          $form->generate_check_box("signofollow", 1, $lang->uses_no_follow, array("checked" => $mybb->input['signofollow'])),
1179          $form->generate_check_box("canchangewebsite", 1, $lang->can_change_website, array("checked" => $mybb->input['canchangewebsite'])),
1180          "{$lang->required_posts}<br /><small class=\"input\">{$lang->required_posts_desc}</small><br />".$form->generate_numeric_field('canusesigxposts', $mybb->input['canusesigxposts'], array('id' => 'canusesigxposts', 'class' => 'field50', 'min' => 0))
1181      );
1182      $form_container->output_row($lang->account_management, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $account_options)."</div>");
1183  
1184      $reputation_options = array(
1185          $form->generate_check_box("usereputationsystem", 1, $lang->show_reputations, array("checked" => $mybb->input['usereputationsystem'])),
1186          $form->generate_check_box("cangivereputations", 1, $lang->can_give_reputation, array("checked" => $mybb->input['cangivereputations'])),
1187          $form->generate_check_box("candeletereputations", 1, $lang->can_delete_own_reputation, array("checked" => $mybb->input['candeletereputations'])),
1188          "{$lang->points_to_award_take}<br /><small class=\"input\">{$lang->points_to_award_take_desc}</small><br />".$form->generate_numeric_field('reputationpower', $mybb->input['reputationpower'], array('id' => 'reputationpower', 'class' => 'field50', 'min' => 0)),
1189          "{$lang->max_reputations_perthread}<br /><small class=\"input\">{$lang->max_reputations_perthread_desc}</small><br />".$form->generate_numeric_field('maxreputationsperthread', $mybb->input['maxreputationsperthread'], array('id' => 'maxreputationsperthread', 'class' => 'field50', 'min' => 0)),
1190          "{$lang->max_reputations_peruser}<br /><small class=\"input\">{$lang->max_reputations_peruser_desc}</small><br />".$form->generate_numeric_field('maxreputationsperuser', $mybb->input['maxreputationsperuser'], array('id' => 'maxreputationsperuser', 'class' => 'field50', 'min' => 0)),
1191          "{$lang->max_reputations_daily}<br /><small class=\"input\">{$lang->max_reputations_daily_desc}</small><br />".$form->generate_numeric_field('maxreputationsday', $mybb->input['maxreputationsday'], array('id' => 'maxreputationsday', 'class' => 'field50', 'min' => 0))
1192      );
1193      $form_container->output_row($lang->reputation_system, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $reputation_options)."</div>");
1194  
1195      $warning_options = array(
1196          $form->generate_check_box("canwarnusers", 1, $lang->can_send_warnings, array("checked" => $mybb->input['canwarnusers'])),
1197          $form->generate_check_box("canreceivewarnings", 1, $lang->can_receive_warnings, array("checked" => $mybb->input['canreceivewarnings'])),
1198          "{$lang->warnings_per_day}<br />".$form->generate_numeric_field('maxwarningsday', $mybb->input['maxwarningsday'], array('id' => 'maxwarningsday', 'class' => 'field50'))
1199      );
1200      $form_container->output_row($lang->warning_system, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $warning_options)."</div>");
1201  
1202      $pm_options = array(
1203          $form->generate_check_box("canusepms", 1, $lang->can_use_pms, array("checked" => $mybb->input['canusepms'])),
1204          $form->generate_check_box("cansendpms", 1, $lang->can_send_pms, array("checked" => $mybb->input['cansendpms'])),
1205          $form->generate_check_box("canoverridepm", 1, $lang->can_override_pms, array("checked" => $mybb->input['canoverridepm'])),
1206          $form->generate_check_box("cantrackpms", 1, $lang->can_track_pms, array("checked" => $mybb->input['cantrackpms'])),
1207          $form->generate_check_box("candenypmreceipts", 1, $lang->can_deny_reciept, array("checked" => $mybb->input['candenypmreceipts'])),
1208          "{$lang->message_quota}<br /><small>{$lang->message_quota_desc}</small><br />".$form->generate_numeric_field('pmquota', $mybb->input['pmquota'], array('id' => 'pmquota', 'class' => 'field50', 'min' => 0)),
1209          "{$lang->max_recipients}<br /><small>{$lang->max_recipients_desc}</small><br />".$form->generate_numeric_field('maxpmrecipients', $mybb->input['maxpmrecipients'], array('id' => 'maxpmrecipients', 'class' => 'field50', 'min' => 0))
1210      );
1211      $form_container->output_row($lang->private_messaging, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $pm_options)."</div>");
1212  
1213      $form_container->end();
1214      echo "</div>";
1215  
1216      //
1217      // MISC
1218      //
1219      echo "<div id=\"tab_misc\">";
1220      $form_container = new FormContainer($lang->misc);
1221  
1222      $calendar_options = array(
1223          $form->generate_check_box("canviewcalendar", 1, $lang->can_view_calendar, array("checked" => $mybb->input['canviewcalendar'])),
1224          $form->generate_check_box("canaddevents", 1, $lang->can_post_events, array("checked" => $mybb->input['canaddevents'])),
1225          $form->generate_check_box("canbypasseventmod", 1, $lang->can_bypass_event_moderation, array("checked" => $mybb->input['canbypasseventmod'])),
1226          $form->generate_check_box("canmoderateevents", 1, $lang->can_moderate_events, array("checked" => $mybb->input['canmoderateevents']))
1227      );
1228      $form_container->output_row($lang->calendar, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $calendar_options)."</div>");
1229  
1230      $wol_options = array(
1231          $form->generate_check_box("canviewonline", 1, $lang->can_view_whos_online, array("checked" => $mybb->input['canviewonline'])),
1232          $form->generate_check_box("canviewwolinvis", 1, $lang->can_view_invisible, array("checked" => $mybb->input['canviewwolinvis'])),
1233          $form->generate_check_box("canviewonlineips", 1, $lang->can_view_ips, array("checked" => $mybb->input['canviewonlineips']))
1234      );
1235      $form_container->output_row($lang->whos_online, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $wol_options)."</div>");
1236  
1237      $misc_options = array(
1238          $form->generate_check_box("canviewmemberlist", 1, $lang->can_view_member_list, array("checked" => $mybb->input['canviewmemberlist'])),
1239          $form->generate_check_box("showinbirthdaylist", 1, $lang->show_in_birthday_list, array("checked" => $mybb->input['showinbirthdaylist'])),
1240          $form->generate_check_box("cansendemail", 1, $lang->can_email_users, array("checked" => $mybb->input['cansendemail'])),
1241          $form->generate_check_box("cansendemailoverride", 1, $lang->can_email_users_override, array("checked" => $mybb->input['cansendemailoverride'])),
1242          "{$lang->max_emails_per_day}<br /><small class=\"input\">{$lang->max_emails_per_day_desc}</small><br />".$form->generate_numeric_field('maxemails', $mybb->input['maxemails'], array('id' => 'maxemails', 'class' => 'field50', 'min' => 0)),
1243          "{$lang->email_flood_time}<br /><small class=\"input\">{$lang->email_flood_time_desc}</small><br />".$form->generate_numeric_field('emailfloodtime', $mybb->input['emailfloodtime'], array('id' => 'emailfloodtime', 'class' => 'field50', 'min' => 0))
1244      );
1245      $form_container->output_row($lang->misc, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $misc_options)."</div>");
1246  
1247      $form_container->end();
1248      echo "</div>";
1249  
1250      //
1251      // MODERATOR CP
1252      //
1253      echo "<div id=\"tab_modcp\">";
1254      $form_container = new FormContainer($lang->mod_cp);
1255  
1256      $forum_post_options = array(
1257          $form->generate_check_box("canmanageannounce", 1, $lang->can_manage_announce, array("checked" => $mybb->input['canmanageannounce'])),
1258          $form->generate_check_box("canmanagemodqueue", 1, $lang->can_manage_mod_queue, array("checked" => $mybb->input['canmanagemodqueue'])),
1259          $form->generate_check_box("canmanagereportedcontent", 1, $lang->can_manage_reported_content, array("checked" => $mybb->input['canmanagereportedcontent'])),
1260          $form->generate_check_box("canviewmodlogs", 1, $lang->can_view_mod_logs, array("checked" => $mybb->input['canviewmodlogs']))
1261      );
1262      $form_container->output_row($lang->forum_post_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $forum_post_options)."</div>");
1263  
1264      $user_options = array(
1265          $form->generate_check_box("caneditprofiles", 1, $lang->can_edit_profiles, array("checked" => $mybb->input['caneditprofiles'])),
1266          $form->generate_check_box("canbanusers", 1, $lang->can_ban_users, array("checked" => $mybb->input['canbanusers'])),
1267          $form->generate_check_box("canviewwarnlogs", 1, $lang->can_view_warnlogs, array("checked" => $mybb->input['canviewwarnlogs'])),
1268          $form->generate_check_box("canuseipsearch", 1, $lang->can_use_ipsearch, array("checked" => $mybb->input['canuseipsearch']))
1269      );
1270      $form_container->output_row($lang->user_options, "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $user_options)."</div>");
1271  
1272      $form_container->end();
1273      echo "</div>";
1274  
1275      $plugins->run_hooks("admin_user_groups_edit_graph");
1276  
1277      $buttons[] = $form->generate_submit_button($lang->save_user_group);
1278      $form->output_submit_wrapper($buttons);
1279  
1280      $form->end();
1281      $page->output_footer();
1282  }
1283  
1284  if($mybb->input['action'] == "delete")
1285  {
1286      $query = $db->simple_select("usergroups", "*", "gid='".$mybb->get_input('gid', MyBB::INPUT_INT)."'");
1287      $usergroup = $db->fetch_array($query);
1288  
1289      if(!$usergroup)
1290      {
1291          flash_message($lang->error_invalid_user_group, 'error');
1292          admin_redirect("index.php?module=user-groups");
1293      }
1294      if($usergroup['type'] == 1)
1295      {
1296          flash_message($lang->error_default_group_delete, 'error');
1297          admin_redirect("index.php?module=user-groups");
1298      }
1299  
1300      // User clicked no
1301      if($mybb->get_input('no'))
1302      {
1303          admin_redirect("index.php?module=user-groups");
1304      }
1305  
1306      $plugins->run_hooks("admin_user_groups_delete");
1307  
1308      if($mybb->request_method == "post")
1309      {
1310          if($usergroup['isbannedgroup'] == 1)
1311          {
1312              // If banned group, move users to default banned group
1313              $updated_users = array("usergroup" => 7);
1314          }
1315          else
1316          {
1317              // Move any users back to the registered group
1318              $updated_users = array("usergroup" => 2);
1319          }
1320  
1321          $db->update_query("users", $updated_users, "usergroup='{$usergroup['gid']}'");
1322  
1323          $updated_users = array("displaygroup" => "usergroup");
1324          $plugins->run_hooks("admin_user_groups_delete_commit");
1325  
1326          $db->update_query("users", $updated_users, "displaygroup='{$usergroup['gid']}'", "", true); // No quotes = displaygroup=usergroup
1327  
1328          switch($db->type)
1329          {
1330              case "pgsql":
1331              case "sqlite":
1332                  $query = $db->simple_select("users", "uid", "','||additionalgroups||',' LIKE '%,{$usergroup['gid']},%'");
1333                  break;
1334              default:
1335                  $query = $db->simple_select("users", "uid", "CONCAT(',',additionalgroups,',') LIKE '%,{$usergroup['gid']},%'");
1336          }
1337          while($user = $db->fetch_array($query))
1338          {
1339              leave_usergroup($user['uid'], $usergroup['gid']);
1340          }
1341  
1342          $db->update_query("banned", array("gid" => 7), "gid='{$usergroup['gid']}'");
1343          $db->update_query("banned", array("oldgroup" => 2), "oldgroup='{$usergroup['gid']}'");
1344          $db->update_query("banned", array("olddisplaygroup" => "oldgroup"), "olddisplaygroup='{$usergroup['gid']}'", "", true); // No quotes = displaygroup=usergroup
1345  
1346          $db->delete_query("forumpermissions", "gid='{$usergroup['gid']}'");
1347          $db->delete_query("calendarpermissions", "gid='{$usergroup['gid']}'");
1348          $db->delete_query("joinrequests", "gid='{$usergroup['gid']}'");
1349          $db->delete_query("moderators", "id='{$usergroup['gid']}' AND isgroup='1'");
1350          $db->delete_query("groupleaders", "gid='{$usergroup['gid']}'");
1351          $db->delete_query("usergroups", "gid='{$usergroup['gid']}'");
1352  
1353          $plugins->run_hooks("admin_user_groups_delete_commit_end");
1354  
1355          $cache->update_groupleaders();
1356          $cache->update_moderators();
1357          $cache->update_usergroups();
1358          $cache->update_forumpermissions();
1359  
1360          // Log admin action
1361          log_admin_action($usergroup['gid'], $usergroup['title']);
1362  
1363          flash_message($lang->success_group_deleted, 'success');
1364          admin_redirect("index.php?module=user-groups");
1365      }
1366      else
1367      {
1368          $page->output_confirm_action("index.php?module=user-groups&amp;action=delete&amp;gid={$usergroup['gid']}", $lang->confirm_group_deletion);
1369      }
1370  }
1371  
1372  if($mybb->input['action'] == "disporder" && $mybb->request_method == "post")
1373  {
1374      $plugins->run_hooks("admin_user_groups_disporder");
1375  
1376      foreach($mybb->input['disporder'] as $gid=>$order)
1377      {
1378          $gid = (int)$gid;
1379          $order = (int)$order;
1380          if($gid != 0 && $order != 0)
1381          {
1382              $sql_array = array(
1383                  'disporder' => $order,
1384              );
1385              $db->update_query('usergroups', $sql_array, "gid = '{$gid}'");
1386          }
1387      }
1388  
1389      // Log admin action
1390      log_admin_action();
1391  
1392      $plugins->run_hooks("admin_user_groups_disporder_commit");
1393  
1394      flash_message($lang->success_group_disporders_updated, 'success');
1395      admin_redirect("index.php?module=user-groups");
1396  }
1397  
1398  if(!$mybb->input['action'])
1399  {
1400      $plugins->run_hooks("admin_user_groups_start");
1401  
1402      if($mybb->request_method == "post")
1403      {
1404          if(!empty($mybb->input['disporder']))
1405          {
1406              foreach($mybb->input['disporder'] as $gid => $order)
1407              {
1408                  $db->update_query("usergroups", array('disporder' => (int)$order), "gid='".(int)$gid."'");
1409              }
1410  
1411              $plugins->run_hooks("admin_user_groups_start_commit");
1412  
1413              $cache->update_usergroups();
1414  
1415              flash_message($lang->success_groups_disporder_updated, 'success');
1416              admin_redirect("index.php?module=user-groups");
1417          }
1418      }
1419  
1420      $page->output_header($lang->manage_user_groups);
1421      $page->output_nav_tabs($sub_tabs, 'manage_groups');
1422  
1423      $form = new Form("index.php?module=user-groups", "post", "groups");
1424  
1425      $primaryusers = $secondaryusers = array();
1426  
1427      $query = $db->query("
1428          SELECT g.gid, COUNT(u.uid) AS users
1429          FROM ".TABLE_PREFIX."users u
1430          LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=u.usergroup)
1431          GROUP BY g.gid
1432      ");
1433      while($groupcount = $db->fetch_array($query))
1434      {
1435          $primaryusers[$groupcount['gid']] = $groupcount['users'];
1436      }
1437  
1438      switch($db->type)
1439      {
1440          case "pgsql":
1441          case "sqlite":
1442              $query = $db->query("
1443                  SELECT g.gid, COUNT(u.uid) AS users
1444                  FROM ".TABLE_PREFIX."users u
1445                  LEFT JOIN ".TABLE_PREFIX."usergroups g ON (','|| u.additionalgroups|| ',' LIKE '%,'|| g.gid|| ',%')
1446                  WHERE g.gid != '0' AND g.gid is not NULL GROUP BY g.gid
1447              ");
1448              break;
1449          default:
1450              $query = $db->query("
1451                  SELECT g.gid, COUNT(u.uid) AS users
1452                  FROM ".TABLE_PREFIX."users u
1453                  LEFT JOIN ".TABLE_PREFIX."usergroups g ON (CONCAT(',', u.additionalgroups, ',') LIKE CONCAT('%,', g.gid, ',%'))
1454                  WHERE g.gid != '0' AND g.gid is not NULL GROUP BY g.gid
1455              ");
1456      }
1457      while($groupcount = $db->fetch_array($query))
1458      {
1459          $secondaryusers[$groupcount['gid']] = $groupcount['users'];
1460      }
1461  
1462      $query = $db->query("
1463          SELECT g.gid, COUNT(r.uid) AS users
1464          FROM ".TABLE_PREFIX."joinrequests r
1465          LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=r.gid)
1466          GROUP BY g.gid
1467      ");
1468  
1469      $joinrequests = array();
1470      while($joinrequest = $db->fetch_array($query))
1471      {
1472          $joinrequests[$joinrequest['gid']] = $joinrequest['users'];
1473      }
1474  
1475      // Fetch group leaders
1476      $leaders = array();
1477      $query = $db->query("
1478          SELECT u.username, u.uid, l.gid
1479          FROM ".TABLE_PREFIX."groupleaders l
1480          INNER JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
1481          ORDER BY u.username ASC
1482      ");
1483      while($leader = $db->fetch_array($query))
1484      {
1485          $leaders[$leader['gid']][] = build_profile_link(htmlspecialchars_uni($leader['username']), $leader['uid'], "_blank");
1486      }
1487  
1488      $form_container = new FormContainer($lang->user_groups);
1489      $form_container->output_row_header($lang->group);
1490      $form_container->output_row_header($lang->number_of_users, array("class" => "align_center", 'width' => '75'));
1491      $form_container->output_row_header($lang->order, array("class" => "align_center", 'width' => '5%'));
1492      $form_container->output_row_header($lang->controls, array("class" => "align_center"));
1493  
1494      $query = $db->simple_select("usergroups", "*", "", array('order_by' => 'disporder'));
1495      while($usergroup = $db->fetch_array($query))
1496      {
1497          if($usergroup['type'] > 1)
1498          {
1499              $icon = "<img src=\"styles/default/images/icons/custom.png\" alt=\"{$lang->custom_user_group}\" style=\"vertical-align: middle;\" />";
1500          }
1501          else
1502          {
1503              $icon = "<img src=\"styles/default/images/icons/default.png\" alt=\"{$lang->default_user_group}\" style=\"vertical-align: middle;\" />";
1504          }
1505  
1506          $leaders_list = '';
1507          if(isset($leaders[$usergroup['gid']]))
1508          {
1509              $leaders_list = "<br />{$lang->group_leaders}: ".implode($lang->comma, $leaders[$usergroup['gid']]);
1510          }
1511  
1512          $join_requests = '';
1513          if(isset($joinrequests[$usergroup['gid']]) && $joinrequests[$usergroup['gid']] > 1 && $usergroup['type'] == 4)
1514          {
1515              $join_requests = " <small><a href=\"index.php?module=user-groups&amp;action=join_requests&amp;gid={$usergroup['gid']}\"><span style=\"color: red;\">({$joinrequests[$usergroup['gid']]} {$lang->outstanding_join_request})</span></a></small>";
1516          }
1517          else if(isset($joinrequests[$usergroup['gid']]) && $joinrequests[$usergroup['gid']] == 1 && $usergroup['type'] == 4)
1518          {
1519              $join_requests = " <small><a href=\"index.php?module=user-groups&amp;action=join_requests&amp;gid={$usergroup['gid']}\"><span style=\"color: red;\">({$joinrequests[$usergroup['gid']]} {$lang->outstanding_join_request})</span></a></small>";
1520          }
1521  
1522          $form_container->output_cell("<div class=\"float_right\">{$icon}</div><div><strong><a href=\"index.php?module=user-groups&amp;action=edit&amp;gid={$usergroup['gid']}\">".format_name(htmlspecialchars_uni($usergroup['title']), $usergroup['gid'])."</a></strong>{$join_requests}<br /><small>".htmlspecialchars_uni($usergroup['description'])."{$leaders_list}</small></div>");
1523  
1524          if(!isset($primaryusers[$usergroup['gid']]))
1525          {
1526              $primaryusers[$usergroup['gid']] = 0;
1527          }
1528          if(!isset($secondaryusers[$usergroup['gid']]))
1529          {
1530              $secondaryusers[$usergroup['gid']] = 0;
1531          }
1532          $numusers = $primaryusers[$usergroup['gid']];
1533          $numusers += $secondaryusers[$usergroup['gid']];
1534  
1535          $form_container->output_cell(my_number_format($numusers), array("class" => "align_center"));
1536  
1537          if($usergroup['showforumteam'] == 1)
1538          {
1539              $form_container->output_cell($form->generate_numeric_field("disporder[{$usergroup['gid']}]", "{$usergroup['disporder']}", array('class' => 'align_center', 'style' => 'width:80%')), array("class" => "align_center"));
1540          }
1541          else
1542          {
1543              $form_container->output_cell("&nbsp;", array("class" => "align_center"));
1544          }
1545  
1546          $popup = new PopupMenu("usergroup_{$usergroup['gid']}", $lang->options);
1547          $popup->add_item($lang->edit_group, "index.php?module=user-groups&amp;action=edit&amp;gid={$usergroup['gid']}");
1548          $popup->add_item($lang->list_users, "index.php?module=user-users&amp;action=search&amp;results=1&amp;conditions[usergroup]={$usergroup['gid']}");
1549          if(isset($joinrequests[$usergroup['gid']]) && $joinrequests[$usergroup['gid']] > 0 && $usergroup['type'] == 4)
1550          {
1551              $popup->add_item($lang->join_requests, "index.php?module=user-groups&amp;action=join_requests&amp;gid={$usergroup['gid']}");
1552          }
1553          $popup->add_item($lang->group_leaders, "index.php?module=user-groups&amp;action=leaders&amp;gid={$usergroup['gid']}");
1554          if($usergroup['type'] > 1)
1555          {
1556              $popup->add_item($lang->delete_group, "index.php?module=user-groups&amp;action=delete&amp;gid={$usergroup['gid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_group_deletion}')");
1557          }
1558          $form_container->output_cell($popup->fetch(), array("class" => "align_center"));
1559          $form_container->construct_row();
1560      }
1561  
1562      if($form_container->num_rows() == 0)
1563      {
1564          $form_container->output_cell($lang->no_groups, array('colspan' => 4));
1565          $form_container->construct_row();
1566      }
1567  
1568      $form_container->end();
1569  
1570      $buttons = array();
1571      $buttons[] = $form->generate_submit_button($lang->update_groups_order);
1572      $form->output_submit_wrapper($buttons);
1573  
1574      $form->end();
1575  
1576      echo <<<LEGEND
1577      <br />
1578      <fieldset>
1579  <legend>{$lang->legend}</legend>
1580  <img src="styles/default/images/icons/custom.png" alt="{$lang->custom_user_group}" style="vertical-align: middle;" /> {$lang->custom_user_group}<br />
1581  <img src="styles/default/images/icons/default.png" alt="{$lang->default_user_group}" style="vertical-align: middle;" /> {$lang->default_user_group}
1582  </fieldset>
1583  LEGEND;
1584  
1585      $page->output_footer();
1586  }


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