link.php 1.3 KB

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