exercise_show_functions.lib.php 11 KB

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