-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathchange_binding_username_claim_tool.php
128 lines (99 loc) · 4.3 KB
/
change_binding_username_claim_tool.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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/>.
/**
* Change binding username claim tool page.
*
* @package auth_oidc
* @author Lai Wei <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2023 onwards Microsoft, Inc. (http://microsoft.com/)
*/
use auth_oidc\form\change_binding_username_claim_tool_form1;
use auth_oidc\form\change_binding_username_claim_tool_form2;
use auth_oidc\preview;
use auth_oidc\process;
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->libdir . '/csvlib.class.php');
require_login();
$url = new moodle_url('/auth/oidc/change_binding_username_claim_tool.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_heading(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));
$PAGE->set_title(get_string('settings_page_change_binding_username_claim_tool', 'auth_oidc'));
admin_externalpage_setup('auth_oidc_change_binding_username_claim_tool');
require_admin();
$iid = optional_param('iid', '', PARAM_INT);
$previewrows = optional_param('previewrows', 10, PARAM_INT);
core_php_time_limit::raise(60 * 60); // 1 hour should be enough.
raise_memory_limit(MEMORY_HUGE);
if (empty($iid)) {
$form1 = new change_binding_username_claim_tool_form1();
if ($formdata = $form1->get_data()) {
$iid = csv_import_reader::get_new_iid('changebindingusernameclaimtool');
$cir = new csv_import_reader($iid, 'changebindingusernameclaimtool');
$content = $form1->get_file_content('usernamefile');
$readcount = $cir->load_csv_content($content, $formdata->encoding, $formdata->delimiter_name);
$csvloaderror = $cir->get_error();
unset($content);
if (!is_null($csvloaderror)) {
throw new moodle_exception('csvloaderror', '', $url, $csvloaderror);
}
} else {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('change_binding_username_claim_tool', 'auth_oidc'));
$bindingusernameclaimurl = new moodle_url('/auth/oidc/binding_username_claim.php');
echo html_writer::tag('p', get_string('change_binding_username_claim_tool_description', 'auth_oidc',
$bindingusernameclaimurl->out()));
$form1->display();
echo $OUTPUT->footer();
exit;
}
} else {
$cir = new csv_import_reader($iid, 'changebindingusernameclaimtool');
}
// Test if columns ok.
$process = new process($cir);
$filecolumns = $process->get_file_columns();
$mform2 = new change_binding_username_claim_tool_form2(null,
['columns' => $filecolumns, 'data' => ['iid' => $iid, 'previewrows' => $previewrows]]);
// If a file has been uploaded, then process it.
if ($mform2->is_cancelled()) {
$cir->cleanup(true);
redirect($url);
} else if ($formdata = $mform2->get_data()) {
// Print the header.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('change_binding_username_claim_tool_result', 'auth_oidc'));
$process->set_form_data($formdata);
$process->process();
echo $OUTPUT->box_start('boxwidthnarrow boxaligncenter generalbox', 'uploadresults');
echo html_writer::tag('p', join('<br />', $process->get_stats()));
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
// Print the header.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('change_binding_username_claim_tool', 'auth_oidc'));
$table = new preview($cir, $filecolumns, $previewrows);
echo html_writer::tag('div', html_writer::table($table), ['class' => 'flexible-wrap']);
if ($table->get_no_error()) {
$mform2->display();
}
echo $OUTPUT->footer();
exit;