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
 * @package    tool
19
 * @subpackage customlang
20
 * @copyright  2010 David Mudrak <david@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
require(__DIR__ . '/../../../config.php');
25
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php');
26
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/filter_form.php');
27
require_once($CFG->libdir.'/adminlib.php');
28
 
29
require_login(SITEID, false);
30
require_capability('tool/customlang:edit', context_system::instance());
31
 
32
$lng                    = required_param('lng', PARAM_LANG);
33
$currentpage            = optional_param('p', 0, PARAM_INT);
34
$translatorsubmitted    = optional_param('translatorsubmitted', 0, PARAM_BOOL);
35
 
36
admin_externalpage_setup('toolcustomlang', '', null,
37
    new moodle_url('/admin/tool/customlang/edit.php', array('lng' => $lng)),
38
    array('pagelayout' => 'report')); // Hack: allows for wide page contents.
39
 
40
$PAGE->requires->js_init_call('M.tool_customlang.init_editor', array(), true);
41
$PAGE->set_context(context_system::instance());
42
$PAGE->set_secondary_active_tab('siteadminnode');
43
$PAGE->set_primary_active_tab('siteadminnode');
44
$PAGE->navbar->add(get_string('editlangpack', 'tool_customlang'), $PAGE->url);
45
 
46
 
47
if (empty($lng)) {
48
    // PARAM_LANG validation failed
49
    throw new \moodle_exception('missingparameter');
50
}
51
 
52
// pre-output processing
53
$filter     = new tool_customlang_filter_form($PAGE->url, null, 'post', '', array('class'=>'filterform'));
54
$filterdata = tool_customlang_utils::load_filter($USER);
55
$filter->set_data($filterdata);
56
 
57
if ($filter->is_cancelled()) {
58
    redirect($PAGE->url);
59
 
60
} elseif ($submitted = $filter->get_data()) {
61
    tool_customlang_utils::save_filter($submitted, $USER);
62
    redirect(new moodle_url($PAGE->url, array('p'=>0)));
63
}
64
 
65
if ($translatorsubmitted) {
66
    $strings = optional_param_array('cust', array(), PARAM_RAW);
67
    $updates = optional_param_array('updates', array(), PARAM_INT);
68
    $checkin = optional_param('savecheckin', false, PARAM_RAW);
69
 
70
    if ($checkin === false) {
71
        $nexturl = new moodle_url($PAGE->url, array('p' => $currentpage));
72
    } else {
73
        $nexturl = new moodle_url('/admin/tool/customlang/index.php', array('action'=>'checkin', 'lng' => $lng, 'sesskey'=>sesskey()));
74
    }
75
 
76
    if (!is_array($strings)) {
77
        $strings = array();
78
    }
79
    $current = $DB->get_records_list('tool_customlang', 'id', array_keys($strings));
80
    $now = time();
81
 
82
    foreach ($strings as $recordid => $customization) {
83
        $customization = trim($customization);
84
 
85
        if (empty($customization) and !is_null($current[$recordid]->local)) {
86
            $current[$recordid]->local = null;
87
            $current[$recordid]->modified = 1;
88
            $current[$recordid]->outdated = 0;
89
            $current[$recordid]->timecustomized = null;
90
            $DB->update_record('tool_customlang', $current[$recordid]);
91
            continue;
92
        }
93
 
94
        if (empty($customization)) {
95
            continue;
96
        }
97
 
98
        if ($customization !== $current[$recordid]->local) {
99
            $current[$recordid]->local = $customization;
100
            $current[$recordid]->modified = 1;
101
            $current[$recordid]->outdated = 0;
102
            $current[$recordid]->timecustomized = $now;
103
            $DB->update_record('tool_customlang', $current[$recordid]);
104
            continue;
105
        }
106
    }
107
 
108
    if (!is_array($updates)) {
109
        $updates = array();
110
    }
111
    if (!empty($updates)) {
112
        list($sql, $params) = $DB->get_in_or_equal($updates);
113
        $DB->set_field_select('tool_customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params);
114
    }
115
 
116
    redirect($nexturl);
117
}
118
 
119
$translator = new tool_customlang_translator($PAGE->url, $lng, $filterdata, $currentpage);
120
 
121
// output starts here
122
$output     = $PAGE->get_renderer('tool_customlang');
123
$paginator  = $output->paging_bar($translator->numofrows, $currentpage, tool_customlang_translator::PERPAGE, $PAGE->url, 'p');
124
 
125
echo $output->header();
126
$filter->display();
127
echo $paginator;
128
echo $output->render($translator);
129
echo $paginator;
130
echo $output->footer();