/** * This function will import the zip file with the respective qti2 * @param array $array_file ($_FILES) */ function ch_qti2_import_file($array_file) { $unzip = 0; $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; } if ($process && $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'; return import_exercise($array_file['name']); } return 'langFileError'; }
/** * 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); $process = FileManager::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/exercise_import.inc.php'; require_once $main_path . 'exercice/export/qti2/qti2_classes.php'; $imported = import_exercise($array_file['name']); if ($imported) { header('Location: exercice.php?' . api_get_cidreq()); } else { Display::display_error_message(get_lang('UplNoFileUploaded')); return false; } } }
include_once '../exercise.class.php'; //Tool title $nameTools = get_lang('ImportExercise'); //bredcrump $interbredcrump[] = array('url' => '../exercice.php', 'name' => get_lang('Exercises')); //---------------------------------- // EXECUTE COMMAND //---------------------------------- $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'show_import'; switch ($cmd) { case 'show_import': $display = '<p>' . get_lang('Imported exercises must consist of a zip or an XML file (IMS-QTI) and be compatible with your Claroline version.') . '<br>' . '</p>' . '<form enctype="multipart/form-data" action="" method="post">' . '<input name="cmd" type="hidden" value="import" />' . '<input name="uploadedExercise" type="file" /><br><br>' . get_lang('Import exercise') . ' : ' . '<input value="' . get_lang('Ok') . '" type="submit" /> ' . claro_html_button($_SERVER['PHP_SELF'], get_lang('Cancel')) . '<br><br>' . '<small>' . get_lang('Max file size') . ' : 2 MB</small>' . '</form>'; break; case 'import': //include needed librabries for treatment $result_log = import_exercise($_FILES['uploadedExercise']['name']); //display the result message (fail or success) $dialogBox = ''; foreach ($result_log as $log) { $dialogBox .= $log . '<br>'; } break; } //---------------------------------- // FIND INFORMATION //---------------------------------- //empty! //---------------------------------- // DISPLAY //---------------------------------- include api_get_path(INCLUDE_PATH) . '/header.inc.php';
if ($is_allowedToEdit && !is_null($cmd)) { //-- import if ($cmd == 'exImport') { require_once get_path('incRepositorySys') . '/lib/fileManage.lib.php'; require_once get_path('incRepositorySys') . '/lib/fileDisplay.lib.php'; require_once get_path('incRepositorySys') . '/lib/fileUpload.lib.php'; require_once get_path('incRepositorySys') . '/lib/file.lib.php'; require_once './export/exercise_import.inc.php'; require_once './lib/question.class.php'; require_once './export/qti2/qti2_classes.php'; require_once get_path('incRepositorySys') . '/lib/backlog.class.php'; if (!isset($_FILES['uploadedExercise']['name'])) { $dialogBox->error(get_lang('Error : no file uploaded')); } else { $backlog = new Backlog(); $importedExId = import_exercise($_FILES['uploadedExercise']['name'], $backlog); if ($importedExId) { $dialogBox->success('<strong>' . get_lang('Import done') . '</strong>'); } else { $dialogBox->error('<strong>' . get_lang('Import failed') . '</strong>'); $cmd = 'rqImport'; } $dialogBox->info($backlog->output()); } } if ($cmd == 'rqImport') { require_once get_path('incRepositorySys') . '/lib/fileDisplay.lib.php'; require_once get_path('incRepositorySys') . '/lib/fileUpload.lib.php'; $dialogBox->form("\n" . '<strong>' . get_lang('Import exercise') . '</strong><br />' . "\n" . get_lang('Imported exercises must be an ims-qti zip file.') . '<br />' . "\n" . '<form enctype="multipart/form-data" action="./exercise.php" method="post">' . "\n" . '<input type="hidden" name="claroFormId" value="' . uniqid('') . '">' . "\n" . '<input name="cmd" type="hidden" value="exImport" />' . "\n" . claro_form_relay_context() . "\n" . '<input name="uploadedExercise" type="file" /><br />' . "\n" . '<small>' . get_lang('Max file size') . ' : ' . format_file_size(get_max_upload_size($maxFilledSpace, $courseDir)) . '</small>' . "\n" . '<p>' . "\n" . '<input value="' . get_lang('Import exercise') . '" type="submit" /> ' . "\n" . claro_html_button(Url::Contextualize('./exercise.php'), get_lang('Cancel')) . '</p>' . "\n" . '</form>'); } //-- export