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 = $this->createNewItem();
48:
49: $item->set('name', $name, false);
50: $item->set('active', $active, false);
51: $item->set('encoding', $encoding, false);
52: $item->set('direction', $direction, false);
53: $item->set('author', $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 = $this->next();
76:
77: $lang = (int) $lang;
78: $client = (int) $client;
79:
80: if ($item === false) {
81: return false;
82: }
83:
84: $clientsLanguageColl = new cApiClientLanguageCollection();
85: $clientsLanguageColl->select('idlang = ' . $item->get("idlang"));
86: if (($clientsLang = $clientsLanguageColl->next()) !== false) {
87: if ($client != $clientsLang->get('idclient')) {
88: $item = $this->nextAccessible();
89: }
90: }
91:
92: if ($item) {
93: if ($perm->have_perm_client('lang[' . $item->get('idlang') . ']') || $perm->have_perm_client('admin[' . $client . ']') || $perm->have_perm_client()) {
94:
95: } else {
96: $item = $this->nextAccessible();
97: }
98:
99: return $item;
100: } else {
101: return false;
102: }
103: }
104:
105: 106: 107: 108: 109: 110:
111: public function getLanguageName($idlang) {
112: $item = new cApiLanguage($idlang);
113: if ($item->isLoaded()) {
114: return $item->get('name');
115: } else {
116: return i18n('No language');
117: }
118: }
119:
120: }
121:
122: 123: 124: 125: 126: 127:
128: class cApiLanguage extends Item {
129:
130: 131: 132: 133: 134:
135: public function __construct($mId = false) {
136: global $cfg;
137: parent::__construct($cfg['tab']['lang'], 'idlang');
138: if ($mId !== false) {
139: $this->loadByPrimaryKey($mId);
140: }
141: }
142:
143: 144: 145: 146: 147:
148: public function store() {
149: $this->set('lastmodified', date('Y-m-d H:i:s'), false);
150: return parent::store();
151: }
152:
153: 154: 155: 156: 157: 158: 159:
160: public function setField($name, $value, $bSafe = true) {
161: switch ($name) {
162: case 'active':
163: $value = (int) $value;
164: break;
165: }
166:
167: return parent::setField($name, $value, $bSafe);
168: }
169:
170: }
171: