exercise_import.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php // $Id: $
  2. /**
  3. * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL)
  4. *
  5. * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  6. *
  7. * @package dokeos.exercise
  8. * @author claro team <cvs@claroline.net>
  9. */
  10. require '../../inc/global.inc.php';
  11. //SECURITY CHECK
  12. if ( api_is_platform_admin() ) api_not_allowed();
  13. //DECLARE NEEDED LIBRARIES
  14. require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  15. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  16. require_once 'exercise_import.inc.php';
  17. include_once '../exercise.class.php';
  18. include_once '../question.class.php';
  19. include_once 'qti/qti_classes.php';
  20. //SQL table name
  21. $tbl_exercise = Database::get_course_table(TABLE_QUIZ_TEST);
  22. $tbl_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  23. $tbl_rel_exercise_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  24. // tool libraries
  25. include_once '../exercise.class.php';
  26. //Tool title
  27. $nameTools = get_lang('ImportExercise');
  28. //bredcrump
  29. $interbredcrump[]= array ('url' => '../exercise.php','name' => get_lang('Exercises'));
  30. //----------------------------------
  31. // EXECUTE COMMAND
  32. //----------------------------------
  33. $cmd = (isset($_REQUEST['cmd'])? $_REQUEST['cmd'] : 'show_import');
  34. switch ( $cmd )
  35. {
  36. case 'show_import' :
  37. {
  38. $display = '<p>'
  39. . get_lang('Imported exercises must consist of a zip or an XML file (IMS-QTI) and be compatible with your Claroline version.') . '<br>'
  40. . '</p>'
  41. . '<form enctype="multipart/form-data" action="" method="post">'
  42. . '<input name="cmd" type="hidden" value="import" />'
  43. . '<input name="uploadedExercise" type="file" /><br><br>'
  44. . get_lang('Import exercise') . ' : '
  45. . '<input value="' . get_lang('Ok') . '" type="submit" /> '
  46. . claro_html_button( $_SERVER['PHP_SELF'], get_lang('Cancel'))
  47. . '<br><br>'
  48. . '<small>' . get_lang('Max file size') . ' : 2&nbsp;MB</small>'
  49. . '</form>';
  50. }
  51. break;
  52. case 'import' :
  53. {
  54. //include needed librabries for treatment
  55. $result_log = import_exercise($_FILES['uploadedExercise']['name']);
  56. //display the result message (fail or success)
  57. $dialogBox = '';
  58. foreach ($result_log as $log)
  59. {
  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) ) echo Display::display_normal_message($dialogBox,false);
  84. //display content
  85. if (isset($display) ) echo $display;
  86. //footer display
  87. include api_get_path(INCLUDE_PATH) . '/footer.inc.php';
  88. ?>