~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to admin/lang.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP // $Id: lang.php,v 1.42.4.3 2004/11/30 03:47:13 moodler Exp $
 
1
<?PHP // $Id: lang.php,v 1.55.2.1 2005/07/14 16:01:23 moodler Exp $
2
2
 
3
3
    require_once("../config.php");
4
4
 
5
 
    optional_variable($mode, "");
6
 
    optional_variable($currentfile, "moodle.php");
 
5
    $mode = optional_param('mode', '', PARAM_ALPHA);
 
6
    $currentfile = optional_param('currentfile', 'moodle.php', PARAM_FILE);
7
7
 
8
8
    require_login();
9
9
 
20
20
    $strlanguage = get_string("language");
21
21
    $strcurrentlanguage = get_string("currentlanguage");
22
22
    $strmissingstrings = get_string("missingstrings");
23
 
    $strcomparelanguage = get_string("comparelanguage");
 
23
    $streditstrings = get_string("editstrings", 'admin');
 
24
    $stredithelpdocs = get_string("edithelpdocs", 'admin');
24
25
    $strthislanguage = get_string("thislanguage");
25
26
 
26
27
    switch ($mode) {
27
28
        case "missing":
28
 
            $navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strmissingstrings";
 
29
            $navigation = "<a href=\"lang.php\">$strlanguage</a> -> $strmissingstrings";
29
30
            $title = $strmissingstrings;
30
 
            $button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/admin/lang.php">'.
 
31
            $button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
31
32
                      '<input type="hidden" name="mode" value="compare" />'.
32
 
                      '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
33
 
                      '<input type="submit" value="'.$strcomparelanguage.'" /></form>';
 
33
                      '<input type="submit" value="'.$streditstrings.'" /></form>';
34
34
            break;
35
35
        case "compare":
36
 
            $navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strcomparelanguage";
37
 
            $title = $strcomparelanguage;
38
 
            $button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/admin/lang.php">'.
 
36
            $navigation = "<a href=\"lang.php\">$strlanguage</a> -> $streditstrings";
 
37
            $title = $streditstrings;
 
38
            $button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
39
39
                      '<input type="hidden" name="mode" value="missing" />'.
40
 
                      '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
41
40
                      '<input type="submit" value="'.$strmissingstrings.'" /></form>';
42
41
            break;
43
42
        default:
57
56
    if (!$mode) {
58
57
        $currlang = current_language();
59
58
        $langs = get_list_of_languages();
60
 
        echo "<table align=center><tr><td align=\"right\">";
 
59
        echo "<table align=\"center\"><tr><td align=\"right\">";
61
60
        echo "<b>$strcurrentlanguage:</b>";
62
61
        echo "</td><td>";
63
 
        echo popup_form ("$CFG->wwwroot/admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
64
 
        echo "</td></tr></table>";
65
 
        print_heading("<a href=\"lang.php?mode=missing&sesskey=$USER->sesskey\">$strmissingstrings</a>");
66
 
        print_heading("<a href=\"lang.php?mode=compare&sesskey=$USER->sesskey\">$strcomparelanguage</a>");
67
 
        echo "<center><hr noshade size=1>";
 
62
        echo popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
 
63
        echo '</td></tr><tr><td colspan="2">';
68
64
        $options["lang"] = $currentlang;
69
65
        print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
70
 
        echo "</center>";
 
66
        echo "</td></tr></table>";
 
67
        print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
 
68
        print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
 
69
        print_heading("<a href=\"langdoc.php\">$stredithelpdocs</a>");
71
70
        print_footer();
72
71
        exit;
73
72
    }
87
86
        }
88
87
    }
89
88
 
