Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 class ilCron
00036 {
00037 var $db;
00038 var $log;
00039
00040 function ilCron(&$db)
00041 {
00042 define('DEBUG',1);
00043 define('SOCKET_TIMEOUT',5);
00044
00045 $this->db = $db;
00046 }
00047
00048 function initLog($path,$file,$client)
00049 {
00050 include_once '../classes/class.ilLog.php';
00051
00052 $this->log =& new ilLog($path,$file,$client);
00053
00054 return true;
00055 }
00056
00057 function txt($language,$key,$module = 'common')
00058 {
00059 $query = "SELECT value FROM lng_data ".
00060 "WHERE module = '".$module."' ".
00061 "AND identifier = '".$key."' ".
00062 "AND lang_key = '".$language."'";
00063
00064 $res = $this->db->query($query);
00065 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00066 {
00067 $value = $row->value;
00068 }
00069 return $value ? $value : $key;
00070 }
00071
00072
00073 function start()
00074 {
00075
00076 if($this->__readSetting('cron_user_check'))
00077 {
00078 $this->__checkUserAccounts();
00079 }
00080 if($this->__readSetting('cron_link_check'))
00081 {
00082 $this->__checkLinks();
00083 }
00084 }
00085
00086 function __checkUserAccounts()
00087 {
00088 $two_weeks_in_seconds = 60 * 60 * 24 * 14;
00089
00090 $this->log->write('Cron: Start checkUserAccounts()');
00091 $query = "SELECT * FROM usr_data,usr_pref ".
00092 "WHERE time_limit_message = '0' ".
00093 "AND time_limit_unlimited = '0' ".
00094 "AND time_limit_from < '".time()."' ".
00095 "AND time_limit_until > '".$two_weeks_in_seconds."' ".
00096 "AND usr_data.usr_id = usr_pref.usr_id ".
00097 "AND keyword = 'language'";
00098
00099 $res = $this->db->query($query);
00100
00101 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00102 {
00103 include_once '../classes/class.ilMimeMail.php';
00104
00105 $data['expires'] = $row->time_limit_until;
00106 $data['email'] = $row->email;
00107 $data['login'] = $row->login;
00108 $data['usr_id'] = $row->usr_id;
00109 $data['language'] = $row->value;
00110 $data['owner'] = $row->time_limit_owner;
00111
00112
00113 $query = "SELECT email FROM usr_data WHERE usr_id = '".$data['owner']."'";
00114
00115 $res2 = $this->db->query($query);
00116 while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
00117 {
00118 $from = $row->email;
00119 }
00120
00121
00122 $mail =& new ilMimeMail();
00123
00124 $mail->From($from);
00125 $mail->To($data['email']);
00126 $mail->Subject($this->txt($data['language'],'account_expires_subject'));
00127 $mail->Body($this->txt($data['language'],'account_expires_body')." ".strftime('%Y-%m-%d %R',$data['expires']));
00128 $mail->send();
00129
00130
00131 $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '".$data['usr_id']."'";
00132 $this->db->query($query);
00133
00134
00135 $this->log->write('Cron: (checkUserAccounts()) sent message to '.$data['login'].'.');
00136 }
00137
00138 }
00139
00140
00141 function __checkLinks()
00142 {
00143 include_once'../classes/class.ilLinkChecker.php';
00144
00145 $link_checker =& new ilLinkChecker($this->db);
00146 $link_checker->setMailStatus(true);
00147
00148 $invalid = $link_checker->checkLinks();
00149 foreach($link_checker->getLogMessages() as $message)
00150 {
00151 $this->log->write($message);
00152 }
00153
00154 return true;
00155 }
00156
00157 function __readSetting($a_keyword)
00158 {
00159 $query = "SELECT * FROM settings ".
00160 "WHERE keyword = '".$a_keyword."'";
00161
00162 $res = $this->db->query($query);
00163 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00164 {
00165 return $row->value ? $row->value : 0;
00166 }
00167 return 0;
00168 }
00169 }
00170 ?>