ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronCheckUserAccounts.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 
35 {
37  {
38  global $ilLog,$ilDB;
39 
40  $this->log =& $ilLog;
41  $this->db =& $ilDB;
42  }
43 
44  function check()
45  {
46  global $ilDB;
47 
48  $this->log->write('Cron: Start ilCronCheckUserAccounts::check()');
49 
50  $now = time();
51  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
52 
53  $query = "SELECT * FROM usr_data,usr_pref ".
54  "WHERE time_limit_message = '0' ".
55  "AND time_limit_unlimited = '0' ".
56  "AND time_limit_from < ".$ilDB->quote($now, "integer")." ".
57  "AND time_limit_until > ".$ilDB->quote($now, "integer")." ".
58  "AND time_limit_until < ".$ilDB->quote($two_weeks_in_seconds, "integer")." ".
59  "AND usr_data.usr_id = usr_pref.usr_id ".
60  "AND keyword = ".$ilDB->quote("language", "text");
61 
62  $res = $ilDB->query($query);
63 
64  while($row = $ilDB->fetchObject($res))
65  {
66  include_once 'Services/Mail/classes/class.ilMimeMail.php';
67 
68  $data['expires'] = $row->time_limit_until;
69  $data['email'] = $row->email;
70  $data['login'] = $row->login;
71  $data['usr_id'] = $row->usr_id;
72  $data['language'] = $row->value;
73  $data['owner'] = $row->time_limit_owner;
74 
75  // Send mail
76  $mail =& new ilMimeMail();
77 
78  $mail->From('noreply');
79  $mail->To($data['email']);
80  $mail->Subject($this->txt($data['language'],'account_expires_subject'));
81  $mail->Body($this->txt($data['language'],'account_expires_body')." ".strftime('%Y-%m-%d %R',$data['expires']));
82  $mail->send();
83 
84  // set status 'mail sent'
85  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '".$data['usr_id']."'";
86  $this->db->query($query);
87 
88  // Send log message
89  $this->log->write('Cron: (checkUserAccounts()) sent message to '.$data['login'].'.');
90 
91 
92  }
93 
94  $this->log->write('Cron: End ilCronCheckUserAccounts::check()');
95 
97  }
98  function txt($language,$key,$module = 'common')
99  {
100  include_once 'Services/Language/classes/class.ilLanguage.php';
101  return ilLanguage::_lookupEntry($language, $module, $key);
102  }
103 
104  protected function checkNotConfirmedUserAccounts()
105  {
106  global $ilDB;
107 
108  $this->log->write('Cron: Start '.__METHOD__);
109 
110  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
111  $oRegSettigs = new ilRegistrationSettings();
112 
113  $query = 'SELECT usr_id FROM usr_data '
114  . 'WHERE reg_hash IS NOT NULL '
115  . 'AND active = %s '
116  . 'AND create_date < %s';
117  $res = $ilDB->queryF(
118  $query,
119  array('integer', 'timestamp'),
120  array(0, date('Y-m-d H:i:s', time() - (int)$oRegSettigs->getRegistrationHashLifetime()))
121  );
122  while($row = $ilDB->fetchAssoc($res))
123  {
124  $oUser = ilObjectFactory::getInstanceByObjId((int)$row['usr_id']);
125  $oUser->delete();
126  $this->log->write('Cron: Deleted '.$oUser->getLogin().' ['.$oUser->getId().'] '.__METHOD__);
127  }
128 
129  $this->log->write('Cron: End '.__METHOD__);
130  }
131 }
132 
133 
134 
135 
136 ?>