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