exercise_show.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  1. <?php //$id: $
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. *
  5. * @package dokeos.exercise
  6. * @author Julio Montoya Armas Added switchable fill in blank option added
  7. * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  8. *
  9. * @todo remove the debug code and use the general debug library
  10. * @todo use the Database:: functions
  11. * @todo small letters for table variables
  12. */
  13. // name of the language file that needs to be included
  14. $language_file=array('exercice','tracking');
  15. // including the global dokeos file
  16. require_once '../inc/global.inc.php';
  17. require_once '../inc/lib/course.lib.php';
  18. // including additional libraries
  19. require_once 'exercise.class.php';
  20. require_once 'question.class.php'; //also defines answer type constants
  21. require_once 'answer.class.php';
  22. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  23. require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  24. if ( empty ( $origin ) ) {
  25. $origin = $_REQUEST['origin'];
  26. }
  27. if ($origin == 'learnpath')
  28. api_protect_course_script();
  29. else
  30. api_protect_course_script(true);
  31. // Database table definitions
  32. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  33. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  34. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  35. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  36. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  37. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  38. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  39. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  40. $dsp_percent = false;
  41. $debug=0;
  42. if($debug>0) {
  43. echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);
  44. }
  45. // general parameters passed via POST/GET
  46. if ( empty ( $learnpath_id ) ) {
  47. $learnpath_id = $_REQUEST['learnpath_id'];
  48. }
  49. if ( empty ( $learnpath_item_id ) ) {
  50. $learnpath_item_id = $_REQUEST['learnpath_item_id'];
  51. }
  52. if ( empty ( $formSent ) ) {
  53. $formSent= $_REQUEST['formSent'];
  54. }
  55. if ( empty ( $exerciseResult ) ) {
  56. $exerciseResult = $_SESSION['exerciseResult'];
  57. }
  58. if ( empty ( $questionId ) ) {
  59. $questionId = $_REQUEST['questionId'];
  60. }
  61. if ( empty ( $choice ) ) {
  62. $choice = $_REQUEST['choice'];
  63. }
  64. if ( empty ( $questionNum ) ) {
  65. $questionNum = $_REQUEST['questionNum'];
  66. }
  67. if ( empty ( $nbrQuestions ) ) {
  68. $nbrQuestions = $_REQUEST['nbrQuestions'];
  69. }
  70. if ( empty ( $questionList ) ) {
  71. $questionList = $_SESSION['questionList'];
  72. }
  73. if ( empty ( $objExercise ) ) {
  74. $objExercise = $_SESSION['objExercise'];
  75. }
  76. if ( empty ( $exeId ) ) {
  77. $exeId = $_REQUEST['id'];
  78. }
  79. if ( empty ( $action ) ) {
  80. $action = $_GET['action'];
  81. }
  82. $current_user_id = api_get_user_id();
  83. $current_user_id = "'".$current_user_id."'";
  84. $current_attempt = $_SESSION['current_exercice_attempt'][$current_user_id];
  85. //Is fraudulent exercice
  86. $current_time = time();
  87. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  88. $expired_date = $_SESSION['expired_time'];
  89. $expired_time = strtotime($expired_date);
  90. //Validation in case of fraud
  91. $total_time_allowed = $expired_time + 30;
  92. if ($total_time_allowed < $current_time) {
  93. $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position=0 WHERE exe_id = '$current_attempt' ";
  94. Database::query($sql_fraud,__FILE__,__LINE__);
  95. }
  96. }
  97. //Unset session for clock time
  98. unset($_SESSION['current_exercice_attempt'][$current_user_id]);
  99. unset($_SESSION['expired_time']);
  100. unset($_SESSION['end_expired_time']);
  101. $is_allowedToEdit=api_is_allowed_to_edit(null,true) || $is_courseTutor;
  102. $nameTools=get_lang('CorrectTest');
  103. if (isset($_SESSION['gradebook'])){
  104. $gradebook= $_SESSION['gradebook'];
  105. }
  106. if (!empty($gradebook) && $gradebook=='view') {
  107. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('Gradebook'));
  108. }
  109. $fromlink = '';
  110. if($origin=='user_course') {
  111. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
  112. $interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student'])."&course=".$_course['id']."&details=true&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("DetailsStudentInCourse"));
  113. } else if($origin=='tracking_course') {
  114. //$interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
  115. //$interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student']).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  116. $interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
  117. $interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$cidReq.'&studentlist=true&id_session='.$_SESSION['id_session'], "name" => get_lang("Tracking"));
  118. $interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student']).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  119. $interbreadcrumb[] = array ("url" => "../mySpace/lp_tracking.php?action=stats&course=".$cidReq."&student_id=".Security::remove_XSS($_GET['student'])."&lp_id=".Security::remove_XSS($_GET['my_lp_id'])."&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("LearningPathDetails"));
  120. $from_myspace = false;
  121. if (isset ($_GET['from']) && $_GET['from'] == 'myspace') {
  122. $fromlink = '&from=myspace';
  123. $this_section = SECTION_TRACKING;
  124. } else {
  125. $this_section = SECTION_COURSES;
  126. }
  127. } elseif($origin=='student_progress') {
  128. $this_section = SECTION_TRACKING;
  129. $interbreadcrumb[] = array ("url" => "../auth/my_progress.php?id_session".Security::remove_XSS($_GET['id_session'])."&course=".$_cid, "name" => get_lang('MyProgress'));
  130. unset($_cid);
  131. } else {
  132. $interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  133. $this_section=SECTION_COURSES;
  134. }
  135. if ($origin != 'learnpath') {
  136. Display::display_header($nameTools,"Exercise");
  137. } else {
  138. Display::display_reduced_header();
  139. }
  140. $emailId = $_REQUEST['email'];
  141. $user_name = $_REQUEST['user'];
  142. $test = $_REQUEST['test'];
  143. $dt = $_REQUEST['dt'];
  144. $marks = $_REQUEST['res'];
  145. $id = $_REQUEST['id'];
  146. $sql_fb_type='SELECT feedback_type FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
  147. $res_fb_type=Database::query($sql_fb_type,__FILE__,__LINE__);
  148. $row_fb_type=Database::fetch_row($res_fb_type);
  149. $feedback_type = $row_fb_type[0];
  150. ?>
  151. <style type="text/css">
  152. <!--
  153. #comments {
  154. position:absolute;
  155. left:795px;
  156. top:0px;
  157. width:200px;
  158. height:75px;
  159. z-index:1;
  160. }
  161. -->
  162. </style>
  163. <script language="javascript">
  164. function showfck(sid,marksid)
  165. {
  166. document.getElementById(sid).style.display='block';
  167. document.getElementById(marksid).style.display='block';
  168. var comment = 'feedback_'+sid;
  169. document.getElementById(comment).style.display='none';
  170. }
  171. function getFCK(vals,marksid)
  172. {
  173. var f=document.getElementById('myform');
  174. var m_id = marksid.split(',');
  175. for(var i=0;i<m_id.length;i++){
  176. var oHidn = document.createElement("input");
  177. oHidn.type = "hidden";
  178. var selname = oHidn.name = "marks_"+m_id[i];
  179. var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
  180. oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
  181. f.appendChild(oHidn);
  182. }
  183. var ids = vals.split(',');
  184. for(var k=0;k<ids.length;k++){
  185. var oHidden = document.createElement("input");
  186. oHidden.type = "hidden";
  187. oHidden.name = "comments_"+ids[k];
  188. oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
  189. oHidden.value = oEditor.GetXHTML(true);
  190. f.appendChild(oHidden);
  191. }
  192. //f.submit();
  193. }
  194. </script>
  195. <?php
  196. /**
  197. * This function gets the comments of an exercise
  198. *
  199. * @param int $id
  200. * @param int $question_id
  201. * @return str the comment
  202. */
  203. function get_comments($id,$question_id)
  204. {
  205. global $TBL_TRACK_ATTEMPT;
  206. $sql = "SELECT teacher_comment FROM ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
  207. $sqlres = Database::query($sql, __FILE__, __LINE__);
  208. $comm = Database::result($sqlres,0,"teacher_comment");
  209. return $comm;
  210. }
  211. /**
  212. * Display the answers to a multiple choice question
  213. *
  214. * @param integer Answer type
  215. * @param integer Student choice
  216. * @param string Textual answer
  217. * @param string Comment on answer
  218. * @param string Correct answer comment
  219. * @param integer Exercise ID
  220. * @param integer Question ID
  221. * @param boolean Whether to show the answer comment or not
  222. * @return void
  223. */
  224. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
  225. {
  226. global $feedback_type;
  227. ?>
  228. <tr>
  229. <td width="5%" align="center">
  230. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  231. border="0" alt="" />
  232. </td>
  233. <td width="5%" align="center">
  234. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  235. border="0" alt=" " />
  236. </td>
  237. <td width="40%" style="border-bottom: 1px solid #4171B5;">
  238. <?php
  239. $answer=api_parse_tex($answer);
  240. echo $answer;
  241. ?>
  242. </td>
  243. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  244. <td width="20%" style="border-bottom: 1px solid #4171B5;">
  245. <?php
  246. $answerComment=api_parse_tex($answerComment);
  247. if($studentChoice)
  248. {
  249. if(!$answerCorrect)
  250. {
  251. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  252. }
  253. else{
  254. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  255. }
  256. }
  257. else
  258. {
  259. echo '&nbsp;';
  260. }
  261. ?>
  262. </td>
  263. <?php
  264. if ($ans==1) {
  265. $comm = get_comments($id,$questionId);
  266. }
  267. ?>
  268. <?php } else { ?>
  269. <td>&nbsp;</td>
  270. <?php } ?>
  271. </tr>
  272. <?php
  273. }
  274. /**
  275. * Shows the answer to a fill-in-the-blanks question, as HTML
  276. * @param string Answer text
  277. * @param int Exercise ID
  278. * @param int Question ID
  279. * @return void
  280. */
  281. function display_fill_in_blanks_answer($answer,$id,$questionId)
  282. { global $feedback_type;
  283. ?>
  284. <tr>
  285. <td>
  286. <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
  287. </td>
  288. <?php
  289. if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
  290. <td>
  291. <?php
  292. $comm = get_comments($id,$questionId);
  293. ?>
  294. </td>
  295. <?php } ?>
  296. </tr>
  297. <?php
  298. }
  299. /**
  300. * Shows the answer to a free-answer question, as HTML
  301. * @param string Answer text
  302. * @param int Exercise ID
  303. * @param int Question ID
  304. * @return void
  305. */
  306. function display_free_answer($answer,$id,$questionId) {
  307. global $feedback_type;
  308. ?>
  309. <tr>
  310. <td>
  311. <?php if (!empty($answer)) {echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY));} ?>
  312. </td>
  313. <?php if(!api_is_allowed_to_edit(null,true) && $feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {?>
  314. <td>
  315. <?php
  316. $comm = get_comments($id,$questionId);
  317. ?>
  318. </td>
  319. <?php }?>
  320. </tr>
  321. <?php
  322. }
  323. /**
  324. * Displays the answer to a hotspot question
  325. *
  326. * @param int $answerId
  327. * @param string $answer
  328. * @param string $studentChoice
  329. * @param string $answerComment
  330. */
  331. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment) {
  332. global $feedback_type;
  333. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  334. "#4271B5",
  335. "#FE8E16",
  336. "#3B3B3B",
  337. "#BCD631",
  338. "#D63173",
  339. "#D7D7D7",
  340. "#90AFDD",
  341. "#AF8640",
  342. "#4F9242",
  343. "#F4EB24",
  344. "#ED2024",
  345. "#45C7F0",
  346. "#F7BDE2");
  347. ?>
  348. <tr>
  349. <td width="100px" valign="top" align="left">
  350. <div style="width:100%;">
  351. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  352. <div style="float:left; padding-left:5px;">
  353. <?php echo $answerId; ?>
  354. </div>
  355. <div><?php echo '&nbsp;'.$answer ?></div>
  356. </div>
  357. </td>
  358. <td width="50px" style="padding-right:15px" valign="top" align="left">
  359. <?php
  360. $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $my_choice; ?>
  361. </td>
  362. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  363. <td valign="top" align="left" >
  364. <?php
  365. $answerComment=api_parse_tex($answerComment);
  366. if($studentChoice) {
  367. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  368. } else {
  369. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  370. }
  371. ?>
  372. </td>
  373. <?php } else { ?>
  374. <td>&nbsp;</td>
  375. <?php } ?>
  376. </tr>
  377. <?php
  378. }
  379. /*
  380. ==============================================================================
  381. MAIN CODE
  382. ==============================================================================
  383. */
  384. // Email configuration settings
  385. $coursecode = api_get_course_id();
  386. $courseName = $_SESSION['_course']['name'];
  387. $to = '';
  388. $teachers = array();
  389. if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) {
  390. $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  391. } else {
  392. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  393. }
  394. $num = count($teachers);
  395. if($num>1) {
  396. $to = array();
  397. foreach($teachers as $teacher) {
  398. $to[] = $teacher['email'];
  399. }
  400. } elseif ($num>0){
  401. foreach($teachers as $teacher) {
  402. $to = $teacher['email'];
  403. }
  404. } else {
  405. //this is a problem (it means that there is no admin for this course)
  406. }
  407. ?>
  408. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  409. <tr>
  410. <td colspan="2">
  411. <?php
  412. $sql_test_name='SELECT title, description, results_disabled FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
  413. $result=Database::query($sql_test_name);
  414. $show_results = true;
  415. // Avoiding the "Score 0/0" message when the exe_id is not set
  416. if (Database::num_rows($result)>0 && isset($id)) {
  417. $test=Database::result($result,0,0);
  418. $exerciseTitle=api_parse_tex($test);
  419. $exerciseDescription=Database::result($result,0,1);
  420. // if the results_disabled of the Quiz is 1 when block the script
  421. $result_disabled=Database::result($result,0,2);
  422. if (!(api_is_platform_admin() || api_is_course_admin()) ) {
  423. if ($result_disabled==1) {
  424. //api_not_allowed();
  425. $show_results = false;
  426. //Display::display_warning_message(get_lang('CantViewResults'));
  427. if ($origin!='learnpath') {
  428. Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
  429. echo '</td>
  430. </tr>
  431. </table>';
  432. }
  433. }
  434. }
  435. if ($show_results == true) {
  436. $user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($_user['user_id'])." ";
  437. $query = "SELECT attempts.question_id, answer from ".$TBL_TRACK_ATTEMPT." as attempts
  438. INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
  439. INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
  440. INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
  441. WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
  442. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  443. //GROUP BY questions.position, attempts.question_id";
  444. $result =Database::query($query, __FILE__, __LINE__);
  445. }
  446. } else {
  447. Display::display_warning_message(get_lang('CantViewResults'));
  448. $show_results = false;
  449. echo '</td>
  450. </tr>
  451. </table>';
  452. }
  453. if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
  454. $show_results = false;
  455. }
  456. if ($show_results == true ) {
  457. ?>
  458. <table width="100%">
  459. <tr>
  460. <td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('CourseTitle')?> : </div></td>
  461. <td><div class="actions-message" width="90%"><?php echo $_course['name'] ?></div></td>
  462. </tr>
  463. <tr>
  464. <td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('User')?> : </div></td>
  465. <td><div class="actions-message" width="90%"><?php
  466. if (isset($_GET['cidReq'])) {
  467. $course_code=Security::remove_XSS($_GET['cidReq']);
  468. } else {
  469. $course_code=api_get_course_id();
  470. }
  471. if (isset($_GET['student'])) {
  472. $user_id=Security::remove_XSS($_GET['student']);
  473. }else {
  474. $user_id=api_get_user_id();
  475. }
  476. $status_info=CourseManager::get_user_in_course_status($user_id,$course_code);
  477. if (STUDENT==$status_info) {
  478. $user_info=api_get_user_info($user_id);
  479. echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
  480. } elseif(COURSEMANAGER==$status_info && !isset($_GET['user'])) {
  481. $user_info=api_get_user_info($user_id);
  482. echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
  483. } else {
  484. echo $user_name;
  485. }
  486. ?></div></td>
  487. </tr>
  488. <tr>
  489. <td style="font-weight:bold" width="10%" class="actions-message">
  490. <?php echo '&nbsp;'.get_lang("Exercise").' :'; ?>
  491. </td>
  492. <td width="90%">
  493. <?php echo $test; ?><br />
  494. <?php echo $exerciseDescription; ?>
  495. </td>
  496. </tr>
  497. </table>
  498. <br />
  499. </table>
  500. <?php
  501. }
  502. $i=$totalScore=$totalWeighting=0;
  503. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  504. $arrques = array();
  505. $arrans = array();
  506. if ($show_results) {
  507. $questionList = array();
  508. $exerciseResult = array();
  509. $k=0;
  510. $counter=0;
  511. while ($row = Database::fetch_array($result)) {
  512. $questionList[] = $row['question_id'];
  513. $exerciseResult[] = $row['answer'];
  514. }
  515. // for each question
  516. foreach($questionList as $questionId) {
  517. $counter++;
  518. $k++;
  519. $choice=$exerciseResult[$questionId];
  520. // creates a temporary Question object
  521. $objQuestionTmp = Question::read($questionId);
  522. $questionName=$objQuestionTmp->selectTitle();
  523. $questionDescription=$objQuestionTmp->selectDescription();
  524. $questionWeighting=$objQuestionTmp->selectWeighting();
  525. $answerType=$objQuestionTmp->selectType();
  526. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  527. // destruction of the Question object
  528. unset($objQuestionTmp);
  529. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  530. $colspan=2;
  531. }
  532. if($answerType == MATCHING || $answerType == FREE_ANSWER) {
  533. $colspan=2;
  534. } else {
  535. $colspan=2;
  536. }
  537. ?>
  538. <div id="question_title" class="sectiontitle">
  539. <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
  540. </div>
  541. <div id="question_description">
  542. <?php echo $questionDescription; ?>
  543. </div>
  544. <?php
  545. if ($answerType == MULTIPLE_ANSWER) {
  546. $choice=array();
  547. ?>
  548. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  549. <tr>
  550. <td>&nbsp;</td>
  551. </tr>
  552. <tr>
  553. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  554. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  555. <td><i><?php echo get_lang("Answer"); ?></i></td>
  556. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  557. <td><i><?php echo get_lang("Comment"); ?></i></td>
  558. <?php } else { ?>
  559. <td>&nbsp;</td>
  560. <?php } ?>
  561. </tr>
  562. <tr>
  563. <td>&nbsp;</td>
  564. </tr>
  565. <?php
  566. // construction of the Answer object
  567. $objAnswerTmp=new Answer($questionId);
  568. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  569. $questionScore=0;
  570. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  571. $answer=$objAnswerTmp->selectAnswer($answerId);
  572. $answerComment=$objAnswerTmp->selectComment($answerId);
  573. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  574. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  575. $queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  576. $resultans = Database::query($queryans, __FILE__, __LINE__);
  577. while ($row = Database::fetch_array($resultans)) {
  578. $ind = $row['answer'];
  579. $choice[$ind] = 1;
  580. }
  581. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  582. $studentChoice=$choice[$numAnswer];
  583. if ($studentChoice) {
  584. $questionScore+=$answerWeighting;
  585. $totalScore+=$answerWeighting;
  586. }
  587. echo '<tr><td>';
  588. if ($answerId==1) {
  589. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  590. } else {
  591. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  592. }
  593. echo '</td></tr>';
  594. $i++;
  595. }
  596. echo '</table>';
  597. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
  598. $choice=array();
  599. ?>
  600. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  601. <tr>
  602. <td>&nbsp;</td>
  603. </tr>
  604. <tr>
  605. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  606. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  607. <td><i><?php echo get_lang("Answer"); ?></i></td>
  608. <td><i><?php echo get_lang("Comment"); ?></i></td>
  609. </tr>
  610. <tr>
  611. <td>&nbsp;</td>
  612. </tr>
  613. <?php
  614. // construction of the Answer object
  615. $objAnswerTmp=new Answer($questionId);
  616. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  617. $questionScore=0;
  618. $real_answers = array();
  619. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  620. $answer=$objAnswerTmp->selectAnswer($answerId);
  621. $answerComment=$objAnswerTmp->selectComment($answerId);
  622. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  623. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  624. $queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  625. $resultans = Database::query($queryans, __FILE__, __LINE__);
  626. while ($row = Database::fetch_array($resultans)) {
  627. $ind = $row['answer'];
  628. $choice[$ind] = 1;
  629. }
  630. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  631. $studentChoice=$choice[$numAnswer];
  632. if ($answerCorrect == 1) {
  633. if ($studentChoice) {
  634. $real_answers[$answerId] = true;
  635. } else {
  636. $real_answers[$answerId] = false;
  637. }
  638. } else {
  639. if ($studentChoice) {
  640. $real_answers[$answerId] = false;
  641. } else {
  642. $real_answers[$answerId] = true;
  643. }
  644. }
  645. echo '<tr><td>';
  646. if ($answerId==1) {
  647. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  648. } else {
  649. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  650. }
  651. echo '</td></tr>';
  652. $i++;
  653. }
  654. $final_answer = true;
  655. foreach($real_answers as $my_answer) {
  656. if (!$my_answer) {
  657. $final_answer = false;
  658. }
  659. }
  660. if ($final_answer) {
  661. //getting only the first score where we save the weight of all the question
  662. $answerWeighting=$objAnswerTmp->selectWeighting(1);
  663. $questionScore+=$answerWeighting;
  664. $totalScore+=$answerWeighting;
  665. }
  666. echo '</table>';
  667. } elseif ($answerType == UNIQUE_ANSWER) {
  668. ?>
  669. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  670. <tr>
  671. <td>&nbsp;</td>
  672. </tr>
  673. <tr>
  674. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  675. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  676. <td><i><?php echo get_lang("Answer"); ?></i></td>
  677. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  678. <td><i><?php echo get_lang("Comment"); ?></i></td>
  679. <?php } else { ?>
  680. <td>&nbsp;</td>
  681. <?php } ?>
  682. </tr>
  683. <tr>
  684. <td>&nbsp;</td>
  685. </tr>
  686. <?php
  687. $objAnswerTmp=new Answer($questionId);
  688. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  689. $questionScore=0;
  690. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  691. $answer=$objAnswerTmp->selectAnswer($answerId);
  692. $answerComment=$objAnswerTmp->selectComment($answerId);
  693. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  694. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  695. $queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  696. $resultans = Database::query($queryans, __FILE__, __LINE__);
  697. $choice = Database::result($resultans,0,"answer");
  698. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  699. $studentChoice=($choice == $numAnswer)?1:0;
  700. if ($studentChoice) {
  701. $questionScore+=$answerWeighting;
  702. $totalScore+=$answerWeighting;
  703. }
  704. echo '<tr><td>';
  705. if ($answerId==1) {
  706. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  707. } else {
  708. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  709. }
  710. echo '</td></tr>';
  711. $i++;
  712. }
  713. echo '</table>';
  714. } elseif ($answerType == FILL_IN_BLANKS) {
  715. ?>
  716. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  717. <tr>
  718. <td>&nbsp;</td>
  719. </tr>
  720. <tr>
  721. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  722. </tr>
  723. <tr>
  724. <td>&nbsp;</td>
  725. </tr>
  726. <?php
  727. $objAnswerTmp=new Answer($questionId);
  728. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  729. $questionScore=0;
  730. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  731. $answer = $objAnswerTmp->selectAnswer($answerId);
  732. $answerComment = $objAnswerTmp->selectComment($answerId);
  733. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  734. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  735. // the question is encoded like this
  736. // [A] B [C] D [E] F::10,10,10@1
  737. // number 1 before the "@" means that is a switchable fill in blank question
  738. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  739. // means that is a normal fill blank question
  740. $pre_array = explode('::', $answer);
  741. // is switchable fill blank or not
  742. $is_set_switchable = explode('@', $pre_array[1]);
  743. $switchable_answer_set=false;
  744. if ($is_set_switchable[1]==1) {
  745. $switchable_answer_set=true;
  746. }
  747. $answer = $pre_array[0];
  748. // splits weightings that are joined with a comma
  749. $answerWeighting = explode(',',$is_set_switchable[0]);
  750. //list($answer,$answerWeighting)=explode('::',$multiple[0]);
  751. //$answerWeighting=explode(',',$answerWeighting);
  752. // we save the answer because it will be modified
  753. $temp=$answer;
  754. // TeX parsing
  755. // 1. find everything between the [tex] and [/tex] tags
  756. $startlocations=api_strpos($temp,'[tex]');
  757. $endlocations=api_strpos($temp,'[/tex]');
  758. if ($startlocations !== false && $endlocations !== false) {
  759. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  760. // 2. replace this by {texcode}
  761. $temp=str_replace($texstring,'{texcode}',$temp);
  762. }
  763. $j=0;
  764. // the loop will stop at the end of the text
  765. $i=0;
  766. //normal fill in blank
  767. if (!$switchable_answer_set) {
  768. while (1) {
  769. // quits the loop if there are no more blanks
  770. if (($pos = api_strpos($temp,'[')) === false) {
  771. // adds the end of the text
  772. $answer.=$temp;
  773. // TeX parsing
  774. $texstring = api_parse_tex($texstring);
  775. break;
  776. }
  777. $temp=api_substr($temp,$pos+1);
  778. // quits the loop if there are no more blanks
  779. if (($pos = api_strpos($temp,']')) === false) {
  780. break;
  781. }
  782. $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  783. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  784. $str = Database::result($resfill,0,"answer");
  785. preg_match_all('#\[([^[]*)\]#', $str, $arr);
  786. $choice = $arr[1];
  787. $tmp=strrpos($choice[$j],' / ');
  788. $choice[$j]=substr($choice[$j],0,$tmp);
  789. $choice[$j]=trim($choice[$j]);
  790. // if the word entered by the student IS the same as the one defined by the professor
  791. if (api_strtolower(api_substr($temp,0,$pos)) == api_strtolower($choice[$j])) {
  792. // gives the related weighting to the student
  793. $questionScore+=$answerWeighting[$j];
  794. // increments total score
  795. $totalScore+=$answerWeighting[$j];
  796. }
  797. // else if the word entered by the student IS NOT the same as the one defined by the professor
  798. $j++;
  799. $temp=api_substr($temp,$pos+1);
  800. $i=$i+1;
  801. }
  802. $answer = stripslashes($str);
  803. $answer = str_replace('rn', '', $answer);
  804. } else {
  805. //multiple fill in blank
  806. while (1) {
  807. // quits the loop if there are no more blanks
  808. if (($pos = api_strpos($temp,'[')) === false) {
  809. // adds the end of the text
  810. $answer.=$temp;
  811. // TeX parsing
  812. $texstring = api_parse_tex($texstring);
  813. //$answer=str_replace("{texcode}",$texstring,$answer);
  814. break;
  815. }
  816. // adds the piece of text that is before the blank and ended by [
  817. $real_text[]=api_substr($temp,0,$pos+1);
  818. $answer.=api_substr($temp,0,$pos+1);
  819. $temp=api_substr($temp,$pos+1);
  820. // quits the loop if there are no more blanks
  821. if (($pos = api_strpos($temp,']')) === false) {
  822. // adds the end of the text
  823. //$answer.=$temp;
  824. break;
  825. }
  826. $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  827. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  828. $str=Database::result($resfill,0,"answer");
  829. preg_match_all ('#\[([^[/]*)/#', $str, $arr);
  830. $choice = $arr[1];
  831. $choice[$j]=trim($choice[$j]);
  832. $user_tags[]=api_strtolower($choice[$j]);
  833. $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
  834. $j++;
  835. $temp=api_substr($temp,$pos+1);
  836. $i=$i+1;
  837. }
  838. $answer='';
  839. for ($i=0;$i<count($correct_tags);$i++) {
  840. if (in_array($user_tags[$i],$correct_tags)) {
  841. // gives the related weighting to the student
  842. $questionScore+=$answerWeighting[$i];
  843. // increments total score
  844. $totalScore+=$answerWeighting[$i];
  845. }
  846. }
  847. $answer = stripslashes($str);
  848. $answer = str_replace('rn', '', $answer);
  849. }
  850. //echo $questionScore."-".$totalScore;
  851. echo '<tr><td>';
  852. display_fill_in_blanks_answer($answer,$id,$questionId);
  853. echo '</td></tr>';
  854. $i++;
  855. }
  856. echo '</table>';
  857. } elseif ($answerType == FREE_ANSWER) {$answer = $str;
  858. ?>
  859. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  860. <tr>
  861. <td>&nbsp;</td>
  862. </tr>
  863. <tr>
  864. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  865. </tr>
  866. <tr>
  867. <td>&nbsp;</td>
  868. </tr>
  869. <?php
  870. $objAnswerTmp = new Answer($questionId);
  871. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  872. $questionScore = 0;
  873. $query = "select answer, marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  874. $resq = Database::query($query);
  875. $choice = Database::result($resq,0,"answer");
  876. $choice = stripslashes($choice);
  877. $choice = str_replace('rn', '', $choice);
  878. $questionScore = Database::result($resq,0,"marks");
  879. if ($questionScore==-1) {
  880. $totalScore+=0;
  881. } else {
  882. $totalScore+=$questionScore;
  883. }
  884. $arrques[] = $questionName;
  885. $arrans[] = $choice;
  886. echo '<tr>
  887. <td valign="top">'.display_free_answer($choice, $id, $questionId).'</td>
  888. </tr>
  889. </table>';
  890. } elseif ($answerType == MATCHING) {
  891. $objAnswerTmp=new Answer($questionId);
  892. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  893. $TBL_TRACK_ATTEMPT= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  894. $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0';
  895. $res_answer = Database::query($sql_answer, __FILE__, __LINE__);
  896. // getting the real answer
  897. $real_list =array();
  898. while ($real_answer = Database::fetch_array($res_answer)) {
  899. $real_list[$real_answer['id']]= $real_answer['answer'];
  900. }
  901. $sql_select_answer = 'SELECT id, answer, correct, id_auto FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct<>0';
  902. $res_answers = Database::query($sql_select_answer, __FILE__, __LINE__);
  903. echo '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
  904. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  905. echo '<tr>
  906. <td><span style="font-style: italic;">'.get_lang("ElementList").'</span> </td>
  907. <td><span style="font-style: italic;">'.get_lang("CorrespondsTo").'</span></td>
  908. </tr>';
  909. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  910. $questionScore=0;
  911. while ($a_answers = Database::fetch_array($res_answers)) {
  912. $i_answer_id = $a_answers['id']; //3
  913. $s_answer_label = $a_answers['answer']; // your dady - you mother
  914. $i_answer_correct_answer = $a_answers['correct']; //1 - 2
  915. $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4
  916. $sql_user_answer = "SELECT answer
  917. FROM $TBL_TRACK_ATTEMPT
  918. WHERE exe_id = '$id' AND question_id = '$questionId' AND position='$i_answer_id_auto'";
  919. $res_user_answer = Database::query($sql_user_answer, __FILE__, __LINE__);
  920. if (Database::num_rows($res_user_answer)>0 ) {
  921. $s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking
  922. } else {
  923. $s_user_answer = 0;
  924. }
  925. $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
  926. $user_answer = '';
  927. if (!empty($s_user_answer)) {
  928. if ($s_user_answer == $i_answer_correct_answer) {
  929. $questionScore+=$i_answerWeighting;
  930. $totalScore+=$i_answerWeighting;
  931. $user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
  932. } else {
  933. $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
  934. }
  935. }
  936. echo '<tr>';
  937. echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
  938. echo '</tr>';
  939. }
  940. echo '</table>';
  941. } elseif ($answerType == HOT_SPOT) {
  942. ?>
  943. <table width="500" border="0">
  944. <?php
  945. $objAnswerTmp=new Answer($questionId);
  946. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  947. $questionScore=0;
  948. ?>
  949. <tr>
  950. <td valign="top" align="center" style="padding-left:0px;" >
  951. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">
  952. <?php
  953. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  954. $answer=$objAnswerTmp->selectAnswer($answerId);
  955. $answerComment=$objAnswerTmp->selectComment($answerId);
  956. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  957. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  958. $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  959. $query = "select hotspot_correct from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".Database::escape_string($id)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
  960. $resq=Database::query($query);
  961. $choice = Database::result($resq,0,"hotspot_correct");
  962. display_hotspot_answer($answerId,$answer,$choice,$answerComment);
  963. $i++;
  964. }
  965. $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  966. $resfree = Database::query($queryfree, __FILE__, __LINE__);
  967. $questionScore= Database::result($resfree,0,"marks");
  968. $totalScore+=$questionScore;
  969. echo '</table></td></tr>';
  970. echo '<tr>
  971. <td colspan="2">'.
  972. //<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="421">
  973. '<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
  974. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  975. </object>
  976. </td>
  977. </tr>
  978. </table><br/>';
  979. }
  980. echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
  981. if ($is_allowedToEdit) {
  982. echo '<tr><td>';
  983. $name = "fckdiv".$questionId;
  984. $marksname = "marksName".$questionId;
  985. ?>
  986. <br />
  987. <a href="javascript://" onclick="showfck('<?php echo $name; ?>','<?php echo $marksname; ?>');">
  988. <?php
  989. if ($answerType == FREE_ANSWER) {
  990. echo get_lang('EditCommentsAndMarks');
  991. } else {
  992. if ($action=='edit') {
  993. echo '<img src="../img/edit.gif"/>'.get_lang('EditIndividualComment');
  994. } else {
  995. echo get_lang('AddComments');
  996. }
  997. }
  998. echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
  999. $comnt = trim(get_comments($id,$questionId));
  1000. if (empty($comnt)) {
  1001. echo '<br />';
  1002. } else {
  1003. echo '<div id="question_feedback">'.$comnt.'</div>';
  1004. }
  1005. echo '</div><div id="'.$name.'" style="display:none">';
  1006. $arrid[] = $questionId;
  1007. $feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
  1008. $feedback_form->addElement('html','<br>');
  1009. $renderer =& $feedback_form->defaultRenderer();
  1010. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  1011. $renderer->setElementTemplate('<div align="left">{element}</div>');
  1012. $comnt = get_comments($id,$questionId);
  1013. ${user.$questionId}['comments_'.$questionId] = $comnt;
  1014. $feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
  1015. $feedback_form->addElement('html','<br>');
  1016. //$feedback_form->addElement('submit','submitQuestion',get_lang('Ok'));
  1017. $feedback_form->setDefaults(${user.$questionId});
  1018. $feedback_form->display();
  1019. echo '</div>';
  1020. } else {
  1021. $comnt = get_comments($id,$questionId);
  1022. echo '<tr><td><br />';
  1023. if (!empty($comnt)) {
  1024. echo '<b>'.get_lang('Feedback').'</b>';
  1025. echo '<div id="question_feedback">'.$comnt.'</div>';
  1026. }
  1027. echo '</td><td>';
  1028. }
  1029. if ($is_allowedToEdit) {
  1030. if ($answerType == FREE_ANSWER) {
  1031. $marksname = "marksName".$questionId;
  1032. ?>
  1033. <div id="<?php echo $marksname; ?>" style="display:none">
  1034. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  1035. <?php
  1036. $arrmarks[] = $questionId;
  1037. echo get_lang("AssignMarks");
  1038. echo "&nbsp;<select name='marks' id='marks'>";
  1039. for ($i=0;$i<=$questionWeighting;$i++) {
  1040. echo '<option '.(($i==$questionScore)?"selected='selected'":'').'>'.$i.'</option>';
  1041. }
  1042. echo '</select>';
  1043. echo '</form><br/ ></div>';
  1044. if ($questionScore==-1 ) {
  1045. $questionScore=0;
  1046. echo '<br />'.get_lang('notCorrectedYet');
  1047. }
  1048. } else {
  1049. $arrmarks[] = $questionId;
  1050. echo '<div id="'.$marksname.'" style="display:none"><form name="marksform_'.$questionId.'" method="post" action="">
  1051. <select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form><br/ ></div>';
  1052. }
  1053. } else {
  1054. if ($questionScore==-1) {
  1055. $questionScore=0;
  1056. }
  1057. }
  1058. ?>
  1059. </td>
  1060. </tr>
  1061. </table>
  1062. <?php
  1063. $my_total_score = float_format($questionScore,1);
  1064. $my_total_weight = float_format($questionWeighting,1);
  1065. echo '<div id="question_score">';
  1066. echo get_lang('Score')." : $my_total_score/$my_total_weight";
  1067. echo '</div>';
  1068. unset($objAnswerTmp);
  1069. $i++;
  1070. $totalWeighting+=$questionWeighting;
  1071. } // end of large foreach on questions
  1072. } //end of condition if $show_results
  1073. if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  1074. //$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
  1075. //Database::query($query,__FILE__,__LINE__);
  1076. if ($show_results) {
  1077. echo '<div id="question_score">'.get_lang('YourTotalScore')." ";
  1078. if($dsp_percent == true) {
  1079. $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
  1080. $my_result = float_format($my_result,1);
  1081. echo $my_result."%";
  1082. } else {
  1083. $my_total_score = float_format($totalScore,1);
  1084. $my_total_weight = float_format($totalWeighting,1);
  1085. echo $my_total_score."/".$my_total_weight;
  1086. }
  1087. echo '!</div>';
  1088. }
  1089. }
  1090. if (is_array($arrid) && is_array($arrmarks)) {
  1091. $strids = implode(",",$arrid);
  1092. $marksid = implode(",",$arrmarks);
  1093. }
  1094. if ($is_allowedToEdit) {
  1095. if (in_array($origin, array('tracking_course','user_course'))) {
  1096. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.urlencode($test).'&emailid='.$emailId.'&origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['cidReq'].$fromlink.'" method="post">';
  1097. echo ' <input type = "hidden" name="totalWeighting" value="'.$totalWeighting.'">';
  1098. if (isset($_GET['myid']) && isset($_GET['my_lp_id']) && isset($_GET['student'])) {
  1099. ?>
  1100. <input type = "hidden" name="lp_item_id" value="<?php echo Security::remove_XSS($_GET['myid']); ?>">
  1101. <input type = "hidden" name="lp_item_view_id" value="<?php echo Security::remove_XSS($_GET['my_lp_id']); ?>">
  1102. <input type = "hidden" name="student_id" value="<?php echo Security::remove_XSS($_GET['student']);?>">
  1103. <input type = "hidden" name="total_score" value="<?php echo $totalScore; ?>">
  1104. <input type = "hidden" name="total_time" value="<?php echo Security::remove_XSS($_GET['total_time']);?>">
  1105. <input type = "hidden" name="my_exe_exo_id" value="<?php echo Security::remove_XSS($_GET['my_exe_exo_id']); ?>">
  1106. <?php
  1107. }
  1108. } else {
  1109. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&totalWeighting='.$totalWeighting.'" method="post">';
  1110. }
  1111. if ($origin!='learnpath' && $origin!='student_progress') {
  1112. ?>
  1113. <button type="submit" class="save" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"><?php echo get_lang('FinishTest'); ?></button>
  1114. </form>
  1115. <?php
  1116. }
  1117. }
  1118. if ($origin=='student_progress' && !isset($_GET['my_lp_id'])) {?>
  1119. <button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Backs');?></button>
  1120. <?php
  1121. } else if($origin=='myprogress') {
  1122. ?>
  1123. <button type="button" class="save" onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id()?>'" value="<?php echo get_lang('Finish'); ?>" ><?php echo get_lang('Finish');?></button>
  1124. <?php
  1125. }
  1126. if ($origin != 'learnpath') {
  1127. $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  1128. //we are not in learnpath tool
  1129. Display::display_footer();
  1130. } else {
  1131. $url_email = api_get_path(WEB_CODE_PATH).'mySpace/lp_tracking.php?course='.api_get_course_id().'&origin=tracking_course&lp_id='.$learnpath_id.'&student_id='.api_get_user_id();
  1132. if (!isset($_GET['fb_type'])) {
  1133. $lp_mode = $_SESSION['lp_mode'];
  1134. $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
  1135. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  1136. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  1137. //record the results in the learning path, using the SCORM interface (API)
  1138. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  1139. echo '</body></html>';
  1140. } else {
  1141. if (!$is_allowedToEdit) {
  1142. send_notification($arrques, $arrans, $to);
  1143. }
  1144. Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
  1145. }
  1146. }
  1147. if (!$is_allowedToEdit) {
  1148. if ($origin != 'learnpath') {
  1149. send_notification($arrques, $arrans, $to);
  1150. }
  1151. }
  1152. //destroying the session
  1153. api_session_unregister('questionList');
  1154. unset ($questionList);
  1155. api_session_unregister('exerciseResult');
  1156. unset ($exerciseResult);
  1157. function send_notification($arrques, $arrans, $to) {
  1158. global $courseName, $exerciseTitle, $url_email;
  1159. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  1160. $user_info = UserManager::get_user_info_by_id(api_get_user_id());
  1161. if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
  1162. return '';
  1163. }
  1164. $mycharset = api_get_system_encoding();
  1165. $msg = '<html><head>
  1166. <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
  1167. <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
  1168. if(count($arrques)>0) {
  1169. $msg .= '<body>
  1170. <p>'.get_lang('OpenQuestionsAttempted').' :
  1171. </p>
  1172. <p>'.get_lang('AttemptDetails').' : <br />
  1173. </p>
  1174. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  1175. <tr>
  1176. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  1177. <td width="469" valign="top"><h2>#course#</h2></td>
  1178. </tr>
  1179. <tr>
  1180. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  1181. <td width="469" valign="top" class="outerframe">#exercise#</td>
  1182. </tr>
  1183. <tr>
  1184. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  1185. <td valign="top" >#firstName# #lastName#</td>
  1186. </tr>
  1187. <tr>
  1188. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  1189. <td valign="top"> #mail#</td>
  1190. </tr></table>
  1191. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  1192. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  1193. for($i=0;$i<sizeof($arrques);$i++) {
  1194. $msg.='
  1195. <tr>
  1196. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  1197. <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
  1198. </tr>
  1199. <tr>
  1200. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  1201. <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
  1202. </tr>';
  1203. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  1204. $msg= str_replace("#firstName#",$user_info['firstname'],$msg1);
  1205. $msg1= str_replace("#lastName#",$user_info['lastname'],$msg);
  1206. $msg= str_replace("#mail#",$user_info['email'],$msg1);
  1207. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  1208. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  1209. $msg1= str_replace("#i#",$i,$msg);
  1210. $msg= str_replace("#course#",$courseName,$msg1);
  1211. }
  1212. $msg.='</table><br>
  1213. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  1214. <a href="#url#">#url#</a></span></body></html>';
  1215. $msg1= str_replace("#url#",$url_email,$msg);
  1216. $mail_content = $msg1;
  1217. $subject = get_lang('OpenQuestionsAttempted');
  1218. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1219. $email_admin = api_get_setting('emailAdministrator');
  1220. $result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
  1221. } else {
  1222. $msg .= '<body>
  1223. <p>'.get_lang('ExerciseAttempted').' <br />
  1224. </p>
  1225. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  1226. <tr>
  1227. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  1228. <td width="469" valign="top"><h2>#course#</h2></td>
  1229. </tr>
  1230. <tr>
  1231. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  1232. <td width="469" valign="top" class="outerframe">#exercise#</td>
  1233. </tr>
  1234. <tr>
  1235. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  1236. '.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
  1237. </tr>
  1238. <tr>
  1239. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  1240. <td valign="top"> #mail#</td>
  1241. </tr></table>';
  1242. $msg= str_replace("#exercise#",$exerciseTitle,$msg);
  1243. $msg= str_replace("#firstName#",$user_info['firstname'],$msg);
  1244. $msg= str_replace("#lastName#",$user_info['lastname'],$msg);
  1245. $msg= str_replace("#mail#",$user_info['email'],$msg);
  1246. $msg= str_replace("#course#",$courseName,$msg);
  1247. $msg.='<br />
  1248. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  1249. <a href="#url#">#url#</a></span></body></html>';
  1250. $msg= str_replace("#url#",$url_email,$msg);
  1251. $mail_content = $msg;
  1252. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  1253. $email_admin = api_get_setting('emailAdministrator');
  1254. $subject = get_lang('ExerciseAttempted');
  1255. $result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
  1256. }
  1257. }