Completed
Push — master ( c9546d...95f607 )
by Julito
09:41
created

public/main/admin/ldap_users_list.php (5 issues)

Labels
Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
/**
4
 * @author Mustapha Alouani
5
 */
6
$cidReset = true;
7
require_once __DIR__.'/../inc/global.inc.php';
8
require '../auth/ldap/authldap.php';
9
$this_section = SECTION_PLATFORM_ADMIN;
10
11
api_protect_admin_script();
12
13
$action = @$_GET["action"] ?: null;
14
$login_as_user_id = @$_GET["user_id"] ?: null;
15
16
// Login as ...
17
if ("login_as" == $action && !empty($login_as_user_id)) {
18
    login_user($login_as_user_id);
0 ignored issues
show
The function login_user was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
    /** @scrutinizer ignore-call */ 
19
    login_user($login_as_user_id);
Loading history...
19
}
20
21
//if we already have a session id and a user...
22
/*
23
if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){
24
    header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
25
}
26
*/
27
28
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('Administration')];
29
$tool_name = get_lang('Search for LDAP users');
30
//Display::display_header($tool_name); //cannot display now as we need to redirect
31
//api_display_tool_title($tool_name);
32
33
if (isset($_GET['action'])) {
34
    $check = Security::check_token('get');
35
    if ($check) {
36
        switch ($_GET['action']) {
37
            case 'show_message':
38
                Display::addFlash(Display::return_message($_GET['message'], 'normal'));
39
                Display::display_header($tool_name);
40
                break;
41
            case 'delete_user':
42
                if ($user_id != $_user['user_id'] && UserManager::delete_user($_GET['user_id'])) {
43
                    Display::addFlash(Display::return_message(get_lang('The user has been deleted'), 'normal'));
44
                } else {
45
                    Display::addFlash(Display::return_message(get_lang('You cannot delete this user'), 'error'));
46
                }
47
                Display::display_header($tool_name);
48
                break;
49
            case 'lock':
50
                $message = lock_unlock_user('lock', $_GET['user_id']);
0 ignored issues
show
The function lock_unlock_user was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
                $message = /** @scrutinizer ignore-call */ lock_unlock_user('lock', $_GET['user_id']);
Loading history...
51
                Display::addFlash(Display::return_message($message, 'normal'));
52
                Display::display_header($tool_name);
53
                break;
54
            case 'unlock':
55
                $message = lock_unlock_user('unlock', $_GET['user_id']);
56
                Display::addFlash(Display::return_message($message, 'normal'));
57
                Display::display_header($tool_name);
58
                break;
59
            case 'add_user':
60
                $id = $_GET['id'];
61
                $UserList = [];
62
                $userid_match_login = [];
63
                foreach ($id as $user_id) {
64
                    $tmp = ldap_add_user($user_id);
0 ignored issues
show
The function ldap_add_user was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
                    $tmp = /** @scrutinizer ignore-call */ ldap_add_user($user_id);
Loading history...
65
                    $UserList[] = $tmp;
66
                    $userid_match_login[$tmp] = $user_id;
67
                }
68
                if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session'] > 0)) {
69
                    ldap_add_user_to_session($UserList, $_GET['id_session']);
0 ignored issues
show
The function ldap_add_user_to_session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
                    /** @scrutinizer ignore-call */ 
70
                    ldap_add_user_to_session($UserList, $_GET['id_session']);
Loading history...
70
                    header('Location: resume_session.php?id_session='.intval($_GET['id_session']));
71
                } else {
72
                    if (count($userid_match_login) > 0) {
73
                        $message = get_lang('LDAP users added or updated').':<br />';
74
                        foreach ($userid_match_login as $user_id => $login) {
75
                            $message .= '- '.$login.'<br />';
76
                        }
77
                    } else {
78
                        $message = get_lang('No user added');
79
                    }
80
                    Display::addFlash(Display::return_message($message, 'normal', false));
81
                    Display::display_header($tool_name);
82
                }
83
                break;
84
            default:
85
                Display::display_header($tool_name);
86
        }
87
        Security::clear_token();
88
    } else {
89
        Display::display_header($tool_name);
90
    }
