dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file exercise_import.inc.php

Documentation is available at exercise_import.inc.php

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

Documentation generated on Thu, 12 Jun 2008 13:25:45 -0500 by phpDocumentor 1.4.1