Julio Montoya 15 years ago
parent
commit
e97058d39a

+ 17 - 12
main/exercice/exercice.php

@@ -427,10 +427,10 @@ if ($show != 'result') {
 require_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
 
 if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
-	require_once ('export/qti2/qti2_export.php');
+	require_once 'export/qti2/qti2_export.php';
 	$export = export_exercise($exerciseId, true);
 
-	require_once (api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php');
+	require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
 	$archive_path = api_get_path(SYS_ARCHIVE_PATH);
 	$temp_dir_short = uniqid();
 	$temp_zip_dir = $archive_path . "/" . $temp_dir_short;
@@ -786,6 +786,8 @@ if (($is_allowedToEdit) and ($origin != 'learnpath')) {
 		echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_test.gif', get_lang('NewEx')) . get_lang('NewEx') . '</a>';
 		echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('question_add.gif', get_lang('AddQuestionToExercise')) . get_lang('AddQuestionToExercise') . '</a>';
 		echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('jqz.gif', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
+		// link to import qti2 ... 
+		echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('jqz.gif', get_lang('ImportQtiQuiz')) . get_lang('ImportQtiQuiz') . '</a>';
 		echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
 	}
 
@@ -869,9 +871,9 @@ if ($show == 'test') {
 		$myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
 		$mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
 		$mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
-
-		$token = Security::get_token();
-
+		
+		$token = Security::get_token();	
+		
 		while ($row = Database :: fetch_array($result)) {
 			//validacion when belongs to a session
 			$session_img = api_get_session_image($row['session_id'], $_user['status']);
@@ -907,15 +909,13 @@ if ($show == 'test') {
 				} else {
 					echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
 				}
-
-				//echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
 ?>
 		    <td>
-		    <a   href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
-
-		    <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>"  onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
+		    <a href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
+		    
+		    <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>"  onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>		    
 		    <a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=clean_results&amp;sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>"  onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;" ><img width="16" src="../img/clean_group.gif" border="0" title="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" /></a>
-
+		    
 			<?php
 
 				if ($row['results_disabled']) {
@@ -948,8 +948,13 @@ if ($show == 'test') {
 					// else if not active
 ?>
 	      		<a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=enable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0"  title="<?php echo get_lang('Activate'); ?>" alt="<?php echo api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
+	      		
 	    		<?php
 				}
+				
+				// export qti ...
+				echo '<a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a>';
+				
 				echo "</td>";
 				echo "</tr>\n";
 			} else { // student only
@@ -1365,7 +1370,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
 		}
 
 		$parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
-
+		
 		$table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
 		$table->set_additional_parameters($parameters);
 		if ($is_allowedToEdit || $is_tutor) {

+ 508 - 666
main/exercice/export/exercise_import.inc.php

@@ -1,5 +1,7 @@
-<?php // $Id:  $
-if ( count( get_included_files() ) == 1 ) die( '---' );
+<?php
+// $Id:  $
+if (count(get_included_files()) == 1)
+	die('---');
 /**
  * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL)
  *
@@ -15,73 +17,42 @@ if ( count( get_included_files() ) == 1 ) die( '---' );
  * function to create a temporary directory (SAME AS IN MODULE ADMIN)
  */
 
-function tempdir($dir, $prefix='tmp', $mode=0777)
-{
-    if (substr($dir, -1) != '/') $dir .= '/';
+function tempdir($dir, $prefix = 'tmp', $mode = 0777) {
+	if (substr($dir, -1) != '/')
+		$dir .= '/';
 
-    do
-    {
-        $path = $dir.$prefix.mt_rand(0, 9999999);
-    } while (!mkdir($path, $mode));
+	do {
+		$path = $dir . $prefix . mt_rand(0, 9999999);
+	} while (!mkdir($path, $mode));
 
-    return $path;
+	return $path;
 }
 
-
 /**
  * @return the path of the temporary directory where the exercise was uploaded and unzipped
  */
 
-function get_and_unzip_uploaded_exercise()
-{
-    $backlog_message = array();
-
-    //Check if the file is valid (not to big and exists)
-
-    if( !isset($_FILES['uploadedExercise'])
-    || !is_uploaded_file($_FILES['uploadedExercise']['tmp_name']))
-    {
-        $backlog_message[] = get_lang('Problem with file upload');
-    }
-    else
-    {
-        $backlog_message[] = get_lang('Temporary file is : ') . $_FILES['uploadedExercise']['tmp_name'];
-    }
-    //1- Unzip folder in a new repository in claroline/module
-
-    include_once (realpath(dirname(__FILE__) . '/../../inc/lib/pclzip/') . '/pclzip.lib.php');
-
-    //unzip files
-
-    $exerciseRepositorySys = get_conf('rootSys') . get_conf('exerciseRepository','cache/');
-
-    //create temp dir for upload
-    //claro_mkdir($exerciseRepositorySys);
-    mkdir($exerciseRepositorySys, api_get_permissions_for_new_directories(), true);
-    //
-    $uploadDirFullPath = tempdir($exerciseRepositorySys, api_get_permissions_for_new_directories());
-    $uploadDir         = str_replace($exerciseRepositorySys,'',$uploadDirFullPath);
-    $exercisePath        = $exerciseRepositorySys.$uploadDir.'/';
-
-    if ( preg_match('/.zip$/i', $_FILES['uploadedExercise']['name']) && treat_uploaded_file($_FILES['uploadedExercise'],$exerciseRepositorySys, $uploadDir, get_conf('maxFilledSpaceForExercise' , 10000000),'unzip',true))
-    {
-        $backlog_message[] = get_lang('Files dezipped sucessfully in ' ) . $exercisePath;
-
-        if (!function_exists('gzopen'))
-        {
-            $backlog_message[] = get_lang('Error : no zlib extension found');
-            claro_delete_file($exercisePath);
-            return claro_failure::set_failure($backlog_message);
-        }
-    }
-    else
-    {
-        $backlog_message[] = get_lang('Impossible to unzip file');
-        claro_delete_file($exercisePath);
-        return claro_failure::set_failure($backlog_message);
-    }
-
-    return $exercisePath;
+function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) {
+	global $_course, $_user;
+	//Check if the file is valid (not to big and exists)
+	if (!isset ($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) {
+		// upload failed
+		return false;
+	}
+
+	//1- Unzip folder in a new repository
+	require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
+	if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 10000000, 1)) {
+		if (!function_exists('gzopen')) {
+			claro_delete_file($uploadPath);
+			return false;
+		}
+		// upload successfull
+		return true;
+	} else {
+		claro_delete_file($uploadPath);
+		return false;
+	}
 }
 /**
  * main function to import an exercise,
@@ -89,512 +60,399 @@ function get_and_unzip_uploaded_exercise()
  * @return an array as a backlog of what was really imported, and error or debug messages to display
  */
 
-function import_exercise($file)
-{
-
-    global $exercise_info;
-    global $element_pile;
-    global $non_HTML_tag_to_avoid;
-    global $record_item_body;
-    global $backlog_message;
-
-    //get required table names
-
-    $tbl_cdb_names = claro_sql_get_course_tbl();
-    $tbl_quiz_exercise = $tbl_cdb_names['qwz_exercise'];
-    $tbl_quiz_question = $tbl_cdb_names['qwz_question'];
-
-    //set some default values for the new exercise
-
-    $exercise_info   = array();
-    $exercise_info['name'] = preg_replace('/.zip$/i','' ,$file);
-    $exercise_info['description'] = get_lang('undefined description');
-    $exercise_info['question'] = array();
-    $element_pile    = array();
-    $backlog_message = array();
-
-    //create parser and array to retrieve info from manifest
-
-    $element_pile = array();  //pile to known the depth in which we are
-    $module_info = array();   //array to store the info we need
-
-    //unzip the uploaded file in a tmp directory
-
-    $exercisePath = get_and_unzip_uploaded_exercise();
-
-    //find the different manifests for each question and parse them.
-
-    $exerciseHandle = opendir($exercisePath);
+function import_exercise($file) {
+	global $exercise_info;
+	global $element_pile;
+	global $non_HTML_tag_to_avoid;
+	global $record_item_body;
+	// used to specify the question directory where files could be found in relation in any question
+	global $questionTempDir;
+
+	$archive_path = api_get_path(SYS_ARCHIVE_PATH) . 'qti2';
+	$baseWorkDir = $archive_path;
+
+	if (!is_dir($baseWorkDir)) {
+		mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true);
+	}
+
+	$uploadPath = '/';
+
+	// set some default values for the new exercise
+	$exercise_info = array ();
+	$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
+	$exercise_info['question'] = array ();
+	$element_pile = array ();
+
+	// create parser and array to retrieve info from manifest
+	$element_pile = array (); //pile to known the depth in which we are
+	$module_info = array (); //array to store the info we need
+
+	// if file is not a .zip, then we cancel all
+	if (!preg_match('/.zip$/i', $file)) {
+		Display :: display_error_message(get_lang('You must upload a zip file'));
+		return false;
+	}
+
+	// unzip the uploaded file in a tmp directory
+	if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
+		Display :: display_error_message(get_lang('You must upload a zip file'));
+		return false;
+	}
+
+	// find the different manifests for each question and parse them.
+	$exerciseHandle = opendir($baseWorkDir);
+	//$question_number = 0;
+	$file_found = false;
+	$operation = false;
+
+	// parse every subdirectory to search xml question files
+	while (false !== ($file = readdir($exerciseHandle))) {
+		if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
+			//find each manifest for each question repository found
+			$questionHandle = opendir($baseWorkDir . '/' . $file);
+			while (false !== ($questionFile = readdir($questionHandle))) {
+				if (preg_match('/.xml$/i', $questionFile)) {
+					parse_file($baseWorkDir, $file, $questionFile);
+					$file_found = true;
+				}
+			}
+		}
+		elseif (preg_match('/.xml$/i', $file)) {
+			parse_file($baseWorkDir, '', $file);
+			$file_found = true;
+		} // else ignore file
+	}
+
+	if (!$file_found) {
+		Display :: display_error_message(get_lang('No XML file found in the zip'));
+		return false;
+	}
+
+	//---------------------
+	//add exercise in tool
+	//---------------------
+
+	//1.create exercise
+	$exercise = new Exercise();
+	$exercise->exercise = $exercise_info['name'];
+	$exercise->save();
+	$last_exercise_id = $exercise->selectId();
+	if (!empty ($last_exercise_id)) {
+		//For each question found...
+		foreach ($exercise_info['question'] as $key => $question_array) {
+			//2.create question
+			$question = new Ims2Question();
+			$question->type = $question_array['type'];
+			$question->setAnswer();
+			$question->updateTitle($question_array['title']); // question ...
+			$type = $question->selectType();
+			$question->type = constant($type); // type ...
+			$question->save($last_exercise_id); // save computed grade
+			$last_question_id = $question->selectId();
+			//3.create answer
+			$answer = new Answer($last_question_id);
+			$answer->new_nbrAnswers = count($question_array['answer']);
+			foreach ($question_array['answer'] as $key => $answers) {
+				$split = explode('_', $key);
+				$i = $split[1];
+				$answer->new_answer[$i] = $answers['value']; // answer ...
+				$answer->new_comment[$i] = $answers['feedback']; // comment ...
+				$answer->new_position[$i] = $i; // position ...
+				// correct answers ...
+				if (in_array($key, $question_array['correct_answers'])) {
+					$answer->new_correct[$i] = 1;
+				} else {
+					$answer->new_correct[$i] = 0;
+				}
+				$answer->new_weighting[$i] = $question_array['weighting'][$key];
+			}
+			$answer->save();
+		}
+		// delete the temp dir where the exercise was unzipped
+		my_delete($baseWorkDir . $uploadPath);
+		$operation = true;
+	}
+	return $operation;
+}
 
-    //find each question repository in the uploaded exercise folder
+function parse_file($exercisePath, $file, $questionFile) {
+	global $exercise_info;
+	global $element_pile;
+	global $non_HTML_tag_to_avoid;
+	global $record_item_body;
+	global $questionTempDir;
+
+	$questionTempDir = $exercisePath . '/' . $file . '/';
+	$questionFilePath = $questionTempDir . $questionFile;
+
+	if (!($fp = @ fopen($questionFilePath, 'r'))) {
+		Display :: display_error_message(get_lang('Error opening question\'s XML file'));
+		return false;
+	} else {
+		$data = fread($fp, filesize($questionFilePath));
+	}
+
+	//parse XML question file
+
+	//used global variable start values declaration :
+
+	$record_item_body = false;
+	$non_HTML_tag_to_avoid = array (
+		"SIMPLECHOICE",
+		"CHOICEINTERACTION",
+		"INLINECHOICEINTERACTION",
+		"INLINECHOICE",
+		"SIMPLEMATCHSET",
+		"SIMPLEASSOCIABLECHOICE",
+		"TEXTENTRYINTERACTION",
+		"FEEDBACKINLINE",
+		"MATCHINTERACTION",
+		"ITEMBODY",
+		"BR",
+		"IMG"
+	);
+
+	//this array to detect tag not supported by claroline import in the xml file to warn the user.
+
+	$non_supported_content_in_question = array (
+		"GAPMATCHINTERACTION",
+		"EXTENDEDTEXTINTERACTION",
+		"HOTTEXTINTERACTION",
+		"HOTSPOTINTERACTION",
+		"SELECTPOINTINTERACTION",
+		"GRAPHICORDERINTERACTION",
+		"GRAPHICASSOCIATIONINTERACTION",
+		"GRAPHICGAPMATCHINTERACTION",
+		"POSITIONOBJECTINTERACTION",
+		"SLIDERINTERACTION",
+		"DRAWINGINTERACTION",
+		"UPLOADINTERACTION",
+		"RESPONSECONDITION",
+		"RESPONSEIF"
+	);
+	$question_format_supported = true;
+
+	$xml_parser = xml_parser_create();
+	xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, false);
+	xml_set_element_handler($xml_parser, 'startElement', 'endElement');
+	xml_set_character_data_handler($xml_parser, 'elementData');
+
+	if (!xml_parse($xml_parser, $data, feof($fp))) {
+		// if reading of the xml file in not successfull :
+		// set errorFound, set error msg, break while statement
+		Display :: display_error_message(get_lang('Error reading XML file'));
+		return false;
+	}
+
+	//close file
+	fclose($fp);
+	if (!$question_format_supported) {
+		Display :: display_error_message(get_lang('Unknown question format in file %file', array (
+			'%file' => $questionFile
+		)));
+		return false;
+	}
+	return true;
+}
 
-    array_push ($backlog_message, get_lang('XML question files found : '));
+/**
+ * Function used by the SAX xml parser when the parser meets a opening tag
+ *
+ * @param unknown_type $parser xml parser created with "xml_parser_create()"
+ * @param unknown_type $name name of the element
+ * @param unknown_type $attributes
+ */
 
-    $question_number = 0;
+function startElement($parser, $name, $attributes) {
+	global $element_pile;
+	global $exercise_info;
+	global $current_question_ident;
+	global $current_answer_id;
+	global $current_match_set;
+	global $currentAssociableChoice;
+	global $current_question_item_body;
+	global $record_item_body;
+	global $non_HTML_tag_to_avoid;
+	global $current_inlinechoice_id;
+	global $cardinality;
+	global $questionTempDir;
+
+	array_push($element_pile, $name);
+	$current_element = end($element_pile);
+	if (sizeof($element_pile) >= 2)
+		$parent_element = $element_pile[sizeof($element_pile) - 2];
+	else
+		$parent_element = "";
+	if (sizeof($element_pile) >= 3)
+		$grant_parent_element = $element_pile[sizeof($element_pile) - 3];
+	else
+		$grant_parent_element = "";
+
+	if ($record_item_body) {
+
+		if ((!in_array($current_element, $non_HTML_tag_to_avoid))) {
+			$current_question_item_body .= "<" . $name;
+
+			foreach ($attributes as $attribute_name => $attribute_value) {
+				$current_question_item_body .= " " . $attribute_name . "=\"" . $attribute_value . "\"";
+			}
+			$current_question_item_body .= ">";
+		} else {
+			//in case of FIB question, we replace the IMS-QTI tag b y the correct answer between "[" "]",
+			//we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced
 
-    //used to specify the question directory where files could be found in relation in any question
+			if ($current_element == 'INLINECHOICEINTERACTION') {
 
-    global $questionTempDir;
+				$current_question_item_body .= "**claroline_start**" . $attributes['RESPONSEIDENTIFIER'] . "**claroline_end**";
+			}
+			if ($current_element == 'TEXTENTRYINTERACTION') {
+				$correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
+				$current_question_item_body .= "[" . $correct_answer_value . "]";
 
+			}
+			if ($current_element == 'BR') {
+				$current_question_item_body .= "<BR/>";
+			}
+		}
 
-    //1- parse the parent directory
+	}
 
-    $questionHandle = opendir($exercisePath);
+	switch ($current_element) {
+		case 'ASSESSMENTITEM' :
+			{
+				//retrieve current question
+
+				$current_question_ident = $attributes['IDENTIFIER'];
+				$exercise_info['question'][$current_question_ident] = array ();
+				$exercise_info['question'][$current_question_ident]['answer'] = array ();
+				$exercise_info['question'][$current_question_ident]['correct_answers'] = array ();
+				$exercise_info['question'][$current_question_ident]['title'] = $attributes['TITLE'];
+				$exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir;
+			}
+			break;
 
-    while (false !== ($questionFile = readdir($questionHandle)))
-    {
-        if (preg_match('/.xml$/i' ,$questionFile))
-        {
-            array_push ($backlog_message, get_lang("XML question file found : ".$questionFile));
-            parse_file($exercisePath, '', $questionFile);
-        }//end if xml question file found
-    }//end while question rep
+		case 'SECTION' :
+			{
+				//retrieve exercise name
 
+				$exercise_info['name'] = $attributes['TITLE'];
 
-    //2- parse every subdirectory to search xml question files
+			}
+			break;
 
-    while (false !== ($file = readdir($exerciseHandle)))
-    {
+		case 'RESPONSEDECLARATION' :
+			{
+				//retrieve question type
 
-        if (is_dir($exercisePath.$file) && $file != "." && $file != "..")
-        {
-            //find each manifest for each question repository found
+				if ("multiple" == $attributes['CARDINALITY']) {
+					$exercise_info['question'][$current_question_ident]['type'] = 'MCMA';
+					$cardinality = 'multiple';
+				}
+				if ("single" == $attributes['CARDINALITY']) {
+					$exercise_info['question'][$current_question_ident]['type'] = 'MCUA';
+					$cardinality = 'single';
+				}
 
-            $questionHandle = opendir($exercisePath.$file);
+				//needed for FIB
 
-            while (false !== ($questionFile = readdir($questionHandle)))
-            {
-                if (preg_match('/.xml$/i' ,$questionFile))
-                {
-                    parse_file($exercisePath, $file, $questionFile);
-                }//end if xml question file found
-            }//end while question rep
-        } //if is_dir
-    }//end while loop to find each question data's
+				$current_answer_id = $attributes['IDENTIFIER'];
 
+			}
+			break;
 
-    //Display data found
+		case 'INLINECHOICEINTERACTION' :
+			{
+				$exercise_info['question'][$current_question_ident]['type'] = 'FIB';
+				$exercise_info['question'][$current_question_ident]['subtype'] = 'LISTBOX_FILL';
+				$current_answer_id = $attributes['RESPONSEIDENTIFIER'];
 
-	array_push ($backlog_message, 'Exercise name  : <b>' . $exercise_info['name'] . '</b>');
-	array_push ($backlog_message, 'Exercise description  : ' . $exercise_info['description']);
+			}
+			break;
 
-    foreach ($exercise_info['question'] as $key => $question)
-    {
-        $question_number++;
-        array_push ($backlog_message, '<b>'.$question_number.'-</b> Question found (' .$key. ')  : <b>' . $question['title'] . '</b>');
-		if (isset($question['statement'])) array_push ($backlog_message, '* Statement : ' . $question['statement']);
-		array_push ($backlog_message, '* Type : '      . $question['type']);
+		case 'INLINECHOICE' :
+			{
+				$current_inlinechoice_id = $attributes['IDENTIFIER'];
+			}
+			break;
 
-		foreach ($exercise_info['question'][$key]['answer'] as $answer)
-		{
-            if ($question['type']=="MATCHING")
-            {
-                array_push ($backlog_message, '** Matchset : ');
-                foreach ($answer as $matchSetElement)
-                {
-                   array_push ($backlog_message, '*** Element ' . $matchSetElement);
-                }
-            }
-            else
-            {
-                array_push ($backlog_message, '** Answer found : '        . $answer['value']);
-                if (isset($answer['feedback'])) array_push ($backlog_message, '*** Answer feedback : '    . $answer['feedback']);
-            }
-		}
+		case 'TEXTENTRYINTERACTION' :
+			{
+				$exercise_info['question'][$current_question_ident]['type'] = 'FIB';
+				$exercise_info['question'][$current_question_ident]['subtype'] = 'TEXTFIELD_FILL';
+				$exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
 
-        if (isset($question['weighting']))
-        {
-            array_push ($backlog_message, '* WEIGHTING for Answers :');
-            foreach ($question['weighting'] as $key => $weighting)
-            {
-                array_push ($backlog_message, '** Answer : '.$key.' ==> weighting : '.$weighting);
-            }
-        }
-
-        if (isset($question['correct_answers']))
-        {
-            array_push ($backlog_message, '* CORRECT ANSWERS :');
-            foreach ($question['correct_answers'] as $answerIdent)
-            {
-                array_push ($backlog_message, '* Answer : '.$answerIdent);
-            }
-        }
-
-		if (isset($question['response_text']))
-        {
-            array_push ($backlog_message, '* Text to fill in : '.$question['response_text'] );
-        }
-    }
-
-    //---------------------
-    //add exercise in tool
-    //---------------------
-
-    //1.create exercise
-
-    $exercise = new Exercise();
-
-    $exercise->setTitle($exercise_info['name']);
-    $exercise->setDescription($exercise_info['description']);
-
-    if ($exercise->validate())
-    {
-        $exercise_id = $exercise->save();
-    }
-    else
-    {
-        array_push ($backlog_message, 'EXERCISE DATA INVALID !!!');
-    }
-
-    //For each question found...
-
-    foreach($exercise_info['question'] as $key => $question_array)
-    {
-        //2.create question
-
-        $question = new ImsQuestion();
-
-        if (isset($question_array['title'])) $question->setTitle($question_array['title']);
-        if (isset($question_array['statement'])) $question->setDescription($question_array['statement']);
-        $question->setType($question_array['type']);
-
-        if ($question->validate())
-        {
-            $question_id = $question->save();
-
-            if ($question_id)
-            {
-                //3.create answers
-
-                $question->setAnswer();
-                $question->import($exercise_info['question'][$key], $exercise_info['question'][$key]['tempdir']);
-                $exercise->addQuestion($question_id);
-                $question->answer->save();
-                $question->save();
-            }
-            else
-            {
-                array_push ($backlog_message, 'IMPOSSIBLE TO SAVE QUESTION !!!');
-            }
-        }
-        else
-        {
-            array_push ($backlog_message, 'QUESTION DATA INVALID !!!');
-        }
-    }
-    $link = "<center><a href=\"../exercise_submit.php?gradebook=$gradebook&exId=".$exercise_id."\">".get_lang('See the exercise')."</a></center>";
-    array_push ($backlog_message, $link);
-
-    //delete the temp dir where the exercise was unzipped
-
-    claro_delete_file($exercisePath);
-
-    return $backlog_message;
-}
+				//replace claroline tags
 
+			}
+			break;
 
+		case 'MATCHINTERACTION' :
+			{
+				$exercise_info['question'][$current_question_ident]['type'] = 'MATCHING';
+			}
+			break;
 
-function parse_file($exercisePath, $file, $questionFile)
-{
-    global $exercise_info;
-    global $element_pile;
-    global $non_HTML_tag_to_avoid;
-    global $record_item_body;
-
-    $questionTempDir = $exercisePath.$file.'/';
-    $questionFilePath = $questionTempDir.$questionFile;
-    $backlog_message = array();
-    array_push ($backlog_message, "* ".$questionFile);
-
-    if (!($fp = @fopen($questionFilePath, 'r')))
-    {
-        array_push ($backlog_message, get_lang("Error opening question's XML file"));
-        return $backlog_message;
-    }
-    else
-    {
-        $data = fread($fp, filesize( $questionFilePath));
-    }
-
-    //parse XML question file
-
-    //used global variable start values declaration :
-
-    $record_item_body = false;
-    $non_HTML_tag_to_avoid = array(
-    "SIMPLECHOICE",
-    "CHOICEINTERACTION",
-    "INLINECHOICEINTERACTION",
-    "INLINECHOICE",
-    "SIMPLEMATCHSET",
-    "SIMPLEASSOCIABLECHOICE",
-    "TEXTENTRYINTERACTION",
-    "FEEDBACKINLINE",
-    "MATCHINTERACTION",
-    "ITEMBODY",
-    "BR",
-    "IMG"
-    );
-
-    //this array to detect tag not supported by claroline import in the xml file to warn the user.
-
-    $non_supported_content_in_question = array(
-    "GAPMATCHINTERACTION",
-    "EXTENDEDTEXTINTERACTION",
-    "HOTTEXTINTERACTION",
-    "HOTSPOTINTERACTION",
-    "SELECTPOINTINTERACTION",
-    "GRAPHICORDERINTERACTION",
-    "GRAPHICASSOCIATIONINTERACTION",
-    "GRAPHICGAPMATCHINTERACTION",
-    "POSITIONOBJECTINTERACTION",
-    "SLIDERINTERACTION",
-    "DRAWINGINTERACTION",
-    "UPLOADINTERACTION",
-    "RESPONSECONDITION",
-    "RESPONSEIF"
-    );
-    $question_format_supported = true;
-
-    $xml_parser = xml_parser_create();
-    xml_set_element_handler($xml_parser, 'startElement', 'endElement');
-    xml_set_character_data_handler($xml_parser, 'elementData');
-
-    if (!xml_parse($xml_parser, $data, feof($fp)))
-    {
-    // if reading of the xml file in not successfull :
-    // set errorFound, set error msg, break while statement
-
-        array_push ($backlog_message, get_lang('Error reading XML file') );
-        return $backlog_message;
-    }
-
-    //close file
-
-    fclose($fp);
-
-    if ($question_format_supported)
-    {
-        array_push ($backlog_message, get_lang('Question format found') );
-    }
-    else
-    {
-        array_push ($backlog_message, get_lang('ERROR in:<b>'.$questionFile.'</b> Question format unknown') );
-    }
-}
+		case 'SIMPLEMATCHSET' :
+			{
+				if (!isset ($current_match_set)) {
+					$current_match_set = 1;
+				} else {
+					$current_match_set++;
+				}
+				$exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = array ();
+			}
+			break;
 
+		case 'SIMPLEASSOCIABLECHOICE' :
+			{
+				$currentAssociableChoice = $attributes['IDENTIFIER'];
+			}
+			break;
 
-/**
- * Function used by the SAX xml parser when the parser meets a opening tag
- *
- * @param unknown_type $parser xml parser created with "xml_parser_create()"
- * @param unknown_type $name name of the element
- * @param unknown_type $attributes
- */
+			//retrieve answers id for MCUA and MCMA questions
 
-function startElement($parser, $name, $attributes)
-{
-    global $element_pile;
-    global $exercise_info;
-    global $current_question_ident;
-    global $current_answer_id;
-    global $current_match_set;
-    global $currentAssociableChoice;
-    global $current_question_item_body;
-    global $record_item_body;
-    global $non_HTML_tag_to_avoid;
-    global $current_inlinechoice_id;
-    global $cardinality;
-    global $questionTempDir;
-
-    array_push($element_pile,$name);
-    $current_element = end($element_pile);
-    if (sizeof($element_pile)>=2) $parent_element        = $element_pile[sizeof($element_pile)-2]; else $parent_element = "";
-    if (sizeof($element_pile)>=3) $grant_parent_element  = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element ="";
-
-    if ($record_item_body)
-    {
-
-        if ((!in_array($current_element,$non_HTML_tag_to_avoid)))
-        {
-            $current_question_item_body .= "<".$name;
-
-            foreach ($attributes as $attribute_name => $attribute_value)
-            {
-                $current_question_item_body .= " ".$attribute_name."=\"".$attribute_value."\"";
-            }
-            $current_question_item_body .= ">";
-        }
-        else
-        {
-            //in case of FIB question, we replace the IMS-QTI tag b y the correct answer between "[" "]",
-            //we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced
-
-            if ($current_element=='INLINECHOICEINTERACTION')
-            {
-
-                  $current_question_item_body .="**claroline_start**".$attributes['RESPONSEIDENTIFIER']."**claroline_end**";
-            }
-            if ($current_element=='TEXTENTRYINTERACTION')
-            {
-                $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
-                $current_question_item_body .= "[".$correct_answer_value."]";
-
-            }
-            if ($current_element=='BR')
-            {
-                $current_question_item_body .= "<BR/>";
-            }
-        }
-
-    }
-
-    switch ($current_element)
-    {
-        case 'ASSESSMENTITEM' :
-        {
-            //retrieve current question
-
-			$current_question_ident = $attributes['IDENTIFIER'];
-            $exercise_info['question'][$current_question_ident] = array();
-            $exercise_info['question'][$current_question_ident]['answer'] = array();
-            $exercise_info['question'][$current_question_ident]['correct_answers'] = array();
-            $exercise_info['question'][$current_question_ident]['title'] = $attributes['TITLE'];
-            $exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir;
-        }
-        break;
-
-        case 'SECTION' :
-        {
-         	//retrieve exercise name
-
-			$exercise_info['name'] = $attributes['TITLE'];
-
-        }
-		break;
+		case 'SIMPLECHOICE' :
+			{
+				$current_answer_id = $attributes['IDENTIFIER'];
+				if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) {
+					$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array ();
+				}
+			}
+			break;
 
-		case 'RESPONSEDECLARATION' :
-        {
-         	//retrieve question type
+		case 'MAPENTRY' :
+			{
+				if ($parent_element == "MAPPING") {
+					$answer_id = $attributes['MAPKEY'];
+
+					if (!isset ($exercise_info['question'][$current_question_ident]['weighting'])) {
+						$exercise_info['question'][$current_question_ident]['weighting'] = array ();
+					}
+					$exercise_info['question'][$current_question_ident]['weighting'][$answer_id] = $attributes['MAPPEDVALUE'];
+				}
+			}
+			break;
 
-			if ( "multiple" == $attributes['CARDINALITY'])
+		case 'MAPPING' :
 			{
-				$exercise_info['question'][$current_question_ident]['type'] = 'MCMA';
-                $cardinality = 'multiple';
+				if (isset ($attributes['DEFAULTVALUE'])) {
+					$exercise_info['question'][$current_question_ident]['default_weighting'] = $attributes['DEFAULTVALUE'];
+				}
 			}
-			if ( "single" == $attributes['CARDINALITY'])
+
+		case 'ITEMBODY' :
 			{
-				$exercise_info['question'][$current_question_ident]['type'] = 'MCUA';
-                $cardinality = 'single';
+				$record_item_body = true;
+				$current_question_item_body = '';
 			}
+			break;
 
-            //needed for FIB
-
-            $current_answer_id = $attributes['IDENTIFIER'];
-
-        }
-		break;
-
-        case 'INLINECHOICEINTERACTION' :
-        {
-            $exercise_info['question'][$current_question_ident]['type'] = 'FIB';
-            $exercise_info['question'][$current_question_ident]['subtype'] = 'LISTBOX_FILL';
-            $current_answer_id = $attributes['RESPONSEIDENTIFIER'];
-
-        }
-        break;
-
-        case 'INLINECHOICE' :
-        {
-            $current_inlinechoice_id = $attributes['IDENTIFIER'];
-        }
-        break;
-
-        case 'TEXTENTRYINTERACTION' :
-        {
-            $exercise_info['question'][$current_question_ident]['type'] = 'FIB';
-            $exercise_info['question'][$current_question_ident]['subtype'] = 'TEXTFIELD_FILL';
-            $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
-
-            //replace claroline tags
-
-        }
-        break;
-
-        case 'MATCHINTERACTION' :
-        {
-            $exercise_info['question'][$current_question_ident]['type'] = 'MATCHING';
-        }
-        break;
-
-        case 'SIMPLEMATCHSET' :
-        {
-            if (!isset($current_match_set))
-            {
-                $current_match_set = 1;
-            }
-            else
-            {
-                $current_match_set++;
-            }
-            $exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = array();
-        }
-        break;
-
-        case 'SIMPLEASSOCIABLECHOICE' :
-        {
-            $currentAssociableChoice = $attributes['IDENTIFIER'];
-        }
-        break;
-
-        //retrieve answers id for MCUA and MCMA questions
-
-        case 'SIMPLECHOICE':
-        {
-            $current_answer_id = $attributes['IDENTIFIER'];
-            if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]))
-            {
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array();
-            }
-        }
-        break;
-
-        case 'MAPENTRY':
-        {
-            if ($parent_element == "MAPPING")
-            {
-                $answer_id = $attributes['MAPKEY'];
-
-                if (!isset($exercise_info['question'][$current_question_ident]['weighting']))
-                {
-                    $exercise_info['question'][$current_question_ident]['weighting'] = array();
-                }
-                $exercise_info['question'][$current_question_ident]['weighting'][$answer_id] = $attributes['MAPPEDVALUE'];
-            }
-        }
-        break;
-
-        case 'MAPPING':
-        {
-            if (isset($attributes['DEFAULTVALUE']))
-            {
-                $exercise_info['question'][$current_question_ident]['default_weighting'] = $attributes['DEFAULTVALUE'];
-            }
-        }
-
-        case 'ITEMBODY':
-        {
-            $record_item_body = true;
-            $current_question_item_body = '';
-        }
-        break;
-
-        case 'IMG' :
-        {
-            $exercise_info['question'][$current_question_ident]['attached_file_url'] =  $attributes['SRC'];
-        }
-        break;
-    }
+		case 'IMG' :
+			{
+				$exercise_info['question'][$current_question_ident]['attached_file_url'] = $attributes['SRC'];
+			}
+			break;
+	}
 }
 
 /**
@@ -604,150 +462,134 @@ function startElement($parser, $name, $attributes)
  * @param $name name of the element
  */
 
