• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

setup/classes/class.ilCron.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 // include pear
00026 //require_once("DB.php");
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                 // add here other checks
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                         // Get owner
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                         // Send mail
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                         // set status 'mail sent'
00131                         $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '".$data['usr_id']."'";
00132                         $this->db->query($query);
00133                         
00134                         // Send log message
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 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1