exercise.lib.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise library
  5. * @todo convert this lib into a static class
  6. *
  7. * shows a question and its answers
  8. * @package chamilo.exercise
  9. * @author Olivier Brouckaert <oli.brouckaert@skynet.be>
  10. * @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $
  11. */
  12. /**
  13. * Code
  14. */
  15. // The initialization class for the online editor is needed here.
  16. require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
  17. /**
  18. * Shows a question
  19. *
  20. * @param int question id
  21. * @param bool if true only show the questions, no exercise title
  22. * @param bool origin i.e = learnpath
  23. * @param int current item from the list of questions
  24. * @param int number of total questions
  25. * */
  26. function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false) {
  27. $s = '';
  28. // Text direction for the current language
  29. $is_ltr_text_direction = api_get_text_direction() != 'rtl';
  30. // Change false to true in the following line to enable answer hinting.
  31. $debug_mark_answer = api_is_allowed_to_edit() && false;
  32. // Reads question information
  33. if (!$objQuestionTmp = Question::read($questionId)) {
  34. // Question not found
  35. return false;
  36. }
  37. $answerType = $objQuestionTmp->selectType();
  38. $pictureName = $objQuestionTmp->selectPicture();
  39. if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
  40. // Question is not a hotspot
  41. if (!$only_questions) {
  42. $questionName = $objQuestionTmp->selectTitle();
  43. $questionDescription = $objQuestionTmp->selectDescription();
  44. $questionName = text_filter($questionName);
  45. if ($show_title) {
  46. $s='<div id="question_title" class="sectiontitle">'.get_lang('Question').' ';
  47. $s.=$current_item;
  48. //@todo I need the get the feedback type
  49. //if($answerType != 1)
  50. //$s.=' / '.$total_item;
  51. echo $s;
  52. echo ' : ';
  53. echo $questionName.'</div>';
  54. }
  55. $s='';
  56. $s.='<table class="exercise_questions" style="margin:4px 4px 4px 0px; padding:2px;">
  57. <tr><td valign="top" colspan="2">';
  58. $questionDescription=text_filter($questionDescription);
  59. $s.=$questionDescription;
  60. $s.='</td></tr></table>';
  61. if (!empty($pictureName)) {
  62. $s.="<tr>
  63. <td align='center' colspan='2'><img src='../document/download.php?doc_url=%2Fimages%2F'".$pictureName."' border='0'></td>
  64. </tr>";
  65. }
  66. $s.= '</table>';
  67. }
  68. $s .= '<div class="rounded exercise_questions" style="width: 720px; padding: 3px;">';
  69. $option_ie = '';
  70. /*
  71. if (!ereg("MSIE",$_SERVER["HTTP_USER_AGENT"])) {
  72. $s .= '<div class="rounded exercise_questions" style="width: 720px; padding: 3px;">';
  73. } else {
  74. $option_ie="margin-left:10px";
  75. }*/
  76. if ($answerType == FREE_ANSWER && $freeze) {
  77. return '';
  78. }
  79. $s .= '<table width="720" class="exercise_options" style="width: 720px;'.$option_ie.' background-color:#fff;">';
  80. // construction of the Answer object (also gets all answers details)
  81. $objAnswerTmp = new Answer($questionId);
  82. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  83. $quiz_question_options = Question::readQuestionOption($questionId);
  84. // For "matching" type here, we need something a little bit special
  85. // because the match between the suggestions and the answers cannot be
  86. // done easily (suggestions and answers are in the same table), so we
  87. // have to go through answers first (elems with "correct" value to 0).
  88. $select_items = array();
  89. //This will contain the number of answers on the left side. We call them
  90. // suggestions here, for the sake of comprehensions, while the ones
  91. // on the right side are called answers
  92. $num_suggestions = 0;
  93. if ($answerType == MATCHING) {
  94. $x = 1; //iterate through answers
  95. $letter = 'A'; //mark letters for each answer
  96. $answer_matching = $cpt1 = array();
  97. $answer_suggestions = $nbrAnswers;
  98. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  99. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  100. $numAnswer = $objAnswerTmp->selectAutoId($answerId);
  101. $answer=$objAnswerTmp->selectAnswer($answerId);
  102. if ($answerCorrect==0) {
  103. // options (A, B, C, ...) that will be put into the list-box
  104. // have the "correct" field set to 0 because they are answer
  105. $cpt1[$x] = $letter;
  106. $answer_matching[$x]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
  107. $x++; $letter++;
  108. }
  109. }
  110. $i = 1;
  111. foreach ($answer_matching as $id => $value) {
  112. $select_items[$i]['id'] = $value['id'];
  113. $select_items[$i]['letter'] = $cpt1[$id];
  114. $select_items[$i]['answer'] = $value['answer'];
  115. $i ++;
  116. }
  117. $num_suggestions = ($nbrAnswers - $x) + 1;
  118. } elseif ($answerType == FREE_ANSWER) {
  119. $oFCKeditor = new FCKeditor("choice[".$questionId."]") ;
  120. $oFCKeditor->ToolbarSet = 'TestFreeAnswer';
  121. $oFCKeditor->Width = '100%';
  122. $oFCKeditor->Height = '200';
  123. $oFCKeditor->Value = '' ;
  124. $s .= '<tr><td colspan="3">';
  125. $s .= $oFCKeditor->CreateHtml();
  126. $s .= '</td></tr>';
  127. }
  128. ?>
  129. <style>
  130. </style>
  131. <script>
  132. $(function() {
  133. /*
  134. var $options = $( "#options" );
  135. $( "div", $options ).draggable({
  136. revert: "invalid", // when not dropped, the item will revert back to its initial position
  137. cursor: "move",
  138. });
  139. var $question_1 = $( "#question_1" );
  140. $question_1.droppable({
  141. accept: "#options div",
  142. activeClass: "ui-state-hover",
  143. hoverClass: "ui-state-active",
  144. drop: function( event, ui ) {
  145. //$( this ).addClass( "ui-state-highlight" );
  146. }
  147. });
  148. var $question_2 = $( "#question_2" );
  149. $question_2.droppable({
  150. accept: "#options div",
  151. hoverClass: "ui-state-active",
  152. drop: function( event, ui ) {
  153. //$( this ).addClass( "ui-state-highlight" );
  154. }
  155. });
  156. $options.droppable({
  157. accept: "#options div",
  158. hoverClass: "ui-state-active",
  159. drop: function( event, ui ) {
  160. }
  161. });*/
  162. });
  163. </script>
  164. <?php
  165. // Now navigate through the possible answers, using the max number of
  166. // answers for the question as a limiter
  167. $lines_count=1; // a counter for matching-type answers
  168. $question_list = array();
  169. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  170. $header .= Display::tag('th', get_lang('Options'));
  171. foreach ($objQuestionTmp->options as $key=>$item) {
  172. $header .= Display::tag('th', $item);
  173. }
  174. $s.=Display::tag('tr',$header, array('style'=>'text-align:left;'));
  175. }
  176. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  177. $answer = $objAnswerTmp->selectAnswer($answerId);
  178. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  179. $numAnswer = $objAnswerTmp->selectAutoId($answerId);
  180. if ($answerType == FILL_IN_BLANKS) {
  181. // splits text and weightings that are joined with the character '::'
  182. list($answer) = explode('::',$answer);
  183. //getting the matches
  184. $answer = api_ereg_replace('\[[^]]+\]','<input type="text" name="choice['.$questionId.'][]" size="10" />',($answer));
  185. }
  186. // Unique answer
  187. if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
  188. // set $debug_mark_answer to true at function start to
  189. // show the correct answer with a suffix '-x'
  190. $help = $selected = '';
  191. if ($debug_mark_answer) {
  192. if ($answerCorrect) {
  193. $help = 'x-';
  194. $selected = 'checked';
  195. }
  196. }
  197. $answer = text_filter($answer);
  198. $answer = Security::remove_XSS($answer, STUDENT);
  199. $s .= Display::input('hidden','choice2['.$questionId.']','0').
  200. '<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;">'.
  201. '<span>'.Display::input('radio','choice['.$questionId.']', $numAnswer, array('class'=>'checkbox','selected'=>$selected)).'</span></p>'.
  202. '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  203. $answer.
  204. '</div></div></td></tr>';
  205. } elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  206. // multiple answers
  207. // set $debug_mark_answer to true at function start to
  208. // show the correct answer with a suffix '-x'
  209. $help = $selected = '';
  210. if ($debug_mark_answer) {
  211. if ($answerCorrect) {
  212. $help = 'x-';
  213. $selected = 'checked="checked"';
  214. }
  215. }
  216. $answer = text_filter($answer);
  217. $answer = Security::remove_XSS($answer, STUDENT);
  218. if ($answerType == MULTIPLE_ANSWER) {
  219. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
  220. $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;">';
  221. $options = array('type'=>'checkbox','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  222. if ($debug_mark_answer) {
  223. if ($answerCorrect) {
  224. $options['checked'] = 'checked';
  225. }
  226. }
  227. $s .= Display::tag('span', Display::tag('input','',$options ));
  228. $s .= '</p>';
  229. $s .= '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  230. $answer.
  231. '</div></div></td></tr>';
  232. } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  233. $options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  234. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
  235. $s .='<tr>';
  236. $s .= Display::tag('td', $answer);
  237. if (!empty($quiz_question_options)) {
  238. foreach ($quiz_question_options as $id=>$item) {
  239. $options['value'] = $id;
  240. $s .= Display::tag('td', Display::tag('input','',$options ));
  241. }
  242. }
  243. $s.='<tr>';
  244. }
  245. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
  246. // multiple answers
  247. // set $debug_mark_answer to true at function start to
  248. // show the correct answer with a suffix '-x'
  249. $help = $selected = '';
  250. if ($debug_mark_answer) {
  251. if ($answerCorrect) {
  252. $help = 'x-';
  253. $selected = 'checked="checked"';
  254. }
  255. }
  256. $answer = text_filter($answer);
  257. $answer = Security::remove_XSS($answer, STUDENT);
  258. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'.
  259. '<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;">'.
  260. '<span><input class="checkbox" type="checkbox" name="choice['.$questionId.']['.$numAnswer.']" value="1" '.$selected.' /></span></p>'.
  261. '<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
  262. $answer.
  263. '</div></div></td></tr>';
  264. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  265. // multiple answers
  266. // set $debug_mark_answer to true at function start to
  267. // show the correct answer with a suffix '-x'
  268. $s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />';
  269. $help = $selected = '';
  270. if ($debug_mark_answer) {
  271. if ($answerCorrect) {
  272. $help = 'x-';
  273. $selected = 'checked="checked"';
  274. }
  275. }
  276. $answer = text_filter($answer);
  277. $answer = Security::remove_XSS($answer, STUDENT);
  278. $options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
  279. $s .='<tr>';
  280. $s .= Display::tag('td', $answer);
  281. foreach ($objQuestionTmp->options as $key=>$item) {
  282. $options['value'] = $key;
  283. $s .= Display::tag('td', Display::tag('input','',$options ));
  284. }
  285. $s.='<tr>';
  286. } elseif ($answerType == FILL_IN_BLANKS) {
  287. // fill in blanks
  288. $s .= '<tr><td colspan="3">'.$answer.'</td></tr>';
  289. } else {
  290. // matching type, showing suggestions and answers
  291. // TODO: replace $answerId by $numAnswer
  292. if ($answerCorrect != 0) {
  293. // only show elements to be answered (not the contents of
  294. // the select boxes, who are corrrect = 0)
  295. $s .= '<tr><td width="45%" valign="top" >';
  296. $parsed_answer = text_filter($answer);
  297. $question_list[] = $parsed_answer;
  298. //left part questions
  299. $s .= ' <span style="float:left; width:8%;"><b>'.$lines_count.'</b>.&nbsp;</span>
  300. <span style="float:left; width:92%;">'.$parsed_answer.'</span></td>';
  301. //middle part (matches selects)
  302. $s .= '<td width="10%" valign="top" align="center">&nbsp;&nbsp;
  303. <select name="choice['.$questionId.']['.$numAnswer.']">
  304. <option value="0">--</option>';
  305. // fills the list-box
  306. foreach ($select_items as $key=>$val) {
  307. // set $debug_mark_answer to true at function start to
  308. // show the correct answer with a suffix '-x'
  309. $help = $selected = '';
  310. if ($debug_mark_answer) {
  311. if ($val['id'] == $answerCorrect) {
  312. $help = '-x';
  313. $selected = 'selected="selected"';
  314. }
  315. }
  316. $s.='<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].$help.'</option>';
  317. } // end foreach()
  318. $s .= '</select>&nbsp;&nbsp;</td>';
  319. //print_r($select_items);
  320. //right part (answers)
  321. $s.='<td width="45%" valign="top" >';
  322. if (isset($select_items[$lines_count])) {
  323. $s.='<span style="float:left; width:5%;"><b>'.$select_items[$lines_count]['letter'].'.</b></span>'.
  324. '<span style="float:left; width:95%;">'.$select_items[$lines_count]['answer'].'</span>';
  325. } else {
  326. $s.='&nbsp;';
  327. }
  328. $s .= '</td>';
  329. $s .= '</tr>';
  330. $lines_count++;
  331. //if the left side of the "matching" has been completely
  332. // shown but the right side still has values to show...
  333. if (($lines_count -1) == $num_suggestions) {
  334. // if it remains answers to shown at the right side
  335. while (isset($select_items[$lines_count])) {
  336. $s .= '<tr>
  337. <td colspan="2">&nbsp;</td>
  338. <td valign="top">';
  339. $s.='<b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'];
  340. $s.="</td>
  341. </tr>";
  342. $lines_count++;
  343. } // end while()
  344. } // end if()
  345. }
  346. }
  347. } // end for()
  348. /*
  349. //Adding divs for the new MATCHING interface
  350. if ($answerType == MATCHING && !$freeze) {
  351. echo '<div id="questions">';
  352. echo Display::tag('h2','Questions');
  353. $i = 1;
  354. foreach ($question_list as $key=>$val) {
  355. echo Display::tag('div', Display::tag('p',$val), array('id'=>'question_'.$i, 'class'=>'question_item ui-widget-header'));
  356. $i++;
  357. }
  358. echo '</div>';
  359. echo Display::tag('h2','Options');
  360. echo '<div id="options" class=" ui-widget-header">';
  361. foreach ($select_items as $key=>$val) {
  362. echo Display::tag('div', Display::tag('p',$val['answer']), array('id'=>'option_'.$i, 'class'=>'option_item ui-widget-content'));
  363. }
  364. echo '</ul>';
  365. }*/
  366. $s .= '</table>';
  367. $s .= '</div><br />';
  368. // destruction of the Answer object
  369. unset($objAnswerTmp);
  370. // destruction of the Question object
  371. unset($objQuestionTmp);
  372. if ($origin != 'export') {
  373. echo $s;
  374. } else {
  375. return($s);
  376. }
  377. } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
  378. // Question is a HOT_SPOT
  379. //checking document/images visibility
  380. if (api_is_platform_admin() || api_is_course_admin()) {
  381. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  382. $course = api_get_course_info();
  383. $doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName);
  384. if (is_numeric($doc_id)) {
  385. $images_folder_visibility = api_get_item_visibility($course,'document', $doc_id, api_get_session_id());
  386. if (!$images_folder_visibility) {
  387. //This message is shown only to the course/platform admin if the image is set to visibility = false
  388. Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage'));
  389. }
  390. }
  391. }
  392. $questionName = $objQuestionTmp->selectTitle();
  393. $questionDescription = $objQuestionTmp->selectDescription();
  394. if ($freeze) {
  395. echo Display::img($objQuestionTmp->selectPicturePath());
  396. return;
  397. }
  398. // Get the answers, make a list
  399. $objAnswerTmp = new Answer($questionId);
  400. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  401. // get answers of hotpost
  402. $answers_hotspot = array();
  403. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  404. $answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId));
  405. $answers_hotspot[$answers['id']] = $objAnswerTmp->selectAnswer($answerId);
  406. }
  407. // display answers of hotpost order by id
  408. $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>'.get_lang('HotspotZones').'</b><dl>';
  409. if (!empty($answers_hotspot)) {
  410. ksort($answers_hotspot);
  411. foreach ($answers_hotspot as $key => $value) {
  412. $answer_list .= '<dt>'.$key.'.- '.$value.'</dt><br />';
  413. }
  414. }
  415. $answer_list .= '</dl></div>';
  416. if ($answerType == HOT_SPOT_DELINEATION) {
  417. $answer_list='';
  418. $swf_file = 'hotspot_delineation_user';
  419. $swf_height = 405;
  420. } else {
  421. $swf_file = 'hotspot_user';
  422. $swf_height = 436;
  423. }
  424. if (!$only_questions) {
  425. if ($show_title) {
  426. echo '<div id="question_title" class="sectiontitle">'.get_lang('Question').' '.$current_item.' : '.$questionName.'</div>';
  427. }
  428. //@todo I need to the get the feedback type
  429. //if($answerType == 2)
  430. // $s.=' / '.$total_item;
  431. echo '<input type="hidden" name="hidden_hotspot_id" value="'.$questionId.'" />';
  432. echo '<table class="exercise_questions" >
  433. <tr>
  434. <td valign="top" colspan="2">';
  435. echo $questionDescription=text_filter($questionDescription);
  436. echo '</td></tr>';
  437. }
  438. $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
  439. $s .= '<script language="JavaScript" type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script>
  440. <script src="../plugin/hotspot/hotspot.js" type="text/javascript" language="JavaScript"></script>
  441. <script language="JavaScript" type="text/javascript">
  442. <!--
  443. // Globals
  444. // Major version of Flash required
  445. var requiredMajorVersion = 7;
  446. // Minor version of Flash required
  447. var requiredMinorVersion = 0;
  448. // Minor version of Flash required
  449. var requiredRevision = 0;
  450. // the version of javascript supported
  451. var jsVersion = 1.0;
  452. // -->
  453. </script>
  454. <script language="VBScript" type="text/vbscript">
  455. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  456. Function VBGetSwfVer(i)
  457. on error resume next
  458. Dim swControl, swVersion
  459. swVersion = 0
  460. set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))
  461. if (IsObject(swControl)) then
  462. swVersion = swControl.GetVariable("$version")
  463. end if
  464. VBGetSwfVer = swVersion
  465. End Function
  466. // -->
  467. </script>
  468. <script language="JavaScript1.1" type="text/javascript">
  469. <!-- // Detect Client Browser type
  470. var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
  471. var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
  472. var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
  473. jsVersion = 1.1;
  474. // JavaScript helper required to detect Flash Player PlugIn version information
  475. function JSGetSwfVer(i) {
  476. // NS/Opera version >= 3 check for Flash plugin in plugin array
  477. if (navigator.plugins != null && navigator.plugins.length > 0) {
  478. if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
  479. var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
  480. var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
  481. descArray = flashDescription.split(" ");
  482. tempArrayMajor = descArray[2].split(".");
  483. versionMajor = tempArrayMajor[0];
  484. versionMinor = tempArrayMajor[1];
  485. if ( descArray[3] != "" ) {
  486. tempArrayMinor = descArray[3].split("r");
  487. } else {
  488. tempArrayMinor = descArray[4].split("r");
  489. }
  490. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  491. flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
  492. } else {
  493. flashVer = -1;
  494. }
  495. }
  496. // MSN/WebTV 2.6 supports Flash 4
  497. else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
  498. // WebTV 2.5 supports Flash 3
  499. else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
  500. // older WebTV supports Flash 2
  501. else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
  502. // Can\'t detect in all other cases
  503. else
  504. {
  505. flashVer = -1;
  506. }
  507. return flashVer;
  508. }
  509. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  510. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
  511. reqVer = parseFloat(reqMajorVer + "." + reqRevision);
  512. // loop backwards through the versions until we find the newest version
  513. for (i=25;i>0;i--) {
  514. if (isIE && isWin && !isOpera) {
  515. versionStr = VBGetSwfVer(i);
  516. } else {
  517. versionStr = JSGetSwfVer(i);
  518. }
  519. if (versionStr == -1 ) {
  520. return false;
  521. } else if (versionStr != 0) {
  522. if(isIE && isWin && !isOpera) {
  523. tempArray = versionStr.split(" ");
  524. tempString = tempArray[1];
  525. versionArray = tempString .split(",");
  526. } else {
  527. versionArray = versionStr.split(".");
  528. }
  529. versionMajor = versionArray[0];
  530. versionMinor = versionArray[1];
  531. versionRevision = versionArray[2];
  532. versionString = versionMajor + "." + versionRevision; // 7.0r24 == 7.24
  533. versionNum = parseFloat(versionString);
  534. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  535. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  536. return true;
  537. } else {
  538. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  539. }
  540. }
  541. }
  542. }
  543. // -->
  544. </script>';
  545. $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520">
  546. <script language="JavaScript" type="text/javascript">
  547. <!--
  548. // Version check based upon the values entered above in "Globals"
  549. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  550. // Check to see if the version meets the requirements for playback
  551. if (hasReqestedVersion) { // if we\'ve detected an acceptable version
  552. var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/'.$swf_file.'.swf?modifyAnswers='.$questionId.'&amp;canClick:'.$canClick.'" width="600" height="'.$swf_height.'">\'
  553. + \'<param name="wmode" value="transparent">\'
  554. + \'<param name="movie" value="../plugin/hotspot/'.$swf_file.'.swf?modifyAnswers='.$questionId.'&amp;canClick:'.$canClick.'" />\'
  555. + \'<\/object>\';
  556. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  557. } else { // flash is too old or we can\'t detect the plugin
  558. var alternateContent = "Error<br \/>"
  559. + "Hotspots requires Macromedia Flash 7.<br \/>"
  560. + "<a href=\"http://www.macromedia.com/go/getflash/\">Get Flash<\/a>";
  561. document.write(alternateContent); // insert non-flash content
  562. }
  563. // -->
  564. </script>
  565. </td>
  566. <td valign="top" align="left">'.$answer_list.'</td></tr>
  567. </table>
  568. </td></tr>';
  569. echo $s;
  570. }
  571. echo '</table><br />';
  572. return $nbrAnswers;
  573. }
  574. function get_exercise_track_exercise_info($exe_id) {
  575. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  576. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  577. $exe_id = intval($exe_id);
  578. $result = array();
  579. if (!empty($exe_id)) {
  580. $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;
  581. $res_fb_type = Database::query($sql_fb_type);
  582. $result = Database::fetch_array($res_fb_type, 'ASSOC');
  583. }
  584. return $result;
  585. }
  586. /**
  587. * Validates the time control key
  588. */
  589. function exercise_time_control_is_valid($exercise_id) {
  590. //Fast check
  591. $exercise_id = intval($exercise_id);
  592. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  593. $sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE id = $exercise_id";
  594. $result = Database::query($sql);
  595. $row = Database::fetch_array($result, 'ASSOC');
  596. if (!empty($row['expired_time']) ) {
  597. $current_expired_time_key = get_time_control_key($exercise_id);
  598. if (isset($_SESSION['expired_time'][$current_expired_time_key])) {
  599. $current_time = time();
  600. $expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC');
  601. $total_time_allowed = $expired_time + 30;
  602. //error_log('expired time converted + 30: '.$total_time_allowed);
  603. //error_log('$current_time: '.$current_time);
  604. if ($total_time_allowed < $current_time) {
  605. return false;
  606. }
  607. return true;
  608. } else {
  609. return false;
  610. }
  611. } else {
  612. return true;
  613. }
  614. }
  615. /**
  616. Deletes the time control token
  617. */
  618. function exercise_time_control_delete($exercise_id) {
  619. $current_expired_time_key = get_time_control_key($exercise_id);
  620. unset($_SESSION['expired_time'][$current_expired_time_key]);
  621. }
  622. /**
  623. Generates the time control key
  624. */
  625. function generate_time_control_key($exercise_id) {
  626. $exercise_id = intval($exercise_id);
  627. return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
  628. }
  629. /**
  630. Returns the time controller key
  631. @todo this function is the same as generate_time_control_key
  632. */
  633. function get_time_control_key($exercise_id) {
  634. $exercise_id = intval($exercise_id);
  635. return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
  636. }
  637. /**
  638. * @todo use this function instead of get_time_control_key
  639. */
  640. function get_session_time_control_key($exercise_id) {
  641. $time_control_key = get_time_control_key($exercise_id);
  642. $return_value = $_SESSION['expired_time'][$time_control_key];
  643. return $return_value;
  644. }
  645. /**
  646. * Gets count of exam results
  647. * @todo this function should be moved in a library + no global calls
  648. */
  649. function get_count_exam_results($exercise_id = null) {
  650. //@todo replace all this globals
  651. global $is_allowedToEdit, $is_tutor,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_HOTPOTATOES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath;
  652. $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
  653. $exercise_id = intval($_GET['exerciseId']);
  654. $exercise_where = '';
  655. if (!empty($exercise_id)) {
  656. $exercise_where = ' AND te.exe_exo_id = '.$exercise_id.' ';
  657. }
  658. $hotpotatoe_where = '';
  659. if (!empty($_GET['path'])) {
  660. $hotpotatoe_path = Database::escape_string($_GET['path']);
  661. $hotpotatoe_where .= ' AND exe_name = "'.$hotpotatoe_path.'" ';
  662. }
  663. $user_id_hotpotato_and = ' AND exe_user_id = ' . api_get_user_id() . ' ';
  664. if ($is_allowedToEdit || $is_tutor) {
  665. $user_id_and = '';
  666. if (!empty ($_POST['filter_by_user'])) {
  667. if ($_POST['filter_by_user'] == 'all') {
  668. $user_id_and = " AND user_id like '%'";
  669. } else {
  670. $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
  671. }
  672. }
  673. if ($_GET['gradebook'] == 'view') {
  674. $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
  675. }
  676. //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
  677. /*$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 ,
  678. 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
  679. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  680. 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) . "'
  681. $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  682. AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  683. $sql="SELECT DISTINCT te.exe_id
  684. 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)
  685. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
  686. //Seems that the $TBL_TRACK_HOTPOTATOES does not have an exercise id that's weird ... we are removing $exercise_where
  687. $hpsql="SELECT count(*) as count
  688. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  689. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id() . "' $user_id_hotpotato_and $hotpotatoe_where
  690. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  691. } else {
  692. // get only this user's results
  693. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  694. /*$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, " .
  695. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  696. "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  697. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  698. 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
  699. AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  700. AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
  701. " 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";*/
  702. $sql="SELECT count(*) as count
  703. 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)
  704. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where";
  705. $hpsql = "SELECT count(*) as count
  706. FROM $TBL_TRACK_HOTPOTATOES
  707. WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' $user_id_hotpotato_and $hotpotatoe_where
  708. ORDER BY exe_cours_id ASC, exe_date DESC";
  709. }
  710. $count = 0;
  711. //Chamilo results
  712. if (empty($hotpotatoe_where)) {
  713. $resx = Database::query($sql);
  714. if (Database::num_rows($resx) > 0) {
  715. if ($is_allowedToEdit || $is_tutor) {
  716. while ($rowx = Database::fetch_array($resx,'ASSOC')) {
  717. $results[] = $rowx;
  718. }
  719. //Special modification to show corretly the pagination
  720. if (is_array($results)) {
  721. if ($_GET['gradebook'] == 'view') {
  722. $filter_by_no_revised = true;
  723. $from_gradebook = true;
  724. }
  725. $sizeof = count($results);
  726. $user_list_id = array ();
  727. $user_last_name = '';
  728. $user_first_name = '';
  729. $quiz_name_list = '';
  730. $duration_list = '';
  731. $date_list = '';
  732. $result_list = '';
  733. $more_details_list = '';
  734. for ($i = 0; $i < $sizeof; $i++) {
  735. $revised = false;
  736. $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . ' WHERE author != "" AND exe_id = ' . Database :: escape_string($results[$i]['exe_id']) .' LIMIT 1';
  737. $query = Database::query($sql_exe);
  738. if (Database :: num_rows($query) > 0) {
  739. $revised = true;
  740. }
  741. if ($filter_by_not_revised && $revised) {
  742. continue;
  743. }
  744. if ($filter_by_revised && !$revised) {
  745. continue;
  746. }
  747. $count++;
  748. }
  749. }
  750. } else {
  751. $rowx = Database::fetch_array($resx,'ASSOC');
  752. $count = $rowx['count'];
  753. }
  754. }
  755. } else {
  756. //Hotpotatoes results
  757. $hpres = Database::query($hpsql);
  758. if (Database::num_rows($hpres) > 0) {
  759. $rowx = Database::fetch_array($hpres,'ASSOC');
  760. $count += $rowx['count'];
  761. }
  762. }
  763. return $count;
  764. }
  765. /**
  766. * Gets the exam'data results
  767. * @todo this function should be moved in a library + no global calls
  768. */
  769. function get_exam_results_data($from, $number_of_items, $column, $direction) {
  770. //@todo replace all this globals
  771. global $is_allowedToEdit, $is_tutor,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_HOTPOTATOES, $TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath,$filter;
  772. $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
  773. $exercise_id = intval($_GET['exerciseId']);
  774. $exercise_where = '';
  775. if (!empty($exercise_id)) {
  776. $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.' ';
  777. }
  778. $hotpotatoe_where = '';
  779. if (!empty($_GET['path'])) {
  780. $hotpotatoe_path = Database::escape_string($_GET['path']);
  781. $hotpotatoe_where .= ' AND exe_name = "'.$hotpotatoe_path.'" ';
  782. }
  783. if ($is_allowedToEdit || $is_tutor) {
  784. $user_id_and = '';
  785. if (!empty ($_POST['filter_by_user'])) {
  786. if ($_POST['filter_by_user'] == 'all') {
  787. $user_id_and = " AND user_id like '%'";
  788. } else {
  789. $user_id_and = " AND user_id = '" . intval($_POST['filter_by_user']) . "' ";
  790. }
  791. }
  792. if ($_GET['gradebook'] == 'view') {
  793. $exercise_where_query = ' te.exe_exo_id =ce.id AND ';
  794. }
  795. //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
  796. /*$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 ,
  797. 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
  798. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  799. 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(api_get_course_id()) . "'
  800. $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
  801. AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
  802. $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,
  803. 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, propagate_neg
  804. 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)
  805. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
  806. $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
  807. FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
  808. WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id()."' $hotpotatoe_where
  809. ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
  810. } else {
  811. // get only this user's results
  812. $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
  813. /*$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, " .
  814. "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  815. "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
  816. FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
  817. 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
  818. AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
  819. AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
  820. " 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";*/
  821. $sql="SELECT ce.title as col0, ce.title as col1, te.exe_duration as exduration, firstname, lastname, te.exe_result as exresult, te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
  822. "te.start_date as col2, steps_counter as exstep, exe_user_id as excruid, ce.results_disabled as exdisabled, propagate_neg
  823. 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)
  824. WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where";
  825. $hpsql = "SELECT '', '', exe_name, exe_result , exe_weighting, exe_date
  826. FROM $TBL_TRACK_HOTPOTATOES
  827. WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' $hotpotatoe_where
  828. ORDER BY exe_cours_id ASC, exe_date DESC";
  829. }
  830. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  831. $teacher_list = CourseManager::get_teacher_list_from_course_code(api_get_course_id());
  832. $teacher_id_list = array();
  833. foreach ($teacher_list as $teacher) {
  834. $teacher_id_list[] = $teacher['user_id'];
  835. }
  836. if (empty($hotpotatoe_where)) {
  837. $column = intval($column);
  838. $from = intval($from);
  839. $number_of_items = intval($number_of_items);
  840. $sql .= " ORDER BY col$column $direction ";
  841. $sql .= " LIMIT $from, $number_of_items";
  842. $results = array();
  843. $resx = Database::query($sql);
  844. while ($rowx = Database::fetch_array($resx,'ASSOC')) {
  845. $results[] = $rowx;
  846. }
  847. $list_info = array();
  848. // Print test results.
  849. $lang_nostartdate = get_lang('NoStartDate') . ' / ';
  850. if (is_array($results)) {
  851. $users_array_id = array ();
  852. if ($_GET['gradebook'] == 'view') {
  853. $filter_by_no_revised = true;
  854. $from_gradebook = true;
  855. }
  856. $sizeof = count($results);
  857. $user_list_id = array ();
  858. $user_last_name = '';
  859. $user_first_name = '';
  860. $quiz_name_list = '';
  861. $duration_list = '';
  862. $date_list = '';
  863. $result_list = '';
  864. $more_details_list = '';
  865. for ($i = 0; $i < $sizeof; $i++) {
  866. $revised = false;
  867. $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . ' WHERE author != "" AND exe_id = ' . Database :: escape_string($results[$i]['exid']) .' LIMIT 1';
  868. $query = Database::query($sql_exe);
  869. if (Database :: num_rows($query) > 0) {
  870. $revised = true;
  871. }
  872. if ($filter_by_not_revised && $revised) {
  873. continue;
  874. }
  875. if ($filter_by_revised && !$revised) {
  876. continue;
  877. }
  878. if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
  879. if (in_array($results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'], $users_array_id)) {
  880. continue;
  881. }
  882. $users_array_id[] = $results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'];
  883. }
  884. if ($is_allowedToEdit || $is_tutor) {
  885. $user_first_name = $results[$i]['col0'];
  886. $user_last_name = $results[$i]['col1'];
  887. $user = $results[$i]['col0'] . $results[$i]['col1'];
  888. $test = $results[$i]['col2'];
  889. } else {
  890. $user_first_name = $results[$i]['firstname'];
  891. $user_last_name = $results[$i]['lastname'];
  892. $user = $results[$i]['firstname'] . $results[$i]['lastname'];
  893. $test = $results[$i]['col0'];
  894. }
  895. $user_list_id[] = $results[$i]['excruid'];
  896. $id = $results[$i]['exid'];
  897. $quiz_name_list = $test;
  898. $dt = api_convert_and_format_date($results[$i]['exweight']);
  899. $res = $results[$i]['exresult'];
  900. $duration = intval($results[$i]['exduration']);
  901. // we filter the results if we have the permission to
  902. if (isset ($results[$i]['exdisabled']))
  903. $result_disabled = intval($results[$i]['exdisabled']);
  904. else
  905. $result_disabled = 0;
  906. if ($result_disabled == 0) {
  907. $add_start_date = $lang_nostartdate;
  908. if ($is_allowedToEdit || $is_tutor) {
  909. $user = $results[$i]['col0'] . $results[$i]['col1'];
  910. $start_date = $results[$i]['col4'];
  911. } else {
  912. $start_date = $results[$i]['col2'];
  913. }
  914. if ($start_date != "0000-00-00 00:00:00") {
  915. $start_date_timestamp = api_strtotime($start_date);
  916. $exe_date_timestamp = api_strtotime($results[$i]['exdate']);
  917. $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
  918. if ($my_duration == 1 ) {
  919. $duration_list = $my_duration . ' ' . get_lang('MinMinute');
  920. } else {
  921. $duration_list = $my_duration. ' ' . get_lang('MinMinutes');
  922. }
  923. if ($results[$i]['exstep'] > 1) {
  924. //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
  925. $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )';
  926. }
  927. //$add_start_date = api_convert_and_format_date($start_date) . ' / ';
  928. } else {
  929. $duration_list = get_lang('NoLogOfDuration');
  930. //echo get_lang('NoLogOfDuration');
  931. }
  932. // Date conversion
  933. if ($is_allowedToEdit || $is_tutor) {
  934. $date_list = api_get_local_time($results[$i]['col4']). ' / ' . api_get_local_time($results[$i]['exdate']);
  935. } else {
  936. $date_list = api_get_local_time($results[$i]['col2']). ' / ' . api_get_local_time($results[$i]['exdate']);
  937. }
  938. // there are already a duration test period calculated??
  939. //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
  940. // if the float look like 10.00 we show only 10
  941. $my_res = $results[$i]['exresult'];
  942. $my_total = $results[$i]['exweight'];
  943. if (!$results[$i]['propagate_neg'] && $my_res < 0) {
  944. $my_res = 0;
  945. }
  946. $ex = show_score($my_res, $my_total);
  947. $result_list = $ex;
  948. $html_link = '';
  949. if ($is_allowedToEdit || $is_tutor) {
  950. if (in_array($results[$i]['excruid'], $teacher_id_list)) {
  951. $html_link.= Display::return_icon('teachers.gif', get_lang('Teacher'));
  952. }
  953. if ($revised) {
  954. $html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&id=$id'>".Display :: return_icon('edit.png', get_lang('Edit'), array(), 22);
  955. $html_link.= '&nbsp;';
  956. } else {
  957. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quiz.gif', get_lang('Qualify'));
  958. $html_link.='&nbsp;';
  959. }
  960. $html_link.="</a>";
  961. if ($is_allowedToEdit) {
  962. if ($filter==2){
  963. $html_link.=' <a href="exercise_history.php?'.api_get_cidreq().'&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
  964. }
  965. }
  966. if (api_is_platform_admin() || $is_tutor) {
  967. $html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&exerciseId='.$exercise_id.'&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.png', get_lang('Delete')).'</a>';
  968. $html_link.='&nbsp;';
  969. }
  970. } else {
  971. if ($revised) {
  972. $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&id=$id'>" . get_lang('Show') . "</a> ";
  973. } else {
  974. $html_link.='&nbsp;' . get_lang('NoResult');
  975. }
  976. }
  977. $more_details_list = $html_link;
  978. if ($is_allowedToEdit || $is_tutor) {
  979. $list_info[] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  980. } else {
  981. $list_info[] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
  982. }
  983. }
  984. }
  985. }
  986. } else {
  987. $hpresults = getManyResultsXCol($hpsql, 6);
  988. // Print HotPotatoes test results.
  989. if (is_array($hpresults)) {
  990. for ($i = 0; $i < sizeof($hpresults); $i++) {
  991. $hp_title = GetQuizName($hpresults[$i][2], $documentPath);
  992. if ($hp_title == '') {
  993. $hp_title = basename($hpresults[$i][2]);
  994. }
  995. //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
  996. $hp_date = api_get_local_time($hpresults[$i][5], null, date_default_timezone_get());
  997. $hp_result = round(($hpresults[$i][3] / ($hpresults[$i][4] != 0 ? $hpresults[$i][4] : 1)) * 100, 2).'% ('.$hpresults[$i][3].' / '.$hpresults[$i][4].')';
  998. if ($is_allowedToEdit || $is_tutor) {
  999. $list_info[] = array($hpresults[$i][0], $hpresults[$i][1], $hp_title, '-', $hp_date , $hp_result , '-');
  1000. } else {
  1001. $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
  1002. }
  1003. }
  1004. }
  1005. }
  1006. return $list_info;
  1007. }
  1008. /**
  1009. * Converts the score with the exercise_max_note and exercise_min_score the platform settings + formats the results using the float_format function
  1010. *
  1011. * @param float score
  1012. * @param float weight
  1013. * @param bool show porcentage or not
  1014. * @param bool use or not the platform settings
  1015. * @return string an html with the score modified
  1016. */
  1017. function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true) {
  1018. if (is_null($score) && is_null($weight)) {
  1019. return '-';
  1020. }
  1021. $html = '';
  1022. $score_rounded = $score;
  1023. $max_note = api_get_setting('exercise_max_score');
  1024. $min_note = api_get_setting('exercise_min_score');
  1025. if ($use_platform_settings) {
  1026. if ($max_note != '' && $min_note != '') {
  1027. if (!empty($weight) && intval($weight) != 0) {
  1028. $score = $min_note + ($max_note - $min_note) * $score /$weight;
  1029. } else {
  1030. $score = $min_note;
  1031. }
  1032. $weight = $max_note;
  1033. }
  1034. }
  1035. $score_rounded = float_format($score, 1);
  1036. $weight = float_format($weight, 1);
  1037. if ($show_percentage) {
  1038. $parent = '(' . $score_rounded . ' / ' . $weight . ')';
  1039. $html = float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1) . "% $parent";
  1040. } else {
  1041. $html = $score_rounded . ' / ' . $weight;
  1042. }
  1043. return $html;
  1044. }
  1045. /**
  1046. * Converts a numeric value in a percentage example 0.66666 to 66.67 %
  1047. * @param $value
  1048. * @return float Converted number
  1049. */
  1050. function convert_to_percentage($value) {
  1051. $return = '-';
  1052. if ($value != '') {
  1053. $return = float_format($value * 100, 1).' %';
  1054. }
  1055. return $return;
  1056. }
  1057. /**
  1058. * Converts a score/weight values to the platform scale
  1059. * @param float score
  1060. * @param float weight
  1061. * @return float the score rounded converted to the new range
  1062. */
  1063. function convert_score($score, $weight) {
  1064. $max_note = api_get_setting('exercise_max_score');
  1065. $min_note = api_get_setting('exercise_min_score');
  1066. if ($score != '' && $weight != '') {
  1067. if ($max_note != '' && $min_note != '') {
  1068. if (!empty($weight)) {
  1069. $score = $min_note + ($max_note - $min_note) * $score / $weight;
  1070. } else {
  1071. $score = $min_note;
  1072. }
  1073. }
  1074. }
  1075. $score_rounded = float_format($score, 1);
  1076. return $score_rounded;
  1077. }
  1078. /**
  1079. * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session)
  1080. * @param array course data
  1081. * @param int session id
  1082. * @return array array with exercise data
  1083. */
  1084. function get_all_exercises($course_info = null, $session_id = 0, $check_dates = false) {
  1085. if(!empty($course_info)) {
  1086. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['db_name']);
  1087. } else {
  1088. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  1089. }
  1090. if ($session_id == -1) {
  1091. $session_id = 0;
  1092. }
  1093. if ($session_id == 0) {
  1094. $conditions = array('where'=>array('active = ? AND session_id = ? '=>array('1', $session_id)), 'order'=>'title');
  1095. } else {
  1096. //All exercises
  1097. $conditions = array('where'=>array('active = ? AND (session_id = 0 OR session_id = ? )' =>array('1', $session_id)), 'order'=>'title');
  1098. }
  1099. //var_dump($conditions);
  1100. return Database::select('*',$TBL_EXERCICES, $conditions);
  1101. }
  1102. /**
  1103. * Gets the position of the score based in a given score (result/weight) and the exe_id based in the user list
  1104. * (NO Exercises in LPs )
  1105. * @param float user score to be compared *attention* $my_score = score/weight and not just the score
  1106. * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO)
  1107. * @param int exercise id
  1108. * @param string course code
  1109. * @param int session id
  1110. * @return int the position of the user between his friends in a course (or course within a session)
  1111. */
  1112. function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $return_string = true) {
  1113. if (empty($session_id)) {
  1114. $session_id = 0;
  1115. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  1116. $user_list = UserManager::get_user_list();
  1117. } else {
  1118. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  1119. $user_list = SessionManager::get_users_by_session($session_id);
  1120. }
  1121. //No score given we return
  1122. if (is_null($my_score)) {
  1123. return '-';
  1124. }
  1125. $best_attempts = array();
  1126. foreach($user_list as $user_data) {
  1127. $user_id = $user_data['user_id'];
  1128. $best_attempts[$user_id]= get_best_attempt_by_user($user_id,$exercise_id,$course_code,$session_id);
  1129. }
  1130. $position_data = array();
  1131. if (empty($best_attempts)) {
  1132. return 1;
  1133. } else {
  1134. $position = 1;
  1135. $my_ranking = array();
  1136. foreach($best_attempts as $user_id => $result) {
  1137. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1138. $my_ranking[$user_id] = $result['exe_result']/$result['exe_weighting'];
  1139. } else {
  1140. $my_ranking[$user_id] = 0;
  1141. }
  1142. }
  1143. //if (!empty($my_ranking)) {
  1144. asort($my_ranking);
  1145. $position = count($my_ranking);
  1146. if (!empty($my_ranking)) {
  1147. foreach($my_ranking as $user_id => $ranking) {
  1148. if ($my_score >= $ranking) {
  1149. if ($my_score == $ranking) {
  1150. $exe_id = $best_attempts[$user_id]['exe_id'];
  1151. if ($my_exe_id < $exe_id) {
  1152. $position--;
  1153. }
  1154. } else {
  1155. $position--;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. //}
  1161. $return_value = array('position'=>$position, 'count'=>count($my_ranking));
  1162. //var_dump($my_score, $my_ranking);
  1163. if ($return_string) {
  1164. if (!empty($position) && !empty($my_ranking)) {
  1165. $return_value = $position.'/'.count($my_ranking);
  1166. } else {
  1167. $return_value = '-';
  1168. }
  1169. }
  1170. return $return_value;
  1171. }
  1172. }
  1173. /**
  1174. * Gets the position of the score based in a given score (result/weight) and the exe_id based in all attempts
  1175. * (NO Exercises in LPs ) old funcionality by attempt
  1176. * @param float user score to be compared attention => score/weight
  1177. * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO)
  1178. * @param int exercise id
  1179. * @param string course code
  1180. * @param int session id
  1181. * @return int the position of the user between his friends in a course (or course within a session)
  1182. */
  1183. function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $return_string = true) {
  1184. if (empty($session_id)) {
  1185. $session_id = 0;
  1186. }
  1187. if (is_null($my_score)) {
  1188. return '-';
  1189. }
  1190. $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
  1191. $position_data = array();
  1192. if (empty($user_results)) {
  1193. return 1;
  1194. } else {
  1195. $position = 1;
  1196. $my_ranking = array();
  1197. foreach($user_results as $result) {
  1198. //print_r($result);
  1199. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1200. $my_ranking[$result['exe_id']] = $result['exe_result']/$result['exe_weighting'];
  1201. } else {
  1202. $my_ranking[$result['exe_id']] = 0;
  1203. }
  1204. }
  1205. asort($my_ranking);
  1206. $position = count($my_ranking);
  1207. if (!empty($my_ranking)) {
  1208. foreach($my_ranking as $exe_id=>$ranking) {
  1209. if ($my_score >= $ranking) {
  1210. if ($my_score == $ranking) {
  1211. if ($my_exe_id < $exe_id) {
  1212. $position--;
  1213. }
  1214. } else {
  1215. $position--;
  1216. }
  1217. }
  1218. }
  1219. }
  1220. $return_value = array('position'=>$position, 'count'=>count($my_ranking));
  1221. //var_dump($my_score, $my_ranking);
  1222. if ($return_string) {
  1223. if (!empty($position) && !empty($my_ranking)) {
  1224. return $position.'/'.count($my_ranking);
  1225. }
  1226. }
  1227. return $return_value;
  1228. }
  1229. }
  1230. /*
  1231. * Get the best attempt in a exercise (NO Exercises in LPs )
  1232. */
  1233. function get_best_attempt_in_course($exercise_id, $course_code, $session_id) {
  1234. $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
  1235. $best_score_data = array();
  1236. $best_score = 0;
  1237. if (!empty($user_results)) {
  1238. foreach($user_results as $result) {
  1239. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1240. $score = $result['exe_result']/$result['exe_weighting'];
  1241. if ($score >= $best_score) {
  1242. $best_score = $score;
  1243. $best_score_data = $result;
  1244. }
  1245. }
  1246. }
  1247. }
  1248. return $best_score_data;
  1249. }
  1250. /*
  1251. * Get the best score in a exercise (NO Exercises in LPs )
  1252. */
  1253. function get_best_attempt_by_user($user_id, $exercise_id, $course_code, $session_id) {
  1254. $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
  1255. $best_score_data = array();
  1256. $best_score = 0;
  1257. if (!empty($user_results)) {
  1258. foreach($user_results as $result) {
  1259. if ($result['exe_user_id'] != $user_id) continue;
  1260. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1261. $score = $result['exe_result']/$result['exe_weighting'];
  1262. if ($score >= $best_score) {
  1263. $best_score = $score;
  1264. $best_score_data = $result;
  1265. }
  1266. }
  1267. }
  1268. }
  1269. return $best_score_data;
  1270. }
  1271. /**
  1272. * Get average score (NO Exercises in LPs )
  1273. * @param int exercise id
  1274. * @param string course code
  1275. * @param int session id
  1276. * @return float Average score
  1277. */
  1278. function get_average_score($exercise_id, $course_code, $session_id) {
  1279. $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
  1280. $avg_score_data = array();
  1281. $avg_score = 0;
  1282. if (!empty($user_results)) {
  1283. foreach($user_results as $result) {
  1284. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1285. $score = $result['exe_result']/$result['exe_weighting'];
  1286. $avg_score +=$score;
  1287. }
  1288. }
  1289. $avg_score = float_format($avg_score / count($user_results), 1);
  1290. }
  1291. return $avg_score;
  1292. }
  1293. /**
  1294. * Get average score by score (NO Exercises in LPs )
  1295. * @param int exercise id
  1296. * @param string course code
  1297. * @param int session id
  1298. * @return float Average score
  1299. */
  1300. function get_average_score_by_course($course_code, $session_id) {
  1301. $user_results = get_all_exercise_results_by_course($course_code, $session_id, false);
  1302. //echo $course_code.' - '.$session_id.'<br />';
  1303. $avg_score = 0;
  1304. if (!empty($user_results)) {
  1305. foreach($user_results as $result) {
  1306. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1307. $score = $result['exe_result']/$result['exe_weighting'];
  1308. //var_dump($score);
  1309. $avg_score +=$score;
  1310. }
  1311. }
  1312. //We asume that all exe_weighting
  1313. //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']);
  1314. $avg_score = ($avg_score / count($user_results));
  1315. }
  1316. //var_dump($avg_score);
  1317. return $avg_score;
  1318. }
  1319. function get_average_score_by_course_by_user($user_id, $course_code, $session_id) {
  1320. $user_results = get_all_exercise_results_by_user($user_id, $course_code, $session_id, false);
  1321. $avg_score = 0;
  1322. if (!empty($user_results)) {
  1323. foreach($user_results as $result) {
  1324. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1325. $score = $result['exe_result']/$result['exe_weighting'];
  1326. $avg_score +=$score;
  1327. }
  1328. }
  1329. //We asume that all exe_weighting
  1330. //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']);
  1331. $avg_score = ($avg_score / count($user_results));
  1332. }
  1333. return $avg_score;
  1334. }
  1335. /**
  1336. * Get average score by score (NO Exercises in LPs )
  1337. * @param int exercise id
  1338. * @param string course code
  1339. * @param int session id
  1340. * @return float Best average score
  1341. */
  1342. function get_best_average_score_by_exercise($exercise_id, $course_code, $session_id, $user_count) {
  1343. $user_results = get_best_exercise_results_by_user($exercise_id, $course_code, $session_id);
  1344. $avg_score = 0;
  1345. if (!empty($user_results)) {
  1346. foreach($user_results as $result) {
  1347. if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
  1348. $score = $result['exe_result']/$result['exe_weighting'];
  1349. $avg_score +=$score;
  1350. }
  1351. }
  1352. //We asume that all exe_weighting
  1353. //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']);
  1354. //$avg_score = ($avg_score / count($user_results));
  1355. if(!empty($user_count)) {
  1356. $avg_score = float_format($avg_score / $user_count, 1) * 100;
  1357. } else {
  1358. $avg_score = 0;
  1359. }
  1360. }
  1361. return $avg_score;
  1362. }