link.php 1.3 KB

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