hotspot_answers.as.php 3.6 KB

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