hotspot_actionscript.as.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file generates the ActionScript variables code used by the HotSpot .swf
  5. * @package chamilo.exercise
  6. * @author Toon Keppens
  7. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  8. */
  9. session_cache_limiter("none");
  10. include('../inc/global.inc.php');
  11. // set vars
  12. $questionId = intval($_GET['modifyAnswers']);
  13. $objQuestion = Question::read($questionId);
  14. $answer_type = $objQuestion->selectType(); //very important
  15. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  16. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  17. $picturePath = $documentPath.'/images';
  18. $pictureName = $objQuestion->selectPicture();
  19. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  20. $pictureWidth = $pictureSize[0];
  21. $pictureHeight = $pictureSize[1];
  22. $course_id = api_get_course_int_id();
  23. // Query db for answers
  24. if ($answer_type==HOT_SPOT_DELINEATION) {
  25. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS
  26. WHERE c_id = $course_id AND question_id = ".intval($questionId)." AND hotspot_type = 'delineation' ORDER BY id";
  27. } else {
  28. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS
  29. WHERE c_id = $course_id AND question_id = ".intval($questionId)." ORDER BY id";
  30. }
  31. $result = Database::query($sql);
  32. $data = [];
  33. $data['lang'] = [
  34. 'Square' => get_lang('Square'),
  35. 'Circle' => get_lang('Circle'),
  36. 'Poly' => get_lang('Poly'),
  37. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  38. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  39. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  40. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  41. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  42. 'ShowHotspots' => get_lang('ShowHotspots'),
  43. 'Triesleft' => get_lang('Triesleft'),
  44. 'ExerciseFinished' => get_lang('ExerciseFinished'),
  45. 'NextAnswer' => get_lang('NextAnswer'),
  46. 'Delineation' => get_lang('Delineation'),
  47. 'CloseDelineation' => get_lang('CloseDelineation'),
  48. 'Oar' => get_lang('oar')
  49. ];
  50. $data['image'] = $objQuestion->selectPicturePath();
  51. $data['image_width'] = $pictureWidth;
  52. $data['image_height'] = $pictureHeight;
  53. $data['courseCode'] = $_course['path'];
  54. $data['hotspots'] = [];
  55. $nmbrTries = 0;
  56. while ($hotspot = Database::fetch_assoc($result))
  57. {
  58. $hotSpot = [];
  59. $hotSpot['id'] = $hotspot['id'];
  60. $hotSpot['answer'] = $hotspot['answer'];
  61. // Square or rectancle
  62. if ($hotspot['hotspot_type'] == 'square' )
  63. {
  64. $hotSpot['type'] = 'square';
  65. }
  66. // Circle or ovale
  67. if ($hotspot['hotspot_type'] == 'circle')
  68. {
  69. $hotSpot['type'] = 'circle';
  70. }
  71. // Polygon
  72. if ($hotspot['hotspot_type'] == 'poly')
  73. {
  74. $hotSpot['type'] = 'poly';
  75. }
  76. // Delineation
  77. if ($hotspot['hotspot_type'] == 'delineation')
  78. {
  79. $hotSpot['type'] = 'delineation';
  80. }
  81. // No error
  82. if ($hotspot['hotspot_type'] == 'noerror')
  83. {
  84. $hotSpot['type'] = 'noerror';
  85. }
  86. // This is a good answer, count + 1 for nmbr of clicks
  87. if ($hotspot['hotspot_type'] > 0)
  88. {
  89. $nmbrTries++;
  90. }
  91. $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
  92. $data['hotspots'][] = $hotSpot;
  93. }
  94. $data['nmbrTries'] = $nmbrTries;
  95. $data['done'] = 'done';
  96. header('Content-Type: application/json');
  97. echo json_encode($data);