|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00024 require(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php'); 00025 require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php'); 00026 require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/filter_form.php'); 00027 00028 require_login(SITEID, false); 00029 require_capability('tool/customlang:edit', get_system_context()); 00030 00031 $lng = required_param('lng', PARAM_LANG); 00032 $currentpage = optional_param('p', 0, PARAM_INT); 00033 $translatorsubmitted = optional_param('translatorsubmitted', 0, PARAM_BOOL); 00034 00035 $PAGE->set_pagelayout('standard'); 00036 $PAGE->set_url('/admin/tool/customlang/edit.php', array('lng' => $lng)); 00037 navigation_node::override_active_url(new moodle_url('/admin/tool/customlang/index.php')); 00038 $PAGE->set_title(get_string('pluginname', 'tool_customlang')); 00039 $PAGE->set_heading(get_string('pluginname', 'tool_customlang')); 00040 $PAGE->requires->js_init_call('M.tool_customlang.init_editor', array(), true); 00041 00042 if (empty($lng)) { 00043 // PARAM_LANG validation failed 00044 print_error('missingparameter'); 00045 } 00046 00047 // pre-output processing 00048 $filter = new tool_customlang_filter_form($PAGE->url, null, 'post', '', array('class'=>'filterform')); 00049 $filterdata = tool_customlang_utils::load_filter($USER); 00050 $filter->set_data($filterdata); 00051 00052 if ($filter->is_cancelled()) { 00053 redirect($PAGE->url); 00054 00055 } elseif ($submitted = $filter->get_data()) { 00056 tool_customlang_utils::save_filter($submitted, $USER); 00057 redirect(new moodle_url($PAGE->url, array('p'=>0))); 00058 } 00059 00060 if ($translatorsubmitted) { 00061 $strings = optional_param_array('cust', array(), PARAM_RAW); 00062 $updates = optional_param_array('updates', array(), PARAM_INT); 00063 $checkin = optional_param('savecheckin', false, PARAM_RAW); 00064 00065 if ($checkin === false) { 00066 $nexturl = $PAGE->url; 00067 } else { 00068 $nexturl = new moodle_url('/admin/tool/customlang/index.php', array('action'=>'checkin', 'lng' => $lng, 'sesskey'=>sesskey())); 00069 } 00070 00071 if (!is_array($strings)) { 00072 $strings = array(); 00073 } 00074 $current = $DB->get_records_list('tool_customlang', 'id', array_keys($strings)); 00075 $now = time(); 00076 00077 foreach ($strings as $recordid => $customization) { 00078 $customization = trim($customization); 00079 00080 if (empty($customization) and !is_null($current[$recordid]->local)) { 00081 $current[$recordid]->local = null; 00082 $current[$recordid]->modified = 1; 00083 $current[$recordid]->outdated = 0; 00084 $current[$recordid]->timecustomized = null; 00085 $DB->update_record('tool_customlang', $current[$recordid]); 00086 continue; 00087 } 00088 00089 if (empty($customization)) { 00090 continue; 00091 } 00092 00093 if ($customization !== $current[$recordid]->local) { 00094 $current[$recordid]->local = $customization; 00095 $current[$recordid]->modified = 1; 00096 $current[$recordid]->outdated = 0; 00097 $current[$recordid]->timecustomized = $now; 00098 $DB->update_record('tool_customlang', $current[$recordid]); 00099 continue; 00100 } 00101 } 00102 00103 if (!is_array($updates)) { 00104 $updates = array(); 00105 } 00106 if (!empty($updates)) { 00107 list($sql, $params) = $DB->get_in_or_equal($updates); 00108 $DB->set_field_select('tool_customlang', 'outdated', 0, "local IS NOT NULL AND id $sql", $params); 00109 } 00110 00111 redirect($nexturl); 00112 } 00113 00114 $translator = new tool_customlang_translator($PAGE->url, $lng, $filterdata, $currentpage); 00115 00116 // output starts here 00117 $output = $PAGE->get_renderer('tool_customlang'); 00118 $paginator = $output->paging_bar($translator->numofrows, $currentpage, tool_customlang_translator::PERPAGE, $PAGE->url, 'p'); 00119 00120 echo $output->header(); 00121 $filter->display(); 00122 echo $paginator; 00123 echo $output->render($translator); 00124 echo $paginator; 00125 echo $output->footer();