qti2.php 3.0 KB

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