hotspot_updatescore.inc.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php //$id:$
  2. /* For licensing terms, see /dokeos_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. /**
  10. * Code
  11. */
  12. include 'exercise.class.php';
  13. include 'question.class.php';
  14. include 'answer.class.php';
  15. include '../inc/global.inc.php';
  16. $courseCode = $_GET['coursecode'];
  17. $questionId = $_GET['questionId'];
  18. $coordinates = $_GET['coord'];
  19. $objExcercise = $_SESSION['objExercise'];
  20. $hotspotId = $_GET['hotspotId'];
  21. $exerciseId = $objExcercise->selectId();
  22. if ($_GET['answerId'] == "0") { // click is NOT on a hotspot
  23. $hit = 0;
  24. $answerId = $hotspotId;
  25. // remove from session
  26. unset($_SESSION['exerciseResult'][$questionId][$answerId]);
  27. // Save clicking order
  28. //$answerOrderId = count($_SESSION['exerciseResult'][$questionId]['order'])+1;
  29. //$_SESSION['exerciseResult'][$questionId]['order'][$answerOrderId] = $answerId;
  30. } else { // user clicked ON a hotspot
  31. $hit = 1;
  32. $answerId = $hotspotId;
  33. // Save into session
  34. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  35. // Save clicking order
  36. //$answerOrderId = count($_SESSION['exerciseResult'][$questionId]['order'])+1;
  37. //$_SESSION['exerciseResult'][$questionId]['order'][$answerOrderId] = $answerId;
  38. }
  39. //round-up the coordinates
  40. $coords = explode('/',$coordinates);
  41. $coordinates = '';
  42. foreach ($coords as $coord) {
  43. list($x,$y) = explode(';',$coord);
  44. $coordinates .= round($x).';'.round($y).'/';
  45. }
  46. $coordinates = substr($coordinates,0,-1);
  47. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(STATISTIC_TRACK_E_HOTSPOTS);
  48. // update db
  49. $update_id = $_SESSION['exerciseResult'][$questionId]['ids'][$answerId];
  50. $sql = "UPDATE $TBL_TRACK_E_HOTSPOT SET coordinate = '".Database::escape_string($coordinates)."' WHERE id ='".Database::escape_string($update_id)."' LIMIT 1 ;;";
  51. $result = Database::query($sql);