hotspot_actionscript_admin.as.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. */
  8. require_once '../inc/global.inc.php';
  9. // set vars
  10. $questionId = intval($_GET['modifyAnswers']);
  11. $objQuestion = Question::read($questionId);
  12. $_course = api_get_course_info();
  13. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  14. $picturePath = $documentPath.'/images';
  15. $pictureName = $objQuestion->selectPicture();
  16. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  17. $pictureWidth = $pictureSize[0];
  18. $pictureHeight = $pictureSize[1];
  19. $data = [];
  20. $data['type'] = 'admin';
  21. $data['lang'] = [
  22. 'Square' => get_lang('Square'),
  23. 'Circle' => get_lang('Circle'),
  24. 'Polygon' => get_lang('Polygon'),
  25. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  26. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  27. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  28. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  29. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  30. 'ShowHotspots' => get_lang('ShowHotspots'),
  31. 'Triesleft' => get_lang('Triesleft'),
  32. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  33. 'NextAnswer' => get_lang('NextAnswer'),
  34. 'Delineation' => get_lang('Delineation'),
  35. 'CloseDelineation' => get_lang('CloseDelineation'),
  36. 'Oar' => get_lang('oar')
  37. ];
  38. $data['image'] = $objQuestion->selectPicturePath();
  39. $data['image_width'] = $pictureWidth;
  40. $data['image_height'] = $pictureHeight;
  41. $data['courseCode'] = $_course['path'];
  42. $data['hotspots'] = [];
  43. // Init
  44. $i = 0;
  45. $nmbrTries = 0;
  46. $answer_type = $objQuestion->type;
  47. $answers = $_SESSION['tmp_answers'];
  48. $nbrAnswers = count($answers['answer']);
  49. for ($i=1;$i <= $nbrAnswers; $i++) {
  50. $hotSpot = [];
  51. $hotSpot['id'] = null;
  52. $hotSpot['answer']= $answers['answer'][$i];
  53. if ($answer_type == HOT_SPOT_DELINEATION) {
  54. if ($i==1) {
  55. $hotSpot['type'] = 'delineation';
  56. } else {
  57. $hotSpot['type'] = 'oar';
  58. }
  59. } else {
  60. // Square or rectancle
  61. if ($answers['hotspot_type'][$i] == 'square') {
  62. $hotSpot['type'] = 'square';
  63. }
  64. // Circle or ovale
  65. if ($answers['hotspot_type'][$i] == 'circle') {
  66. $hotSpot['type'] = 'circle';
  67. }
  68. // Polygon
  69. if ($answers['hotspot_type'][$i] == 'poly') {
  70. $hotSpot['type'] = 'poly';
  71. }
  72. /*// Delineation
  73. if ($answers['hotspot_type'][$i] == 'delineation')
  74. {
  75. $output .= "&hotspot_".$i."_type=delineation";
  76. }*/
  77. }
  78. // This is a good answer, count + 1 for nmbr of clicks
  79. if ($answers['weighting'][$i] > 0) {
  80. $nmbrTries++;
  81. }
  82. $hotSpot['coord'] = $answers['hotspot_coordinates'][$i];
  83. $data['hotspots'][] = $hotSpot;
  84. }
  85. // Output
  86. $data['nmbrTries'] = $nmbrTries;
  87. $data['done'] = 'done';
  88. header('Content-Type: application/json');
  89. echo json_encode($data);