1: <?php
2: /**
3: * A representation of a Kolab entity.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Server
12: */
13:
14: /**
15: * This class provides basic methods common to all Kolab server objects.
16: *
17: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Server
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Server
27: */
28: class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Object_Inetorgperson
29: {
30: /** The specific object class of this object type */
31: const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson';
32:
33: /** Define attributes specific to this object type */
34:
35: /**
36: * The attributes defined for this class.
37: *
38: * @var array
39: */
40: static public $attributes = array(
41: 'alias', 'kolabHomeServer', 'kolabFreebusyHost'
42: /* 'kolabDelegate', 'kolabDeleteFlag', 'kolabFreeBusyFuture', */
43: /* , , 'kolabImapServer', */
44: /* 'kolabInvitationPolicy', 'kolabSalutation', 'gender', */
45: /* 'kolabMaritalStatus', 'homeFacsimileTelephoneNumber', 'germanTaxId', */
46: /* 'c', 'cyrus-userquota', 'kolabAllowSMTPRecipient', 'kolabAllowSMTPFrom', */
47: /* 'apple-birthday', 'apple-birthdayDate', 'birthPlace', 'birthName', */
48: /* 'pseudonym', 'countryOfCitizenship', 'legalForm', */
49: /* 'tradeRegisterRegisteredCapital', 'bylawURI', 'dateOfIncorporation', */
50: /* 'legalRepresentative', 'commercialProcuration', */
51: /* 'legalRepresentationPolicy', 'actingDeputy', 'VATNumber', */
52: /* 'otherLegalRelationship', 'inLiquidation', 'tradeRegisterType', */
53: /* 'tradeRegisterLocation', 'tradeRegisterIdentifier', 'tradeRegisterURI', */
54: /* 'tradeRegisterLastChangedDate', 'domainComponent', */
55: );
56:
57:
58: /**
59: * A structure to initialize the attribute structure for this class.
60: *
61: * @var array
62: */
63: /* static public $init_attributes = array( */
64: /* 'defined' => array( */
65: /* self::ATTRIBUTE_DELEGATE, */
66: /* self::ATTRIBUTE_DELETED, */
67: /* self::ATTRIBUTE_FBFUTURE, */
68: /* self::ATTRIBUTE_HOMESERVER, */
69: /* self::ATTRIBUTE_FREEBUSYHOST, */
70: /* self::ATTRIBUTE_IMAPHOST, */
71: /* self::ATTRIBUTE_IPOLICY, */
72: /* self::ATTRIBUTE_SALUTATION, */
73: /* self::ATTRIBUTE_GENDER, */
74: /* self::ATTRIBUTE_MARITALSTATUS, */
75: /* self::ATTRIBUTE_HOMEFAX, */
76: /* self::ATTRIBUTE_GERMANTAXID, */
77: /* self::ATTRIBUTE_COUNTRY, */
78: /* self::ATTRIBUTE_QUOTA, */
79: /* self::ATTRIBUTE_ALLOWEDRECIPIENTS, */
80: /* self::ATTRIBUTE_ALLOWEDFROM, */
81: /* self::ATTRIBUTE_DATEOFBIRTH, */
82: /* self::ATTRIBUTE_PLACEOFBIRTH, */
83: /* self::ATTRIBUTE_BIRTHNAME, */
84: /* self::ATTRIBUTE_PSEUDONYM, */
85: /* self::ATTRIBUTE_COUNTRYCITIZENSHIP, */
86: /* self::ATTRIBUTE_LEGALFORM, */
87: /* self::ATTRIBUTE_REGISTEREDCAPITAL, */
88: /* self::ATTRIBUTE_BYLAWURI, */
89: /* self::ATTRIBUTE_DATEOFINCORPORATION, */
90: /* self::ATTRIBUTE_LEGALREPRESENTATIVE, */
91: /* self::ATTRIBUTE_COMMERCIALPROCURATION, */
92: /* self::ATTRIBUTE_LEGALREPRESENTATIONPOLICY, */
93: /* self::ATTRIBUTE_ACTINGDEPUTY, */
94: /* self::ATTRIBUTE_VATNUMBER, */
95: /* self::ATTRIBUTE_OTHERLEGAL, */
96: /* self::ATTRIBUTE_INLIQUIDATION, */
97: /* self::ATTRIBUTE_TRTYPE, */
98: /* self::ATTRIBUTE_TRLOCATION, */
99: /* self::ATTRIBUTE_TRIDENTIFIER, */
100: /* self::ATTRIBUTE_TRURI, */
101: /* self::ATTRIBUTE_TRLASTCHANGED, */
102: /* self::ATTRIBUTE_DC, */
103: /* ), */
104: /* 'locked' => array( */
105: /* self::ATTRIBUTE_MAIL, */
106: /* ), */
107: /* /\** */
108: /* * Derived attributes are calculated based on other attribute values. */
109: /* *\/ */
110: /* 'derived' => array( */
111: /* self::ATTRDATE_DATEOFBIRTH => array( */
112: /* 'method' => 'getDate', */
113: /* 'args' => array( */
114: /* self::ATTRIBUTE_DATEOFBIRTH, */
115: /* ), */
116: /* ), */
117: /* ), */
118: /* 'object_classes' => array( */
119: /* self::OBJECTCLASS_KOLABINETORGPERSON, */
120: /* ), */
121: /* ); */
122:
123: /**
124: * Generates an ID for the given information.
125: *
126: * @param array $info The data of the object.
127: *
128: * @static
129: *
130: * @return string|PEAR_Error The ID.
131: */
132: public function generateId(array &$info)
133: {
134: /**
135: * Never rename the object, even if the components of the CN attribute
136: * changed
137: */
138: if ($this->exists()) {
139: return false;
140: }
141: return self::ATTRIBUTE_CN . '=' . $this->generateCn($info);
142: }
143:
144: /**
145: * Generates the common name for the given information.
146: *
147: * @param array $info The data of the object.
148: *
149: * @return string The common name.
150: */
151: public function generateCn($info)
152: {
153: global $conf;
154:
155: /** The fields that should get mapped into the user ID. */
156: if (isset($conf['kolab']['server']['params']['user_cn_mapfields'])) {
157: $id_mapfields = $conf['kolab']['server']['params']['user_cn_mapfields'];
158: } else {
159: $id_mapfields = array(self::ATTRIBUTE_GIVENNAME,
160: self::ATTRIBUTE_SN);
161: }
162:
163: /** The user ID format. */
164: if (isset($conf['kolab']['server']['params']['user_cn_format'])) {
165: $id_format = $conf['kolab']['server']['params']['user_cn_format'];
166: } else {
167: $id_format = '%s %s';
168: }
169:
170: $fieldarray = array();
171: foreach ($id_mapfields as $mapfield) {
172: if (isset($info[$mapfield])) {
173: $id = $info[$mapfield];
174: if (is_array($id)) {
175: $id = $id[0];
176: }
177: $fieldarray[] = $this->server->structure->quoteForUid($id);
178: } else {
179: $fieldarray[] = '';
180: }
181: }
182: return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,");
183: }
184:
185: /**
186: * Distill the server side object information to save.
187: *
188: * @param array $info The information about the object.
189: *
190: * @return NULL.
191: *
192: * @throws Horde_Kolab_Server_Exception If the given information contains errors.
193: */
194: public function prepareObjectInformation(array &$info)
195: {
196: if (!$this->exists()) {
197: if (!isset($info[self::ATTRIBUTE_CN])) {
198: if (!isset($info[self::ATTRIBUTE_SN]) || !isset($info[self::ATTRIBUTE_GIVENNAME])) {
199: throw new Horde_Kolab_Server_Exception("Either the last name or the given name is missing!");
200: } else {
201: $info[self::ATTRIBUTE_CN] = $this->generateCn($info);
202: }
203: }
204: }
205: }
206:
207: /**
208: * Return the filter string to retrieve this object type.
209: *
210: * @return string The filter to retrieve this object type from the server
211: * database.
212: */
213: public static function getFilter()
214: {
215: $filter = new Horde_Kolab_Server_Query_Element_Equals(
216: 'Objectclass',
217: self::OBJECTCLASS_KOLABINETORGPERSON
218: );
219: return $filter;
220: }
221:
222: /**
223: * List the external pop3 accounts of this object.
224: *
225: * @return array The data of the pop3 accounts.
226: */
227: public function getExternalAccounts()
228: {
229: $result = array();
230: $account_uids = $this->objectsForUid($this->server, $this->uid, Horde_Kolab_Server_Object_Kolabpop3account::OBJECTCLASS_KOLABEXTERNALPOP3ACCOUNT);
231: if ($account_uids !== false) {
232: foreach ($account_uids as $account_uid) {
233: $account = $this->server->fetch($account_uid, 'Horde_Kolab_Server_Object_Kolabpop3account');
234: $result[] = $account->toHash();
235: }
236: }
237: return $result;
238: }
239:
240: /**
241: * Create/update an external pop3 accounts of this object.
242: *
243: * @param array $account The account data.
244: *
245: * @return NULL
246: */
247: public function saveExternalAccount($account)
248: {
249: $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $this->getUid();
250: $object = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolabpop3account',
251: null, $this->server, $account);
252: $object->save();
253: }
254:
255: /**
256: * Delete an external account.
257: *
258: * @param string $mail The mail address of the pop3 account.
259: *
260: * @return NULL
261: */
262: public function deleteExternalAccount($mail)
263: {
264: $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $this->getUid();
265: $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL] = $mail;
266: $object = &Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolabpop3account',
267: null, $this->server, $account);
268: $object->delete();
269: }
270:
271: /**
272: * Returns the server url of the given type for this user.
273: *
274: * This method is used to encapsulate multidomain support.
275: *
276: * @param string $server_type The type of server URL that should be returned.
277: *
278: * @return string The server url or empty on error.
279: */
280: public function getServer($server_type)
281: {
282: global $conf;
283:
284: switch ($server_type) {
285: case 'freebusy':
286: $server = $this->get(self::ATTRIBUTE_FREEBUSYHOST);
287: if (!empty($server)) {
288: return $server;
289: }
290: if (isset($conf['kolab']['freebusy']['server'])) {
291: return $conf['kolab']['freebusy']['server'];
292: }
293: $server = $this->getServer('homeserver');
294: if (empty($server)) {
295: $server = $_SERVER['SERVER_NAME'];
296: }
297: if (isset($conf['kolab']['server']['freebusy_url_format'])) {
298: return sprintf($conf['kolab']['server']['freebusy_url_format'],
299: $server);
300: } else {
301: return 'https://' . $server . '/freebusy';
302: }
303: case 'imap':
304: $server = $this->get(self::ATTRIBUTE_IMAPHOST);
305: if (!empty($server)) {
306: return $server;
307: }
308: case 'homeserver':
309: default:
310: return $this->get(self::ATTRIBUTE_HOMESERVER);
311: }
312: }
313: }