1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
33: class Horde_Kolab_FreeBusy_Driver_Freebusy_Kolab extends Horde_Kolab_FreeBusy_Driver_Freebusy_Base
34: {
35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: public function fetch($params = array())
46: {
47: $extended = !empty($params['extended']);
48:
49: }
50:
51: 52: 53: 54: 55: 56: 57:
58: protected function handleCallee($callee)
59: {
60: $this->owner = $owner;
61:
62: $result = $this->_process();
63: if (is_a($result, 'PEAR_Error')) {
64: return $result;
65: }
66: return true;
67: }
68:
69: 70: 71: 72: 73: 74: 75:
76: protected function handleCalleePart($callee_part)
77: {
78:
79: $req_folder = Horde_String::convertCharset($req_folder, 'UTF-8', 'UTF7-IMAP');
80: $folder = explode('/', $req_folder);
81: if (count($folder) < 2) {
82: return PEAR::raiseError(sprintf(Horde_Kolab_FreeBusy_Translation::t("No such folder %s"), $req_folder));
83: }
84:
85: $folder[0] = strtolower($folder[0]);
86: $req_folder = implode('/', $folder);
87: $this->owner = $folder[0];
88: unset($folder[0]);
89: $this->folder = join('/', $folder);
90:
91: $result = $this->_process();
92: if (is_a($result, 'PEAR_Error')) {
93: return $result;
94: }
95: return true;
96: }
97:
98: 99: 100: 101: 102: 103:
104: private function _process()
105: {
106: global $conf;
107:
108: require_once 'Horde/Kolab/Server.php';
109:
110: if (isset($conf['kolab']['ldap']['phpdn'])) {
111: $params = array(
112: 'uid' => $conf['kolab']['ldap']['phpdn'],
113: 'pass' => $conf['kolab']['ldap']['phppw'],
114: );
115: } else {
116: $params = array(
117: 'user' => $GLOBALS['registry']->getAuth(),
118: 'pass' => $GLOBALS['registry']->getAuthCredential('password')
119: );
120: }
121:
122:
123: $db = &Horde_Kolab_Server::singleton($params);
124:
125: $db->fetch();
126:
127:
128: try {
129: $server = $db->fetch(sprintf('k=kolab,%s',
130: $db->getBaseUid()),
131: 'Horde_Kolab_Server_Object_Kolab_Server');
132: $this->server_object = $server;
133: } catch (Horde_Kolab_Server_Exception $e) {
134: Horde::logMessage(sprintf("Failed fetching the k=kolab configuration object. Error was: %s",
135: $e->getMessage()),
136: __FILE__, __LINE__, PEAR_LOG_ERR);
137: $this->server_object = null;
138: }
139:
140:
141: $udn = $db->uidForIdOrMail($this->user);
142: if (is_a($udn, 'PEAR_Error')) {
143: return $udn;
144: }
145: if ($udn) {
146: $user = $db->fetch($udn, 'Horde_Kolab_Server_Object_Kolab_User');
147: if (is_a($user, 'PEAR_Error')) {
148: return $user;
149: }
150: $this->user_object = $user;
151: }
152:
153: if ($this->user_object && $this->user_object->exists()) {
154: $mail = $this->user_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL);
155: if (is_a($mail, 'PEAR_Error')) {
156: return $mail;
157: }
158: if ($mail) {
159: $this->user = $mail;
160: }
161: }
162:
163:
164: $odn = $db->uidForIdOrMailOrAlias($this->owner);
165: if (is_a($odn, 'PEAR_Error')) {
166: return $odn;
167: }
168: if (!$odn) {
169: $idx = strpos($this->user, '@');
170: if($idx !== false) {
171: $domain = substr($this->user, $idx+1);
172: Horde::logMessage(sprintf("Trying to append %s to %s",
173: $domain, $this->owner),
174: __FILE__, __LINE__, PEAR_LOG_DEBUG);
175: $odn = $odn = $db->uidForIdOrMail($this->owner . '@' . $domain);
176: }
177: }
178:
179: if ($odn) {
180: $owner = $db->fetch($odn, 'Horde_Kolab_Server_Object_Kolab_User');
181: if (is_a($owner, 'PEAR_Error')) {
182: return $owner;
183: }
184: $this->owner_object = &$owner;
185: }
186:
187: if (!empty($this->owner_object)) {
188: if ($this->owner_object->exists()) {
189: $this->owner = $this->owner_object->get(Horde_Kolab_Server_Object_Kolab_User::ATTRIBUTE_MAIL);
190:
191: $freebusyserver = $this->owner_object->getServer('freebusy');
192: if (!is_a($freebusyserver, 'PEAR_Error')) {
193: $this->freebusyserver = $freebusyserver;
194: }
195: }
196: } else {
197: return PEAR::raiseError(Horde_Kolab_FreeBusy_Translation::t("Unable to determine owner of the free/busy data!"));
198: }
199:
200:
201: $this->imap_folder = $this->_getImapFolder();
202:
203: return true;
204: }
205:
206: 207: 208: 209: 210: 211:
212: function _getImapFolder()
213: {
214: $userdom = false;
215: $ownerdom = false;
216: if (ereg( '(.*)@(.*)', $this->user, $regs)) {
217:
218: $user = $regs[1];
219: $userdom = $regs[2];
220: } else {
221: $user = $this->user;
222: }
223:
224: if(ereg( '(.*)@(.*)', $this->owner, $regs)) {
225:
226: $owner = $regs[1];
227: $ownerdom = $regs[2];
228: } else {
229: $owner = $this->owner;
230: }
231:
232: $fldrcomp = array();
233: if ($user == $owner) {
234: $fldrcomp[] = 'INBOX';
235: } else {
236: $fldrcomp[] = 'user';
237: $fldrcomp[] = $owner;
238: }
239:
240: if (!empty($this->folder)) {
241: $fldrcomp[] = $this->folder;
242: }
243:
244: $folder = join('/', $fldrcomp);
245: if ($ownerdom && !$userdom) {
246: $folder .= '@' . $ownerdom;
247: }
248: return $folder;
249: }
250: }
251: