1+ <?php
2+ /*
3+ Copyright (c) 2008, Till Brehm, projektfarm Gmbh
4+ All rights reserved.
5+
6+ Redistribution and use in source and binary forms, with or without modification,
7+ are permitted provided that the following conditions are met:
8+
9+ * Redistributions of source code must retain the above copyright notice,
10+ this list of conditions and the following disclaimer.
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ this list of conditions and the following disclaimer in the documentation
13+ and/or other materials provided with the distribution.
14+ * Neither the name of ISPConfig nor the names of its contributors
15+ may be used to endorse or promote products derived from this software without
16+ specific prior written permission.
17+
18+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+ */
29+
30+ require_once ('../../lib/config.inc.php ' );
31+ require_once ('../../lib/app.inc.php ' );
32+
33+ // Checking permissions for the module
34+ if (!stristr ($ _SESSION ['s ' ]['user ' ]['modules ' ],'admin ' )) {
35+ header ('Location: ../index.php ' );
36+ exit ;
37+ }
38+
39+ //* This is only allowed for administrators
40+ if (!$ app ->auth ->is_admin ()) die ('only allowed for administrators. ' );
41+
42+ $ app ->uses ('tpl ' );
43+
44+ $ app ->tpl ->newTemplate ('form.tpl.htm ' );
45+ $ app ->tpl ->setInclude ('content_tpl ' , 'templates/language_add.htm ' );
46+
47+ //* reading languages
48+ $ language_option = '' ;
49+ $ error = '' ;
50+ $ msg = '' ;
51+ $ selected_language = (isset ($ _REQUEST ['lng_select ' ]))?substr ($ _REQUEST ['lng_select ' ],0 ,2 ):'en ' ;
52+ $ handle = opendir (ISPC_ROOT_PATH .'/lib/lang/ ' );
53+ while ($ file = readdir ($ handle )) {
54+ if ($ file != '. ' && $ file != '.. ' ) {
55+ $ tmp_lng = substr ($ file ,0 ,-4 );
56+ if ($ tmp_lng !='' ) {
57+ $ selected = ($ tmp_lng == $ selected_language )?'SELECTED ' :'' ;
58+ $ language_option .= "<option value=' $ tmp_lng' $ selected> $ tmp_lng</option> " ;
59+ if (isset ($ _POST ['lng_new ' ]) && $ _POST ['lng_new ' ] == $ tmp_lng ) $ error = 'Language exists already. ' ;
60+ }
61+ }
62+ }
63+ $ app ->tpl ->setVar ('language_option ' ,$ language_option );
64+ $ app ->tpl ->setVar ('error ' ,$ error );
65+
66+ if (isset ($ _POST ['lng_new ' ]) && strlen ($ _POST ['lng_new ' ]) == 2 && $ error == '' ) {
67+ $ lng_new = $ _POST ['lng_new ' ];
68+ if (!preg_match ("/^[a-z]{2}$/i " , $ lng_new )) die ('unallowed characters in language name. ' );
69+
70+ //* Make a copy of every language file
71+ $ bgcolor = '#FFFFFF ' ;
72+ $ language_files_list = array ();
73+ $ handle = @opendir (ISPC_WEB_PATH );
74+ while ($ file = @readdir ($ handle )) {
75+ if ($ file != '. ' && $ file != '.. ' ) {
76+ if (@is_dir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' )) {
77+ $ handle2 = opendir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' );
78+ while ($ lang_file = @readdir ($ handle2 )) {
79+ if ($ lang_file != '. ' && $ lang_file != '.. ' && substr ($ lang_file ,0 ,2 ) == $ selected_language ) {
80+ $ new_lang_file = $ lng_new .substr ($ lang_file ,2 );
81+ //echo ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file.' ## '.ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$new_lang_file;
82+ copy (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang/ ' .$ lang_file ,ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang/ ' .$ new_lang_file );
83+ $ msg = 'Added new language ' .$ lng_new ;
84+ }
85+ }
86+ }
87+ }
88+ }
89+ }
90+
91+ $ app ->tpl ->setVar ('msg ' ,$ msg );
92+
93+ //* load language file
94+ $ lng_file = 'lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'_language_add.lng ' ;
95+ include ($ lng_file );
96+ $ app ->tpl ->setVar ($ wb );
97+
98+ $ app ->tpl_defaults ();
99+ $ app ->tpl ->pparse ();
100+
101+
102+ ?>
0 commit comments