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