diff --git a/lib/calcms/user_stats.pm b/lib/calcms/user_stats.pm index 3cd66a5..1561215 100644 --- a/lib/calcms/user_stats.pm +++ b/lib/calcms/user_stats.pm @@ -67,8 +67,6 @@ sub get ($$) { $limit }; - #print STDERR Dumper($query).Dumper(\@bind_values); - my $results = db::get( $dbh, $query, \@bind_values ); return $results; } @@ -125,8 +123,6 @@ sub get_stats($$) { $limit }; - #print STDERR Dumper($query).Dumper(\@bind_values); - my $results = db::get( $dbh, $query, \@bind_values ); for my $result (@$results) { $result->{score} = 0; @@ -193,7 +189,6 @@ sub update ($$) { where user=? and project_id=? and studio_id=? and series_id=? }; - #print STDERR Dumper($query).Dumper(\@bind_values); my $dbh = db::connect($config); return db::put( $dbh, $query, \@bind_values ); } @@ -203,25 +198,16 @@ sub increase ($$$) { my $usecase = shift; my $options = shift; - #print STDERR Dumper($usecase)." ".Dumper($options); - return undef unless defined $usecase; return undef unless defined $options->{project_id}; return undef unless defined $options->{studio_id}; return undef unless defined $options->{series_id}; return undef unless defined $options->{user}; - #print STDERR "ok\n"; - my $columns = get_columns($config); - - #print STDERR "columns:".Dumper($columns); return undef unless defined $columns->{$usecase}; my $entries = get( $config, $options ); - - #print STDERR "exist:".Dumper($columns); - if ( scalar @$entries == 0 ) { my $entry = { project_id => $options->{project_id}, @@ -231,20 +217,37 @@ sub increase ($$$) { $usecase => 1, }; - #print STDERR "user_stats::insert\n"; return insert( $config, $entry ); } elsif ( scalar @$entries == 1 ) { my $entry = $entries->[0]; $entry->{$usecase}++ if defined - - #print STDERR "user_stats::update\n"; - return update( $config, $entry ); + return update( $config, $entry ); } else { print STDERR "user_stats: to few options given: $usecase," . Dumper($options) . "\n"; } } +sub get_active_users{ + my $config = shift; + + my $dbh = db::connect($config); + + my $query=qq{ + select u.name login, u.full_name, + s.last_login, s.login_count, + u.disabled, u.created_at, u.created_by + from calcms_users u left join ( + SELECT user , max(start) last_login, count(user) login_count + FROM calcms_user_sessions + group by user + ) s on s.user=u.name + order by u.disabled, s.last_login desc, u.created_at desc + }; + my $results = db::get( $dbh, $query, [] ); + return $results; +} + sub error ($) { my $msg = shift; print "ERROR: $msg
\n"; diff --git a/website/agenda/planung/pot/de/menu.po b/website/agenda/planung/pot/de/menu.po index 7181cb6..c5008c9 100644 --- a/website/agenda/planung/pot/de/menu.po +++ b/website/agenda/planung/pot/de/menu.po @@ -58,3 +58,6 @@ msgstr "Dienstplan" msgid "preview" msgstr "Vorschau" +msgid "user-stats" +msgstr "Nutzeraktivität" + diff --git a/website/agenda/planung/pot/de/user-stats.po b/website/agenda/planung/pot/de/user-stats.po index 0e843bf..15bbbaa 100644 --- a/website/agenda/planung/pot/de/user-stats.po +++ b/website/agenda/planung/pot/de/user-stats.po @@ -31,3 +31,30 @@ msgstr "letzte Änderung" msgid "label_score" msgstr "Punkte" +msgid "label_login" +msgstr "Login" + +msgid "label_full_name" +msgstr "Name" + +msgid "label_last_login" +msgstr "letztes Login" + +msgid "label_login_count" +msgstr "Anzahl Logins" + +msgid "label_disabled" +msgstr "gesperrt" + +msgid "label_created_at" +msgstr "erstellt am" + +msgid "label_created_by" +msgstr "erstellt von" + +msgid "button_show_active_users" +msgstr "aktive Nutzer" + +msgid "button_show_user_stats" +msgstr "Nutzerstatistik" + diff --git a/website/agenda/planung/pot/en/menu.po b/website/agenda/planung/pot/en/menu.po index b4cd0eb..fba146c 100644 --- a/website/agenda/planung/pot/en/menu.po +++ b/website/agenda/planung/pot/en/menu.po @@ -58,3 +58,6 @@ msgstr "Schedule" msgid "preview" msgstr "Preview" +msgid "user-stats" +msgstr "User Stats" + diff --git a/website/agenda/planung/pot/en/user-stats.po b/website/agenda/planung/pot/en/user-stats.po index 3a7bd6a..8b63e90 100644 --- a/website/agenda/planung/pot/en/user-stats.po +++ b/website/agenda/planung/pot/en/user-stats.po @@ -31,3 +31,30 @@ msgstr "last modified at" msgid "label_score" msgstr "Score" +msgid "label_login" +msgstr "Login" + +msgid "label_full_name" +msgstr "Name" + +msgid "label_last_login" +msgstr "last login date" + +msgid "label_login_count" +msgstr "login counts" + +msgid "label_disabled" +msgstr "disabled" + +msgid "label_created_at" +msgstr "created at" + +msgid "label_created_by" +msgstr "created by" + +msgid "button_show_active_users" +msgstr "active users" + +msgid "button_show_user_stats" +msgstr "user stats" + diff --git a/website/agenda/planung/templates/default.html b/website/agenda/planung/templates/default.html index 7aaad28..2c93603 100644 --- a/website/agenda/planung/templates/default.html +++ b/website/agenda/planung/templates/default.html @@ -51,6 +51,10 @@
 
