Added support for .txt files - refs BT#7010

1.9.x
Yannick Warnier 12 years ago
parent b8aaa09ab0
commit 1fe1829419
  1. 2
      main/exercice/aiken.php
  2. 29
      main/exercice/export/aiken/aiken_import.inc.php

@ -66,7 +66,7 @@ function aiken_import_file($array_file) {
require_once $lib_path.'fileUpload.lib.php'; require_once $lib_path.'fileUpload.lib.php';
require_once $lib_path.'fileManage.lib.php'; require_once $lib_path.'fileManage.lib.php';
$process = process_uploaded_file($array_file); $process = process_uploaded_file($array_file);
if (preg_match('/\.zip$/i', $array_file['name'])) { if (preg_match('/\.(zip|txt)$/i', $array_file['name'])) {
// if it's a zip, allow zip upload // if it's a zip, allow zip upload
$unzip = 1; $unzip = 1;
} }

@ -43,13 +43,15 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) {
if (!isset ($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) { if (!isset ($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) {
// upload failed // upload failed
return false; return false;
} }
if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1)) { if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1)) {
if (!function_exists('gzopen')) { if (!function_exists('gzopen')) {
return false; return false;
} }
// upload successful // upload successful
return true; return true;
} elseif (preg_match('/.txt/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 0)) {
return true;
} else { } else {
return false; return false;
} }
@ -77,7 +79,7 @@ function import_exercise($file) {
// set some default values for the new exercise // set some default values for the new exercise
$exercise_info = array (); $exercise_info = array ();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file); $exercise_info['name'] = preg_replace('/.(zip|txt)$/i', '', $file);
$exercise_info['question'] = array(); $exercise_info['question'] = array();
$element_pile = array (); $element_pile = array ();
@ -86,15 +88,17 @@ function import_exercise($file) {
//$module_info = array (); //array to store the info we need //$module_info = array (); //array to store the info we need
// if file is not a .zip, then we cancel all // if file is not a .zip, then we cancel all
if (!preg_match('/.zip$/i', $file)) { if (!preg_match('/.(zip|txt)$/i', $file)) {
Display :: display_error_message(get_lang('You must upload a zip file')); Display :: display_error_message(get_lang('YouMustUploadAZipOrTxtFile'));
return false; return false;
} }
// unzip the uploaded file in a tmp directory // unzip the uploaded file in a tmp directory
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) { if (preg_match('/.(zip|txt)$/i', $file)) {
Display :: display_error_message(get_lang('You must upload a zip file')); if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
return false; Display :: display_error_message(get_lang('ThereWasAProblemWithYourFile'));
return false;
}
} }
// find the different manifests for each question and parse them. // find the different manifests for each question and parse them.
@ -120,7 +124,7 @@ function import_exercise($file) {
} // else ignore file } // else ignore file
} }
if (!$file_found) { if (!$file_found) {
Display :: display_error_message(get_lang('No TXT file found in the zip')); Display :: display_error_message(get_lang('NoTxtFileFoundInTheZip'));
return false; return false;
} }
if ($result == false ) { if ($result == false ) {
@ -153,14 +157,16 @@ function import_exercise($file) {
$answer->new_nbrAnswers = count($question_array['answer']); $answer->new_nbrAnswers = count($question_array['answer']);
//error_log('Scanning answers'); //error_log('Scanning answers');
$max_score = 0; $max_score = 0;
error_log(print_r($question_array['feedback'],1));
foreach ($question_array['answer'] as $key => $answers) { foreach ($question_array['answer'] as $key => $answers) {
$key++; $key++;
$answer->new_answer[$key] = $answers['value']; // answer ... $answer->new_answer[$key] = $answers['value']; // answer ...
$answer->new_comment[$key] = $answers['feedback']; // comment ... //$answer->new_comment[$key] = $answers['feedback']; // comment ...
$answer->new_position[$key] = $key; // position ... $answer->new_position[$key] = $key; // position ...
// correct answers ... // correct answers ...
if (in_array($key, $question_array['correct_answers'])) { if (in_array($key, $question_array['correct_answers'])) {
$answer->new_correct[$key] = 1; $answer->new_correct[$key] = 1;
$answer->new_comment[$key] = $question_array['feedback'];
} else { } else {
$answer->new_correct[$key] = 0; $answer->new_correct[$key] = 0;
} }
@ -209,6 +215,7 @@ function parse_file($exercisePath, $file, $questionFile) {
$info = utf8_encode($info); $info = utf8_encode($info);
} }
$exercise_info['question'][$question_index]['type'] = 'MCUA'; $exercise_info['question'][$question_index]['type'] = 'MCUA';
$exercise_info['question'][$question_index]['feedback'] = '';
if (preg_match('/^([A-Z])(\)|\.)\s(.*)/', $info, $matches)) { if (preg_match('/^([A-Z])(\)|\.)\s(.*)/', $info, $matches)) {
//adding one of the posible answers //adding one of the posible answers
$exercise_info['question'][$question_index]['answer'][]['value'] = $matches[3]; $exercise_info['question'][$question_index]['answer'][]['value'] = $matches[3];
@ -222,7 +229,9 @@ function parse_file($exercisePath, $file, $questionFile) {
} elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) { } elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) {
//Comment of correct answer //Comment of correct answer
$correct_answer_index = array_search($matches[1], $answers_array); $correct_answer_index = array_search($matches[1], $answers_array);
$exercise_info['question'][$question_index]['answer'][$correct_answer_index]['feedback'] = $matches[1]; //$exercise_info['question'][$question_index]['answer'][$correct_answer_index]['feedback'] = $matches[1];
$exercise_info['question'][$question_index]['feedback'] = $matches[1];
error_log('Storing feedback: '.$matches[1]);
} elseif (preg_match('/^TAGS:\s?([A-Z])\s?/', $info, $matches)) { } elseif (preg_match('/^TAGS:\s?([A-Z])\s?/', $info, $matches)) {
//TAGS for chamilo >= 1.10 //TAGS for chamilo >= 1.10
$exercise_info['question'][$question_index]['answer_tags'] = explode(',', $matches[1]); $exercise_info['question'][$question_index]['answer_tags'] = explode(',', $matches[1]);

Loading…
Cancel
Save