hotspot_answers.as.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file generates the ActionScript variables code used by the
  5. * HotSpot .swf
  6. * @package chamilo.exercise
  7. * @author Toon Keppens, Julio Montoya adding hotspot "medical" support
  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. // set vars
  17. $userId = $_user['user_id'];
  18. $questionId = $_GET['modifyAnswers'];
  19. $exe_id = $_GET['exe_id'];
  20. $from_db = isset($_GET['from_db']) ? $_GET['from_db'] : 0;
  21. $objQuestion = Question :: read($questionId);
  22. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  23. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  24. $picturePath = $documentPath.'/images';
  25. $pictureName = $objQuestion->selectPicture();
  26. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  27. $pictureWidth = $pictureSize[0];
  28. $pictureHeight = $pictureSize[1];
  29. $courseLang = $_course['language'];
  30. $courseCode = $_course['sysCode'];
  31. $coursePath = $_course['path'];
  32. $answer_type = $objQuestion->selectType();
  33. if ($answer_type==HOT_SPOT_DELINEATION) {
  34. // Query db for answers
  35. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror' ORDER BY id";
  36. } else {
  37. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' ORDER BY id";
  38. }
  39. $result = Database::query($sql);
  40. // Init
  41. $output = "hotspot_lang=$courseLang&hotspot_image=$pictureName&hotspot_image_width=$pictureWidth&hotspot_image_height=$pictureHeight&courseCode=$coursePath";
  42. $i = 0;
  43. while ($hotspot = Database::fetch_array($result)) {
  44. $output .= "&hotspot_".$hotspot['id']."=true";
  45. // Square or rectancle
  46. if ($hotspot['hotspot_type'] == 'square' ) {
  47. $output .= "&hotspot_".$hotspot['id']."_type=square";
  48. }
  49. // Circle or ovale
  50. if ($hotspot['hotspot_type'] == 'circle') {
  51. $output .= "&hotspot_".$hotspot['id']."_type=circle";
  52. }
  53. // Polygon
  54. if ($hotspot['hotspot_type'] == 'poly') {
  55. $output .= "&hotspot_".$hotspot['id']."_type=poly";
  56. }
  57. // Delineation
  58. if ($hotspot['hotspot_type'] == 'delineation') {
  59. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  60. }
  61. // oar
  62. if ($hotspot['hotspot_type'] == 'oar') {
  63. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  64. }
  65. $output .= "&hotspot_".$hotspot['id']."_coord=".$hotspot['hotspot_coordinates']."";
  66. $i++;
  67. }
  68. // Generate empty (the maximum number of points is 12 - it is said so in the user interface)
  69. $i++;
  70. for ($i; $i <= 12; $i++) {
  71. $output .= "&hotspot_".$i."=false";
  72. }
  73. // set vars
  74. $questionId = $_GET['modifyAnswers'];
  75. $course_code = $_course['id'];
  76. // Get clicks
  77. if(isset($_SESSION['exerciseResultCoordinates']) && $from_db==0) {
  78. foreach ($_SESSION['exerciseResultCoordinates'][$questionId] as $coordinate) {
  79. $output2 .= $coordinate."|";
  80. }
  81. } else {
  82. // get it from db
  83. $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  84. $sql = 'SELECT hotspot_coordinate '.
  85. ' FROM '.$tbl_track_e_hotspot.
  86. ' WHERE hotspot_question_id = '.intval($questionId).
  87. ' AND hotspot_course_code = "'.Database::escape_string($course_code).'"'.
  88. ' AND hotspot_exe_id='.intval($exe_id);
  89. $rs = @Database::query($sql); // don't output error because we are in Flash execution.
  90. while($row = Database :: fetch_array($rs)) {
  91. $output2 .= $row['hotspot_coordinate']."|";
  92. }
  93. }
  94. $output .= "&p_hotspot_answers=".api_substr($output2,0,-1)."&done=done";
  95. $explode = explode('&', $output);
  96. echo $output;