1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: cInclude('includes', 'functions.con.php');
18: cInclude('includes', 'functions.str.php');
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32: function langEditLanguage($idlang, $langname, $encoding, $active, $direction = 'ltr') {
33: $oLang = new cApiLanguage();
34: if ($oLang->loadByPrimaryKey((int) $idlang)) {
35: if ('' === $langname) {
36: $langname = "-- ".i18n("New language")." --";
37: }
38: $oLang->set('name', $langname, false);
39: $oLang->set('encoding', $encoding, false);
40: $oLang->set('active', $active, false);
41: $oLang->set('direction', $direction, false);
42: return $oLang->store();
43: }
44: return false;
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
57: function langNewLanguage($name, $client) {
58: global $cfgClient, $notification;
59:
60:
61: $oLangCol = new cApiLanguageCollection();
62: $oLangItem = $oLangCol->create($name, 0, 'utf-8', 'ltr');
63:
64: $oClientLangCol = new cApiClientLanguageCollection();
65: $oClientLangItem = $oClientLangCol->create($client, $oLangItem->get('idlang'));
66:
67:
68: $destPath = $cfgClient[$client]['config']['path'];
69:
70: if (cFileHandler::exists($destPath) && cFileHandler::exists($destPath . 'config.php')) {
71: $buffer = cFileHandler::read($destPath . 'config.php');
72: $outbuf = str_replace('!LANG!', $oLangItem->get('idlang'), $buffer);
73: cFileHandler::write($destPath . 'config.php.new', $outbuf);
74: if (cFileHandler::exists($destPath . 'config.php')) {
75: cFileHandler::remove($destPath . 'config.php');
76: }
77:
78: cFileHandler::rename($destPath . 'config.php.new', 'config.php');
79: } else {
80: $notification->displayNotification('error', i18n("Could not set the language-ID in the file 'config.php'. Please set the language manually."));
81: }
82:
83: return $oLangItem->get('idlang');
84: }
85:
86: 87: 88: 89: 90: 91: 92: 93: 94:
95: function langRenameLanguage($idlang, $name) {
96: $oLang = new cApiLanguage();
97: if ($oLang->loadByPrimaryKey(cSecurity::toInteger($idlang))) {
98: $oLang->set('name', $name, false);
99: return $oLang->store();
100: }
101: return false;
102: }
103:
104: 105: 106: 107: 108: 109: 110: 111: 112:
113: function langDeleteLanguage($iIdLang, $iIdClient = 0) {
114: global $db, $sess, $client, $cfg, $notification, $cfgClient;
115:
116: $deleteok = 1;
117: $iIdLang = (int) $iIdLang;
118: $iIdClient = (int) $iIdClient;
119:
120:
121:
122:
123:
124:
125: if ($iIdClient == 0) {
126: $iIdClient = $client;
127: }
128:
129:
130: $sql = "SELECT * FROM " . $cfg['tab']['art_lang'] . " AS A, " . $cfg['tab']['art'] . " AS B " . "WHERE A.idart=B.idart AND B.idclient=" . $iIdClient . " AND A.idlang=" . $iIdLang;
131: $db->query($sql);
132: if ($db->nextRecord()) {
133: conDeleteArt($db->f('idart'));
134: }
135:
136:
137: $sql = "SELECT * FROM " . $cfg['tab']['cat_lang'] . " AS A, " . $cfg['tab']['cat'] . " AS B " . "WHERE A.idcat=B.idcat AND B.idclient=" . $iIdClient . " AND A.idlang=" . $iIdLang;
138: $db->query($sql);
139: if ($db->nextRecord()) {
140: strDeleteCategory($db->f('idcat'));
141: }
142:
143: $aIdArtLang = array();
144: $aIdArt = array();
145: $aIdCatLang = array();
146: $aIdCat = array();
147: $aIdTplCfg = array();
148:
149: if ($deleteok == 1) {
150:
151:
152: $lastlanguage = 0;
153: $sql = "SELECT COUNT(*) FROM " . $cfg['tab']['clients_lang'] . " WHERE idclient=" . $iIdClient;
154: $db->query($sql);
155: $db->nextRecord();
156: if ($db->f(0) == 1) {
157: $lastlanguage = 1;
158: }
159:
160:
161: $sql = "SELECT A.idtplcfg AS idtplcfg, idartlang, A.idart FROM " . $cfg['tab']['art_lang'] . " AS A, " . $cfg['tab']['art'] . " AS B WHERE A.idart=B.idart AND B.idclient=" . $iIdClient . "
162: AND idlang!=0 AND idlang=" . $iIdLang;
163: $db->query($sql);
164: while ($db->nextRecord()) {
165: $aIdArtLang[] = $db->f('idartlang');
166: $aIdArt[] = $db->f('idart');
167: $aIdTplCfg[] = $db->f('idtplcfg');
168: }
169: foreach ($aIdArtLang as $value) {
170: $value = (int) $value;
171: $sql = "DELETE FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang=" . $value;
172: $db->query($sql);
173: $sql = "DELETE FROM " . $cfg['tab']['content'] . " WHERE idartlang=" . $value;
174: $db->query($sql);
175: }
176:
177: if ($lastlanguage == 1) {
178: foreach ($aIdArt as $value) {
179: $value = (int) $value;
180: $sql = "DELETE FROM " . $cfg['tab']['art'] . " WHERE idart=" . $value;
181: $db->query($sql);
182: $sql = "DELETE FROM " . $cfg['tab']['cat_art'] . " WHERE idart=" . $value;
183: $db->query($sql);
184: }
185: }
186:
187:
188: $sql = "SELECT A.idtplcfg AS idtplcfg, idcatlang, A.idcat FROM " . $cfg['tab']['cat_lang'] . " AS A, " . $cfg['tab']['cat'] . " AS B WHERE A.idcat=B.idcat AND B.idclient=" . $iIdClient . "
189: AND idlang!=0 AND idlang=" . $iIdLang;
190: $db->query($sql);
191: while ($db->nextRecord()) {
192: $aIdCatLang[] = $db->f('idcatlang');
193: $aIdCat[] = $db->f('idcat');
194: $aIdTplCfg[] = $db->f('idtplcfg');
195: }
196: foreach ($aIdCatLang as $value) {
197: $sql = "DELETE FROM " . $cfg['tab']['cat_lang'] . " WHERE idcatlang=" . (int) $value;
198: $db->query($sql);
199: }
200: if ($lastlanguage == 1) {
201: foreach ($aIdCat as $value) {
202: $value = (int) $value;
203: $sql = "DELETE FROM " . $cfg['tab']['cat'] . " WHERE idcat=" . $value;
204: $db->query($sql);
205: $sql = "DELETE FROM " . $cfg['tab']["cat_tree"] . " WHERE idcat=" . $value;
206: $db->query($sql);
207: }
208: }
209:
210:
211: $sql = "DELETE FROM " . $cfg['tab']['stat'] . " WHERE idlang=" . $iIdLang . " AND idclient=" . $iIdClient;
212: $db->query($sql);
213:
214:
215: if (cFileHandler::exists($cfgClient[$iIdClient]['code']['path'])) {
216:
217: foreach (new DirectoryIterator($cfgClient[$iIdClient]['code']['path']) as $file) {
218: if ($file->isFile() === false) {
219: continue;
220: }
221:
222: $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
223: if ($extension != 'php') {
224: continue;
225: }
226:
227: if (preg_match('/' . $iIdClient . '.' . $iIdLang . '.[0-9*]/s', $file->getBasename())) {
228: cFileHandler::remove($cfgClient[$iIdClient]['code']['path'] . '/' . $file->getFilename());
229: }
230: }
231: }
232:
233: foreach ($aIdTplCfg as $tplcfg) {
234: $tplcfg = (int) $tplcfg;
235: if ($tplcfg != 0) {
236:
237: $sql = "DELETE FROM " . $cfg['tab']['tpl_conf'] . " WHERE idtplcfg=" . $tplcfg;
238: $db->query($sql);
239:
240: $sql = "DELETE FROM " . $cfg['tab']['container_conf'] . " WHERE idtplcfg=" . $tplcfg;
241: $db->query($sql);
242: }
243: }
244:
245:
246: $sql = "DELETE FROM " . $cfg['tab']['clients_lang'] . " WHERE idclient=" . $iIdClient . " AND idlang=" . $iIdLang;
247: $db->query($sql);
248:
249:
250: $sql = "DELETE FROM " . $cfg['tab']['lang'] . " WHERE idlang=" . $iIdLang;
251: $db->query($sql);
252:
253:
254: $oPropertyColl = new cApiPropertyCollection($iIdClient);
255: $oPropertyColl->deleteProperties('idlang', $iIdLang);
256: } else {
257: return $notification->returnMessageBox('error', i18n("Could not delete language"), 0);
258: }
259: }
260:
261: 262: 263: 264: 265: 266: 267:
268: function langActivateDeactivateLanguage($idlang, $active) {
269: $oLang = new cApiLanguage();
270: if ($oLang->loadByPrimaryKey((int) $idlang)) {
271: $oLang->set('active', (int) $active, false);
272: return $oLang->store();
273: }
274: return false;
275: }
276:
277: 278: 279: 280: 281: 282: 283: 284: 285: 286:
287: function langGetTextDirection($idlang, $db = NULL) {
288: static $oLang;
289: if (!isset($oLang)) {
290: $oLang = new cApiLanguage();
291: }
292: $direction = '';
293: if ($oLang->loadByPrimaryKey((int) $idlang)) {
294: $direction = $oLang->get('direction');
295: }
296: if ($direction != 'ltr' && $direction != 'rtl') {
297: $direction = 'ltr';
298: }
299: return $direction;
300: }
301: