Adding "deleting inactive users" scripts (no ready for production) see #2912

skala
Julio Montoya 15 years ago
parent bd51cec74a
commit c1a269228c
  1. 45
      main/admin/inactive_user_list.php
  2. 44
      main/inc/lib/usermanager.lib.php

@ -0,0 +1,45 @@
<?php
/* For licensing terms, see /license.txt */
/**
@author Andre Boivin base code
@author Julio Montoya fixing lot of little details
@todo this script is not ready for a production use that's why I'm commenting the function delete_inactive_student
* @package chamilo.admin
* script pour effacer les user inactif depuis x temps
*/
// name of the language file that needs to be included
$language_file = array ('registration','admin');
$cidReset = true;
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'security.lib.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
$tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
/**
* Make sure this function is protected because it does NOT check password!
*
*/
/** INIT SECTION
*/
Display :: display_header($tool_name, "");
//On sélectionne les user élèves
$sql = "SELECT user_id FROM ".$table_user." user WHERE user.status= '5' ORDER by lastname " ;
$result = Database::query($sql);
while($row = Database::fetch_array($result)) {
$user_id = $row['user_id'];
// pour chaque élève, on trouve la dernière connexion
//$last_connection_date = UserManager:: delete_inactive_student($user_id, 2, true);
}
/* FOOTER */
Display :: display_footer();

@ -3310,4 +3310,48 @@ class UserManager
return $icon_link;
}
/**
*
* @param int student id
* @param int years
* @param bool show warning_message
* @param bool return_timestamp
*/
public static function delete_inactive_student($student_id, $years = 2, $warning_message = false, $return_timestamp = false) {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date FROM ' . $tbl_track_login . ' WHERE login_user_id = ' . intval($student_id) . ' ORDER BY login_date DESC LIMIT 0,1';
if (empty($years)) {
$years = 1;
}
$inactive_time = $years * 31536000; //1 year
$rs = Database::query($sql);
if (Database::num_rows($rs)>0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
$last_login_date = api_get_local_time($last_login_date, null, date_default_timezone_get());
if ($return_timestamp) {
return api_strtotime($last_login_date);
} else {
if (!$warning_message) {
return api_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
$timestamp = api_strtotime($last_login_date);
$currentTimestamp = time();
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds 63072000= 2 ans
// if ($currentTimestamp - $timestamp > 184590 )
if ($currentTimestamp - $timestamp > $inactive_time && UserManager::delete_user($student_id )) {
Display :: display_normal_message(get_lang('UserDeleted'));
//avec validation:
// $result .= '<a href="user_list.php?action=delete_user&amp;user_id='.$student_id.'&amp;'.$url_params.'&amp;sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
echo '<p>','id',$student_id ,':',$last_login_date,'</p>';
}
}
}
}
}
return false;
}
}
Loading…
Cancel
Save