-function endElement($parser,$name)
-{
-    global $element_pile;
-    global $exercise_info;
+function endElement($parser, $name) {
+	global $element_pile;
+	global $exercise_info;
 	global $current_question_ident;
-    global $record_item_body;
-    global $current_question_item_body;
-    global $non_HTML_tag_to_avoid;
-    global $cardinality;
+	global $record_item_body;
+	global $current_question_item_body;
+	global $non_HTML_tag_to_avoid;
+	global $cardinality;
 
 	$current_element = end($element_pile);
 
-    //treat the record of the full content of itembody tag :
-
-    if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid)))
-    {
-        $current_question_item_body .= "</".$name.">";
-    }
-
-    switch ($name)
-    {
-        case 'ITEMBODY':
-            {
-                $record_item_body = false;
-                if ($exercise_info['question'][$current_question_ident]['type']=='FIB')
-                {
-                    $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
-                }
-                else
-                {
-                    $exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body;
-                }
-            }
-        break;
-    }
-    array_pop($element_pile);
+	//treat the record of the full content of itembody tag :
+
+	if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
+		$current_question_item_body .= "</" . $name . ">";
+	}
+
+	switch ($name) {
+		case 'ITEMBODY' :
+			{
+				$record_item_body = false;
+				if ($exercise_info['question'][$current_question_ident]['type'] == 'FIB') {
+					$exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body;
+				} else {
+					$exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body;
+				}
+			}
+			break;
+	}
+	array_pop($element_pile);
 
 }
 
