1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class Horde_Kolab_FreeBusy_View {
21:
22: 23: 24: 25: 26:
27: var $_data;
28:
29: 30: 31: 32: 33:
34: function Horde_Kolab_FreeBusy_View(&$data)
35: {
36: $this->_data = $data;
37: }
38:
39: 40: 41:
42: function render()
43: {
44: echo 'Not implemented!';
45: }
46: }
47:
48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59:
60: class Horde_Kolab_FreeBusy_View_vfb extends Horde_Kolab_FreeBusy_View {
61:
62: 63: 64: 65: 66:
67: var $_vfb;
68:
69: 70: 71: 72: 73:
74: var $_ts;
75:
76: 77: 78: 79: 80:
81: function Horde_Kolab_FreeBusy_View_vfb(&$data)
82: {
83:
84: $data['vfb'] = $data['fb']->exportvCalendar();
85:
86: $ts = time();
87:
88: $components = &$data['fb']->getComponents();
89: foreach ($components as $component) {
90: if ($component->getType() == 'vFreebusy') {
91: $attr = $component->getAttribute('DTSTAMP');
92: if (!empty($attr) && !is_a($attr, 'PEAR_Error')) {
93: $ts = $attr;
94: break;
95: }
96: }
97: }
98:
99: $data['ts'] = $ts;
100:
101: Horde_Kolab_FreeBusy_View::Horde_Kolab_FreeBusy_View($data);
102: }
103:
104: 105: 106: 107: 108:
109: function render()
110: {
111: global $conf;
112:
113: if (!empty($conf['fb']['send_content_type'])) {
114: $send_content_type = $conf['fb']['send_content_type'];
115: } else {
116: $send_content_type = false;
117: }
118:
119: if (!empty($conf['fb']['send_content_length'])) {
120: $send_content_length = $conf['fb']['send_content_length'];
121: } else {
122: $send_content_length = false;
123: }
124:
125: if (!empty($conf['fb']['send_content_disposition'])) {
126: $send_content_disposition = $conf['fb']['send_content_disposition'];
127: } else {
128: $send_content_disposition = false;
129: }
130:
131:
132: header('Cache-Control: no-store, no-cache, must-revalidate');
133: header('Cache-Control: post-check=0, pre-check=0', false);
134: header('Pragma: no-cache');
135: header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
136: header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->_data['ts']) . ' GMT');
137: header('Pragma: public');
138: header('Content-Transfer-Encoding: none');
139: if ($send_content_type) {
140: header('Content-Type: text/calendar');
141: }
142: if ($send_content_length) {
143: header('Content-Length: ' . strlen($this->_data['vfb']));
144: }
145: if ($send_content_disposition) {
146: header('Content-Disposition: attachment; filename="' . $this->_data['name'] . '"');
147: }
148:
149: echo $this->_data['vfb'];
150:
151: exit(0);
152: }
153: }
154:
155:
156: define('FREEBUSY_ERROR_NOTFOUND', 0);
157: define('FREEBUSY_ERROR_UNAUTHORIZED', 1);
158: define('FREEBUSY_ERROR_SERVER', 2);
159:
160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172:
173: class Horde_Kolab_FreeBusy_View_error extends Horde_Kolab_FreeBusy_View {
174:
175: 176: 177:
178: function render()
179: {
180: switch ($this->_data['type']) {
181: case FREEBUSY_ERROR_NOTFOUND:
182: $this->notFound($this->_data['error']);
183: exit(1);
184: case FREEBUSY_ERROR_UNAUTHORIZED:
185: $this->unauthorized($this->_data['error']);
186: exit(1);
187: case FREEBUSY_ERROR_SERVER:
188: $this->serverError($this->_data['error']);
189: exit(1);
190: }
191: }
192:
193: 194: 195: 196: 197:
198: function notFound($error)
199: {
200: $headers = array('HTTP/1.0 404 Not Found');
201: if (isset($_SERVER['REQUEST_URI'])) {
202: $url = htmlentities($_SERVER['REQUEST_URI']);
203: } else {
204: $url = '/';
205: }
206: $message = sprintf(Horde_Kolab_FreeBusy_Translation::t("The requested URL %s was not found on this server."), $url);
207:
208: $this->_errorPage($error, $headers, Horde_Kolab_FreeBusy_Translation::t("404 Not Found"), Horde_Kolab_FreeBusy_Translation::t("Not found"), $message);
209: }
210:
211: 212: 213: 214: 215:
216: function unauthorized($error)
217: {
218: global $conf;
219:
220: if (!empty($conf['kolab']['imap']['maildomain'])) {
221: $email_domain = $conf['kolab']['imap']['maildomain'];
222: } else {
223: $email_domain = 'localhost';
224: }
225:
226: $headers = array('WWW-Authenticate: Basic realm="freebusy-' . $email_domain . '"',
227: 'HTTP/1.0 401 Unauthorized');
228:
229: $this->_errorPage($error, $headers, Horde_Kolab_FreeBusy_Translation::t("401 Unauthorized"), Horde_Kolab_FreeBusy_Translation::t("Unauthorized"),
230: Horde_Kolab_FreeBusy_Translation::t("You are not authorized to access the requested URL."));
231: }
232:
233: 234: 235: 236: 237:
238: function serverError($error)
239: {
240: $headers = array('HTTP/1.0 500 Server Error');
241: if (isset($_SERVER['REQUEST_URI'])) {
242: $url = htmlentities($_SERVER['REQUEST_URI']);
243: } else {
244: $url = '/';
245: }
246: $this->_errorPage($error, $headers, Horde_Kolab_FreeBusy_Translation::t("500 Server Error"), Horde_Kolab_FreeBusy_Translation::t("Error"),
247: htmlentities($$url));
248: }
249:
250: 251: 252: 253: 254: 255: 256: 257: 258:
259: function _errorPage($error, $headers, $title, $headline, $body)
260: {
261: global $conf;
262:
263:
264: foreach ($headers as $line) {
265: header($line);
266: }
267:
268:
269: echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n";
270: echo "<html><head><title>" . $title . "</title></head>\n";
271: echo "<body>\n";
272: echo "<h1>" . $headline . "</h1>\n";
273: echo "<p>" . $body . "</p>\n";
274: if (!empty($error)) {
275: echo "<hr><pre>" . $error->getMessage() . "</pre>\n";
276: Horde::logMessage($error, 'ERR');
277: }
278: echo "<hr>\n";
279: echo isset($_SERVER['SERVER_SIGNATURE'])?$_SERVER['SERVER_SIGNATURE']:'' . "\n";
280: echo "</body></html>\n";
281: }
282: }
283:
284: