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 cApiClientCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['clients'], 'idclient');
31: $this->_setItemClass('cApiClient');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: public function create($name, $errsite_cat = 0, $errsite_art = 0, $author = '', $created = '', $lastmodified = '') {
47: global $auth;
48:
49: if (empty($author)) {
50: $author = $auth->auth['uname'];
51: }
52: if (empty($created)) {
53: $created = date('Y-m-d H:i:s');
54: }
55: if (empty($lastmodified)) {
56: $lastmodified = date('Y-m-d H:i:s');
57: }
58:
59: $item = $this->createNewItem();
60: $item->set('name', $name);
61: $item->set('errsite_cat', $errsite_cat);
62: $item->set('errsite_art', $errsite_art);
63: $item->set('author', $author);
64: $item->set('created', $created);
65: $item->set('lastmodified', $lastmodified);
66: $item->store();
67:
68: return $item;
69: }
70:
71: 72: 73: 74: 75: 76:
77: public function getAvailableClients() {
78: $clients = array();
79:
80: $this->select();
81:
82: while (($item = $this->next()) !== false) {
83: $clients[$item->get('idclient')] = array(
84: 'name' => $item->get('name')
85: );
86: }
87:
88: return $clients;
89: }
90:
91: 92: 93: 94: 95: 96:
97: public function getAccessibleClients() {
98: global $perm;
99: $clients = array();
100: $this->select();
101: while (($item = $this->next()) !== false) {
102: if ($perm->have_perm_client("client[" . $item->get('idclient') . "]") || $perm->have_perm_client("admin[" . $item->get('idclient') . "]") || $perm->have_perm_client()) {
103: $clients[$item->get('idclient')] = array(
104: 'name' => $item->get('name')
105: );
106: }
107: }
108: return $clients;
109: }
110:
111: 112: 113: 114: 115:
116: public function getFirstAccessibleClient() {
117: global $perm;
118: $this->select();
119: while (($item = $this->next()) !== false) {
120: if ($perm->have_perm_client("client[" . $item->get('idclient') . "]") || $perm->have_perm_client("admin[" . $item->get('idclient') . "]")) {
121: return $item;
122: }
123: }
124: return NULL;
125: }
126:
127: 128: 129: 130: 131: 132: 133:
134: public function getClientname($idClient) {
135: $this->select("idclient='" . (int) $idClient . "'");
136: if (($item = $this->next()) !== false) {
137: return $item->get('name');
138: } else {
139: return i18n("No client");
140: }
141: }
142:
143: 144: 145: 146: 147: 148: 149:
150: public function hasLanguageAssigned($idClient) {
151: $client = new cApiClient($idClient);
152:
153: return $client->hasLanguages();
154: }
155: }
156:
157: 158: 159: 160: 161: 162: 163:
164: class cApiClient extends Item {
165:
166: 167: 168: 169: 170: 171: 172:
173: private $idclient;
174:
175: 176: 177: 178: 179:
180: protected $_oPropertyCollection;
181:
182: 183: 184: 185: 186: 187:
188: public function __construct($id = false) {
189: global $cfg;
190: parent::__construct($cfg['tab']['clients'], 'idclient');
191: if ($id !== false) {
192: $this->loadByPrimaryKey($id);
193: }
194: }
195:
196: 197: 198: 199: 200: 201: 202:
203: public function __get($name) {
204: if ($name === 'idclient') {
205: return $this->get('idclient');
206: } else {
207: return parent::__get($name);
208: }
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218:
219: public function __set($name, $value) {
220: if ($name === 'idclient') {
221: $this->set('idclient', cSecurity::toInteger($value));
222: } else {
223: parent::__set($name, $value);
224: }
225: }
226:
227: 228: 229: 230: 231: 232: 233: 234: 235: 236:
237: public static function getInstance($client = false) {
238: static $currentInstance = array();
239:
240: cDeprecated('This method is deprecated and is not needed any longer');
241:
242: if (!$client) {
243:
244: $client = cRegistry::getClientId();
245: }
246:
247: if (!isset($currentInstance[$client])) {
248: $currentInstance[$client] = new cApiClient($client);
249: }
250:
251: return $currentInstance[$client];
252: }
253:
254: 255: 256: 257: 258: 259:
260: public function loadByPrimaryKey($idKey) {
261: if (parent::loadByPrimaryKey($idKey) == true) {
262: $this->set('idclient', $idKey);
263: return true;
264: }
265: return false;
266: }
267:
268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279:
280: public function setProperty($type, $name, $value, $idproperty = 0) {
281: $oPropertyColl = $this->_getPropertiesCollectionInstance();
282: $oPropertyColl->setValue('clientsetting', $this->get('idclient'), $type, $name, $value, $idproperty);
283: }
284:
285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296:
297: public function getProperty($type, $name, $client = 0) {
298: $propertyColl = $this->_getPropertiesCollectionInstance();
299: return $propertyColl->getValue('clientsetting', $this->get('idclient'), $type, $name);
300: }
301:
302: 303: 304: 305: 306: 307: 308: 309: 310: 311:
312: public function deleteProperty($idProp, $p2 = "", $client = 0) {
313: $propertyColl = $this->_getPropertiesCollectionInstance();
314: $propertyColl->delete($idProp);
315: }
316:
317: 318: 319: 320: 321: 322: 323: 324:
325: public function getPropertiesByType($type) {
326: $propertyColl = $this->_getPropertiesCollectionInstance();
327: return $propertyColl->getValuesByType('clientsetting', $this->get('idclient'), $type);
328: }
329:
330: 331: 332: 333: 334: 335: 336: 337:
338: public function getProperties() {
339: $propertyColl = $this->_getPropertiesCollectionInstance();
340: $whereString = "itemid='" . $this->get('idclient') . "' AND itemtype='clientsetting'";
341: $propertyColl->select($whereString, "", "type, name, value ASC");
342:
343: if ($propertyColl->count() > 0) {
344: $array = array();
345:
346: while (($item = $propertyColl->next()) !== false) {
347: $array[$item->get('idproperty')]['type'] = $item->get('type');
348: $array[$item->get('idproperty')]['name'] = $item->get('name');
349: $array[$item->get('idproperty')]['value'] = $item->get('value');
350: }
351:
352: return $array;
353: } else {
354: return false;
355: }
356: }
357:
358: 359: 360: 361: 362:
363: public function hasLanguages() {
364: $clientLanguageCollection = new cApiClientLanguageCollection();
365: $clientLanguageCollection->setWhere("idclient", $this->get("idclient"));
366: $clientLanguageCollection->query();
367:
368: if ($clientLanguageCollection->next()) {
369: return true;
370: } else {
371: return false;
372: }
373: }
374:
375: 376: 377: 378: 379: 380: 381: 382: 383:
384: public function setField($name, $value, $bSafe = true) {
385: switch ($name) {
386: case 'errsite_cat':
387: case 'errsite_art':
388: $value = (int) $value;
389: break;
390: }
391:
392: parent::setField($name, $value, $bSafe);
393: }
394:
395: 396: 397: 398: 399: 400: 401:
402: protected function _getPropertiesCollectionInstance($client = 0) {
403:
404: if (!is_object($this->_oPropertyCollection)) {
405: $this->_oPropertyCollection = new cApiPropertyCollection();
406: $this->_oPropertyCollection->changeClient($this->get('idclient'));
407: }
408: return $this->_oPropertyCollection;
409: }
410:
411: }
412: