exercise_show_functions.lib.php 12 KB

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