hotspot_updatescore.inc.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file saves every click in the hotspot tool into track_e_hotspots.
  6. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Toon Keppens
  10. *
  11. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. api_protect_course_script(true);
  15. $courseCode = $_GET['coursecode'];
  16. $questionId = $_GET['questionId'];
  17. $coordinates = $_GET['coord'];
  18. $objExercise = Session::read('objExercise');
  19. $hotspotId = $_GET['hotspotId'];
  20. $exerciseId = $objExercise->selectId();
  21. if ($_GET['answerId'] == "0") { // click is NOT on a hotspot
  22. $hit = 0;
  23. $answerId = $hotspotId;
  24. // remove from session
  25. unset($_SESSION['exerciseResult'][$questionId][$answerId]);
  26. } else { // user clicked ON a hotspot
  27. $hit = 1;
  28. $answerId = $hotspotId;
  29. // Save into session
  30. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  31. }
  32. //round-up the coordinates
  33. $coords = explode('/', $coordinates);
  34. $coordinates = '';
  35. foreach ($coords as $coord) {
  36. list($x, $y) = explode(';', $coord);
  37. $coordinates .= round($x).';'.round($y).'/';
  38. }
  39. $coordinates = substr($coordinates, 0, -1);
  40. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  41. // update db
  42. $update_id = $_SESSION['exerciseResult'][$questionId]['ids'][$answerId];
  43. $sql = "UPDATE $TBL_TRACK_E_HOTSPOT
  44. SET coordinate = '".Database::escape_string($coordinates)."'
  45. WHERE id = ".intval($update_id)."
  46. LIMIT 1";
  47. $result = Database::query($sql);