1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833:
<?php
if (!defined('SMF'))
die('No direct access...');
function deleteMembergroups($groups)
{
global $smcFunc, $modSettings, $txt;
if (!is_array($groups))
$groups = array((int) $groups);
else
{
$groups = array_unique($groups);
foreach ($groups as $key => $value)
$groups[$key] = (int) $value;
}
$protected_groups = array(-1, 0, 1, 3, 4);
if (!allowedTo('admin_forum'))
{
$request = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE group_type = {int:is_protected}',
array(
'is_protected' => 1,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$protected_groups[] = $row['id_group'];
$smcFunc['db_free_result']($request);
}
$groups = array_diff($groups, array_unique($protected_groups));
if (empty($groups))
return 'no_group_found';
$subscriptions = array();
$request = $smcFunc['db_query']('', '
SELECT id_subscribe, name, id_group, add_groups
FROM {db_prefix}subscriptions
ORDER BY name');
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (in_array($row['id_group'], $groups))
$subscriptions[] = $row['name'];
else
{
$add_groups = explode(',', $row['add_groups']);
if (count(array_intersect($add_groups, $groups)) != 0)
$subscriptions[] = $row['name'];
}
}
$smcFunc['db_free_result']($request);
if (!empty($subscriptions))
{
loadLanguage('ManageMembers');
$txt['membergroups_cannot_delete_paid'] = sprintf($txt['membergroups_cannot_delete_paid'], implode(', ', $subscriptions));
return 'group_cannot_delete_sub';
}
$request = $smcFunc['db_query']('', '
SELECT group_name
FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
logAction('delete_group', array('group' => $row['group_name']), 'admin');
$smcFunc['db_free_result']($request);
call_integration_hook('integrate_delete_membergroups', array($groups));
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}permissions
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}board_permissions
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}group_moderators
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}moderator_groups
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_group_requests
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET id_group = {int:regular_group}
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
'regular_group' => 0,
)
);
$smcFunc['db_query']('', '
UPDATE {db_prefix}membergroups
SET id_parent = {int:uninherited}
WHERE id_parent IN ({array_int:group_list})',
array(
'group_list' => $groups,
'uninherited' => -2,
)
);
$request = $smcFunc['db_query']('', '
SELECT id_member, additional_groups
FROM {db_prefix}members
WHERE FIND_IN_SET({raw:additional_groups_explode}, additional_groups) != 0',
array(
'additional_groups_explode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups),
)
);
$updates = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$updates[$row['additional_groups']][] = $row['id_member'];
$smcFunc['db_free_result']($request);
foreach ($updates as $additional_groups => $memberArray)
updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
$request = $smcFunc['db_query']('', '
SELECT id_board, member_groups
FROM {db_prefix}boards
WHERE FIND_IN_SET({raw:member_groups_explode}, member_groups) != 0',
array(
'member_groups_explode' => implode(', member_groups) != 0 OR FIND_IN_SET(', $groups),
)
);
$updates = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$updates[$row['member_groups']][] = $row['id_board'];
$smcFunc['db_free_result']($request);
foreach ($updates as $member_groups => $boardArray)
$smcFunc['db_query']('', '
UPDATE {db_prefix}boards
SET member_groups = {string:member_groups}
WHERE id_board IN ({array_int:board_lists})',
array(
'board_lists' => $boardArray,
'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
)
);
updateStats('postgroups');
$settings_update = array('settings_updated' => time());
if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
$settings_update['spider_group'] = 0;
updateSettings($settings_update);
return true;
}
function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false)
{
global $smcFunc, $modSettings, $sourcedir;
if (!$permissionCheckDone)
isAllowedTo('manage_membergroups');
updateSettings(array('settings_updated' => time()));
if (!is_array($members))
$members = array((int) $members);
else
{
$members = array_unique($members);
foreach ($members as $key => $value)
$members[$key] = (int) $value;
}
if ($groups === null || $groups == 1 || (is_array($groups) && in_array(1, $groups)))
{
$admins = array();
listMembergroupMembers_Href($admins, 1);
$non_changing_admins = array_diff(array_keys($admins), $members);
if (empty($non_changing_admins))
$members = array_diff($members, array_keys($admins));
}
if (empty($members))
return false;
elseif ($groups === null)
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET
id_group = {int:regular_member},
additional_groups = {string:blank_string}
WHERE id_member IN ({array_int:member_list})' . (allowedTo('admin_forum') ? '' : '
AND id_group != {int:admin_group}
AND FIND_IN_SET({int:admin_group}, additional_groups) = 0'),
array(
'member_list' => $members,
'regular_member' => 0,
'admin_group' => 1,
'blank_string' => '',
)
);
updateStats('postgroups', $members);
foreach ($members as $member)
logAction('removed_all_groups', array('member' => $member), 'admin');
return true;
}
elseif (!is_array($groups))
$groups = array((int) $groups);
else
{
$groups = array_unique($groups);
foreach ($groups as $key => $value)
$groups[$key] = (int) $value;
}
$implicitGroups = array(-1, 0, 3);
$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, min_posts
FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:group_list})',
array(
'group_list' => $groups,
)
);
$group_names = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['min_posts'] != -1)
$implicitGroups[] = $row['id_group'];
else
$group_names[$row['id_group']] = $row['group_name'];
}
$smcFunc['db_free_result']($request);
$groups = array_diff($groups, $implicitGroups);
if (!allowedTo('admin_forum') && !$ignoreProtected)
{
$request = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE group_type = {int:is_protected}',
array(
'is_protected' => 1,
)
);
$protected_groups = array(1);
while ($row = $smcFunc['db_fetch_assoc']($request))
$protected_groups[] = $row['id_group'];
$smcFunc['db_free_result']($request);
$groups = array_diff($groups, array_unique($protected_groups));
}
if (empty($groups) || empty($members))
return false;
$log_inserts = array();
$request = $smcFunc['db_query']('', '
SELECT id_member, id_group
FROM {db_prefix}members AS members
WHERE id_group IN ({array_int:group_list})
AND id_member IN ({array_int:member_list})',
array(
'group_list' => $groups,
'member_list' => $members,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
$smcFunc['db_free_result']($request);
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET id_group = {int:regular_member}
WHERE id_group IN ({array_int:group_list})
AND id_member IN ({array_int:member_list})',
array(
'group_list' => $groups,
'member_list' => $members,
'regular_member' => 0,
)
);
$request = $smcFunc['db_query']('', '
SELECT id_member, additional_groups
FROM {db_prefix}members
WHERE (FIND_IN_SET({raw:additional_groups_implode}, additional_groups) != 0)
AND id_member IN ({array_int:member_list})
LIMIT {int:limit}',
array(
'member_list' => $members,
'additional_groups_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups),
'limit' => count($members),
)
);
$updates = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
foreach (explode(',', $row['additional_groups']) as $group)
if (in_array($group, $groups))
$log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
$updates[$row['additional_groups']][] = $row['id_member'];
}
$smcFunc['db_free_result']($request);
foreach ($updates as $additional_groups => $memberArray)
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET additional_groups = {string:additional_groups}
WHERE id_member IN ({array_int:member_list})',
array(
'member_list' => $memberArray,
'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
)
);
updateStats('postgroups', $members);
if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
{
require_once($sourcedir . '/Logging.php');
foreach ($log_inserts as $extra)
logAction('removed_from_group', $extra, 'admin');
}
return true;
}
function addMembersToGroup($members, $group, $type = 'auto', $permissionCheckDone = false, $ignoreProtected = false)
{
global $smcFunc, $sourcedir;
if (!$permissionCheckDone)
isAllowedTo('manage_membergroups');
updateSettings(array('settings_updated' => time()));
if (!is_array($members))
$members = array((int) $members);
else
{
$members = array_unique($members);
foreach ($members as $key => $value)
$members[$key] = (int) $value;
}
$group = (int) $group;
$implicitGroups = array(-1, 0, 3);
$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, min_posts
FROM {db_prefix}membergroups
WHERE id_group = {int:current_group}',
array(
'current_group' => $group,
)
);
$group_names = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['min_posts'] != -1)
$implicitGroups[] = $row['id_group'];
else
$group_names[$row['id_group']] = $row['group_name'];
}
$smcFunc['db_free_result']($request);
if (in_array($group, $implicitGroups) || empty($members))
return false;
if (!allowedTo('admin_forum') && $group == 1)
return false;
elseif (!allowedTo('admin_forum') && !$ignoreProtected)
{
$request = $smcFunc['db_query']('', '
SELECT group_type
FROM {db_prefix}membergroups
WHERE id_group = {int:current_group}
LIMIT {int:limit}',
array(
'current_group' => $group,
'limit' => 1,
)
);
list ($is_protected) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if ($is_protected == 1)
return false;
}
if ($type == 'only_additional')
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
WHERE id_member IN ({array_int:member_list})
AND id_group != {int:id_group}
AND FIND_IN_SET({int:id_group}, additional_groups) = 0',
array(
'member_list' => $members,
'id_group' => $group,
'id_group_string' => (string) $group,
'id_group_string_extend' => ',' . $group,
'blank_string' => '',
)
);
elseif ($type == 'only_primary' || $type == 'force_primary')
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET id_group = {int:id_group}
WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
AND id_group = {int:regular_group}
AND FIND_IN_SET({int:id_group}, additional_groups) = 0'),
array(
'member_list' => $members,
'id_group' => $group,
'regular_group' => 0,
)
);
elseif ($type == 'auto')
$smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET
id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
additional_groups = CASE WHEN id_group = {int:id_group} THEN additional_groups
WHEN additional_groups = {string:blank_string} THEN {string:id_group_string}
ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
WHERE id_member IN ({array_int:member_list})
AND id_group != {int:id_group}
AND FIND_IN_SET({int:id_group}, additional_groups) = 0',
array(
'member_list' => $members,
'regular_group' => 0,
'id_group' => $group,
'blank_string' => '',
'id_group_string' => (string) $group,
'id_group_string_extend' => ',' . $group,
)
);
else
trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names));
updateStats('postgroups', $members);
require_once($sourcedir . '/Logging.php');
foreach ($members as $member)
logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin');
return true;
}
function listMembergroupMembers_Href(&$members, $membergroup, $limit = null)
{
global $scripturl, $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name
FROM {db_prefix}members
WHERE id_group = {int:id_group} OR FIND_IN_SET({int:id_group}, additional_groups) != 0' . ($limit === null ? '' : '
LIMIT ' . ($limit + 1)),
array(
'id_group' => $membergroup,
)
);
$members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
$smcFunc['db_free_result']($request);
if ($limit !== null && count($members) > $limit)
{
array_pop($members);
return true;
}
else
return false;
}
function cache_getMembergroupList()
{
global $scripturl, $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
)
);
$groupCache = array();
$group = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$group[$row['id_group']] = $row;
$groupCache[$row['id_group']] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
}
$smcFunc['db_free_result']($request);
call_integration_hook('integrate_getMembergroupList', array(&$groupCache, $group));
return array(
'data' => $groupCache,
'expires' => time() + 3600,
'refresh_eval' => 'return $GLOBALS[\'modSettings\'][\'settings_updated\'] > ' . time() . ';',
);
}
function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
{
global $scripturl, $context, $settings, $smcFunc, $user_info;
$request = $smcFunc['db_query']('substring_membergroups', '
SELECT mg.id_group, mg.group_name, mg.min_posts, mg.description, mg.group_type, mg.online_color, mg.hidden,
mg.icons, COALESCE(gm.id_member, 0) AS can_moderate, 0 AS num_members
FROM {db_prefix}membergroups AS mg
LEFT JOIN {db_prefix}group_moderators AS gm ON (gm.id_group = mg.id_group AND gm.id_member = {int:current_member})
WHERE mg.min_posts {raw:min_posts}' . (allowedTo('admin_forum') ? '' : '
AND mg.id_group != {int:mod_group}') . '
ORDER BY {raw:sort}',
array(
'current_member' => $user_info['id'],
'min_posts' => ($membergroup_type === 'post_count' ? '!= ' : '= ') . -1,
'mod_group' => 3,
'sort' => $sort,
)
);
$groups = array();
$group_ids = array();
$context['can_moderate'] = allowedTo('manage_membergroups');
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
continue;
$row['icons'] = explode('#', $row['icons']);
$groups[$row['id_group']] = array(
'id_group' => $row['id_group'],
'group_name' => $row['group_name'],
'min_posts' => $row['min_posts'],
'desc' => parse_bbc($row['description'], false, '', $context['description_allowed_tags']),
'online_color' => $row['online_color'],
'type' => $row['group_type'],
'num_members' => $row['num_members'],
'moderators' => array(),
'icons' => !empty($row['icons'][0]) && !empty($row['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/membericons/' . $row['icons'][1] . '" alt="*">', $row['icons'][0]) : '',
);
$context['can_moderate'] |= $row['can_moderate'];
$group_ids[] = $row['id_group'];
}
$smcFunc['db_free_result']($request);
if (!empty($group_ids))
{
if ($membergroup_type === 'post_count')
{
$query = $smcFunc['db_query']('', '
SELECT id_post_group AS id_group, COUNT(*) AS num_members
FROM {db_prefix}members
WHERE id_post_group IN ({array_int:group_list})
GROUP BY id_post_group',
array(
'group_list' => $group_ids,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
$groups[$row['id_group']]['num_members'] += $row['num_members'];
$smcFunc['db_free_result']($query);
}
else
{
$query = $smcFunc['db_query']('', '
SELECT id_group, COUNT(*) AS num_members
FROM {db_prefix}members
WHERE id_group IN ({array_int:group_list})
GROUP BY id_group',
array(
'group_list' => $group_ids,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
$groups[$row['id_group']]['num_members'] += $row['num_members'];
$smcFunc['db_free_result']($query);
if ($context['can_moderate'])
{
$query = $smcFunc['db_query']('', '
SELECT mg.id_group, COUNT(*) AS num_members
FROM {db_prefix}membergroups AS mg
INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_string}
AND mem.id_group != mg.id_group
AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0)
WHERE mg.id_group IN ({array_int:group_list})
GROUP BY mg.id_group',
array(
'group_list' => $group_ids,
'blank_string' => '',
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
$groups[$row['id_group']]['num_members'] += $row['num_members'];
$smcFunc['db_free_result']($query);
}
}
$query = $smcFunc['db_query']('', '
SELECT mods.id_group, mods.id_member, mem.member_name, mem.real_name
FROM {db_prefix}group_moderators AS mods
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
WHERE mods.id_group IN ({array_int:group_list})',
array(
'group_list' => $group_ids,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
$smcFunc['db_free_result']($query);
}
if (substr($sort, 0, 1) == '1' || strpos($sort, ', 1') !== false)
{
$sort_ascending = strpos($sort, 'DESC') === false;
foreach ($groups as $group)
$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
}
return $groups;
}
?>