-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
103 lines (91 loc) · 3.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Import a framework.
*
* @package tool_uploadactivitycompletions
* @copyright 2020 Tim St.Clair (https://github.com/frumbert/)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/phpunit/classes/util.php');
admin_externalpage_setup('tooluploadactivitycompletions');
$pagetitle = get_string('pluginname', 'tool_uploadactivitycompletions');
$context = context_system::instance();
$url = new moodle_url("/admin/tool/uploadactivitycompletions/index.php");
$returnurl = new moodle_url("/admin/tool/uploadactivitycompletions/index.php");
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_title($pagetitle);
$PAGE->set_pagelayout('admin');
$PAGE->set_heading($pagetitle);
$importid = optional_param('importid', '', PARAM_INT);
$confirm = optional_param('confirm', '0', PARAM_BOOL);
$needsconfirm = optional_param('needsconfirm', '0', PARAM_BOOL);
$text = null;
$encoding = null;
$delimiter = null;
// First time - import_form returns a 0, and import_confirm_form a 1.
if (empty($importid)) {
$mform1 = new tool_uploadactivitycompletions_import_form($url->out(false));
// Was the first form submitted.
if ($form1data = $mform1->get_data()) {
$text = $mform1->get_file_content('importfile');
$encoding = $form1data->encoding;
$delimiter = $form1data->delimiter_name;
} else {
// First time.
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
$mform1->display();
echo $OUTPUT->footer();
die();
}
}
$importer = new tool_uploadactivitycompletions_importer($text, $encoding, $delimiter);
unset($text);
$mform2 = new tool_uploadactivitycompletions_import_confirm_form(null, $importer);
// Was the second form submitted.
if ($form2data = $mform2->is_cancelled()) {
redirect($returnurl);
} else if ($form2data = $mform2->get_data()) {
$importid = $form2data->importid;
$importer = new tool_uploadactivitycompletions_importer(null, null, null, $importid, $form2data);
$error = $importer->get_error();
if ($error) {
redirect($returnurl);
} else {
$processingresponse = $importer->execute(new tool_uploadactivitycompletions_tracker(tool_uploadactivitycompletions_tracker::OUTPUT_HTML, false));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('uploadactivitycompletionsresult', 'tool_uploadactivitycompletions'));
echo $processingresponse;
echo $OUTPUT->continue_button($url);
}
} else {
// First time.
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
if (!completion_info::is_enabled_for_site()) {
echo get_string("completionnotenabledforsite");
} else {
$mform2->display();
}
echo $OUTPUT->footer();
die();
}
echo $OUTPUT->footer();