parent
							
								
									7d5d3a2f92
								
							
						
					
					
						commit
						9e3b21b73c
					
				@ -0,0 +1,159 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * This tool allows platform admins to anonymize users by uploading a text file, with one username per line. | 
				
			||||
 * | 
				
			||||
 * @package chamilo.admin | 
				
			||||
 */ | 
				
			||||
 | 
				
			||||
use Doctrine\Common\Collections\Criteria; | 
				
			||||
 | 
				
			||||
$cidReset = true; | 
				
			||||
require_once __DIR__.'/../inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
$this_section = SECTION_PLATFORM_ADMIN; | 
				
			||||
api_protect_admin_script(true, null); | 
				
			||||
 | 
				
			||||
$tool_name = get_lang('BulkAnonymizeUsers'); | 
				
			||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')]; | 
				
			||||
 | 
				
			||||
set_time_limit(0); | 
				
			||||
ini_set('memory_limit', -1); | 
				
			||||
 | 
				
			||||
Display::display_header($tool_name); | 
				
			||||
 | 
				
			||||
$step1Form = new FormValidator('step1Form'); | 
				
			||||
 | 
				
			||||
$usernameListFile = $step1Form->addFile('usernameList', get_lang('UsernameList')); | 
				
			||||
$step1Form->addButtonUpload(get_lang('Upload')); | 
				
			||||
 | 
				
			||||
$step2Form = new FormValidator('step2Form'); | 
				
			||||
$usernameTextarea = $step2Form->addTextarea( | 
				
			||||
    'usersToBeAnonymized', | 
				
			||||
    get_lang('UsersAboutToBeAnonymized'), | 
				
			||||
    [ | 
				
			||||
        'readonly' => 1, | 
				
			||||
    ] | 
				
			||||
); | 
				
			||||
$step2Form->addButtonUpdate(get_lang('Anonymize')); | 
				
			||||
 | 
				
			||||
