source: moodle/trunk/fuentes/admin/tool/langimport/index.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 7.7 KB
Line 
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 * Fetches language packages from download.moodle.org server
19 *
20 * Language packages are available at https://download.moodle.org/langpack/
21 * in ZIP format together with a file languages.md5 containing their hashes
22 * and meta info.
23 * Locally, language packs are saved into $CFG->dataroot/lang/
24 *
25 * @package    tool
26 * @subpackage langimport
27 * @copyright  2005 Yu Zhang
28 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 */
30
31require(__DIR__.'/../../../config.php');
32require_once($CFG->libdir.'/adminlib.php');
33
34admin_externalpage_setup('toollangimport');
35
36if (empty($CFG->langotherroot)) {
37    throw new moodle_exception('missingcfglangotherroot', 'tool_langimport');
38}
39
40$mode          = optional_param('mode', 0, PARAM_INT);              // action
41$pack          = optional_param_array('pack', array(), PARAM_SAFEDIR);    // pack to install
42$uninstalllang = optional_param('uninstalllang', '', PARAM_LANG);   // installed pack to uninstall
43$confirm       = optional_param('confirm', 0, PARAM_BOOL);          // uninstallation confirmation
44$purgecaches   = optional_param('purgecaches', false, PARAM_BOOL);  // explicit caches reset
45
46if ($purgecaches) {
47    require_sesskey();
48    get_string_manager()->reset_caches();
49    redirect($PAGE->url);
50}
51
52if (!empty($CFG->skiplangupgrade)) {
53    echo $OUTPUT->header();
54    echo $OUTPUT->box(get_string('langimportdisabled', 'tool_langimport'));
55    echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('purgecaches' => 1)), get_string('purgestringcaches', 'tool_langimport'));
56    echo $OUTPUT->footer();
57    die;
58}
59
60define('INSTALLATION_OF_SELECTED_LANG', 2);
61define('DELETION_OF_SELECTED_LANG', 4);
62define('UPDATE_ALL_LANG', 5);
63
64get_string_manager()->reset_caches();
65
66$controller = new tool_langimport\controller();
67
68if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) {
69    core_php_time_limit::raise();
70    $controller->install_languagepacks($pack);
71}
72
73if ($mode == DELETION_OF_SELECTED_LANG and !empty($uninstalllang)) {
74    if ($uninstalllang == 'en') {
75        // TODO.
76        $controller->errors[] = 'English language pack can not be uninstalled';
77
78    } else if (!$confirm and confirm_sesskey()) {
79        echo $OUTPUT->header();
80        echo $OUTPUT->confirm(get_string('uninstallconfirm', 'tool_langimport', $uninstalllang),
81                     'index.php?mode='.DELETION_OF_SELECTED_LANG.'&uninstalllang='.$uninstalllang.'&confirm=1',
82                     'index.php');
83        echo $OUTPUT->footer();
84        die;
85
86    } else if (confirm_sesskey()) {
87        $controller->uninstall_language($uninstalllang);
88    }
89}
90
91if ($mode == UPDATE_ALL_LANG) {
92    core_php_time_limit::raise();
93    $controller->update_all_installed_languages();
94}
95get_string_manager()->reset_caches();
96
97echo $OUTPUT->header();
98echo $OUTPUT->heading(get_string('langimport', 'tool_langimport'));
99
100$installedlangs = get_string_manager()->get_list_of_translations(true);
101
102$missingparents = array();
103foreach ($installedlangs as $installedlang => $unused) {
104    $parent = get_parent_language($installedlang);
105    if (empty($parent)) {
106        continue;
107    }
108    if (!isset($installedlangs[$parent])) {
109        $missingparents[$installedlang] = $parent;
110    }
111}
112
113if ($availablelangs = $controller->availablelangs) {
114    $remote = true;
115} else {
116    $remote = false;
117    $availablelangs = array();
118    echo $OUTPUT->box_start();
119    print_string('remotelangnotavailable', 'tool_langimport', $CFG->dataroot.'/lang/');
120    echo $OUTPUT->box_end();
121}
122
123if ($controller->info) {
124    $info = implode('<br />', $controller->info);
125    echo $OUTPUT->notification($info, 'notifysuccess');
126}
127
128if ($controller->errors) {
129    $info = implode('<br />', $controller->errors);
130    echo $OUTPUT->notification($info, 'notifyproblem');
131}
132
133if ($missingparents) {
134    foreach ($missingparents as $l => $parent) {
135        $a = new stdClass();
136        $a->lang   = $installedlangs[$l];
137        $a->parent = $parent;
138        foreach ($availablelangs as $alang) {
139            if ($alang[0] == $parent) {
140                $shortlang = $alang[0];
141                $a->parent = $alang[2].' ('.$shortlang.')';
142            }
143        }
144        $info = get_string('missinglangparent', 'tool_langimport', $a);
145        echo $OUTPUT->notification($info, 'notifyproblem');
146    }
147}
148
149echo $OUTPUT->box_start();
150
151echo html_writer::start_tag('table');
152echo html_writer::start_tag('tr');
153
154// list of installed languages
155$url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => DELETION_OF_SELECTED_LANG));
156echo html_writer::start_tag('td', array('valign' => 'top'));
157echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $url->out(), 'method' => 'post'));
158echo html_writer::start_tag('fieldset');
159echo html_writer::label(get_string('installedlangs', 'tool_langimport'), 'menuuninstalllang');
160echo html_writer::empty_tag('br');
161echo html_writer::select($installedlangs, 'uninstalllang', '', false, array('size' => 15));
162echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
163echo html_writer::empty_tag('br');
164echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('uninstall', 'tool_langimport')));
165echo html_writer::end_tag('fieldset');
166echo html_writer::end_tag('form');
167if ($remote) {
168    $url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => UPDATE_ALL_LANG));
169    echo html_writer::start_tag('form', array('id' => 'updateform', 'action' => $url->out(), 'method' => 'post'));
170    echo html_writer::tag('fieldset', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatelangs','tool_langimport'))));
171    echo html_writer::end_tag('form');
172}
173echo html_writer::end_tag('td');
174
175// list of available languages
176$options = array();
177foreach ($availablelangs as $alang) {
178    if (!empty($alang[0]) and trim($alang[0]) !== 'en' and !$controller->is_installed_lang($alang[0], $alang[1])) {
179        $options[$alang[0]] = $alang[2].' ('.$alang[0].')';
180    }
181}
182if (!empty($options)) {
183    echo html_writer::start_tag('td', array('valign' => 'top'));
184    $url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
185    echo html_writer::start_tag('form', array('id' => 'installform', 'action' => $url->out(), 'method' => 'post'));
186    echo html_writer::start_tag('fieldset');
187    echo html_writer::label(get_string('availablelangs','install'), 'menupack');
188    echo html_writer::empty_tag('br');
189    echo html_writer::select($options, 'pack[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
190    echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
191    echo html_writer::empty_tag('br');
192    echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('install','tool_langimport')));
193    echo html_writer::end_tag('fieldset');
194    echo html_writer::end_tag('form');
195    echo html_writer::end_tag('td');
196}
197
198echo html_writer::end_tag('tr');
199echo html_writer::end_tag('table');
200echo $OUTPUT->box_end();
201echo $OUTPUT->footer();
202die();
Note: See TracBrowser for help on using the repository browser.