Quick Search:

View

Revision:

Diff

Diff from 1862 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/admin/includes/classes/language.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
121
3   $Id: language.php 1862 2009-03-06 23:34:07Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1374
8   Copyright (c) 2007 osCommerce
hpdl
1
9
hpdl
1498
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1
13 */
14
15   require('../includes/classes/language.php');
16
17   class osC_Language_Admin extends osC_Language {
18
hpdl
410
19 /* Public methods */
hpdl
1512
20     function loadIniFile($filename = null, $comment = '#', $language_code = null) {
21       if ( is_null($language_code) ) {
22         $language_code = $this->_code;
hpdl
410
23       }
hpdl
1
24
hpdl
1512
25       if ( $this->_languages[$language_code]['parent_id'] > 0 ) {
26         $this->loadIniFile($filename, $comment, $this->getCodeFromID($this->_languages[$language_code]['parent_id']));
27       }
28
hpdl
1492
29       if ( is_null($filename) ) {
hpdl
1512
30         if ( file_exists('includes/languages/' . $language_code . '.php') ) {
31           $contents = file('includes/languages/' . $language_code . '.php');
32         } else {
33           return array();
34         }
hpdl
1492
35       } else {
hpdl
1512
36         if ( substr(realpath('includes/languages/' . $language_code . '/' . $filename), 0, strlen(realpath('includes/languages/' . $language_code))) != realpath('includes/languages/' . $language_code) ) {
hpdl
1492
37           return array();
38         }
hpdl
1491
39
hpdl
1512
40         if ( !file_exists('includes/languages/' . $language_code . '/' . $filename) ) {
hpdl
1492
41           return array();
42         }
43
hpdl
1512
44         $contents = file('includes/languages/' . $language_code . '/' . $filename);
hpdl
1491
45       }
46
47       $ini_array = array();
48
49       foreach ( $contents as $line ) {
50         $line = trim($line);
51
52         $firstchar = substr($line, 0, 1);
53
54         if ( !empty($line) && ( $firstchar != $comment) ) {
55           $delimiter = strpos($line, '=');
56
57           if ( $delimiter !== false ) {
58             $key = trim(substr($line, 0, $delimiter));
59             $value = trim(substr($line, $delimiter + 1));
60
61             $ini_array[$key] = $value;
62           } elseif ( isset($key) ) {
63             $ini_array[$key] .= trim($line);
64           }
65         }
66       }
67
68       unset($contents);
69
70       $this->_definitions = array_merge($this->_definitions, $ini_array);
71     }
72
hpdl
1512
73     function injectDefinitions($file, $language_code = null) {
74       if ( is_null($language_code) ) {
75         $language_code = $this->_code;
76       }
77
78       if ( $this->_languages[$language_code]['parent_id'] > 0 ) {
79         $this->injectDefinitions($file, $this->getCodeFromID($this->_languages[$language_code]['parent_id']));
80       }
81
82       foreach ($this->extractDefinitions($language_code . '/' . $file) as $def) {
hpdl
410
83         $this->_definitions[$def['key']] = $def['value'];
84       }
hpdl
1
85     }
86
hpdl
410
87     function &extractDefinitions($xml) {
hpdl
1512
88       $definitions = array();
hpdl
121
89
hpdl
1512
90       if ( file_exists(dirname(__FILE__) . '/../../../includes/languages/' . $xml) ) {
91         $osC_XML = new osC_XML(file_get_contents(dirname(__FILE__) . '/../../../includes/languages/' . $xml));
hpdl
410
92
hpdl
1512
93         $definitions = $osC_XML->toArray();
94
95         if (isset($definitions['language']['definitions']['definition'][0]) === false) {
96           $definitions['language']['definitions']['definition'] = array($definitions['language']['definitions']['definition']);
97         }
98
99         $definitions = $definitions['language']['definitions']['definition'];
hpdl
121
100       }
hpdl
410
101
hpdl
1512
102       return $definitions;
hpdl
121
103     }
104
hpdl
1332
105     function export($id, $groups, $include_language_data = true) {
106       global $osC_Database, $osC_Currencies;
107
108       $language = osC_Language_Admin::getData($id);
109
110       $export_array = array();
111
112       if ( $include_language_data === true ) {
113         $export_array['language']['data'] = array('title-CDATA' => $language['name'],
114                                                   'code-CDATA' => $language['code'],
115                                                   'locale-CDATA' => $language['locale'],
116                                                   'character_set-CDATA' => $language['charset'],
117                                                   'text_direction-CDATA' => $language['text_direction'],
118                                                   'date_format_short-CDATA' => $language['date_format_short'],
119                                                   'date_format_long-CDATA' => $language['date_format_long'],
120                                                   'time_format-CDATA' => $language['time_format'],
121                                                   'default_currency-CDATA' => $osC_Currencies->getCode($language['currencies_id']),
122                                                   'numerical_decimal_separator-CDATA' => $language['numeric_separator_decimal'],
123                                                   'numerical_thousands_separator-CDATA' => $language['numeric_separator_thousands']);
hpdl
1512
124
125         if ( $language['parent_id'] > 0 ) {
126           $export_array['language']['data']['parent_language_code'] = osC_Language_Admin::getCode($language['parent_id']);
127         }
hpdl
1332
128       }
129
130       $Qdefs = $osC_Database->query('select content_group, definition_key, definition_value from :table_languages_definitions where languages_id = :languages_id and content_group in (":content_group") order by content_group, definition_key');
131       $Qdefs->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
132       $Qdefs->bindInt(':languages_id', $id);
133       $Qdefs->bindRaw(':content_group', implode('", "', $groups));
134       $Qdefs->execute();
135
136       while ($Qdefs->next()) {
137         $export_array['language']['definitions']['definition'][] = array('key' => $Qdefs->value('definition_key'),
138                                                                          'value-CDATA' => $Qdefs->value('definition_value'),
139                                                                          'group' => $Qdefs->value('content_group'));
140       }
141
142       $osC_XML = new osC_XML($export_array, $language['charset']);
143       $xml = $osC_XML->toXML();
144
145       header('Content-disposition: attachment; filename=' . $language['code'] . '.xml');
146       header('Content-Type: application/force-download');
147       header('Content-Transfer-Encoding: binary');
148       header('Content-Length: ' . strlen($xml));
149       header('Pragma: no-cache');
150       header('Expires: 0');
151
152       echo $xml;
153
154       exit;
155     }
156
hpdl
410
157     function import($file, $type) {
hpdl
1332
158       global $osC_Database, $osC_Currencies;
hpdl
1
159
hpdl
410
160       if (file_exists('../includes/languages/' . $file . '.xml')) {
161         $osC_XML = new osC_XML(file_get_contents('../includes/languages/' . $file . '.xml'));
162         $source = $osC_XML->toArray();
hpdl
1
163
hpdl
806
164         $language = array('name' => $source['language']['data']['title'],
165                           'code' => $source['language']['data']['code'],
166                           'locale' => $source['language']['data']['locale'],
167                           'charset' => $source['language']['data']['character_set'],
168                           'date_format_short' => $source['language']['data']['date_format_short'],
169                           'date_format_long' => $source['language']['data']['date_format_long'],
170                           'time_format' => $source['language']['data']['time_format'],
171                           'text_direction' => $source['language']['data']['text_direction'],
hpdl
833
172                           'currency' => $source['language']['data']['default_currency'],
hpdl
806
173                           'numeric_separator_decimal' => $source['language']['data']['numerical_decimal_separator'],
hpdl
1512
174                           'numeric_separator_thousands' => $source['language']['data']['numerical_thousands_separator'],
175                           'parent_language_code' => $source['language']['data']['parent_language_code'],
176                           'parent_id' => 0
hpdl
410
177                          );
hpdl
1
178
hpdl
833
179         if (!$osC_Currencies->exists($language['currency'])) {
180           $language['currency'] = DEFAULT_CURRENCY;
181         }
182
hpdl
1512
183         if ( !empty($language['parent_language_code']) ) {
184           $Qlanguage = $osC_Database->query('select languages_id from :table_languages where code = :code');
185           $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
186           $Qlanguage->bindValue(':code', $language['parent_language_code']);
187           $Qlanguage->execute();
188
189           if ( $Qlanguage->numberOfRows() === 1 ) {
190             $language['parent_id'] = $Qlanguage->valueInt('languages_id');
191           }
192         }
193
hpdl
1527
194         $definitions = array();
hpdl
1
195
hpdl
1527
196         if ( isset($source['language']['definitions']['definition']) ) {
197           $definitions = $source['language']['definitions']['definition'];
198
199           if ( isset($definitions['key']) && isset($definitions['value']) && isset($definitions['group']) ) {
200             $definitions = array(array('key' => $definitions['key'],
201                                        'value' => $definitions['value'],
202                                        'group' => $definitions['group']));
203           }
hpdl
1512
204         }
205
hpdl
410
206         unset($source);
hpdl
1
207
hpdl
410
208         $error = false;
209         $add_category_and_product_placeholders = true;
hpdl
1
210
hpdl
410
211         $osC_Database->startTransaction();
212
213         $Qcheck = $osC_Database->query('select languages_id from :table_languages where code = :code');
214         $Qcheck->bindTable(':table_languages', TABLE_LANGUAGES);
215         $Qcheck->bindValue(':code', $language['code']);
216         $Qcheck->execute();
217
218         if ($Qcheck->numberOfRows() === 1) {
219           $add_category_and_product_placeholders = false;
220
221           $language_id = $Qcheck->valueInt('languages_id');
222
hpdl
1512
223           $Qlanguage = $osC_Database->query('update :table_languages set name = :name, code = :code, locale = :locale, charset = :charset, date_format_short = :date_format_short, date_format_long = :date_format_long, time_format = :time_format, text_direction = :text_direction, currencies_id = :currencies_id, numeric_separator_decimal = :numeric_separator_decimal, numeric_separator_thousands = :numeric_separator_thousands, parent_id = :parent_id where languages_id = :languages_id');
hpdl
410
224           $Qlanguage->bindInt(':languages_id', $language_id);
225         } else {
hpdl
1512
226           $Qlanguage = $osC_Database->query('insert into :table_languages (name, code, locale, charset, date_format_short, date_format_long, time_format, text_direction, currencies_id, numeric_separator_decimal, numeric_separator_thousands, parent_id) values (:name, :code, :locale, :charset, :date_format_short, :date_format_long, :time_format, :text_direction, :currencies_id, :numeric_separator_decimal, :numeric_separator_thousands, :parent_id)');
hpdl
1
227         }
hpdl
410
228         $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
229         $Qlanguage->bindValue(':name', $language['name']);
230         $Qlanguage->bindValue(':code', $language['code']);
231         $Qlanguage->bindValue(':locale', $language['locale']);
232         $Qlanguage->bindValue(':charset', $language['charset']);
233         $Qlanguage->bindValue(':date_format_short', $language['date_format_short']);
234         $Qlanguage->bindValue(':date_format_long', $language['date_format_long']);
235         $Qlanguage->bindValue(':time_format', $language['time_format']);
236         $Qlanguage->bindValue(':text_direction', $language['text_direction']);
hpdl
833
237         $Qlanguage->bindInt(':currencies_id', $osC_Currencies->getID($language['currency']));
hpdl
410
238         $Qlanguage->bindValue(':numeric_separator_decimal', $language['numeric_separator_decimal']);
239         $Qlanguage->bindValue(':numeric_separator_thousands', $language['numeric_separator_thousands']);
hpdl
1512
240         $Qlanguage->bindInt(':parent_id', $language['parent_id']);
hpdl
1374
241         $Qlanguage->setLogging($_SESSION['module'], ($Qcheck->numberOfRows() === 1 ? $language_id : null));
hpdl
410
242         $Qlanguage->execute();
hpdl
1
243
hpdl
410
244         if ($osC_Database->isError()) {
245           $error = true;
246         } else {
247           if ($Qcheck->numberOfRows() !== 1) {
248             $language_id = $osC_Database->nextID();
249           }
hpdl
1
250
hpdl
1332
251           $default_language_id = osC_Language_Admin::getData(osC_Language_Admin::getID(DEFAULT_LANGUAGE), 'languages_id');
hpdl
1
252
hpdl
410
253           if ($type == 'replace') {
254             $Qdel =  $osC_Database->query('delete from :table_languages_definitions where languages_id = :languages_id');
255             $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
256             $Qdel->bindInt(':languages_id', $language_id);
257             $Qdel->execute();
258
hpdl
1
259             if ($osC_Database->isError()) {
260               $error = true;
261             }
262           }
263         }
264
265         if ($error === false) {
hpdl
410
266           $osC_DirectoryListing = new osC_DirectoryListing('../includes/languages/' . $file);
267           $osC_DirectoryListing->setRecursive(true);
268           $osC_DirectoryListing->setIncludeDirectories(false);
269           $osC_DirectoryListing->setAddDirectoryToFilename(true);
270           $osC_DirectoryListing->setCheckExtension('xml');
hpdl
1
271
hpdl
410
272           foreach ($osC_DirectoryListing->getFiles() as $files) {
hpdl
1332
273             $definitions = array_merge($definitions, osC_Language_Admin::extractDefinitions($file . '/' . $files['name']));
hpdl
410
274           }
hpdl
1
275
hpdl
410
276           foreach ($definitions as $def) {
277             $insert = false;
278             $update = false;
279
280             if ($type == 'replace') {
281               $insert = true;
282             } else {
283               $Qcheck = $osC_Database->query('select definition_key, content_group from :table_languages_definitions where definition_key = :definition_key and languages_id = :languages_id and content_group = :content_group');
284               $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
285               $Qcheck->bindValue(':definition_key', $def['key']);
286               $Qcheck->bindInt(':languages_id', $language_id);
287               $Qcheck->bindValue(':content_group', $def['group']);
288               $Qcheck->execute();
289
290               if ($Qcheck->numberOfRows() > 0) {
291                 if ($type == 'update') {
292                   $update = true;
293                 }
294               } elseif ($type == 'add') {
295                 $insert = true;
296               }
hpdl
1
297             }
hpdl
410
298
299             if ( ($insert === true) || ($update === true) ) {
300               if ($insert === true) {
301                 $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
302               } else {
303                 $Qdef = $osC_Database->query('update :table_languages_definitions set content_group = :content_group, definition_key = :definition_key, definition_value = :definition_value where definition_key = :definition_key and languages_id = :languages_id and content_group = :content_group');
304                 $Qdef->bindValue(':definition_key', $def['key']);
305                 $Qdef->bindValue(':content_group', $def['group']);
306               }
hpdl
837
307               $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
hpdl
410
308               $Qdef->bindInt(':languages_id', $language_id);
309               $Qdef->bindValue(':content_group', $def['group']);
310               $Qdef->bindValue(':definition_key', $def['key']);
311               $Qdef->bindValue(':definition_value', $def['value']);
312               $Qdef->execute();
313
314               if ($osC_Database->isError()) {
315                 $error = true;
316                 break;
317               }
318             }
hpdl
1
319           }
320         }
321
hpdl
410
322         if ($add_category_and_product_placeholders === true) {
323           if ($error === false) {
324             $Qcategories = $osC_Database->query('select categories_id, categories_name from :table_categories_description where language_id = :language_id');
325             $Qcategories->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
326             $Qcategories->bindInt(':language_id', $default_language_id);
327             $Qcategories->execute();
hpdl
1
328
hpdl
410
329             while ($Qcategories->next()) {
330               $Qinsert = $osC_Database->query('insert into :table_categories_description (categories_id, language_id, categories_name) values (:categories_id, :language_id, :categories_name)');
331               $Qinsert->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
332               $Qinsert->bindInt(':categories_id', $Qcategories->valueInt('categories_id'));
333               $Qinsert->bindInt(':language_id', $language_id);
334               $Qinsert->bindValue(':categories_name', $Qcategories->value('categories_name'));
335               $Qinsert->execute();
hpdl
1
336
hpdl
410
337               if ($osC_Database->isError()) {
338                 $error = true;
339                 break;
340               }
hpdl
1
341             }
342           }
343
hpdl
410
344           if ($error === false) {
hpdl
1862
345             $Qproducts = $osC_Database->query('select products_id, products_name, products_description, products_keyword, products_tags, products_url from :table_products_description where language_id = :language_id');
hpdl
410
346             $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
347             $Qproducts->bindInt(':language_id', $default_language_id);
348             $Qproducts->execute();
hpdl
1
349
hpdl
410
350             while ($Qproducts->next()) {
hpdl
1862
351               $Qinsert = $osC_Database->query('insert into :table_products_description (products_id, language_id, products_name, products_description, products_keyword, products_tags, products_url) values (:products_id, :language_id, :products_name, :products_description, :products_keyword, :products_tags, :products_url)');
hpdl
410
352               $Qinsert->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
353               $Qinsert->bindInt(':products_id', $Qproducts->valueInt('products_id'));
354               $Qinsert->bindInt(':language_id', $language_id);
hpdl
968
355               $Qinsert->bindValue(':products_name', $Qproducts->value('products_name'));
356               $Qinsert->bindValue(':products_description', $Qproducts->value('products_description'));
357               $Qinsert->bindValue(':products_keyword', $Qproducts->value('products_keyword'));
358               $Qinsert->bindValue(':products_tags', $Qproducts->value('products_tags'));
359               $Qinsert->bindValue(':products_url', $Qproducts->value('products_url'));
hpdl
410
360               $Qinsert->execute();
hpdl
1
361
hpdl
410
362               if ($osC_Database->isError()) {
363                 $error = true;
364                 break;
365               }
hpdl
1
366             }
367           }
368
hpdl
410
369           if ($error === false) {
370             $Qoptions = $osC_Database->query('select products_options_id, products_options_name from :table_products_options where language_id = :language_id');
371             $Qoptions->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
372             $Qoptions->bindInt(':language_id', $default_language_id);
373             $Qoptions->execute();
hpdl
1
374
hpdl
410
375             while ($Qoptions->next()) {
376               $Qinsert = $osC_Database->query('insert into :table_products_options (products_options_id, language_id, products_options_name) values (:products_options_id, :language_id, :products_options_name)');
377               $Qinsert->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
378               $Qinsert->bindInt(':products_options_id', $Qoptions->valueInt('products_options_id'));
379               $Qinsert->bindInt(':language_id', $language_id);
380               $Qinsert->bindValue(':products_options_name', $Qoptions->value('products_options_name'));
381               $Qinsert->execute();
hpdl
1
382
hpdl
410
383               if ($osC_Database->isError()) {
384                 $error = true;
385                 break;
386               }
hpdl
1
387             }
388           }
hpdl
410
389
390           if ($error === false) {
391             $Qvalues = $osC_Database->query('select products_options_values_id, products_options_values_name from :table_products_options_values where language_id = :language_id');
392             $Qvalues->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
393             $Qvalues->bindInt(':language_id', $default_language_id);
394             $Qvalues->execute();
395
396             while ($Qvalues->next()) {
397               $Qinsert = $osC_Database->query('insert into :table_products_options_values (products_options_values_id, language_id, products_options_values_name) values (:products_options_values_id, :language_id, :products_options_values_name)');
398               $Qinsert->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
399               $Qinsert->bindInt(':products_options_values_id', $Qvalues->valueInt('products_options_values_id'));
400               $Qinsert->bindInt(':language_id', $language_id);
401               $Qinsert->bindValue(':products_options_values_name', $Qvalues->value('products_options_values_name'));
402               $Qinsert->execute();
403
404               if ($osC_Database->isError()) {
405                 $error = true;
406                 break;
407               }
408             }
409           }
410
411           if ($error === false) {
412             $Qmanufacturers = $osC_Database->query('select manufacturers_id, manufacturers_url from :table_manufacturers_info where languages_id = :languages_id');
413             $Qmanufacturers->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
414             $Qmanufacturers->bindInt(':languages_id', $default_language_id);
415             $Qmanufacturers->execute();
416
417             while ($Qmanufacturers->next()) {
418               $Qinsert = $osC_Database->query('insert into :table_manufacturers_info (manufacturers_id, languages_id, manufacturers_url) values (:manufacturers_id, :languages_id, :manufacturers_url)');
419               $Qinsert->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
420               $Qinsert->bindInt(':manufacturers_id', $Qmanufacturers->valueInt('manufacturers_id'));
421               $Qinsert->bindInt(':languages_id', $language_id);
422               $Qinsert->bindValue(':manufacturers_url', $Qmanufacturers->value('manufacturers_url'));
423               $Qinsert->execute();
424
425               if ($osC_Database->isError()) {
426                 $error = true;
427                 break;
428               }
429             }
430           }
431
432           if ($error === false) {
433             $Qstatus = $osC_Database->query('select orders_status_id, orders_status_name from :table_orders_status where language_id = :language_id');
434             $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
435             $Qstatus->bindInt(':language_id', $default_language_id);
436             $Qstatus->execute();
437
438             while ($Qstatus->next()) {
439               $Qinsert = $osC_Database->query('insert into :table_orders_status (orders_status_id, language_id, orders_status_name) values (:orders_status_id, :language_id, :orders_status_name)');
440               $Qinsert->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
441               $Qinsert->bindInt(':orders_status_id', $Qstatus->valueInt('orders_status_id'));
442               $Qinsert->bindInt(':language_id', $language_id);
443               $Qinsert->bindValue(':orders_status_name', $Qstatus->value('orders_status_name'));
444               $Qinsert->execute();
445
446               if ($osC_Database->isError()) {
447                 $error = true;
448                 break;
449               }
450             }
451           }
hpdl
971
452
453           if ($error === false) {
454             $Qgroup = $osC_Database->query('select id, title, code, size_width, size_height, force_size from :table_products_images_groups where language_id = :language_id');
455             $Qgroup->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS);
456             $Qgroup->bindInt(':language_id', $default_language_id);
457             $Qgroup->execute();
458
459             while ($Qgroup->next()) {
460               $Qinsert = $osC_Database->query('insert into :table_products_images_groups (id, language_id, title, code, size_width, size_height, force_size) values (:id, :language_id, :title, :code, :size_width, :size_height, :force_size)');
461               $Qinsert->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS);
462               $Qinsert->bindInt(':id', $Qgroup->valueInt('id'));
463               $Qinsert->bindInt(':language_id', $language_id);
464               $Qinsert->bindValue(':title', $Qgroup->value('title'));
465               $Qinsert->bindValue(':code', $Qgroup->value('code'));
466               $Qinsert->bindInt(':size_width', $Qgroup->value('size_width'));
467               $Qinsert->bindInt(':size_height', $Qgroup->value('size_height'));
468               $Qinsert->bindInt(':force_size', $Qgroup->value('force_size'));
469               $Qinsert->execute();
470
471               if ($osC_Database->isError()) {
472                 $error = true;
473                 break;
474               }
475             }
476           }
hpdl
1
477         }
478       }
479
480       if ($error === false) {
481         $osC_Database->commitTransaction();
482
483         osC_Cache::clear('languages');
484
485         return true;
486       } else {
487         $osC_Database->rollbackTransaction();
488       }
489
490       return false;
491     }
492
hpdl
1332
493     function getData($id, $key = null) {
494       global $osC_Database;
495
496       $Qlanguage = $osC_Database->query('select * from :table_languages where languages_id = :languages_id');
497       $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
498       $Qlanguage->bindInt(':languages_id', $id);
499       $Qlanguage->execute();
500
501       $result = $Qlanguage->toArray();
502
503       $Qlanguage->freeResult();
504
505       if ( empty($key) ) {
506         return $result;
507       } else {
508         return $result[$key];
509       }
510     }
511
512     function getID($code = null) {
513       global $osC_Database;
514
515       if ( empty($code) ) {
516         return $this->_languages[$this->_code]['id'];
517       }
518
519       $Qlanguage = $osC_Database->query('select languages_id from :table_languages where code = :code');
520       $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
521       $Qlanguage->bindValue(':code', $code);
522       $Qlanguage->execute();
523
524       $result = $Qlanguage->toArray();
525
526       $Qlanguage->freeResult();
527
528       return $result['languages_id'];
529     }
530
hpdl
1512
531     function getCode($id = null) {
532       global $osC_Database;
533
534       if ( empty($id) ) {
535         return $this->_code;
536       }
537
538       $Qlanguage = $osC_Database->query('select code from :table_languages where languages_id = :languages_id');
539       $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
540       $Qlanguage->bindValue(':languages_id', $id);
541       $Qlanguage->execute();
542
543       $result = $Qlanguage->toArray();
544
545       $Qlanguage->freeResult();
546
547       return $result['code'];
548     }
549
hpdl
1
550     function update($id, $language, $default = false) {
551       global $osC_Database;
552
553       $error = false;
554
555       $osC_Database->startTransaction();
556
hpdl
1512
557       $Qlanguage = $osC_Database->query('update :table_languages set name = :name, code = :code, locale = :locale, charset = :charset, date_format_short = :date_format_short, date_format_long = :date_format_long, time_format = :time_format, text_direction = :text_direction, currencies_id = :currencies_id, numeric_separator_decimal = :numeric_separator_decimal, numeric_separator_thousands = :numeric_separator_thousands, parent_id = :parent_id, sort_order = :sort_order where languages_id = :languages_id');
hpdl
1
558       $Qlanguage->bindTable(':table_languages', TABLE_LANGUAGES);
559       $Qlanguage->bindValue(':name', $language['name']);
560       $Qlanguage->bindValue(':code', $language['code']);
hpdl
410
561       $Qlanguage->bindValue(':locale', $language['locale']);
562       $Qlanguage->bindValue(':charset', $language['charset']);
563       $Qlanguage->bindValue(':date_format_short', $language['date_format_short']);
564       $Qlanguage->bindValue(':date_format_long', $language['date_format_long']);
565       $Qlanguage->bindValue(':time_format', $language['time_format']);
566       $Qlanguage->bindValue(':text_direction', $language['text_direction']);
567       $Qlanguage->bindInt(':currencies_id', $language['currencies_id']);
568       $Qlanguage->bindValue(':numeric_separator_decimal', $language['numeric_separator_decimal']);
569       $Qlanguage->bindValue(':numeric_separator_thousands', $language['numeric_separator_thousands']);
hpdl
1512
570       $Qlanguage->bindInt(':parent_id', $language['parent_id']);
hpdl
1
571       $Qlanguage->bindInt(':sort_order', $language['sort_order']);
572       $Qlanguage->bindInt(':languages_id', $id);
hpdl
1374
573       $Qlanguage->setLogging($_SESSION['module'], $id);
hpdl
1
574       $Qlanguage->execute();
575
576       if ($osC_Database->isError()) {
577         $error = true;
578       }
579
580       if ($error === false) {
581         if ($default === true) {
582           $Qupdate = $osC_Database->query('update :table_configuration set configuration_value = :configuration_value where configuration_key = :configuration_key');
583           $Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
584           $Qupdate->bindValue(':configuration_value', $language['code']);
585           $Qupdate->bindValue(':configuration_key', 'DEFAULT_LANGUAGE');
hpdl
1374
586           $Qupdate->setLogging($_SESSION['module'], $id);
hpdl
1
587           $Qupdate->execute();
588
589           if ($osC_Database->isError() === false) {
590             if ($Qupdate->affectedRows()) {
591               osC_Cache::clear('configuration');
592             }
593           } else {
594             $error = true;
595           }
596         }
597       }
598
599       if ($error === false) {
600         $osC_Database->commitTransaction();
601
602         osC_Cache::clear('languages');
603
604         return true;
605       } else {
606         $osC_Database->rollbackTransaction();
607       }
608
609       return false;
610     }
611
hpdl
1332
612     function saveDefinitions($id, $group, $data) {
613       global $osC_Database;
614
615       $error = false;
616
617       $osC_Database->startTransaction();
618
619       foreach ($data as $key => $value) {
620         $Qupdate = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and languages_id = :languages_id and content_group = :content_group');
621         $Qupdate->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
622         $Qupdate->bindValue(':definition_value', $value);
623         $Qupdate->bindValue(':definition_key', $key);
624         $Qupdate->bindInt(':languages_id', $id);
625         $Qupdate->bindValue(':content_group', $group);
hpdl
1374
626         $Qupdate->setLogging($_SESSION['module'], $id);
hpdl
1332
627         $Qupdate->execute();
628
629         if ($osC_Database->isError()) {
630           $error = true;
631           break;
632         }
633       }
634
635       if ($error === false) {
636         $osC_Database->commitTransaction();
637
638         osC_Cache::clear('languages-' . osC_Language_Admin::getData($id, 'code') . '-' . $group);
639
640         return true;
641       }
642
643       $osC_Database->rollbackTransaction();
644
645       return false;
646     }
647
648     function insertDefinition($group, $data) {
649       global $osC_Database, $osC_Language;
650
651       $error = false;
652
653       $osC_Database->startTransaction();
654
655       foreach ($osC_Language->getAll() as $l) {
656         $Qdefinition = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
657         $Qdefinition->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
658         $Qdefinition->bindInt(':languages_id', $l['id']);
659         $Qdefinition->bindValue(':content_group', $group);
660         $Qdefinition->bindValue(':definition_key', $data['key']);
661         $Qdefinition->bindValue(':definition_value', $data['value'][$l['id']]);
hpdl
1374
662         $Qdefinition->setLogging($_SESSION['module']);
hpdl
1332
663         $Qdefinition->execute();
664
665         if ($osC_Database->isError()) {
666           $error = true;
667           break;
668         }
669       }
670
671       if ($error === false) {
672         $osC_Database->commitTransaction();
673
674         osC_Cache::clear('languages-' . osC_Language_Admin::getData($id, 'code') . '-' . $group);
675
676         return true;
677       }
678
679       $osC_Database->rollbackTransaction();
680
681       return false;
682     }
683
hpdl
1
684     function remove($id) {
685       global $osC_Database;
686
687       $Qcheck = $osC_Database->query('select code from :table_languages where languages_id = :languages_id');
688       $Qcheck->bindTable(':table_languages', TABLE_LANGUAGES);
689       $Qcheck->bindInt(':languages_id', $id);
690       $Qcheck->execute();
691
692       if ($Qcheck->value('code') != DEFAULT_LANGUAGE) {
693         $error = false;
694
695         $osC_Database->startTransaction();
696
697         $Qcategories = $osC_Database->query('delete from :table_categories_description where language_id = :language_id');
698         $Qcategories->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
699         $Qcategories->bindInt(':language_id', $id);
700         $Qcategories->execute();
701
702         if ($osC_Database->isError()) {
703           $error = true;
704         }
705
706         if ($error === false) {
707           $Qproducts = $osC_Database->query('delete from :table_products_description where language_id = :language_id');
708           $Qproducts->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
709           $Qproducts->bindInt(':language_id', $id);
710           $Qproducts->execute();
711
712           if ($osC_Database->isError()) {
713             $error = true;
714           }
715         }
716
717         if ($error === false) {
718           $Qproducts = $osC_Database->query('delete from :table_products_options where language_id = :language_id');
719           $Qproducts->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
720           $Qproducts->bindInt(':language_id', $id);
721           $Qproducts->execute();
722
723           if ($osC_Database->isError()) {
724             $error = true;
725           }
726         }
727
728         if ($error === false) {
729           $Qproducts = $osC_Database->query('delete from :table_products_options_values where language_id = :language_id');
730           $Qproducts->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
731           $Qproducts->bindInt(':language_id', $id);
732           $Qproducts->execute();
733
734           if ($osC_Database->isError()) {
735             $error = true;
736           }
737         }
738
739         if ($error === false) {
740           $Qmanufacturers = $osC_Database->query('delete from :table_manufacturers_info where languages_id = :languages_id');
741           $Qmanufacturers->bindTable(':table_manufacturers_info', TABLE_MANUFACTURERS_INFO);
742           $Qmanufacturers->bindInt(':languages_id', $id);
743           $Qmanufacturers->execute();
744
745           if ($osC_Database->isError()) {
746             $error = true;
747           }
748         }
749
750         if ($error === false) {
751           $Qstatus = $osC_Database->query('delete from :table_orders_status where language_id = :language_id');
752           $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
753           $Qstatus->bindInt(':language_id', $id);
754           $Qstatus->execute();
755
756           if ($osC_Database->isError()) {
757             $error = true;
758           }
759         }
760
761         if ($error === false) {
hpdl
971
762           $Qgroup = $osC_Database->query('delete from :table_products_images_groups where language_id = :language_id');
763           $Qgroup->bindTable(':table_products_images_groups', TABLE_PRODUCTS_IMAGES_GROUPS);
764           $Qgroup->bindInt(':language_id', $id);
765           $Qgroup->execute();
766
767           if ($osC_Database->isError()) {
768             $error = true;
769           }
770         }
771
772         if ($error === false) {
hpdl
1
773           $Qlanguages = $osC_Database->query('delete from :table_languages where languages_id = :languages_id');
774           $Qlanguages->bindTable(':table_languages', TABLE_LANGUAGES);
775           $Qlanguages->bindInt(':languages_id', $id);
hpdl
1374
776           $Qlanguages->setLogging($_SESSION['module'], $id);
hpdl
1
777           $Qlanguages->execute();
778
779           if ($osC_Database->isError()) {
780             $error = true;
781           }
782         }
783
784         if ($error === false) {
hpdl
410
785           $Qdefinitions = $osC_Database->query('delete from :table_languages_definitions where languages_id = :languages_id');
hpdl
961
786           $Qdefinitions->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
hpdl
410
787           $Qdefinitions->bindInt(':languages_id', $id);
788           $Qdefinitions->execute();
789
790           if ($osC_Database->isError()) {
791             $error = true;
792           }
793         }
794
795         if ($error === false) {
hpdl
1
796           $osC_Database->commitTransaction();
797
798           osC_Cache::clear('languages');
799
800           return true;
801         } else {
802           $osC_Database->rollbackTransaction();
803         }
804       }
805
806       return false;
807     }
hpdl
1332
808
809     function deleteDefinitions($language_id, $group, $keys) {
810       global $osC_Database;
811
812       $error = false;
813
814       $osC_Database->startTransaction();
815
816       foreach ($keys as $id) {
817         $Qdel = $osC_Database->query('delete from :table_languages_definitions where id = :id');
818         $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
819         $Qdel->bindValue(':id', $id);
hpdl
1374
820         $Qdel->setLogging($_SESSION['module'], $id);
hpdl
1332
821         $Qdel->execute();
822
823         if ($osC_Database->isError()) {
824           $error = true;
825           break;
826         }
827       }
828
829       if ($error === false) {
830         $osC_Database->commitTransaction();
831
832         osC_Cache::clear('languages-' . osC_Language_Admin::getData($language_id, 'code') . '-' . $group);
833
834         return true;
835       }
836
837       $osC_Database->rollbackTransaction();
838
839       return false;
840     }
hpdl
1434
841
842     function showImage($code = null, $width = '16', $height = '10', $parameters = null) {
843       if ( empty($code) ) {
844         $code = $this->_code;
845       }
846
847       $image_code = strtolower(substr($code, 3));
848
849       if ( !is_numeric($width) ) {
850         $width = 16;
851       }
852
853       if ( !is_numeric($height) ) {
854         $height = 10;
855       }
856
857       return osc_image('../images/worldflags/' . $image_code . '.png', $this->_languages[$code]['name'], $width, $height, $parameters);
858     }
hpdl
1492
859
860     function isDefined($key) {
861       return isset($this->_definitions[$key]);
862     }
hpdl
1
863   }
864 ?>