ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCron.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 
25 // include pear
26 //require_once("DB.php");
27 
34 class ilCron
35 {
36  var $db;
37  var $log;
38 
39  function ilCron(&$db)
40  {
41  define('DEBUG',1);
42  define('SOCKET_TIMEOUT',5);
43 
44  $this->db = $db;
45  }
46 
47  function initLog($path,$file,$client)
48  {
49  include_once '../Services/Logging/classes/class.ilLog.php';
50 
51  $this->log =& new ilLog($path,$file,$client);
52 
53  return true;
54  }
55 
56  function txt($language,$key,$module = 'common')
57  {
58  $query = "SELECT value FROM lng_data ".
59  "WHERE module = '".$module."' ".
60  "AND identifier = '".$key."' ".
61  "AND lang_key = '".$language."'";
62 
63  $res = $this->db->query($query);
64  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
65  {
66  $value = $row->value;
67  }
68  return $value ? $value : $key;
69  }
70 
71 
72  function start()
73  {
74  // add here other checks
75  if($this->__readSetting('cron_user_check'))
76  {
77  $this->__checkUserAccounts();
78  }
79  if($this->__readSetting('cron_link_check'))
80  {
81  $this->__checkLinks();
82  }
83  }
84 
86  {
87  $two_weeks_in_seconds = 60 * 60 * 24 * 14;
88 
89  $this->log->write('Cron: Start checkUserAccounts()');
90  $query = "SELECT * FROM usr_data,usr_pref ".
91  "WHERE time_limit_message = '0' ".
92  "AND time_limit_unlimited = '0' ".
93  "AND time_limit_from < '".time()."' ".
94  "AND time_limit_until > '".$two_weeks_in_seconds."' ".
95  "AND usr_data.usr_id = usr_pref.usr_id ".
96  "AND keyword = 'language'";
97 
98  $res = $this->db->query($query);
99 
100  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
101  {
102  include_once '../Services/Mail/classes/class.ilMimeMail.php';
103 
104  $data['expires'] = $row->time_limit_until;
105  $data['email'] = $row->email;
106  $data['login'] = $row->login;
107  $data['usr_id'] = $row->usr_id;
108  $data['language'] = $row->value;
109  $data['owner'] = $row->time_limit_owner;
110 
111  // Get owner
112  $query = "SELECT email FROM usr_data WHERE usr_id = '".$data['owner']."'";
113 
114  $res2 = $this->db->query($query);
115  while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
116  {
117  $from = $row->email;
118  }
119 
120  // Send mail
121  $mail =& new ilMimeMail();
122 
123  $mail->From($from);
124  $mail->To($data['email']);
125  $mail->Subject($this->txt($data['language'],'account_expires_subject'));
126  $mail->Body($this->txt($data['language'],'account_expires_body')." ".strftime('%Y-%m-%d %R',$data['expires']));
127  $mail->send();
128 
129  // set status 'mail sent'
130  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '".$data['usr_id']."'";
131  $this->db->query($query);
132 
133  // Send log message
134  $this->log->write('Cron: (checkUserAccounts()) sent message to '.$data['login'].'.');
135  }
136 
137  }
138 
139 
140  function __checkLinks()
141  {
142  include_once'../classes/class.ilLinkChecker.php';
143 
144  $link_checker =& new ilLinkChecker($this->db);
145  $link_checker->setMailStatus(true);
146 
147  $invalid = $link_checker->checkLinks();
148  foreach($link_checker->getLogMessages() as $message)
149  {
150  $this->log->write($message);
151  }
152 
153  return true;
154  }
155 
156  function __readSetting($a_keyword)
157  {
158  $query = "SELECT * FROM settings ".
159  "WHERE keyword = '".$a_keyword."'";
160 
161  $res = $this->db->query($query);
162  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
163  {
164  return $row->value ? $row->value : 0;
165  }
166  return 0;
167  }
168 }
169 ?>