hotspot_actionscript_admin.as.php 3.3 KB

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