exercise_import.php 3.2 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 'exercise_import.inc.php';
  18. include_once '../exercise.class.php';
  19. include_once '../question.class.php';
  20. include_once 'qti/qti_classes.php';
  21. //SQL table name
  22. $tbl_exercise = Database::get_course_table(TABLE_QUIZ_TEST);
  23. $tbl_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  24. $tbl_rel_exercise_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  25. // tool libraries
  26. include_once '../exercise.class.php';
  27. //Tool title
  28. $nameTools = get_lang('ImportExercise');
  29. //bredcrump
  30. $interbredcrump[] = array('url' => '../exercice.php', 'name' => get_lang('Exercises'));
  31. //----------------------------------
  32. // EXECUTE COMMAND
  33. //----------------------------------
  34. $cmd = (isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'show_import');
  35. switch ($cmd) {
  36. case 'show_import' :
  37. {
  38. $display = '<p>'
  39. .get_lang(
  40. 'Imported exercises must consist of a zip or an XML file (IMS-QTI) and be compatible with your Claroline version.'
  41. ).'<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(
  77. TOOL_QUIZ,
  78. array(
  79. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  80. 'CreateDocumentDir' => '../../../courses/'.api_get_course_path().'/document/',
  81. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  82. )
  83. );
  84. //Display Forms or dialog box(if needed)
  85. if (isset($dialogBox)) {
  86. echo Display::display_normal_message($dialogBox, false);
  87. }
  88. //display content
  89. if (isset($display)) {
  90. echo $display;
  91. }
  92. //footer display
  93. include api_get_path(INCLUDE_PATH).'/footer.inc.php';
  94. ?>