qti2.php 2.9 KB

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