hotspot_updatescore.inc.php 1.5 KB

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