|
|
@ -7,6 +7,7 @@ |
|
|
|
* @author César Perales <cesar.perales@gmail.com> Parse function for Aiken format |
|
|
|
* @author César Perales <cesar.perales@gmail.com> Parse function for Aiken format |
|
|
|
* @package chamilo.exercise |
|
|
|
* @package chamilo.exercise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Security check |
|
|
|
* Security check |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -20,9 +21,11 @@ if (count(get_included_files()) == 1) |
|
|
|
* @param int $mode |
|
|
|
* @param int $mode |
|
|
|
* @return string |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function tempdir($dir, $prefix = 'tmp', $mode = 0777) { |
|
|
|
function tempdir($dir, $prefix = 'tmp', $mode = 0777) |
|
|
|
if (substr($dir, -1) != '/') |
|
|
|
{ |
|
|
|
|
|
|
|
if (substr($dir, -1) != '/') { |
|
|
|
$dir .= '/'; |
|
|
|
$dir .= '/'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
$path = $dir.$prefix.mt_rand(0, 9999999); |
|
|
|
$path = $dir.$prefix.mt_rand(0, 9999999); |
|
|
@ -40,7 +43,12 @@ function aiken_display_form() |
|
|
|
$name_tools = get_lang('ImportAikenQuiz'); |
|
|
|
$name_tools = get_lang('ImportAikenQuiz'); |
|
|
|
$form = '<div class="actions">'; |
|
|
|
$form = '<div class="actions">'; |
|
|
|
$form .= '<a href="exercise.php?show=test&'.api_get_cidreq().'">' . |
|
|
|
$form .= '<a href="exercise.php?show=test&'.api_get_cidreq().'">' . |
|
|
|
Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
|
|
Display::return_icon( |
|
|
|
|
|
|
|
'back.png', |
|
|
|
|
|
|
|
get_lang('BackToExercisesList'), |
|
|
|
|
|
|
|
'', |
|
|
|
|
|
|
|
ICON_SIZE_MEDIUM |
|
|
|
|
|
|
|
).'</a>'; |
|
|
|
$form .= '</div>'; |
|
|
|
$form .= '</div>'; |
|
|
|
$form_validator = new FormValidator( |
|
|
|
$form_validator = new FormValidator( |
|
|
|
'aiken_upload', |
|
|
|
'aiken_upload', |
|
|
@ -66,7 +74,8 @@ function aiken_display_form() |
|
|
|
* @param string $uploadPath |
|
|
|
* @param string $uploadPath |
|
|
|
* @return bool True on success, false on failure |
|
|
|
* @return bool True on success, false on failure |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) { |
|
|
|
function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) |
|
|
|
|
|
|
|
{ |
|
|
|
$_course = api_get_course_info(); |
|
|
|
$_course = api_get_course_info(); |
|
|
|
$_user = api_get_user_info(); |
|
|
|
$_user = api_get_user_info(); |
|
|
|
// Check if the file is valid (not to big and exists) |
|
|
|
// Check if the file is valid (not to big and exists) |
|
|
@ -74,6 +83,7 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) { |
|
|
|
// 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, 'overwrite', false)) { |
|
|
|
if (preg_match('/.zip$/i', $_FILES['userFile']['name']) && handle_uploaded_document($_course, $_FILES['userFile'], $baseWorkDir, $uploadPath, $_user['user_id'], 0, null, 1, 'overwrite', false)) { |
|
|
|
if (!function_exists('gzopen')) { |
|
|
|
if (!function_exists('gzopen')) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -117,7 +127,6 @@ function aiken_import_exercise($file) |
|
|
|
// unzip the uploaded file in a tmp directory |
|
|
|
// unzip the uploaded file in a tmp directory |
|
|
|
if (preg_match('/.(zip|txt)$/i', $file)) { |
|
|
|
if (preg_match('/.(zip|txt)$/i', $file)) { |
|
|
|
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) { |
|
|
|
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) { |
|
|
|
|
|
|
|
|
|
|
|
return 'ThereWasAProblemWithYourFile'; |
|
|
|
return 'ThereWasAProblemWithYourFile'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -155,7 +164,6 @@ function aiken_import_exercise($file) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($result !== true) { |
|
|
|
if ($result !== true) { |
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -236,7 +244,8 @@ function aiken_import_exercise($file) |
|
|
|
* @return string|boolean True on success, error message on error |
|
|
|
* @return string|boolean True on success, error message on error |
|
|
|
* @assert ('','','') === false |
|
|
|
* @assert ('','','') === false |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) { |
|
|
|
function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) |
|
|
|
|
|
|
|
{ |
|
|
|
global $questionTempDir; |
|
|
|
global $questionTempDir; |
|
|
|
|
|
|
|
|
|
|
|
$questionTempDir = $exercisePath . '/' . $file . '/'; |
|
|
|
$questionTempDir = $exercisePath . '/' . $file . '/'; |
|
|
@ -329,6 +338,7 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Imports the zip file |
|
|
|
* Imports the zip file |
|
|
|
* @param array $array_file ($_FILES) |
|
|
|
* @param array $array_file ($_FILES) |
|
|
|
|
|
|
|
* @return bool |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function aiken_import_file($array_file) |
|
|
|
function aiken_import_file($array_file) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -342,7 +352,6 @@ function aiken_import_file($array_file) |
|
|
|
if ($process && $unzip == 1) { |
|
|
|
if ($process && $unzip == 1) { |
|
|
|
$imported = aiken_import_exercise($array_file['name']); |
|
|
|
$imported = aiken_import_exercise($array_file['name']); |
|
|
|
if (is_numeric($imported) && !empty($imported)) { |
|
|
|
if (is_numeric($imported) && !empty($imported)) { |
|
|
|
|
|
|
|
|
|
|
|
Display::addFlash(Display::return_message(get_lang('Uploaded'))); |
|
|
|
Display::addFlash(Display::return_message(get_lang('Uploaded'))); |
|
|
|
|
|
|
|
|
|
|
|
return $imported; |
|
|
|
return $imported; |
|
|
|