hotspot_savescore.inc.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. include('../inc/lib/database.lib.php');
  17. $courseCode = $_GET['coursecode'];
  18. $questionId = $_GET['questionId'];
  19. $coordinates = $_GET['coord'];
  20. $objExcercise = $this->exercise;
  21. $exerciseId = $objExcercise->selectId();
  22. // Save clicking order
  23. $answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids'])+1;
  24. if ($_GET['answerId'] == "0") // click is NOT on a hotspot
  25. {
  26. $hit = 0;
  27. $answerId = NULL;
  28. }
  29. else // user clicked ON a hotspot
  30. {
  31. $hit = 1;
  32. $answerId = api_substr($_GET['answerId'],22,2);
  33. // Save into session
  34. $_SESSION['exerciseResult'][$questionId][$answerId] = $hit;
  35. }
  36. //round-up the coordinates
  37. $coords = explode('/',$coordinates);
  38. $coordinates = '';
  39. foreach ($coords as $coord) {
  40. list($x,$y) = explode(';',$coord);
  41. $coordinates .= round($x).';'.round($y).'/';
  42. }
  43. $coordinates = substr($coordinates,0,-1);
  44. $TBL_TRACK_E_HOTSPOT = Database::get_main_table(STATISTIC_TRACK_E_HOTSPOTS);
  45. // Save into db
  46. $sql = "INSERT INTO $TBL_TRACK_E_HOTSPOT (user_id , course_id , quiz_id , question_id , answer_id , correct , coordinate ) VALUES (
  47. '".Database::escape_string($_user['user_id'])."',
  48. '".Database::escape_string($courseCode)."',
  49. '".Database::escape_string($exerciseId)."',
  50. '".Database::escape_string($questionId)."',
  51. '".Database::escape_string($answerId)."',
  52. '".Database::escape_string($hit)."',
  53. '".Database::escape_string($coordinates)."')";
  54. $result = Database::query($sql);
  55. // Save insert id into session if users changes answer.
  56. $insert_id = Database::insert_id();
  57. $_SESSION['exerciseResult'][$questionId]['ids'][$answerOrderId] = $insert_id;