source: moodle/trunk/fuentes/admin/tool/customlang/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: 5.0 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 * Performs checkout of the strings into the translation table
19 *
20 * @package    tool
21 * @subpackage customlang
22 * @copyright  2010 David Mudrak <david@moodle.com>
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26define('NO_OUTPUT_BUFFERING', true); // progress bar is used here
27
28require(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
29require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php');
30require_once($CFG->libdir.'/adminlib.php');
31
32require_login(null, false);
33require_capability('tool/customlang:view', context_system::instance());
34
35$action  = optional_param('action', '', PARAM_ALPHA);
36$confirm = optional_param('confirm', false, PARAM_BOOL);
37$lng     = optional_param('lng', '', PARAM_LANG);
38
39admin_externalpage_setup('toolcustomlang');
40$langs = get_string_manager()->get_list_of_translations();
41
42// pre-output actions
43if ($action === 'checkout') {
44    require_sesskey();
45    require_capability('tool/customlang:edit', context_system::instance());
46    if (empty($lng)) {
47        print_error('missingparameter');
48    }
49
50    $PAGE->set_cacheable(false);    // progress bar is used here
51    $output = $PAGE->get_renderer('tool_customlang');
52    echo $output->header();
53    echo $output->heading(get_string('pluginname', 'tool_customlang'));
54    $progressbar = new progress_bar();
55    $progressbar->create();         // prints the HTML code of the progress bar
56
57    // we may need a bit of extra execution time and memory here
58    core_php_time_limit::raise(HOURSECS);
59    raise_memory_limit(MEMORY_EXTRA);
60    tool_customlang_utils::checkout($lng, $progressbar);
61
62    echo $output->continue_button(new moodle_url('/admin/tool/customlang/edit.php', array('lng' => $lng)), 'get');
63    echo $output->footer();
64    exit;
65}
66
67if ($action === 'checkin') {
68    require_sesskey();
69    require_capability('tool/customlang:edit', context_system::instance());
70    if (empty($lng)) {
71        print_error('missingparameter');
72    }
73
74    if (!$confirm) {
75        $output = $PAGE->get_renderer('tool_customlang');
76        echo $output->header();
77        echo $output->heading(get_string('pluginname', 'tool_customlang'));
78        echo $output->heading($langs[$lng], 3);
79        $numofmodified = tool_customlang_utils::get_count_of_modified($lng);
80        if ($numofmodified != 0) {
81            echo $output->heading(get_string('modifiednum', 'tool_customlang', $numofmodified), 3);
82            echo $output->confirm(get_string('confirmcheckin', 'tool_customlang'),
83                                  new moodle_url($PAGE->url, array('action'=>'checkin', 'lng'=>$lng, 'confirm'=>1)),
84                                  new moodle_url($PAGE->url, array('lng'=>$lng)));
85        } else {
86            echo $output->heading(get_string('modifiedno', 'tool_customlang', $numofmodified), 3);
87            echo $output->continue_button(new moodle_url($PAGE->url, array('lng' => $lng)));
88        }
89        echo $output->footer();
90        die();
91
92    } else {
93        tool_customlang_utils::checkin($lng);
94        redirect($PAGE->url);
95    }
96}
97
98$output = $PAGE->get_renderer('tool_customlang');
99
100// output starts here
101echo $output->header();
102echo $output->heading(get_string('pluginname', 'tool_customlang'));
103
104if (empty($lng)) {
105    $s = new single_select($PAGE->url, 'lng', $langs);
106    $s->label = get_accesshide(get_string('language'));
107    $s->class = 'langselector';
108    echo $output->box($OUTPUT->render($s), 'langselectorbox');
109    echo $OUTPUT->footer();
110    exit;
111}
112
113echo $output->heading($langs[$lng], 3);
114
115$numofmodified = tool_customlang_utils::get_count_of_modified($lng);
116
117if ($numofmodified != 0) {
118    echo $output->heading(get_string('modifiednum', 'tool_customlang', $numofmodified), 3);
119}
120
121$menu = array();
122if (has_capability('tool/customlang:edit', context_system::instance())) {
123    $menu['checkout'] = array(
124        'title'     => get_string('checkout', 'tool_customlang'),
125        'url'       => new moodle_url($PAGE->url, array('action' => 'checkout', 'lng' => $lng)),
126        'method'    => 'post',
127    );
128    if ($numofmodified != 0) {
129        $menu['checkin'] = array(
130            'title'     => get_string('checkin', 'tool_customlang'),
131            'url'       => new moodle_url($PAGE->url, array('action' => 'checkin', 'lng' => $lng)),
132            'method'    => 'post',
133        );
134    }
135}
136echo $output->render(new tool_customlang_menu($menu));
137
138echo $output->footer();
Note: See TracBrowser for help on using the repository browser.