exercise_import.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php // $Id: $
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL)
  5. * @package chamilo.exercise
  6. * @author claro team <cvs@claroline.net>
  7. */
  8. /**
  9. * Code
  10. */
  11. require '../../inc/global.inc.php';
  12. //SECURITY CHECK
  13. if (api_is_platform_admin()) {
  14. api_not_allowed();
  15. }
  16. //DECLARE NEEDED LIBRARIES
  17. require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  18. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  19. require_once 'exercise_import.inc.php';
  20. include_once '../exercise.class.php';
  21. include_once '../question.class.php';
  22. include_once 'qti/qti_classes.php';
  23. //SQL table name
  24. $tbl_exercise = Database::get_course_table(TABLE_QUIZ_TEST);
  25. $tbl_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  26. $tbl_rel_exercise_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  27. // tool libraries
  28. include_once '../exercise.class.php';
  29. //Tool title
  30. $nameTools = get_lang('ImportExercise');
  31. //bredcrump
  32. $interbredcrump[] = array('url' => '../exercice.php', 'name' => get_lang('Exercises'));
  33. //----------------------------------
  34. // EXECUTE COMMAND
  35. //----------------------------------
  36. $cmd = (isset($_REQUEST['cmd'])? $_REQUEST['cmd'] : 'show_import');
  37. switch ($cmd) {
  38. case 'show_import' :
  39. {
  40. $display = '<p>'
  41. . get_lang('Imported exercises must consist of a zip or an XML file (IMS-QTI) and be compatible with your Claroline version.') . '<br>'
  42. . '</p>'
  43. . '<form enctype="multipart/form-data" action="" method="post">'
  44. . '<input name="cmd" type="hidden" value="import" />'
  45. . '<input name="uploadedExercise" type="file" /><br><br>'
  46. . get_lang('Import exercise') . ' : '
  47. . '<input value="' . get_lang('Ok') . '" type="submit" /> '
  48. . claro_html_button( $_SERVER['PHP_SELF'], get_lang('Cancel'))
  49. . '<br><br>'
  50. . '<small>' . get_lang('Max file size') . ' : 2&nbsp;MB</small>'
  51. . '</form>';
  52. }
  53. break;
  54. case 'import': {
  55. //include needed librabries for treatment
  56. $result_log = import_exercise($_FILES['uploadedExercise']['name']);
  57. //display the result message (fail or success)
  58. $dialogBox = '';
  59. foreach ($result_log as $log) {
  60. $dialogBox .= $log.'<br>';
  61. }
  62. }
  63. break;
  64. }
  65. //----------------------------------
  66. // FIND INFORMATION
  67. //----------------------------------
  68. //empty!
  69. //----------------------------------
  70. // DISPLAY
  71. //----------------------------------
  72. include api_get_path(INCLUDE_PATH) . '/header.inc.php';
  73. //display title
  74. // Tool introduction
  75. // TODO: These settings to be checked when it is possible.
  76. Display::display_introduction_section(TOOL_QUIZ, array(
  77. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  78. 'CreateDocumentDir' => '../../../courses/'.api_get_course_path().'/document/',
  79. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  80. )
  81. );
  82. //Display Forms or dialog box(if needed)
  83. if (isset($dialogBox)) {
  84. echo Display::display_normal_message($dialogBox, false);
  85. }
  86. //display content
  87. if (isset($display)) {
  88. echo $display;
  89. }
  90. //footer display
  91. include api_get_path(INCLUDE_PATH) . '/footer.inc.php';
  92. ?>