From 5f3b160801c01a2f837381bfdf68e23a60da6fe8 Mon Sep 17 00:00:00 2001 From: ywarnier Date: Tue, 8 Feb 2011 23:21:14 -0500 Subject: [PATCH] Implemented platformwide not logged in statistics (closes #1929) --- main/admin/statistics/index.php | 4 +++ main/admin/statistics/statistics.lib.php | 44 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/main/admin/statistics/index.php b/main/admin/statistics/index.php index 635570b302..dea9c786ca 100755 --- a/main/admin/statistics/index.php +++ b/main/admin/statistics/index.php @@ -45,6 +45,7 @@ $tools[$strUsers]['action=logins&type=month'] = get_lang('Logins').' ('.get_ $tools[$strUsers]['action=logins&type=day'] = get_lang('Logins').' ('.get_lang('PeriodDay').')'; $tools[$strUsers]['action=logins&type=hour'] = get_lang('Logins').' ('.get_lang('PeriodHour').')'; $tools[$strUsers]['action=pictures'] = get_lang('CountUsers').' ('.get_lang('UserPicture').')'; +$tools[$strUsers]['action=no_login_users'] = get_lang('StatsUsersDidNotLoginInLastPeriods'); // system ... $tools[$strSystem]['action=activities'] = get_lang('ImportantActivities'); @@ -131,6 +132,9 @@ switch ($_GET['action']) { $friends = statistics::get_friends(); statistics::print_stats(get_lang('CountFriends'), $friends); break; + case 'no_login_users': + statistics::print_users_not_logged_in_stats(); + break; } Display::display_footer(); diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php index 29d7e35ad6..775fc50695 100755 --- a/main/admin/statistics/statistics.lib.php +++ b/main/admin/statistics/statistics.lib.php @@ -623,4 +623,48 @@ class Statistics { } return $list_friends; } + /** + * Print the number of users that didn't login for a certain period of time + */ + function print_users_not_logged_in_stats() { + global $_configuration; + $total_logins = array(); + $table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $current_url_id = api_get_current_access_url_id(); + $total = self::count_users(); + if ($_configuration['multiple_access_urls']) { + $table_url = ", $access_url_rel_user_table"; + $where_url = " AND login_user_id=user_id AND access_url_id='".$current_url_id."'"; + } else { + $table_url = ''; + $where_url=''; + } + $sql[get_lang('Thisday')] = + "SELECT count(distinct(login_user_id)) AS number ". + " FROM $table $table_url ". + " WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= NOW() $where_url"; + $sql[get_lang('Last7days')] = + "SELECT count(distinct(login_user_id)) AS number ". + " FROM $table $table_url ". + " WHERE DATE_ADD(login_date, INTERVAL 7 DAY) >= NOW() $where_url"; + $sql[get_lang('Last31days')] = + "SELECT count(distinct(login_user_id)) AS number ". + " FROM $table $table_url ". + " WHERE DATE_ADD(login_date, INTERVAL 31 DAY) >= NOW() $where_url"; + $sql[sprintf(get_lang('LastXMonths'),6)] = + "SELECT count(distinct(login_user_id)) AS number ". + " FROM $table $table_url ". + " WHERE DATE_ADD(login_date, INTERVAL 6 MONTH) >= NOW() $where_url"; + $sql[get_lang('NeverConnected')] = + "SELECT count(distinct(login_user_id)) AS number ". + " FROM $table $table_url WHERE 1=1 $where_url"; + foreach ($sql as $index => $query) { + $res = Database::query($query); + $obj = Database::fetch_object($res); + $r = $total - $obj->number; + $total_logins[$index] = $r < 0 ? 0 : $r; + } + Statistics::print_stats(get_lang('StatsUsersDidNotLoginInLastPeriods'),$total_logins,false); + } }