exercise_jump.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if (isset($_GET['doexercise'])) {
  23. $doExerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.http_build_query([
  24. 'session_id' => $session_id,
  25. 'cidReq' => $cidReq,
  26. 'gradebook' => $gradebook,
  27. 'origin' => '',
  28. 'learnpath_id' => '',
  29. 'learnpath_item_id' => '',
  30. 'exerciseId' => intval($_GET['doexercise']),
  31. ]);
  32. }
  33. // no support for hot potatoes
  34. if ($type == LINK_HOTPOTATOES) {
  35. $exerciseId = $_GET['exerciseId'];
  36. $path = Security::remove_XSS($_GET['path']);
  37. $doExerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/showinframes.php?'.http_build_query([
  38. 'session_id' => $session_id,
  39. 'cidReq' => Security::remove_XSS($cidReq),
  40. 'file' => $path,
  41. 'cid' => api_get_course_id(),
  42. 'uid' => api_get_user_id(),
  43. ]);
  44. header('Location: '.$doExerciseUrl);
  45. exit;
  46. }
  47. if (isset($_GET['doexercise'])) {
  48. header('Location: '.$doExerciseUrl);
  49. exit;
  50. } else {
  51. $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?session_id='.$session_id.'&cidReq='.Security::remove_XSS($cidReq);
  52. if (isset($_GET['gradebook'])) {
  53. $url .= '&gradebook=view&exerciseId='.intval($_GET['exerciseId']);
  54. // Check if exercise is inserted inside a LP, if that's the case
  55. $exerciseId = $_GET['exerciseId'];
  56. $exercise = new Exercise();
  57. $exercise->read($exerciseId);
  58. if (!empty($exercise->id)) {
  59. if ($exercise->exercise_was_added_in_lp) {
  60. if (!empty($exercise->lpList)) {
  61. $count = count($exercise->lpList);
  62. if ($count == 1) {
  63. // If the exercise was added once redirect to the LP
  64. $firstLp = current($exercise->lpList);
  65. if (isset($firstLp['lp_id'])) {
  66. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&lp_id='.$firstLp['lp_id'].'&action=view&isStudentView=true';
  67. }
  68. } else {
  69. // If the exercise was added multiple times show the LP list
  70. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=list';
  71. }
  72. }
  73. }
  74. }
  75. }
  76. header('Location: '.$url);
  77. exit;
  78. }