hotspot_answers.as.php 3.7 KB

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