hotspot_actionscript.as.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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['type'] = 'user';
  34. $data['lang'] = [
  35. 'Square' => get_lang('Square'),
  36. 'Circle' => get_lang('Circle'),
  37. 'Polygon' => get_lang('Polygon'),
  38. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  39. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  40. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  41. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  42. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  43. 'ShowHotspots' => get_lang('ShowHotspots'),
  44. 'Triesleft' => get_lang('Triesleft'),
  45. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  46. 'NextAnswer' => get_lang('NextAnswer'),
  47. 'Delineation' => get_lang('Delineation'),
  48. 'CloseDelineation' => get_lang('CloseDelineation'),
  49. 'Oar' => get_lang('Oar'),
  50. 'ClosePolygon' => get_lang('ClosePolygon')
  51. ];
  52. $data['image'] = $objQuestion->selectPicturePath();
  53. $data['image_width'] = $pictureWidth;
  54. $data['image_height'] = $pictureHeight;
  55. $data['courseCode'] = $_course['path'];
  56. $data['hotspots'] = [];
  57. $nmbrTries = 0;
  58. while ($hotspot = Database::fetch_assoc($result))
  59. {
  60. $hotSpot = [];
  61. $hotSpot['id'] = $hotspot['id'];
  62. $hotSpot['answer'] = $hotspot['answer'];
  63. // Square or rectancle
  64. if ($hotspot['hotspot_type'] == 'square' )
  65. {
  66. $hotSpot['type'] = 'square';
  67. }
  68. // Circle or ovale
  69. if ($hotspot['hotspot_type'] == 'circle')
  70. {
  71. $hotSpot['type'] = 'circle';
  72. }
  73. // Polygon
  74. if ($hotspot['hotspot_type'] == 'poly')
  75. {
  76. $hotSpot['type'] = 'poly';
  77. }
  78. // Delineation
  79. if ($hotspot['hotspot_type'] == 'delineation')
  80. {
  81. $hotSpot['type'] = 'delineation';
  82. }
  83. // No error
  84. if ($hotspot['hotspot_type'] == 'noerror')
  85. {
  86. $hotSpot['type'] = 'noerror';
  87. }
  88. // This is a good answer, count + 1 for nmbr of clicks
  89. if ($hotspot['hotspot_type'] > 0)
  90. {
  91. $nmbrTries++;
  92. }
  93. $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
  94. $data['hotspots'][] = $hotSpot;
  95. }
  96. $data['nmbrTries'] = $nmbrTries;
  97. $data['done'] = 'done';
  98. header('Content-Type: application/json');
  99. echo json_encode($data);