-function elementData($parser,$data)
-{
+function elementData($parser, $data) {
 
-    global $element_pile;
-    global $exercise_info;
+	global $element_pile;
+	global $exercise_info;
 	global $current_question_ident;
-    global $current_answer_id;
-    global $current_match_set;
-    global $currentAssociableChoice;
-    global $current_question_item_body;
-    global $record_item_body;
-    global $non_HTML_tag_to_avoid;
-    global $current_inlinechoice_id;
-    global $cardinality;
-
-    $current_element       = end($element_pile);
-	if (sizeof($element_pile)>=2) $parent_element        = $element_pile[sizeof($element_pile)-2]; else $parent_element = "";
-	if (sizeof($element_pile)>=3) $grant_parent_element  = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element = "";
+	global $current_answer_id;
+	global $current_match_set;
+	global $currentAssociableChoice;
+	global $current_question_item_body;
+	global $record_item_body;
+	global $non_HTML_tag_to_avoid;
+	global $current_inlinechoice_id;
+	global $cardinality;
+
+	$current_element = end($element_pile);
+	if (sizeof($element_pile) >= 2)
+		$parent_element = $element_pile[sizeof($element_pile) - 2];
+	else
+		$parent_element = "";
+	if (sizeof($element_pile) >= 3)
+		$grant_parent_element = $element_pile[sizeof($element_pile) - 3];
+	else
+		$grant_parent_element = "";
 
 	//treat the record of the full content of itembody tag (needed for question statment and/or FIB text:
 
-    if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid)))
-    {
-        $current_question_item_body .= $data;
-    }
-
-    switch ($current_element)
-    {
-        case 'SIMPLECHOICE':
-        {
-            if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value']))
-            {
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
-            }
-            else
-            {
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ' '.trim($data);
-            }
-        }
-        break;
-
-        case 'FEEDBACKINLINE' :
-        {
-            if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback']))
-            {
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] = trim($data);
-            }
-            else
-            {
-                $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' '.trim($data);
-            }
-        }
-        break;
-
-        case 'SIMPLEASSOCIABLECHOICE' :
-        {
-            $exercise_info['question'][$current_question_ident]['answer'][$current_match_set][$currentAssociableChoice] = trim($data);
-        }
-        break;
-
-        case 'VALUE':
-        {
-            if ($parent_element=="CORRECTRESPONSE")
-            {
-                if ($cardinality=="single")
-                {
-                    $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data;
-                }
-                else
-                {
-                    $exercise_info['question'][$current_question_ident]['correct_answers'][] = $data;
-                }
-            }
-        }
-        break;
-
-        case 'ITEMBODY' :
-        {
-            $current_question_item_body .= $data;
-
-        }
-        break;
-
-        case 'INLINECHOICE' :
-        {
-
-            // if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" :
-
-            $answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
-
-            if ($current_inlinechoice_id == $answer_identifier)
-            {
-
-                $current_question_item_body = str_replace("**claroline_start**".$current_answer_id."**claroline_end**", "[".$data."]", $current_question_item_body);
-            }
-            else // save wrong answers in an array
-            {
-                if(!isset($exercise_info['question'][$current_question_ident]['wrong_answers']))
-                {
-                    $exercise_info['question'][$current_question_ident]['wrong_answers'] = array();
-                }
-                $exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data;
-            }
-        }
-        break;
-    }
+	if ($record_item_body && (!in_array($current_element, $non_HTML_tag_to_avoid))) {
+		$current_question_item_body .= $data;
+	}
+
+	switch ($current_element) {
+		case 'SIMPLECHOICE' :
+			{
+				if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) {
+					$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data);
+				} else {
+					$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ' ' . trim($data);
+				}
+			}
+			break;
+
+		case 'FEEDBACKINLINE' :
+			{
+				if (!isset ($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'])) {
+					$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] = trim($data);
+				} else {
+					$exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' ' . trim($data);
+				}
+			}
+			break;
+
+		case 'SIMPLEASSOCIABLECHOICE' :
+			{
+				$exercise_info['question'][$current_question_ident]['answer'][$current_match_set][$currentAssociableChoice] = trim($data);
+			}
+			break;
+
+		case 'VALUE' :
+			{
+				if ($parent_element == "CORRECTRESPONSE") {
+					if ($cardinality == "single") {
+						$exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data;
+					} else {
+						$exercise_info['question'][$current_question_ident]['correct_answers'][] = $data;
+					}
+				}
+			}
+			break;
+
+		case 'ITEMBODY' :
+			{
+				$current_question_item_body .= $data;
+
+			}
+			break;
+
+		case 'INLINECHOICE' :
+			{
+
+				// if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" :
+
+				$answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id];
+
+				if ($current_inlinechoice_id == $answer_identifier) {
+
+					$current_question_item_body = str_replace("**claroline_start**" . $current_answer_id . "**claroline_end**", "[" . $data . "]", $current_question_item_body);
+				} else // save wrong answers in an array
+					{
+					if (!isset ($exercise_info['question'][$current_question_ident]['wrong_answers'])) {
+						$exercise_info['question'][$current_question_ident]['wrong_answers'] = array ();
+					}
+					$exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data;
+				}
+			}
+			break;
+	}
 }
 ?>