91
} else {
92
    Display::display_header($tool_name);
93
}
94
95
if (isset($_POST['action'])) {
96
    $check = Security::check_token('get');
97
    if ($check) {
98
        switch ($_POST['action']) {
99
            case 'delete':
100
                $number_of_selected_users = count($_POST['id']);
101
                $number_of_deleted_users = 0;
102
                foreach ($_POST['id'] as $index => $user_id) {
103
                    if ($user_id != $_user['user_id']) {
104
                        if (UserManager::delete_user($user_id)) {
105
                            $number_of_deleted_users++;
106
                        }
107
                    }
108
                }
109
                if ($number_of_selected_users == $number_of_deleted_users) {
110
                    echo Display::return_message(get_lang('Selected users deleted'), 'normal');
111
                } else {
112
                    echo Display::return_message(get_lang('Some of the selected users have not been deleted. We recommend you confirm which, by using the advanced search.'), 'error');
113
                }
114
                break;
115
            case 'add_user':
116
                $number_of_selected_users = count($_POST['id']);
117
                $number_of_added_users = 0;
118
                $UserList = [];
119
                foreach ($_POST['id'] as $index => $user_id) {
120
                    if ($user_id != $_user['user_id']) {
121
                        $UserList[] = ldap_add_user($user_id);
122
                    }
123
                }
124
                if (isset($_GET['id_session']) && ("" != trim($_GET['id_session']))) {
125
                    addUserToSession($UserList, $_GET['id_session']);
0 ignored issues
show
The function addUserToSession was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
                    /** @scrutinizer ignore-call */ 
126
                    addUserToSession($UserList, $_GET['id_session']);
Loading history...
126
                }
127
                if (count($UserList) > 0) {
128
                    echo Display::return_message(
129
                        count($UserList)." ".get_lang('LDAP users added')
130
                    );
131
                } else {
132
                    echo Display::return_message(get_lang('No user added'));
133
                }
134
                break;
135
        }
136
        Security::clear_token();
137
    }
138
}
139
140
$form = new FormValidator('advanced_search', 'get');
141
$form->addText('keyword_username', get_lang('Login'), false);
142
if (api_is_western_name_order()) {
143
    $form->addText('keyword_firstname', get_lang('First name'), false);
144
    $form->addText('keyword_lastname', get_lang('Last name'), false);
145
} else {
146
    $form->addText('keyword_lastname', get_lang('Last name'), false);
147
    $form->addText('keyword_firstname', get_lang('First name'), false);
148
}
149
if (isset($_GET['id_session'])) {
150
    $form->addElement('hidden', 'id_session', $_GET['id_session']);
151
}
152
153
$type = [];
154
$type["all"] = get_lang('All');
155
$type["employee"] = get_lang('Trainer');
156
$type["student"] = get_lang('Learner');
157
158
$form->addElement('select', 'keyword_type', get_lang('Status'), $type);
159
// Structure a rajouer ??
160
$form->addElement('submit', 'submit', get_lang('Validate'));
161
//$defaults['keyword_active'] = 1;
162
//$defaults['keyword_inactive'] = 1;
163
//$form->setDefaults($defaults);
164
$form->display();
165
$parameters['keyword_username'] = @$_GET['keyword_username'] ?: null;
166
$parameters['keyword_firstname'] = @$_GET['keyword_firstname'] ?: null;
167
$parameters['keyword_lastname'] = @$_GET['keyword_lastname'] ?: null;
168
$parameters['keyword_email'] = @$_GET['keyword_email'] ?: null;
169
if (isset($_GET['id_session'])) {
170
    $parameters['id_session'] = $_GET['id_session'];
171
}
172
// Create a sortable table with user-data
173
174
$parameters['sec_token'] = Security::get_token();
175
$table = new SortableTable(
176
    'users',
177
    'ldap_get_number_of_users',
178
    'ldap_get_user_data',
179
    (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
180
);
181
$table->set_additional_parameters($parameters);
182
$table->set_header(0, '', false);
183
$table->set_header(1, get_lang('Login'));
184
if (api_is_western_name_order()) {
185
    $table->set_header(2, get_lang('First name'));
186
    $table->set_header(3, get_lang('Last name'));
187
} else {
188
    $table->set_header(2, get_lang('Last name'));
189
    $table->set_header(3, get_lang('First name'));
190
}
191
$table->set_header(4, get_lang('e-mail'));
192
$table->set_header(5, get_lang('Detail'));
193
//$table->set_column_filter(5, 'email_filter');
194
//$table->set_column_filter(5, 'active_filter');
195
$table->set_column_filter(5, 'modify_filter');
196
$table->set_form_actions(['add_user' => get_lang('Add LDAP users')]);
197
$table->display();
198
199
Display::display_footer();
200