session_import_drh.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script(true);
  10. api_protect_limit_for_session_admin();
  11. $form_sent = 0;
  12. $tool_name = get_lang('Import list of HR directors into sessions');
  13. $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('Session list')];
  14. set_time_limit(0);
  15. $inserted_in_course = [];
  16. // Display the header.
  17. Display::display_header($tool_name);
  18. echo '<div class="actions">';
  19. echo '<a href="../session/session_list.php">'.
  20. Display::return_icon('back.png', get_lang('Back to').' '.get_lang('Administration'), '', ICON_SIZE_MEDIUM).'</a>';
  21. echo '</div>';
  22. if (!empty($error_message)) {
  23. echo Display::return_message($error_message, 'normal', false);
  24. }
  25. $form = new FormValidator(
  26. 'import_sessions',
  27. 'post',
  28. api_get_self(),
  29. null,
  30. ['enctype' => 'multipart/form-data']
  31. );
  32. $form->addElement('file', 'import_file', get_lang('Import marks in an assessment'));
  33. $form->addElement('checkbox', 'remove_old_relationships', null, get_lang('Remove previous relationships'));
  34. //$form->addElement('checkbox', 'send_email', null, get_lang('Send a mail to users'));
  35. $form->addButtonImport(get_lang('Import session(s)'));
  36. if ($form->validate()) {
  37. if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
  38. $values = $form->exportValues();
  39. $sendMail = isset($values['send_email']) ? true : false;
  40. $removeOldRelationships = isset($values['remove_old_relationships']) ? true : false;
  41. $result = SessionManager::importSessionDrhCSV(
  42. $_FILES['import_file']['tmp_name'],
  43. $sendMail,
  44. $removeOldRelationships
  45. );
  46. Display::addFlash(Display::return_message($result, 'info', false));
  47. header('Location: '.api_get_self());
  48. exit;
  49. } else {
  50. $error_message = get_lang('No file was sent');
  51. }
  52. }
  53. $form->display();
  54. ?>
  55. <p><?php echo get_lang('The CSV file must look like this').' ('.get_lang('Fields in <strong>bold</strong> are mandatory.').')'; ?> :</p>
  56. <blockquote>
  57. <pre>
  58. Username;SessionName;
  59. drh1;Session 1;
  60. drh2;Session 2;
  61. </pre>
  62. </blockquote>
  63. <?php
  64. /* FOOTER */
  65. Display::display_footer();