From b8aaa09ab04be59a4eaf682a718bc3103c1db08c Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 27 Nov 2013 10:41:03 -0500 Subject: [PATCH] Minor: Code cleanup and re-ordering messages - refs BT#7010 --- main/exercice/aiken.php | 77 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/main/exercice/aiken.php b/main/exercice/aiken.php index c9a6ec4b5d..3f451f7ef8 100644 --- a/main/exercice/aiken.php +++ b/main/exercice/aiken.php @@ -1,11 +1,10 @@ Updated function names and import files for Aiken format support -* @version $Id: Aiken.php 2010-03-12 12:14:25Z $ +* Code for Aiken import integration. +* @package chamilo.exercise +* @author Ronny Velasquez +* @author César Perales Updated function names and import files for Aiken format support */ /** * Code @@ -29,7 +28,7 @@ $this_section = SECTION_COURSES; // access restriction: only teachers are allowed here if (!api_is_allowed_to_edit(null, true)) { - api_not_allowed(); + api_not_allowed(); } // the breadcrumbs @@ -39,18 +38,21 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true); /** * This function displays the form for import of the zip file with qti2 */ -function aiken_display_form() { - $name_tools = get_lang('ImportAikenQuiz'); - $form = ''; +function aiken_display_form($msg = '') { + $name_tools = get_lang('ImportAikenQuiz'); + $form = ''; + if (!empty($msg)) { + $form .= $msg; + } $form_validator = new FormValidator('aiken_upload', 'post',api_get_self()."?".api_get_cidreq(), null, array('enctype' => 'multipart/form-data') ); $form_validator->addElement('header', $name_tools); $form_validator->addElement('file', 'userFile', get_lang('DownloadFile')); $form_validator->addElement('style_submit_button', 'submit', get_lang('Send'), 'class="upload"'); - $form .= $form_validator->return_form(); + $form .= $form_validator->return_form(); - echo $form; + echo $form; } /** @@ -59,43 +61,44 @@ function aiken_display_form() { */ function aiken_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 && $unzip == 1) { - $main_path = api_get_path(SYS_CODE_PATH); - require_once $main_path.'exercice/export/aiken/aiken_import.inc.php'; + $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 && $unzip == 1) { + $main_path = api_get_path(SYS_CODE_PATH); + require_once $main_path.'exercice/export/aiken/aiken_import.inc.php'; require_once $main_path.'exercice/export/aiken/aiken_classes.php'; $imported = import_exercise($array_file['name']); if ($imported) { - header('Location: exercice.php?'.api_get_cidreq()); + header('Location: exercice.php?'.api_get_cidreq()); } else { - Display::display_error_message(get_lang('UplNoFileUploaded')); - return false; + $msg = Display::return_message(get_lang('UplNoFileUploaded'),'error'); + return $msg; } - } + } } -// display header -Display::display_header(get_lang('ImportAikenQuiz'), 'Exercises'); - +$msg = ''; // import file if ((api_is_allowed_to_edit(null, true))) { - if (isset($_POST['submit'])) { - aiken_import_file($_FILES['userFile']); - } + if (isset($_POST['submit'])) { + $msg = aiken_import_file($_FILES['userFile']); + } } +// display header +Display::display_header(get_lang('ImportAikenQuiz'), 'Exercises'); + // display Aiken form -aiken_display_form(); +aiken_display_form($msg); // display the footer Display::display_footer(); \ No newline at end of file