hotspot_actionscript_admin.as.php 3.2 KB

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