From cfac0250b855b8321f80c2905293d154747ca445 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 27 Jun 2014 17:38:05 +0200 Subject: [PATCH] Fixing qti import response see BT#7780 --- main/exercice/export/exercise_import.inc.php | 18 +++++----- main/exercice/qti2.php | 38 +++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/main/exercice/export/exercise_import.inc.php b/main/exercice/export/exercise_import.inc.php index 41324583dc..0c460b596e 100755 --- a/main/exercice/export/exercise_import.inc.php +++ b/main/exercice/export/exercise_import.inc.php @@ -102,14 +102,14 @@ function import_exercise($file) // 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; + + return 'UplZipCorrupt'; } // 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; + + return 'UplZipCorrupt'; } // find the different manifests for each question and parse them. @@ -144,15 +144,14 @@ function import_exercise($file) } if (!$file_found) { - Display :: display_error_message(get_lang('No XML file found in the zip')); - return false; + + return 'No XML file found in the zip'; } if ($result == false) { return false; } - $doc = new DOMDocument(); $doc->load($filePath); $encoding = $doc->encoding; @@ -207,9 +206,10 @@ function import_exercise($file) // delete the temp dir where the exercise was unzipped my_delete($baseWorkDir . $uploadPath); - $operation = true; + return $last_exercise_id; } - return $operation; + + return false; } /** * We assume the file charset is UTF8 diff --git a/main/exercice/qti2.php b/main/exercice/qti2.php index cbff29efe4..2f452b3db6 100755 --- a/main/exercice/qti2.php +++ b/main/exercice/qti2.php @@ -10,7 +10,7 @@ * Code */ // name of the language file that needs to be included -$language_file = 'exercice'; +$language_file = array('exercice', 'document'); // including the global Chamilo file require_once '../inc/global.inc.php'; @@ -62,7 +62,7 @@ function ch_qti2_display_form() /** * This function will import the zip file with the respective qti2 - * @param array $uploaded_file ($_FILES) + * @param array $array_file ($_FILES) */ function ch_qti2_import_file($array_file) { @@ -70,7 +70,9 @@ function ch_qti2_import_file($array_file) $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); + + $process = process_uploaded_file($array_file, false); + if (preg_match('/\.zip$/i', $array_file['name'])) { // if it's a zip, allow zip upload $unzip = 1; @@ -81,28 +83,32 @@ function ch_qti2_import_file($array_file) 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']); + return import_exercise($array_file['name']); + } + + return 'langFileError'; +} + +$message = null; - if ($imported) { - header('Location: '.api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq()); +// import file +if ((api_is_allowed_to_edit(null, true))) { + if (isset($_POST['submit'])) { + $imported = ch_qti2_import_file($_FILES['userFile']); + + if (is_numeric($imported) && !empty($imported)) { + header('Location: '.api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&exerciseId='.$imported); exit; } else { - Display::display_error_message(get_lang('UplNoFileUploaded')); - - return false; + $message = Display::return_message(get_lang($imported)); } - } + } } // Display header Display::display_header(get_lang('ImportQtiQuiz'), 'Exercises'); -// import file -if ((api_is_allowed_to_edit(null, true))) { - if (isset($_POST['submit'])) { - ch_qti2_import_file($_FILES['userFile']); - } -} +echo $message; // display qti form ch_qti2_display_form();