exercise_jump.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. * @author Bert Steppé
  10. * @package chamilo.gradebook
  11. */
  12. api_block_anonymous_users();
  13. $this_section = SECTION_COURSES;
  14. $gradebook = Security::remove_XSS($_GET['gradebook']);
  15. $session_id = api_get_session_id();
  16. $cidReq = Security::remove_XSS($_GET['cidReq']);
  17. $type = Security::remove_XSS($_GET['type']);
  18. $doExerciseUrl = '';
  19. if (isset($_GET['doexercise'])) {
  20. $doExerciseUrl = api_get_path(WEB_CODE_PATH) . 'exercise/overview.php?' . http_build_query([
  21. 'session_id' => $session_id,
  22. 'cidReq' => $cidReq,
  23. 'gradebook' => $gradebook,
  24. 'origin' => '',
  25. 'learnpath_id' => '',
  26. 'learnpath_item_id' => '',
  27. 'exerciseId' => intval($_GET['doexercise'])
  28. ]);
  29. }
  30. // no support for hot potatoes
  31. if ($type == LINK_HOTPOTATOES) {
  32. $doExerciseUrl = api_get_path(WEB_CODE_PATH) . 'exercise/exercice.php?session_id='.$session_id.'&cidReq='.Security::remove_XSS($cidReq);
  33. }
  34. if (isset($_GET['doexercise'])) {
  35. header('Location: '.$doExerciseUrl);
  36. exit;
  37. } else {
  38. $url = api_get_path(WEB_CODE_PATH) . 'exercise/overview.php?session_id='.$session_id.'&cidReq='.Security::remove_XSS($cidReq);
  39. if (isset($_GET['gradebook'])) {
  40. $url .= '&gradebook=view&exerciseId='.intval($_GET['exerciseId']);
  41. // Check if exercise is inserted inside a LP, if that's the case
  42. $exerciseId = $_GET['exerciseId'];
  43. $exercise = new Exercise();
  44. $exercise->read($exerciseId);
  45. if (!empty($exercise->id)) {
  46. if ($exercise->exercise_was_added_in_lp) {
  47. if (!empty($exercise->lpList)) {
  48. $count = count($exercise->lpList);
  49. if ($count == 1) {
  50. // If the exercise was added once redirect to the LP
  51. $firstLp = current($exercise->lpList);
  52. if (isset($firstLp['lp_id'])) {
  53. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq() . '&lp_id=' . $firstLp['lp_id'] . '&action=view&isStudentView=true';
  54. }
  55. } else {
  56. // If the exercise was added multiple times show the LP list
  57. $url = api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq().'&action=list';
  58. }
  59. }
  60. }
  61. }
  62. }
  63. header('Location: '.$url);
  64. exit;
  65. }