ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserCronCheckAccounts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Services/Cron/classes/class.ilCronJob.php";
5 
15 {
16  protected $counter = 0; // [int]
17 
18  public function getId()
19  {
20  return "user_check_accounts";
21  }
22 
23  public function getTitle()
24  {
25  global $lng;
26 
27  return $lng->txt("check_user_accounts");
28  }
29 
30  public function getDescription()
31  {
32  global $lng;
33 
34  return $lng->txt("check_user_accounts_desc");
35  }
36 
37  public function getDefaultScheduleType()
38  {
40  }
41 
42  public function getDefaultScheduleValue()
43  {
44  return;
45  }
46 
47  public function hasAutoActivation()
48  {
49  return false;
50  }
51 
52  public function hasFlexibleSchedule()
53  {
54  return false;
55  }
56 
57  public function run()
58  {
59  global $ilDB, $ilLog, $lng;
60 
62 
63  $now = time();
64  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
65 
66  // all users who are currently active and expire in the next 2 weeks
67  $query = "SELECT * FROM usr_data,usr_pref ".
68  "WHERE time_limit_message = '0' ".
69  "AND time_limit_unlimited = '0' ".
70  "AND time_limit_from < ".$ilDB->quote($now, "integer")." ".
71  "AND time_limit_until > ".$ilDB->quote($now, "integer")." ".
72  "AND time_limit_until < ".$ilDB->quote($two_weeks_in_seconds, "integer")." ".
73  "AND usr_data.usr_id = usr_pref.usr_id ".
74  "AND keyword = ".$ilDB->quote("language", "text");
75 
76  $res = $ilDB->query($query);
77 
78  while($row = $ilDB->fetchObject($res))
79  {
80  include_once 'Services/Mail/classes/class.ilMimeMail.php';
81 
82  $data['expires'] = $row->time_limit_until;
83  $data['email'] = $row->email;
84  $data['login'] = $row->login;
85  $data['usr_id'] = $row->usr_id;
86  $data['language'] = $row->value;
87  $data['owner'] = $row->time_limit_owner;
88 
89  // Send mail
90  $mail =& new ilMimeMail();
91 
92  $mail->From('noreply');
93  $mail->To($data['email']);
94  $mail->Subject($this->txt($data['language'],'account_expires_subject'), true);
95  $mail->Body($this->txt($data['language'],'account_expires_body')." ".strftime('%Y-%m-%d %R',$data['expires']));
96  $mail->send();
97 
98  // set status 'mail sent'
99  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '".$data['usr_id']."'";
100  $ilDB->query($query);
101 
102  // Send log message
103  $ilLog->write('Cron: (checkUserAccounts()) sent message to '.$data['login'].'.');
104 
105  $this->counter++;
106  }
107 
109 
110  if($this->counter)
111  {
112  $status = ilCronJobResult::STATUS_OK;
113  }
114  $result = new ilCronJobResult();
115  $result->setStatus($status);
116  return $result;
117  }
118 
119  // #13288 / #12345
120  protected function txt($language,$key,$module = 'common')
121  {
122  include_once 'Services/Language/classes/class.ilLanguage.php';
123  return ilLanguage::_lookupEntry($language, $module, $key);
124  }
125 
126  protected function checkNotConfirmedUserAccounts()
127  {
128  global $ilDB, $ilLog;
129 
130  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
131  $oRegSettigs = new ilRegistrationSettings();
132 
133  $query = 'SELECT usr_id FROM usr_data '
134  . 'WHERE reg_hash IS NOT NULL '
135  . 'AND active = %s '
136  . 'AND create_date < %s';
137  $res = $ilDB->queryF(
138  $query,
139  array('integer', 'timestamp'),
140  array(0, date('Y-m-d H:i:s', time() - (int)$oRegSettigs->getRegistrationHashLifetime()))
141  );
142  while($row = $ilDB->fetchAssoc($res))
143  {
144  $oUser = ilObjectFactory::getInstanceByObjId((int)$row['usr_id']);
145  $oUser->delete();
146  $ilLog->write('Cron: Deleted '.$oUser->getLogin().' ['.$oUser->getId().'] '.__METHOD__);
147 
148  $this->counter++;
149  }
150  }
151 }