session_user_import.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $language_file = array('admin', 'registration');
  7. $cidReset = true;
  8. //require '../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script(true);
  11. $form_sent = 0;
  12. $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
  13. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  14. $error_message = Security::remove_XSS($_GET['message']);
  15. }
  16. $tool_name = get_lang('ImportUsers');
  17. $session_id = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  18. if (empty($session_id)) {
  19. api_not_allowed(true);
  20. }
  21. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  22. $interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList'));
  23. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$session_id,"name" => get_lang('SessionOverview'));
  24. set_time_limit(0);
  25. if (isset($_POST['formSent']) && $_POST['formSent']) {
  26. if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
  27. $form_sent = $_POST['formSent'];
  28. $send_mail = $_POST['sendMail'] ? 1 : 0;
  29. // CSV
  30. $users = Import::csv_to_array($_FILES['import_file']['tmp_name']);
  31. $user_list = array();
  32. foreach ($users as $user_data) {
  33. $username = $user_data['username'];
  34. $user_id = UserManager::get_user_id_from_username($username);
  35. if ($user_id) {
  36. $user_list[] = $user_id;
  37. }
  38. }
  39. if (!empty($user_list)) {
  40. SessionManager::suscribe_users_to_session($session_id, $user_list, null, false, $send_mail);
  41. foreach ($user_list as & $user_id) {
  42. $user_info = api_get_user_info($user_id);
  43. $user_id = $user_info['complete_name'];
  44. }
  45. $error_message = get_lang('UsersAdded').' : '.implode(', ', $user_list);
  46. }
  47. } else {
  48. $error_message = get_lang('NoInputFile');
  49. }
  50. }
  51. // Display the header.
  52. Display::display_header($tool_name);
  53. if (count($inserted_in_course) > 1) {
  54. $msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
  55. foreach ($inserted_in_course as $code => $title) {
  56. $msg .= ' '.$title.' ('.$title.'),';
  57. }
  58. $msg = substr($msg, 0, -1);
  59. Display::display_warning_message($msg);
  60. }
  61. echo '<div class="actions">';
  62. echo '<a href="resume_session.php?id_session='.$session_id.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
  63. echo '</div>';
  64. if (!empty($error_message)) {
  65. Display::display_normal_message($error_message, false);
  66. }
  67. $form = new FormValidator('import_sessions', 'post', api_get_self().'?id_session='.$session_id, null, array('enctype' => 'multipart/form-data'));
  68. $form->addElement('hidden', 'formSent', 1);
  69. $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
  70. $form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers'));
  71. $form->addElement('button', 'submit', get_lang('Import'));
  72. $defaults = array('sendMail' => 'true');
  73. $form->setDefaults($defaults);
  74. $form->display();
  75. ?>
  76. <font color="gray">
  77. <p><?php echo get_lang('CSVMustLookLike'); ?> :</p>
  78. <blockquote>
  79. <pre>
  80. username;
  81. admin;
  82. teacher;
  83. jmontoya;
  84. </pre>
  85. </blockquote>
  86. <?php
  87. Display::display_footer();