hotspot_answers.as.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file generates the ActionScript variables code used by the
  5. * HotSpot .swf
  6. * @package chamilo.exercise
  7. * @author Toon Keppens, Julio Montoya adding hotspot "medical" support
  8. */
  9. /**
  10. * Code
  11. */
  12. include('exercise.class.php');
  13. include('question.class.php');
  14. include('answer.class.php');
  15. include('../inc/global.inc.php');
  16. // set vars
  17. $userId = $_user['user_id'];
  18. $questionId = $_GET['modifyAnswers'];
  19. $exe_id = $_GET['exe_id'];
  20. $from_db = isset($_GET['from_db']) ? $_GET['from_db'] : 0;
  21. $objQuestion = Question :: read($questionId);
  22. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  23. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  24. $picturePath = $documentPath.'/images';
  25. $pictureName = $objQuestion->selectPicture();
  26. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  27. $pictureWidth = $pictureSize[0];
  28. $pictureHeight = $pictureSize[1];
  29. $courseLang = $_course['language'];
  30. $courseCode = $_course['sysCode'];
  31. $coursePath = $_course['path'];
  32. $answer_type = $objQuestion->selectType();
  33. $course_id = api_get_course_int_id();
  34. if ($answer_type==HOT_SPOT_DELINEATION) {
  35. // Query db for answers
  36. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  37. WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror' ORDER BY id";
  38. } else {
  39. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  40. WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' ORDER BY id";
  41. }
  42. $result = Database::query($sql);
  43. // Init
  44. $output = "hotspot_lang=$courseLang&hotspot_image=$pictureName&hotspot_image_width=$pictureWidth&hotspot_image_height=$pictureHeight&courseCode=$coursePath";
  45. $i = 0;
  46. while ($hotspot = Database::fetch_array($result)) {
  47. $output .= "&hotspot_".$hotspot['id']."=true";
  48. // Square or rectancle
  49. if ($hotspot['hotspot_type'] == 'square' ) {
  50. $output .= "&hotspot_".$hotspot['id']."_type=square";
  51. }
  52. // Circle or ovale
  53. if ($hotspot['hotspot_type'] == 'circle') {
  54. $output .= "&hotspot_".$hotspot['id']."_type=circle";
  55. }
  56. // Polygon
  57. if ($hotspot['hotspot_type'] == 'poly') {
  58. $output .= "&hotspot_".$hotspot['id']."_type=poly";
  59. }
  60. // Delineation
  61. if ($hotspot['hotspot_type'] == 'delineation') {
  62. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  63. }
  64. // oar
  65. if ($hotspot['hotspot_type'] == 'oar') {
  66. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  67. }
  68. $output .= "&hotspot_".$hotspot['id']."_coord=".$hotspot['hotspot_coordinates']."";
  69. $i++;
  70. }
  71. // Generate empty (the maximum number of points is 12 - it is said so in the user interface)
  72. $i++;
  73. for ($i; $i <= 12; $i++) {
  74. $output .= "&hotspot_".$i."=false";
  75. }
  76. // set vars
  77. $questionId = $_GET['modifyAnswers'];
  78. $course_code = $_course['id'];
  79. // Get clicks
  80. if(isset($_SESSION['exerciseResultCoordinates']) && $from_db==0) {
  81. foreach ($_SESSION['exerciseResultCoordinates'][$questionId] as $coordinate) {
  82. $output2 .= $coordinate."|";
  83. }
  84. } else {
  85. // get it from db
  86. $tbl_track_e_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  87. $sql = 'SELECT hotspot_coordinate '.
  88. ' FROM '.$tbl_track_e_hotspot.
  89. ' WHERE hotspot_question_id = '.intval($questionId).
  90. ' AND hotspot_course_code = "'.Database::escape_string($course_code).'"'.
  91. ' AND hotspot_exe_id='.intval($exe_id);
  92. $rs = @Database::query($sql); // don't output error because we are in Flash execution.
  93. while($row = Database :: fetch_array($rs)) {
  94. $output2 .= $row['hotspot_coordinate']."|";
  95. }
  96. }
  97. $output .= "&p_hotspot_answers=".api_substr($output2,0,-1)."&done=done";
  98. $explode = explode('&', $output);
  99. echo $output;