4 include_once
"Services/Cron/classes/class.ilCronJob.php";
5 include_once
'Services/Mail/classes/class.ilMimeMail.php';
6 include_once
'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
30 if(is_object($ilSetting))
32 $this->include_roles = $ilSetting->get(
33 'cron_inactive_user_delete_include_roles', null
35 if($this->include_roles === null) $this->include_roles = array();
36 else $this->include_roles = explode(
',', $this->include_roles);
38 $this->period = $ilSetting->get(
39 'cron_inactive_user_delete_period',
40 self::DEFAULT_INACTIVITY_PERIOD
42 $this->reminderTimer = $ilSetting->get(
43 'cron_inactive_user_reminder_period',
44 self::DEFAULT_REMINDER_PERIOD
57 switch($schedule_time)
60 $time_difference = 86400;
63 $time_difference = 60 * $multiplier;
66 $time_difference = 3600 * $multiplier;
69 $time_difference = 86400 * $multiplier;
72 $time_difference = 604800;
75 $time_difference = 2629743;
78 $time_difference = 7889229;
81 $time_difference = 31556926;
84 return $time_difference;
89 return "user_inactive";
96 return $lng->txt(
"delete_inactive_user_accounts");
103 return $lng->txt(
"delete_inactive_user_accounts_desc");
131 public function run()
133 global $rbacreview,
$ilLog;
136 $reminder_time = (int)$this->reminderTimer;
137 $checkMail = (int)$this->period - $reminder_time;
141 $userMailsDelivered = 0;
142 foreach($usr_ids as $usr_id)
144 if($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID)
continue;
147 foreach($this->include_roles as $role_id)
149 if( $rbacreview->isAssigned($usr_id, $role_id) )
165 $timestamp_last_login = strtotime($user->getLastLogin());
166 $grace_period_over = time() - ((int)$this->period * 24 * 60 * 60);
167 if($timestamp_last_login < $grace_period_over)
172 else if($reminder_time > 0)
174 $timestamp_for_deletion = $timestamp_last_login - $grace_period_over;
179 $userMailsDelivered++;
190 $ilLog->write(
"CRON - ilCronDeleteInactiveUserAccounts::run(), deleted => $userDeleted User(s), sent reminder mail to $userMailsDelivered User(s)");
199 $time_difference = 0;
202 if(!is_array($cron_timing) || !is_array($cron_timing[0]))
204 return time() + $date_for_deletion + $time_difference;
207 if(array_key_exists(
'schedule_type', $cron_timing[0]))
209 if((array_key_exists(
'schedule_type', $cron_timing[0]) && $cron_timing[0][
'schedule_value'] != null))
211 $multiplier = $cron_timing[0][
'schedule_value'];
215 return time() + $date_for_deletion + $time_difference;
221 $lng->loadLanguageModule(
"user");
224 $schedule->setTitle($lng->txt(
'delete_inactive_user_accounts_frequency'),
225 'delete_inactive_user_accounts_frequency');
226 $schedule->setInfo($lng->txt(
'delete_inactive_user_accounts_frequency_desc'),
227 'delete_inactive_user_accounts_frequency_desc');
229 include_once(
'Services/Form/classes/class.ilMultiSelectInputGUI.php');
231 $lng->txt(
'delete_inactive_user_accounts_include_roles'),
232 'cron_inactive_user_delete_include_roles'
234 $sub_mlist->
setInfo($lng->txt(
'delete_inactive_user_accounts_include_roles_desc'));
236 foreach($rbacreview->getGlobalRoles() as $role_id)
238 if( $role_id != ANONYMOUS_ROLE_ID )
239 $roles[$role_id] = $ilObjDataCache->lookupTitle($role_id);
241 $sub_mlist->setOptions($roles);
242 $setting = $ilSetting->get(
'cron_inactive_user_delete_include_roles', null);
243 if($setting === null) $setting = array();
244 else $setting = explode(
',', $setting);
245 $sub_mlist->setValue($setting);
246 $sub_mlist->setWidth(300);
247 #$sub_mlist->setHeight(100);
252 $lng->txt(
'delete_inactive_user_accounts_period'),
253 'cron_inactive_user_delete_period'
255 $sub_text->
setInfo($lng->txt(
'delete_inactive_user_accounts_period_desc'));
256 $sub_text->setValue($ilSetting->get(
"cron_inactive_user_delete_period", $default_setting));
257 $sub_text->setSize(4);
258 $sub_text->setMaxLength(4);
259 $sub_text->setRequired(
true);
263 $lng->txt(
'send_mail_to_inactive_users'),
264 'cron_inactive_user_reminder_period'
266 $sub_period->
setInfo($lng->txt(
"send_mail_to_inactive_users_desc"));
267 $sub_period->setValue($ilSetting->get(
"cron_inactive_user_reminder_period", $default_setting));
268 $sub_period->setSuffix($lng->txt(
"send_mail_to_inactive_users_suffix"));
269 $sub_period->setSize(4);
270 $sub_period->setMaxLength(4);
271 $sub_period->setRequired(
false);
272 $sub_period->setMinValue(0);
287 $lng->loadLanguageModule(
"user");
288 $setting = implode(
',',
$_POST[
'cron_inactive_user_delete_include_roles']);
289 if(!strlen($setting))
303 $a_form->
getItemByPostVar(
'cron_inactive_user_delete_period')->setAlert($lng->txt(
'send_mail_to_inactive_users_numbers_only'),
'send_mail_to_inactive_users_numbers_only');
308 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert($lng->txt(
'send_mail_to_inactive_users_numbers_only'),
'send_mail_to_inactive_users_numbers_only');
310 if($reminder_period >= $delete_period)
313 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert($lng->txt(
'send_mail_to_inactive_users_must_be_smaller_than'),
'send_mail_to_inactive_users_must_be_smaller_than');
318 $check_window_logic = $delete_period - $reminder_period;
321 if($check_window_logic < $cron_period_custom)
328 if($check_window_logic <= 7)
335 if($check_window_logic <= 31)
342 if($check_window_logic <= 92)
349 if($check_window_logic <= 366)
357 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert($lng->txt(
'send_mail_reminder_window_too_small'),
'send_mail_reminder_window_too_small');
360 if(
$_POST[
'cron_inactive_user_delete_period'])
362 $ilSetting->set(
'cron_inactive_user_delete_include_roles', $setting);
363 $ilSetting->set(
'cron_inactive_user_delete_period',
$_POST[
'cron_inactive_user_delete_period']);
365 if($this->reminderTimer > $reminder_period)
369 $ilSetting->set(
'cron_inactive_user_reminder_period', $reminder_period);
382 if(strpos($number,
',') || strpos($number,
'.'))