MDL-78284 theme: Add new interactive content and update styles
[moodle.git] / admin / tool / lpimportcsv / index.php
blob8c25e02debb50652f16d1f87fe8f757a7ecab6a0
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Import a framework.
20 * @package tool_lpimportcsv
21 * @copyright 2016 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 define('NO_OUTPUT_BUFFERING', true);
25 require_once(__DIR__ . '/../../../config.php');
26 require_once($CFG->libdir.'/adminlib.php');
28 admin_externalpage_setup('toollpimportcsv');
30 $pagetitle = get_string('pluginname', 'tool_lpimportcsv');
32 $context = context_system::instance();
34 $url = new moodle_url("/admin/tool/lpimportcsv/index.php");
35 $PAGE->set_context($context);
36 $PAGE->set_url($url);
37 $PAGE->set_title($pagetitle);
38 $PAGE->set_pagelayout('admin');
39 $PAGE->set_heading($pagetitle);
41 $form = null;
42 echo $OUTPUT->header();
43 if (optional_param('needsconfirm', 0, PARAM_BOOL)) {
44 $form = new \tool_lpimportcsv\form\import($url->out(false));
45 } else if (optional_param('confirm', 0, PARAM_BOOL)) {
46 $importer = new \tool_lpimportcsv\framework_importer();
47 $form = new \tool_lpimportcsv\form\import_confirm(null, $importer);
48 } else {
49 $form = new \tool_lpimportcsv\form\import($url->out(false));
52 if ($form->is_cancelled()) {
53 $form = new \tool_lpimportcsv\form\import($url->out(false));
54 } else if ($data = $form->get_data()) {
55 require_sesskey();
57 if ($data->confirm) {
58 $importid = $data->importid;
59 $importer = new \tool_lpimportcsv\framework_importer(null, null, null, $importid, $data, true);
61 $error = $importer->get_error();
62 if ($error) {
63 $form = new \tool_lpimportcsv\form\import($url->out(false));
64 $form->set_import_error($error);
65 } else {
66 $framework = $importer->import();
67 $urlparams = ['competencyframeworkid' => $framework->get('id'), 'pagecontextid' => $context->id];
68 $frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', $urlparams);
69 echo $OUTPUT->notification(get_string('competencyframeworkcreated', 'tool_lp'), 'notifysuccess');
70 echo $OUTPUT->continue_button($frameworksurl);
71 die();
73 } else {
74 $text = $form->get_file_content('importfile');
75 $encoding = $data->encoding;
76 $delimiter = $data->delimiter_name;
77 $importer = new \tool_lpimportcsv\framework_importer($text, $encoding, $delimiter, 0, null, true);
78 $confirmform = new \tool_lpimportcsv\form\import_confirm(null, $importer);
79 $form = $confirmform;
80 $pagetitle = get_string('confirmcolumnmappings', 'tool_lpimportcsv');
84 echo $OUTPUT->heading($pagetitle);
86 $form->display();
88 echo $OUTPUT->footer();