ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailSummaryNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Mail/classes/class.ilMailNotification.php';
5 
6 include_once 'Services/Mail/classes/class.ilMimeMail.php';
7 
15 {
19  public function __construct()
20  {
22  }
23 
24  public function send()
25  {
26  global $ilDB, $lng, $ilSetting;
27 
28  $is_message_enabled = $ilSetting->get("mail_notification_message");
29 
30  $res = $ilDB->queryF('SELECT mail.* FROM mail_options
31  INNER JOIN mail ON mail.user_id = mail_options.user_id
32  INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
33  WHERE cronjob_notification = %s
34  AND send_time >= %s
35  AND m_status = %s',
36  array('integer', 'timestamp', 'text'),
37  array(1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'unread')
38  );
39 
40  $users = array();
41  $user_id = 0;
42 
43  while($row = $ilDB->fetchAssoc($res))
44  {
45  if($user_id == 0 || $row['user_id'] != $user_id)
46  {
47  $user_id = $row['user_id'];
48  }
49  $users[$user_id][] = $row;
50  }
51 
52  foreach($users as $user_id => $mail_data)
53  {
54  $this->initLanguage($user_id);
55  $user_lang = $this->getLanguage() ? $this->getLanguage() : $lng;
56 
57  $this->initMail();
58 
59  $this->setRecipients($user_id);
60  $this->setSubject($this->getLanguageText('mail_notification_subject'));
61 
62  $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
63  $this->appendBody("\n\n");
64  if(count($mail_data) == 1)
65  {
66  $this->appendBody(sprintf($user_lang->txt('mail_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
67  }
68  else
69  {
70  $this->appendBody(sprintf($user_lang->txt('mails_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
71  }
72  $this->appendBody("\n\n");
73 
74  $counter = 1;
75  foreach($mail_data as $mail)
76  {
77  $this->appendBody("----------------------------------------------------------------------------------------------");
78  $this->appendBody("\n\n");
79  $this->appendBody('#'.$counter."\n\n");
80  $this->appendBody($user_lang->txt('date') .": ".$mail['send_time']);
81  $this->appendBody("\n");
82  $this->appendBody($user_lang->txt('sender') .": ".ilObjUser::_lookupLogin($mail['sender_id'])."");
83  $this->appendBody("\n");
84  $this->appendBody($user_lang->txt('subject').": ". $mail['m_subject']);
85  $this->appendBody("\n\n");
86 
87  if($is_message_enabled == true)
88  {
89  $this->appendBody($user_lang->txt('message').": ". $mail['m_message']);
90  $this->appendBody("\n\n");
91  }
92  ++$counter;
93  }
94  $this->appendBody("----------------------------------------------------------------------------------------------");
95  $this->appendBody("\n\n");
96  $this->appendBody($user_lang->txt('follow_link_to_read_mails')." ");
97  $this->appendBody("\n");
98  $mailbox_link = ilUtil::_getHttpPath();
99  $mailbox_link .= "/goto.php?target=mail&client_id=".CLIENT_ID;
100 
101  $this->appendBody($mailbox_link);
102  $this->appendBody("\n\n");
105 
106  $mmail = new ilMimeMail();
107  $mmail->autoCheck(false);
108  $mmail->From(ilMail::getIliasMailerAddress());
109  $mmail->To(ilObjUser::_lookupEmail($user_id));
110 
111  $mmail->Subject($this->getSubject());
112  $mmail->Body($this->getBody());
113  $mmail->Send();
114  }
115  }
116 }