qti2.php 2.9 KB

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