hotspot_savescore.inc.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file saves every click in the hotspot tool into track_e_hotspots
  5. * @package chamilo.exercise
  6. * @author Toon Keppens
  7. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  8. */
  9. require_once '../inc/global.inc.php';
  10. $courseCode = $_GET['coursecode'];
  11. $questionId = $_GET['questionId'];
  12. $coordinates = $_GET['coord'];
  13. $objExcercise = $_SESSION['objExercise'];
  14. $exerciseId = $objExcercise->selectId();
  15. // Save clicking order
  16. $answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids'])+1;
  17. if ($_GET['answerId'] == "0") // click is NOT on a hotspot
  18. {
  19. $hit = 0;
  20. $answerId = NULL;
  21. }
  22. else // user clicked ON a hotspot
  23. {
  24. $hit = 1;
  25. $answerId = api_substr($_GET['answerId'],22,2);
  26. // Save into session
  27. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  28. }
  29. //round-up the coordinates
  30. $coords = explode('/',$coordinates);
  31. $coordinates = '';
  32. foreach ($coords as $coord) {
  33. list($x,$y) = explode(';',$coord);
  34. $coordinates .= round($x).';'.round($y).'/';
  35. }
  36. $coordinates = substr($coordinates,0,-1);
  37. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  38. // Save into db
  39. $params = [
  40. 'user_id' => api_get_user_id(),
  41. 'course_id' => $courseCode,
  42. 'quiz_id' => $exerciseId,
  43. 'question_id' => $questionId,
  44. 'answer_id' => $answerId,
  45. 'correct' => $hit ,
  46. 'coordinate' => $coordinates
  47. ];
  48. // Save insert id into session if users changes answer.
  49. $insert_id = Database::insert($TBL_TRACK_E_HOTSPOT, $params);
  50. $_SESSION['exerciseResult'][$questionId]['ids'][$answerOrderId] = $insert_id;