| Conditions | 112 |
| Total Lines | 577 |
| Code Lines | 294 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 648 | function EditMembergroup() |
||
| 649 | { |
||
| 650 | global $context, $txt, $sourcedir, $modSettings, $smcFunc, $settings; |
||
| 651 | |||
| 652 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
||
| 653 | |||
| 654 | if (!empty($modSettings['deny_boards_access'])) |
||
| 655 | loadLanguage('ManagePermissions'); |
||
| 656 | |||
| 657 | // Make sure this group is editable. |
||
| 658 | if (!empty($_REQUEST['group'])) |
||
| 659 | { |
||
| 660 | $request = $smcFunc['db_query']('', ' |
||
| 661 | SELECT id_group |
||
| 662 | FROM {db_prefix}membergroups |
||
| 663 | WHERE id_group = {int:current_group}' . (allowedTo('admin_forum') ? '' : ' |
||
| 664 | AND group_type != {int:is_protected}') . ' |
||
| 665 | LIMIT {int:limit}', |
||
| 666 | array( |
||
| 667 | 'current_group' => $_REQUEST['group'], |
||
| 668 | 'is_protected' => 1, |
||
| 669 | 'limit' => 1, |
||
| 670 | ) |
||
| 671 | ); |
||
| 672 | list ($_REQUEST['group']) = $smcFunc['db_fetch_row']($request); |
||
| 673 | $smcFunc['db_free_result']($request); |
||
| 674 | } |
||
| 675 | |||
| 676 | // Now, do we have a valid id? |
||
| 677 | if (empty($_REQUEST['group'])) |
||
| 678 | fatal_lang_error('membergroup_does_not_exist', false); |
||
| 679 | |||
| 680 | // People who can manage boards are a bit special. |
||
| 681 | require_once($sourcedir . '/Subs-Members.php'); |
||
| 682 | $board_managers = groupsAllowedTo('manage_boards', null); |
||
| 683 | $context['can_manage_boards'] = in_array($_REQUEST['group'], $board_managers['allowed']); |
||
| 684 | |||
| 685 | // Can this group moderate any boards? |
||
| 686 | $request = $smcFunc['db_query']('', ' |
||
| 687 | SELECT COUNT(*) |
||
| 688 | FROM {db_prefix}moderator_groups |
||
| 689 | WHERE id_group = {int:current_group}', |
||
| 690 | array( |
||
| 691 | 'current_group' => $_REQUEST['group'], |
||
| 692 | ) |
||
| 693 | ); |
||
| 694 | |||
| 695 | // Why don't we have a $smcFunc['db_result'] function? |
||
| 696 | $result = $smcFunc['db_fetch_row']($request); |
||
| 697 | $context['is_moderator_group'] = ($result[0] > 0); |
||
| 698 | $smcFunc['db_free_result']($request); |
||
| 699 | |||
| 700 | // The delete this membergroup button was pressed. |
||
| 701 | if (isset($_POST['delete'])) |
||
| 702 | { |
||
| 703 | checkSession(); |
||
| 704 | validateToken('admin-mmg'); |
||
| 705 | |||
| 706 | require_once($sourcedir . '/Subs-Membergroups.php'); |
||
| 707 | $result = deleteMembergroups($_REQUEST['group']); |
||
| 708 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
||
| 709 | if ($result === 'group_cannot_delete_sub') |
||
| 710 | fatal_lang_error('membergroups_cannot_delete_paid', false); |
||
| 711 | |||
| 712 | redirectexit('action=admin;area=membergroups;'); |
||
| 713 | } |
||
| 714 | // A form was submitted with the new membergroup settings. |
||
| 715 | elseif (isset($_POST['save'])) |
||
| 716 | { |
||
| 717 | // Validate the session. |
||
| 718 | checkSession(); |
||
| 719 | validateToken('admin-mmg'); |
||
| 720 | |||
| 721 | // Can they really inherit from this group? |
||
| 722 | if ($_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && isset($_POST['group_inherit']) && $_POST['group_inherit'] != -2 && !allowedTo('admin_forum')) |
||
| 723 | { |
||
| 724 | $request = $smcFunc['db_query']('', ' |
||
| 725 | SELECT group_type |
||
| 726 | FROM {db_prefix}membergroups |
||
| 727 | WHERE id_group = {int:inherit_from} |
||
| 728 | LIMIT {int:limit}', |
||
| 729 | array( |
||
| 730 | 'inherit_from' => $_POST['group_inherit'], |
||
| 731 | 'limit' => 1, |
||
| 732 | ) |
||
| 733 | ); |
||
| 734 | list ($inherit_type) = $smcFunc['db_fetch_row']($request); |
||
| 735 | $smcFunc['db_free_result']($request); |
||
| 736 | } |
||
| 737 | |||
| 738 | // Set variables to their proper value. |
||
| 739 | $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0; |
||
| 740 | $_POST['min_posts'] = isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $_REQUEST['group'] > 3 ? abs((int) $_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1); |
||
| 741 | $_POST['icons'] = (empty($_POST['icon_count']) || $_POST['icon_count'] < 0) ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image']; |
||
| 742 | $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || (isset($_POST['group_type']) && $_POST['group_type'] != -1)) ? trim($_POST['group_desc']) : ''; |
||
| 743 | $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || ($_POST['group_type'] == 1 && !allowedTo('admin_forum')) ? 0 : (int) $_POST['group_type']; |
||
| 744 | $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden']; |
||
| 745 | $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2; |
||
| 746 | $_POST['group_tfa_force'] = (empty($modSettings['tfa_mode']) || $modSettings['tfa_mode'] != 2 || empty($_POST['group_tfa_force'])) ? 0 : 1; |
||
| 747 | |||
| 748 | //@todo Don't set online_color for the Moderators group? |
||
| 749 | |||
| 750 | // Do the update of the membergroup settings. |
||
| 751 | $smcFunc['db_query']('', ' |
||
| 752 | UPDATE {db_prefix}membergroups |
||
| 753 | SET group_name = {string:group_name}, online_color = {string:online_color}, |
||
| 754 | max_messages = {int:max_messages}, min_posts = {int:min_posts}, icons = {string:icons}, |
||
| 755 | description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden}, |
||
| 756 | id_parent = {int:group_inherit}, tfa_required = {int:tfa_required} |
||
| 757 | WHERE id_group = {int:current_group}', |
||
| 758 | array( |
||
| 759 | 'max_messages' => $_POST['max_messages'], |
||
| 760 | 'min_posts' => $_POST['min_posts'], |
||
| 761 | 'group_type' => $_POST['group_type'], |
||
| 762 | 'group_hidden' => $_POST['group_hidden'], |
||
| 763 | 'group_inherit' => $_POST['group_inherit'], |
||
| 764 | 'current_group' => (int) $_REQUEST['group'], |
||
| 765 | 'group_name' => $smcFunc['htmlspecialchars']($_POST['group_name']), |
||
| 766 | 'online_color' => $_POST['online_color'], |
||
| 767 | 'icons' => $_POST['icons'], |
||
| 768 | 'group_desc' => $smcFunc['normalize']($_POST['group_desc']), |
||
| 769 | 'tfa_required' => $_POST['group_tfa_force'], |
||
| 770 | ) |
||
| 771 | ); |
||
| 772 | |||
| 773 | call_integration_hook('integrate_save_membergroup', array((int) $_REQUEST['group'])); |
||
| 774 | |||
| 775 | // Time to update the boards this membergroup has access to. |
||
| 776 | if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) |
||
| 777 | { |
||
| 778 | $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess']; |
||
| 779 | |||
| 780 | $changed_boards['allow'] = array(); |
||
| 781 | $changed_boards['deny'] = array(); |
||
| 782 | $changed_boards['ignore'] = array(); |
||
| 783 | foreach ($accesses as $group_id => $action) |
||
| 784 | $changed_boards[$action][] = (int) $group_id; |
||
| 785 | |||
| 786 | $smcFunc['db_query']('', ' |
||
| 787 | DELETE FROM {db_prefix}board_permissions_view |
||
| 788 | WHERE id_group = {int:group_id}', |
||
| 789 | array( |
||
| 790 | 'group_id' => (int) $_REQUEST['group'], |
||
| 791 | ) |
||
| 792 | ); |
||
| 793 | |||
| 794 | foreach (array('allow', 'deny') as $board_action) |
||
| 795 | { |
||
| 796 | // Find all board this group is in, but shouldn't be in. |
||
| 797 | $request = $smcFunc['db_query']('', ' |
||
| 798 | SELECT id_board, {raw:column} |
||
| 799 | FROM {db_prefix}boards |
||
| 800 | WHERE FIND_IN_SET({string:current_group}, {raw:column}) != 0' . (empty($changed_boards[$board_action]) ? '' : ' |
||
| 801 | AND id_board NOT IN ({array_int:board_access_list})'), |
||
| 802 | array( |
||
| 803 | 'current_group' => (int) $_REQUEST['group'], |
||
| 804 | 'board_access_list' => $changed_boards[$board_action], |
||
| 805 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 806 | ) |
||
| 807 | ); |
||
| 808 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 809 | $smcFunc['db_query']('', ' |
||
| 810 | UPDATE {db_prefix}boards |
||
| 811 | SET {raw:column} = {string:member_group_access} |
||
| 812 | WHERE id_board = {int:current_board}', |
||
| 813 | array( |
||
| 814 | 'current_board' => $row['id_board'], |
||
| 815 | 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))), |
||
| 816 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 817 | ) |
||
| 818 | ); |
||
| 819 | $smcFunc['db_free_result']($request); |
||
| 820 | |||
| 821 | // Add the membergroup to all boards that hadn't been set yet. |
||
| 822 | if (!empty($changed_boards[$board_action])) |
||
| 823 | { |
||
| 824 | $smcFunc['db_query']('', ' |
||
| 825 | UPDATE {db_prefix}boards |
||
| 826 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
||
| 827 | WHERE id_board IN ({array_int:board_list}) |
||
| 828 | AND FIND_IN_SET({int:current_group}, {raw:column}) = 0', |
||
| 829 | array( |
||
| 830 | 'board_list' => $changed_boards[$board_action], |
||
| 831 | 'blank_string' => '', |
||
| 832 | 'current_group' => (int) $_REQUEST['group'], |
||
| 833 | 'group_id_string' => (string) (int) $_REQUEST['group'], |
||
| 834 | 'comma_group' => ',' . $_REQUEST['group'], |
||
| 835 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
||
| 836 | ) |
||
| 837 | ); |
||
| 838 | |||
| 839 | $insert = array(); |
||
| 840 | foreach ($changed_boards[$board_action] as $board_id) |
||
| 841 | $insert[] = array((int) $_REQUEST['group'], $board_id, $board_action == 'allow' ? 0 : 1); |
||
| 842 | |||
| 843 | $smcFunc['db_insert']('insert', |
||
| 844 | '{db_prefix}board_permissions_view', |
||
| 845 | array('id_group' => 'int', 'id_board' => 'int', 'deny' => 'int'), |
||
| 846 | $insert, |
||
| 847 | array('id_group', 'id_board', 'deny') |
||
| 848 | ); |
||
| 849 | } |
||
| 850 | } |
||
| 851 | } |
||
| 852 | |||
| 853 | // Remove everyone from this group! |
||
| 854 | if ($_POST['min_posts'] != -1) |
||
| 855 | { |
||
| 856 | $smcFunc['db_query']('', ' |
||
| 857 | UPDATE {db_prefix}members |
||
| 858 | SET id_group = {int:regular_member} |
||
| 859 | WHERE id_group = {int:current_group}', |
||
| 860 | array( |
||
| 861 | 'regular_member' => 0, |
||
| 862 | 'current_group' => (int) $_REQUEST['group'], |
||
| 863 | ) |
||
| 864 | ); |
||
| 865 | |||
| 866 | $request = $smcFunc['db_query']('', ' |
||
| 867 | SELECT id_member, additional_groups |
||
| 868 | FROM {db_prefix}members |
||
| 869 | WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0', |
||
| 870 | array( |
||
| 871 | 'current_group' => (int) $_REQUEST['group'], |
||
| 872 | ) |
||
| 873 | ); |
||
| 874 | $updates = array(); |
||
| 875 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 876 | $updates[$row['additional_groups']][] = $row['id_member']; |
||
| 877 | $smcFunc['db_free_result']($request); |
||
| 878 | |||
| 879 | foreach ($updates as $additional_groups => $memberArray) |
||
| 880 | updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
||
| 881 | |||
| 882 | // Sorry, but post groups can't moderate boards |
||
| 883 | $smcFunc['db_query']('', ' |
||
| 884 | DELETE FROM {db_prefix}moderator_groups |
||
| 885 | WHERE id_group = {int:current_group}', |
||
| 886 | array( |
||
| 887 | 'current_group' => (int) $_REQUEST['group'], |
||
| 888 | ) |
||
| 889 | ); |
||
| 890 | } |
||
| 891 | elseif ($_REQUEST['group'] != 3) |
||
| 892 | { |
||
| 893 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
||
| 894 | if ($_POST['group_hidden'] == 2) |
||
| 895 | { |
||
| 896 | $request = $smcFunc['db_query']('', ' |
||
| 897 | SELECT id_member, additional_groups |
||
| 898 | FROM {db_prefix}members |
||
| 899 | WHERE id_group = {int:current_group} |
||
| 900 | AND FIND_IN_SET({int:current_group}, additional_groups) = 0', |
||
| 901 | array( |
||
| 902 | 'current_group' => (int) $_REQUEST['group'], |
||
| 903 | ) |
||
| 904 | ); |
||
| 905 | $updates = array(); |
||
| 906 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 907 | $updates[$row['additional_groups']][] = $row['id_member']; |
||
| 908 | $smcFunc['db_free_result']($request); |
||
| 909 | |||
| 910 | foreach ($updates as $additional_groups => $memberArray) |
||
| 911 | { |
||
| 912 | $new_groups = (!empty($additional_groups) ? $additional_groups . ',' : '') . $_REQUEST['group']; // We already validated this a while ago. |
||
| 913 | updateMemberData($memberArray, array('additional_groups' => $new_groups)); |
||
| 914 | } |
||
| 915 | |||
| 916 | $smcFunc['db_query']('', ' |
||
| 917 | UPDATE {db_prefix}members |
||
| 918 | SET id_group = {int:regular_member} |
||
| 919 | WHERE id_group = {int:current_group}', |
||
| 920 | array( |
||
| 921 | 'regular_member' => 0, |
||
| 922 | 'current_group' => $_REQUEST['group'], |
||
| 923 | ) |
||
| 924 | ); |
||
| 925 | |||
| 926 | // Hidden groups can't moderate boards |
||
| 927 | $smcFunc['db_query']('', ' |
||
| 928 | DELETE FROM {db_prefix}moderator_groups |
||
| 929 | WHERE id_group = {int:current_group}', |
||
| 930 | array( |
||
| 931 | 'current_group' => $_REQUEST['group'], |
||
| 932 | ) |
||
| 933 | ); |
||
| 934 | } |
||
| 935 | |||
| 936 | // Either way, let's check our "show group membership" setting is correct. |
||
| 937 | $request = $smcFunc['db_query']('', ' |
||
| 938 | SELECT COUNT(*) |
||
| 939 | FROM {db_prefix}membergroups |
||
| 940 | WHERE group_type > {int:non_joinable}', |
||
| 941 | array( |
||
| 942 | 'non_joinable' => 1, |
||
| 943 | ) |
||
| 944 | ); |
||
| 945 | list ($have_joinable) = $smcFunc['db_fetch_row']($request); |
||
| 946 | $smcFunc['db_free_result']($request); |
||
| 947 | |||
| 948 | // Do we need to update the setting? |
||
| 949 | if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
||
| 950 | updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
||
| 951 | } |
||
| 952 | |||
| 953 | // Do we need to set inherited permissions? |
||
| 954 | if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit']) |
||
| 955 | { |
||
| 956 | require_once($sourcedir . '/ManagePermissions.php'); |
||
| 957 | updateChildPermissions($_POST['group_inherit']); |
||
| 958 | } |
||
| 959 | |||
| 960 | // Finally, moderators! |
||
| 961 | $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : ''; |
||
| 962 | $smcFunc['db_query']('', ' |
||
| 963 | DELETE FROM {db_prefix}group_moderators |
||
| 964 | WHERE id_group = {int:current_group}', |
||
| 965 | array( |
||
| 966 | 'current_group' => $_REQUEST['group'], |
||
| 967 | ) |
||
| 968 | ); |
||
| 969 | if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3) |
||
| 970 | { |
||
| 971 | $group_moderators = array(); |
||
| 972 | |||
| 973 | // Get all the usernames from the string |
||
| 974 | if (!empty($moderator_string)) |
||
| 975 | { |
||
| 976 | $moderator_string = strtr(preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($moderator_string, ENT_QUOTES)), array('"' => '"')); |
||
| 977 | preg_match_all('~"([^"]+)"~', $moderator_string, $matches); |
||
| 978 | $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string))); |
||
| 979 | for ($k = 0, $n = count($moderators); $k < $n; $k++) |
||
| 980 | { |
||
| 981 | $moderators[$k] = trim($moderators[$k]); |
||
| 982 | |||
| 983 | if (strlen($moderators[$k]) == 0) |
||
| 984 | unset($moderators[$k]); |
||
| 985 | } |
||
| 986 | |||
| 987 | // Find all the id_member's for the member_name's in the list. |
||
| 988 | if (!empty($moderators)) |
||
| 989 | { |
||
| 990 | $request = $smcFunc['db_query']('', ' |
||
| 991 | SELECT id_member |
||
| 992 | FROM {db_prefix}members |
||
| 993 | WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators}) |
||
| 994 | LIMIT {int:count}', |
||
| 995 | array( |
||
| 996 | 'moderators' => $moderators, |
||
| 997 | 'count' => count($moderators), |
||
| 998 | ) |
||
| 999 | ); |
||
| 1000 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1001 | $group_moderators[] = $row['id_member']; |
||
| 1002 | $smcFunc['db_free_result']($request); |
||
| 1003 | } |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | if (!empty($_POST['moderator_list'])) |
||
| 1007 | { |
||
| 1008 | $moderators = array(); |
||
| 1009 | foreach ($_POST['moderator_list'] as $moderator) |
||
| 1010 | $moderators[] = (int) $moderator; |
||
| 1011 | |||
| 1012 | if (!empty($moderators)) |
||
| 1013 | { |
||
| 1014 | $request = $smcFunc['db_query']('', ' |
||
| 1015 | SELECT id_member |
||
| 1016 | FROM {db_prefix}members |
||
| 1017 | WHERE id_member IN ({array_int:moderators}) |
||
| 1018 | LIMIT {int:num_moderators}', |
||
| 1019 | array( |
||
| 1020 | 'moderators' => $moderators, |
||
| 1021 | 'num_moderators' => count($moderators), |
||
| 1022 | ) |
||
| 1023 | ); |
||
| 1024 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1025 | $group_moderators[] = $row['id_member']; |
||
| 1026 | $smcFunc['db_free_result']($request); |
||
| 1027 | } |
||
| 1028 | } |
||
| 1029 | |||
| 1030 | // Make sure we don't have any duplicates first... |
||
| 1031 | $group_moderators = array_unique($group_moderators); |
||
| 1032 | |||
| 1033 | // Found some? |
||
| 1034 | if (!empty($group_moderators)) |
||
| 1035 | { |
||
| 1036 | $mod_insert = array(); |
||
| 1037 | foreach ($group_moderators as $moderator) |
||
| 1038 | $mod_insert[] = array($_REQUEST['group'], $moderator); |
||
| 1039 | |||
| 1040 | $smcFunc['db_insert']('insert', |
||
| 1041 | '{db_prefix}group_moderators', |
||
| 1042 | array('id_group' => 'int', 'id_member' => 'int'), |
||
| 1043 | $mod_insert, |
||
| 1044 | array('id_group', 'id_member') |
||
| 1045 | ); |
||
| 1046 | } |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | // There might have been some post group changes. |
||
| 1050 | if ($_POST['min_posts'] != -1) |
||
| 1051 | updateStats('postgroups'); |
||
| 1052 | |||
| 1053 | // We've definitely changed some group stuff. |
||
| 1054 | updateSettings(array( |
||
| 1055 | 'settings_updated' => time(), |
||
| 1056 | )); |
||
| 1057 | |||
| 1058 | // Log the edit. |
||
| 1059 | logAction('edited_group', array('group' => $smcFunc['htmlspecialchars']($_POST['group_name'])), 'admin'); |
||
| 1060 | |||
| 1061 | redirectexit('action=admin;area=membergroups'); |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | // Fetch the current group information. |
||
| 1065 | $request = $smcFunc['db_query']('', ' |
||
| 1066 | SELECT group_name, description, min_posts, online_color, max_messages, icons, group_type, hidden, id_parent, tfa_required |
||
| 1067 | FROM {db_prefix}membergroups |
||
| 1068 | WHERE id_group = {int:current_group} |
||
| 1069 | LIMIT 1', |
||
| 1070 | array( |
||
| 1071 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1072 | ) |
||
| 1073 | ); |
||
| 1074 | if ($smcFunc['db_num_rows']($request) == 0) |
||
| 1075 | fatal_lang_error('membergroup_does_not_exist', false); |
||
| 1076 | $row = $smcFunc['db_fetch_assoc']($request); |
||
| 1077 | $smcFunc['db_free_result']($request); |
||
| 1078 | |||
| 1079 | $row['icons'] = explode('#', $row['icons']); |
||
| 1080 | |||
| 1081 | $context['group'] = array( |
||
| 1082 | 'id' => $_REQUEST['group'], |
||
| 1083 | 'name' => $row['group_name'], |
||
| 1084 | 'description' => $smcFunc['htmlspecialchars']($row['description'], ENT_QUOTES), |
||
| 1085 | 'editable_name' => $row['group_name'], |
||
| 1086 | 'color' => $row['online_color'], |
||
| 1087 | 'min_posts' => $row['min_posts'], |
||
| 1088 | 'max_messages' => $row['max_messages'], |
||
| 1089 | 'icon_count' => (int) $row['icons'][0], |
||
| 1090 | 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '', |
||
| 1091 | 'is_post_group' => $row['min_posts'] != -1, |
||
| 1092 | 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], |
||
| 1093 | 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, |
||
| 1094 | 'inherited_from' => $row['id_parent'], |
||
| 1095 | 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
| 1096 | 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
| 1097 | 'allow_protected' => allowedTo('admin_forum'), |
||
| 1098 | 'tfa_required' => $row['tfa_required'], |
||
| 1099 | ); |
||
| 1100 | |||
| 1101 | // Get any moderators for this group |
||
| 1102 | $request = $smcFunc['db_query']('', ' |
||
| 1103 | SELECT mem.id_member, mem.real_name |
||
| 1104 | FROM {db_prefix}group_moderators AS mods |
||
| 1105 | INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) |
||
| 1106 | WHERE mods.id_group = {int:current_group}', |
||
| 1107 | array( |
||
| 1108 | 'current_group' => $_REQUEST['group'], |
||
| 1109 | ) |
||
| 1110 | ); |
||
| 1111 | $context['group']['moderators'] = array(); |
||
| 1112 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1113 | $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
||
| 1114 | $smcFunc['db_free_result']($request); |
||
| 1115 | |||
| 1116 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
||
| 1117 | |||
| 1118 | if (!empty($context['group']['moderators'])) |
||
| 1119 | list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
||
| 1120 | |||
| 1121 | // Get a list of boards this membergroup is allowed to see. |
||
| 1122 | $context['boards'] = array(); |
||
| 1123 | if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) |
||
| 1124 | { |
||
| 1125 | $request = $smcFunc['db_query']('', ' |
||
| 1126 | SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level, |
||
| 1127 | FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access, FIND_IN_SET({string:current_group}, b.deny_member_groups) != 0 AS cannot_access |
||
| 1128 | FROM {db_prefix}boards AS b |
||
| 1129 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
||
| 1130 | ORDER BY board_order', |
||
| 1131 | array( |
||
| 1132 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1133 | ) |
||
| 1134 | ); |
||
| 1135 | $context['categories'] = array(); |
||
| 1136 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1137 | { |
||
| 1138 | // This category hasn't been set up yet.. |
||
| 1139 | if (!isset($context['categories'][$row['id_cat']])) |
||
| 1140 | $context['categories'][$row['id_cat']] = array( |
||
| 1141 | 'id' => $row['id_cat'], |
||
| 1142 | 'name' => $row['cat_name'], |
||
| 1143 | 'boards' => array() |
||
| 1144 | ); |
||
| 1145 | |||
| 1146 | // Set this board up, and let the template know when it's a child. (indent them..) |
||
| 1147 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
||
| 1148 | 'id' => $row['id_board'], |
||
| 1149 | 'name' => $row['name'], |
||
| 1150 | 'child_level' => $row['child_level'], |
||
| 1151 | 'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'), |
||
| 1152 | 'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'), |
||
| 1153 | ); |
||
| 1154 | } |
||
| 1155 | $smcFunc['db_free_result']($request); |
||
| 1156 | |||
| 1157 | // Now, let's sort the list of categories into the boards for templates that like that. |
||
| 1158 | $temp_boards = array(); |
||
| 1159 | foreach ($context['categories'] as $category) |
||
| 1160 | { |
||
| 1161 | $temp_boards[] = array( |
||
| 1162 | 'name' => $category['name'], |
||
| 1163 | 'child_ids' => array_keys($category['boards']) |
||
| 1164 | ); |
||
| 1165 | $temp_boards = array_merge($temp_boards, array_values($category['boards'])); |
||
| 1166 | |||
| 1167 | // Include a list of boards per category for easy toggling. |
||
| 1168 | $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']); |
||
| 1169 | } |
||
| 1170 | } |
||
| 1171 | |||
| 1172 | // Get a list of all the image formats we can select. |
||
| 1173 | $imageExts = array('png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'); |
||
| 1174 | |||
| 1175 | // Scan the directory. |
||
| 1176 | $context['possible_icons'] = array(); |
||
| 1177 | if ($files = scandir($settings['default_theme_dir'] . '/images/membericons')) |
||
| 1178 | { |
||
| 1179 | // Loop through every file in the directory. |
||
| 1180 | foreach ($files as $value) |
||
| 1181 | { |
||
| 1182 | // Grab the image extension. |
||
| 1183 | $ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); |
||
| 1184 | |||
| 1185 | // If the extension is not empty, and it is valid |
||
| 1186 | if (!empty($ext) && in_array($ext, $imageExts)) |
||
| 1187 | $context['possible_icons'][] = $value; |
||
| 1188 | } |
||
| 1189 | } |
||
| 1190 | |||
| 1191 | // Insert our JS, if we have possible icons. |
||
| 1192 | if (!empty($context['possible_icons'])) |
||
| 1193 | loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
||
| 1194 | |||
| 1195 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
||
| 1196 | |||
| 1197 | // Finally, get all the groups this could be inherited off. |
||
| 1198 | $request = $smcFunc['db_query']('', ' |
||
| 1199 | SELECT id_group, group_name |
||
| 1200 | FROM {db_prefix}membergroups |
||
| 1201 | WHERE id_group != {int:current_group}' . |
||
| 1202 | (empty($modSettings['permission_enable_postgroups']) ? ' |
||
| 1203 | AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : ' |
||
| 1204 | AND group_type != {int:is_protected}') . ' |
||
| 1205 | AND id_group NOT IN (1, 3) |
||
| 1206 | AND id_parent = {int:not_inherited}', |
||
| 1207 | array( |
||
| 1208 | 'current_group' => (int) $_REQUEST['group'], |
||
| 1209 | 'min_posts' => -1, |
||
| 1210 | 'not_inherited' => -2, |
||
| 1211 | 'is_protected' => 1, |
||
| 1212 | ) |
||
| 1213 | ); |
||
| 1214 | $context['inheritable_groups'] = array(); |
||
| 1215 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
| 1216 | $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
||
| 1217 | $smcFunc['db_free_result']($request); |
||
| 1218 | |||
| 1219 | call_integration_hook('integrate_view_membergroup'); |
||
| 1220 | |||
| 1221 | $context['sub_template'] = 'edit_group'; |
||
| 1222 | $context['page_title'] = $txt['membergroups_edit_group']; |
||
| 1223 | |||
| 1224 | createToken('admin-mmg'); |
||
| 1225 | } |
||
| 1273 | ?> |