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