exercise_show_functions.lib.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. static 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. static 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. static 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. static 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. static 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%">
  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%">
  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%">
  200. <?php
  201. echo $answer;
  202. ?>
  203. </td>
  204. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  205. <td width="20%">
  206. <?php
  207. if ($studentChoice) {
  208. if ($answerCorrect) {
  209. $color = 'green';
  210. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  211. } else {
  212. $color = 'black';
  213. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  214. }
  215. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
  216. } else {
  217. if ($answerCorrect) {
  218. //echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  219. } else {
  220. //echo '<span style="font-weight: normal; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  221. }
  222. }
  223. ?>
  224. </td>
  225. <?php
  226. if ($ans==1) {
  227. $comm = get_comments($id,$questionId);
  228. }
  229. ?>
  230. <?php } else { ?>
  231. <td>&nbsp;</td>
  232. <?php } ?>
  233. </tr>
  234. <?php
  235. }
  236. /**
  237. * Display the answers to a multiple choice question
  238. *
  239. * @param integer Answer type
  240. * @param integer Student choice
  241. * @param string Textual answer
  242. * @param string Comment on answer
  243. * @param string Correct answer comment
  244. * @param integer Exercise ID
  245. * @param integer Question ID
  246. * @param boolean Whether to show the answer comment or not
  247. * @return void
  248. */
  249. static function display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  250. global $feedback_type;
  251. ?>
  252. <tr>
  253. <td width="5%">
  254. <?php
  255. $question = new MultipleAnswerTrueFalse();
  256. $course_id = api_get_course_int_id();
  257. $new_options = Question::readQuestionOption($questionId, $course_id);
  258. //Your choice
  259. if (isset($new_options[$studentChoice])) {
  260. echo get_lang($new_options[$studentChoice]['name']);
  261. } else {
  262. echo '-';
  263. }
  264. ?>
  265. </td>
  266. <td width="5%">
  267. <?php
  268. //Expected choice
  269. if (isset($new_options[$answerCorrect])) {
  270. echo get_lang($new_options[$answerCorrect]['name']);
  271. } else {
  272. echo '-';
  273. }
  274. ?>
  275. </td>
  276. <td width="40%">
  277. <?php echo $answer; ?>
  278. </td>
  279. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  280. <td width="20%">
  281. <?php
  282. $color = "black";
  283. if (isset($new_options[$studentChoice])) {
  284. if ($studentChoice == $answerCorrect) {
  285. $color = "green";
  286. }
  287. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
  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. static 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%">
  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%">
  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%">
  341. <?php
  342. //my answer
  343. echo $answer;
  344. ?>
  345. </td>
  346. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  347. <td width="20%">
  348. <?php
  349. //@todo replace this harcoded value
  350. if ($studentChoice) {
  351. $color = "black";
  352. if ($studentChoice == $answerCorrect) {
  353. $color = "green";
  354. }
  355. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
  356. }
  357. if ($studentChoice == 2 || $studentChoice == '') {
  358. //echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
  359. } else {
  360. if ($studentChoice == $answerCorrect) {
  361. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  362. } else {
  363. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  364. }
  365. }
  366. ?>
  367. </td>
  368. <?php
  369. if ($ans==1) {
  370. $comm = get_comments($id,$questionId);
  371. }
  372. ?>
  373. <?php } else { ?>
  374. <td>&nbsp;</td>
  375. <?php } ?>
  376. </tr>
  377. <?php
  378. }
  379. }