1: <?php
2: /**
3: * The Kolab implementation of the free/busy system.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_FreeBusy
9: * @author Thomas Arendsen Hein <thomas@intevation.de>
10: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
11: * @author Gunnar Wrobel <wrobel@pardus.de>
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
14: */
15:
16: /**
17: * The core Controller handling the different request types.
18: *
19: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you did not
22: * receive this file, see
23: * http://www.horde.org/licenses/lgpl21.
24: *
25: * @category Kolab
26: * @package Kolab_FreeBusy
27: * @author Thomas Arendsen Hein <thomas@intevation.de>
28: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
29: * @author Gunnar Wrobel <wrobel@pardus.de>
30: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
31: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
32: */
33: class Horde_Kolab_FreeBusy_Freebusy_Controller_Freebusy
34: extends Horde_Kolab_FreeBusy_Controller_Base
35: {
36: /**
37: * Fetch the free/busy data for a user.
38: *
39: * @return NULL
40: */
41: public function fetch()
42: {
43: $this->logger->debug(sprintf("Starting generation of free/busy data for user %s",
44: $this->params->callee));
45:
46: $params = array('extended' => $this->params->type == 'xfb');
47:
48: // @todo: Reconsider this. We have been decoupled from the
49: // global context here but reinjecting this value seems
50: // extremely weird. Are there any other options?
51: $this->app->callee = $this->params->callee;
52: $this->data = $this->app->driver->fetch($this->params);
53:
54: $this->logger->debug('Delivering complete free/busy data.');
55:
56: /* Display the result to the user */
57: $this->render();
58:
59: $this->logger->debug('Free/busy generation complete.');
60: }
61:
62: /**
63: * Trigger regeneration of free/busy data in a calender.
64: *
65: * @return NULL
66: */
67: public function trigger()
68: {
69: //@todo: FIX:: Horde::logMessage(sprintf("Starting generation of partial free/busy data for folder %s",
70: // $req_folder), __FILE__, __LINE__, PEAR_LOG_DEBUG);
71:
72: $this->export = $this->_app->get(
73: 'Horde_Kolab_FreeBusy_Export'
74: );
75: }
76: /* $this->logger->debug(sprintf("Starting generation of partial free/busy data for folder %s", */
77: /* $this->params->part)); */
78:
79: /* $params = array('extended' => $this->params->type == 'pxfb', */
80: /* 'cached' => $this->params->cache); */
81:
82: /* // @todo: Reconsider this. We have been decoupled from the */
83: /* // global context here but reinjecting this value seems */
84: /* // extremely weird. Are there any other options? */
85: /* $this->app->callee_part = $this->params->part; */
86: /* $this->data = $this->app->driver->trigger($this->params); */
87:
88: /* $this->logger->debug("Delivering partial free/busy data."); */
89:
90: /* /\* Display the result to the user *\/ */
91: /* $this->render(); */
92:
93: /* $this->logger->debug("Free/busy generation complete."); */
94:
95:
96: /**
97: * Regenerate the free/busy cache data.
98: *
99: * @return NULL
100: */
101: function ®enerate($reporter)
102: {
103: $access = new Horde_Kolab_FreeBusy_Access();
104: $result = $access->authenticated();
105: if (is_a($result, 'PEAR_Error')) {
106: return $result->getMessage();
107: }
108:
109: /* Load the required Kolab libraries */
110: require_once "Horde/Kolab/Storage/List.php";
111:
112: $list = &Kolab_List::singleton();
113: $calendars = $list->getByType('event');
114: if (is_a($calendars, 'PEAR_Error')) {
115: return $calendars->getMessage();
116: }
117:
118: $this->_initCache();
119:
120: $lines = array();
121:
122: foreach ($calendars as $calendar) {
123: /**
124: * We are using imap folders for our calendar list but
125: * the library expects us to follow the trigger format
126: * used by pfb.php
127: */
128: $req_domain = explode('@', $calendar->name);
129: if (isset($req_domain[1])) {
130: $domain = $req_domain[1];
131: } else {
132: $domain = null;
133: }
134: $req_folder = explode('/', $req_domain[0]);
135: if ($req_folder[0] == 'user') {
136: unset($req_folder[0]);
137: $owner = $req_folder[1];
138: unset($req_folder[1]);
139: } else if ($req_folder[0] == 'INBOX') {
140: $owner = $access->user;
141: unset($req_folder[0]);
142: }
143:
144: $trigger = $owner . ($domain ? '@' . $domain : '') . '/' . join('/', $req_folder);
145: $trigger = Horde_String::convertCharset($trigger, 'UTF7-IMAP', 'UTF-8');
146:
147: /* Validate folder access */
148: $result = $access->parseFolder($trigger);
149: if (is_a($result, 'PEAR_Error')) {
150: $reporter->failure($calendar->name, $result->getMessage());
151: continue;
152: }
153:
154: /* Hack for allowing manager access */
155: if ($access->user == 'manager') {
156: $imapc = &Horde_Kolab_IMAP::singleton($GLOBALS['conf']['kolab']['imap']['server'],
157: $GLOBALS['conf']['kolab']['imap']['port']);
158: $result = $imapc->connect($access->user, $GLOBALS['registry']->getAuthCredential('password'));
159: if (is_a($result, 'PEAR_Error')) {
160: $reporter->failure($calendar->name, $result->getMessage());
161: continue;
162: }
163: $acl = $imapc->getACL($calendar->name);
164: if (is_a($acl, 'PEAR_Error')) {
165: $reporter->failure($calendar->name, $result->getMessage());
166: continue;
167: }
168: $oldacl = '';
169: if (isset($acl['manager'])) {
170: $oldacl = $acl['manager'];
171: }
172: $result = $imapc->setACL($calendar->name, 'manager', 'lrs');
173: if (is_a($result, 'PEAR_Error')) {
174: $reporter->failure($calendar->name, $result->getMessage());
175: continue;
176: }
177: }
178:
179: /* Update the cache */
180: $result = $this->_cache->store($access);
181: if (is_a($result, 'PEAR_Error')) {
182: $reporter->failure($calendar->name, $result->getMessage());
183: continue;
184: }
185:
186: /* Revert the acl */
187: if ($access->user == 'manager' && $oldacl) {
188: $result = $imapc->setACL($calendar->name, 'manager', $oldacl);
189: if (is_a($result, 'PEAR_Error')) {
190: $reporter->failure($calendar->name, $result->getMessage());
191: continue;
192: }
193: }
194:
195: $reporter->success($calendar->name);
196:
197: }
198: return $lines;
199: }
200:
201: /**
202: * Delete data for a specific user.
203: *
204: * @return NULL
205: */
206: public function delete()
207: {
208: }
209: }
210: