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