hotspot_answers.as.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. include('../inc/global.inc.php');
  10. // Set vars
  11. $questionId = intval($_GET['modifyAnswers']);
  12. $exe_id = intval($_GET['exe_id']);
  13. $objQuestion = Question :: read($questionId);
  14. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  15. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  16. $picturePath = $documentPath.'/images';
  17. $pictureName = $objQuestion->selectPicture();
  18. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  19. $pictureWidth = $pictureSize[0];
  20. $pictureHeight = $pictureSize[1];
  21. $answer_type = $objQuestion->selectType();
  22. $course_id = api_get_course_int_id();
  23. if ($answer_type == HOT_SPOT_DELINEATION) {
  24. // Query db for answers
  25. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  26. WHERE c_id = $course_id AND question_id = ".intval($questionId)." AND hotspot_type <> 'noerror' ORDER BY id";
  27. } else {
  28. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  29. WHERE c_id = $course_id AND question_id = ".intval($questionId)." ORDER BY id";
  30. }
  31. $result = Database::query($sql);
  32. // Init
  33. $data = [];
  34. $data['type'] = 'solution';
  35. $data['lang'] = [
  36. 'Square' => get_lang('Square'),
  37. 'Circle' => get_lang('Circle'),
  38. 'Polygon' => get_lang('Polygon'),
  39. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  40. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  41. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  42. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  43. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  44. 'ShowHotspots' => get_lang('ShowHotspots'),
  45. 'Triesleft' => get_lang('Triesleft'),
  46. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  47. 'NextAnswer' => get_lang('NextAnswer'),
  48. 'Delineation' => get_lang('Delineation'),
  49. 'CloseDelineation' => get_lang('CloseDelineation'),
  50. 'Oar' => get_lang('Oar'),
  51. 'ClosePolygon' => get_lang('ClosePolygon')
  52. ];
  53. $data['image'] = $objQuestion->selectPicturePath();
  54. $data['image_width'] = $pictureWidth;
  55. $data['image_height'] = $pictureHeight;
  56. $data['courseCode'] = $_course['path'];
  57. $data['hotspots'] = [];
  58. while ($hotspot = Database::fetch_array($result)) {
  59. $hotSpot = [];
  60. $hotSpot['id'] = $hotspot['id'];
  61. $hotSpot['answer'] = $hotspot['answer'];
  62. // Square or rectancle
  63. if ($hotspot['hotspot_type'] == 'square' ) {
  64. $hotSpot['type'] = 'square';
  65. }
  66. // Circle or ovale
  67. if ($hotspot['hotspot_type'] == 'circle') {
  68. $hotSpot['type'] = 'circle';
  69. }
  70. // Polygon
  71. if ($hotspot['hotspot_type'] == 'poly') {
  72. $hotSpot['type'] = 'poly';
  73. }
  74. // Delineation
  75. if ($hotspot['hotspot_type'] == 'delineation') {
  76. $hotSpot['type'] = 'delineation';
  77. }
  78. // oar
  79. if ($hotspot['hotspot_type'] == 'oar') {
  80. $hotSpot['type'] = 'delineation';
  81. }
  82. $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
  83. $data['hotspots'][] = $hotSpot;
  84. }
  85. $data['answers'] = [];
  86. $tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  87. $sql = "SELECT hotspot_coordinate
  88. FROM $tbl_track_e_hotspot
  89. WHERE hotspot_question_id = $questionId AND
  90. c_id = $course_id AND
  91. hotspot_exe_id = $exe_id
  92. ORDER by hotspot_id";
  93. $rs = Database::query($sql); // don't output error because we are in Flash execution.
  94. while($row = Database :: fetch_array($rs, 'ASSOC')) {
  95. $data['answers'][] = $row['hotspot_coordinate'];
  96. }
  97. $data['done'] = 'done';
  98. header('Content-Type: application/json');
  99. echo json_encode($data);