ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 include_once './Services/Mail/classes/class.ilMailOptions.php';
6 
7 include_once 'Services/Mail/classes/class.ilMimeMail.php';
8 include_once 'Services/Mail/classes/class.ilMail.php';
9 
17 {
21  protected $lng;
22 
26  protected $db;
27 
31  protected $settings;
32 
36  public function __construct($a_is_personal_workspace = false)
37  {
38  global $DIC;
39 
40  $this->db = $DIC->database();
41  $this->lng = $DIC->language();
42  $this->settings = $DIC->settings();
43 
44  parent::__construct($a_is_personal_workspace);
45  }
46 
47  public function send()
48  {
49  $is_message_enabled = $this->settings->get("mail_notification_message");
50 
51  $res = $this->db->queryF(
52  'SELECT mail.* FROM mail_options
53  INNER JOIN mail ON mail.user_id = mail_options.user_id
54  INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
55  INNER JOIN usr_data ud ON ud.usr_id = mail.user_id
56  WHERE mail_options.cronjob_notification = %s
57  AND mail.send_time >= %s
58  AND mail.m_status = %s
59  AND ud.active = %s',
60  array('integer', 'timestamp', 'text', 'integer'),
61  array(1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'unread', 1)
62  );
63 
64  $users = array();
65  $user_id = 0;
66 
67  while ($row = $this->db->fetchAssoc($res)) {
68  if ($user_id == 0 || $row['user_id'] != $user_id) {
69  $user_id = $row['user_id'];
70  }
71  $users[$user_id][] = $row;
72  }
73 
75  $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
76  $sender = $senderFactory->system();
77 
78  foreach ($users as $user_id => $mail_data) {
79  $this->initLanguage($user_id);
80  $user_lang = $this->getLanguage() ? $this->getLanguage() : $this->lng;
81 
82  $this->initMail();
83 
84  $this->setRecipients(array($user_id));
85  $this->setSubject($this->getLanguageText('mail_notification_subject'));
86 
87  $this->setBody(ilMail::getSalutation($user_id, $user_lang));
88  $this->appendBody("\n\n");
89  if (count($mail_data) == 1) {
90  $this->appendBody(sprintf($user_lang->txt('mail_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
91  } else {
92  $this->appendBody(sprintf($user_lang->txt('mails_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
93  }
94  $this->appendBody("\n\n");
95 
96  $counter = 1;
97  foreach ($mail_data as $mail) {
98  $this->appendBody("----------------------------------------------------------------------------------------------");
99  $this->appendBody("\n\n");
100  $this->appendBody('#' . $counter . "\n\n");
101  $this->appendBody($user_lang->txt('date') . ": " . $mail['send_time']);
102  $this->appendBody("\n");
103  if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
104  $senderName = ilMail::_getIliasMailerName();
105  } else {
106  $senderName = ilObjUser::_lookupLogin($mail['sender_id']);
107  }
108  $this->appendBody($user_lang->txt('sender') . ": " . $senderName);
109  $this->appendBody("\n");
110  $this->appendBody($user_lang->txt('subject') . ": " . $mail['m_subject']);
111  $this->appendBody("\n\n");
112 
113  if ($is_message_enabled == true) {
114  $this->appendBody($user_lang->txt('message') . ": " . $mail['m_message']);
115  $this->appendBody("\n\n");
116  }
117  ++$counter;
118  }
119  $this->appendBody("----------------------------------------------------------------------------------------------");
120  $this->appendBody("\n\n");
121  $this->appendBody($user_lang->txt('follow_link_to_read_mails') . " ");
122  $this->appendBody("\n");
123  $mailbox_link = ilUtil::_getHttpPath();
124  $mailbox_link .= "/goto.php?target=mail&client_id=" . CLIENT_ID;
125 
126  $this->appendBody($mailbox_link);
127  $this->appendBody("\n\n");
130 
131  $mmail = new ilMimeMail();
132  $mmail->From($sender);
133  $mmail->To(ilMailOptions::getExternalEmailsByUserId($user_id));
134 
135  $mmail->Subject($this->getSubject());
136  $mmail->Body($this->getBody());
137  $mmail->Send();
138  }
139  }
140 }
static _lookupLogin($a_user_id)
lookup login
global $DIC
Definition: saml.php:7
initLanguage($a_usr_id)
Init language.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
__construct($a_is_personal_workspace=false)
{}
$counter
Base class for course/group mail notifications.
foreach($_POST as $key=> $value) $res
Class ilMimeMail.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
settings()
Definition: settings.php:2
static _getHttpPath()
static getExternalEmailsByUserId($user_id, ilMailOptions $mail_options=null)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
appendBody($a_body)
Append body text.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)