1 | <?php
|
---|
2 |
|
---|
3 | /***************************************************************************
|
---|
4 | * Dolphin Smart Community Builder
|
---|
5 | * -----------------
|
---|
6 | * begin : Mon Mar 23 2006
|
---|
7 | * copyright : (C) 2006 BoonEx Group
|
---|
8 | * website : http://www.boonex.com/
|
---|
9 | * This file is part of Dolphin - Smart Community Builder
|
---|
10 | *
|
---|
11 | * Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
|
---|
12 | * http://creativecommons.org/licenses/by/3.0/
|
---|
13 | *
|
---|
14 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
---|
15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
16 | * See the Creative Commons Attribution 3.0 License for more details.
|
---|
17 | * You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
|
---|
18 | * see license.txt file; if not, write to marketing@boonex.com
|
---|
19 | ***************************************************************************/
|
---|
20 |
|
---|
21 | define ('BX_SECURITY_EXCEPTIONS', true);
|
---|
22 | $aBxSecurityExceptions = array ();
|
---|
23 | for ($i=1; $i<255 ; ++$i) {
|
---|
24 | $aBxSecurityExceptions[] = 'POST.string_for_'.$i;
|
---|
25 | $aBxSecurityExceptions[] = 'REQUEST.string_for_'.$i;
|
---|
26 | }
|
---|
27 |
|
---|
28 | require_once( '../inc/header.inc.php' );
|
---|
29 | require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
|
---|
30 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
|
---|
31 | require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
|
---|
32 | require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
|
---|
33 | require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
|
---|
34 | bx_import('BxTemplSearchResult');
|
---|
35 |
|
---|
36 | $logged['admin'] = member_auth( 1, true, true );
|
---|
37 |
|
---|
38 | //--- Process submit ---//
|
---|
39 | $mixedResultSettings = '';
|
---|
40 | $mixedResultCreate = '';
|
---|
41 | $mixedResultAvailable = '';
|
---|
42 | $mixedResultKeys = '';
|
---|
43 | //--- Change settings ---//
|
---|
44 | if(isset($_POST['save_settings'])) {
|
---|
45 | setParam('lang_default', $_POST['lang_default']);
|
---|
46 | $mixedResultSettings = '_adm_txt_settings_success';
|
---|
47 | }
|
---|
48 |
|
---|
49 | //--- Create/Edit/Delete/Recompile/Export/Import Languages ---//
|
---|
50 | if(isset($_POST['create_language'])) {
|
---|
51 | $mixedResultCreate = createLanguage($_POST);
|
---|
52 | }
|
---|
53 | else if(isset($_POST['import_language'])) {
|
---|
54 | $mixedResultCreate = importLanguage($_POST, $_FILES);
|
---|
55 | }
|
---|
56 | else if(isset($_POST['adm-lang-compile']) && !empty($_POST['langs'])) {
|
---|
57 | foreach($_POST['langs'] as $iLangId)
|
---|
58 | if(!compileLanguage((int)$iLangId)) {
|
---|
59 | $mixedResultAvailable = '_adm_txt_langs_cannot_compile';
|
---|
60 | break;
|
---|
61 | }
|
---|
62 | if(empty($mixedResultAvailable))
|
---|
63 | $mixedResultAvailable = '_adm_txt_langs_success_compile';
|
---|
64 | }
|
---|
65 | else if(isset($_POST['adm-lang-delete']) && !empty($_POST['langs'])) {
|
---|
66 | $sNameDefault = getParam('lang_default');
|
---|
67 | foreach($_POST['langs'] as $iLangId) {
|
---|
68 | $sName = getLanguageName($iLangId);
|
---|
69 | if($sName == $sNameDefault) {
|
---|
70 | $mixedResultAvailable = '_adm_txt_langs_cannot_delete_default';
|
---|
71 | break;
|
---|
72 | }
|
---|
73 |
|
---|
74 | if(!deleteLanguage((int)$iLangId)){
|
---|
75 | $mixedResultAvailable = '_adm_txt_langs_cannot_delete';
|
---|
76 | break;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | if(empty($mixedResultAvailable))
|
---|
81 | $mixedResultAvailable = '_adm_txt_langs_success_delete';
|
---|
82 | }
|
---|
83 | else if(isset($_GET['action']) && $_GET['action'] == 'export' && isset($_GET['id'])) {
|
---|
84 | $aLanguage = $GLOBALS['MySQL']->getRow("SELECT `Name`, `Flag`, `Title` FROM `sys_localization_languages` WHERE `ID`='" . (int)$_GET['id'] . "' LIMIT 1");
|
---|
85 |
|
---|
86 | $aContent = array();
|
---|
87 | $aItems = $GLOBALS['MySQL']->getAll("SELECT `tlk`.`Key` AS `key`, `tls`.`String` AS `string` FROM `sys_localization_keys` AS `tlk` LEFT JOIN `sys_localization_strings` AS `tls` ON `tlk`.`ID`=`tls`.`IDKey` WHERE `tls`.`IDLanguage`='" . (int)$_GET['id'] . "'");
|
---|
88 | foreach($aItems as $aItem)
|
---|
89 | $aContent[$aItem['key']] = $aItem['string'];
|
---|
90 |
|
---|
91 | $sName = 'lang_' . $aLanguage['Name'] . '.php';
|
---|
92 | $sContent = "<?php\n\$aLangInfo=" . var_export($aLanguage, true) . ";\n\$aLangContent=" . var_export($aContent, true) . ";\n?>";
|
---|
93 |
|
---|
94 | header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
---|
95 | header ("Content-type: application/octet-stream");
|
---|
96 | header ("Content-Length: " . strlen($sContent));
|
---|
97 | header ("Content-Disposition: attachment; filename=" . $sName);
|
---|
98 | echo $sContent;
|
---|
99 | exit;
|
---|
100 | }
|
---|
101 |
|
---|
102 | //--- Create/Delete/Edit Language Key ---//
|
---|
103 | if(isset($_POST['action']) && $_POST['action'] == 'get_edit_form') {
|
---|
104 | $oJson = new Services_JSON();
|
---|
105 | echo $oJson->encode(array('code' => PageCodeKeyEdit((int)$_POST['id'])));
|
---|
106 | exit;
|
---|
107 | }
|
---|
108 | if(isset($_POST['create_key'])) {
|
---|
109 | $sName = process_db_input($_POST['name']);
|
---|
110 | $iCategoryId = (int)$_POST['category'];
|
---|
111 |
|
---|
112 | $mixedResult = $GLOBALS['MySQL']->query("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES('" . $iCategoryId . "', '" . $sName . "')", false);
|
---|
113 | if($mixedResult !== false) {
|
---|
114 | $bCompiled = true;
|
---|
115 | $iKeyId = (int)$GLOBALS['MySQL']->lastId();
|
---|
116 | $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
|
---|
117 | foreach($aLanguages as $aLanguage)
|
---|
118 | if(isset($_POST['string_for_' . $aLanguage['id']])) {
|
---|
119 | $GLOBALS['MySQL']->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('" . $iKeyId . "', '" . $aLanguage['id'] . "', '" . process_db_input($_POST['string_for_' . $aLanguage['id']]) . "')");
|
---|
120 |
|
---|
121 | $bCompiled = $bCompiled && compileLanguage((int)$aLanguage['id']);
|
---|
122 | }
|
---|
123 |
|
---|
124 | $aResult = $bCompiled ? array('code' => 0, 'message' => '_adm_txt_langs_success_key_save') : array('code' => 1, 'message' => '_adm_txt_langs_cannot_compile');
|
---|
125 | } else
|
---|
126 | $aResult = array('code' => 2, 'message' => '_adm_txt_langs_already_exists');
|
---|
127 |
|
---|
128 | $aResult['message'] = MsgBox(_t($aResult['message']));
|
---|
129 |
|
---|
130 | $oJson = new Services_JSON();
|
---|
131 | echo "<script>parent.onResult('add', " . $oJson->encode($aResult) . ");</script>";
|
---|
132 | exit;
|
---|
133 | } else if(isset($_POST['edit_key'])) {
|
---|
134 | $iId = (int)$_POST['id'];
|
---|
135 |
|
---|
136 | $bCompiled = true;
|
---|
137 | $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
|
---|
138 | foreach($aLanguages as $aLanguage)
|
---|
139 | if(isset($_POST['string_for_' . $aLanguage['id']])) {
|
---|
140 | $GLOBALS['MySQL']->query("REPLACE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('" . $iId . "', '" . $aLanguage['id'] . "', '" . process_db_input($_POST['string_for_' . $aLanguage['id']]) . "')");
|
---|
141 |
|
---|
142 | $bCompiled = $bCompiled && compileLanguage((int)$aLanguage['id']);
|
---|
143 | }
|
---|
144 | $aResult = $bCompiled ? array('code' => 0, 'message' => '_adm_txt_langs_success_key_save') : array('code' => 1, 'message' => '_adm_txt_langs_cannot_compile');
|
---|
145 | $aResult['message'] = MsgBox(_t($aResult['message']));
|
---|
146 |
|
---|
147 | $oJson = new Services_JSON();
|
---|
148 | echo "<script>parent.onResult('edit', " . $oJson->encode($aResult) . ");</script>";
|
---|
149 | exit;
|
---|
150 | }
|
---|
151 |
|
---|
152 | if(isset($_POST['adm-lang-key-delete']) && is_array($_POST['keys'])) {
|
---|
153 | foreach($_POST['keys'] as $iKeyId)
|
---|
154 | $GLOBALS['MySQL']->query("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`ID`='" . $iKeyId . "'");
|
---|
155 | }
|
---|
156 | $iNameIndex = 5;
|
---|
157 | $_page = array(
|
---|
158 | 'name_index' => $iNameIndex,
|
---|
159 | 'css_name' => array('forms_adv.css', 'lang_file.css'),
|
---|
160 | 'js_name' => array('lang_file.js'),
|
---|
161 | 'header' => _t('_adm_page_cpt_lang_file'),
|
---|
162 | );
|
---|
163 | $_page_cont[$iNameIndex] = array(
|
---|
164 | 'page_result_code' => $sResult,
|
---|
165 | 'page_code_settings' => PageCodeSettings($mixedResultSettings),
|
---|
166 | 'page_code_create' => PageCodeCreate($mixedResultCreate),
|
---|
167 | 'page_code_available' => PageCodeAvailable($mixedResultAvailable),
|
---|
168 | 'page_code_keys' => PageCodeKeys($mixedResultKeys),
|
---|
169 | 'page_code_key' => PageCodeKeyCreate() . DesignBoxAdmin (_t('_adm_box_cpt_lang_files'), '
|
---|
170 | <div class="RSSAggrCont" rssid="boonex_unity_lang_files" rssnum="5" member="0">
|
---|
171 | <div class="loading_rss">
|
---|
172 | <img src="' . getTemplateImage('loading.gif') . '" alt="' . _t('_loading ...') . '" />
|
---|
173 | </div>
|
---|
174 | </div>'),
|
---|
175 | );
|
---|
176 |
|
---|
177 | PageCodeAdmin();
|
---|
178 |
|
---|
179 | function PageCodeSettings($mixedResult) {
|
---|
180 | $aForm = array(
|
---|
181 | 'form_attrs' => array(
|
---|
182 | 'id' => 'adm-settings-form-settings',
|
---|
183 | 'name' => 'adm-settings-form-settings',
|
---|
184 | 'action' => $_SERVER['PHP_SELF'],
|
---|
185 | 'method' => 'post',
|
---|
186 | 'enctype' => 'multipart/form-data'
|
---|
187 | ),
|
---|
188 | 'params' => array(),
|
---|
189 | 'inputs' => array(
|
---|
190 | 'lang_default' => array(
|
---|
191 | 'type' => 'select',
|
---|
192 | 'name' => 'lang_default',
|
---|
193 | 'caption' => _t('_adm_txt_langs_def_lang'),
|
---|
194 | 'values' => array(),
|
---|
195 | 'value' => getParam('lang_default'),
|
---|
196 | ),
|
---|
197 | 'save_settings' => array(
|
---|
198 | 'type' => 'submit',
|
---|
199 | 'name' => 'save_settings',
|
---|
200 | 'value' => _t("_adm_btn_settings_save"),
|
---|
201 | )
|
---|
202 | )
|
---|
203 | );
|
---|
204 | $aLangs = getLangsArr();
|
---|
205 | foreach($aLangs as $sName => $sTitle )
|
---|
206 | $aForm['inputs']['lang_default']['values'][] = array('key' => $sName, 'value' => htmlspecialchars_adv( $sTitle ));
|
---|
207 |
|
---|
208 | $oForm = new BxTemplFormView($aForm);
|
---|
209 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode()));
|
---|
210 |
|
---|
211 | if($mixedResult !== true && !empty($mixedResult))
|
---|
212 | $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
|
---|
213 |
|
---|
214 | return DesignBoxAdmin(_t('_adm_box_cpt_lang_settings'), $sResult);
|
---|
215 | }
|
---|
216 | function PageCodeCreate($mixedResult) {
|
---|
217 | if(isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id']))
|
---|
218 | $aLanguage = $GLOBALS['MySQL']->getRow("SELECT `ID` AS `id`, `Name` AS `name`, `Flag` AS `flag`, `Title` AS `title` FROM `sys_localization_languages` WHERE `ID`='" . (int)$_GET['id'] . "' LIMIT 1");
|
---|
219 |
|
---|
220 | //--- Create language form ---//
|
---|
221 | $aFormCreate = array(
|
---|
222 | 'form_attrs' => array(
|
---|
223 | 'id' => 'adm-settings-form-files',
|
---|
224 | 'name' => 'adm-settings-form-files',
|
---|
225 | 'action' => $_SERVER['PHP_SELF'],
|
---|
226 | 'method' => 'post',
|
---|
227 | 'enctype' => 'multipart/form-data'
|
---|
228 | ),
|
---|
229 | 'inputs' => array(
|
---|
230 | 'CopyLanguage_Title' => array(
|
---|
231 | 'type' => 'text',
|
---|
232 | 'name' => 'CopyLanguage_Title',
|
---|
233 | 'caption' => _t('_adm_txt_langs_title'),
|
---|
234 | 'value' => isset($aLanguage['title']) ? $aLanguage['title'] : '',
|
---|
235 | ),
|
---|
236 | 'CopyLanguage_Name' => array(
|
---|
237 | 'type' => 'text',
|
---|
238 | 'name' => 'CopyLanguage_Name',
|
---|
239 | 'caption' => _t('_adm_txt_langs_code'),
|
---|
240 | 'value' => isset($aLanguage['name']) ? $aLanguage['name'] : '',
|
---|
241 | ),
|
---|
242 | 'Flag' => array(
|
---|
243 | 'type' => 'select',
|
---|
244 | 'name' => 'Flag',
|
---|
245 | 'caption' => _t('_adm_txt_langs_flag'),
|
---|
246 | 'values' => array(),
|
---|
247 | 'value' => isset($aLanguage['flag']) ? $aLanguage['flag'] : strtolower(getParam('default_country')),
|
---|
248 | ),
|
---|
249 | 'CopyLanguage_SourceLangID' => array(
|
---|
250 | 'type' => 'select',
|
---|
251 | 'name' => 'CopyLanguage_SourceLangID',
|
---|
252 | 'caption' => _t('_adm_txt_langs_copy_from'),
|
---|
253 | 'values' => array()
|
---|
254 | ),
|
---|
255 | 'create_language' => array(
|
---|
256 | 'type' => 'submit',
|
---|
257 | 'name' => 'create_language',
|
---|
258 | 'value' => _t("_adm_btn_lang_save"),
|
---|
259 | )
|
---|
260 | )
|
---|
261 | );
|
---|
262 | //--- Copy from ---//
|
---|
263 | $aLangs = getLangsArr(false, true);
|
---|
264 | foreach($aLangs as $iId => $sName)
|
---|
265 | $aFormCreate['inputs']['CopyLanguage_SourceLangID']['values'][] = array('key' => $iId, 'value' => htmlspecialchars_adv( $sName ));
|
---|
266 |
|
---|
267 | //--- Flags ---//
|
---|
268 | $aCountries = $GLOBALS['MySQL']->getAll("SELECT `ISO2` AS `code`, `Country` AS `title` FROM `sys_countries` ORDER BY `Country`");
|
---|
269 | foreach($aCountries AS $aCountry) {
|
---|
270 | $sCode = strtolower($aCountry['code']);
|
---|
271 | $aFormCreate['inputs']['Flag']['values'][] = array('key' => $sCode, 'value' => $aCountry['title']);
|
---|
272 | }
|
---|
273 |
|
---|
274 | if(!empty($aLanguage)) {
|
---|
275 | unset($aFormCreate['inputs']['CopyLanguage_SourceLangID']);
|
---|
276 | $aFormCreate['inputs']['id'] = array(
|
---|
277 | 'type' => 'hidden',
|
---|
278 | 'name' => 'id',
|
---|
279 | 'value' => $aLanguage['id']
|
---|
280 | );
|
---|
281 | }
|
---|
282 | $oFormCreate = new BxTemplFormView($aFormCreate);
|
---|
283 |
|
---|
284 | //--- Import language form ---//
|
---|
285 | $aFormImport = array(
|
---|
286 | 'form_attrs' => array(
|
---|
287 | 'id' => 'adm-settings-form-import',
|
---|
288 | 'name' => 'adm-settings-form-import',
|
---|
289 | 'action' => $_SERVER['PHP_SELF'],
|
---|
290 | 'method' => 'post',
|
---|
291 | 'enctype' => 'multipart/form-data'
|
---|
292 | ),
|
---|
293 | 'inputs' => array(
|
---|
294 | 'ImportLanguage_File' => array(
|
---|
295 | 'type' => 'file',
|
---|
296 | 'name' => 'ImportLanguage_File',
|
---|
297 | 'caption' => _t('_adm_txt_langs_file'),
|
---|
298 | ),
|
---|
299 | 'import_language' => array(
|
---|
300 | 'type' => 'submit',
|
---|
301 | 'name' => 'import_language',
|
---|
302 | 'value' => _t('_adm_btn_lang_import'),
|
---|
303 | )
|
---|
304 | )
|
---|
305 | );
|
---|
306 | $oFormImport = new BxTemplFormView($aFormImport);
|
---|
307 |
|
---|
308 | //--- Create page ---//
|
---|
309 | $aTopItems = array(
|
---|
310 | 'adm-langs-btn-create' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_create'), 'active' => 1),
|
---|
311 | 'adm-langs-btn-import' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_import'))
|
---|
312 | );
|
---|
313 |
|
---|
314 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_create.html', array(
|
---|
315 | 'content_create' => $oFormCreate->getCode(),
|
---|
316 | 'content_import' => $oFormImport->getCode()
|
---|
317 | ));
|
---|
318 |
|
---|
319 | if($mixedResult !== true && !empty($mixedResult))
|
---|
320 | $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
|
---|
321 |
|
---|
322 | return DesignBoxAdmin(_t('_adm_box_cpt_lang_create'), $sResult, $aTopItems);
|
---|
323 | }
|
---|
324 | function PageCodeAvailable($mixedResult) {
|
---|
325 | //--- Get Items ---//
|
---|
326 | $aItems = array();
|
---|
327 | $sNameDefault = getParam('lang_default');
|
---|
328 |
|
---|
329 | $aLangs = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title`, `Flag` AS `flag` FROM `sys_localization_languages` ORDER BY `Name`");
|
---|
330 | foreach($aLangs as $aLang)
|
---|
331 | $aItems[] = array(
|
---|
332 | 'name' => $aLang['name'],
|
---|
333 | 'value' => $aLang['id'],
|
---|
334 | 'title' => $aLang['title'],
|
---|
335 | 'icon' => $GLOBALS['site']['flags'] . $aLang['flag'] . '.gif',
|
---|
336 | 'default' => $aLang['name'] == $sNameDefault ? '(' . _t('_adm_txt_langs_default') . ')' : '',
|
---|
337 | 'edit_link' => $GLOBALS['site']['url_admin'] . 'lang_file.php?action=edit&id=' . $aLang['id'],
|
---|
338 | 'export_link' => $GLOBALS['site']['url_admin'] . 'lang_file.php?action=export&id=' . $aLang['id']
|
---|
339 | );
|
---|
340 |
|
---|
341 | //--- Get Controls ---//
|
---|
342 | $aButtons = array(
|
---|
343 | 'adm-lang-compile' => _t('_adm_txt_langs_compile'),
|
---|
344 | 'adm-lang-delete' => _t('_adm_txt_langs_delete')
|
---|
345 | );
|
---|
346 | $sControls = BxTemplSearchResult::showAdminActionsPanel('adm-langs-form', $aButtons, 'langs');
|
---|
347 |
|
---|
348 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_files.html', array('bx_repeat:items' => $aItems, 'controls' => $sControls));
|
---|
349 |
|
---|
350 | if($mixedResult !== true && !empty($mixedResult))
|
---|
351 | $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
|
---|
352 |
|
---|
353 | return DesignBoxAdmin(_t('_adm_box_cpt_lang_available'), $sResult);
|
---|
354 | }
|
---|
355 | function PageCodeKeys($mixedResult) {
|
---|
356 | $sFilter = '';
|
---|
357 | $aItems = array();
|
---|
358 | if(isset($_GET['filter'])) {
|
---|
359 | $sFilter = $_GET['filter'];
|
---|
360 |
|
---|
361 | $aKeys = $GLOBALS['MySQL']->getAll("SELECT `tk`.`ID` AS `id`, `tk`.`Key` AS `key`, `tc`.`Name` AS `category` FROM `sys_localization_keys` AS `tk` LEFT JOIN `sys_localization_strings` AS `ts` ON `tk`.`ID`=`ts`.`IDKey` LEFT JOIN `sys_localization_categories` AS `tc` ON `tk`.`IDCategory`=`tc`.`ID` WHERE `tk`.`Key` LIKE '%" . $sFilter . "%' OR `ts`.`String` LIKE '%" . $sFilter . "%' GROUP BY `tk`.`ID`");
|
---|
362 | foreach($aKeys as $aKey)
|
---|
363 | $aItems[] = array(
|
---|
364 | 'id' => $aKey['id'],
|
---|
365 | 'key' => $aKey['key'],
|
---|
366 | 'category' => $aKey['category'],
|
---|
367 | 'admin_url' => $GLOBALS['site']['url_admin']
|
---|
368 | );
|
---|
369 | }
|
---|
370 |
|
---|
371 | //--- Get Controls ---//
|
---|
372 | $aButtons = array(
|
---|
373 | 'adm-lang-key-delete' => _t('_adm_txt_langs_delete')
|
---|
374 | );
|
---|
375 | $sControls = BxTemplSearchResult::showAdminActionsPanel('adm-keys-form', $aButtons, 'keys');
|
---|
376 |
|
---|
377 | $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_keys.html', array(
|
---|
378 | 'filter_value' => $sFilter,
|
---|
379 | 'filter_checked' => !empty($sFilter) ? 'checked="checked"' : '',
|
---|
380 | 'bx_repeat:items' => !empty($aItems) ? $aItems : MsgBox(_t('_Empty')),
|
---|
381 | 'control' => $sControls,
|
---|
382 | 'url_admin' => $GLOBALS['site']['url_admin']
|
---|
383 | ));
|
---|
384 |
|
---|
385 | if($mixedResult !== true && !empty($mixedResult))
|
---|
386 | $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
|
---|
387 |
|
---|
388 | return DesignBoxAdmin(_t('_adm_box_cpt_lang_keys'), $sResult);
|
---|
389 | }
|
---|
390 | function PageCodeKeyCreate() {
|
---|
391 | $aForm = array(
|
---|
392 | 'form_attrs' => array(
|
---|
393 | 'id' => 'adm-langs-add-key-form',
|
---|
394 | 'name' => 'adm-langs-add-key-form',
|
---|
395 | 'action' => $_SERVER['PHP_SELF'],
|
---|
396 | 'method' => 'post',
|
---|
397 | 'enctype' => 'multipart/form-data',
|
---|
398 | 'target' => 'adm-langs-add-key-iframe'
|
---|
399 | ),
|
---|
400 | 'params' => array(),
|
---|
401 | 'inputs' => array(
|
---|
402 | 'name' => array(
|
---|
403 | 'type' => 'text',
|
---|
404 | 'name' => 'name',
|
---|
405 | 'caption' => _t('_adm_txt_keys_name'),
|
---|
406 | 'value' => '',
|
---|
407 | ),
|
---|
408 | 'category' => array(
|
---|
409 | 'type' => 'select',
|
---|
410 | 'name' => 'category',
|
---|
411 | 'caption' => _t('_adm_txt_keys_category'),
|
---|
412 | 'value' => '',
|
---|
413 | 'values' => array()
|
---|
414 | ),
|
---|
415 | )
|
---|
416 | );
|
---|
417 |
|
---|
418 | $aCategories = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `title` FROM `sys_localization_categories`");
|
---|
419 | foreach($aCategories as $aCategory)
|
---|
420 | $aForm['inputs']['category']['values'][] = array('key' => $aCategory['id'], 'value' => $aCategory['title']);
|
---|
421 |
|
---|
422 | $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
|
---|
423 | foreach($aLanguages as $aLanguage)
|
---|
424 | $aForm['inputs']['string_for_' . $aLanguage['id']] = array(
|
---|
425 | 'type' => 'textarea',
|
---|
426 | 'name' => 'string_for_' . $aLanguage['id'],
|
---|
427 | 'caption' => _t('_adm_txt_keys_string_for', $aLanguage['title']),
|
---|
428 | 'value' => '',
|
---|
429 | );
|
---|
430 |
|
---|
431 | $aForm['inputs']['create_key'] = array(
|
---|
432 | 'type' => 'submit',
|
---|
433 | 'name' => 'create_key',
|
---|
434 | 'value' => _t("_adm_btn_lang_save"),
|
---|
435 | );
|
---|
436 |
|
---|
437 | $oForm = new BxTemplFormView($aForm);
|
---|
438 | return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_key.html', array('type' => 'add', 'content' => $oForm->getCode()));
|
---|
439 | }
|
---|
440 | function PageCodeKeyEdit($iId) {
|
---|
441 | $aForm = array(
|
---|
442 | 'form_attrs' => array(
|
---|
443 | 'id' => 'adm-langs-edit-key-form',
|
---|
444 | 'name' => 'adm-langs-edit-key-form',
|
---|
445 | 'action' => $_SERVER['PHP_SELF'],
|
---|
446 | 'method' => 'post',
|
---|
447 | 'enctype' => 'multipart/form-data',
|
---|
448 | 'target' => 'adm-langs-edit-key-iframe'
|
---|
449 | ),
|
---|
450 | 'params' => array(),
|
---|
451 | 'inputs' => array(
|
---|
452 | 'id' => array(
|
---|
453 | 'type' => 'hidden',
|
---|
454 | 'name' => 'id',
|
---|
455 | 'value' => $iId
|
---|
456 | ),
|
---|
457 | 'name' => array(
|
---|
458 | 'type' => 'text',
|
---|
459 | 'name' => 'name',
|
---|
460 | 'caption' => _t('_adm_txt_keys_name'),
|
---|
461 | 'value' => $GLOBALS['MySQL']->getOne("SELECT `Key` FROM `sys_localization_keys` WHERE `ID`='" . $iId . "' LIMIT 1"),
|
---|
462 | 'attrs' => array(
|
---|
463 | 'disabled' => 'disabled'
|
---|
464 | )
|
---|
465 | ),
|
---|
466 | )
|
---|
467 | );
|
---|
468 |
|
---|
469 | $aStrings = $GLOBALS['MySQL']->getAllWithKey("SELECT CONCAT('string_for_', `IDLanguage`) AS `key`, `String` AS `value` FROM `sys_localization_strings` WHERE `IDKey`='" . $iId . "'", "key");
|
---|
470 | $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
|
---|
471 | foreach($aLanguages as $aLanguage) {
|
---|
472 | $sKey = 'string_for_' . $aLanguage['id'];
|
---|
473 |
|
---|
474 | $aForm['inputs'][$sKey] = array(
|
---|
475 | 'type' => 'textarea',
|
---|
476 | 'name' => 'string_for_' . $aLanguage['id'],
|
---|
477 | 'caption' => _t('_adm_txt_keys_string_for', $aLanguage['title']),
|
---|
478 | 'value' => $aStrings[$sKey]['value'],
|
---|
479 | );
|
---|
480 | }
|
---|
481 | $aForm['inputs']['edit_key'] = array(
|
---|
482 | 'type' => 'submit',
|
---|
483 | 'name' => 'edit_key',
|
---|
484 | 'value' => _t("_adm_btn_lang_save"),
|
---|
485 | );
|
---|
486 |
|
---|
487 | $oForm = new BxTemplFormView($aForm);
|
---|
488 | return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_key.html', array('type' => 'edit', 'content' => $oForm->getCode()));
|
---|
489 | }
|
---|
490 | function createLanguage(&$aData) {
|
---|
491 | global $MySQL;
|
---|
492 |
|
---|
493 | $sTitle = process_db_input($aData['CopyLanguage_Title']);
|
---|
494 | $sName = mb_strtolower( process_db_input($aData['CopyLanguage_Name']) );
|
---|
495 | $sFlag = htmlspecialchars_adv($aData['Flag']);
|
---|
496 | $iSourceId = isset($aData['CopyLanguage_SourceLangID']) ? (int)$aData['CopyLanguage_SourceLangID'] : 0;
|
---|
497 |
|
---|
498 | if(strlen($sTitle) <= 0)
|
---|
499 | return '_adm_txt_langs_empty_title';
|
---|
500 | if(strlen($sName) <= 0)
|
---|
501 | return '_adm_txt_langs_empty_name';
|
---|
502 |
|
---|
503 | if(isset($aData['id']) && (int)$aData['id'] != 0) {
|
---|
504 | $MySQL->query("UPDATE `sys_localization_languages` SET `Name`='" . $sName . "', `Flag`='" . $sFlag . "', `Title`='" . $sTitle . "' WHERE `ID`='" . (int)$aData['id'] . "'");
|
---|
505 |
|
---|
506 | return '_adm_txt_langs_success_updated';
|
---|
507 | }
|
---|
508 |
|
---|
509 |
|
---|
510 | $mixedResult = $MySQL->query("INSERT INTO `sys_localization_languages` (`Name`, `Flag`, `Title`) VALUES ('{$sName}', '{$sFlag}', '{$sTitle}')");
|
---|
511 | if($mixedResult === false)
|
---|
512 | return '_adm_txt_langs_cannot_create';
|
---|
513 |
|
---|
514 | $iId = db_last_id();
|
---|
515 | $aStrings = $MySQL->getAll("SELECT `IDKey`, `String` FROM `sys_localization_strings` WHERE `IDLanguage` = $iSourceId");
|
---|
516 |
|
---|
517 | foreach($aStrings as $aString){
|
---|
518 | $aString['String'] = addslashes($aString['String']);
|
---|
519 | $MySQL->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES ('{$aString['IDKey']}', $iId, '{$aString['String']}')");
|
---|
520 |
|
---|
521 | if( !db_affected_rows() )
|
---|
522 | return '_adm_txt_langs_cannot_add_string';
|
---|
523 | }
|
---|
524 |
|
---|
525 | return '_adm_txt_langs_success_create';
|
---|
526 | }
|
---|
527 | function importLanguage(&$aData, &$aFiles) {
|
---|
528 | global $MySQL;
|
---|
529 |
|
---|
530 | $sTmpPath = $GLOBALS['dir']['tmp'] . mktime() . ".php";
|
---|
531 | if(!file_exists($aFiles['ImportLanguage_File']['tmp_name']) || !move_uploaded_file($aFiles['ImportLanguage_File']['tmp_name'], $sTmpPath))
|
---|
532 | return '_adm_txt_langs_cannot_upload_file';
|
---|
533 |
|
---|
534 | require_once($sTmpPath);
|
---|
535 |
|
---|
536 | $mixedResult = $MySQL->query("INSERT INTO `sys_localization_languages` (`Name`, `Flag`, `Title`) VALUES ('" . $aLangInfo['Name'] . "', '" . $aLangInfo['Flag'] . "', '" . $aLangInfo['Title'] . "')");
|
---|
537 | if($mixedResult === false) {
|
---|
538 | @unlink($sTmpPath);
|
---|
539 | return '_adm_txt_langs_cannot_create';
|
---|
540 | }
|
---|
541 |
|
---|
542 | $iId = (int)$MySQL->lastId();
|
---|
543 | $aKeys = $MySQL->getAllWithKey("SELECT `ID` AS `id`, `Key` AS `key` FROM `sys_localization_keys`", "key");
|
---|
544 | foreach($aLangContent as $sKey => $sString) {
|
---|
545 | if(!isset($aKeys[$sKey]))
|
---|
546 | continue;
|
---|
547 |
|
---|
548 | $MySQL->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES ('" . $aKeys[$sKey]['id'] . "', " . $iId . ", '" . addslashes($sString) . "')");
|
---|
549 | }
|
---|
550 |
|
---|
551 | compileLanguage($iId);
|
---|
552 |
|
---|
553 | @unlink($sTmpPath);
|
---|
554 | return '_adm_txt_langs_success_import';
|
---|
555 | }
|
---|
556 | function getLanguageName($iId) {
|
---|
557 | return $GLOBALS['MySQL']->getOne("SELECT `Name` FROM `sys_localization_languages` WHERE `ID`='" . (int)$iId . "' LIMIT 1");
|
---|
558 | }
|
---|
559 |
|
---|
560 | ?>
|
---|