survey.ajax.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../global.inc.php';
  4. $action = isset($_GET['a']) ? $_GET['a'] : null;
  5. $current_user_id = api_get_user_id();
  6. $courseId = api_get_course_int_id();
  7. switch ($action) {
  8. case 'save_question':
  9. if (api_is_anonymous()) {
  10. echo '';
  11. break;
  12. }
  13. $surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : null;
  14. $questionId = isset($_GET['question_id']) ? $_GET['question_id'] : null;
  15. $status = isset($_GET['status']) ? (int) $_GET['status'] : null;
  16. $userId = api_get_user_id();
  17. $surveyData = SurveyManager::get_survey($surveyId);
  18. if (empty($surveyData)) {
  19. exit;
  20. }
  21. SurveyUtil::remove_answer(
  22. $userId,
  23. $surveyId,
  24. $questionId,
  25. $courseId
  26. );
  27. SurveyUtil::store_answer(
  28. $userId,
  29. $surveyId,
  30. $questionId,
  31. 1,
  32. $status,
  33. $surveyData
  34. );
  35. break;
  36. }
  37. exit;