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: 18: 19: 20: 21: 22:
23: class cApiLanguageCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['lang'], 'idlang');
31: $this->_setItemClass('cApiLanguage');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: public function create($name, $active, $encoding, $direction) {
45: global $auth;
46:
47: $item = parent::createNewItem();
48:
49: $item->set('name', $this->escape($name), false);
50: $item->set('active', (int) $active, false);
51: $item->set('encoding', $this->escape($encoding), false);
52: $item->set('direction', $this->escape($direction), false);
53: $item->set('author', $this->escape($auth->auth['uid']), false);
54: $item->set('created', date('Y-m-d H:i:s'), false);
55: $item->set('lastmodified', '0000-00-00 00:00:00', false);
56: $item->store();
57:
58: return $item;
59: }
60:
61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
72: public function nextAccessible() {
73: global $perm, $client, $lang;
74:
75: $item = parent::next();
76:
77: $lang = (int) $lang;
78: $client = (int) $client;
79:
80: $clientsLanguageColl = new cApiClientLanguageCollection();
81: $clientsLanguageColl->select('idlang = ' . $lang);
82: if (($clientsLang = $clientsLanguageColl->next()) !== false) {
83: if ($client != $clientsLang->get('idclient')) {
84: $item = $this->nextAccessible();
85: }
86: }
87:
88: if ($item) {
89: if ($perm->have_perm_client('lang[' . $item->get('idlang') . ']') || $perm->have_perm_client('admin[' . $client . ']') || $perm->have_perm_client()) {
90:
91: } else {
92: $item = $this->nextAccessible();
93: }
94:
95: return $item;
96: } else {
97: return false;
98: }
99: }
100:
101: 102: 103: 104: 105: 106:
107: public function getLanguageName($idlang) {
108: $item = new cApiLanguage($idlang);
109: if ($item->isLoaded()) {
110: return $item->get('name');
111: } else {
112: return i18n('No language');
113: }
114: }
115:
116: }
117:
118: 119: 120: 121: 122: 123:
124: class cApiLanguage extends Item {
125:
126: 127: 128: 129: 130:
131: public function __construct($mId = false) {
132: global $cfg;
133: parent::__construct($cfg['tab']['lang'], 'idlang');
134: if ($mId !== false) {
135: $this->loadByPrimaryKey($mId);
136: }
137: }
138:
139: 140: 141: 142: 143:
144: public function store() {
145: $this->set('lastmodified', date('Y-m-d H:i:s'), false);
146: return parent::store();
147: }
148:
149: }
150: