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