Code Duplication    Length = 97-97 lines in 2 locations

src/groups/members.php 1 location

@@ 63-159 (lines=97) @@
60
61
// add/remove selected accounts
62
63
if (try_request('submitted') == 'othersform')
64
{
65
    debug_write_log(DEBUG_NOTICE, 'Data are submitted (adding new members).');
66
67
    if (LDAP_ENABLED && !LDAP_ENUMERATION)
68
    {
69
        $accounts = ustrcut($_REQUEST['accounts'], 1000);
70
        $accounts = ustr_replace("\n", ',', $accounts);
71
72
        mb_regex_encoding('UTF-8');
73
        $names = mb_split(',', $accounts);
74
75
        $accounts = NULL;
76
    }
77
    else
78
    {
79
        $names = try_request('accounts', array());
80
    }
81
82
    foreach ($names as $username)
83
    {
84
        $username = trim($username);
85
86
        if (ustrlen($username) != 0)
87
        {
88
            if (LDAP_ENABLED && !LDAP_ENUMERATION)
89
            {
90
                if (usubstr($username, ustrlen($username) - 1, 1) == '@')
91
                {
92
                    debug_write_log(DEBUG_NOTICE, 'Found @ at the end of login.');
93
                    $username = usubstr($username, 0, ustrlen($username) - 1);
94
                    $account = FALSE;
95
                }
96
                else
97
                {
98
                    $account = account_find_username($username . ACCOUNT_SUFFIX);
99
                }
100
            }
101
            else
102
            {
103
                $account = account_find_username($username);
104
            }
105
106
            if ($account)
107
            {
108
                group_membership_add($id, $account['account_id']);
109
            }
110
            else
111
            {
112
                $account_id = (LDAP_ENABLED ? account_register_ldapuser($username) : NULL);
113
114
                if (is_null($account_id))
115
                {
116
                    debug_write_log(DEBUG_NOTICE, 'Cannot find Active Directory account.');
117
118
                    if (LDAP_ENABLED && !LDAP_ENUMERATION)
119
                    {
120
                        $accounts .= $username . "\n";
121
                    }
122
                }
123
                else
124
                {
125
                    group_membership_add($id, $account_id);
126
                }
127
            }
128
        }
129
    }
130
131
    if (LDAP_ENABLED && !LDAP_ENUMERATION)
132
    {
133
        $_SESSION[VAR_LDAP_ENUMERATION] = $accounts;
134
    }
135
136
    exit;
137
}
138
elseif (try_request('submitted') == 'membersform')
139
{
140
    debug_write_log(DEBUG_NOTICE, 'Data are submitted (removing selected members).');
141
142
    if (isset($_REQUEST['accounts']))
143
    {
144
        foreach ($_REQUEST['accounts'] as $account)
145
        {
146
            group_membership_remove($id, $account);
147
        }
148
    }
149
    else
150
    {
151
        debug_write_log(DEBUG_NOTICE, 'No accounts are selected.');
152
    }
153
154
    exit;
155
}
156
else
157
{
158
    debug_write_log(DEBUG_NOTICE, 'Data are being requested.');
159
}
160
161
// generate left side
162

src/projects/gmembers.php 1 location

@@ 69-165 (lines=97) @@
66
67
// add/remove selected accounts
68
69
if (try_request('submitted') == 'othersform')
70
{
71
    debug_write_log(DEBUG_NOTICE, 'Data are submitted (adding new members).');
72
73
    if (LDAP_ENABLED && !LDAP_ENUMERATION)
74
    {
75
        $accounts = ustrcut($_REQUEST['accounts'], 1000);
76
        $accounts = ustr_replace("\n", ',', $accounts);
77
78
        mb_regex_encoding('UTF-8');
79
        $names = mb_split(',', $accounts);
80
81
        $accounts = NULL;
82
    }
83
    else
84
    {
85
        $names = try_request('accounts', array());
86
    }
87
88
    foreach ($names as $username)
89
    {
90
        $username = trim($username);
91
92
        if (ustrlen($username) != 0)
93
        {
94
            if (LDAP_ENABLED && !LDAP_ENUMERATION)
95
            {
96
                if (usubstr($username, ustrlen($username) - 1, 1) == '@')
97
                {
98
                    debug_write_log(DEBUG_NOTICE, 'Found @ at the end of login.');
99
                    $username = usubstr($username, 0, ustrlen($username) - 1);
100
                    $account = FALSE;
101
                }
102
                else
103
                {
104
                    $account = account_find_username($username . ACCOUNT_SUFFIX);
105
                }
106
            }
107
            else
108
            {
109
                $account = account_find_username($username);
110
            }
111
112
            if ($account)
113
            {
114
                group_membership_add($id, $account['account_id']);
115
            }
116
            else
117
            {
118
                $account_id = (LDAP_ENABLED ? account_register_ldapuser($username) : NULL);
119
120
                if (is_null($account_id))
121
                {
122
                    debug_write_log(DEBUG_NOTICE, 'Cannot find Active Directory account.');
123
124
                    if (LDAP_ENABLED && !LDAP_ENUMERATION)
125
                    {
126
                        $accounts .= $username . "\n";
127
                    }
128
                }
129
                else
130
                {
131
                    group_membership_add($id, $account_id);
132
                }
133
            }
134
        }
135
    }
136
137
    if (LDAP_ENABLED && !LDAP_ENUMERATION)
138
    {
139
        $_SESSION[VAR_LDAP_ENUMERATION] = $accounts;
140
    }
141
142
    exit;
143
}
144
elseif (try_request('submitted') == 'membersform')
145
{
146
    debug_write_log(DEBUG_NOTICE, 'Data are submitted (removing selected members).');
147
148
    if (isset($_REQUEST['accounts']))
149
    {
150
        foreach ($_REQUEST['accounts'] as $account)
151
        {
152
            group_membership_remove($id, $account);
153
        }
154
    }
155
    else
156
    {
157
        debug_write_log(DEBUG_NOTICE, 'No accounts are selected.');
158
    }
159
160
    exit;
161
}
162
else
163
{
164
    debug_write_log(DEBUG_NOTICE, 'Data are being requested.');
165
}
166
167
// generate left side
168