hotspot_actionscript_admin.as.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Toon Keppens
  10. */
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. api_protect_course_script(false);
  13. $isAllowedToEdit = api_is_allowed_to_edit(null, true);
  14. if (!$isAllowedToEdit) {
  15. api_not_allowed(true);
  16. exit;
  17. }
  18. $_course = api_get_course_info();
  19. $questionId = isset($_GET['modifyAnswers']) ? (int) $_GET['modifyAnswers'] : 0;
  20. $objQuestion = Question::read($questionId);
  21. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  22. $picturePath = $documentPath.'/images';
  23. $pictureName = $objQuestion->getPictureFilename();
  24. $pictureSize = getimagesize($picturePath.'/'.$pictureName);
  25. $pictureWidth = $pictureSize[0];
  26. $pictureHeight = $pictureSize[1];
  27. $data = [];
  28. $data['type'] = 'admin';
  29. $data['lang'] = [
  30. 'Square' => get_lang('Square'),
  31. 'Ellipse' => get_lang('Ellipse'),
  32. 'Polygon' => get_lang('Polygon'),
  33. 'HotspotStatus1' => get_lang('HotspotStatus1'),
  34. 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
  35. 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
  36. 'HotspotStatus3' => get_lang('HotspotStatus3'),
  37. 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
  38. 'ShowHotspots' => get_lang('ShowHotspots'),
  39. 'Triesleft' => get_lang('Triesleft'),
  40. 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
  41. 'NextAnswer' => get_lang('NextAnswer'),
  42. 'Delineation' => get_lang('Delineation'),
  43. 'CloseDelineation' => get_lang('CloseDelineation'),
  44. 'Oar' => get_lang('Oar'),
  45. 'ClosePolygon' => get_lang('ClosePolygon'),
  46. 'DelineationStatus1' => get_lang('DelineationStatus1'),
  47. ];
  48. $data['image'] = $objQuestion->selectPicturePath();
  49. $data['image_width'] = $pictureWidth;
  50. $data['image_height'] = $pictureHeight;
  51. $data['courseCode'] = $_course['path'];
  52. $data['hotspots'] = [];
  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);