|
14 | 14 | $this_section = SECTION_PLATFORM_ADMIN;
|
15 | 15 | api_protect_admin_script(true, null);
|
16 | 16 |
|
17 |
| -$tool_name = get_lang('BulkAnonymizeUsers'); |
18 |
| -$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')]; |
| 17 | +$tool_name = get_lang('Anonymise users list'); |
| 18 | +$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('Administration')]; |
19 | 19 |
|
20 | 20 | set_time_limit(0);
|
21 | 21 | ini_set('memory_limit', -1);
|
|
24 | 24 |
|
25 | 25 | $step1Form = new FormValidator('step1Form');
|
26 | 26 |
|
27 |
| -$usernameListFile = $step1Form->addFile('usernameList', get_lang('UsernameList')); |
| 27 | +$usernameListFile = $step1Form->addFile('usernameList', get_lang('Username list')); |
28 | 28 | $step1Form->addButtonUpload(get_lang('Upload'));
|
29 | 29 |
|
30 | 30 | $step2Form = new FormValidator('step2Form');
|
31 | 31 | $usernameTextarea = $step2Form->addTextarea(
|
32 | 32 | 'usersToBeAnonymized',
|
33 |
| - get_lang('UsersAboutToBeAnonymized'), |
| 33 | + get_lang('Users about to be anonymized:'), |
34 | 34 | [
|
35 | 35 | 'readonly' => 1,
|
36 | 36 | ]
|
37 | 37 | );
|
38 |
| -$anonymizedSessions = $step2Form->addCheckBox('anonymize_sessions', null, get_lang('AnonymizeUserSessions')); |
| 38 | +$anonymizedSessions = $step2Form->addCheckBox('anonymize_sessions', null, get_lang("Anonymize user's sessions")); |
39 | 39 | $step2Form->addButtonUpdate(get_lang('Anonymize'));
|
40 | 40 |
|
41 | 41 | if ($step1Form->validate() && $usernameListFile->isUploadedFile()) {
|
42 | 42 | $usernameListFileUploaded = $usernameListFile->getValue();
|
43 | 43 | $usernameListFileUploaded['name'] = api_htmlentities($usernameListFileUploaded['name']);
|
44 | 44 | $filePath = $usernameListFileUploaded['tmp_name'];
|
45 | 45 | if (!file_exists($filePath)) {
|
46 |
| - throw new Exception(get_lang('CouldNotReadFile').' '.$filePath); |
| 46 | + throw new Exception(get_lang('Could not read file.').' '.$filePath); |
47 | 47 | }
|
48 | 48 | $submittedUsernames = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
49 | 49 | if (false === $submittedUsernames) {
|
50 |
| - throw new Exception(get_lang('CouldNotReadFileLines').' '.$filePath); |
| 50 | + throw new Exception(get_lang('Could not read file lines.').' '.$filePath); |
51 | 51 | }
|
52 | 52 |
|
53 | 53 | $submittedUsernames = array_map('api_htmlentities', $submittedUsernames);
|
54 | 54 | $submittedUsernames = array_filter($submittedUsernames);
|
55 | 55 |
|
56 | 56 | if (empty($submittedUsernames)) {
|
57 | 57 | printf(
|
58 |
| - '<p>'.get_lang('FileXHasNoData').'</p>', |
| 58 | + '<p>'.get_lang('File %s is empty or only contains empty lines.').'</p>', |
59 | 59 | '<em>'.$usernameListFileUploaded['name'].'</em>'
|
60 | 60 | );
|
61 | 61 | } else {
|
62 | 62 | printf(
|
63 |
| - '<p>'.get_lang('FileXHasYNonEmptyLines').'</p>', |
| 63 | + '<p>'.get_lang('File %s has %d non-empty lines.').'</p>', |
64 | 64 | '<em>'.$usernameListFileUploaded['name'].'</em>',
|
65 | 65 | count($submittedUsernames)
|
66 | 66 | );
|
67 | 67 | $uniqueSubmittedUsernames = array_values(array_unique($submittedUsernames));
|
68 | 68 | if (count($uniqueSubmittedUsernames) !== count($submittedUsernames)) {
|
69 | 69 | printf(
|
70 |
| - '<p>'.get_lang('DuplicatesOnlyXUniqueUserNames').'</p>', |
| 70 | + '<p>'.get_lang('There are duplicates: only %d unique user names were extracted.').'</p>', |
71 | 71 | count($uniqueSubmittedUsernames)
|
72 | 72 | );
|
73 | 73 | }
|
|
82 | 82 | }
|
83 | 83 | }
|
84 | 84 | if (empty($users)) {
|
85 |
| - echo '<p>'.get_lang('NoLineMatchedAnyActualUserName').'</p>'; |
| 85 | + echo '<p>'.get_lang('No line matched any actual user name.').'</p>'; |
86 | 86 | } else {
|
87 | 87 | $foundUsernames = [];
|
88 | 88 | /** @var User $user */
|
89 | 89 | foreach ($users as $user) {
|
90 | 90 | $foundUsernames[] = $user->getUsername();
|
91 | 91 | }
|
92 | 92 | if (count($users) !== count($uniqueSubmittedUsernames)) {
|
93 |
| - printf('<p>'.get_lang('OnlyXLinesMatchedActualUsers').'</p>', count($users)); |
| 93 | + printf('<p>'.get_lang('Only %d lines matched actual users.').'</p>', count($users)); |
94 | 94 | $usernamesNotFound = array_diff($uniqueSubmittedUsernames, $foundUsernames);
|
95 | 95 | printf(
|
96 |
| - '<p>'.get_lang('TheFollowingXLinesDoNotMatchAnyActualUser').'<pre>%s</pre></p>', |
| 96 | + '<p>'.get_lang('The following %d line(s) do not match any actual user:').'<pre>%s</pre></p>', |
97 | 97 | count($usernamesNotFound),
|
98 | 98 | join("\n", $usernamesNotFound)
|
99 | 99 | );
|
100 | 100 | }
|
101 |
| - printf('<p>'.get_lang('XUsersAreAboutToBeAnonymized').'</p>', count($foundUsernames)); |
| 101 | + printf('<p>'.get_lang('%d users are about to be anonymized :').'</p>', count($foundUsernames)); |
102 | 102 | $usernameTextarea->setValue(join("\n", $foundUsernames));
|
103 | 103 | $step2Form->display();
|
104 | 104 | }
|
|
108 | 108 | if (false === $usernames) {
|
109 | 109 | throw new Exception('preg_split failed');
|
110 | 110 | }
|
111 |
| - printf('<p>'.get_lang('LoadingXUsers')."</p>\n", count($usernames)); |
| 111 | + printf('<p>'.get_lang('Loading %d users...')."</p>\n", count($usernames)); |
112 | 112 | $users = UserManager::getRepository()->matching(
|
113 | 113 | Criteria::create()->where(
|
114 | 114 | Criteria::expr()->in('username', $usernames)
|
115 | 115 | )
|
116 | 116 | );
|
117 | 117 | $anonymizedSessionsValue = $anonymizedSessions->getValue();
|
118 | 118 | if (count($users) === count($usernames)) {
|
119 |
| - printf('<p>'.get_lang('AnonymizingXUsers')."</p>\n", count($users)); |
| 119 | + printf('<p>'.get_lang('Anonymizing %d users...')."</p>\n", count($users)); |
120 | 120 | $anonymized = [];
|
121 | 121 | $errors = [];
|
122 | 122 | $tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
|
|
136 | 136 | $sessionId = $session['id'];
|
137 | 137 | $sessionTitle = $session['name'];
|
138 | 138 | $usersCount = SessionManager::get_users_by_session($sessionId, null, true);
|
139 |
| - echo '<p> '.$sessionTitle.' ('.$sessionId.') - '.get_lang('Students').': '.$usersCount.'</p>'; |
| 139 | + echo '<p> '.$sessionTitle.' ('.$sessionId.') - '.get_lang('Learners').': '.$usersCount.'</p>'; |
140 | 140 | if (1 === $usersCount) {
|
141 | 141 | $uniqueId = uniqid('anon_session', true);
|
142 | 142 | echo '<p> '.get_lang('Rename').': '.$sessionTitle.' -> '.$uniqueId.'</p>';
|
143 | 143 | $sql = "UPDATE $tableSession SET name = '$uniqueId' WHERE id = $sessionId";
|
144 | 144 | Database::query($sql);
|
145 | 145 | } else {
|
146 |
| - echo '<p> '.sprintf(get_lang('SessionXSkipped'), $sessionTitle).'</p>'; |
| 146 | + echo '<p> '.sprintf(get_lang('Session %s skipped'), $sessionTitle).'</p>'; |
147 | 147 | }
|
148 | 148 | }
|
149 | 149 | }
|
|
161 | 161 | echo "</p>\n";
|
162 | 162 | }
|
163 | 163 | if (empty($error)) {
|
164 |
| - printf('<p>'.get_lang('AllXUsersWereAnonymized').'</p>', count($users)); |
| 164 | + printf('<p>'.get_lang('All %d users were anonymized.').'</p>', count($users)); |
165 | 165 | } else {
|
166 | 166 | printf(
|
167 | 167 | '<p>'
|
168 |
| - .get_lang('OnlyXUsersWereAnonymized') |
| 168 | + .get_lang('Only %d users were anonymized.') |
169 | 169 | .' '
|
170 |
| - .get_lang('AttemptedAnonymizationOfTheseXUsersFailed') |
| 170 | + .get_lang('Attempted anonymization of the following %d users failed:') |
171 | 171 | .'<pre>%s</pre></p>',
|
172 | 172 | count($users),
|
173 | 173 | count($errors),
|
|
176 | 176 | }
|
177 | 177 | } else {
|
178 | 178 | printf(
|
179 |
| - '<p>'.get_lang('InternalInconsistencyXUsersFoundForYUserNames').'</p>', |
| 179 | + '<p>'.get_lang('Internal inconsistency found : %d users found from %d submitted usernames. Please start over.').'</p>', |
180 | 180 | count($users),
|
181 | 181 | count($usernames)
|
182 | 182 | );
|
183 | 183 | }
|
184 | 184 | } else {
|
185 |
| - echo '<p>'.get_lang('PleaseUploadListOfUsers').'</p>'; |
| 185 | + echo '<p>'.get_lang('Please upload a text file listing the users to be anonymized, one username per line.').'</p>'; |
186 | 186 | $step1Form->display();
|
187 | 187 | }
|
188 | 188 |
|
|
0 commit comments