qti2.php 2.9 KB

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