qti2.php 3.0 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. /**
  10. * Code
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = 'exercice';
  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("url" => "exercice.php", "name" => get_lang('Exercices'));
  29. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  30. /**
  31. * This function displays the form for import of the zip file with qti2
  32. */
  33. function ch_qti2_display_form()
  34. {
  35. $name_tools = get_lang('ImportQtiQuiz');
  36. $form = '<div class="actions">';
  37. $form .= '<a href="exercice.php?show=test">'.Display :: return_icon(
  38. 'back.png',
  39. get_lang('BackToExercisesList'),
  40. '',
  41. ICON_SIZE_MEDIUM
  42. ).'</a>';
  43. $form .= '</div>';
  44. $form_validator = new FormValidator('qti_upload', 'post', api_get_self()."?".api_get_cidreq(
  45. ), null, array('enctype' => 'multipart/form-data'));
  46. $form_validator->addElement('header', $name_tools);
  47. $form_validator->addElement('file', 'userFile', get_lang('DownloadFile'));
  48. $form_validator->addElement('style_submit_button', 'submit', get_lang('Send'), 'class="upload"');
  49. $form .= $form_validator->return_form();
  50. echo $form;
  51. }
  52. /**
  53. * This function will import the zip file with the respective qti2
  54. * @param array $uploaded_file ($_FILES)
  55. */
  56. function ch_qti2_import_file($array_file)
  57. {
  58. $unzip = 0;
  59. $lib_path = api_get_path(LIBRARY_PATH);
  60. $process = FileManager::process_uploaded_file($array_file);
  61. if (preg_match('/\.zip$/i', $array_file['name'])) {
  62. // if it's a zip, allow zip upload
  63. $unzip = 1;
  64. }
  65. if ($process && $unzip == 1) {
  66. $main_path = api_get_path(SYS_CODE_PATH);
  67. require_once $main_path.'exercice/export/exercise_import.inc.php';
  68. require_once $main_path.'exercice/export/qti2/qti2_classes.php';
  69. $imported = import_exercise($array_file['name']);
  70. if ($imported) {
  71. header('Location: exercice.php?'.api_get_cidreq());
  72. } else {
  73. Display::display_error_message(get_lang('UplNoFileUploaded'));
  74. return false;
  75. }
  76. }
  77. }
  78. // display header
  79. Display::display_header(get_lang('ImportQtiQuiz'), 'Exercises');
  80. // import file
  81. if ((api_is_allowed_to_edit(null, true))) {
  82. if (isset($_POST['submit'])) {
  83. ch_qti2_import_file($_FILES['userFile']);
  84. }
  85. }
  86. // display qti form
  87. ch_qti2_display_form();
  88. // display the footer
  89. Display::display_footer();