exercise_jump.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Sets needed course variables and then jumps to the exercises result page.
  5. * This intermediate page is needed because the user is not inside a course
  6. * when visiting the gradebook, and several course scripts rely on these
  7. * variables.
  8. * Most code here is ripped from /main/course_home/course_home.php.
  9. *
  10. * @author Bert Steppé
  11. *
  12. * @package chamilo.gradebook
  13. */
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. api_block_anonymous_users();
  16. $this_section = SECTION_COURSES;
  17. $gradebook = Security::remove_XSS($_GET['gradebook']);
  18. $session_id = api_get_session_id();
  19. $cidReq = Security::remove_XSS($_GET['cidReq']);
  20. $type = Security::remove_XSS($_GET['type']);
  21. $doExerciseUrl = '';
  22. // no support for hot potatoes
  23. if ($type == LINK_HOTPOTATOES) {
  24. $exerciseId = $_GET['exerciseId'];
  25. $path = Security::remove_XSS($_GET['path']);
  26. $doExerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/showinframes.php?'.http_build_query(
  27. [
  28. 'session_id' => $session_id,
  29. 'cidReq' => Security::remove_XSS($cidReq),
  30. 'file' => $path,
  31. 'cid' => api_get_course_id(),
  32. 'uid' => api_get_user_id(),
  33. ]
  34. );
  35. header('Location: '.$doExerciseUrl);
  36. exit;
  37. }
  38. if (!empty($doExerciseUrl)) {
  39. header('Location: '.$doExerciseUrl);
  40. exit;
  41. } else {
  42. $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'
  43. .http_build_query(['session_id' => $session_id, 'cidReq' => $cidReq]);
  44. if (isset($_GET['gradebook'])) {
  45. $url .= '&gradebook=view&exerciseId='.((int) $_GET['exerciseId']);
  46. // Check if exercise is inserted inside a LP, if that's the case
  47. $exerciseId = $_GET['exerciseId'];
  48. $exercise = new Exercise();
  49. $exercise->read($exerciseId);
  50. if (!empty($exercise->id)) {
  51. if ($exercise->exercise_was_added_in_lp) {
  52. if (!empty($exercise->lpList)) {
  53. $count = count($exercise->lpList);
  54. if ($count == 1) {
  55. // If the exercise was added once redirect to the LP
  56. $firstLp = current($exercise->lpList);
  57. if (isset($firstLp['lp_id'])) {
  58. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&'
  59. .http_build_query(
  60. [
  61. 'lp_id' => $firstLp['lp_id'],
  62. 'action' => 'view',
  63. 'isStudentView' => 'true',
  64. ]
  65. );
  66. }
  67. } else {
  68. // If the exercise was added multiple times show the LP list
  69. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=list';
  70. }
  71. }
  72. } else {
  73. $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.http_build_query(
  74. [
  75. 'session_id' => $session_id,
  76. 'cidReq' => $cidReq,
  77. 'gradebook' => $gradebook,
  78. 'origin' => '',
  79. 'learnpath_id' => '',
  80. 'learnpath_item_id' => '',
  81. 'exerciseId' => (int) $_GET['exerciseId'],
  82. ]
  83. );
  84. }
  85. }
  86. }
  87. header('Location: '.$url);
  88. exit;
  89. }