Conditions | 111 |
Total Lines | 575 |
Code Lines | 293 |
Lines | 0 |
Ratio | 0 % |
Changes | 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($_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 | updateStats('postgroups'); |
||
1051 | // We've definitely changed some group stuff. |
||
1052 | updateSettings(array( |
||
1053 | 'settings_updated' => time(), |
||
1054 | )); |
||
1055 | |||
1056 | // Log the edit. |
||
1057 | logAction('edited_group', array('group' => $smcFunc['htmlspecialchars']($_POST['group_name'])), 'admin'); |
||
1058 | |||
1059 | redirectexit('action=admin;area=membergroups'); |
||
1060 | } |
||
1061 | |||
1062 | // Fetch the current group information. |
||
1063 | $request = $smcFunc['db_query']('', ' |
||
1064 | SELECT group_name, description, min_posts, online_color, max_messages, icons, group_type, hidden, id_parent, tfa_required |
||
1065 | FROM {db_prefix}membergroups |
||
1066 | WHERE id_group = {int:current_group} |
||
1067 | LIMIT 1', |
||
1068 | array( |
||
1069 | 'current_group' => (int) $_REQUEST['group'], |
||
1070 | ) |
||
1071 | ); |
||
1072 | if ($smcFunc['db_num_rows']($request) == 0) |
||
1073 | fatal_lang_error('membergroup_does_not_exist', false); |
||
1074 | $row = $smcFunc['db_fetch_assoc']($request); |
||
1075 | $smcFunc['db_free_result']($request); |
||
1076 | |||
1077 | $row['icons'] = explode('#', $row['icons']); |
||
1078 | |||
1079 | $context['group'] = array( |
||
1080 | 'id' => $_REQUEST['group'], |
||
1081 | 'name' => $row['group_name'], |
||
1082 | 'description' => $smcFunc['htmlspecialchars']($row['description'], ENT_QUOTES), |
||
1083 | 'editable_name' => $row['group_name'], |
||
1084 | 'color' => $row['online_color'], |
||
1085 | 'min_posts' => $row['min_posts'], |
||
1086 | 'max_messages' => $row['max_messages'], |
||
1087 | 'icon_count' => (int) $row['icons'][0], |
||
1088 | 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '', |
||
1089 | 'is_post_group' => $row['min_posts'] != -1, |
||
1090 | 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'], |
||
1091 | 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0, |
||
1092 | 'inherited_from' => $row['id_parent'], |
||
1093 | 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
1094 | 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4, |
||
1095 | 'allow_protected' => allowedTo('admin_forum'), |
||
1096 | 'tfa_required' => $row['tfa_required'], |
||
1097 | ); |
||
1098 | |||
1099 | // Get any moderators for this group |
||
1100 | $request = $smcFunc['db_query']('', ' |
||
1101 | SELECT mem.id_member, mem.real_name |
||
1102 | FROM {db_prefix}group_moderators AS mods |
||
1103 | INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) |
||
1104 | WHERE mods.id_group = {int:current_group}', |
||
1105 | array( |
||
1106 | 'current_group' => $_REQUEST['group'], |
||
1107 | ) |
||
1108 | ); |
||
1109 | $context['group']['moderators'] = array(); |
||
1110 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1111 | $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
||
1112 | $smcFunc['db_free_result']($request); |
||
1113 | |||
1114 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
||
1115 | |||
1116 | if (!empty($context['group']['moderators'])) |
||
1117 | list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
||
1118 | |||
1119 | // Get a list of boards this membergroup is allowed to see. |
||
1120 | $context['boards'] = array(); |
||
1121 | if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3) |
||
1122 | { |
||
1123 | $request = $smcFunc['db_query']('', ' |
||
1124 | SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level, |
||
1125 | 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 |
||
1126 | FROM {db_prefix}boards AS b |
||
1127 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat) |
||
1128 | ORDER BY board_order', |
||
1129 | array( |
||
1130 | 'current_group' => (int) $_REQUEST['group'], |
||
1131 | ) |
||
1132 | ); |
||
1133 | $context['categories'] = array(); |
||
1134 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1135 | { |
||
1136 | // This category hasn't been set up yet.. |
||
1137 | if (!isset($context['categories'][$row['id_cat']])) |
||
1138 | $context['categories'][$row['id_cat']] = array( |
||
1139 | 'id' => $row['id_cat'], |
||
1140 | 'name' => $row['cat_name'], |
||
1141 | 'boards' => array() |
||
1142 | ); |
||
1143 | |||
1144 | // Set this board up, and let the template know when it's a child. (indent them..) |
||
1145 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
||
1146 | 'id' => $row['id_board'], |
||
1147 | 'name' => $row['name'], |
||
1148 | 'child_level' => $row['child_level'], |
||
1149 | 'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'), |
||
1150 | 'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'), |
||
1151 | ); |
||
1152 | } |
||
1153 | $smcFunc['db_free_result']($request); |
||
1154 | |||
1155 | // Now, let's sort the list of categories into the boards for templates that like that. |
||
1156 | $temp_boards = array(); |
||
1157 | foreach ($context['categories'] as $category) |
||
1158 | { |
||
1159 | $temp_boards[] = array( |
||
1160 | 'name' => $category['name'], |
||
1161 | 'child_ids' => array_keys($category['boards']) |
||
1162 | ); |
||
1163 | $temp_boards = array_merge($temp_boards, array_values($category['boards'])); |
||
1164 | |||
1165 | // Include a list of boards per category for easy toggling. |
||
1166 | $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']); |
||
1167 | } |
||
1168 | } |
||
1169 | |||
1170 | // Get a list of all the image formats we can select. |
||
1171 | $imageExts = array('png', 'jpg', 'jpeg', 'bmp', 'gif'); |
||
1172 | |||
1173 | // Scan the directory. |
||
1174 | $context['possible_icons'] = array(); |
||
1175 | if ($files = scandir($settings['default_theme_dir'] . '/images/membericons')) |
||
1176 | { |
||
1177 | // Loop through every file in the directory. |
||
1178 | foreach ($files as $value) |
||
1179 | { |
||
1180 | // Grab the image extension. |
||
1181 | $ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION); |
||
1182 | |||
1183 | // If the extension is not empty, and it is valid |
||
1184 | if (!empty($ext) && in_array($ext, $imageExts)) |
||
1185 | $context['possible_icons'][] = $value; |
||
1186 | } |
||
1187 | } |
||
1188 | |||
1189 | // Insert our JS, if we have possible icons. |
||
1190 | if (!empty($context['possible_icons'])) |
||
1191 | loadJavaScriptFile('icondropdown.js', array('validate' => true, 'minimize' => true), 'smf_icondropdown'); |
||
1192 | |||
1193 | loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
||
1194 | |||
1195 | // Finally, get all the groups this could be inherited off. |
||
1196 | $request = $smcFunc['db_query']('', ' |
||
1197 | SELECT id_group, group_name |
||
1198 | FROM {db_prefix}membergroups |
||
1199 | WHERE id_group != {int:current_group}' . |
||
1200 | (empty($modSettings['permission_enable_postgroups']) ? ' |
||
1201 | AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : ' |
||
1202 | AND group_type != {int:is_protected}') . ' |
||
1203 | AND id_group NOT IN (1, 3) |
||
1204 | AND id_parent = {int:not_inherited}', |
||
1205 | array( |
||
1206 | 'current_group' => (int) $_REQUEST['group'], |
||
1207 | 'min_posts' => -1, |
||
1208 | 'not_inherited' => -2, |
||
1209 | 'is_protected' => 1, |
||
1210 | ) |
||
1211 | ); |
||
1212 | $context['inheritable_groups'] = array(); |
||
1213 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1214 | $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
||
1215 | $smcFunc['db_free_result']($request); |
||
1216 | |||
1217 | call_integration_hook('integrate_view_membergroup'); |
||
1218 | |||
1219 | $context['sub_template'] = 'edit_group'; |
||
1220 | $context['page_title'] = $txt['membergroups_edit_group']; |
||
1221 | |||
1222 | createToken('admin-mmg'); |
||
1223 | } |
||
1271 | ?> |