qti2.php 3.2 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. // name of the language file that needs to be included
  10. $language_file = 'exercice';
  11. // including the global Chamilo file
  12. require_once '../inc/global.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  14. // including additional libraries
  15. require_once 'exercise.class.php';
  16. require_once 'question.class.php';
  17. require_once 'answer.class.php';
  18. // section (for the tabs)
  19. $this_section = SECTION_COURSES;
  20. // access restriction: only teachers are allowed here
  21. if (!api_is_allowed_to_edit(null, true)) {
  22. api_not_allowed();
  23. }
  24. // the breadcrumbs
  25. $interbreadcrumb[]= array ("url"=>"exercice.php", "name"=> get_lang('Exercices'));
  26. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  27. /**
  28. * This function displays the form for import of the zip file with qti2
  29. */
  30. function ch_qti2_display_form() {
  31. $name_tools = get_lang('ImportQtiQuiz');
  32. $form = '<div class="actions">';
  33. $form .= '<a href="exercice.php?show=test">' . Display :: return_icon('back.png', get_lang('BackToExercisesList'),'','32').'</a>';
  34. $form .= '</div>';
  35. $form .= '<form action='.api_get_self()."?".api_get_cidreq().' method="post" enctype="multipart/form-data">';
  36. $form .= '<div class="row"><div class="form_header">'.$name_tools.'</div></div>';
  37. $form .= '<div class="row">';
  38. $form .= '<div class="label" style="padding:10px">';
  39. $form .= '<span class="form_required">*</span>';
  40. $form .= get_lang('DownloadFile').' :';
  41. $form .= '</div>';
  42. $form .= '<div class="formw">';
  43. $form .= '<div style="padding:10px">
  44. <input type="file" name="userFile"><br /><br />
  45. <button type="submit" class="upload" name="submit" value="'.get_lang('Send').'">'.get_lang('SendFile').'</button>
  46. </div>';
  47. $form .= '</div></div>';
  48. echo $form;
  49. }
  50. /**
  51. * This function will import the zip file with the respective qti2
  52. * @param array $uploaded_file ($_FILES)
  53. */
  54. function ch_qti2_import_file($array_file) {
  55. $unzip = 0;
  56. $lib_path = api_get_path(LIBRARY_PATH);
  57. require_once $lib_path.'fileUpload.lib.php';
  58. require_once $lib_path.'fileManage.lib.php';
  59. $process = 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?' . Security::remove_XSS(api_get_cidreq()) .'');
  71. } else {
  72. Display::display_error_message(get_lang('The import was not performed'));
  73. return false;
  74. }
  75. }
  76. }
  77. // import file
  78. if ((api_is_allowed_to_edit(null, true))) {
  79. if (isset($_POST['submit'])) {
  80. ch_qti2_import_file($_FILES['userFile']);
  81. }
  82. }
  83. // display header
  84. Display::display_header(get_lang('ImportQtiQuiz'), 'Exercises');
  85. // display qti form
  86. ch_qti2_display_form();
  87. // display the footer
  88. Display::display_footer();
  89. ?>