+ +
 
+
+
 
 
diff --git a/website/agenda/planung/templates/user-active.html b/website/agenda/planung/templates/user-active.html new file mode 100644 index 0000000..c94b240 --- /dev/null +++ b/website/agenda/planung/templates/user-active.html @@ -0,0 +1,67 @@ + + + + + + + + +

+
+ + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/website/agenda/planung/templates/user-stats.html b/website/agenda/planung/templates/user-stats.html index cd08cc9..524271d 100644 --- a/website/agenda/planung/templates/user-stats.html +++ b/website/agenda/planung/templates/user-stats.html @@ -28,6 +28,10 @@ table#user_stats_table input{
+ +
@@ -36,15 +40,15 @@ table#user_stats_table input{ - + + + + + + + + diff --git a/website/agenda/planung/user-stats.cgi b/website/agenda/planung/user-stats.cgi index 8ed6d39..c55b685 100755 --- a/website/agenda/planung/user-stats.cgi +++ b/website/agenda/planung/user-stats.cgi @@ -58,9 +58,16 @@ return unless uac::check( $config, $params, $user_presets ) == 1; our $errors = []; -show_stats( $config, $request ); +if ($params->{action} eq 'show-active-users'){ + show_active_users($config, $request); + return; +}; +if ($params->{action} eq 'show-user-stats'){ + show_user_stats( $config, $request ); + return; +}; -sub show_stats { +sub show_user_stats { my $config = shift; my $request = shift; @@ -70,14 +77,38 @@ sub show_stats { uac::permissions_denied('read_user_stats'); return; } - print STDERR "continue\n"; $params->{user_stats} = user_stats::get_stats( $config, $params ); $params->{permissions} = $permissions; $params->{errors} = $errors; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'user-stats' } ); uac::set_template_permissions( $permissions, $params ); - template::process( $config, 'print', $params->{template}, $params ); + my $template = template::check( $config, 'user-stats' ); + template::process( $config, 'print', $template, $params ); +} + +sub show_active_users{ + my $config = shift; + my $request = shift; + + my $params = $request->{params}->{checked}; + my $permissions = $request->{permissions}; + unless ( $permissions->{read_user_stats} ) { + uac::permissions_denied('read_user_stats'); + return; + } + my $user_stats = user_stats::get_active_users( $config, $params ); + for my $user (@$user_stats){ + $user->{disabled} = $user->{disabled} ? 'x' : '-'; + } + $params->{user_stats} = $user_stats; + $params->{permissions} = $permissions; + $params->{errors} = $errors; + + $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'user-stats' } ); + uac::set_template_permissions( $permissions, $params ); + my $template = template::check( $config, 'user-active' ); + template::process( $config, 'print', $template, $params ); } sub check_params { @@ -86,10 +117,12 @@ sub check_params { my $checked = {}; - #template - my $template = ''; - $template = template::check( $config, $params->{template}, 'user-stats' ); - $checked->{template} = $template; + $checked->{action} = ''; + if ( defined $params->{action} ) { + if ( $params->{action} =~ /^(show-user-stats|show-active-users)$/ ) { + $checked->{action} = $params->{action}; + } + } #numeric values for my $param ( 'project_id', 'default_studio_id', 'studio_id', 'series_id' ) {
- - - - - - - - +