exercise_import.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php // $Id: $
  2. if ( count( get_included_files() ) == 1 ) die( '---' );
  3. /**
  4. * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL)
  5. *
  6. * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  7. *
  8. * @package dokeos.exercise
  9. *
  10. * @author claro team <cvs@claroline.net>
  11. * @author Guillaume Lederer <guillaume@claroline.net>
  12. */
  13. /**
  14. * function to create a temporary directory (SAME AS IN MODULE ADMIN)
  15. */
  16. function tempdir($dir, $prefix='tmp', $mode=0777)
  17. {
  18. if (substr($dir, -1) != '/') $dir .= '/';
  19. do
  20. {
  21. $path = $dir.$prefix.mt_rand(0, 9999999);
  22. } while (!mkdir($path, $mode));
  23. return $path;
  24. }
  25. /**
  26. * @return the path of the temporary directory where the exercise was uploaded and unzipped
  27. */
  28. function get_and_unzip_uploaded_exercise()
  29. {
  30. $backlog_message = array();
  31. //Check if the file is valid (not to big and exists)
  32. if( !isset($_FILES['uploadedExercise'])
  33. || !is_uploaded_file($_FILES['uploadedExercise']['tmp_name']))
  34. {
  35. $backlog_message[] = get_lang('Problem with file upload');
  36. }
  37. else
  38. {
  39. $backlog_message[] = get_lang('Temporary file is : ') . $_FILES['uploadedExercise']['tmp_name'];
  40. }
  41. //1- Unzip folder in a new repository in claroline/module
  42. include_once (realpath(dirname(__FILE__) . '/../../inc/lib/pclzip/') . '/pclzip.lib.php');
  43. //unzip files
  44. $exerciseRepositorySys = get_conf('rootSys') . get_conf('exerciseRepository','cache/');
  45. //create temp dir for upload
  46. claro_mkdir($exerciseRepositorySys);
  47. $uploadDirFullPath = tempdir($exerciseRepositorySys);
  48. $uploadDir = str_replace($exerciseRepositorySys,'',$uploadDirFullPath);
  49. $exercisePath = $exerciseRepositorySys.$uploadDir.'/';
  50. if ( preg_match('/.zip$/i', $_FILES['uploadedExercise']['name']) && treat_uploaded_file($_FILES['uploadedExercise'],$exerciseRepositorySys, $uploadDir, get_conf('maxFilledSpaceForExercise' , 10000000),'unzip',true))
  51. {
  52. $backlog_message[] = get_lang('Files dezipped sucessfully in ' ) . $exercisePath;
  53. if (!function_exists('gzopen'))
  54. {
  55. $backlog_message[] = get_lang('Error : no zlib extension found');
  56. claro_delete_file($exercisePath);
  57. return claro_failure::set_failure($backlog_message);
  58. }
  59. }
  60. else
  61. {
  62. $backlog_message[] = get_lang('Impossible to unzip file');
  63. claro_delete_file($exercisePath);
  64. return claro_failure::set_failure($backlog_message);
  65. }
  66. return $exercisePath;
  67. }
  68. /**
  69. * main function to import an exercise,
  70. *
  71. * @return an array as a backlog of what was really imported, and error or debug messages to display
  72. */
  73. function import_exercise($file)
  74. {
  75. global $exercise_info;
  76. global $element_pile;
  77. global $non_HTML_tag_to_avoid;
  78. global $record_item_body;
  79. global $backlog_message;
  80. //get required table names
  81. $tbl_cdb_names = claro_sql_get_course_tbl();
  82. $tbl_quiz_exercise = $tbl_cdb_names['qwz_exercise'];
  83. $tbl_quiz_question = $tbl_cdb_names['qwz_question'];
  84. //set some default values for the new exercise
  85. $exercise_info = array();
  86. $exercise_info['name'] = preg_replace('/.zip$/i','' ,$file);
  87. $exercise_info['description'] = get_lang('undefined description');
  88. $exercise_info['question'] = array();
  89. $element_pile = array();
  90. $backlog_message = array();
  91. //create parser and array to retrieve info from manifest
  92. $element_pile = array(); //pile to known the depth in which we are
  93. $module_info = array(); //array to store the info we need
  94. //unzip the uploaded file in a tmp directory
  95. $exercisePath = get_and_unzip_uploaded_exercise();
  96. //find the different manifests for each question and parse them.
  97. $exerciseHandle = opendir($exercisePath);
  98. //find each question repository in the uploaded exercise folder
  99. array_push ($backlog_message, get_lang('XML question files found : '));
  100. $question_number = 0;
  101. //used to specify the question directory where files could be found in relation in any question
  102. global $questionTempDir;
  103. //1- parse the parent directory
  104. $questionHandle = opendir($exercisePath);
  105. while (false !== ($questionFile = readdir($questionHandle)))
  106. {
  107. if (preg_match('/.xml$/i' ,$questionFile))
  108. {
  109. array_push ($backlog_message, get_lang("XML question file found : ".$questionFile));
  110. parse_file($exercisePath, '', $questionFile);
  111. }//end if xml question file found
  112. }//end while question rep
  113. //2- parse every subdirectory to search xml question files
  114. while (false !== ($file = readdir($exerciseHandle)))
  115. {
  116. if (is_dir($exercisePath.$file) && $file != "." && $file != "..")
  117. {
  118. //find each manifest for each question repository found
  119. $questionHandle = opendir($exercisePath.$file);
  120. while (false !== ($questionFile = readdir($questionHandle)))
  121. {
  122. if (preg_match('/.xml$/i' ,$questionFile))
  123. {
  124. parse_file($exercisePath, $file, $questionFile);
  125. }//end if xml question file found
  126. }//end while question rep
  127. } //if is_dir
  128. }//end while loop to find each question data's
  129. //Display data found
  130. array_push ($backlog_message, 'Exercise name : <b>' . $exercise_info['name'] . '</b>');
  131. array_push ($backlog_message, 'Exercise description : ' . $exercise_info['description']);
  132. foreach ($exercise_info['question'] as $key => $question)
  133. {
  134. $question_number++;
  135. array_push ($backlog_message, '<b>'.$question_number.'-</b> Question found (' .$key. ') : <b>' . $question['title'] . '</b>');
  136. if (isset($question['statement'])) array_push ($backlog_message, '* Statement : ' . $question['statement']);
  137. array_push ($backlog_message, '* Type : ' . $question['type']);
  138. foreach ($exercise_info['question'][$key]['answer'] as $answer)
  139. {
  140. if ($question['type']=="MATCHING")
  141. {
  142. array_push ($backlog_message, '** Matchset : ');
  143. foreach ($answer as $matchSetElement)
  144. {
  145. array_push ($backlog_message, '*** Element ' . $matchSetElement);
  146. }
  147. }
  148. else
  149. {
  150. array_push ($backlog_message, '** Answer found : ' . $answer['value']);
  151. if (isset($answer['feedback'])) array_push ($backlog_message, '*** Answer feedback : ' . $answer['feedback']);
  152. }
  153. }
  154. if (isset($question['weighting']))
  155. {
  156. array_push ($backlog_message, '* WEIGHTING for Answers :');
  157. foreach ($question['weighting'] as $key => $weighting)
  158. {
  159. array_push ($backlog_message, '** Answer : '.$key.' ==> weighting : '.$weighting);
  160. }
  161. }
  162. if (isset($question['correct_answers']))
  163. {
  164. array_push ($backlog_message, '* CORRECT ANSWERS :');
  165. foreach ($question['correct_answers'] as $answerIdent)
  166. {
  167. array_push ($backlog_message, '* Answer : '.$answerIdent);
  168. }
  169. }
  170. if (isset($question['response_text']))
  171. {
  172. array_push ($backlog_message, '* Text to fill in : '.$question['response_text'] );
  173. }
  174. }
  175. //---------------------
  176. //add exercise in tool
  177. //---------------------
  178. //1.create exercise
  179. $exercise = new Exercise();
  180. $exercise->setTitle($exercise_info['name']);
  181. $exercise->setDescription($exercise_info['description']);
  182. if ($exercise->validate())
  183. {
  184. $exercise_id = $exercise->save();
  185. }
  186. else
  187. {
  188. array_push ($backlog_message, 'EXERCISE DATA INVALID !!!');
  189. }
  190. //For each question found...
  191. foreach($exercise_info['question'] as $key => $question_array)
  192. {
  193. //2.create question
  194. $question = new ImsQuestion();
  195. if (isset($question_array['title'])) $question->setTitle($question_array['title']);
  196. if (isset($question_array['statement'])) $question->setDescription($question_array['statement']);
  197. $question->setType($question_array['type']);
  198. if ($question->validate())
  199. {
  200. $question_id = $question->save();
  201. if ($question_id)
  202. {
  203. //3.create answers
  204. $question->setAnswer();
  205. $question->import($exercise_info['question'][$key], $exercise_info['question'][$key]['tempdir']);
  206. $exercise->addQuestion($question_id);
  207. $question->answer->save();
  208. $question->save();
  209. }
  210. else
  211. {
  212. array_push ($backlog_message, 'IMPOSSIBLE TO SAVE QUESTION !!!');
  213. }
  214. }
  215. else
  216. {
  217. array_push ($backlog_message, 'QUESTION DATA INVALID !!!');
  218. }
  219. }
  220. $link = "<center><a href=\"../exercise_submit.php?gradebook=$gradebook&exId=".$exercise_id."\">".get_lang('See the exercise')."</a></center>";
  221. array_push ($backlog_message, $link);
  222. //delete the temp dir where the exercise was unzipped
  223. claro_delete_file($exercisePath);
  224. return $backlog_message;
  225. }
  226. function parse_file($exercisePath, $file, $questionFile)
  227. {
  228. global $exercise_info;
  229. global $element_pile;
  230. global $non_HTML_tag_to_avoid;
  231. global $record_item_body;
  232. $questionTempDir = $exercisePath.$file.'/';
  233. $questionFilePath = $questionTempDir.$questionFile;
  234. $backlog_message = array();
  235. array_push ($backlog_message, "* ".$questionFile);
  236. if (!($fp = @fopen($questionFilePath, 'r')))
  237. {
  238. array_push ($backlog_message, get_lang("Error opening question's XML file"));
  239. return $backlog_message;
  240. }
  241. else
  242. {
  243. $data = fread($fp, filesize( $questionFilePath));
  244. }
  245. //parse XML question file
  246. //used global variable start values declaration :
  247. $record_item_body = false;
  248. $non_HTML_tag_to_avoid = array(
  249. "SIMPLECHOICE",
  250. "CHOICEINTERACTION",
  251. "INLINECHOICEINTERACTION",
  252. "INLINECHOICE",
  253. "SIMPLEMATCHSET",
  254. "SIMPLEASSOCIABLECHOICE",
  255. "TEXTENTRYINTERACTION",
  256. "FEEDBACKINLINE",
  257. "MATCHINTERACTION",
  258. "ITEMBODY",
  259. "BR",
  260. "IMG"
  261. );
  262. //this array to detect tag not supported by claroline import in the xml file to warn the user.
  263. $non_supported_content_in_question = array(
  264. "GAPMATCHINTERACTION",
  265. "EXTENDEDTEXTINTERACTION",
  266. "HOTTEXTINTERACTION",
  267. "HOTSPOTINTERACTION",
  268. "SELECTPOINTINTERACTION",
  269. "GRAPHICORDERINTERACTION",
  270. "GRAPHICASSOCIATIONINTERACTION",
  271. "GRAPHICGAPMATCHINTERACTION",
  272. "POSITIONOBJECTINTERACTION",
  273. "SLIDERINTERACTION",
  274. "DRAWINGINTERACTION",
  275. "UPLOADINTERACTION",
  276. "RESPONSECONDITION",
  277. "RESPONSEIF"
  278. );
  279. $question_format_supported = true;
  280. $xml_parser = xml_parser_create();
  281. xml_set_element_handler($xml_parser, 'startElement', 'endElement');
  282. xml_set_character_data_handler($xml_parser, 'elementData');
  283. if (!xml_parse($xml_parser, $data, feof($fp)))
  284. {
  285. // if reading of the xml file in not successfull :
  286. // set errorFound, set error msg, break while statement
  287. array_push ($backlog_message, get_lang('Error reading XML file') );
  288. return $backlog_message;
  289. }
  290. //close file
  291. fclose($fp);
  292. if ($question_format_supported)
  293. {
  294. array_push ($backlog_message, get_lang('Question format found') );
  295. }
  296. else
  297. {
  298. array_push ($backlog_message, get_lang('ERROR in:<b>'.$questionFile.'</b> Question format unknown') );
  299. }
  300. }
  301. /**
  302. * Function used by the SAX xml parser when the parser meets a opening tag
  303. *
  304. * @param unknown_type $parser xml parser created with "xml_parser_create()"
  305. * @param unknown_type $name name of the element
  306. * @param unknown_type $attributes
  307. */
  308. function startElement($parser, $name, $attributes)
  309. {
  310. global $element_pile;
  311. global $exercise_info;
  312. global $current_question_ident;
  313. global $current_answer_id;
  314. global $current_match_set;
  315. global $currentAssociableChoice;
  316. global $current_question_item_body;
  317. global $record_item_body;
  318. global $non_HTML_tag_to_avoid;
  319. global $current_inlinechoice_id;
  320. global $cardinality;
  321. global $questionTempDir;
  322. array_push($element_pile,$name);
  323. $current_element = end($element_pile);
  324. if (sizeof($element_pile)>=2) $parent_element = $element_pile[sizeof($element_pile)-2]; else $parent_element = "";
  325. if (sizeof($element_pile)>=3) $grant_parent_element = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element ="";
  326. if ($record_item_body)
  327. {
  328. if ((!in_array($current_element,$non_HTML_tag_to_avoid)))
  329. {
  330. $current_question_item_body .= "<".$name;
  331. foreach ($attributes as $attribute_name => $attribute_value)
  332. {
  333. $current_question_item_body .= " ".$attribute_name."=\"".$attribute_value."\"";
  334. }
  335. $current_question_item_body .= ">";
  336. }
  337. else
  338. {
  339. //in case of FIB question, we replace the IMS-QTI tag b y the correct answer between "[" "]",
  340. //we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced
  341. if ($current_element=='INLINECHOICEINTERACTION')
  342. {
  343. $current_question_item_body .="**claroline_start**".$attributes['RESPONSEIDENTIFIER']."**claroline_end**";
  344. }
  345. if ($current_element=='TEXTENTRYINTERACTION')
  346. {
  347. $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
  348. $current_question_item_body .= "[".$correct_answer_value."]";
  349. }
  350. if ($current_element=='BR')
  351. {
  352. $current_question_item_body .= "<BR/>";
  353. }
  354. }
  355. }
  356. switch ($current_element)
  357. {
  358. case 'ASSESSMENTITEM' :
  359. {
  360. //retrieve current question
  361. $current_question_ident = $attributes['IDENTIFIER'];
  362. $exercise_info['question'][$current_question_ident] = array();
  363. $exercise_info['question'][$current_question_ident]['answer'] = array();
  364. $exercise_info['question'][$current_question_ident]['correct_answers'] = array();
  365. $exercise_info['question'][$current_question_ident]['title'] = $attributes['TITLE'];
  366. $exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir;
  367. }
  368. break;
  369. case 'SECTION' :
  370. {
  371. //retrieve exercise name
  372. $exercise_info['name'] = $attributes['TITLE'];
  373. }
  374. break;
  375. case 'RESPONSEDECLARATION' :
  376. {
  377. //retrieve question type
  378. if ( "multiple" == $attributes['CARDINALITY'])
  379. {
  380. $exercise_info['question'][$current_question_ident]['type'] = 'MCMA';
  381. $cardinality = 'multiple';
  382. }
  383. if ( "single" == $attributes['CARDINALITY'])
  384. {
  385. $exercise_info['question'][$current_question_ident]['type'] = 'MCUA';
  386. $cardinality = 'single';
  387. }
  388. //needed for FIB
  389. $current_answer_id = $attributes['IDENTIFIER'];
  390. }
  391. break;
  392. case 'INLINECHOICEINTERACTION' :
  393. {
  394. $exercise_info['question'][$current_question_ident]['type'] = 'FIB';
  395. $exercise_info['question'][$current_question_ident]['subtype'] = 'LISTBOX_FILL';
  396. $current_answer_id = $attributes['RESPONSEIDENTIFIER'];
  397. }
  398. break;
  399. case 'INLINECHOICE' :
  400. {
  401. $current_inlinechoice_id = $attributes['IDENTIFIER'];
  402. }
  403. break;
  404. case 'TEXTENTRYINTERACTION' :
  405. {
  406. $exercise_info['question'][$current_question_ident]['type'] = 'FIB';
  407. $exercise_info['question'][$current_question_ident]['subtype'] = 'TEXTFIELD_FILL';
  408. $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
  409. //replace claroline tags
  410. }
  411. break;
  412. case 'MATCHINTERACTION' :
  413. {
  414. $exercise_info['question'][$current_question_ident]['type'] = 'MATCHING';
  415. }
  416. break;
  417. case 'SIMPLEMATCHSET' :
  418. {
  419. if (!isset($current_match_set))
  420. {
  421. $current_match_set = 1;
  422. }
  423. else
  424. {
  425. $current_match_set++;
  426. }
  427. $exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = array();
  428. }
  429. break;
  430. case 'SIMPLEASSOCIABLECHOICE' :
  431. {
  432. $currentAssociableChoice = $attributes['IDENTIFIER'];
  433. }
  434. break;
  435. //retrieve answers id for MCUA and MCMA questions
  436. case 'SIMPLECHOICE':
  437. {
  438. $current_answer_id = $attributes['IDENTIFIER'];
  439. if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]))
  440. {
  441. $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array();
  442. }
  443. }
  444. break;
  445. case 'MAPENTRY':
  446. {
  447. if ($parent_element == "MAPPING")
  448. {
  449. $answer_id = $attributes['MAPKEY'];
  450. if (!isset($exercise_info['question'][$current_question_ident]['weighting']))
  451. {
  452. $exercise_info['question'][$current_question_ident]['weighting'] = array();
  453. }
  454. $exercise_info['question'][$current_question_ident]['weighting'][$answer_id] = $attributes['MAPPEDVALUE'];
  455. }
  456. }
  457. break;
  458. case 'MAPPING':
  459. {
  460. if (isset($attributes['DEFAULTVALUE']))
  461. {
  462. $exercise_info['question'][$current_question_ident]['default_weighting'] = $attributes['DEFAULTVALUE'];
  463. }
  464. }
  465. case 'ITEMBODY':
  466. {
  467. $record_item_body = true;
  468. $current_question_item_body = '';
  469. }
  470. break;
  471. case 'IMG' :
  472. {
  473. $exercise_info['question'][$current_question_ident]['attached_file_url'] = $attributes['SRC'];
  474. }
  475. break;
  476. }
  477. }
  478. /**
  479. * Function used by the SAX xml parser when the parser meets a closing tag
  480. *
  481. * @param $parser xml parser created with "xml_parser_create()"
  482. * @param $name name of the element
  483. */
  484. function endElement($parser,$name)
  485. {
  486. global $element_pile;
  487. global $exercise_info;
  488. global $current_question_ident;
  489. global $record_item_body;
  490. global $current_question_item_body;
  491. global $non_HTML_tag_to_avoid;
  492. global $cardinality;
  493. $current_element = end($element_pile);
  494. //treat the record of the full content of itembody tag :
  495. if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid)))
  496. {
  497. $current_question_item_body .= "</".$name.">";
  498. }
  499. switch ($name)
  500. {
  501. case 'ITEMBODY':
  502. {
  503. $record_item_body = false;
  504. if ($exercise_info['question'][$current_question_ident]['type']=='FIB')
  505. {
  506. $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
  507. }
  508. else
  509. {
  510. $exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body;
  511. }
  512. }
  513. break;
  514. }
  515. array_pop($element_pile);
  516. }
  517. function elementData($parser,$data)
  518. {
  519. global $element_pile;
  520. global $exercise_info;
  521. global $current_question_ident;
  522. global $current_answer_id;
  523. global $current_match_set;
  524. global $currentAssociableChoice;
  525. global $current_question_item_body;
  526. global $record_item_body;
  527. global $non_HTML_tag_to_avoid;
  528. global $current_inlinechoice_id;
  529. global $cardinality;
  530. $current_element = end($element_pile);
  531. if (sizeof($element_pile)>=2) $parent_element = $element_pile[sizeof($element_pile)-2]; else $parent_element = "";
  532. if (sizeof($element_pile)>=3) $grant_parent_element = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element = "";
  533. //treat the record of the full content of itembody tag (needed for question statment and/or FIB text:
  534. if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid)))
  535. {
  536. $current_question_item_body .= $data;
  537. }
  538. switch ($current_element)
  539. {
  540. case 'SIMPLECHOICE':
  541. {
  542. if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value']))
  543. {
  544. $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
  545. }
  546. else
  547. {
  548. $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ' '.trim($data);
  549. }
  550. }
  551. break;
  552. case 'FEEDBACKINLINE' :
  553. {
  554. if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback']))
  555. {
  556. $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] = trim($data);
  557. }
  558. else
  559. {
  560. $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' '.trim($data);
  561. }
  562. }
  563. break;
  564. case 'SIMPLEASSOCIABLECHOICE' :
  565. {
  566. $exercise_info['question'][$current_question_ident]['answer'][$current_match_set][$currentAssociableChoice] = trim($data);
  567. }
  568. break;
  569. case 'VALUE':
  570. {
  571. if ($parent_element=="CORRECTRESPONSE")
  572. {
  573. if ($cardinality=="single")
  574. {
  575. $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data;
  576. }
  577. else
  578. {
  579. $exercise_info['question'][$current_question_ident]['correct_answers'][] = $data;
  580. }
  581. }
  582. }
  583. break;
  584. case 'ITEMBODY' :
  585. {
  586. $current_question_item_body .= $data;
  587. }
  588. break;
  589. case 'INLINECHOICE' :
  590. {
  591. // if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" :
  592. $answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
  593. if ($current_inlinechoice_id == $answer_identifier)
  594. {
  595. $current_question_item_body = str_replace("**claroline_start**".$current_answer_id."**claroline_end**", "[".$data."]", $current_question_item_body);
  596. }
  597. else // save wrong answers in an array
  598. {
  599. if(!isset($exercise_info['question'][$current_question_ident]['wrong_answers']))
  600. {
  601. $exercise_info['question'][$current_question_ident]['wrong_answers'] = array();
  602. }
  603. $exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data;
  604. }
  605. }
  606. break;
  607. }
  608. }
  609. ?>