root/trunk/gui/admin/multilanguage.php

Revision 1372, 8.3 kB (checked in by rats, 1 month ago)

* Added Mailsize function
* Fixed #1594: (CentOS) More perl dependencies on CentOS
* Fixed #1595: (CentOS) CentOS perl docs: Advice to autoconfigure first
* Fixed #1483: Misleading information in INSTALL-files
* Fixed #1512: Subdomains for domain-aliases
* Fixed #1509: New subdomain management system
* Fixed Order delete bug
* Fixed #1507: Some errors on around "Execute Query" option on a database
* Fixed #1511: e-mail aliases & autoreply
* Fixed #1151: Update Hosting Package should only visible for a customer if a hosting plan to update is available (thanks Feg)
* Fixed #1556: Special Characters like Umlauts (äüöÄÜÖ) and Ligatures (ß) in Javascript messages are encoded, wrongly.
* PHPmyAdmin 3.0.0

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $tpl = new pTemplate();
26 $tpl->define_dynamic('page', Config::get('ADMIN_TEMPLATE_PATH') . '/multilanguage.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('lang_row', 'page');
29 $tpl->define_dynamic('lang_delete_link', 'lang_row');
30 $tpl->define_dynamic('lang_delete_show', 'lang_row');
31 $tpl->define_dynamic('lang_radio', 'lang_row');
32 $tpl->define_dynamic('lang_def', 'lang_row');
33
34 $theme = Config::get('USER_INITIAL_THEME');
35
36 $tpl->assign(
37         array(
38             'TR_ADMIN_I18N_PAGE_TITLE' => tr('ispCP - Admin/Internationalisation'),
39             'THEME_COLOR_PATH' => "../themes/$theme",
40             'THEME_CHARSET' => tr('encoding'),
41             'ISP_LOGO' => get_logo($_SESSION['user_id'])
42             )
43     );
44
45 function update_def_lang() {
46     $sql = Database::getInstance();
47     global $theme;
48
49     if (isset($_POST['uaction']) && $_POST['uaction'] === 'change_language') {
50         if (isset($_POST['default_language']) && !empty($_POST['default_language'])) {
51             $user_id = $_SESSION['user_id'];
52             $user_lang = $_POST['default_language'];
53
54             $query = <<<SQL_QUERY
55                 select
56                     *
57                 from
58                     user_gui_props
59                 where
60                     user_id = ?
61 SQL_QUERY;
62
63             $rs = exec_query($sql, $query, array($user_id));
64
65             if ($rs->RecordCount() == 0) {
66                 $query = <<<SQL_QUERY
67                         insert into
68                             user_gui_props
69                             (
70                                 user_id,
71                                 lang,
72                                 layout
73                             )
74                         values
75                             (
76                                 ?,
77                                 ?,
78                                 ?
79                             )
80 SQL_QUERY;
81
82                 $rs = exec_query($sql, $query, array($user_id, $user_lang, $theme));
83             } else {
84                 $query = <<<SQL_QUERY
85                     update
86                         user_gui_props
87                     set
88                         lang = ?
89                     where
90                         user_id = ?
91 SQL_QUERY;
92
93                 $rs = exec_query($sql, $query, array($user_lang, $user_id));
94             }
95
96             $_SESSION['user_def_lang'] = $user_lang;
97
98             set_page_message(tr('Default language changed!'));
99         }
100     }
101 }
102
103 function install_lang() {
104     $sql = Database::getInstance();
105
106     if (isset($_POST['uaction']) && $_POST['uaction'] === 'upload_language') {
107         // add lang pack now !
108         $file_type = $_FILES['lang_file']['type'];
109         $file = $_FILES['lang_file']['tmp_name'];
110
111         if (empty($_FILES['lang_file']['name']) || !file_exists($file) || !is_readable($file)) {
112             set_page_message(tr('Upload file error!'));
113             return;
114         }
115
116         if ($file_type !== "text/plain" && $file_type !== "application/octet-stream") {
117             set_page_message(tr('You can upload only text files!'));
118             return;
119         } else {
120             $fp = fopen($file, 'r');
121
122             if (!$fp) {
123                 set_page_message(tr('Could not read language file!'));
124                 return;
125             }
126
127             $t = '';
128             $ab = array('ispcp_languageSetlocaleValue' => '', 'ispcp_table' => '', 'ispcp_language' => '');
129             $errors = 0;
130
131             while (!feof($fp) && $errors <= 3) {
132                 $t = fgets($fp);
133
134                 $msgid = '';
135                 $msgstr = '';
136
137                 @list($msgid, $msgstr) = $t = explode(' = ', $t);
138
139                 if (count($t) != 1) {
140                     $ab[$msgid] = rtrim($msgstr);
141                 } else {
142                     $errors++;
143                 }
144             }
145
146             fclose($fp);
147
148             if ($errors > 3) {
149                 set_page_message(tr('Uploaded file is not a valid language file!'));
150                 return ;
151             }
152
153             if (empty($ab['ispcp_languageSetlocaleValue']) || empty($ab['ispcp_table']) || empty($ab['ispcp_language']) || !preg_match('/^[a-z]{2}(_[A-Z]{2}){0,1}$/Di', $ab['ispcp_languageSetlocaleValue']) || !preg_match('/^[a-z0-9]+$/Di', $ab['ispcp_table'])) {
154                 set_page_message(tr('Uploaded file does not contain the language information!'));
155                 return ;
156             }
157
158             $lang_table = 'lang_' . $ab['ispcp_table'];
159
160             $lang_update = false;
161
162             for ($i = 0, $tables = $sql->MetaTables(), $nlang = count($tables); $i < $nlang; $i++) {
163                 if ($lang_table == $tables[$i]) {
164                     $lang_update = true;
165                     break;
166                 }
167             }
168
169             if ($lang_update) {
170                 $sql->Execute("DROP TABLE IF EXISTS `$lang_table`;");
171             }
172
173             $sql->Execute("CREATE TABLE `$lang_table` (
174                                 msgid text collate utf8_unicode_ci,
175                                 msgstr text collate utf8_unicode_ci,
176                                 KEY msgid (msgid(25))
177                                 ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
178                 );
179
180             foreach ($ab as $msgid => $msgstr) {
181                 $query = "INSERT INTO `$lang_table` (msgid, msgstr) VALUES (?, ?)";
182                 exec_query($sql, $query, str_replace("\\n", "\n", array($msgid, $msgstr)));
183             }
184
185             if (!$lang_update) {
186                 write_log(sprintf("%s added new language: %s", $_SESSION['user_logged'], $ab['ispcp_language']));
187                 set_page_message(tr('New language installed!'));
188             } else {
189                 write_log(sprintf("%s updated language: %s", $_SESSION['user_logged'], $ab['ispcp_language']));
190                 set_page_message(tr('Language was updated!'));
191             }
192         }
193     }
194 }
195
196 function show_lang(&$tpl, &$sql) {
197     $tables = $sql->MetaTables();
198
199     $nlang = count($tables);
200
201     $row = 1;
202
203     list($user_def_lang, $user_def_layout) = get_user_gui_props($sql, $_SESSION['user_id']);
204
205     $usr_def_lng = explode('_', $user_def_lang);
206
207     for($i = 0;$i < $nlang;$i++) {
208         $data = $tables[$i];
209         $pos = strpos($data, "lang_");
210         if ($pos === false) {
211             /* not found... ... next :) */
212             continue;
213         }
214         $dat = explode('_', $data);
215
216         $query = <<<SQL_QUERY
217                 select
218                     count(msgid) as cnt
219                 from
220                     $tables[$i]
221 SQL_QUERY;
222         $rs = exec_query($sql, $query, array());
223
224         $query = <<<SQL_QUERY
225                 select
226                     msgstr
227                 from
228                     $tables[$i]
229                 where
230                     msgid = 'ispcp_language'
231 SQL_QUERY;
232         $res = exec_query($sql, $query, array());
233
234         if ($res->RecordCount() == 0) {
235             $language_name = tr('Unknown');
236         } else {
237             $language_name = $res->fields['msgstr'];
238         }
239
240         if ($row++ % 2 == 0) {
241             $tpl->assign('LANG_CLASS', 'content2');
242         } else {
243             $tpl->assign('LANG_CLASS', 'content');
244         }
245
246         if ($usr_def_lng[1] == $dat[1]) {
247             $tpl->assign(
248                 array(
249                     'DEFAULT' => tr('yes'),
250                     'LANG_RADIO' => '',
251                     )
252                 );
253             $tpl->parse('LANG_DEF', 'lang_def');
254         } else {
255             $tpl->assign(
256                 array(
257                     'LANG_DEF' => '',
258                     'LANG_VALUE' => 'lang_' . $dat[1],
259                     )
260                 );
261             $tpl->parse('LANG_RADIO', 'lang_radio');
262         }
263
264         if (Config::get('USER_INITIAL_LANG') == 'lang_' . $dat[1] || $usr_def_lng[1] == $dat[1]) {
265             $tpl->assign(
266                 array(
267                     'TR_UNINSTALL' => tr('uninstall'),
268                     'LANG_DELETE_LINK' => '',
269                     )
270                 );
271             $tpl->parse('LANG_DELETE_SHOW', 'lang_delete_show');
272         } else {
273             $tpl->assign(
274                 array(
275                     'TR_UNINSTALL' => tr('uninstall'),
276                     'URL_DELETE' => 'language_delete.php?delete_lang=lang_' . $dat[1],
277                     'LANG_DELETE_SHOW' => '',
278                     )
279                 );
280             $tpl->parse('LANG_DELETE_LINK', 'lang_delete_link');
281         }
282         // 'LANGUAGE' => $dat[1],
283         // $res
284         $tpl->assign(
285             array(
286                 'LANGUAGE' => $language_name,
287                 'MESSAGES' => tr('%d messages translated', $rs->fields['cnt']),
288                 'URL_EXPORT' => 'multilanguage_export.php?export_lang=lang_' . $dat[1],
289                 )
290             );
291
292         $tpl->parse('LANG_ROW', '.lang_row');
293     }
294 }
295
296 /*
297  *
298  * static page messages.
299  *
300  */
301
302 update_def_lang();
303
304 gen_admin_mainmenu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/main_menu_settings.tpl');
305 gen_admin_menu($tpl, Config::get('ADMIN_TEMPLATE_PATH') . '/menu_settings.tpl');
306
307 install_lang();
308
309 show_lang($tpl, $sql);
310
311 $tpl->assign(
312         array(
313             'TR_MULTILANGUAGE' => tr('Internationalisation'),
314             'TR_INSTALLED_LANGUAGES' => tr('Installed languages'),
315             'TR_LANGUAGE' => tr('Language'),
316             'TR_MESSAGES' => tr('Messages'),
317             'TR_DEFAULT' => tr('Default'),
318             'TR_ACTION' => tr('Action'),
319             'TR_SAVE' => tr('Save'),
320             'TR_INSTALL_NEW_LANGUAGE' => tr('Install new language'),
321             'TR_LANGUAGE_FILE' => tr('Language file'),
322             'ISP_LOGO' => get_logo($_SESSION['user_id']),
323             'TR_INSTALL' => tr('Install'),
324             'TR_EXPORT' => tr('Export'),
325             'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete %s?', true, '%s'),
326             )
327     );
328
329 gen_page_message($tpl);
330
331 $tpl->parse('PAGE', 'page');
332 $tpl->prnt();
333
334 if (Config::get('DUMP_GUI_DEBUG'))
335     dump_gui_debug();
336
337 unset_messages();
338
339 ?>
340
Note: See TracBrowser for help on using the browser.