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

Generated on Fri Dec 13 2013 17:57:03 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1