exercise_jump.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 '../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 = null;
  20. if (isset($_GET['doexercise'])) {
  21. $doExerciseUrl = api_get_path(WEB_CODE_PATH) . 'exercice/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. $doExerciseUrl = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?session_id='.$session_id.'&cidReq='.Security::remove_XSS($cidReq);
  34. }
  35. if (isset($_GET['doexercise'])) {
  36. header('Location: '.$doExerciseUrl);
  37. exit;
  38. } else {
  39. $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?session_id='.$session_id.'&cidReq='.Security::remove_XSS($cidReq);
  40. if (isset($_GET['gradebook'])) {
  41. $url .= '&gradebook=view&exerciseId='.intval($_GET['exerciseId']);
  42. // Check if exercise is inserted inside a LP, if that's the case
  43. $exerciseId = $_GET['exerciseId'];
  44. $exercise = new Exercise();
  45. $exercise->read($exerciseId);
  46. if (!empty($exercise->id)) {
  47. if ($exercise->exercise_was_added_in_lp) {
  48. if (!empty($exercise->lpList)) {
  49. $count = count($exercise->lpList);
  50. if ($count == 1) {
  51. // If the exercise was added once redirect to the LP
  52. $firstLp = current($exercise->lpList);
  53. if (isset($firstLp['lp_id'])) {
  54. $url = api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq() . '&lp_id=' . $firstLp['lp_id'] . '&action=view&isStudentView=true';
  55. }
  56. } else {
  57. // If the exercise was added multiple times show the LP list
  58. $url = api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq().'&action=list';
  59. }
  60. }
  61. }
  62. }
  63. }
  64. header('Location: '.$url);
  65. exit;
  66. }