qti2.php 2.9 KB

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