if ($step1Form->validate() && $usernameListFile->isUploadedFile()) { | 
				
			||||
    $filePath = $usernameListFile->getValue()['tmp_name']; | 
				
			||||
    if (!file_exists($filePath)) { | 
				
			||||
        throw new Exception(get_lang('CouldNotReadFile').' '.$filePath); | 
				
			||||
    } | 
				
			||||
    $submittedUsernames = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | 
				
			||||
    if (false === $submittedUsernames) { | 
				
			||||
        throw new Exception(get_lang('CouldNotReadFileLines').' '.$filePath); | 
				
			||||
    } | 
				
			||||
    if (empty($submittedUsernames)) { | 
				
			||||
        printf( | 
				
			||||
            '<p>'.get_lang('FileXHasNoData').'</p>', | 
				
			||||
            '<em>'.$usernameListFile->getValue()['name'].'</em>' | 
				
			||||
        ); | 
				
			||||
    } else { | 
				
			||||
        printf( | 
				
			||||
            '<p>'.get_lang('FileXHasYNonEmptyLines').'</p>', | 
				
			||||
            '<em>'.$usernameListFile->getValue()['name'].'</em>', | 
				
			||||
            count($submittedUsernames) | 
				
			||||
        ); | 
				
			||||
        $uniqueSubmittedUsernames = array_values(array_unique($submittedUsernames)); | 
				
			||||
        if (count($uniqueSubmittedUsernames) !== count($submittedUsernames)) { | 
				
			||||
            printf( | 
				
			||||
                '<p>'.get_lang('DuplicatesOnlyXUniqueUserNames').'</p>', | 
				
			||||
                count($uniqueSubmittedUsernames) | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
        $matching = UserManager::getRepository()->matching( | 
				
			||||
            Criteria::create()->where( | 
				
			||||
                Criteria::expr()->in('username', $uniqueSubmittedUsernames) | 
				
			||||
            ) | 
				
			||||
        ); | 
				
			||||
        foreach ($matching as $element) { | 
				
			||||
            if (!is_null($element)) { | 
				
			||||
                $users[] = $element; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        if (empty($users)) { | 
				
			||||
            echo '<p>'.get_lang('NoLineMatchedAnyActualUserName').'</p>'; | 
				
			||||
        } else { | 
				
			||||
            $foundUsernames = []; | 
				
			||||
            foreach ($users as $user) { | 
				
			||||
                $foundUsernames[] = $user->getUsername(); | 
				
			||||
            } | 
				
			||||
            if (count($users) !== count($uniqueSubmittedUsernames)) { | 
				
			||||
                printf('<p>'.get_lang('OnlyXLinesMatchedActualUsers').'</p>', count($users)); | 
				
			||||
                $usernamesNotFound = array_diff($uniqueSubmittedUsernames, $foundUsernames); | 
				
			||||
                printf( | 
				
			||||
                    '<p>'.get_lang('TheFollowingXLinesDoNotMatchAnyActualUser').'<pre>%s</pre></p>', | 
				
			||||
                    count($usernamesNotFound), | 
				
			||||
                    join("\n", $usernamesNotFound) | 
				
			||||
                ); | 
				
			||||
            } | 
				
			||||
            printf('<p>'.get_lang('XUsersAreAboutToBeAnonymized').'</p>', count($foundUsernames)); | 
				
			||||
            $usernameTextarea->setValue(join("\n", $foundUsernames)); | 
				
			||||
            $step2Form->display(); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} elseif ($step2Form->validate()) { | 
				
			||||
    $usernames = preg_split("/\s+/", $usernameTextarea->getValue()); | 
				
			||||
    if (false === $usernames) { | 
				
			||||
        throw new Exception('preg_split failed'); | 
				
			||||
    } | 
				
			||||
    printf('<p>'.get_lang('LoadingXUsers')."</p>\n", count($usernames)); | 
				
			||||
    $users = UserManager::getRepository()->matching( | 
				
			||||
        Criteria::create()->where( | 
				
			||||
            Criteria::expr()->in('username', $usernames) | 
				
			||||
        ) | 
				
			||||
    ); | 
				
			||||
    if (count($users) === count($usernames)) { | 
				
			||||
        printf('<p>'.get_lang('AnonymizingXUsers')."</p>\n", count($users)); | 
				
			||||
        $anonymized = []; | 
				
			||||
        $errors = []; | 
				
			||||
        foreach ($users as $user) { | 
				
			||||
            $username = $user->getUsername(); | 
				
			||||
            $userId = $user->getId(); | 
				
			||||
            $name = api_get_person_name($user->getFirstname(), $user->getLastname()); | 
				
			||||
            echo "<p>$username ($name, id=$userId):\n"; | 
				
			||||
            try { | 
				
			||||
                if (UserManager::anonymize($userId)) { | 
				
			||||
                    echo get_lang('Done'); | 
				
			||||
                    $anonymized[] = $username; | 
				
			||||
                } else { | 
				
			||||
                    echo 'error: UserManager::anonymize failed.'; | 
				
			||||
                    $errors[] = $username; | 
				
			||||
                } | 
				
			||||
            } catch (Exception $exception) { | 
				
			||||
                echo 'error: '.$exception->getMessage(); | 
				
			||||
                $errors[] = $username; | 
				
			||||
            } | 
				
			||||
            echo "</p>\n"; | 
				
			||||
        } | 
				
			||||
        if (empty($error)) { | 
				
			||||
            printf('<p>'.get_lang('AllXUsersWereAnonymized').'</p>', count($users)); | 
				
			||||
        } else { | 
				
			||||
            printf( | 
				
			||||
                '<p>' | 
				
			||||
                .get_lang('OnlyXUsersWereAnonymized') | 
				
			||||
                .' ' | 
				
			||||
                .get_lang('AttemptedAnonymizationOfTheseXUsersFailed') | 
				
			||||
                .'<pre>%s</pre></p>', | 
				
			||||
                count($users), | 
				
			||||
                count($errors), | 
				
			||||
                join("\n", $errors) | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } else { | 
				
			||||
        printf( | 
				
			||||
            '<p>'.get_lang('InternalInconsistencyXUsersFoundForYUserNames').'</p>', | 
				
			||||
            count($users), | 
				
			||||
            count($usernames) | 
				
			||||
        ); | 
				
			||||
    } | 
				
			||||
} else { | 
				
			||||
    echo '<p>'.get_lang('PleaseUploadListOfUsers').'</p>'; | 
				
			||||
    $step1Form->display(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
Display::display_footer(); | 
				
			||||
@ -0,0 +1,88 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
$cidReset = true; | 
				
			||||
require_once __DIR__.'/../inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
api_block_anonymous_users(true); | 
				
			||||
 | 
				
			||||
$allow = api_get_plugin_setting('pausetraining', 'tool_enable') === 'true'; | 
				
			||||
$allowPauseFormation = api_get_plugin_setting('pausetraining', 'allow_users_to_edit_pause_formation') === 'true'; | 
				
			||||
 | 
				
			||||
if (false === $allow || false === $allowPauseFormation) { | 
				
			||||
    api_not_allowed(true); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$userId = api_get_user_id(); | 
				
			||||
 | 
				
			||||
$userInfo = api_get_user_info($userId); | 
				
			||||
 | 
				
			||||
$justification = ''; | 
				
			||||
$plugin = PauseTraining::create(); | 
				
			||||
 | 
				
			||||
$form = new FormValidator('pausetraining'); | 
				
			||||
$form->addHeader($plugin->get_lang('PauseTraining')); | 
				
			||||
 | 
				
			||||
$extraField = new ExtraField('user'); | 
				
			||||
 | 
				
			||||
$return = $extraField->addElements( | 
				
			||||
    $form, | 
				
			||||
    $userId, | 
				
			||||
    [], | 
				
			||||
    false, | 
				
			||||
    false, | 
				
			||||
    ['pause_formation', 'start_pause_date', 'end_pause_date', 'allow_notifications'], | 
				
			||||
    [], | 
				
			||||
    [], | 
				
			||||
    false, | 
				
			||||
    true | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$form->addRule( | 
				
			||||
    ['extra_start_pause_date', 'extra_end_pause_date'], | 
				
			||||
    get_lang('StartDateShouldBeBeforeEndDate'), | 
				
			||||
    'date_compare', | 
				
			||||
    'lte' | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$form->addButtonSend(get_lang('Update')); | 
				
			||||
if ($form->validate()) { | 
				
			||||
    $values = $form->getSubmitValues(1); | 
				
			||||
    $values['item_id'] = $userId; | 
				
			||||
 | 
				
			||||
    if (!isset($values['extra_pause_formation'])) { | 
				
			||||
        $values['extra_pause_formation'] = 0; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    if (!isset($values['extra_allow_notifications'])) { | 
				
			||||
        $values['extra_allow_notifications'] = 0; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    $extraField = new ExtraFieldValue('user'); | 
				
			||||
    $extraField->saveFieldValues($values, true, false, [], [], true); | 
				
			||||
 | 
				
			||||
    Display::addFlash(Display::return_message(get_lang('Update'))); | 
				
			||||
    header('Location: '.api_get_self()); | 
				
			||||
    exit; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$tabs = SocialManager::getHomeProfileTabs('pausetraining'); | 
				
			||||
$content = $tabs.$form->returnForm(); | 
				
			||||
 | 
				
			||||
$tpl = new Template(get_lang('ModifyProfile')); | 
				
			||||
 | 
				
			||||
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home'); | 
				
			||||
$menu = SocialManager::show_social_menu( | 
				
			||||
    'home', | 
				
			||||
    null, | 
				
			||||
    api_get_user_id(), | 
				
			||||
    false, | 
				
			||||
    false | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$tpl->assign('social_menu_block', $menu); | 
				
			||||
$tpl->assign('social_right_content', $content); | 
				
			||||
$social_layout = $tpl->get_template('social/edit_profile.tpl'); | 
				
			||||
 | 
				
			||||
$tpl->display($social_layout); | 
				
			||||
@ -0,0 +1,82 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
/** | 
				
			||||
 * Responses to AJAX calls for course chat. | 
				
			||||
 */ | 
				
			||||
require_once __DIR__.'/../global.inc.php'; | 
				
			||||
 | 
				
			||||
if (!api_protect_course_script(false)) { | 
				
			||||
    exit; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$courseId = api_get_course_int_id(); | 
				
			||||
$userId = api_get_user_id(); | 
				
			||||
$sessionId = api_get_session_id(); | 
				
			||||
$groupId = api_get_group_id(); | 
				
			||||
$json = ['status' => false]; | 
				
			||||
 | 
				
			||||
$courseChatUtils = new CourseChatUtils($courseId, $userId, $sessionId, $groupId); | 
				
			||||
 | 
				
			||||
switch ($_REQUEST['action']) { | 
				
			||||
    case 'chat_logout': | 
				
			||||
        $logInfo = [ | 
				
			||||
            'tool' => TOOL_CHAT, | 
				
			||||
            'action' => 'exit', | 
				
			||||
            'action_details' => 'exit-chat', | 
				
			||||
        ]; | 
				
			||||
        Event::registerLog($logInfo); | 
				
			||||
        break; | 
				
			||||
    case 'track': | 
				
			||||
        $courseChatUtils->keepUserAsConnected(); | 
				
			||||
        $courseChatUtils->disconnectInactiveUsers(); | 
				
			||||
 | 
				
			||||
        $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; | 
				
			||||
        $filePath = $courseChatUtils->getFileName(true, $friend); | 
				
			||||
        $newFileSize = file_exists($filePath) ? filesize($filePath) : 0; | 
				
			||||
        $oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; | 
				
			||||
        $newUsersOnline = $courseChatUtils->countUsersOnline(); | 
				
			||||
        $oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; | 
				
			||||
 | 
				
			||||
        $json = [ | 
				
			||||
            'status' => true, | 
				
			||||
            'data' => [ | 
				
			||||
                'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, | 
				
			||||
                'history' => $newFileSize !== $oldFileSize ? $courseChatUtils->readMessages(false, $friend) : null, | 
				
			||||
                'usersOnline' => $newUsersOnline, | 
				
			||||
                'userList' => $newUsersOnline != $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, | 
				
			||||
                'currentFriend' => $friend, | 
				
			||||
            ], | 
				
			||||
        ]; | 
				
			||||
 | 
				
			||||
        break; | 
				
			||||
    case 'preview': | 
				
			||||
        $json = [ | 
				
			||||
            'status' => true, | 
				
			||||
            'data' => [ | 
				
			||||
                'message' => CourseChatUtils::prepareMessage($_REQUEST['message']), | 
				
			||||
            ], | 
				
			||||
        ]; | 
				
			||||
        break; | 
				
			||||
    case 'reset': | 
				
			||||
        $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; | 
				
			||||
 | 
				
			||||
        $json = [ | 
				
			||||
            'status' => true, | 
				
			||||
            'data' => $courseChatUtils->readMessages(true, $friend), | 
				
			||||
        ]; | 
				
			||||
        break; | 
				
			||||
    case 'write': | 
				
			||||
        $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; | 
				
			||||
        $writed = $courseChatUtils->saveMessage($_POST['message'], $friend); | 
				
			||||
 | 
				
			||||
        $json = [ | 
				
			||||
            'status' => $writed, | 
				
			||||
            'data' => [ | 
				
			||||
                'writed' => $writed, | 
				
			||||
            ], | 
				
			||||
        ]; | 
				
			||||
        break; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
header('Content-Type: application/json'); | 
				
			||||
echo json_encode($json); | 
				
			||||
@ -0,0 +1,27 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../global.inc.php'; | 
				
			||||
 | 
				
			||||
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; | 
				
			||||
$isAllowedToEdit = api_is_allowed_to_edit(); | 
				
			||||
 | 
				
			||||
switch ($action) { | 
				
			||||
    case 'search': | 
				
			||||
        if ($isAllowedToEdit) { | 
				
			||||
            $groups = GroupManager::getGroupListFilterByName($_REQUEST['q'], null, api_get_course_int_id()); | 
				
			||||
            $list = []; | 
				
			||||
            foreach ($groups as $group) { | 
				
			||||
                $list[] = [ | 
				
			||||
                    'id' => $group['iid'], | 
				
			||||
                    'text' => $group['name'], | 
				
			||||
                ]; | 
				
			||||
            } | 
				
			||||
            echo json_encode(['items' => $list]); | 
				
			||||
        } | 
				
			||||
        break; | 
				
			||||
    default: | 
				
			||||
        break; | 
				
			||||
} | 
				
			||||
exit; | 
				
			||||
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						
					Loading…
					
					
				
		Reference in new issue