Fix user information export to CSV

pull/2487/head
jmontoyaa 8 years ago
parent 13f54347a4
commit cacc344c95
  1. 115
      main/admin/user_information.php
  2. 4
      main/inc/lib/export.lib.inc.php
  3. 12
      main/inc/lib/tracking.lib.php

@ -40,6 +40,7 @@ $userId = $user['user_id'];
$tool_name = $user['complete_name'].(empty($user['official_code']) ? '' : ' ('.$user['official_code'].')');
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$csvContent = [];
// only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
$login_as_icon = '';
@ -89,7 +90,6 @@ if (api_is_platform_admin()) {
);
}
$studentBossList = UserManager::getStudentBossList($userId);
$studentBossListToString = '';
if ($studentBossList) {
@ -107,63 +107,6 @@ if ($studentBossList) {
$studentBossListToString = $table->toHtml();
}
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'send_legal':
$subject = get_lang('SendLegalSubject');
$content = sprintf(
get_lang('SendLegalDescriptionToUrlX'),
api_get_path(WEB_PATH)
);
MessageManager::send_message_simple($userId, $subject, $content);
Display::addFlash(Display::return_message(get_lang('Sent')));
break;
case 'delete_legal':
$extraFieldValue = new ExtraFieldValue('user');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
$result = $extraFieldValue->delete($value['id']);
if ($result) {
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
break;
case 'unsubscribe':
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
$courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) {
break;
}
if (CourseManager::getUserInCourseStatus($userId, $courseInfo['real_id']) == STUDENT) {
CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
} else {
Display::addFlash(Display::return_message(
get_lang('CannotUnsubscribeUserFromCourse'),
'error',
false
));
}
break;
case 'unsubscribeSessionCourse':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
SessionManager::removeUsersFromCourseSession(
array($userId),
$sessionId,
api_get_course_info($courseCode)
);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
break;
case 'export':
Export :: arrayToCsv($csvContent, 'user_information_'.$user);
exit;
break;
}
}
// Show info about who created this user and when
$creatorId = $user['creator_id'];
$creatorInfo = api_get_user_info($creatorId);
@ -406,7 +349,7 @@ if (count($sessions) > 0) {
} else {
$sessionInformation = '<p>'.get_lang('NoSessionsForThisUser').'</p>';
}
$courseToolInformationTotal = null;
$courseToolInformationTotal = '';
/**
* Show the courses in which this user is subscribed
@ -536,8 +479,59 @@ if (api_is_multiple_url_enabled()) {
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'send_legal':
$subject = get_lang('SendLegalSubject');
$content = sprintf(
get_lang('SendLegalDescriptionToUrlX'),
api_get_path(WEB_PATH)
);
MessageManager::send_message_simple($userId, $subject, $content);
Display::addFlash(Display::return_message(get_lang('Sent')));
break;
case 'delete_legal':
$extraFieldValue = new ExtraFieldValue('user');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
$result = $extraFieldValue->delete($value['id']);
if ($result) {
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
break;
case 'unsubscribe':
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
$courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) {
break;
}
if (CourseManager::getUserInCourseStatus($userId, $courseInfo['real_id']) == STUDENT) {
CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
} else {
Display::addFlash(Display::return_message(
get_lang('CannotUnsubscribeUserFromCourse'),
'error',
false
));
}
break;
case 'unsubscribeSessionCourse':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
SessionManager::removeUsersFromCourseSession(
array($userId),
$sessionId,
api_get_course_info($courseCode)
);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
break;
case 'export':
Export :: arrayToCsv($csvContent, 'user_information_'.$user);
Export::arrayToCsv(
$csvContent,
'user_information_'.$user['user_id']
);
exit;
break;
}
@ -554,7 +548,6 @@ echo '<div class="actions">
'.$exportLink.'
'.$vCardExportLink.'
</div>';
echo Display::page_header($tool_name);
$fullUrlBig = UserManager::getUserPicture(

@ -53,6 +53,10 @@ class Export
$writer->setStream(fopen($filePath, 'w'));
foreach ($data as $item) {
if (empty($item)) {
$writer->writeItem([]);
continue;
}
$item = array_map('trim', $item);
$writer->writeItem($item);
}

@ -7598,8 +7598,8 @@ class TrackingUserLogCSV
}
/**
* @param $userId
* @param $courseInfo
* @param int $userId
* @param array $courseInfo
* @param int $sessionId
* @return array
*/
@ -7609,7 +7609,7 @@ class TrackingUserLogCSV
$sessionId = 0
) {
$csvContent = array();
$courseToolInformation = null;
$courseToolInformation = '';
$headerTool = array(
array(get_lang('Title')),
array(get_lang('CreatedAt')),
@ -7629,7 +7629,7 @@ class TrackingUserLogCSV
if (!empty($courseForumInformationArray)) {
$csvContent[] = array();
$csvContent[] = get_lang('Forums');
$csvContent[] = [get_lang('Forums')];
$csvContent[] = $headerListForCSV;
foreach ($courseForumInformationArray as $row) {
$csvContent[] = $row;
@ -7652,7 +7652,7 @@ class TrackingUserLogCSV
if (!empty($courseWorkInformationArray)) {
$csvContent[] = null;
$csvContent[] = get_lang('Works');
$csvContent[] = [get_lang('Works')];
$csvContent[] = $headerListForCSV;
foreach ($courseWorkInformationArray as $row) {
@ -7668,8 +7668,8 @@ class TrackingUserLogCSV
$courseWorkInformationArray
);
}
$courseToolInformationTotal = null;
$courseToolInformationTotal = null;
if (!empty($courseToolInformation)) {
$sessionTitle = null;
if (!empty($sessionId)) {

Loading…
Cancel
Save