ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarMailNotification.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once './Services/Mail/classes/class.ilMailNotification.php';
25 
35 {
42 
43  const TYPE_USER = 7;
45 
46  private $appointment_id = null;
47 
51  public function __construct()
52  {
53  $this->setSender(ANONYMOUS_USER_ID);
54  }
55 
61  public function setAppointmentId($a_id)
62  {
63  $this->appointment_id = $a_id;
64 
65  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
66  $this->appointment = new ilCalendarEntry($this->getAppointmentId());
67  }
68 
73  public function getAppointment()
74  {
75  return $this->appointment;
76  }
77 
82  public function getAppointmentId()
83  {
84  return $this->appointment_id;
85  }
86 
87  public function appendAppointmentDetails()
88  {
89  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
90  $app = new ilCalendarEntry($this->getAppointmentId());
91  $this->appendBody($app->appointmentToMailString($this->getLanguage()));
92  }
93 
94 
99  public function send()
100  {
101  global $rbacreview,$lng;
102 
103  switch($this->getType())
104  {
105  case self::TYPE_USER:
106  $rcp = array_pop($this->getRecipients());
107  $this->initLanguage($rcp);
108  $this->getLanguage()->loadLanguageModule('dateplaner');
109  $this->initMail();
110  $this->setSubject(
111  sprintf(
112  $this->getLanguageText('cal_mail_notification_subject'),
113  $this->getAppointment()->getTitle()
114  )
115  );
116  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
117  $this->appendBody("\n\n");
118  $this->appendBody(
119  $this->getLanguageText('cal_mail_notification_body')
120  );
121  $this->appendBody("\n\n");
122  $this->appendAppointmentDetails();
123  $this->appendBody("\n\n");
124  $this->getMail()->appendInstallationSignature(true);
125  $this->addAttachment();
126 
127  $this->sendMail(
128  $this->getRecipients(),
129  array('system'),
130  true
131  );
132  break;
133 
134  case self::TYPE_USER_ANONYMOUS:
135 
136  $rcp = array_pop($this->getRecipients());
137 
138  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
139  $this->getLanguage()->loadLanguageModule('dateplaner');
140  $this->getLanguage()->loadLanguageModule('mail');
141  $this->initMail();
142  $this->setSubject(
143  sprintf(
144  $this->getLanguageText('cal_mail_notification_subject'),
145  $this->getAppointment()->getTitle()
146  )
147  );
148  $this->setBody(ilMail::getSalutation(0, $this->getLanguage()));
149  $this->appendBody("\n\n");
150  $this->appendBody(
151  $this->getLanguageText('cal_mail_notification_body')
152  );
153  $this->appendBody("\n\n");
154  $this->appendAppointmentDetails();
155  $this->appendBody("\n\n");
156  $this->getMail()->appendInstallationSignature(true);
157  $this->addAttachment();
158 
159  $this->sendMail(
160  $this->getRecipients(),
161  array('email'),
162  false
163  );
164  break;
165 
166  case self::TYPE_GRP_NEW_NOTIFICATION:
167 
168  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
169  $this->getLanguage()->loadLanguageModule('grp');
170  $this->getLanguage()->loadLanguageModule('dateplaner');
171  $this->initMail();
172  $this->setSubject(
173  sprintf($this->getLanguageText('cal_grp_new_notification_sub'),$this->getObjectTitle(true))
174  );
175  $this->setBody($this->getLanguageText('grp_notification_salutation'));
176  $this->appendBody("\n\n");
177  $this->appendBody(
178  sprintf($this->getLanguageText('cal_grp_new_notification_body'),$this->getObjectTitle(true))
179  );
180  $this->appendBody("\n\n");
181  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
182  $this->appendBody("\n\n");
183 
184  $this->appendAppointmentDetails();
185 
186  $this->appendBody("\n\n");
187  $this->appendBody($this->createPermanentLink());
188  $this->getMail()->appendInstallationSignature(true);
189 
190  $this->addAttachment();
191 
192  $this->sendMail(array('#il_grp_admin_'.$this->getRefId(),'#il_grp_member_'.$this->getRefId()),array('system'),false);
193  break;
194 
195  case self::TYPE_GRP_NOTIFICATION:
196 
197  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
198  $this->getLanguage()->loadLanguageModule('grp');
199  $this->getLanguage()->loadLanguageModule('dateplaner');
200  $this->initMail();
201  $this->setSubject(
202  sprintf($this->getLanguageText('cal_grp_notification_sub'),$this->getObjectTitle(true))
203  );
204  $this->setBody($this->getLanguageText('grp_notification_salutation'));
205  $this->appendBody("\n\n");
206  $this->appendBody(
207  sprintf($this->getLanguageText('cal_grp_notification_body'),$this->getObjectTitle(true))
208  );
209  $this->appendBody("\n\n");
210 
211  $this->appendAppointmentDetails();
212 
213  $this->appendBody("\n\n");
214  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
215  $this->appendBody("\n\n");
216  $this->appendBody($this->createPermanentLink());
217  $this->getMail()->appendInstallationSignature(true);
218 
219  $this->addAttachment();
220 
221  $this->sendMail(array('#il_grp_admin_'.$this->getRefId(),'#il_grp_member_'.$this->getRefId()),array('system'),false);
222  break;
223 
224  case self::TYPE_CRS_NEW_NOTIFICATION:
225 
226  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
227  $this->getLanguage()->loadLanguageModule('crs');
228  $this->getLanguage()->loadLanguageModule('dateplaner');
229  $this->initMail();
230  $this->setSubject(
231  sprintf($this->getLanguageText('cal_crs_new_notification_sub'),$this->getObjectTitle(true))
232  );
233  $this->setBody($this->getLanguageText('crs_notification_salutation'));
234  $this->appendBody("\n\n");
235  $this->appendBody(
236  sprintf($this->getLanguageText('cal_crs_new_notification_body'),$this->getObjectTitle(true))
237  );
238  $this->appendBody("\n\n");
239  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
240  $this->appendBody("\n\n");
241  $this->appendBody($this->createPermanentLink());
242  $this->appendBody("\n\n");
243  $this->appendAppointmentDetails();
244 
245  $this->getMail()->appendInstallationSignature(true);
246 
247  $this->addAttachment();
248 
249  $this->sendMail(array('#il_crs_admin_'.$this->getRefId(),'#il_crs_tutor_'.$this->getRefId(),'#il_crs_member_'.$this->getRefId()),array('system'),false);
250  break;
251 
252  case self::TYPE_CRS_NOTIFICATION:
253 
254  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
255  $this->getLanguage()->loadLanguageModule('crs');
256  $this->getLanguage()->loadLanguageModule('dateplaner');
257  $this->initMail();
258  $this->setSubject(
259  sprintf($this->getLanguageText('cal_crs_notification_sub'),$this->getObjectTitle(true))
260  );
261  $this->setBody($this->getLanguageText('crs_notification_salutation'));
262  $this->appendBody("\n\n");
263  $this->appendBody(
264  sprintf($this->getLanguageText('cal_crs_notification_body'),$this->getObjectTitle(true))
265  );
266  $this->appendBody("\n\n");
267 
268  $this->appendAppointmentDetails();
269 
270  $this->appendBody("\n\n");
271  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
272  $this->appendBody("\n\n");
273  $this->appendBody($this->createPermanentLink());
274  $this->getMail()->appendInstallationSignature(true);
275 
276  $this->addAttachment();
277 
278  $this->sendMail(array('#il_crs_admin_'.$this->getRefId(),'#il_crs_tutor_'.$this->getRefId(),'#il_crs_member_'.$this->getRefId()),array('system'),false);
279  break;
280 
281  case self::TYPE_BOOKING_CONFIRMATION:
282 
283  $user_id = array_pop($this->getRecipients());
284  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
285  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
286  $entry = new ilCalendarEntry($this->getAppointmentId());
287  $booking = new ilBookingEntry($entry->getContextId());
288 
289  $this->initLanguage($user_id);
290  $this->getLanguage()->loadLanguageModule('dateplaner');
291  $this->initMail();
292  $this->setSubject(
293  sprintf($this->getLanguageText('cal_booking_confirmation_subject'),$entry->getTitle())
294  );
295  $this->setBody(ilMail::getSalutation($user_id,$this->getLanguage()));
296  $this->appendBody("\n\n");
297  $this->appendBody(
298  sprintf($this->getLanguageText('cal_booking_confirmation_body'),ilObjUser::_lookupFullname($booking->getObjId()))
299  );
300  $this->appendBody("\n\n");
301 
302  $this->appendAppointmentDetails($booking);
303 
304  /*
305  $this->appendBody("\n\n");
306  $this->appendBody($this->getLanguageText('cal_booking_confirmation_link'));
307  $this->appendBody("\n\n");
308  $this->appendBody($this->createPermanentLink());
309  */
310  $this->getMail()->appendInstallationSignature(true);
311 
312  $this->sendMail(array($user_id),array('system'),true);
313 
314  $this->appendBody("\n\n");
315  $this->appendBody($this->getLanguageText('cal_booking_confirmation_user')."\n");
316  $this->appendBody(ilObjUser::_lookupFullname($user_id));
317 
318  $this->sendMail(array($booking->getObjId()),array('system'),true);
319  break;
320 
321  case self::TYPE_BOOKING_CANCELLATION:
322 
323  $user_id = array_pop($this->getRecipients());
324  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
325  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
326  $entry = new ilCalendarEntry($this->getAppointmentId());
327  $booking = new ilBookingEntry($entry->getContextId());
328 
329  $user_id = array_pop($this->getRecipients());
330  $this->initLanguage($user_id);
331  $this->getLanguage()->loadLanguageModule('dateplaner');
332  $this->initMail();
333  $this->setSubject(
334  sprintf($this->getLanguageText('cal_booking_cancellation_subject'),$entry->getTitle())
335  );
336  $this->setBody(ilMail::getSalutation($user_id,$this->getLanguage()));
337  $this->appendBody("\n\n");
338  $this->appendBody(
339  sprintf($this->getLanguageText('cal_booking_cancellation_body'),ilObjUser::_lookupFullname($booking->getObjId()))
340  );
341  $this->appendBody("\n\n");
342 
343  $this->appendAppointmentDetails($booking);
344 
345  $this->getMail()->appendInstallationSignature(true);
346 
347  $this->sendMail(array($user_id),array('system'),true);
348 
349  $this->appendBody("\n\n");
350  $this->appendBody($this->getLanguageText('cal_booking_cancellation_user')."\n");
351  $this->appendBody(ilObjUser::_lookupFullname($user_id));
352 
353  $this->sendMail(array($booking->getObjId()),array('system'),true);
354  break;
355  }
356 
357  $this->deleteAttachments();
358  }
359 
360  protected function addAttachment()
361  {
362  global $ilUser;
363 
364  include_once './Services/Calendar/classes/Export/class.ilCalendarExport.php';
365  $export = new ilCalendarExport();
366  $export->setExportType(ilCalendarExport::EXPORT_APPOINTMENTS);
367  $export->setAppointments(array($this->getAppointmentId()));
368  $export->export();
369 
370  include_once './Services/Mail/classes/class.ilFileDataMail.php';
371  $attachment = new ilFileDataMail($this->getSender());
372  $attachment->storeAsAttachment(
373  'appointment.ics',
374  $export->getExportString()
375  );
376 
377  $this->setAttachments(
378  array(
379  'appointment.ics'
380  )
381  );
382  }
383 
387  protected function deleteAttachments()
388  {
389  include_once './Services/Mail/classes/class.ilFileDataMail.php';
390  $attachment = new ilFileDataMail($this->getSender());
391  $attachment->unlinkFiles($this->getAttachments());
392 
393  }
394 }
395 ?>