exercise.lib.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise library
  5. * shows a question and its answers
  6. * @package dokeos.exercise
  7. * @author Olivier Brouckaert <oli.brouckaert@skynet.be>
  8. * @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $
  9. */
  10. // The initialization class for the online editor is needed here.
  11. require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
  12. /**
  13. * Shows a question
  14. *
  15. * @param int question id
  16. * @param bool only answers
  17. * @param bool origin i.e = learnpath
  18. * @param int current item from the list of questions
  19. * @param int number of total questions
  20. * */
  21. function showQuestion($questionId, $onlyAnswers = false, $origin = false, $current_item = '', $show_title = true, $freeze = false) {
  22. // Text direction for the current language
  23. $is_ltr_text_direction = api_get_text_direction() != 'rtl';
  24. // Change false to true in the following line to enable answer hinting.
  25. $debug_mark_answer = api_is_allowed_to_edit() && false;
  26. // Reads question informations.
  27. if (!$objQuestionTmp = Question::read($questionId)) {
  28. // question not found
  29. return false;
  30. }
  31. $answerType = $objQuestionTmp->selectType();
  32. $pictureName = $objQuestionTmp->selectPicture();
  33. if ($answerType != HOT_SPOT) {
  34. // Question is not of type hotspot
  35. if (!$onlyAnswers) {
  36. $questionName=$objQuestionTmp->selectTitle();
  37. $questionDescription=$objQuestionTmp->selectDescription();
  38. $questionName=text_filter($questionName);
  39. if ($show_title) {
  40. $s='<div id="question_title" class="sectiontitle">'.get_lang('Question').' ';
  41. $s.=$current_item;
  42. //@todo I need the get the feedback type
  43. //if($answerType != 1)
  44. //$s.=' / '.$total_item;
  45. echo $s;
  46. echo ' : ';
  47. echo $questionName.'</div>';
  48. }
  49. $s='';
  50. $s.='<table class="exercise_questions" style="margin:4px 4px 4px 0px; padding:2px;">
  51. <tr><td valign="top" colspan="2">';
  52. $questionDescription=text_filter($questionDescription);
  53. $s.=$questionDescription;
  54. $s.='</td></tr></table>';
  55. if (!empty($pictureName)) {
  56. $s.="<tr>
  57. <td align='center' colspan='2'><img src='../document/download.php?doc_url=%2Fimages%2F'".$pictureName."' border='0'></td>
  58. </tr>";
  59. }
  60. }
  61. $s.= '</table>';
  62. $s .= '<div class="rounded exercise_questions" style="width: 720px; padding: 3px;">';
  63. $option_ie = '';
  64. /*
  65. if (!ereg("MSIE",$_SERVER["HTTP_USER_AGENT"])) {
  66. $s .= '<div class="rounded exercise_questions" style="width: 720px; padding: 3px;">';
  67. } else {
  68. $option_ie="margin-left:10px";
  69. }*/
  70. if ($answerType == FREE_ANSWER && $freeze) {
  71. return '';
  72. }
  73. $s .= '<table width="720" class="exercise_options" style="width: 720px;'.$option_ie.' background-color:#fff;">';
  74. // construction of the Answer object (also gets all answers details)
  75. $objAnswerTmp=new Answer($questionId);
  76. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  77. $quiz_question_options = Question::readQuestionOption($questionId);
  78. // For "matching" type here, we need something a little bit special
  79. // because the match between the suggestions and the answers cannot be
  80. // done easily (suggestions and answers are in the same table), so we
  81. // have to go through answers first (elems with "correct" value to 0).
  82. $select_items = array();
  83. //This will contain the number of answers on the left side. We call them
  84. // suggestions here, for the sake of comprehensions, while the ones
  85. // on the right side are called answers
  86. $num_suggestions = 0;
  87. if ($answerType == MATCHING) {
  88. $x = 1; //iterate through answers
  89. $letter = 'A'; //mark letters for each answer
  90. $answer_matching = $cpt1 = array();
  91. $answer_suggestions = $nbrAnswers;
  92. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  93. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  94. $numAnswer = $objAnswerTmp->selectAutoId($answerId);
  95. $answer=$objAnswerTmp->selectAnswer($answerId);
  96. if ($answerCorrect==0) {
  97. // options (A, B, C, ...) that will be put into the list-box
  98. // have the "correct" field set to 0 because they are answer
  99. $cpt1[$x] = $letter;
  100. $answer_matching[$x]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
  101. $x++; $letter++;
  102. }
  103. }
  104. $i = 1;
  105. foreach ($answer_matching as $id => $value) {
  106. $select_items[$i]['id'] = $value['id'];
  107. $select_items[$i]['letter'] = $cpt1[$id];
  108. $select_items[$i]['answer'] = $value['answer'];
  109. $i ++;
  110. }
  111. $num_suggestions = ($nbrAnswers - $x) + 1;
  112. } elseif ($answerType == FREE_ANSWER) {
  113. $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
  114. $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
  115. $oFCKeditor->Width = '100%';
  116. $oFCKeditor->Height = '200';
  117. $oFCKeditor->Value = '' ;
  118. $s .= '<tr><td colspan="3">';
  119. $s .= $oFCKeditor->CreateHtml();
  120. $s .= '</td></tr>';
  121. }
  122. ?>
  123. <style>
  124. #questions {
  125. width:40%;
  126. height:50px;
  127. float:left;
  128. padding:5px;
  129. }
  130. #options {
  131. width:40%;
  132. float:left;
  133. padding:5px;
  134. }
  135. .question_item {
  136. height:50px;
  137. padding:5px;
  138. margin:10px 0px 10px 0px;
  139. }
  140. .option_item {
  141. width:150px;
  142. padding:3px;
  143. margin:10px;
  144. }
  145. </style>
  146. <script>
  147. $(function() {
  148. var $options = $( "#options" );
  149. $( "div", $options ).draggable({
  150. revert: "invalid", // when not dropped, the item will revert back to its initial position
  151. cursor: "move",
  152. });
  153. var $question_1 = $( "#question_1" );
  154. $question_1.droppable({
  155. accept: "#options div",
  156. activeClass: "ui-state-hover",
  157. hoverClass: "ui-state-active",
  158. drop: function( event, ui ) {
  159. //$( this ).addClass( "ui-state-highlight" );
  160. }
  161. });
  162. var $question_2 = $( "#question_2" );
  163. $question_2.droppable({
  164. accept: "#options div",
  165. hoverClass: "ui-state-active",
  166. drop: function( event, ui ) {
  167. //$( this ).addClass( "ui-state-highlight" );
  168. }
  169. });
  170. $options.droppable({
  171. accept: "#options div",
  172. hoverClass: "ui-state-active",
  173. drop: function( event, ui ) {
  174. }
  175. });
  176. });
  177. </script>
  178. <?php
  179. // Now navigate through the possible answers, using the max number of
  180. // answers for the question as a limiter
  181. $lines_count=1; // a counter for matching-type answers
  182. $question_list = array();
  183. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  184. $header .= Display::tag('th', get_lang('Options'));
  185. foreach ($objQuestionTmp->options as $key=>$item) {
  186. $header .= Display::tag('th', $item);
  187. }
  188. $s.=Display::tag('tr',$header);
  189. }
  190. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  191. $answer = $objAnswerTmp->selectAnswer($answerId);
  192. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  193. $numAnswer = $objAnswerTmp->selectAutoId($answerId);
  194. if ($answerType == FILL_IN_BLANKS) {
  195. // splits text and weightings that are joined with the character '::'
  196. list($answer) = explode('::',$answer);
  197. // because [] is parsed here we follow this procedure:
  198. $answer = text_filter($answer);
  199. //getting the matches
  200. $answer = api_ereg_replace('\[[^]]+\]','<input type="text" name="choice['.$questionId.'][]" size="10" />',($answer));
  201. }
  202. // Unique answer
  203. if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
  204. // set $debug_mark_answer to true at function start to
  205. // show the correct answer with a suffix '-x'
  206. $help = $selected = '';
  207. if ($debug_mark_answer) {
  208. if ($answerCorrect) {
  209. $help = 'x-';
  210. $selected = 'checked';
  211. }
  212. }
  213. $answer = text_filter($answer);
  214. $answer = Security::remove_XSS($answer, STUDENT);
  215. $s .= Display::input('hidden','choice2['.$questionId.']','0').
  216. '<tr><td colspan="3"><div class="u-m-answer"><p style="float: '.($is_ltr_text_direction ? 'left' : 'right').'; padding-'.($is_ltr_text_direction ? 'right' : 'left').': 4px;">'.
  217. '<span>'.Display::input('radio','choice['.$questionId.']', $numAnswer, array('class'=>'checkbox','selected'=>$selected)).'</span></p>'.
  218. '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  219. $answer.
  220. '</div></div></td></tr>';
  221. } elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  222. // multiple answers
  223. // set $debug_mark_answer to true at function start to
  224. // show the correct answer with a suffix '-x'
  225. $help = $selected = '';
  226. if ($debug_mark_answer) {
  227. if ($answerCorrect) {
  228. $help = 'x-';
  229. $selected = 'checked="checked"';
  230. }
  231. }
  232. $answer = text_filter($answer);
  233. $answer = Security::remove_XSS($answer, STUDENT);
  234. if ($answerType == MULTIPLE_ANSWER) {
  235. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
  236. $s .= '<tr><td colspan="3"><div class="u-m-answer"><p style="float: '.($is_ltr_text_direction ? 'left' : 'right').'; padding-'.($is_ltr_text_direction ? 'right' : 'left').': 4px;">';
  237. $options = array('type'=>'checkbox','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  238. if ($answerCorrect) {
  239. $options['checked'] = 'checked';
  240. }
  241. $s .= Display::tag('span', Display::tag('input','',$options ));
  242. $s .= '</p>';
  243. $s .= '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  244. $answer.
  245. '</div></div></td></tr>';
  246. } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  247. $options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  248. $s .='<tr>';
  249. $s .= Display::tag('td', $answer);
  250. if (!empty($quiz_question_options)) {
  251. foreach ($quiz_question_options as $id=>$item) {
  252. $options['value'] = $id;
  253. $s .= Display::tag('td', Display::tag('input','',$options ));
  254. }
  255. }
  256. $s.='<tr>';
  257. }
  258. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
  259. // multiple answers
  260. // set $debug_mark_answer to true at function start to
  261. // show the correct answer with a suffix '-x'
  262. $help = $selected = '';
  263. if ($debug_mark_answer) {
  264. if ($answerCorrect) {
  265. $help = 'x-';
  266. $selected = 'checked="checked"';
  267. }
  268. }
  269. $answer = text_filter($answer);
  270. $answer = Security::remove_XSS($answer, STUDENT);
  271. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'.
  272. '<tr><td colspan="3"><div class="u-m-answer"><p style="float: '.($is_ltr_text_direction ? 'left' : 'right').'; padding-'.($is_ltr_text_direction ? 'right' : 'left').': 4px;">'.
  273. '<span><input class="checkbox" type="checkbox" name="choice['.$questionId.']['.$numAnswer.']" value="1" '.$selected.' /></span></p>'.
  274. '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  275. $answer.
  276. '</div></div></td></tr>';
  277. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  278. // multiple answers
  279. // set $debug_mark_answer to true at function start to
  280. // show the correct answer with a suffix '-x'
  281. $help = $selected = '';
  282. if ($debug_mark_answer) {
  283. if ($answerCorrect) {
  284. $help = 'x-';
  285. $selected = 'checked="checked"';
  286. }
  287. }
  288. $answer = text_filter($answer);
  289. $answer = Security::remove_XSS($answer, STUDENT);
  290. $options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  291. $s .='<tr>';
  292. $s .= Display::tag('td', $answer);
  293. foreach ($objQuestionTmp->options as $key=>$item) {
  294. $options['value'] = $key;
  295. $s .= Display::tag('td', Display::tag('input','',$options ));
  296. }
  297. $s.='<tr>';
  298. } elseif ($answerType == FILL_IN_BLANKS) {
  299. // fill in blanks
  300. $s .= '<tr><td colspan="3">'.$answer.'</td></tr>';
  301. } else {
  302. // matching type, showing suggestions and answers
  303. // TODO: replace $answerId by $numAnswer
  304. if ($answerCorrect != 0) {
  305. // only show elements to be answered (not the contents of
  306. // the select boxes, who are corrrect = 0)
  307. $s .= '<tr><td width="45%" valign="top" >';
  308. $parsed_answer = text_filter($answer);
  309. $question_list[] = $parsed_answer;
  310. //left part questions
  311. $s .= ' <span style="float:left; width:8%;"><b>'.$lines_count.'</b>.&nbsp;</span>
  312. <span style="float:left; width:92%;">'.$parsed_answer.'</span></td>';
  313. //middle part (matches selects)
  314. $s .= '<td width="10%" valign="top" align="center">&nbsp;&nbsp;
  315. <select name="choice['.$questionId.']['.$numAnswer.']">
  316. <option value="0">--</option>';
  317. // fills the list-box
  318. foreach ($select_items as $key=>$val) {
  319. // set $debug_mark_answer to true at function start to
  320. // show the correct answer with a suffix '-x'
  321. $help = $selected = '';
  322. if ($debug_mark_answer) {
  323. if ($val['id'] == $answerCorrect) {
  324. $help = '-x';
  325. $selected = 'selected="selected"';
  326. }
  327. }
  328. $s.='<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].$help.'</option>';
  329. } // end foreach()
  330. $s .= '</select>&nbsp;&nbsp;</td>';
  331. //print_r($select_items);
  332. //right part (answers)
  333. $s.='<td width="45%" valign="top" >';
  334. if (isset($select_items[$lines_count])) {
  335. $s.='<span style="float:left; width:5%;"><b>'.$select_items[$lines_count]['letter'].'.</b></span>'.
  336. '<span style="float:left; width:95%;">'.$select_items[$lines_count]['answer'].'</span>';
  337. } else {
  338. $s.='&nbsp;';
  339. }
  340. $s .= '</td>';
  341. $s .= '</tr>';
  342. $lines_count++;
  343. //if the left side of the "matching" has been completely
  344. // shown but the right side still has values to show...
  345. if (($lines_count -1) == $num_suggestions) {
  346. // if it remains answers to shown at the right side
  347. while (isset($select_items[$lines_count])) {
  348. $s .= '<tr>
  349. <td colspan="2">&nbsp;</td>
  350. <td valign="top">';
  351. $s.='<b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'];
  352. $s.="</td>
  353. </tr>";
  354. $lines_count++;
  355. } // end while()
  356. } // end if()
  357. }
  358. }
  359. } // end for()
  360. //Adding divs for the new MATCHING interface
  361. if ($answerType == MATCHING && !$freeze) {
  362. echo '<div id="questions">';
  363. echo Display::tag('h2','Questions');
  364. $i = 1;
  365. foreach ($question_list as $key=>$val) {
  366. echo Display::tag('div', Display::tag('p',$val), array('id'=>'question_'.$i, 'class'=>'question_item ui-widget-header'));
  367. $i++;
  368. }
  369. echo '</div>';
  370. echo Display::tag('h2','Options');
  371. echo '<div id="options" class=" ui-widget-header">';
  372. foreach ($select_items as $key=>$val) {
  373. echo Display::tag('div', Display::tag('p',$val['answer']), array('id'=>'option_'.$i, 'class'=>'option_item ui-widget-content'));
  374. }
  375. echo '</ul>';
  376. }
  377. $s .= '</table>';
  378. $s .= '</div><br />';
  379. // destruction of the Answer object
  380. unset($objAnswerTmp);
  381. // destruction of the Question object
  382. unset($objQuestionTmp);
  383. if ($origin != 'export') {
  384. echo $s;
  385. } else {
  386. return($s);
  387. }
  388. } elseif ($answerType == HOT_SPOT) {
  389. // Question is of type HOT_SPOT
  390. //checking document/images visibility
  391. if (api_is_platform_admin() || api_is_course_admin()) {
  392. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  393. $course = api_get_course_info();
  394. $doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName);
  395. if (is_numeric($doc_id)) {
  396. $images_folder_visibility = api_get_item_visibility($course,'document', $doc_id, api_get_session_id());
  397. if (!$images_folder_visibility) {
  398. //This message is shown only to the course/platform admin if the image is set to visibility = false
  399. Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage'));
  400. }
  401. }
  402. }
  403. $questionName = $objQuestionTmp->selectTitle();
  404. $questionDescription = $objQuestionTmp->selectDescription();
  405. if ($freeze) {
  406. echo Display::img($objQuestionTmp->selectPicturePath());
  407. exit;
  408. }
  409. // Get the answers, make a list
  410. $objAnswerTmp = new Answer($questionId);
  411. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  412. // get answers of hotpost
  413. $answers_hotspot = array();
  414. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  415. $answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId));
  416. $answers_hotspot[$answers['id']] = $objAnswerTmp->selectAnswer($answerId);
  417. }
  418. // display answers of hotpost order by id
  419. $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>'.get_lang('HotspotZones').'</b><dl>';
  420. if (!empty($answers_hotspot)) {
  421. ksort($answers_hotspot);
  422. foreach ($answers_hotspot as $key => $value) {
  423. $answer_list .= '<dt>'.$key.'.- '.$value.'</dt><br />';
  424. }
  425. }
  426. $answer_list .= '</dl></div>';
  427. if (!$onlyAnswers) {
  428. if ($show_title) {
  429. echo '<div id="question_title" class="sectiontitle">'.get_lang('Question').' '.$current_item.' : '.$questionName.'</div>';
  430. }
  431. //@todo I need to the get the feedback type
  432. //if($answerType == 2)
  433. // $s.=' / '.$total_item;
  434. echo '<input type="hidden" name="hidden_hotspot_id" value="'.$questionId.'" />';
  435. echo '<table class="exercise_questions" >
  436. <tr>
  437. <td valign="top" colspan="2">';
  438. echo $questionDescription=text_filter($questionDescription);
  439. echo '</td></tr>';
  440. }
  441. $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
  442. $s .= '<script language="JavaScript" type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script>
  443. <script src="../plugin/hotspot/hotspot.js" type="text/javascript" language="JavaScript"></script>
  444. <script language="JavaScript" type="text/javascript">
  445. <!--
  446. // Globals
  447. // Major version of Flash required
  448. var requiredMajorVersion = 7;
  449. // Minor version of Flash required
  450. var requiredMinorVersion = 0;
  451. // Minor version of Flash required
  452. var requiredRevision = 0;
  453. // the version of javascript supported
  454. var jsVersion = 1.0;
  455. // -->
  456. </script>
  457. <script language="VBScript" type="text/vbscript">
  458. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  459. Function VBGetSwfVer(i)
  460. on error resume next
  461. Dim swControl, swVersion
  462. swVersion = 0
  463. set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))
  464. if (IsObject(swControl)) then
  465. swVersion = swControl.GetVariable("$version")
  466. end if
  467. VBGetSwfVer = swVersion
  468. End Function
  469. // -->
  470. </script>
  471. <script language="JavaScript1.1" type="text/javascript">
  472. <!-- // Detect Client Browser type
  473. var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
  474. var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
  475. var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
  476. jsVersion = 1.1;
  477. // JavaScript helper required to detect Flash Player PlugIn version information
  478. function JSGetSwfVer(i) {
  479. // NS/Opera version >= 3 check for Flash plugin in plugin array
  480. if (navigator.plugins != null && navigator.plugins.length > 0) {
  481. if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
  482. var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
  483. var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
  484. descArray = flashDescription.split(" ");
  485. tempArrayMajor = descArray[2].split(".");
  486. versionMajor = tempArrayMajor[0];
  487. versionMinor = tempArrayMajor[1];
  488. if ( descArray[3] != "" ) {
  489. tempArrayMinor = descArray[3].split("r");
  490. } else {
  491. tempArrayMinor = descArray[4].split("r");
  492. }
  493. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  494. flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
  495. } else {
  496. flashVer = -1;
  497. }
  498. }
  499. // MSN/WebTV 2.6 supports Flash 4
  500. else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
  501. // WebTV 2.5 supports Flash 3
  502. else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
  503. // older WebTV supports Flash 2
  504. else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
  505. // Can\'t detect in all other cases
  506. else
  507. {
  508. flashVer = -1;
  509. }
  510. return flashVer;
  511. }
  512. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  513. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
  514. reqVer = parseFloat(reqMajorVer + "." + reqRevision);
  515. // loop backwards through the versions until we find the newest version
  516. for (i=25;i>0;i--) {
  517. if (isIE && isWin && !isOpera) {
  518. versionStr = VBGetSwfVer(i);
  519. } else {
  520. versionStr = JSGetSwfVer(i);
  521. }
  522. if (versionStr == -1 ) {
  523. return false;
  524. } else if (versionStr != 0) {
  525. if(isIE && isWin && !isOpera) {
  526. tempArray = versionStr.split(" ");
  527. tempString = tempArray[1];
  528. versionArray = tempString .split(",");
  529. } else {
  530. versionArray = versionStr.split(".");
  531. }
  532. versionMajor = versionArray[0];
  533. versionMinor = versionArray[1];
  534. versionRevision = versionArray[2];
  535. versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24
  536. versionNum = parseFloat(versionString);
  537. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  538. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  539. return true;
  540. } else {
  541. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  542. }
  543. }
  544. }
  545. }
  546. // -->
  547. </script>';
  548. $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520">
  549. <script language="JavaScript" type="text/javascript">
  550. <!--
  551. // Version check based upon the values entered above in "Globals"
  552. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  553. // Check to see if the version meets the requirements for playback
  554. if (hasReqestedVersion) { // if we\'ve detected an acceptable version
  555. var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_user.swf?modifyAnswers='.$questionId.'&amp;canClick:'.$canClick.'" width="560" height="436">\'
  556. + \'<param name="movie" value="../plugin/hotspot/hotspot_user.swf?modifyAnswers='.$questionId.'&amp;canClick:'.$canClick.'" />\'
  557. + \'<\/object>\';
  558. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  559. } else { // flash is too old or we can\'t detect the plugin
  560. var alternateContent = "Error<br \/>"
  561. + "Hotspots requires Macromedia Flash 7.<br \/>"
  562. + "<a href=\"http://www.macromedia.com/go/getflash/\">Get Flash<\/a>";
  563. document.write(alternateContent); // insert non-flash content
  564. }
  565. // -->
  566. </script>
  567. </td>
  568. <td valign="top" align="left">'.$answer_list.'</td></tr>
  569. </table>
  570. </td></tr>';
  571. echo $s;
  572. }
  573. echo '</table><br />';
  574. return $nbrAnswers;
  575. }
  576. function get_exercise_track_exercise_info($exe_id) {
  577. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  578. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  579. $exe_id = intval($exe_id);
  580. $result = array();
  581. if (!empty($exe_id)) {
  582. $sql_fb_type = 'SELECT * FROM '.$TBL_EXERCICES.' as e INNER JOIN '.$TBL_TRACK_EXERCICES.' as te ON (e.id=te.exe_exo_id) WHERE te.exe_id='.$exe_id;
  583. $res_fb_type = Database::query($sql_fb_type);
  584. $result = Database::fetch_array($res_fb_type, 'ASSOC');
  585. }
  586. return $result;
  587. }
  588. /**
  589. * Validates the time control key
  590. */
  591. function exercise_time_control_is_valid($exercise_id) {
  592. //Fast check
  593. $exercise_id = intval($exercise_id);
  594. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  595. $sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE id = $exercise_id";
  596. $result = Database::query($sql);
  597. $row = Database::fetch_array($result, 'ASSOC');
  598. if (!empty($row['expired_time']) ) {
  599. $current_expired_time_key = get_time_control_key($exercise_id);
  600. if (isset($_SESSION['expired_time'][$current_expired_time_key])) {
  601. $current_time = time();
  602. $expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC');
  603. $total_time_allowed = $expired_time + 30;
  604. //error_log('expired time converted + 30: '.$total_time_allowed);
  605. //error_log('$current_time: '.$current_time);
  606. if ($total_time_allowed < $current_time) {
  607. return false;
  608. }
  609. return true;
  610. } else {
  611. return false;
  612. }
  613. } else {
  614. return true;
  615. }
  616. }
  617. /**
  618. Deletes the time control token
  619. */
  620. function exercise_time_control_delete($exercise_id) {
  621. $current_expired_time_key = get_time_control_key($exercise_id);
  622. unset($_SESSION['expired_time'][$current_expired_time_key]);
  623. }
  624. /**
  625. Generates the time control key
  626. */
  627. function generate_time_control_key($exercise_id) {
  628. $exercise_id = intval($exercise_id);
  629. return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
  630. }
  631. /**
  632. Returns the time controller key
  633. @todo this function is the same as generate_time_control_key
  634. */
  635. function get_time_control_key($exercise_id) {
  636. $exercise_id = intval($exercise_id);
  637. return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
  638. }
  639. /**
  640. * @todo use this function instead of get_time_control_key
  641. */
  642. function get_session_time_control_key($exercise_id) {
  643. $time_control_key = get_time_control_key($exercise_id);
  644. $return_value = $_SESSION['expired_time'][$time_control_key];
  645. return $return_value;
  646. }
  647. /**
  648. * Gets count of exam results
  649. * @todo this function should be moved in a library + no global calls
  650. */
  651. function get_count_exam_results($exercise_id = null) {
  652. global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath;
  653. $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
  654. if ($is_allowedToEdit || $is_tutor) {
  655. $user_id_and = '';
  656. if (!empty ($_POST['filter_by_user'])) {
  657. if ($_POST['filter_by_user'] == 'all') {
  658. $user_id_and = " AND user_id like '%'";
  659. } else {
  660. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  661. }
  662. }
  663. if ($_GET['gradebook'] == 'view') {
  664. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  665. }
  666. $exercise_where = '';
  667. if (isset($_GET['exerciseId'])) {
  668. $exercise_where = ' AND te.exe_exo_id = '.intval($_GET['exerciseId']).' ';
  669. }
  670. if (!empty($exercise_id)) {
  671. $exercise_where = ' AND te.exe_exo_id = '.intval($exercise_id).' ';
  672. }
  673. //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
  674. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname col1" : "lastname as userpart1, firstname as col1").", ce.title as extitle, te.exe_result as exresult ,
  675. te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration
  676. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  677. WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  678. $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  679. AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  680. $sql="SELECT count(*) as count
  681. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  682. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
  683. $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date
  684. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  685. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and $exercise_where
  686. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  687. } else {
  688. // get only this user's results
  689. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  690. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult, " .
  691. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  692. "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  693. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  694. WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id
  695. AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  696. AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
  697. " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  698. $sql="SELECT count(*) as count
  699. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  700. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND" .
  701. " orig_lp_id = 0 AND orig_lp_item_id = 0 ";
  702. $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
  703. FROM $TBL_TRACK_HOTPOTATOES
  704. WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
  705. ORDER BY exe_cours_id ASC, exe_date DESC";
  706. }
  707. $resx = Database::query($sql);
  708. $rowx = Database::fetch_array($resx,'ASSOC');
  709. return $rowx['count'];
  710. }
  711. /**
  712. * Gets the exam'data results
  713. * @todo this function should be moved in a library + no global calls
  714. */
  715. function get_exam_results_data($from, $number_of_items, $column, $direction) {
  716. global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath,$filter;
  717. $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
  718. if ($is_allowedToEdit || $is_tutor) {
  719. $user_id_and = '';
  720. if (!empty ($_POST['filter_by_user'])) {
  721. if ($_POST['filter_by_user'] == 'all') {
  722. $user_id_and = " AND user_id like '%'";
  723. } else {
  724. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  725. }
  726. }
  727. if ($_GET['gradebook'] == 'view') {
  728. $exercise_where_query = ' te.exe_exo_id =ce.id AND ';
  729. }
  730. $exercise_where = '';
  731. if (isset($_GET['exerciseId'])) {
  732. $exercise_where .= ' AND te.exe_exo_id = '.intval($_GET['exerciseId']).' ';
  733. }
  734. //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
  735. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult ,
  736. te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration
  737. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  738. WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  739. $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  740. AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  741. $sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as col2, te.exe_result as exresult , te.exe_weighting as exweight,
  742. te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as col4, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration
  743. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  744. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
  745. $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date
  746. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  747. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid)." $user_id_and $exercise_where
  748. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  749. } else {
  750. // get only this user's results
  751. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  752. /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult, " .
  753. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  754. "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  755. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  756. WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id
  757. AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  758. AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
  759. " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  760. $sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1")." , ce.title as col2, te.exe_result as exresult, " .
  761. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  762. "te.start_date as col4, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  763. FROM $TBL_EXERCICES AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
  764. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($_cid) . "' $user_id_and $session_id_and AND ce.active <>-1 AND" .
  765. " orig_lp_id = 0 AND orig_lp_item_id = 0 ";
  766. $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
  767. FROM $TBL_TRACK_HOTPOTATOES
  768. WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
  769. ORDER BY exe_cours_id ASC, exe_date DESC";
  770. }
  771. $column = intval($column);
  772. $from = intval($from);
  773. $number_of_items = intval($number_of_items);
  774. $sql .= " ORDER BY col$column $direction ";
  775. $sql .= " LIMIT $from,$number_of_items";
  776. $results = array();
  777. $resx = Database::query($sql);
  778. while ($rowx = Database::fetch_array($resx,'ASSOC')) {
  779. $results[] = $rowx;
  780. }
  781. $hpresults = getManyResultsXCol($hpsql, 5);
  782. $has_test_results = false;
  783. $list_info = array();
  784. // Print test results.
  785. $lang_nostartdate = get_lang('NoStartDate') . ' / ';
  786. if (is_array($results)) {
  787. $has_test_results = true;
  788. $users_array_id = array ();
  789. if ($_GET['gradebook'] == 'view') {
  790. $filter_by_no_revised = true;
  791. $from_gradebook = true;
  792. }
  793. $sizeof = sizeof($results);
  794. $user_list_id = array ();
  795. $user_last_name = '';
  796. $user_first_name = '';
  797. $quiz_name_list = '';
  798. $duration_list = '';
  799. $date_list = '';
  800. $result_list = '';
  801. $more_details_list = '';
  802. for ($i = 0; $i < $sizeof; $i++) {
  803. $revised = false;
  804. $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . '
  805. WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i]['exid']) . "'" . ' LIMIT 1';
  806. $query = Database::query($sql_exe);
  807. if (Database :: num_rows($query) > 0) {
  808. $revised = true;
  809. }
  810. if ($filter_by_not_revised && $revised) {
  811. continue;
  812. }
  813. if ($filter_by_revised && !$revised) {
  814. continue;
  815. }
  816. if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  817. if (in_array($results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'], $users_array_id)) {
  818. continue;
  819. }
  820. $users_array_id[] = $results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'];
  821. }
  822. $user_first_name = $results[$i]['col0'];
  823. $user_last_name = $results[$i]['col1'];
  824. $user_list_id[] = $results[$i]['excruid'];
  825. $id = $results[$i]['exid'];
  826. $user = $results[$i]['col0'] . $results[$i]['col1'];
  827. $test = $results[$i]['col2'];
  828. $quiz_name_list = $test;
  829. $dt = api_convert_and_format_date($results[$i]['exweight'], null, date_default_timezone_get());
  830. $res = $results[$i]['exresult'];
  831. $duration = intval($results[$i]['exduration']);
  832. // we filter the results if we have the permission to
  833. if (isset ($results[$i]['exdisabled']))
  834. $result_disabled = intval($results[$i]['exdisabled']);
  835. else
  836. $result_disabled = 0;
  837. if ($result_disabled == 0) {
  838. $add_start_date = $lang_nostartdate;
  839. if ($is_allowedToEdit || $is_tutor) {
  840. $user = $results[$i]['col0'] . $results[$i]['col1'];
  841. }
  842. if ($results[$i]['col4'] != "0000-00-00 00:00:00") {
  843. //echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
  844. $exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get());
  845. $start_date_timestamp = api_strtotime($results[$i]['col4'], date_default_timezone_get());
  846. $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
  847. if ($my_duration == 1 ) {
  848. $duration_list = $my_duration . ' ' . get_lang('MinMinute');
  849. } else {
  850. $duration_list = $my_duration. ' ' . get_lang('MinMinutes');
  851. }
  852. if ($results[$i]['exstep'] > 1) {
  853. //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  854. $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )';
  855. }
  856. $add_start_date = api_convert_and_format_date($results[$i]['col4'], null, date_default_timezone_get()) . ' / ';
  857. } else {
  858. $duration_list = get_lang('NoLogOfDuration');
  859. //echo get_lang('NoLogOfDuration');
  860. }
  861. // Date conversion
  862. $date_list = api_get_local_time($results[$i]['col4']). ' / ' . api_get_local_time($results[$i]['exdate']);
  863. // there are already a duration test period calculated??
  864. //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
  865. // if the float look like 10.00 we show only 10
  866. $my_res = float_format($results[$i]['exresult'],1);
  867. $my_total = float_format($results[$i]['exweight'],1);
  868. $ex = show_score($my_res, $my_total);
  869. //$result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
  870. $result_list = $ex;
  871. $html_link = '';
  872. if ($is_allowedToEdit || $is_tutor) {
  873. if ($revised) {
  874. $html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&id=$id'>".Display :: return_icon('edit.gif', get_lang('Edit'));
  875. $html_link.= '&nbsp;';
  876. } else {
  877. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
  878. $html_link.='&nbsp;';
  879. }
  880. $html_link.="</a>";
  881. if (api_is_platform_admin() || $is_tutor) {
  882. $html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.gif', get_lang('Delete')).'</a>';
  883. $html_link.='&nbsp;';
  884. }
  885. if ($is_allowedToEdit) {
  886. if ($filter==2){
  887. $html_link.=' <a href="exercice_history.php?'.api_get_cidreq().'&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  888. }
  889. }
  890. } else {
  891. if ($revised) {
  892. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&id=$id'>" . get_lang('Show') . "</a> ";
  893. } else {
  894. $html_link.='&nbsp;' . get_lang('NoResult');
  895. }
  896. }
  897. $more_details_list = $html_link;
  898. if ($is_allowedToEdit || $is_tutor) {
  899. $list_info [] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  900. } else {
  901. $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  902. }
  903. }
  904. }
  905. }
  906. // Print HotPotatoes test results.
  907. if (is_array($hpresults)) {
  908. $has_test_results = true;
  909. for ($i = 0; $i < sizeof($hpresults); $i++) {
  910. $hp_title = GetQuizName($hpresults[$i][1], $documentPath);
  911. if ($hp_title == '') {
  912. $hp_title = basename($hpresults[$i][1]);
  913. }
  914. //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
  915. $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get());
  916. $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')';
  917. if ($is_allowedToEdit) {
  918. $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-');
  919. } else {
  920. $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
  921. }
  922. }
  923. }
  924. return $list_info;
  925. }
  926. /**
  927. * Transform the score with exercise_max_note and exercise_min_score the platform settings
  928. * @param float score
  929. * @param float weight
  930. * @param bool show porcentage or not
  931. * @return string an html with the score modified
  932. */
  933. function show_score($score, $weight, $show_porcentage = true) {
  934. $html = '';
  935. $score_rounded = $score;
  936. if ($score != '' && $weight != '') {
  937. $max_note = api_get_setting('exercise_max_score');
  938. $min_note = api_get_setting('exercise_min_score');
  939. if ($max_note != '' && $min_note != '') {
  940. if (!empty($weight)) {
  941. $score = $min_note + ($max_note - $min_note) * $score /$weight;
  942. } else {
  943. $score = $min_note;
  944. }
  945. $score_rounded = round($score, 2);
  946. $weight = $max_note;
  947. }
  948. if ($show_porcentage) {
  949. $html = round(($score / ($weight != 0 ? $weight : 1)) * 100, 2) . '% (' . $score_rounded . ' / ' . $weight . ')';
  950. } else {
  951. $html = $score_rounded . ' / ' . $weight;
  952. }
  953. }
  954. return $html;
  955. }
  956. function convert_score($score, $weight) {
  957. $html = '';
  958. $score_rounded = $score;
  959. if ($score != '' && $weight != '') {
  960. $max_note = api_get_setting('exercise_max_score');
  961. $min_note = api_get_setting('exercise_min_score');
  962. if ($max_note != '' && $min_note != '') {
  963. if (!empty($weight)) {
  964. $score = $min_note + ($max_note - $min_note) * $score /$weight;
  965. } else {
  966. $score = $min_note;
  967. }
  968. $score_rounded = round($score, 2);
  969. }
  970. }
  971. return $score_rounded;
  972. }