qti2.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code for Qti2 import integration.
  5. * @package chamilo.exercise
  6. * @author Ronny Velasquez
  7. * @version $Id: qti2.php 2010-03-12 12:14:25Z $
  8. */
  9. // including the global Chamilo file
  10. // section (for the tabs)
  11. $this_section = SECTION_COURSES;
  12. // access restriction: only teachers are allowed here
  13. if (!api_is_allowed_to_edit(null, true)) {
  14. api_not_allowed();
  15. }
  16. // the breadcrumbs
  17. $interbreadcrumb[]= array (
  18. "url" => api_get_path(WEB_CODE_PATH) . "exercise/exercise.php?".api_get_cidreq(),
  19. "name" => get_lang('Exercises')
  20. );
  21. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  22. /**
  23. * This function displays the form to import the zip file with qti2
  24. */
  25. function ch_qti2_display_form()
  26. {
  27. $name_tools = get_lang('ImportQtiQuiz');
  28. $form = '<div class="actions">';
  29. $form .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'exercise/exercise.php?show=test&'.api_get_cidreq().'">'.
  30. Display :: return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM).'</a>';
  31. $form .= '</div>';
  32. $formValidator = new FormValidator(
  33. 'qti_upload',
  34. 'post',
  35. api_get_self()."?".api_get_cidreq(),
  36. null,
  37. array('enctype' => 'multipart/form-data')
  38. );
  39. $formValidator->addElement('header', $name_tools);
  40. $formValidator->addElement('file', 'userFile', get_lang('DownloadFile'));
  41. $formValidator->addButtonImport(get_lang('Upload'));
  42. $form .= $formValidator->returnForm();
  43. echo $form;
  44. }
  45. /**
  46. * This function will import the zip file with the respective qti2
  47. * @param array $array_file ($_FILES)
  48. * @return string|array
  49. */
  50. function ch_qti2_import_file($array_file)
  51. {
  52. $unzip = 0;
  53. $process = process_uploaded_file($array_file, false);
  54. if (preg_match('/\.zip$/i', $array_file['name'])) {
  55. // if it's a zip, allow zip upload
  56. $unzip = 1;
  57. }
  58. if ($process && $unzip == 1) {
  59. $main_path = api_get_path(SYS_CODE_PATH);
  60. require_once $main_path.'exercise/export/exercise_import.inc.php';
  61. require_once $main_path.'exercise/export/qti2/qti2_classes.php';
  62. return import_exercise($array_file['name']);
  63. }
  64. return 'langFileError';
  65. }
  66. $message = null;
  67. // import file
  68. if ((api_is_allowed_to_edit(null, true))) {
  69. if (isset($_POST['submit'])) {
  70. $imported = ch_qti2_import_file($_FILES['userFile']);
  71. if (is_numeric($imported) && !empty($imported)) {
  72. header('Location: '.api_get_path(WEB_CODE_PATH) . 'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$imported);
  73. exit;
  74. } else {
  75. $message = Display::return_message(get_lang($imported));
  76. }
  77. }
  78. }
  79. // Display header
  80. Display::display_header(get_lang('ImportQtiQuiz'), 'Exercises');
  81. echo $message;
  82. // display qti form
  83. ch_qti2_display_form();
  84. // display the footer
  85. Display::display_footer();