link.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../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).'survey/fillsurvey.php?invitationcode='.$invitation_code.'&course='.$course_info['code'];
  37. header('Location: '.$link);
  38. exit;
  39. }
  40. } else {
  41. api_not_allowed(true);
  42. }