Repository navigation
Expand file tree
/
Copy pathglossarymanageradmin.php
More file actions
82 lines (71 loc) · 3.02 KB
/
Copy pathglossarymanageradmin.php
File metadata and controls
82 lines (71 loc) · 3.02 KB
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
<?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/>.
/**
* Local Deepler plugin glossaries management settings in Admin.
*
* @package local_deepler
* @copyright 2025 Bruno Baudry
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use DeepL\DeepLClient;
use local_deepler\local\services\lang_helper;
use local_deepler\local\data\glossary;
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/version.php');
require_login();
global $USER, $PAGE, $OUTPUT;
$context = context_user::instance($USER->id);
require_login();
require_capability('local/deepler:edittranslations', $context);
$PAGE->set_context($context);
/** @var local_deepler\output\glossary_renderer $renderer */
$renderer = $PAGE->get_renderer('local_deepler', 'glossary');
$PAGE->set_url(new moodle_url('/local/deepler/glossarymanager.php'));
$title = get_string('glossary:manage:title', 'local_deepler');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_pagelayout('base');
echo $OUTPUT->header();
// Load glossary manager.
$apikey = get_config('local_deepler', 'apikey');
if ($apikey) {
$langhelper = new lang_helper(new DeepLClient($apikey), $apikey);
$langhelper->initdeepl($USER, $plugin->release);
// Prepare content.
$pluginsglossaries = $langhelper->syncdeeplglossaries();
// Handle glossary deletion status.
if (isset($_REQUEST['deletestatus'])) {
// Statuses are: deeplissue, failed, idmissing, invalidsesskey, success.
$status = $_REQUEST['deletestatus'];
$glossary = $_REQUEST['name'] . ' (' . $_REQUEST['token'] . ')';
echo $renderer->handle_glossary_status('delete', $status, $glossary);
}
// Handle glossary upload status.
if (isset($_REQUEST['uploadstatus'])) {
// Statuses are: deeplissue, failed, fileerror, invalidsesskey, success, suffixerror, unknownerror.
$status = $_REQUEST['uploadstatus'];
$message = $_REQUEST['message'] ?? '';
echo $renderer->handle_glossary_status('upload', $status, $message);
}
// Glossary table.
echo $renderer->glossary_uploader('admin');
echo $renderer->glossaries_table_admin($pluginsglossaries);
} else {
echo $renderer->glossary_warning(get_string('error'), get_string('missingmainapikey', 'local_deepler'));
}
// Add js.
$PAGE->requires->js_call_amd('local_deepler/glossary', 'init', ['version' => $plugin->release]);
echo $OUTPUT->footer();