ILIAS  Release_4_0_x_branch Revision 61816
 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-2009 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  $GLOBALS["ilDB"] = $this->db;
47  include_once './Services/Administration/classes/class.ilSetting.php';
48  $this->setting = new ilSetting();
49 
50  }
51 
52  function initLog($path,$file,$client)
53  {
54  include_once './Services/Logging/classes/class.ilLog.php';
55 
56  $this->log =& new ilLog($path,$file,$client);
57 
58  return true;
59  }
60 
61  function txt($language,$key,$module = 'common')
62  {
63  include_once './Services/Language/classes/class.ilLanguage.php';
64  return ilLanguage::_lookupEntry($language, $module, $key);
65  }
66 
67 
68  function start()
69  {
70  // add here other checks
71  if($this->__readSetting('cron_user_check'))
72  {
73  $this->__checkUserAccounts();
74  }
75  if($this->__readSetting('cron_link_check'))
76  {
77  $this->__checkLinks();
78  }
79  }
80 
82  {
83  global $ilDB;
84 
85  $two_weeks_in_seconds = 60 * 60 * 24 * 14;
86 
87  $this->log->write('Cron: Start checkUserAccounts()');
88  $query = "SELECT * FROM usr_data,usr_pref ".
89  "WHERE time_limit_message = ".$ilDB->quote(0, "integer")." ".
90  "AND time_limit_unlimited = ".$ilDB->quote(0, "integer")." ".
91  "AND time_limit_from < ".$ilDB->quote(time(), "integer")." ".
92  "AND time_limit_until > ".$ilDB->quote($two_weeks_in_seconds, "integer")." ".
93  "AND usr_data.usr_id = usr_pref.usr_id ".
94  "AND keyword = ".$ilDB->quote("language", "text");
95 
96  $res = $ilDB->query($query);
97 
98  while($row = $ilDB->fetchObject($res))
99  {
100  include_once './Services/Mail/classes/class.ilMimeMail.php';
101 
102  $data['expires'] = $row->time_limit_until;
103  $data['email'] = $row->email;
104  $data['login'] = $row->login;
105  $data['usr_id'] = $row->usr_id;
106  $data['language'] = $row->value;
107  $data['owner'] = $row->time_limit_owner;
108 
109  // Get owner
110  $query = "SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote($data['owner'], "integer");
111 
112  $res2 = $this->db->query($query);
113  while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
114  {
115  $from = $row->email;
116  }
117 
118  // Send mail
119  $mail =& new ilMimeMail();
120 
121  $mail->From($from);
122  $mail->To($data['email']);
123  $mail->Subject($this->txt($data['language'],'account_expires_subject'));
124  $mail->Body($this->txt($data['language'],'account_expires_body')." ".strftime('%Y-%m-%d %R',$data['expires']));
125  $mail->send();
126 
127  // set status 'mail sent'
128  $query = "UPDATE usr_data SET time_limit_message = ".$ilDB->quote(1, "integer").
129  " WHERE usr_id = ".$ilDB->quote($data['usr_id'], "integer");
130  $ilDB->manipulate($query);
131 
132  // Send log message
133  $this->log->write('Cron: (checkUserAccounts()) sent message to '.$data['login'].'.');
134  }
135 
136  }
137 
138 
139  function __checkLinks()
140  {
141  include_once'./classes/class.ilLinkChecker.php';
142 
143  $link_checker =& new ilLinkChecker($this->db);
144  $link_checker->setMailStatus(true);
145 
146  $invalid = $link_checker->checkLinks();
147  foreach($link_checker->getLogMessages() as $message)
148  {
149  $this->log->write($message);
150  }
151 
152  return true;
153  }
154 
155  function __readSetting($a_keyword)
156  {
157  return $this->setting->get($a_keyword);
158 /* $query = "SELECT * FROM sett ings ".
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 ?>