hotspot_updatescore.inc.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $hotspotId = $_GET['hotspotId'];
  15. $exerciseId = $objExcercise->selectId();
  16. if ($_GET['answerId'] == "0") { // click is NOT on a hotspot
  17. $hit = 0;
  18. $answerId = $hotspotId;
  19. // remove from session
  20. unset($_SESSION['exerciseResult'][$questionId][$answerId]);
  21. // Save clicking order
  22. //$answerOrderId = count($_SESSION['exerciseResult'][$questionId]['order'])+1;
  23. //$_SESSION['exerciseResult'][$questionId]['order'][$answerOrderId] = $answerId;
  24. } else { // user clicked ON a hotspot
  25. $hit = 1;
  26. $answerId = $hotspotId;
  27. // Save into session
  28. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  29. // Save clicking order
  30. //$answerOrderId = count($_SESSION['exerciseResult'][$questionId]['order'])+1;
  31. //$_SESSION['exerciseResult'][$questionId]['order'][$answerOrderId] = $answerId;
  32. }
  33. //round-up the coordinates
  34. $coords = explode('/',$coordinates);
  35. $coordinates = '';
  36. foreach ($coords as $coord) {
  37. list($x,$y) = explode(';',$coord);
  38. $coordinates .= round($x).';'.round($y).'/';
  39. }
  40. $coordinates = substr($coordinates,0,-1);
  41. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  42. // update db
  43. $update_id = $_SESSION['exerciseResult'][$questionId]['ids'][$answerId];
  44. $sql = "UPDATE $TBL_TRACK_E_HOTSPOT SET coordinate = '".Database::escape_string($coordinates)."' WHERE id = ".intval($update_id)." LIMIT 1 ;;";
  45. $result = Database::query($sql);