exercise_show_functions.lib.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * EVENTS LIBRARY
  5. *
  6. * This is the events library for Chamilo.
  7. * Functions of this library are used to record informations when some kind
  8. * of event occur. Each event has his own types of informations then each event
  9. * use its own function.
  10. *
  11. * @package chamilo.library
  12. * @todo convert queries to use Database API
  13. */
  14. /**
  15. * Class
  16. * @package chamilo.library
  17. */
  18. class ExerciseShowFunctions {
  19. /**
  20. * Shows the answer to a fill-in-the-blanks question, as HTML
  21. * @param string Answer text
  22. * @param int Exercise ID
  23. * @param int Question ID
  24. * @return void
  25. */
  26. function display_fill_in_blanks_answer($answer,$id,$questionId) {
  27. global $feedback_type;
  28. if (empty($id)) {
  29. echo '<tr><td>'. nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)).'</td></tr>';
  30. } else {
  31. ?>
  32. <tr>
  33. <td>
  34. <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
  35. </td>
  36. <?php
  37. if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
  38. <td>
  39. <?php
  40. $comm = get_comments($id,$questionId);
  41. ?>
  42. </td>
  43. <?php } ?>
  44. </tr>
  45. <?php
  46. }
  47. }
  48. /**
  49. * Shows the answer to a free-answer question, as HTML
  50. * @param string Answer text
  51. * @param int Exercise ID
  52. * @param int Question ID
  53. * @return void
  54. */
  55. function display_free_answer($answer,$id,$questionId) {
  56. global $feedback_type;
  57. if (empty($id)) {
  58. if (!empty($answer)) {
  59. echo '<tr>';
  60. echo Display::tag('td',nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)), array('width'=>'55%'));
  61. echo '</tr>';
  62. }
  63. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  64. echo '<tr>';
  65. echo Display::tag('td',get_lang('notCorrectedYet'), array('width'=>'45%'));
  66. echo '</tr>';
  67. } else {
  68. echo '<tr><td>&nbsp;</td></tr>';
  69. }
  70. } else {
  71. echo '<tr>';
  72. if (!empty($answer)) {
  73. echo '<td>';
  74. echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY));
  75. echo '</td>';
  76. }
  77. if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  78. echo '<td>';
  79. $comm = get_comments($id,$questionId);
  80. echo '</td>';
  81. }
  82. echo '</tr>';
  83. }
  84. }
  85. /**
  86. * Displays the answer to a hotspot question
  87. *
  88. * @param int $answerId
  89. * @param string $answer
  90. * @param string $studentChoice
  91. * @param string $answerComment
  92. */
  93. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment) {
  94. global $feedback_type;
  95. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  96. "#4271B5",
  97. "#FE8E16",
  98. "#45C7F0",
  99. "#BCD631",
  100. "#D63173",
  101. "#D7D7D7",
  102. "#90AFDD",
  103. "#AF8640",
  104. "#4F9242",
  105. "#F4EB24",
  106. "#ED2024",
  107. "#3B3B3B",
  108. "#F7BDE2");
  109. ?>
  110. <table class="data_table">
  111. <tr>
  112. <td width="100px" valign="top" align="left">
  113. <div style="width:100%;">
  114. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  115. <div style="float:left; padding-left:5px;">
  116. <?php echo $answerId; ?>
  117. </div>
  118. <div><?php echo '&nbsp;'.$answer ?></div>
  119. </div>
  120. </td>
  121. <td width="50px" style="padding-right:15px" valign="top" align="left">
  122. <?php
  123. $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
  124. echo $my_choice;
  125. ?>
  126. </td>
  127. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  128. <td valign="top" align="left" >
  129. <?php
  130. if($studentChoice) {
  131. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  132. } else {
  133. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  134. }
  135. ?>
  136. </td>
  137. <?php } else { ?>
  138. <td>&nbsp;</td>
  139. <?php } ?>
  140. </tr>
  141. <?php
  142. }
  143. /**
  144. * Display the answers to a multiple choice question
  145. *
  146. * @param integer Answer type
  147. * @param integer Student choice
  148. * @param string Textual answer
  149. * @param string Comment on answer
  150. * @param string Correct answer comment
  151. * @param integer Exercise ID
  152. * @param integer Question ID
  153. * @param boolean Whether to show the answer comment or not
  154. * @return void
  155. */
  156. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  157. global $feedback_type;
  158. ?>
  159. <tr>
  160. <td width="5%" align="center">
  161. <img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  162. border="0" alt="" />
  163. </td>
  164. <td width="5%" align="center">
  165. <img src="../img/<?php echo (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION))) ? 'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  166. border="0" alt=" " />
  167. </td>
  168. <td width="40%" style="border-bottom: 1px solid #4171B5;">
  169. <?php
  170. echo $answer;
  171. ?>
  172. </td>
  173. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  174. <td width="20%" style="border-bottom: 1px solid #4171B5;">
  175. <?php
  176. if ($studentChoice) {
  177. if($answerCorrect) {
  178. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  179. } else {
  180. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  181. }
  182. } else {
  183. if($answerCorrect) {
  184. echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  185. } else {
  186. echo '<span style="font-weight: normal; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  187. }
  188. }
  189. ?>
  190. </td>
  191. <?php
  192. if ($ans==1) {
  193. $comm = get_comments($id,$questionId);
  194. }
  195. ?>
  196. <?php } else { ?>
  197. <td>&nbsp;</td>
  198. <?php } ?>
  199. </tr>
  200. <?php
  201. }
  202. /**
  203. * Display the answers to a multiple choice question
  204. *
  205. * @param integer Answer type
  206. * @param integer Student choice
  207. * @param string Textual answer
  208. * @param string Comment on answer
  209. * @param string Correct answer comment
  210. * @param integer Exercise ID
  211. * @param integer Question ID
  212. * @param boolean Whether to show the answer comment or not
  213. * @return void
  214. */
  215. function display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  216. global $feedback_type;
  217. ?>
  218. <tr>
  219. <td width="5%" align="center">
  220. <?php
  221. $question = new MultipleAnswerTrueFalse();
  222. $course_id = api_get_course_int_id();
  223. $new_options = Question::readQuestionOption($questionId, $course_id);
  224. //Your choice
  225. if (isset($new_options[$studentChoice])) {
  226. echo get_lang($new_options[$studentChoice]['name']);
  227. } else {
  228. echo '-';
  229. }
  230. ?>
  231. </td>
  232. <td width="5%" align="center">
  233. <?php
  234. //Expected choice
  235. if (isset($new_options[$answerCorrect])) {
  236. echo get_lang($new_options[$answerCorrect]['name']);
  237. } else {
  238. echo '-';
  239. }
  240. ?>
  241. </td>
  242. <td width="40%" style="border-bottom: 1px solid #4171B5;">
  243. <?php echo $answer; ?>
  244. </td>
  245. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  246. <td width="20%" style="border-bottom: 1px solid #4171B5;">
  247. <?php
  248. //@todo replace this harcoded value
  249. if ($studentChoice == 3 || $studentChoice == '') {
  250. echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  251. } else {
  252. if ($studentChoice == $answerCorrect) {
  253. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  254. } else {
  255. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  256. }
  257. }
  258. ?>
  259. </td>
  260. <?php
  261. if ($ans==1) {
  262. $comm = get_comments($id, $questionId);
  263. }
  264. ?>
  265. <?php } else { ?>
  266. <td>&nbsp;</td>
  267. <?php } ?>
  268. </tr>
  269. <?php
  270. }
  271. /**
  272. * Display the answers to a multiple choice question
  273. *
  274. * @param integer Answer type
  275. * @param integer Student choice
  276. * @param string Textual answer
  277. * @param string Comment on answer
  278. * @param string Correct answer comment
  279. * @param integer Exercise ID
  280. * @param integer Question ID
  281. * @param boolean Whether to show the answer comment or not
  282. * @return void
  283. */
  284. function display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  285. global $feedback_type;
  286. ?>
  287. <tr>
  288. <td width="5%" align="center">
  289. <?php
  290. //Your choice
  291. $question = new MultipleAnswerCombinationTrueFalse();
  292. if (isset($question->options[$studentChoice])) {
  293. echo $question->options[$studentChoice];
  294. } else {
  295. echo $question->options[2];
  296. }
  297. ?>
  298. </td>
  299. <td width="5%" align="center">
  300. <?php
  301. //Expected choice
  302. if (isset($question->options[$answerCorrect])) {
  303. echo $question->options[$answerCorrect];
  304. } else {
  305. echo $question->options[2];
  306. }
  307. ?>
  308. </td>
  309. <td width="40%" style="border-bottom: 1px solid #4171B5;">
  310. <?php
  311. //my answer
  312. echo $answer;
  313. ?>
  314. </td>
  315. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  316. <td width="20%" style="border-bottom: 1px solid #4171B5;">
  317. <?php
  318. //@todo replace this harcoded value
  319. if ($studentChoice == 2 || $studentChoice == '') {
  320. echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  321. } else {
  322. if ($studentChoice == $answerCorrect) {
  323. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  324. } else {
  325. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  326. }
  327. }
  328. ?>
  329. </td>
  330. <?php
  331. if ($ans==1) {
  332. $comm = get_comments($id,$questionId);
  333. }
  334. ?>
  335. <?php } else { ?>
  336. <td>&nbsp;</td>
  337. <?php } ?>
  338. </tr>
  339. <?php
  340. }
  341. }