ILIAS  Release_4_4_x_branch Revision 61816
 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  const TYPE_USER = 7;
45 
46  private $appointment_id = null;
47 
51  public function __construct()
52  {
53 
54  $this->setSender(ANONYMOUS_USER_ID);
55  }
56 
62  public function setAppointmentId($a_id)
63  {
64  $this->appointment_id = $a_id;
65 
66  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
67  $this->appointment = new ilCalendarEntry($this->getAppointmentId());
68  }
69 
74  public function getAppointment()
75  {
76  return $this->appointment;
77  }
78 
83  public function getAppointmentId()
84  {
85  return $this->appointment_id;
86  }
87 
88  public function appendAppointmentDetails()
89  {
90  include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
91  $app = new ilCalendarEntry($this->getAppointmentId());
92  $this->appendBody($app->appointmentToMailString($this->getLanguage()));
93  }
94 
95 
100  public function send()
101  {
102  global $rbacreview,$lng;
103 
104  switch($this->getType())
105  {
106  case self::TYPE_USER:
107  $rcp = array_pop($this->getRecipients());
108  $this->initLanguage($rcp);
109  $this->getLanguage()->loadLanguageModule('dateplaner');
110  $this->initMail();
111  $this->setSubject(
112  sprintf(
113  $this->getLanguageText('cal_mail_notification_subject'),
114  $this->getAppointment()->getTitle()
115  )
116  );
117  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
118  $this->appendBody("\n\n");
119  $this->appendBody(
120  $this->getLanguageText('cal_mail_notification_body')
121  );
122  $this->appendBody("\n\n");
123  $this->appendAppointmentDetails();
124  $this->appendBody("\n\n");
125  $this->getMail()->appendInstallationSignature(true);
126  $this->addAttachment();
127 
128  $this->sendMail(
129  $this->getRecipients(),
130  array('system'),
131  true
132  );
133  break;
134 
135  case self::TYPE_USER_ANONYMOUS:
136 
137  $rcp = array_pop($this->getRecipients());
138 
139  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
140  $this->getLanguage()->loadLanguageModule('dateplaner');
141  $this->getLanguage()->loadLanguageModule('mail');
142  $this->initMail();
143  $this->setSubject(
144  sprintf(
145  $this->getLanguageText('cal_mail_notification_subject'),
146  $this->getAppointment()->getTitle()
147  )
148  );
149  $this->setBody(ilMail::getSalutation(0, $this->getLanguage()));
150  $this->appendBody("\n\n");
151  $this->appendBody(
152  $this->getLanguageText('cal_mail_notification_body')
153  );
154  $this->appendBody("\n\n");
155  $this->appendAppointmentDetails();
156  $this->appendBody("\n\n");
157  $this->getMail()->appendInstallationSignature(true);
158  $this->addAttachment();
159 
160  $this->sendMail(
161  $this->getRecipients(),
162  array('email'),
163  false
164  );
165  break;
166 
167  case self::TYPE_GRP_NEW_NOTIFICATION:
168 
169  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
170  $this->getLanguage()->loadLanguageModule('grp');
171  $this->getLanguage()->loadLanguageModule('dateplaner');
172  $this->initMail();
173  $this->setSubject(
174  sprintf($this->getLanguageText('cal_grp_new_notification_sub'),$this->getObjectTitle(true))
175  );
176  $this->setBody($this->getLanguageText('grp_notification_salutation'));
177  $this->appendBody("\n\n");
178  $this->appendBody(
179  sprintf($this->getLanguageText('cal_grp_new_notification_body'),$this->getObjectTitle(true))
180  );
181  $this->appendBody("\n\n");
182  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
183  $this->appendBody("\n\n");
184 
185  $this->appendAppointmentDetails();
186 
187  $this->appendBody("\n\n");
188  $this->appendBody($this->createPermanentLink());
189  $this->getMail()->appendInstallationSignature(true);
190 
191  $this->addAttachment();
192 
193  $this->sendMail(array('#il_grp_admin_'.$this->getRefId(),'#il_grp_member_'.$this->getRefId()),array('system'),false);
194  break;
195 
196  case self::TYPE_GRP_NOTIFICATION:
197 
198  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
199  $this->getLanguage()->loadLanguageModule('grp');
200  $this->getLanguage()->loadLanguageModule('dateplaner');
201  $this->initMail();
202  $this->setSubject(
203  sprintf($this->getLanguageText('cal_grp_notification_sub'),$this->getObjectTitle(true))
204  );
205  $this->setBody($this->getLanguageText('grp_notification_salutation'));
206  $this->appendBody("\n\n");
207  $this->appendBody(
208  sprintf($this->getLanguageText('cal_grp_notification_body'),$this->getObjectTitle(true))
209  );
210  $this->appendBody("\n\n");
211 
212  $this->appendAppointmentDetails();
213 
214  $this->appendBody("\n\n");
215  $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
216  $this->appendBody("\n\n");
217  $this->appendBody($this->createPermanentLink());
218  $this->getMail()->appendInstallationSignature(true);
219 
220  $this->addAttachment();
221 
222  $this->sendMail(array('#il_grp_admin_'.$this->getRefId(),'#il_grp_member_'.$this->getRefId()),array('system'),false);
223  break;
224 
225  case self::TYPE_CRS_NEW_NOTIFICATION:
226 
227  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
228  $this->getLanguage()->loadLanguageModule('crs');
229  $this->getLanguage()->loadLanguageModule('dateplaner');
230  $this->initMail();
231  $this->setSubject(
232  sprintf($this->getLanguageText('cal_crs_new_notification_sub'),$this->getObjectTitle(true))
233  );
234  $this->setBody($this->getLanguageText('crs_notification_salutation'));
235  $this->appendBody("\n\n");
236  $this->appendBody(
237  sprintf($this->getLanguageText('cal_crs_new_notification_body'),$this->getObjectTitle(true))
238  );
239  $this->appendBody("\n\n");
240  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
241  $this->appendBody("\n\n");
242  $this->appendBody($this->createPermanentLink());
243  $this->appendBody("\n\n");
244  $this->appendAppointmentDetails();
245 
246  $this->getMail()->appendInstallationSignature(true);
247 
248  $this->addAttachment();
249 
250  $this->sendMail(array('#il_crs_admin_'.$this->getRefId(),'#il_crs_tutor_'.$this->getRefId(),'#il_crs_member_'.$this->getRefId()),array('system'),false);
251  break;
252 
253  case self::TYPE_CRS_NOTIFICATION:
254 
255  $this->setLanguage(ilLanguageFactory::_getLanguage($lng->getDefaultLanguage()));
256  $this->getLanguage()->loadLanguageModule('crs');
257  $this->getLanguage()->loadLanguageModule('dateplaner');
258  $this->initMail();
259  $this->setSubject(
260  sprintf($this->getLanguageText('cal_crs_notification_sub'),$this->getObjectTitle(true))
261  );
262  $this->setBody($this->getLanguageText('crs_notification_salutation'));
263  $this->appendBody("\n\n");
264  $this->appendBody(
265  sprintf($this->getLanguageText('cal_crs_notification_body'),$this->getObjectTitle(true))
266  );
267  $this->appendBody("\n\n");
268 
269  $this->appendAppointmentDetails();
270 
271  $this->appendBody("\n\n");
272  $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
273  $this->appendBody("\n\n");
274  $this->appendBody($this->createPermanentLink());
275  $this->getMail()->appendInstallationSignature(true);
276 
277  $this->addAttachment();
278 
279  $this->sendMail(array('#il_crs_admin_'.$this->getRefId(),'#il_crs_tutor_'.$this->getRefId(),'#il_crs_member_'.$this->getRefId()),array('system'),false);
280  break;
281 
282  case self::TYPE_BOOKING_CONFIRMATION:
283 
284  $user_id = array_pop($this->getRecipients());
285  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
286  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
287  $entry = new ilCalendarEntry($this->getAppointmentId());
288  $booking = new ilBookingEntry($entry->getContextId());
289 
290  $this->initLanguage($user_id);
291  $this->getLanguage()->loadLanguageModule('dateplaner');
292  $this->initMail();
293  $this->setSubject(
294  sprintf($this->getLanguageText('cal_booking_confirmation_subject'),$entry->getTitle())
295  );
296  $this->setBody(ilMail::getSalutation($user_id,$this->getLanguage()));
297  $this->appendBody("\n\n");
298  $this->appendBody(
299  sprintf($this->getLanguageText('cal_booking_confirmation_body'),ilObjUser::_lookupFullname($booking->getObjId()))
300  );
301  $this->appendBody("\n\n");
302 
303  $this->appendAppointmentDetails($booking);
304 
305  /*
306  $this->appendBody("\n\n");
307  $this->appendBody($this->getLanguageText('cal_booking_confirmation_link'));
308  $this->appendBody("\n\n");
309  $this->appendBody($this->createPermanentLink());
310  */
311  $this->getMail()->appendInstallationSignature(true);
312 
313  $this->sendMail(array($user_id),array('system'),true);
314 
315  $this->appendBody("\n\n");
316  $this->appendBody($this->getLanguageText('cal_booking_confirmation_user')."\n");
317  $this->appendBody(ilObjUser::_lookupFullname($user_id));
318 
319  $this->sendMail(array($booking->getObjId()),array('system'),true);
320  break;
321 
322  case self::TYPE_BOOKING_CANCELLATION:
323 
324  $user_id = array_pop($this->getRecipients());
325  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
326  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
327  $entry = new ilCalendarEntry($this->getAppointmentId());
328  $booking = new ilBookingEntry($entry->getContextId());
329 
330  $user_id = array_pop($this->getRecipients());
331  $this->initLanguage($user_id);
332  $this->getLanguage()->loadLanguageModule('dateplaner');
333  $this->initMail();
334  $this->setSubject(
335  sprintf($this->getLanguageText('cal_booking_cancellation_subject'),$entry->getTitle())
336  );
337  $this->setBody(ilMail::getSalutation($user_id,$this->getLanguage()));
338  $this->appendBody("\n\n");
339  $this->appendBody(
340  sprintf($this->getLanguageText('cal_booking_cancellation_body'),ilObjUser::_lookupFullname($booking->getObjId()))
341  );
342  $this->appendBody("\n\n");
343 
344  $this->appendAppointmentDetails($booking);
345 
346  $this->getMail()->appendInstallationSignature(true);
347 
348  $this->sendMail(array($user_id),array('system'),true);
349 
350  $this->appendBody("\n\n");
351  $this->appendBody($this->getLanguageText('cal_booking_cancellation_user')."\n");
352  $this->appendBody(ilObjUser::_lookupFullname($user_id));
353 
354  $this->sendMail(array($booking->getObjId()),array('system'),true);
355  break;
356 
358 
359  $user_id = array_pop($this->getRecipients());
360 
361  include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
362  include_once 'Services/Booking/classes/class.ilBookingEntry.php';
363  $entry = new ilCalendarEntry($this->getAppointmentId());
364  $booking = new ilBookingEntry($entry->getContextId());
365 
366  $this->initLanguage($user_id);
367  $this->getLanguage()->loadLanguageModule('dateplaner');
368  $this->initMail();
369  $this->setSubject(
370  sprintf($this->getLanguageText('cal_ch_booking_reminder_subject'),$entry->getTitle())
371  );
372  $this->setBody(ilMail::getSalutation($user_id,$this->getLanguage()));
373  $this->appendBody("\n\n");
374  $this->appendBody(
375  sprintf($this->getLanguageText('cal_ch_booking_reminder_body'),ilObjUser::_lookupFullname($booking->getObjId()))
376  );
377  $this->appendBody("\n\n");
378 
379  $this->appendAppointmentDetails($booking);
380 
381  $this->getMail()->appendInstallationSignature(true);
382  $this->sendMail(array($user_id),array('system'),true);
383  break;
384  }
385 
386  $this->deleteAttachments();
387 
388  }
389 
390  protected function addAttachment()
391  {
392  global $ilUser;
393 
394  include_once './Services/Calendar/classes/Export/class.ilCalendarExport.php';
395  $export = new ilCalendarExport();
396  $export->setExportType(ilCalendarExport::EXPORT_APPOINTMENTS);
397  $export->setAppointments(array($this->getAppointmentId()));
398  $export->export();
399 
400  include_once './Services/Mail/classes/class.ilFileDataMail.php';
401  $attachment = new ilFileDataMail($this->getSender());
402  $attachment->storeAsAttachment(
403  'appointment.ics',
404  $export->getExportString()
405  );
406 
407  $this->setAttachments(
408  array(
409  'appointment.ics'
410  )
411  );
412  }
413 
417  protected function deleteAttachments()
418  {
419  include_once './Services/Mail/classes/class.ilFileDataMail.php';
420  $attachment = new ilFileDataMail($this->getSender());
421  $attachment->unlinkFiles($this->getAttachments());
422 
423  }
424 }
425 ?>