[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/user/ -> groups.php (source)

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


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1