upload_exercise.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Upload quiz: This script shows the upload quiz feature
  5. * Initial work by Isaac flores on Nov 4 of 2010
  6. * Encoding fixes Julio Montoya
  7. * @package chamilo.exercise
  8. */
  9. use \ChamiloSession as Session;
  10. $language_file[] = 'learnpath';
  11. $language_file[] = 'exercice';
  12. // setting the help
  13. $help_content = 'exercise_upload';
  14. require_once '../inc/global.inc.php';
  15. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  16. require_once api_get_path(LIBRARY_PATH) . 'pear/excelreader/reader.php';
  17. require_once 'exercise.class.php';
  18. require_once 'question.class.php';
  19. require_once 'unique_answer.class.php';
  20. require_once '../newscorm/learnpath.class.php';
  21. require_once '../newscorm/learnpathItem.class.php';
  22. // Security check
  23. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  24. if (!$is_allowed_to_edit) {
  25. api_not_allowed(true);
  26. }
  27. // setting the tabs
  28. $this_section = SECTION_COURSES;
  29. $htmlHeadXtra[] = "<script>
  30. $(document).ready( function(){
  31. $('#user_custom_score').click(function() {
  32. $('#options').toggle();
  33. });
  34. });
  35. </script>";
  36. // Action handling
  37. lp_upload_quiz_action_handling();
  38. $interbreadcrumb[] = array(
  39. "url" => "exercice.php?".api_get_cidreq(),
  40. "name" => get_lang('Exercices'),
  41. );
  42. // Display the header
  43. Display :: display_header(get_lang('ImportExcelQuiz'), 'Exercises');
  44. if (isset($_GET['message'])) {
  45. if (in_array($_GET['message'], array('ExerciseEdited'))) {
  46. Display :: display_confirmation_message(get_lang($_GET['message']));
  47. }
  48. }
  49. // display the actions
  50. echo '<div class="actions">';
  51. echo lp_upload_quiz_actions();
  52. echo '</div>';
  53. // the main content
  54. lp_upload_quiz_main();
  55. function lp_upload_quiz_actions()
  56. {
  57. $return = '<a href="exercice.php?'.api_get_cidReq().'">'.
  58. Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  59. return $return;
  60. }
  61. function lp_upload_quiz_secondary_actions()
  62. {
  63. $return = '<a href="exercise_report.php?' . api_get_cidreq() . '">' .
  64. Display :: return_icon('reporting32.png', get_lang('Tracking')) . get_lang('Tracking') . '</a>';
  65. return $return;
  66. }
  67. function lp_upload_quiz_main() {
  68. // variable initialisation
  69. $lp_id = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : null;
  70. $form = new FormValidator(
  71. 'upload',
  72. 'POST',
  73. api_get_self().'?'.api_get_cidreq().'&lp_id='.$lp_id,
  74. '',
  75. array('enctype' => 'multipart/form-data')
  76. );
  77. $form->addElement('header', get_lang('ImportExcelQuiz'));
  78. $form->addElement('file', 'user_upload_quiz', get_lang('FileUpload'));
  79. $link = '<a href="../exercice/quiz_template.xls">'.
  80. Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')).get_lang('DownloadExcelTemplate').'</a>';
  81. $form->addElement('advanced_settings', $link);
  82. $table = new HTML_Table(array('class' => 'table'));
  83. $tableList = array(
  84. UNIQUE_ANSWER => get_lang('UniqueSelect'),
  85. MULTIPLE_ANSWER => get_lang('MultipleSelect'),
  86. FILL_IN_BLANKS => get_lang('FillBlanks'),
  87. MATCHING => get_lang('Matching'),
  88. FREE_ANSWER => get_lang('FreeAnswer'),
  89. GLOBAL_MULTIPLE_ANSWER => get_lang('GlobalMultipleAnswer')
  90. );
  91. $table->setHeaderContents(0, 0, get_lang('QuestionType'));
  92. $table->setHeaderContents(0, 1, '#');
  93. $row = 1;
  94. foreach ($tableList as $key => $label ) {
  95. $table->setCellContents($row, 0, $label);
  96. $table->setCellContents($row, 1, $key);
  97. $row++;
  98. }
  99. $table = $table->toHtml();
  100. $form->addElement('label', get_lang('QuestionType'), $table);
  101. $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id'=> 'user_custom_score'));
  102. $form->addElement('html', '<div id="options" style="display:none">');
  103. $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
  104. $form->addElement('text', 'incorrect_score', get_lang('IncorrectScore'));
  105. $form->addElement('html', '</div>');
  106. $form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
  107. $form->add_progress_bar();
  108. $form->addElement('style_submit_button', 'submit_upload_quiz', get_lang('Send'), 'class="upload"');
  109. // Display the upload field
  110. $form->display();
  111. }
  112. /**
  113. * Handles a given Excel spreadsheets as in the template provided
  114. */
  115. function lp_upload_quiz_action_handling() {
  116. global $debug;
  117. $_course = api_get_course_info();
  118. $courseId = $_course['real_id'];
  119. if (!isset($_POST['submit_upload_quiz'])) {
  120. return;
  121. }
  122. // Get the extension of the document.
  123. $path_info = pathinfo($_FILES['user_upload_quiz']['name']);
  124. // Check if the document is an Excel document
  125. if ($path_info['extension'] != 'xls') {
  126. return;
  127. }
  128. // Read the Excel document
  129. $data = new Spreadsheet_Excel_Reader();
  130. // Set output Encoding.
  131. $data->setOutputEncoding(api_get_system_encoding());
  132. // Reading the xls document.
  133. $data->read($_FILES['user_upload_quiz']['tmp_name']);
  134. $correctScore = isset($_POST['correct_score']) ? $_POST['correct_score'] : null;
  135. $incorrectScore = isset($_POST['incorrect_score']) ? $_POST['incorrect_score'] : null;
  136. $useCustomScore = isset($_POST['user_custom_score']) ? true : false;
  137. $propagateNegative = 0;
  138. if ($useCustomScore && !empty($incorrectScore)) {
  139. if ($incorrectScore < 0) {
  140. $propagateNegative = 1;
  141. }
  142. }
  143. // Variables
  144. $quiz_index = 0;
  145. $question_title_index = array();
  146. $question_name_index_init = array();
  147. $question_name_index_end = array();
  148. $score_index = array();
  149. $feedback_true_index = array();
  150. $feedback_false_index = array();
  151. $number_questions = 0;
  152. $question_description_index = array();
  153. $noNegativeScoreIndex = array();
  154. $questionTypeList = array();
  155. $questionTypeIndex = array();
  156. $categoryList = array();
  157. // Reading all the first column items sequentially to create breakpoints
  158. for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
  159. if ($data->sheets[0]['cells'][$i][1] == 'Quiz' && $i == 1) {
  160. $quiz_index = $i; // Quiz title position, only occurs once
  161. } elseif ($data->sheets[0]['cells'][$i][1] == 'Question') {
  162. $question_title_index[] = $i; // Question title position line
  163. $question_name_index_init[] = $i + 1; // Questions name 1st position line
  164. $number_questions++;
  165. } elseif ($data->sheets[0]['cells'][$i][1] == 'Score') {
  166. $question_name_index_end[] = $i - 1; // Question name position
  167. $score_index[] = $i; // Question score position
  168. } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackTrue') {
  169. $feedback_true_index[] = $i; // FeedbackTrue position (line)
  170. } elseif ($data->sheets[0]['cells'][$i][1] == 'FeedbackFalse') {
  171. $feedback_false_index[] = $i; // FeedbackFalse position (line)
  172. } elseif ($data->sheets[0]['cells'][$i][1] == 'EnrichQuestion') {
  173. $question_description_index[] = $i;
  174. } elseif ($data->sheets[0]['cells'][$i][1] == 'NoNegativeScore') {
  175. $noNegativeScoreIndex[] = $i;
  176. } elseif ($data->sheets[0]['cells'][$i][1] == 'QuestionType') {
  177. $questionTypeIndex[] = $i;
  178. }
  179. }
  180. // Variables
  181. $quiz = array();
  182. $question = array();
  183. $new_answer = array();
  184. $score_list = array();
  185. $feedback_true_list = array();
  186. $feedback_false_list = array();
  187. $question_description = array();
  188. $noNegativeScoreList = array();
  189. // Getting questions.
  190. $k = $z = $q = $l = $m = $n = 0;
  191. for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
  192. if (is_array($data->sheets[0]['cells'][$i])) {
  193. $column_data = $data->sheets[0]['cells'][$i];
  194. // Fill all column with data to have a full array
  195. for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) {
  196. if (empty($column_data[$x])) {
  197. $data->sheets[0]['cells'][$i][$x] = '';
  198. }
  199. }
  200. // Array filled with data
  201. $column_data = $data->sheets[0]['cells'][$i];
  202. } else {
  203. $column_data = '';
  204. }
  205. // Fill quiz data
  206. if ($quiz_index == $i) {
  207. // The title always in the first position
  208. $quiz = $column_data;
  209. } elseif (in_array($i, $question_title_index)) {
  210. //a complete line where 1st column is 'Question'
  211. $question[$k] = $column_data;
  212. for ($counter = 0; $counter < 12; $counter++) {
  213. $myData = isset($data->sheets[0]['cells'][$i + $counter]) ? $data->sheets[0]['cells'][$i + $counter] : null;
  214. if (isset($myData[1]) && $myData[1] == 'QuestionType') {
  215. $questionTypeList[$k] = $myData[3];
  216. }
  217. if (isset($myData[1]) && $myData[1] == 'Category') {
  218. $categoryList[$k] = $myData[2];
  219. }
  220. }
  221. if (!isset($questionTypeList[$k])) {
  222. $questionTypeList[$k] = null;
  223. }
  224. $k++;
  225. } elseif (in_array($i, $score_index)) {
  226. //a complete line where 1st column is 'Score'
  227. $score_list[$z] = $column_data;
  228. $z++;
  229. } elseif (in_array($i, $feedback_true_index)) {
  230. //a complete line where 1st column is 'FeedbackTrue'
  231. $feedback_true_list[$q] = $column_data;
  232. $q++;
  233. } elseif (in_array($i, $feedback_false_index)) {
  234. //a complete line where 1st column is 'FeedbackFalse' for wrong answers
  235. $feedback_false_list[$l] = $column_data;
  236. $l++;
  237. } elseif (in_array($i, $question_description_index)) {
  238. //a complete line where 1st column is 'EnrichQuestion'
  239. $question_description[$m] = $column_data;
  240. $m++;
  241. } elseif (in_array($i, $noNegativeScoreIndex)) {
  242. //a complete line where 1st column is 'NoNegativeScore'
  243. $noNegativeScoreList[$z - 1] = $column_data;
  244. }
  245. }
  246. // Get answers
  247. for ($i = 0; $i < count($question_name_index_init); $i++) {
  248. for ($j = $question_name_index_init[$i]; $j <= $question_name_index_end[$i]; $j++) {
  249. if (is_array($data->sheets[0]['cells'][$j])) {
  250. $column_data = $data->sheets[0]['cells'][$j];
  251. // Fill all column with data
  252. for ($x = 1; $x <= $data->sheets[0]['numCols']; $x++) {
  253. if (empty($column_data[$x])) {
  254. $data->sheets[0]['cells'][$j][$x] = '';
  255. }
  256. }
  257. $column_data = $data->sheets[0]['cells'][$j];
  258. // Array filled of data
  259. if (is_array($column_data) && count($column_data) > 0) {
  260. $new_answer[$i][$j] = $column_data;
  261. }
  262. }
  263. }
  264. }
  265. // Quiz title.
  266. $quiz_title = $quiz[2];
  267. if ($quiz_title != '') {
  268. // Variables
  269. $type = 2;
  270. $random = $active = $results = $max_attempt = $expired_time = 0;
  271. // Make sure feedback is enabled (3 to disable), otherwise the fields
  272. // added to the XLS are not shown, which is confusing
  273. $feedback = 0;
  274. // Quiz object
  275. $exercise = new Exercise();
  276. $quiz_id = $exercise->createExercise(
  277. $quiz_title,
  278. $expired_time,
  279. $type,
  280. $random,
  281. $active,
  282. $results,
  283. $max_attempt,
  284. $feedback,
  285. $propagateNegative
  286. );
  287. if ($quiz_id) {
  288. // insert into the item_property table
  289. api_item_property_update(
  290. $_course,
  291. TOOL_QUIZ,
  292. $quiz_id,
  293. 'QuizAdded',
  294. api_get_user_id()
  295. );
  296. // Import questions.
  297. for ($i = 0; $i < $number_questions; $i++) {
  298. // Question name
  299. $question_title = $question[$i][2];
  300. $description = isset($question_description[$i][2]) ? $question_description[$i][2] : '';
  301. $categoryId = null;
  302. if (isset($categoryList[$i]) && !empty($categoryList[$i])) {
  303. $categoryName = $categoryList[$i];
  304. $categoryId = Testcategory::get_category_id_for_title($categoryName, $courseId);
  305. if (empty($categoryId)) {
  306. $category = new Testcategory(null, $categoryName, '');
  307. $categoryId = $category->addCategoryInBDD();
  308. }
  309. }
  310. $question_description_text = "<p></p>";
  311. if (!empty($description)) {
  312. // Question description.
  313. $question_description_text = "<p>".$description."</p>";
  314. }
  315. // Unique answers are the only question types available for now
  316. // through xls-format import
  317. $answerList = isset($new_answer[$i]) ? $new_answer[$i] : '';
  318. $question_id = null;
  319. if (isset($questionTypeList[$i])) {
  320. $detectQuestionType = intval($questionTypeList[$i]);
  321. } else {
  322. $detectQuestionType = detectQuestionType(
  323. $answerList,
  324. $score_list
  325. );
  326. }
  327. /** @var Question $answer */
  328. switch ($detectQuestionType) {
  329. case FREE_ANSWER:
  330. $answer = new FreeAnswer();
  331. break;
  332. case GLOBAL_MULTIPLE_ANSWER:
  333. $answer = new GlobalMultipleAnswer();
  334. break;
  335. case MULTIPLE_ANSWER:
  336. $answer = new MultipleAnswer();
  337. break;
  338. case FILL_IN_BLANKS:
  339. $answer = new FillBlanks();
  340. $question_description_text = '';
  341. break;
  342. case MATCHING:
  343. $answer = new Matching();
  344. break;
  345. case UNIQUE_ANSWER:
  346. default:
  347. $answer = new UniqueAnswer();
  348. break;
  349. }
  350. if ($question_title != '') {
  351. $question_id = $answer->create_question(
  352. $quiz_id,
  353. $question_title,
  354. $question_description_text,
  355. 0, // max score
  356. $answer->type
  357. );
  358. if (!empty($categoryId)) {
  359. Testcategory::add_category_for_question_id(
  360. $categoryId,
  361. $question_id,
  362. $courseId
  363. );
  364. }
  365. }
  366. switch ($detectQuestionType) {
  367. case GLOBAL_MULTIPLE_ANSWER:
  368. case MULTIPLE_ANSWER:
  369. case UNIQUE_ANSWER:
  370. $total = 0;
  371. if (is_array($answerList) && !empty($question_id)) {
  372. $id = 1;
  373. $objAnswer = new Answer($question_id, $courseId);
  374. $globalScore = $score_list[$i][3];
  375. // Calculate the number of correct answers to divide the
  376. // score between them when importing from CSV
  377. $numberRightAnswers = 0;
  378. foreach ($answerList as $answer_data) {
  379. if (strtolower($answer_data[3]) == 'x') {
  380. $numberRightAnswers++;
  381. }
  382. }
  383. foreach ($answerList as $answer_data) {
  384. $answerValue = $answer_data[2];
  385. $correct = 0;
  386. $score = 0;
  387. if (strtolower($answer_data[3]) == 'x') {
  388. $correct = 1;
  389. $score = $score_list[$i][3];
  390. $comment = $feedback_true_list[$i][2];
  391. } else {
  392. $comment = $feedback_false_list[$i][2];
  393. $floatVal = (float)$answer_data[3];
  394. if (is_numeric($floatVal)) {
  395. $score = $answer_data[3];
  396. }
  397. }
  398. if ($useCustomScore) {
  399. if ($correct) {
  400. $score = $correctScore;
  401. } else {
  402. $score = $incorrectScore;
  403. }
  404. }
  405. // Fixing scores:
  406. switch ($detectQuestionType) {
  407. case GLOBAL_MULTIPLE_ANSWER:
  408. if (isset($noNegativeScoreList[$i][3])) {
  409. if (!(strtolower($noNegativeScoreList[$i][3]) == 'x') &&
  410. !$correct
  411. ) {
  412. $score = $score_list[$i][3] * -1;
  413. }
  414. } else {
  415. $score = $score_list[$i][3] * -1;
  416. }
  417. $score /= $numberRightAnswers;
  418. break;
  419. case UNIQUE_ANSWER:
  420. break;
  421. case MULTIPLE_ANSWER:
  422. if (!$correct) {
  423. //$total = $total - $score;
  424. }
  425. break;
  426. }
  427. $objAnswer->createAnswer(
  428. $answerValue,
  429. $correct,
  430. $comment,
  431. $score,
  432. $id
  433. );
  434. $total += $score;
  435. $id++;
  436. }
  437. $objAnswer->save();
  438. $questionObj = Question::read(
  439. $question_id,
  440. $courseId
  441. );
  442. switch ($detectQuestionType) {
  443. case GLOBAL_MULTIPLE_ANSWER:
  444. $questionObj->updateWeighting($globalScore);
  445. break;
  446. case UNIQUE_ANSWER:
  447. case MULTIPLE_ANSWER:
  448. default:
  449. $questionObj->updateWeighting($total);
  450. break;
  451. }
  452. $questionObj->save();
  453. }
  454. break;
  455. case FREE_ANSWER:
  456. $questionObj = Question::read($question_id, $courseId);
  457. $globalScore = $score_list[$i][3];
  458. $questionObj->updateWeighting($globalScore);
  459. $questionObj->save();
  460. break;
  461. case FILL_IN_BLANKS:
  462. $scoreList = array();
  463. $size = array();
  464. $globalScore = 0;
  465. foreach ($answerList as $data) {
  466. $score = isset($data[3]) ? $data[3] : 0;
  467. $globalScore += $score;
  468. $scoreList[] = $score;
  469. $size[] = 200;
  470. }
  471. $scoreToString = implode(',', $scoreList);
  472. $sizeToString = implode(',', $size);
  473. //<p>Texte long avec les [mots] à [remplir] mis entre [crochets]</p>::10,10,10:200.36363999999998,200,200:0@'
  474. $answerValue = $description.'::'.$scoreToString.':'.$sizeToString.':0@';
  475. $objAnswer = new Answer($question_id, $courseId);
  476. $objAnswer->createAnswer(
  477. $answerValue,
  478. '', //$correct,
  479. '', //$comment,
  480. $globalScore,
  481. 1
  482. );
  483. $objAnswer->save();
  484. $questionObj = Question::read($question_id, $courseId);
  485. $questionObj->updateWeighting($globalScore);
  486. $questionObj->save();
  487. break;
  488. case MATCHING:
  489. $globalScore = $score_list[$i][3];
  490. $position = 1;
  491. $objAnswer = new Answer($question_id, $courseId);
  492. foreach ($answerList as $data) {
  493. $option = isset($data[3]) ? $data[3] : '';
  494. $objAnswer->createAnswer($option, 0, '', 0, $position);
  495. $position++;
  496. }
  497. $counter = 1;
  498. foreach ($answerList as $data) {
  499. $value = isset($data[2]) ? $data[2] : '';
  500. $position++;
  501. $objAnswer->createAnswer(
  502. $value,
  503. $counter,
  504. ' ',
  505. $globalScore,
  506. $position
  507. );
  508. $counter++;
  509. }
  510. $objAnswer->save();
  511. $questionObj = Question::read($question_id, $courseId);
  512. $questionObj->updateWeighting($globalScore);
  513. $questionObj->save();
  514. break;
  515. }
  516. }
  517. }
  518. if (isset($_SESSION['lpobject'])) {
  519. if ($debug > 0) {
  520. error_log('New LP - SESSION[lpobject] is defined', 0);
  521. }
  522. $oLP = unserialize($_SESSION['lpobject']);
  523. if (is_object($oLP)) {
  524. if ($debug > 0) {
  525. error_log('New LP - oLP is object', 0);
  526. }
  527. if ((empty($oLP->cc)) OR $oLP->cc != api_get_course_id()) {
  528. if ($debug > 0) {
  529. error_log('New LP - Course has changed, discard lp object', 0);
  530. }
  531. $oLP = null;
  532. Session::erase('oLP');
  533. Session::erase('lpobject');
  534. } else {
  535. $_SESSION['oLP'] = $oLP;
  536. }
  537. }
  538. }
  539. if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) {
  540. $previous = $_SESSION['oLP']->select_previous_item_id();
  541. $parent = 0;
  542. // Add a Quiz as Lp Item
  543. $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, '');
  544. // Redirect to home page for add more content
  545. header('location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.Security::remove_XSS($_GET['lp_id']));
  546. exit;
  547. } else {
  548. // header('location: exercice.php?' . api_get_cidreq());
  549. echo '<script>window.location.href = "'.api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidReq().'&exerciseId='.$quiz_id.'&session_id='.api_get_session_id().'"</script>';
  550. }
  551. }
  552. }
  553. /**
  554. * @param array $answers_data
  555. * @return int
  556. */
  557. function detectQuestionType($answers_data) {
  558. $correct = 0;
  559. $isNumeric = false;
  560. if (empty($answers_data)) {
  561. return FREE_ANSWER;
  562. }
  563. foreach ($answers_data as $answer_data) {
  564. if (strtolower($answer_data[3]) == 'x') {
  565. $correct++;
  566. } else {
  567. if (is_numeric($answer_data[3])) {
  568. $isNumeric = true;
  569. }
  570. }
  571. }
  572. if ($correct == 1) {
  573. $type = UNIQUE_ANSWER;
  574. } else if ($correct > 1) {
  575. $type = MULTIPLE_ANSWER;
  576. } else {
  577. $type = FREE_ANSWER;
  578. }
  579. if ($type == MULTIPLE_ANSWER) {
  580. if ($isNumeric) {
  581. $type = MULTIPLE_ANSWER;
  582. } else {
  583. $type = GLOBAL_MULTIPLE_ANSWER;
  584. }
  585. }
  586. return $type;
  587. }
  588. if (!isset($origin) || isset($origin) && $origin != 'learnpath') {
  589. //so we are not in learnpath tool
  590. Display :: display_footer();
  591. }