exercise_import.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. require_once 'exercise_import.inc.php';
  17. //SQL table name
  18. $tbl_exercise = Database::get_course_table(TABLE_QUIZ_TEST);
  19. $tbl_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  20. $tbl_rel_exercise_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  21. // tool libraries
  22. //Tool title
  23. $nameTools = get_lang('ImportExercise');
  24. //bredcrump
  25. $interbredcrump[] = array('url' => '../exercise.php', 'name' => get_lang('Exercises'));
  26. //----------------------------------
  27. // EXECUTE COMMAND
  28. //----------------------------------
  29. $cmd = (isset($_REQUEST['cmd'])? $_REQUEST['cmd'] : 'show_import');
  30. switch ($cmd) {
  31. case 'show_import' :
  32. {
  33. $display = '<p>'
  34. . get_lang('Imported exercises must consist of a zip or an XML file (IMS-QTI) and be compatible with your Claroline version.') . '<br>'
  35. . '</p>'
  36. . '<form enctype="multipart/form-data" action="" method="post">'
  37. . '<input name="cmd" type="hidden" value="import" />'
  38. . '<input name="uploadedExercise" type="file" /><br><br>'
  39. . get_lang('Import exercise') . ' : '
  40. . '<input value="' . get_lang('Ok') . '" type="submit" /> '
  41. . claro_html_button( $_SERVER['PHP_SELF'], get_lang('Cancel'))
  42. . '<br><br>'
  43. . '<small>' . get_lang('Max file size') . ' : 2&nbsp;MB</small>'
  44. . '</form>';
  45. }
  46. break;
  47. case 'import': {
  48. //include needed librabries for treatment
  49. $result_log = import_exercise($_FILES['uploadedExercise']['name']);
  50. //display the result message (fail or success)
  51. $dialogBox = '';
  52. foreach ($result_log as $log) {
  53. $dialogBox .= $log.'<br>';
  54. }
  55. }
  56. break;
  57. }
  58. //----------------------------------
  59. // FIND INFORMATION
  60. //----------------------------------
  61. //empty!
  62. //----------------------------------
  63. // DISPLAY
  64. //----------------------------------
  65. include api_get_path(INCLUDE_PATH) . '/header.inc.php';
  66. //display title
  67. // Tool introduction
  68. // TODO: These settings to be checked when it is possible.
  69. Display::display_introduction_section(TOOL_QUIZ, array(
  70. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
  71. 'CreateDocumentDir' => '../../../courses/'.api_get_course_path().'/document/',
  72. 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
  73. )
  74. );
  75. //Display Forms or dialog box(if needed)
  76. if (isset($dialogBox)) {
  77. echo Display::display_normal_message($dialogBox, false);
  78. }
  79. //display content
  80. if (isset($display)) {
  81. echo $display;
  82. }
  83. //footer display
  84. include api_get_path(INCLUDE_PATH) . '/footer.inc.php';
  85. ?>