+ 101 - 0
main/exercice/qti2.php

@@ -0,0 +1,101 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+*	Code for Qti2 import integration.
+*	@package chamilo.exercise
+* 	@author Ronny Velasquez
+* 	@version $Id: qti2.php  2010-03-12 12:14:25Z $
+*/
+
+// name of the language file that needs to be included
+$language_file = 'exercice';
+
+// including the global Chamilo file
+require_once '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'document.lib.php';
+
+// including additional libraries
+require_once 'exercise.class.php';
+require_once 'question.class.php';
+require_once 'answer.class.php';
+
+// section (for the tabs)
+$this_section = SECTION_COURSES;
+
+// access restriction: only teachers are allowed here
+if (!api_is_allowed_to_edit(null, true)) {
+	api_not_allowed();
+}
+
+// the breadcrumbs
+$interbreadcrumb[]= array ("url"=>"./exercice.php", "name"=> get_lang('Exercices'));
+$is_allowedToEdit = api_is_allowed_to_edit(null, true);
+
+/**
+ * This function displays the form for import of the zip file with qti2
+ */
+function ch_qti2_display_form() {
+	$name_tools = get_lang('ImportQtiQuiz');
+	$form  = '<div class="actions">';
+	$form .= '<a href="exercice.php?show=test">' . Display :: return_icon('message_reply_forum.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
+	$form .= '</div>';
+	$form .= '<form action='.api_get_self()."?".api_get_cidreq().' method="post" enctype="multipart/form-data">';
+	$form .= '<div class="row"><div class="form_header">'.$name_tools.'</div></div>';
+	$form .= '<div class="row">';
+	$form .= '<div class="label" style="padding:10px">';
+	$form .= '<span class="form_required">*</span>';
+	$form .= get_lang('DownloadFile').' :';
+	$form .= '</div>';
+	$form .= '<div class="formw">';
+	$form .= '<div style="padding:10px">
+			  <input type="file" name="userFile"><br /><br />
+			  <button type="submit" class="upload" name="submit" value="'.get_lang('Send').'">'.get_lang('SendFile').'</button>
+		 	  </div>';
+	$form .= '</div></div>';
+	echo $form;
+}
+
+/**
+ * This function will import the zip file with the respective qti2
+ * @param array $uploaded_file ($_FILES)
+ */
+function ch_qti2_import_file($array_file) {
+	$unzip = 0;
+	$lib_path = api_get_path(LIBRARY_PATH);
+	require_once $lib_path.'fileUpload.lib.php';
+	require_once $lib_path.'fileManage.lib.php';
+	$process = process_uploaded_file($array_file);
+	if (preg_match('/\.zip$/i', $array_file['name'])) {
+		// if it's a zip, allow zip upload
+		$unzip = 1;
+	}
+	if ($process == true && $unzip == 1) {
+		$main_path = api_get_path(SYS_CODE_PATH);
+		require_once $main_path.'exercice/export/exercise_import.inc.php';
+        require_once $main_path.'exercice/export/qti2/qti2_classes.php';
+        $imported = import_exercise($array_file['name']);
+        if ($imported == true) {
+        	header('Location: exercice.php?' . Security::remove_XSS(api_get_cidreq()) .'');
+        } else {
+            Display::display_error_message(get_lang('The import was not performed'));
+            return false;
+        }
+	}
+}
+
+// import file
+if ((api_is_allowed_to_edit(null, true))) {
+	if (isset($_POST['submit'])) {
+		ch_qti2_import_file($_FILES['userFile']);
+	}
+}
+
+// display header
+Display::display_header($name_tools, get_lang('Exercise'));
+
+// display qti form
+ch_qti2_display_form();
+
+// display the footer
+Display::display_footer();
+?>

+ 4 - 4
main/exercice/question.class.php

@@ -775,11 +775,11 @@ abstract class Question
      * @param - integer $exerciseId - exercise ID
      * @param - boolean $fromSave - comming from $this->save() or not
 	 */
-	function addToList($exerciseId, $fromSave=FALSE) {
-		global $TBL_EXERCICE_QUESTION;
-		$id=$this->id;
+	function addToList($exerciseId, $fromSave = FALSE) {
+		$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+		$id = $this->id;
 		// checks if the exercise ID is not in the list
-		if(!in_array($exerciseId,$this->exerciseList)) {
+		if (!in_array($exerciseId,$this->exerciseList)) {
 			$this->exerciseList[]=$exerciseId;
 			$sql="INSERT INTO $TBL_EXERCICE_QUESTION (question_id, exercice_id) VALUES('".Database::escape_string($id)."','".Database::escape_string($exerciseId)."')";
 			Database::query($sql);

+ 1 - 1
main/gradebook/index.php

@@ -862,7 +862,7 @@ if ($category != '0') {
 	//DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
 }
 
-if (api_is_platform_admin() || api_is_allowed_to_create_course()  || $status==1) {
+if (api_is_allowed_to_edit(null, true)) {
 /*
 -----------------------------------------------------------
 	Introduction section (teacher edit)

+ 5 - 5
main/gradebook/lib/fe/displaygradebook.php

@@ -11,7 +11,7 @@ class DisplayGradebook
 	*/
 	function display_header_result($evalobj, $selectcat, $shownavbar) {
 		$status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
-		if ($shownavbar == '1' && $status==1) {
+		if (api_is_allowed_to_edit(null, true)) {
 			$header = '<div class="actions">';
 			$header .= '<a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat=' . $selectcat . '">'. Display::return_icon(('back.png'),get_lang('FolderView')) . get_lang('FolderView') . '</a>';
 			if ($evalobj->get_course_code() == null) {
@@ -268,7 +268,7 @@ class DisplayGradebook
 		$user_id=api_get_user_id();
 		$course_code=$my_category['course_code'];
 		$status_user=api_get_status_of_user_in_course ($user_id,$course_code);
-		if (($status_user==1 && $is_course_admin && !isset ($_GET['search'])) || api_is_platform_admin() || api_is_course_coach()) {
+		if (api_is_allowed_to_edit(null, true)) {
 			if ($selectcat == '0') {
                 if ($show_add_qualification === true) {
 				   // $header .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat=0"><img src="../img/folder_new.gif" alt="' . get_lang('NewCategory') . '" /> ' . get_lang('NewCategory') . '</a></td>';
@@ -306,7 +306,7 @@ class DisplayGradebook
                 		$header .= '<td style="vertical-align: top;"><a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() .'">'.Display::return_icon('acces_tool.gif', get_lang('ScoreEdit')).' ' . get_lang('ScoreEdit') . '</a>';
 	            
 					}
-					if (api_is_course_admin() || api_is_platform_admin() || api_is_course_coach()) {
+					if (api_is_allowed_to_edit(null, true)) {
 						$header .= '<td style="vertical-align: top;"><a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('stats_access.gif', get_lang('FlatView')).' ' . get_lang('FlatView') . '</a>';		
 						$header .= '<td style="vertical-align: top;"><a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('acces_tool.gif', get_lang('AttachCertificate')).' ' . get_lang('AttachCertificate') . '</a>';
 						$header .= '<td style="vertical-align: top;"><a href="gradebook_display_certificate.php?'.$my_api_cidreq.'&amp;cat_id='.(int)$_GET['selectcat'].'">'.Display::return_icon('acces_tool.gif', get_lang('Certificate')).' ' . get_lang('GradebookSeeListOfStudentsCertificates') . '</a>';
@@ -324,7 +324,7 @@ class DisplayGradebook
 	function display_reduce_header_gradebook($catobj,$is_course_admin, $is_platform_admin, $simple_search_form, $show_add_qualification = true, $show_add_link = true) {
 		//student
 		if (!$is_course_admin) {
-			/*$user= get_user_info_from_id(api_get_user_id());
+			$user= get_user_info_from_id(api_get_user_id());
 			$catcourse= Category :: load($catobj->get_id());
 			$scoredisplay = ScoreDisplay :: instance();
 			$scorecourse = $catcourse[0]->calc_score(api_get_user_id());
@@ -337,7 +337,7 @@ class DisplayGradebook
 				$scoreinfo.= '<br />'.get_lang('TotalForThisCategory') . ' : <b>' . $scorecourse_display . '</b>';
 			$scoreinfo.= '<br />'.get_lang('Total') . ' : <b>' . $scoretotal_display . '</b>';
 			Display :: display_normal_message($scoreinfo,false);
-			*/
+			
 		}
 			// show navigation tree and buttons?
 			$header = '<div class="actions">';

+ 7 - 7
main/gradebook/lib/fe/gradebooktable.class.php

@@ -31,14 +31,14 @@ class GradebookTable extends SortableTable
 			$this->set_additional_parameters($addparams);
 		}
 		$column= 0;
-		if ((($status==1 || is_null($status)) && api_is_allowed_to_create_course()) && ($_SESSION['studentview']<>'studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
+		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++,'','','width="25px"');
 		}
 		$this->set_header($column++, get_lang('Type'),'','width="35px"');
 		$this->set_header($column++, get_lang('Name'));
 		$this->set_header($column++, get_lang('Description'));
 
-		if (($status==1 || is_null($status))  && api_is_allowed_to_create_course() && $_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
+		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++, get_lang('Weight'),'','width="50px"');
 		} else {
 			if (empty($_GET['selectcat']) ) {
@@ -49,13 +49,13 @@ class GradebookTable extends SortableTable
 
 			}
 		}
-		if (($status==1 || is_null($status))  && api_is_allowed_to_create_course()) {
+		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++, get_lang('Date'),true, 'width="100px"');
 		} elseif (($status<>1)  && !api_is_allowed_to_create_course() && (!isset($_GET['selectcat']) || $_GET['selectcat']==0)) {
 			$this->set_header($column++, get_lang('Date'),true, 'width="100px"');
 		}
 		//admins get an edit column
-		if (($status==1 || is_null($status)) && api_is_allowed_to_create_course() && $_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
+		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++, get_lang('Modify'), false, 'width="100"');
 			//actions on multiple selected documents
 			$this->set_form_actions(array (
@@ -133,14 +133,14 @@ class GradebookTable extends SortableTable
 			$invisibility_span_open = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
 			$invisibility_span_close = (api_is_allowed_to_create_course() && $item->is_visible() == '0') ? '</span>' : '';
 
-			if (/*($status_user==1 ||is_null($status_user)) && */api_is_allowed_to_create_course() && ($_SESSION['studentview']<>'studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false')) {
+			if (api_is_allowed_to_edit(null, true)) {
 				$row[] = $this->build_id_column ($item);
 			}
 
 			$row[] = $this->build_type_column ($item);
 			$row[] = $invisibility_span_open . $this->build_name_link ($item) . $invisibility_span_close;
 			$row[] = $invisibility_span_open . $data[2] . $invisibility_span_close;
-			if (($status_user==1 || is_null($status_user)) && api_is_allowed_to_create_course()) {
+			if (api_is_allowed_to_edit(null, true)) {
 				$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
 				$weight_total_links += intval($data[3]);
 			} else {
@@ -175,7 +175,7 @@ class GradebookTable extends SortableTable
 				$row[] = $invisibility_span_open . str_replace(' ','&nbsp;',$data[4]) . $invisibility_span_close;
 			
 			//admins get an edit column
-			if (($status_user==1 || is_null($status_user)) && api_is_allowed_to_create_course() && ($_SESSION['studentview']<>'studentview' || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false'))) {
+			if (api_is_allowed_to_edit(null, true)) {
 				$cat=new Category();
 				$show_message=$cat->show_message_resource_delete($item->get_course_code());				
 				if ($show_message===false) {

+ 1 - 1
main/gradebook/lib/fe/resulttable.class.php

@@ -138,7 +138,7 @@ class ResultTable extends SortableTable
 
 	private function build_edit_column ($item) {
 		$status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
-		if ($status==1) {//api_is_course_admin()
+		if (api_is_allowed_to_edit(null, true)) {//api_is_course_admin()
 			$edit_column = '<a href="' . api_get_self() . '?editres=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '"><img src="../img/edit.gif" border="0" title="' . get_lang('Modify') . '" alt="" /></a>';
 		}
 		if ($this->evaluation->get_course_code() == null) {

+ 1 - 1
main/gradebook/lib/gradebook_data_generator.class.php

@@ -91,7 +91,7 @@ class GradebookDataGenerator
 			$row[] = $item->get_name();
 			$row[] = $item->get_description();
 			$row[] = $item->get_weight();
-			if (($status==1 || is_null($status))  && api_is_allowed_to_create_course()) {
+			if (api_is_allowed_to_edit(null, true)) {
 				$row[] = $this->build_date_column ($item);
 			}
 			if(count($this->evals_links)>0)

+ 1 - 1
main/gradebook/lib/gradebook_functions.inc.php

@@ -196,7 +196,7 @@ function build_edit_icons_eval($eval, $selectcat) {
 		$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'" onclick="return confirmation();"><img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>';
 		//$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?moveeval=' . $eval->get_id() . '&selectcat=' . $selectcat . '"><img src="../img/deplacer_fichier.gif" border="0" title="' . get_lang('Move') . '" alt="" /></a>';
 		$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=' . $selectcat . ' "><img src="../img/' . $visibility_icon . '.gif" border="0" title="' . get_lang('Visible') . '" alt="" /></a>';
-		if ($status==1 || is_null($status)){
+		if (api_is_allowed_to_edit(null, true)){
 			$modify_icons .= '&nbsp;<a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&amp;selectcat=' . $selectcat . ' &amp;cidReq='.$eval->get_course_code().'"><img src="../img/file_txt_small.gif" border="0" title="' . get_lang('GradebookQualifyLog') . '" alt="" /></a>';
 		}
 		return $modify_icons;

+ 1 - 1
main/install/update-db-scorm-1.6.x-1.8.0.inc.php

@@ -39,7 +39,7 @@ function my_get_time($time) {
 // Open log file
 $fh = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'.log', 'w');
 $fh_revert = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'_revert.log', 'w');
-$fh_res = fopen(api_get_path(SYS_ARCHIVE_PATH)'newscorm_'.time().'_res.log', 'w');
+$fh_res = fopen(api_get_path(SYS_ARCHIVE_PATH).'newscorm_'.time().'_res.log', 'w');
 fwrite($fh, "-- Recording course homepages links changes to enable reverting\n");
 fwrite($fh_revert, "-- Recording reverted course homepages links changes to enable reverting\n");
 fwrite($fh_res, "-- Recording resulting course homepages links changes\n");