[ Index ]

PHP Cross Reference of MyBB 1.8.27

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


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