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