ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronMailNotification.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
34 {
36  {
37  global $ilLog,$ilDB;
38 
39  $this->log =& $ilLog;
40  $this->db =& $ilDB;
41  }
42 
43  function sendMails($res)
44  {
45  global $ilias, $rbacsystem;
46 
47  }
48 
49  function sendNotifications()
50  {
51  global $ilias;
52 
53  include_once "Services/Mail/classes/class.ilMail.php";
54  include_once './Services/User/classes/class.ilObjUser.php';
55  include_once "./Services/Language/classes/class.ilLanguage.php";
56 
57  $query = "SELECT mail.* "
58  ."FROM mail_options "
59  ."INNER JOIN mail ON mail.user_id = mail_options.user_id "
60  ."INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id "
61  ."WHERE 1 "
62  ."AND cronjob_notification = '1' "
63  ."AND send_time >= '" . date("Y-m-d H:i:s", time() - 60 * 60 * 24). "' "
64  ."AND mail_obj_data.type = 'inbox' "
65  ."AND m_status = 'unread' "
66  ." ";
67 
68  $res = $this->db->query($query);
69 
70  $users = array();
71 
72  $user_id = 0;
73  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
74  {
75  if ($user_id == 0 || $row['user_id'] != $user_id) $user_id = $row['user_id'];
76 
77  $users[$user_id][] = $row;
78  }
79 
80  $numRows = 0;
81  foreach ($users as $user_id => $mail_data)
82  {
83  $tmp_mail_obj = new ilMail($user_id);
84 
85  include_once "Services/Mail/classes/class.ilMimeMail.php";
86 
87  $mmail = new ilMimeMail();
88  $mmail->autoCheck(false);
89  $mmail->From('noreply');
90  $mmail->To(ilObjUser::_lookupEmail($user_id));
91  $mmail->Subject($tmp_mail_obj->formatNotificationSubject());
92  $mmail->Body($tmp_mail_obj->formatNotificationMessage($user_id, $mail_data));
93 
94  $mmail->Send();
95 
96  unset($tmp_mail_obj);
97 
98  ++$numRows;
99  }
100 
101  $this->log->write(__METHOD__.': Send '.$numRows.' messages.');
102 
103  return true;
104  }
105 }
106 ?>