qti2.php 3.3 KB

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