qti2.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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'),'','32').'</a>';
  37. $form .= '</div>';
  38. $form .= '<form action='.api_get_self()."?".api_get_cidreq().' method="post" enctype="multipart/form-data">';
  39. $form .= '<div class="row"><div class="form_header">'.$name_tools.'</div></div>';
  40. $form .= '<div class="row">';
  41. $form .= '<div class="label" style="padding:10px">';
  42. $form .= '<span class="form_required">*</span>';
  43. $form .= get_lang('DownloadFile').' :';
  44. $form .= '</div>';
  45. $form .= '<div class="formw">';
  46. $form .= '<div style="padding:10px">
  47. <input type="file" name="userFile"><br /><br />
  48. <button type="submit" class="upload" name="submit" value="'.get_lang('Send').'">'.get_lang('SendFile').'</button>
  49. </div>';
  50. $form .= '</div></div>';
  51. echo $form;
  52. }
  53. /**
  54. * This function will import the zip file with the respective qti2
  55. * @param array $uploaded_file ($_FILES)
  56. */
  57. function ch_qti2_import_file($array_file) {
  58. $unzip = 0;
  59. $lib_path = api_get_path(LIBRARY_PATH);
  60. require_once $lib_path.'fileUpload.lib.php';
  61. require_once $lib_path.'fileManage.lib.php';
  62. $process = process_uploaded_file($array_file);
  63. if (preg_match('/\.zip$/i', $array_file['name'])) {
  64. // if it's a zip, allow zip upload
  65. $unzip = 1;
  66. }
  67. if ($process && $unzip == 1) {
  68. $main_path = api_get_path(SYS_CODE_PATH);
  69. require_once $main_path.'exercice/export/exercise_import.inc.php';
  70. require_once $main_path.'exercice/export/qti2/qti2_classes.php';
  71. $imported = import_exercise($array_file['name']);
  72. if ($imported) {
  73. header('Location: exercice.php?' . Security::remove_XSS(api_get_cidreq()) .'');
  74. } else {
  75. Display::display_error_message(get_lang('The import was not performed'));
  76. return false;
  77. }
  78. }
  79. }
  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 header
  87. Display::display_header(get_lang('ImportQtiQuiz'), 'Exercises');
  88. // display qti form
  89. ch_qti2_display_form();
  90. // display the footer
  91. Display::display_footer();
  92. ?>