exercise_show_functions.lib.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. /**
  21. * Shows the answer to a fill-in-the-blanks question, as HTML
  22. * @param string Answer text
  23. * @param int Exercise ID
  24. * @param int Question ID
  25. * @return void
  26. */
  27. static function display_fill_in_blanks_answer($feedback_type, $answer, $id, $questionId)
  28. {
  29. if (empty($id)) {
  30. echo '<tr><td>'. (Security::remove_XSS($answer)).'</td></tr>';
  31. } else {
  32. ?>
  33. <tr>
  34. <td>
  35. <?php
  36. echo (Security::remove_XSS($answer));
  37. ?>
  38. </td>
  39. <?php
  40. if (!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  41. <td>
  42. <?php
  43. $comm = get_comments($id,$questionId);
  44. ?>
  45. </td>
  46. <?php } ?>
  47. </tr>
  48. <?php
  49. }
  50. }
  51. /**
  52. * Shows the answer to a free-answer question, as HTML
  53. * @param string Answer text
  54. * @param int Exercise ID
  55. * @param int Question ID
  56. * @return void
  57. */
  58. static function display_free_answer($feedback_type, $answer, $exe_id, $questionId, $questionScore = null)
  59. {
  60. $comments = get_comments($exe_id, $questionId);
  61. if (!empty($answer)) {
  62. echo '<tr><td>';
  63. echo nl2br(Security::remove_XSS($answer, COURSEMANAGERLOWSECURITY));
  64. echo '</td></tr>';
  65. }
  66. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  67. if ($questionScore > 0 || !empty($comments)) {
  68. } else {
  69. echo '<tr>';
  70. echo Display::tag('td', Display::return_message(get_lang('notCorrectedYet')), array());
  71. echo '</tr>';
  72. }
  73. }
  74. }
  75. static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $nano = null)
  76. {
  77. if (isset($nano)) {
  78. echo $nano->show_audio_file();
  79. }
  80. if (empty($id)) {
  81. echo '<tr>';
  82. echo Display::tag('td',nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)), array('width'=>'55%'));
  83. echo '</tr>';
  84. if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  85. echo '<tr>';
  86. echo Display::tag('td',get_lang('notCorrectedYet'), array('width'=>'45%'));
  87. echo '</tr>';
  88. } else {
  89. echo '<tr><td>&nbsp;</td></tr>';
  90. }
  91. } else {
  92. echo '<tr>';
  93. echo '<td>';
  94. if (!empty($answer)) {
  95. echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY));
  96. }
  97. echo '</td>';
  98. if (!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
  99. echo '<td>';
  100. $comm = get_comments($id,$questionId);
  101. echo '</td>';
  102. }
  103. echo '</tr>';
  104. }
  105. }
  106. /**
  107. * Displays the answer to a hotspot question
  108. *
  109. * @param int $answerId
  110. * @param string $answer
  111. * @param string $studentChoice
  112. * @param string $answerComment
  113. */
  114. static function display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment)
  115. {
  116. $hotspot_colors = array(
  117. "", // $i starts from 1 on next loop (ugly fix)
  118. "#4271B5",
  119. "#FE8E16",
  120. "#45C7F0",
  121. "#BCD631",
  122. "#D63173",
  123. "#D7D7D7",
  124. "#90AFDD",
  125. "#AF8640",
  126. "#4F9242",
  127. "#F4EB24",
  128. "#ED2024",
  129. "#3B3B3B",
  130. "#F7BDE2");
  131. ?>
  132. <table class="data_table">
  133. <tr>
  134. <td width="100px" valign="top" align="left">
  135. <div style="width:100%;">
  136. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  137. <div style="float:left; padding-left:5px;">
  138. <?php echo $answerId; ?>
  139. </div>
  140. <div><?php echo '&nbsp;'.$answer ?></div>
  141. </div>
  142. </td>
  143. <td width="50px" style="padding-right:15px" valign="top" align="left">
  144. <?php
  145. $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
  146. echo $my_choice;
  147. ?>
  148. </td>
  149. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  150. <td valign="top" align="left" >
  151. <?php
  152. if ($studentChoice) {
  153. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  154. } else {
  155. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  156. }
  157. ?>
  158. </td>
  159. <?php } else { ?>
  160. <td>&nbsp;</td>
  161. <?php } ?>
  162. </tr>
  163. <?php
  164. }
  165. /**
  166. * Display the answers to a multiple choice question
  167. *
  168. * @param integer Answer type
  169. * @param integer Student choice
  170. * @param string Textual answer
  171. * @param string Comment on answer
  172. * @param string Correct answer comment
  173. * @param integer Exercise ID
  174. * @param integer Question ID
  175. * @param boolean Whether to show the answer comment or not
  176. * @return void
  177. */
  178. static function display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
  179. {
  180. $imageType = (in_array($answerType, array(UNIQUE_ANSWER,UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) ? 'radio' : 'checkbox';
  181. $image = $imageType.($studentChoice ? '_on' : '_off');
  182. $image .= '.gif';
  183. $imageAnswer = $imageType.($answerCorrect ? '_on' : '_off');
  184. $imageAnswer .= '.gif';
  185. ?>
  186. <tr>
  187. <td width="5%">
  188. <?php Display::display_icon($image); ?>
  189. </td>
  190. <td width="5%">
  191. <?php Display::display_icon($imageAnswer); ?>
  192. </td>
  193. <td width="40%">
  194. <?php
  195. echo $answer;
  196. ?>
  197. </td>
  198. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  199. <td width="20%">
  200. <?php
  201. if ($studentChoice) {
  202. if ($answerCorrect) {
  203. $color = 'green';
  204. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  205. } else {
  206. $color = 'black';
  207. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  208. }
  209. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  210. } else {
  211. if ($answerCorrect) {
  212. //echo '<span style="font-weight: bold; color: #000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  213. } else {
  214. //echo '<span style="font-weight: normal; color: #000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  215. }
  216. }
  217. ?>
  218. </td>
  219. <?php
  220. if ($ans==1) {
  221. $comm = get_comments($id,$questionId);
  222. }
  223. ?>
  224. <?php } else { ?>
  225. <td>&nbsp;</td>
  226. <?php } ?>
  227. </tr>
  228. <?php
  229. }
  230. /** @todo check if this function is used */
  231. static function display_unique_image_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
  232. {
  233. global $feedback_type;
  234. $imageType = (in_array($answerType, array(UNIQUE_ANSWER,UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) ? 'radio' : 'checkbox';
  235. $image = $imageType.($studentChoice ? '_on' : '_off');
  236. $image .= '.gif';
  237. $imageAnswer = $imageType.($answerCorrect ? '_on' : '_off');
  238. $imageAnswer .= '.gif';
  239. ?>
  240. <tr>
  241. <tr>
  242. <td width="5%">
  243. <?php Display::display_icon($image); ?>
  244. </td>
  245. <td width="5%">
  246. <?php Display::display_icon($imageAnswer); ?>
  247. </td>
  248. <td width="40%">
  249. <?php
  250. echo $answer;
  251. ?>
  252. </td>
  253. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  254. <td width="20%">
  255. <?php
  256. if ($studentChoice) {
  257. if ($answerCorrect) {
  258. $color = 'green';
  259. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  260. } else {
  261. $color = 'black';
  262. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  263. }
  264. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  265. } else {
  266. if ($answerCorrect) {
  267. //echo '<span style="font-weight: bold; color: #000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  268. } else {
  269. //echo '<span style="font-weight: normal; color: #000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  270. }
  271. }
  272. ?>
  273. </td>
  274. <?php
  275. if ($ans==1) {
  276. $comm = get_comments($id,$questionId);
  277. }
  278. ?>
  279. <?php } else { ?>
  280. <td>&nbsp;</td>
  281. <?php } ?>
  282. </tr>
  283. <?php
  284. }
  285. /**
  286. * Display the answers to a multiple choice question
  287. *
  288. * @param integer Answer type
  289. * @param integer Student choice
  290. * @param string Textual answer
  291. * @param string Comment on answer
  292. * @param string Correct answer comment
  293. * @param integer Exercise ID
  294. * @param integer Question ID
  295. * @param boolean Whether to show the answer comment or not
  296. * @return void
  297. */
  298. static function display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  299. ?>
  300. <tr>
  301. <td width="5%">
  302. <?php
  303. $question = new MultipleAnswerTrueFalse();
  304. $course_id = api_get_course_int_id();
  305. $new_options = Question::readQuestionOption($questionId, $course_id);
  306. //Your choice
  307. if (isset($new_options[$studentChoice])) {
  308. echo get_lang($new_options[$studentChoice]['name']);
  309. } else {
  310. echo '-';
  311. }
  312. ?>
  313. </td>
  314. <td width="5%">
  315. <?php
  316. //Expected choice
  317. if (isset($new_options[$answerCorrect])) {
  318. echo get_lang($new_options[$answerCorrect]['name']);
  319. } else {
  320. echo '-';
  321. }
  322. ?>
  323. </td>
  324. <td width="40%">
  325. <?php echo $answer; ?>
  326. </td>
  327. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  328. <td width="20%">
  329. <?php
  330. $color = "black";
  331. if (isset($new_options[$studentChoice])) {
  332. if ($studentChoice == $answerCorrect) {
  333. $color = "green";
  334. }
  335. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  336. }
  337. ?>
  338. </td>
  339. <?php
  340. if ($ans==1) {
  341. $comm = get_comments($id, $questionId);
  342. }
  343. ?>
  344. <?php } else { ?>
  345. <td>&nbsp;</td>
  346. <?php } ?>
  347. </tr>
  348. <?php
  349. }
  350. /**
  351. * Display the answers to a multiple choice question
  352. *
  353. * @param integer Answer type
  354. * @param integer Student choice
  355. * @param string Textual answer
  356. * @param string Comment on answer
  357. * @param string Correct answer comment
  358. * @param integer Exercise ID
  359. * @param integer Question ID
  360. * @param boolean Whether to show the answer comment or not
  361. * @return void
  362. */
  363. static function display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
  364. ?>
  365. <tr>
  366. <td width="5%">
  367. <?php
  368. //Your choice
  369. $question = new MultipleAnswerCombinationTrueFalse();
  370. if (isset($question->options[$studentChoice])) {
  371. echo $question->options[$studentChoice];
  372. } else {
  373. echo $question->options[2];
  374. }
  375. ?>
  376. </td>
  377. <td width="5%">
  378. <?php
  379. //Expected choice
  380. if (isset($question->options[$answerCorrect])) {
  381. echo $question->options[$answerCorrect];
  382. } else {
  383. echo $question->options[2];
  384. }
  385. ?>
  386. </td>
  387. <td width="40%">
  388. <?php
  389. //my answer
  390. echo $answer;
  391. ?>
  392. </td>
  393. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  394. <td width="20%">
  395. <?php
  396. //@todo replace this harcoded value
  397. if ($studentChoice) {
  398. $color = "black";
  399. if ($studentChoice == $answerCorrect) {
  400. $color = "green";
  401. }
  402. echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  403. }
  404. if ($studentChoice == 2 || $studentChoice == '') {
  405. //echo '<span style="font-weight: bold; color: #000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  406. } else {
  407. if ($studentChoice == $answerCorrect) {
  408. //echo '<span style="font-weight: bold; color: #008000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  409. } else {
  410. //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(Text::make_clickable($answerComment)).'</span>';
  411. }
  412. }
  413. ?>
  414. </td>
  415. <?php
  416. if ($ans==1) {
  417. $comm = get_comments($id,$questionId);
  418. }
  419. ?>
  420. <?php } else { ?>
  421. <td>&nbsp;</td>
  422. <?php } ?>
  423. </tr>
  424. <?php
  425. }
  426. }