[ Index ]

PHP Cross Reference of MyBB 1.8.21

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


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