session_user_import.php 2.7 KB

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