Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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.
13
//
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/>.
16
 
17
/**
18
 * Import custom lang files.
19
 *
20
 * @package    tool_customlang
21
 * @subpackage customlang
22
 * @copyright  2020 Ferran Recio <ferran@moodle.com>
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
use tool_customlang\form\import;
27
use tool_customlang\local\importer;
28
 
29
require(__DIR__ . '/../../../config.php');
30
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php');
31
require_once($CFG->libdir.'/adminlib.php');
32
 
33
require_login(SITEID, false);
34
require_capability('tool/customlang:edit', context_system::instance());
35
 
36
$lng = required_param('lng', PARAM_LANG);
37
 
38
admin_externalpage_setup('toolcustomlang', '', null,
39
    new moodle_url('/admin/tool/customlang/import.php', ['lng' => $lng]));
40
 
41
$PAGE->set_context(context_system::instance());
42
 
43
$PAGE->set_secondary_active_tab('siteadminnode');
44
$PAGE->set_primary_active_tab('siteadminnode');
45
$PAGE->navbar->add(get_string('import', 'tool_customlang'), $PAGE->url);
46
 
47
$output = $PAGE->get_renderer('tool_customlang');
48
 
49
$form = new import(null, ['lng' => $lng]);
50
if ($data = $form->get_data()) {
51
    require_sesskey();
52
 
53
    // Get the file from the users draft area.
54
    $usercontext = context_user::instance($USER->id);
55
    $fs = get_file_storage();
56
    $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data->pack, 'id',
57
        false);
58
 
59
    // Send files to the importer.
60
    $importer = new importer($data->lng, $data->importmode);
61
    $importer->import($files);
62
 
63
    echo $output->header();
64
 
65
    // Display logs.
66
    $log = $importer->get_log();
67
    foreach ($log as $message) {
68
        echo $output->notification($message->get_message(), $message->errorlevel);
69
    }
70
 
71
    // Show continue button.
72
    echo $output->continue_button(new moodle_url('index.php', array('lng' => $lng)));
73
 
74
} else {
75
    echo $output->header();
76
 
77
    $form->display();
78
}
79
 
80
echo $OUTPUT->footer();