Allowing import user list in a course session see BT#4747

skala
Julio Montoya 12 years ago
parent d2d327b2f4
commit d507d8961e
  1. 2
      main/inc/lib/course.lib.php
  2. 2
      main/inc/lib/import.lib.php
  3. 24
      main/user/user.php
  4. 39
      main/user/user_import.php

@ -400,7 +400,7 @@ class CourseManager {
if (!empty($session_id)) { if (!empty($session_id)) {
$session_id = intval($session_id); $session_id = intval($session_id);
} else { } else {
$session_id = intval($_SESSION['id_session']); $session_id = api_get_session_id();
} }
$status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT; $status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;

@ -41,7 +41,7 @@ class Import {
* *
* @deprecated use cvs_reader instead * @deprecated use cvs_reader instead
*/ */
function csv_to_array($filename, $csv_order = 'vertical') { static function csv_to_array($filename, $csv_order = 'vertical') {
$result = array(); $result = array();
// Encoding detection. // Encoding detection.

@ -397,11 +397,7 @@ if ( api_is_allowed_to_edit(null, true)) {
} }
$actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a> '; $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a> ';
$actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> '; $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> ';
$actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> ';
if (!api_get_session_id()) {
$actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> ';
}
$actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&type=pdf">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a> '; $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&type=pdf">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a> ';
$actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."</a>"; $actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."</a>";
@ -629,6 +625,13 @@ function modify_filter($user_id) {
if ($is_allowed_to_track) { if ($is_allowed_to_track) {
$result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" ><img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" /></a>'; $result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" ><img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" /></a>';
} }
//if platform admin, show the login_as icon (this drastically shortens
// time taken by support to test things out)
if (api_is_platform_admin()) {
$result .= ' <a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
}
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
// edit // edit
@ -636,9 +639,9 @@ function modify_filter($user_id) {
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) { if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
// unregister // unregister
if ($user_id != $current_user_id) { if ($user_id != $current_user_id) {
$result .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('unsubscribe_course.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;'; $result .= '<a class="btn btn-small" href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.get_lang('Unreg').'</a>&nbsp;';
} else { } else {
$result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;'; //$result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
} }
} }
} else { } else {
@ -649,12 +652,7 @@ function modify_filter($user_id) {
} }
} }
} }
//if platform admin, show the login_as icon (this drastically shortens
// time taken by support to test things out)
if (api_is_platform_admin()) {
$result .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
}
return $result; return $result;
} }

@ -23,14 +23,13 @@ $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="s
$course_code = api_get_course_id(); $course_code = api_get_course_id();
if (api_get_session_id()) {
api_not_allowed();
}
if (empty($course_code)) { if (empty($course_code)) {
api_not_allowed(); api_not_allowed(true);
} }
$session_id = api_get_session_id();
$message = ''; $message = '';
$user_to_show = array(); $user_to_show = array();
$type = ''; $type = '';
@ -57,12 +56,20 @@ if ($form->validate()) {
if (empty($invalid_users)) { if (empty($invalid_users)) {
$type = 'confirmation'; $type = 'confirmation';
$message = get_lang('ListOfUsersSubscribedToCourse'); $message = get_lang('ListOfUsersSubscribedToCourse');
foreach ($users as $user) {
$result = CourseManager :: subscribe_user($user['id'], $course_code, STUDENT); foreach ($users as $user) {
//just to make sure CourseManager :: subscribe_user($user['id'], $course_code, STUDENT, $session_id);
if (CourseManager :: is_user_subscribed_in_course($user['id'], $course_code)) { if (empty($session_id)) {
$user_to_show[]= $clean_users[$user['id']]['complete_name']; //just to make sure
} if (CourseManager :: is_user_subscribed_in_course($user['id'], $course_code)) {
$user_to_show[]= $clean_users[$user['id']]['complete_name'];
}
} else {
//just to make sure
if (CourseManager :: is_user_subscribed_in_course($user['id'], $course_code, true, $session_id)) {
$user_to_show[]= $clean_users[$user['id']]['complete_name'];
}
}
} }
} else { } else {
$message = get_lang('CheckUsersWithId'); $message = get_lang('CheckUsersWithId');
@ -90,4 +97,14 @@ if (!empty($message)) {
} }
$form->display(); $form->display();
echo get_lang('CSVMustLookLike');
echo '<blockquote>';
echo '<pre>
"id";
"x";
"y";
</pre>
';
echo '</blockquote>';
Display::display_footer(); Display::display_footer();
Loading…
Cancel
Save