link.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. //require_once '../inc/global.inc.php';
  4. $survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null;
  5. if (empty($survey_id)) {
  6. api_not_allowed(true);
  7. }
  8. if (!SurveyManager::survey_generation_hash_available()) {
  9. api_not_allowed(true);
  10. }
  11. $course_info = api_get_course_info_by_id($_REQUEST['c']);
  12. $hash_is_valid = SurveyManager::validate_survey_hash(
  13. $survey_id,
  14. $_REQUEST['c'],
  15. $_REQUEST['s'],
  16. $_REQUEST['g'],
  17. $_REQUEST['h']
  18. );
  19. if ($hash_is_valid && $course_info) {
  20. $survey_data = SurveyManager::get_survey(
  21. $survey_id,
  22. null,
  23. $course_info['code']
  24. );
  25. $invitation_code = api_get_unique_id();
  26. $params = array(
  27. 'c_id' => $_REQUEST['c'],
  28. 'session_id' => $_REQUEST['s'],
  29. 'user' => $invitation_code,
  30. 'survey_code' => $survey_data['code'],
  31. 'invitation_code' => $invitation_code,
  32. 'invitation_date' => api_get_utc_datetime()
  33. );
  34. $invitation_id = SurveyUtil::save_invitation($params);
  35. if ($invitation_id) {
  36. $link = api_get_path(WEB_CODE_PATH).
  37. 'survey/fillsurvey.php
  38. ?invitationcode='.$invitation_code.
  39. '&course='.$course_info['code'].
  40. 'cidReq='.$course_info['code']
  41. ;
  42. header('Location: '.$link);
  43. exit;
  44. }
  45. } else {
  46. api_not_allowed(true);
  47. }