hotspot_savescore.inc.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. $sql = "INSERT INTO $TBL_TRACK_E_HOTSPOT (user_id , course_id , quiz_id , question_id , answer_id , correct , coordinate ) VALUES (
  40. ".intval($_user['user_id']).",
  41. '".Database::escape_string($courseCode)."',
  42. ".intval($exerciseId).",
  43. ".intval($questionId).",
  44. ".intval($answerId).",
  45. ".intval($hit)."',
  46. '".Database::escape_string($coordinates)."')";
  47. $result = Database::query($sql);
  48. // Save insert id into session if users changes answer.
  49. $insert_id = Database::insert_id();
  50. $_SESSION['exerciseResult'][$questionId]['ids'][$answerOrderId] = $insert_id;