3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @subpackage customlang
21 * @copyright 2010 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
26 require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/locallib.php');
27 require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/filter_form.php');
29 require_login(SITEID, false);
30 require_capability('report/customlang:edit', get_system_context());
32 $lng = required_param('lng', PARAM_LANG);
33 $currentpage = optional_param('p', 0, PARAM_INT);
34 $translatorsubmitted = optional_param('translatorsubmitted', 0, PARAM_BOOL);
36 $PAGE->set_pagelayout('standard');
37 $PAGE->set_url('/admin/report/customlang/edit.php', array('lng' => $lng));
38 navigation_node::override_active_url(new moodle_url('/admin/report/customlang/index.php'));
39 $PAGE->set_title(get_string('pluginname', 'report_customlang'));
40 $PAGE->set_heading(get_string('pluginname', 'report_customlang'));
41 $PAGE->requires->js_init_call('M.report_customlang.init_editor', array(), true);
44 // PARAM_LANG validation failed
45 print_error('missingparameter');
48 // pre-output processing
49 $filter = new report_customlang_filter_form($PAGE->url, null, 'post', '', array('class'=>'filterform'));
50 $filterdata = report_customlang_utils::load_filter($USER);
51 $filter->set_data($filterdata);
53 if ($filter->is_cancelled()) {
56 } elseif ($submitted = $filter->get_data()) {
57 report_customlang_utils::save_filter($submitted, $USER);
58 redirect(new moodle_url($PAGE->url, array('p'=>0)));
61 if ($translatorsubmitted) {
62 $strings = optional_param_array('cust', array(), PARAM_RAW);
63 $updates = optional_param_array('updates', array(), PARAM_INT);
64 $checkin = optional_param('savecheckin', false, PARAM_RAW);
66 if ($checkin === false) {
67 $nexturl = $PAGE->url;
69 $nexturl = new moodle_url('/admin/report/customlang/index.php', array('action'=>'checkin', 'lng' => $lng, 'sesskey'=>sesskey()));
72 if (!is_array($strings)) {
75 $current = $DB->get_records_list('report_customlang', 'id', array_keys($strings));
78 foreach ($strings as $recordid => $customization) {
79 $customization = trim($customization);
81 if (empty($customization) and !is_null($current[$recordid]->local)) {
82 $current[$recordid]->local = null;
83 $current[$recordid]->modified = 1;
84 $current[$recordid]->outdated = 0;
85 $current[$recordid]->timecustomized = null;
86 $DB->update_record('report_customlang', $current[$recordid]);
90 if (empty($customization)) {
94 if ($customization !== $current[$recordid]->local) {
95 $current[$recordid]->local = $customization;
96 $current[$recordid]->modified = 1;
97 $current[$recordid]->outdated = 0;
98 $current[$recordid]->timecustomized = $now;
99 $DB->update_record('report_customlang', $current[$recordid]);
104 if (!is_array($updates)) {
107 if (!empty($updates)) {
108 list($sql, $params) = $DB->get_in_or_equal($updates);
109 $DB->set_field_select('report_customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params);
115 $translator = new report_customlang_translator($PAGE->url, $lng, $filterdata, $currentpage);
117 // output starts here
118 $output = $PAGE->get_renderer('report_customlang');
119 $paginator = $output->paging_bar($translator->numofrows, $currentpage, report_customlang_translator::PERPAGE, $PAGE->url, 'p');
121 echo $output->header();
124 echo $output->render($translator);
126 echo $output->footer();