90
 
    if ($mode == "missing" and confirm_sesskey()) {
 
89
    if ($mode == "missing") {
91
90
        // For each file, check that a counterpart exists, then check all the strings
92
91
    
93
92
        foreach ($stringfiles as $file) {
94
 
            if (!file_exists("$langdir/$file")) {
95
 
                if (!touch("$langdir/$file")) {
96
 
                    echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$file")."</font></p>";
97
 
                    continue;
98
 
                }
99
 
            }
100
 
    
101
93
            unset($string);
102
94
            include("$enlangdir/$file");
103
95
            $enstring = $string;  
104
 
    
 
96
            
105
97
            unset($string);
106
 
            include("$langdir/$file");
 
98
 
 
99
            if (file_exists("$langdir/$file")) {
 
100
                include("$langdir/$file");
 
101
            } else {
 
102
                notify(get_string("filemissing", "", "$langdir/$file"));
 
103
                $string = array();
 
104
            }
107
105
    
108
106
            $first = true;
109
107
            foreach ($enstring as $key => $value) {
110
 
                if (!isset($string[$key]) or $string[$key] == "") {
 
108
                if (empty($string[$key])) {
111
109
                    $value = htmlspecialchars($value);
112
110
                    $value = str_replace("$"."a", "\\$"."a", $value);
113
111
                    $value = str_replace("%%","%",$value);
130
128
    
131
129
        foreach ($files as $filekey => $file) {    // check all the help files.
132
130
            if (!file_exists("$langdir/help/$file")) {
133
 
                echo "<p><font color=red>".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
 
131
                echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
134
132
                $somethingfound = true;
135
133
                continue;
136
134
            }
141
139
        }
142
140
        foreach ($files as $filekey => $file) {    // check all the docs files.
143
141
            if (!file_exists("$langdir/docs/$file")) {
144
 
                echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
 
142
                echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/docs/$file")."</font></p>";
145
143
                $somethingfound = true;
146
144
                continue;
147
145
            }
153
151
            notice(get_string("languagegood"), "lang.php");
154
152
        }
155
153
 
156
 
    } else if ($mode == "compare" and confirm_sesskey()) {
 
154
    } else if ($mode == "compare") {
157
155
 
158
156
        if (isset($_POST['currentfile'])){   // Save a file
 
157
            if (!confirm_sesskey()) {
 
158
                error(get_string('confirmsesskeybad', 'error'));
 
159
            }
159
160
            $newstrings = $_POST;
160
161
            unset($newstrings['currentfile']);
161
162
            if (lang_save_file($langdir, $currentfile, $newstrings)) {
162
163
                notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
163
164
            } else {
164
 
                error("Could not save the file '$currentfile'!", "lang.php?mode=compare&currentfile=$currentfile&sesskey=$USER->sesskey");
 
165
                error("Could not save the file '$currentfile'!", "lang.php?mode=compare&amp;currentfile=$currentfile");
165
166
            }
166
167
        }
167
168
 
168
 
        print_heading_with_help($strcomparelanguage, "langedit");
 
169
        print_heading_with_help($streditstrings, "langedit");
169
170
 
170
171
        print_simple_box_start("center", "80%");
171
172
        echo '<center><font size="2">';
173
174
            if ($file == $currentfile) {
174
175
                echo "<b>$file</b> &nbsp; ";
175
176
            } else {
176
 
                echo "<a href=\"lang.php?mode=compare&currentfile=$file&sesskey=$USER->sesskey\">$file</a> &nbsp; ";
 
177
                echo "<a href=\"lang.php?mode=compare&amp;currentfile=$file\">$file</a> &nbsp; ";
177
178
            }
178
179
        }
179
180
        echo '</font></center>';
184
185
 
185
186
        if (!file_exists("$langdir/$currentfile")) {
186
187
            if (!touch("$langdir/$currentfile")) {
187
 
                echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
 
188
                echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
188
189
                continue;
189
190
            }
190
191
        }
195
196
            fclose($f);
196
197
        } else {
197
198
            $editable = false;
198
 
            echo "<p><font size=1>".get_string("makeeditable", "", "$langdir/$currentfile")."</font></p>";
 
199
            echo "<p><font size=\"1\">".get_string("makeeditable", "", "$langdir/$currentfile")."</font></p>";
199
200
        }
200
201
        error_reporting(7);
201
202
 
216
217
 
217
218
        if ($editable) {
218
219
            echo "<form name=\"$currentfile\" action=\"lang.php\" method=\"post\">";
219
 
            echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
220
220
        }
221
 
        echo "<table width=\"100%\" cellpadding=2 cellspacing=3 border=0>";
 
221
        echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"3\" border=\"0\" class=\"generalbox\">";
222
222
        foreach ($enstring as $key => $envalue) {
223
223
            $envalue = nl2br(htmlspecialchars($envalue));
224
224
            $envalue = preg_replace('/(\$a\-\&gt;[a-zA-Z0-9]*|\$a)/', '<b>$0</b>', $envalue);  // Make variables bold. 
225
225
            $envalue = str_replace("%%","%",$envalue);
226
226
            $envalue = str_replace("\\","",$envalue);              // Delete all slashes
227
227
 
228
 
            echo "\n\n<tr>";
229
 
            echo "<td dir=ltr lang=en width=20% bgcolor=\"$THEME->cellheading\" nowrap valign=top>$key</td>\n";
230
 
            echo "<td dir=ltr lang=en width=40% bgcolor=\"$THEME->cellheading\" valign=top>$envalue</td>\n";
 
228
            echo "\n\n".'<tr>';
 
229
            echo '<td dir="ltr" lang="en" width="20%" nowrap="nowrap" valign="top">'.$key.'</td>'."\n";
 
230
            echo '<td dir="ltr" lang="en" width="40%" valign="top">'.$envalue.'</td>'."\n";
231
231
 
232
232
            $value = $string[$key];
233
233
            $value = str_replace("\r","",$value);              // Bad character caused by Windows
239
239
            $value = str_replace(">","&gt;",$value);
240
240
            $value = str_replace('"',"&quot;",$value);
241
241
 
242
 
            $cellcolour = $value ? $THEME->cellcontent: $THEME->highlight;
 
242
            $cellcolour = $value ? '': 'class="highlight"';
243
243
 
244
244
            if ($editable) {
245
 
                echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>\n";
 
245
                echo '<td width="40%" '.$cellcolour.' valign="top">'."\n";
246
246
                if (isset($string[$key])) {
247
247
                    $valuelen = strlen($value);
248
248
                } else {
251
251
                $cols=50;
252
252
                if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
253
253
                    $rows = ceil($valuelen / $cols);
254
 
                    echo "<textarea name=\"string-$key\" cols=\"$cols\" rows=\"$rows\">$value</textarea>\n";
 
254
                    echo '<textarea name="stringXXX'.$key.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>'."\n";
255
255
                } else {
256
256
                    if ($valuelen) {
257
257
                        $cols = $valuelen + 2;
258
258
                    }
259
 
                    echo "<input type=\"text\" name=\"string-$key\" value=\"$value\" size=\"$cols\"></td>";
 
259
                    echo '<input type="text" name="stringXXX'.$key.'" value="'.$value.'" size="'.$cols.'" />';
260
260
                }
261
 
                echo "</TD>\n";
 
261
                echo '</td>';
262
262
 
263
263
            } else {
264
 
                echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>$value</td>\n";
 
264
                echo '<td width="40%" bgcolor="'.$cellcolour.'" valign="top">'.$value.'</td>';
265
265
            }
266
266
        }
267
267
        if ($editable) {
268
 
            echo "<tr><td colspan=2>&nbsp;<td><br />";
269
 
            echo "    <input type=\"hidden\" name=\"currentfile\" value=\"$currentfile\">";
270
 
            echo "    <input type=\"hidden\" name=\"mode\" value=\"compare\">";
271
 
            echo "    <input type=\"submit\" name=\"update\" value=\"".get_string("savechanges").": $currentfile\">";
272
 
            echo "</td></tr>";
 
268
            echo '<tr><td colspan="2">&nbsp;<td><br />';
 
269
            echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
 
270
            echo '    <input type="hidden" name="currentfile" value="'.$currentfile.'" />';
 
271
            echo '    <input type="hidden" name="mode" value="compare" />';
 
272
            echo '    <input type="submit" name="update" value="'.get_string('savechanges').': '.$currentfile.'" />';
 
273
            echo '</td></tr>';
273
274
        }
274
 
        echo "</table>";
275
 
        echo "</form>";
 
275
        echo '</table>';
 
276
        echo '</form>'; 
276
277
 
277
278
    }
278
279
 
303
304
    ksort($strings);
304
305
 
305
306
    foreach ($strings as $key => $value) {
306
 
        list($id, $stringname) = explode("-",$key);
 
307
        list($id, $stringname) = explode('XXX',$key);
307
308
        if ($CFG->lang != "zh_hk" and $CFG->lang != "zh_tw") {  // Some MB languages include backslash bytes
308
309
            $value = str_replace("\\","",$value);           // Delete all slashes
309
310
        }