1: <?php
2: /**
3: * Handles Itip response data.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Itip
9: * @author Mike Cochrane <mike@graftonhall.co.nz>
10: * @author Chuck Hagenbuch <chuck@horde.org>
11: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
12: * @author Gunnar Wrobel <wrobel@pardus.de>
13: * @license http://www.horde.org/licenses/lgpl21 LGPL
14: * @link http://pear.horde.org/index.php?package=Itip
15: */
16:
17: /**
18: * Handles Itip response data.
19: *
20: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
21: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
22: *
23: * See the enclosed file COPYING for license information (LGPL). If you did not
24: * receive this file, see
25: * {@link http://www.horde.org/licenses/lgpl21 LGPL}.
26: *
27: * @category Horde
28: * @package Itip
29: * @author Mike Cochrane <mike@graftonhall.co.nz>
30: * @author Chuck Hagenbuch <chuck@horde.org>
31: * @author Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
32: * @author Gunnar Wrobel <wrobel@pardus.de>
33: * @license http://www.horde.org/licenses/lgpl21 LGPL
34: * @link http://pear.horde.org/index.php?package=Itip
35: */
36: class Horde_Itip_Response
37: {
38: /**
39: * The request we are going to answer.
40: *
41: * @var Horde_Itip_Event
42: */
43: private $_request;
44:
45: /**
46: * The requested resource.
47: *
48: * @var Horde_Itip_Resource
49: */
50: private $_resource;
51:
52: /**
53: * Constructor.
54: *
55: * @param Horde_Itip_Event $request The request this instance will
56: * respond to.
57: * @param Horde_Itip_Resource $resource The requested resource.
58: */
59: public function __construct(
60: Horde_Itip_Event $request,
61: Horde_Itip_Resource $resource
62: )
63: {
64: $this->_request = $request;
65: $this->_resource = $resource;
66: }
67:
68: /**
69: * Return the original request.
70: *
71: * @return Horde_Itip_Event The original request.
72: */
73: public function getRequest()
74: {
75: return $this->_request;
76: }
77:
78: /**
79: * Return the response as an iCalendar vEvent object.
80: *
81: * @param Horde_Itip_Response_Type $type The response type.
82: * @param Horde_Icalendar|boolean $vCal The parent container or false if not
83: * provided.
84: *
85: * @return Horde_Icalendar_Vevent The response object.
86: */
87: public function getVevent(
88: Horde_Itip_Response_Type $type,
89: $vCal = false
90: )
91: {
92: $itip_reply = new Horde_Itip_Event_Vevent(
93: Horde_Icalendar::newComponent('VEVENT', $vCal)
94: );
95: $this->_request->copyEventInto($itip_reply);
96:
97: $type->setRequest($this->_request);
98:
99: $itip_reply->setAttendee(
100: $this->_resource->getMailAddress(),
101: $this->_resource->getCommonName(),
102: $type->getStatus()
103: );
104: return $itip_reply->getVevent();
105: }
106:
107: /**
108: * Return the response as an iCalendar object.
109: *
110: * @param Horde_Itip_Response_Type $type The response type.
111: * @param Horde_Itip_Response_Options $options The options for the response.
112: *
113: * @return Horde_Icalendar The response object.
114: */
115: public function getIcalendar(
116: Horde_Itip_Response_Type $type,
117: Horde_Itip_Response_Options $options
118: )
119: {
120: $vCal = new Horde_Icalendar();
121: $options->prepareIcalendar($vCal);
122: $vCal->setAttribute('METHOD', 'REPLY');
123: $vCal->addComponent($this->getVevent($type, $vCal));
124: return $vCal;
125: }
126:
127: /**
128: * Return the response as a MIME message.
129: *
130: * @param Horde_Itip_Response_Type $type The response type.
131: * @param Horde_Itip_Response_Options $options The options for the response.
132: *
133: * @return array A list of two object: The mime headers and the mime
134: * message.
135: */
136: public function getMessage(
137: Horde_Itip_Response_Type $type,
138: Horde_Itip_Response_Options $options
139: )
140: {
141: $message = new Horde_Mime_Part();
142: $message->setType('text/calendar');
143: $options->prepareIcsMimePart($message);
144: $message->setContents(
145: $this->getIcalendar($type, $options)->exportvCalendar()
146: );
147: $message->setEOL("\r\n");
148: $message->setName('event-reply.ics');
149: $message->setContentTypeParameter('METHOD', 'REPLY');
150:
151: // Build the reply headers.
152: $from = $this->_resource->getFrom();
153: $reply_to = $this->_resource->getReplyTo();
154: $headers = new Horde_Mime_Headers();
155: $headers->addHeader('Date', date('r'));
156: $headers->addHeader('From', $from);
157: $headers->addHeader('To', $this->_request->getOrganizer());
158: if (!empty($reply_to) && $reply_to != $from) {
159: $headers->addHeader('Reply-to', $reply_to);
160: }
161: $headers->addHeader(
162: 'Subject', $type->getSubject()
163: );
164:
165: $options->prepareResponseMimeHeaders($headers);
166:
167: return array($headers, $message);
168: }
169:
170: /**
171: * Return the response as a MIME message.
172: *
173: * @param Horde_Itip_Response_Type $type The response type.
174: * @param Horde_Itip_Response_Options $options The options for the response.
175: *
176: * @return array A list of two object: The mime headers and the mime
177: * message.
178: */
179: public function getMultiPartMessage(
180: Horde_Itip_Response_Type $type,
181: Horde_Itip_Response_Options $options
182: )
183: {
184: $message = new Horde_Mime_Part();
185: $message->setType('multipart/alternative');
186:
187: list($headers, $ics) = $this->getMessage($type, $options);
188:
189: $body = new Horde_Mime_Part();
190: $body->setType('text/plain');
191: $options->prepareMessageMimePart($body);
192: $body->setContents(Horde_String::wrap($type->getMessage(), 76));
193:
194: $message->addPart($body);
195: $message->addPart($ics);
196:
197: return array($headers, $message);
198: }
199: }