[LON-CAPA-cvs] cvs: loncom /auth roles.tab rolesplain.tab /interface loncommon.pm loncreateuser.pm lonuserutils.pm mydesk.tab

raeburn raeburn at source.lon-capa.org
Sun Oct 9 23:02:57 EDT 2016


raeburn		Mon Oct 10 03:02:57 2016 EDT

  Modified files:              
    /loncom/interface	mydesk.tab lonuserutils.pm loncommon.pm 
                     	loncreateuser.pm 
    /loncom/auth	roles.tab rolesplain.tab 
  Log:
  - "User Access Log" item added to User Management Menu (Single Users) in
    domain context -- 'vac' priv assigned at domain level to domain coordinator
    and domain helpdesk.
  - Can search for user in a domain, and view log-in, logout and role selection
    history, as recorded in user's activity.log file. 
  
  
-------------- next part --------------
Index: loncom/interface/mydesk.tab
diff -u loncom/interface/mydesk.tab:1.168 loncom/interface/mydesk.tab:1.169
--- loncom/interface/mydesk.tab:1.168	Thu Oct  6 16:20:05 2016
+++ loncom/interface/mydesk.tab	Mon Oct 10 03:02:47 2016
@@ -201,6 +201,7 @@
 5:2:pcst:$crs:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:Manage course users:umn
 5:2:pcst:$cmty:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:Manage community users:umn
 5:2:pcca:$requested_domain:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:Manage co-authors:umn
+5:2:pvac:$requested_domain:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:View information about users:umn
 5:2:pcdc:/:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:Create users or modify the roles and privileges of users:umn
 5:2:pmau:$requested_domain:cprv.png:user[_1]:privs[_1]:go('/adm/createuser');:Create users or modify the roles and privileges of users:umn
 5:3:clear
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.175 loncom/interface/lonuserutils.pm:1.176
--- loncom/interface/lonuserutils.pm:1.175	Tue Oct  4 21:02:16 2016
+++ loncom/interface/lonuserutils.pm	Mon Oct 10 03:02:47 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.175 2016/10/04 21:02:16 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.176 2016/10/10 03:02:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5887,6 +5887,9 @@
         if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
             $permission{'custom'} = 1;
         }
+        if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
+            $permission{'activity'} = 1;
+        }
         $permission{'view'} = $permission{'cusr'};
     }
     my $allowed = 0;
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1254 loncom/interface/loncommon.pm:1.1255
--- loncom/interface/loncommon.pm:1.1254	Mon Oct  3 19:40:17 2016
+++ loncom/interface/loncommon.pm	Mon Oct 10 03:02:47 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1254 2016/10/03 19:40:17 raeburn Exp $
+# $Id: loncommon.pm,v 1.1255 2016/10/10 03:02:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9960,7 +9960,7 @@
 }
 
 sub user_picker {
-    my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
+    my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom) = @_;
     my $currdom = $dom;
     my @alldoms = &Apache::lonnet::all_domains();
     if (@alldoms == 1) {
@@ -10024,7 +10024,12 @@
                                        );
     &html_escape(\%html_lt);
     &js_escape(\%js_lt);
-    my $domform = &select_dom_form($currdom,'srchdomain',1,1);
+    my $domform;
+    if ($fixeddom) {
+        $domform = &select_dom_form($currdom,'srchdomain',1,1,undef,[$currdom]);
+    } else {
+        $domform = &select_dom_form($currdom,'srchdomain',1,1);
+    }
     my $srchinsel = ' <select name="srchin">';
 
     my @srchins = ('crs','dom','alc','instd');
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.415 loncom/interface/loncreateuser.pm:1.416
--- loncom/interface/loncreateuser.pm:1.415	Mon Oct 10 02:53:02 2016
+++ loncom/interface/loncreateuser.pm	Mon Oct 10 03:02:48 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.415 2016/10/10 02:53:02 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.416 2016/10/10 03:02:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -737,6 +737,8 @@
         $helpitem = 'Course_Editing_Custom_Roles';
     } elsif ($env{'form.action'} eq 'singlestudent') {
         $helpitem = 'Course_Add_Student';
+    } elsif ($env{'form.action'} eq 'accesslogs') {
+        $helpitem = 'Domain_User_Access_Logs';
     }
     my %breadcrumb_text = &singleuser_breadcrumb($crstype);
     if ($env{'form.action'} eq 'custom') {
@@ -766,6 +768,7 @@
                     'srst' => 'Search for a user and enroll as a student',
                     'srme' => 'Search for a user and enroll as a member',
                     'srad' => 'Search for a user and modify/add user information or roles',
+                    'srva' => 'Search for a user and view access log information',
 		    'usr'  => "Username",
                     'dom'  => "Domain",
                     'ecrp' => "Define or Edit Custom Role",
@@ -818,6 +821,8 @@
             } else {
                 $actiontext = $lt{'srst'};
             }
+        } elsif ($env{'form.action'} eq 'accesslogs') {
+            $actiontext = $lt{'srva'}; 
         }
         $r->print("<h3>$actiontext</h3>");
         if ($env{'form.origform'} ne 'crtusername') {
@@ -826,7 +831,7 @@
                          '<br clear="all" />');
             }
         }
-        $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
+        $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
     }
 }
 
@@ -869,7 +874,7 @@
 }
 
 sub entry_form {
-    my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
+    my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
     my ($usertype,$inexact);
     if (ref($srch) eq 'HASH') {
         if (($srch->{'srchin'} eq 'dom') &&
@@ -889,10 +894,12 @@
         &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
     my ($userpicker,$cansearch) = 
        &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
-                                       'document.crtuser',$cancreate,$usertype);
+                                       'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
     my $srchbutton = &mt('Search');
     if ($env{'form.action'} eq 'singlestudent') {
         $srchbutton = &mt('Search and Enroll');
+    } elsif ($env{'form.action'} eq 'accesslogs') {
+        $srchbutton = &mt('Search');
     } elsif ($cancreate && $responsemsg ne '' && $inexact) {
         $srchbutton = &mt('Search or Add New User');
     }
@@ -909,7 +916,7 @@
     } else {
         $output = '<p>'.$userpicker.'</p>';
     }
-    if ($env{'form.phase'} eq '') {
+    if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs')) {
         my $defdom=$env{'request.role.domain'};
         my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
         my %lt=&Apache::lonlocal::texthash(
@@ -1025,9 +1032,11 @@
                                        'usrch'          => "User Search to add/modify roles",
                                        'stusrch'        => "User Search to enroll student",
                                        'memsrch'        => "User Search to enroll member",
+                                       'srcva'          => "Search for a user and view access log information",
                                        'usel'           => "Select a user to add/modify roles",
                                        'stusel'         => "Select a user to enroll as a student",
                                        'memsel'         => "Select a user to enroll as a member",
+                                       'vacsel'         => "Select a user to view access log",
                                        'username'       => "username",
                                        'domain'         => "domain",
                                        'lastname'       => "last name",
@@ -1076,6 +1085,10 @@
                 $r->print($lt{'stusel'});
             }
             $r->print('</h3>');
+        } elsif ($env{'form.action'} eq 'accesslogs') {
+            $r->print("<b>$lt{'srcva'}</b><br />");
+            $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
+            $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
         }
     }
     $r->print('<form name="usersrchform" method="post" action="">'.
@@ -1611,6 +1624,10 @@
         }
         $breadcrumb_text{'userpicked'} = 'Select a user',
         $breadcrumb_text{'modify'} = 'Set section/dates',
+    } elsif ($env{'form.action'} eq 'accesslogs') {
+        $breadcrumb_text{'search'} = 'View access logs for a user';
+        $breadcrumb_text{'userpicked'} = 'Select a user',
+        $breadcrumb_text{'activity'} = 'Activity',
     } else {
         $breadcrumb_text{'search'} = 'Create/modify a user';
         $breadcrumb_text{'userpicked'} = 'Select a user',
@@ -4609,8 +4626,9 @@
         } else {
             &Apache::lonuserutils::print_first_users_upload_form($r,$context);
         }
-    } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
-             eq 'singlestudent')) && ($permission->{'cusr'})) {
+    } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
+              eq 'singlestudent')) && ($permission->{'cusr'})) ||
+             (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
         my $phase = $env{'form.phase'};
         my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
 	&Apache::loncreateuser::restore_prev_selections();
@@ -4619,7 +4637,7 @@
 	    $srch->{$item} = $env{'form.'.$item};
 	}
         if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
-            ($phase eq 'createnewuser')) {
+            ($phase eq 'createnewuser') || ($phase eq 'activity')) {
             if ($env{'form.phase'} eq 'createnewuser') {
                 my $response;
                 if ($env{'form.srchterm'} !~ /^$match_username$/) {
@@ -4649,8 +4667,8 @@
                     &print_user_selection_page($r,$response,$srch,$results,
                                                \@search,$context,undef,$crstype,
                                                $brcrum);
-                } elsif ($currstate eq 'modify') {
-                    my ($ccuname,$ccdomain);
+                } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
+                    my ($ccuname,$ccdomain,$uhome);
                     if (($srch->{'srchby'} eq 'uname') && 
                         ($srch->{'srchtype'} eq 'exact')) {
                         $ccuname = $srch->{'srchterm'};
@@ -4661,12 +4679,32 @@
                     }
                     $ccuname =&LONCAPA::clean_username($ccuname);
                     $ccdomain=&LONCAPA::clean_domain($ccdomain);
-                    if ($env{'form.forcenewuser'}) {
-                        $response = '';
+                    if ($env{'form.action'} eq 'accesslogs') {
+                        my $uhome;
+                        if (($ccuname ne '') && ($ccdomain ne '')) {
+                           $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
+                        }
+                        if (($uhome eq '') || ($uhome eq 'no_host')) {
+                            $env{'form.phase'} = '';
+                            undef($forcenewuser);
+                            #if ($response) {
+                            #    unless ($response =~ m{\Q<br /><br />\E$}) {
+                            #        $response .= '<br /><br />';
+                            #    }
+                            #}
+                            &print_username_entry_form($r,$context,$response,$srch,
+                                                       $forcenewuser,$crstype,$brcrum);
+                        } else {
+                            &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
+                        }
+                    } else {
+                        if ($env{'form.forcenewuser'}) {
+                            $response = '';
+                        }
+                        &print_user_modification_page($r,$ccuname,$ccdomain,
+                                                      $srch,$response,$context,
+                                                      $permission,$crstype,$brcrum);
                     }
-                    &print_user_modification_page($r,$ccuname,$ccdomain,
-                                                  $srch,$response,$context,
-                                                  $permission,$crstype,$brcrum);
                 } elsif ($currstate eq 'query') {
                     &print_user_query_page($r,'createuser',$brcrum);
                 } else {
@@ -4677,9 +4715,17 @@
             } elsif ($env{'form.phase'} eq 'userpicked') {
                 my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
                 my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
-                &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
-                                              $context,$permission,$crstype,
-                                              $brcrum);
+                if ($env{'form.action'} eq 'accesslogs') {
+                    &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
+                } else {
+                    &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
+                                                  $context,$permission,$crstype,
+                                                  $brcrum);
+                }
+            } elsif ($env{'form.action'} eq 'accesslogs') {
+                my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
+                my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
+                &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
             }
         } elsif ($env{'form.phase'} eq 'update_user_data') {
             &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
@@ -5310,6 +5356,16 @@
        );
 
     if ($context eq 'domain'){
+        push(@{  $menu[0]->{items} }, # Single Users
+            {
+             linktext => 'User Access Log',
+             icon => 'document-properties.png',  
+             #help => 'User_Access_Logs',
+             url => '/adm/createuser?action=accesslogs',
+             permission => $permission->{'activity'},
+             linktitle => 'View user access log.',
+            }
+        );
         
         push(@{ $menu[2]->{items} }, #Category: Administration
             {
@@ -6591,6 +6647,324 @@
     return;
 }
 
+sub print_useraccesslogs_display {
+    my ($r,$uname,$udom,$permission,$brcrum) = @_;
+    my $formname = 'accesslog';
+    my $form = 'document.accesslog';
+
+# set breadcrumbs
+    my %breadcrumb_text = &singleuser_breadcrumb();
+    push (@{$brcrum},
+        {href => "javascript:backPage($form)",
+         text => $breadcrumb_text{'search'}});
+    my (@prevphases,$prevphasestr);
+    if ($env{'form.prevphases'}) {
+        @prevphases = split(/,/,$env{'form.prevphases'});
+        $prevphasestr = $env{'form.prevphases'};
+    }
+    if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/, at prevphases))) {
+        push(@{$brcrum},
+              {href => "javascript:backPage($form,'get_user_info','select')",
+               text => $breadcrumb_text{'userpicked'}});
+        if ($env{'form.phase'} eq 'userpicked') {
+            $prevphasestr = 'userpicked';
+        }
+    }
+    push(@{$brcrum},
+             {href => '/adm/createuser?action=accesslogs',
+              text => 'User access logs',
+              help => 'User_Access_Logs'});
+    my $bread_crumbs_component = 'User Access Logs';
+    my $args = { bread_crumbs           => $brcrum,
+                 bread_crumbs_component => 'User Management'};
+
+# set javascript 
+    my ($jsback,$elements) = &crumb_utilities();
+    my $jsnav = &userlogdisplay_js($formname);
+
+    my $jscript = (<<ENDSCRIPT);
+<script type="text/javascript">
+// <![CDATA[
+
+$jsback
+$jsnav
+
+// ]]>
+</script>
+
+ENDSCRIPT
+
+# print page header 
+    $r->print(&header($jscript,$args));
+
+# early out unless log data can be displayed.
+    unless ($permission->{'activity'}) {
+        $r->print('<p class="LC_warning">'
+                 .&mt('You do not have rights to display user access logs.')
+                 .'</p>'
+                 .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
+        return;
+    }
+
+    unless ($udom eq $env{'request.role.domain'}) {
+        $r->print('<p class="LC_warning">'
+                 .&mt("User's domain must match role's domain")
+                 .'</p>'
+                 .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
+        return;    
+    }
+
+    if (($uname eq '') || ($udom eq '')) {
+        $r->print('<p class="LC_warning">'
+                 .&mt('Invalid username or domain')
+                 .'</p>'
+                 .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
+        return;
+    }
+
+# set defaults
+    my $now = time();
+    my $defstart = $now - (7*24*3600);
+    my %defaults = (
+                     page                 => '1',
+                     show                 => '10',
+                     activity             => 'any',
+                     accesslog_start_date => $defstart,
+                     accesslog_end_date   => $now,
+                   );
+    my $more_records = 0;
+
+# set current
+    my %curr;
+    foreach my $item ('show','page','activity') {
+        $curr{$item} = $env{'form.'.$item};
+    }
+    my ($startdate,$enddate) =
+        &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
+    $curr{'accesslog_start_date'} = $startdate;
+    $curr{'accesslog_end_date'} = $enddate;
+    foreach my $key (keys(%defaults)) {
+        if ($curr{$key} eq '') {
+            $curr{$key} = $defaults{$key};
+        }
+    }
+    my ($minshown,$maxshown);
+    $minshown = 1;
+    my $count = 0;
+    if ($curr{'show'} =~ /\D/) {
+        $curr{'page'} = 1;
+    } else {
+        $maxshown = $curr{'page'} * $curr{'show'};
+        if ($curr{'page'} > 1) {
+            $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
+        }
+    }
+
+# form header
+    $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
+              &activity_display_filter($formname,\%curr));
+
+    my $showntableheader = 0;
+    my ($nav_script,$nav_links);
+
+# table header
+    my $tableheader =
+        &Apache::loncommon::start_data_table_header_row()
+       .'<th> </th>'
+       .'<th>'.&mt('When').'</th>'
+       .'<th>'.&mt('HostID').'</th>'
+       .'<th>'.&mt('Event').'</th>'
+       .'<th>'.&mt('Other data').'</th>'
+       .&Apache::loncommon::end_data_table_header_row();
+
+    my %filters=(
+        start  => $curr{'accesslog_start_date'},
+        end    => $curr{'accesslog_end_date'},
+        action => $curr{'activity'},
+    );
+
+    my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
+    unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
+        my (%courses,%missing);
+        my @results = split(/\&/,$reply);
+        foreach my $item (reverse(@results)) {
+            my ($timestamp,$host,$event) = split(/:/,$item);
+            next unless ($event =~ /^(Log|Role)/);
+            if ($curr{'show'} !~ /\D/) {
+                if ($count >= $curr{'page'} * $curr{'show'}) {
+                    $more_records = 1;
+                    last;
+                }
+            }
+            $count ++;
+            next if ($count < $minshown);
+            unless ($showntableheader) {
+                $r->print($nav_script
+                         .&Apache::loncommon::start_data_table()
+                         .$tableheader);
+                $r->rflush();
+                $showntableheader = 1;
+            }
+            my ($shown,$extra,);
+            my ($event,$data) = split(/\s+/,&unescape($event));
+            if ($event eq 'Role') {
+                my ($rolecode,$extent) = split(/\./,$data,2);
+                next if ($extent eq '');
+                my ($crstype,$desc,$info);
+                if ($extent =~ m{^/($match_domain)/($match_courseid)$}) {
+                    my ($cdom,$cnum) = ($1,$2);
+                    my $cid = $cdom.'_'.$cnum;
+                    if (exists($courses{$cid})) {
+                        $crstype = $courses{$cid}{'type'};
+                        $desc = $courses{$cid}{'description'};
+                    } elsif ($missing{$cid}) {
+                        $crstype = 'Course';
+                        $desc = 'Course/Community';
+                    } else {
+                        my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
+                        if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
+                            $courses{$cid} = $crsinfo{$cid};
+                            $crstype = $crsinfo{$cid}{'type'};
+                            $desc = $crsinfo{$cid}{'description'};
+                        } else {
+                            $missing{$cid} = 1;
+                        }
+                    }
+                    $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
+                } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
+                    my ($dom,$name) = ($1,$2);
+                    if ($rolecode eq 'au') {
+                        $extra = '';
+                    } elsif ($rolecode =~ /^(ca|aa)$/) {
+                        $extra = &mt('Authoring Space: [_1]',$name.':'.$dom); 
+                    } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
+                        $extra = &mt('Domain: [_1]',$dom);
+                    }
+                }
+                my $rolename;
+                if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
+                    my $role = $3;
+                    my $owner = "($2:$1)"; 
+                    if ($2 eq $1.'-domainconfig') {
+                        $owner = '(ad hoc)';
+                    } 
+                    $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
+                } else {
+                    $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
+                }
+                $shown = &mt('Role selection: [_1]',$rolename);
+            } else {
+                $shown = &mt($event);
+                if ($data ne '') {
+                   $extra = &mt('Client IP address: [_1]',$data);
+                }
+            }
+            $r->print(
+            &Apache::loncommon::start_data_table_row()
+           .'<td>'.$count.'</td>'
+           .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
+           .'<td>'.$host.'</td>'
+           .'<td>'.$shown.'</td>'
+           .'<td>'.$extra.'</td>'
+           .&Apache::loncommon::end_data_table_row()."\n");
+        }
+    }
+
+    if ($showntableheader) { # Table footer, if content displayed above
+        $r->print(&Apache::loncommon::end_data_table().
+                  &userlogdisplay_navlinks(\%curr,$more_records));
+    } else { # No content displayed above
+        $r->print('<p class="LC_info">'
+                 .&mt('There are no records to display.')
+                 .'</p>');
+    }
+
+    # Form Footer
+    $r->print(
+        '<input type="hidden" name="currstate" value="" />'
+       .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
+       .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
+       .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
+       .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
+       .'<input type="hidden" name="phase" value="activity" />'
+       .'<input type="hidden" name="action" value="accesslogs" />'
+       .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
+       .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
+       .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
+       .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
+       .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
+       .'</form>');
+    return;
+}
+
+sub earlyout_accesslog_form {
+    my ($formname,$prevphasestr,$udom) = @_;
+    my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
+   return <<"END";
+<form action="/adm/createuser" method="post" name="$formname">
+<input type="hidden" name="currstate" value="" />
+<input type="hidden" name="prevphases" value="$prevphasestr" />
+<input type="hidden" name="phase" value="activity" />
+<input type="hidden" name="action" value="accesslogs" />
+<input type="hidden" name="srchdomain" value="$udom" />
+<input type="hidden" name="srchby" value="$env{'form.srchby'}" />
+<input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
+<input type="hidden" name="srchterm" value="$srchterm" />
+<input type="hidden" name="srchin" value="$env{'form.srchin'}" />
+</form>
+END
+}
+
+sub activity_display_filter {
+    my ($formname,$curr) = @_;
+    my $nolink = 1;
+    my $output = '<table><tr><td valign="top">'.
+                 '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
+                 &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
+                                              (&mt('all'),5,10,20,50,100,1000,10000)).
+                 '</td><td>  </td>';
+    my $startform =
+        &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
+                                            $curr->{'accesslog_start_date'},undef,
+                                            undef,undef,undef,undef,undef,undef,$nolink);
+    my $endform =
+        &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
+                                            $curr->{'accesslog_end_date'},undef,
+                                            undef,undef,undef,undef,undef,undef,$nolink);
+    my %lt = &Apache::lonlocal::texthash (
+                                          activity => 'Activity',
+                                          Role     => 'Role selection',
+                                          log      => 'Log-in or Logout',
+    );
+    $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
+               '<table><tr><td>'.&mt('After:').
+               '</td><td>'.$startform.'</td></tr>'.
+               '<tr><td>'.&mt('Before:').'</td>'.
+               '<td>'.$endform.'</td></tr></table>'.
+               '</td>'.
+               '<td>  </td>'.
+               '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
+               '<select name="activity"><option value="any"';
+    if ($curr->{'activity'} eq 'any') {
+        $output .= ' selected="selected"';
+    }
+    $output .= '>'.&mt('Any').'</option>'."\n";
+    foreach my $activity ('Role','log') {
+        my $selstr = '';
+        if ($activity eq $curr->{'activity'}) {
+            $selstr = ' selected="selected"';
+        }
+        $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
+    }
+    $output .= '</select></td>'.
+               '</tr></table>';
+    # Update Display button
+    $output .= '<p>'
+              .'<input type="submit" value="'.&mt('Update Display').'" />'
+              .'</p>';
+    return $output;
+}
+
 sub userlogdisplay_js {
     my ($formname) = @_;
     return <<"ENDSCRIPT";
@@ -6860,6 +7234,9 @@
                                 &build_search_response($context,$srch,%srch_results);
                         } else {
                             $currstate = 'modify';
+                            if ($env{'form.action'} eq 'accesslogs') {
+                                $currstate = 'activity';
+                            }
                             my $uname = $srch->{'srchterm'};
                             my $udom = $srch->{'srchdomain'};
                             $srch_results{$uname.':'.$udom} =
@@ -7147,7 +7524,11 @@
         $currstate = 'select';
     } else {
         if (keys(%srch_results) == 1) {
-            $currstate = 'modify';
+            if ($env{'form.action'} eq 'accesslogs') {
+                $currstate = 'activity';
+            } else {
+                $currstate = 'modify';
+            }
             $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
             if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
                 $response .= ': '.&display_domain_info($srch->{'srchdomain'});
@@ -7192,7 +7573,8 @@
                     $createdom = $env{'form.coursedom'};
                 }
             }
-            if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
+            unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
+                    ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
                 my $cancreate =
                     &Apache::lonuserutils::can_create_user($createdom,$context);
                 my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
Index: loncom/auth/roles.tab
diff -u loncom/auth/roles.tab:1.63 loncom/auth/roles.tab:1.64
--- loncom/auth/roles.tab:1.63	Thu Oct  6 16:20:15 2016
+++ loncom/auth/roles.tab	Mon Oct 10 03:02:57 2016
@@ -1,6 +1,6 @@
 su:s csu&U:sma:mau:cdc&U:dro:psa:adv
 dc:s bre:sma:adv:mcr:srm
-dc:d cli&UIK:cau&UIK:cca&UIK:caa&UIK:cdg&UIK:cdh&UIK:mau:ccc&U:cco&U:cin&UIK:cta&UIK:cep&UIK:ccr&UIK:cst&UIK:cad&UIK:csc&UIK:dro:mky:psa:usc:mpq:mut:eco&U
+dc:d cli&UIK:cau&UIK:cca&UIK:caa&UIK:cdg&UIK:cdh&UIK:mau:ccc&U:cco&U:cin&UIK:cta&UIK:cep&UIK:ccr&UIK:cst&UIK:cad&UIK:csc&UIK:dro:mky:psa:usc:mpq:mut:vac:eco&U
 cc:s bre:sma:mcr:vsa:adv:vcl
 cc:c cin&IK:cta&IK:cep&IK:ccr&IK:cst&IK:are:cre:ere:vgr:gan:dcm:evb:srm:dff:opa:mgr:mqg:mgq:rin:pch:plc:mdc:usc:vsa:vcl:mdg:vcg:pav:pfo:whn:las:pac:dch
 co:s bro:sma:mcr:vsa:adv:vcl 
@@ -29,7 +29,7 @@
 aa:s sma:bro:pav
 aa:d are:ere
 dg:d bre&R
-dh:d sma:rar:dcd:dcc
+dh:d sma:rar:dcd:dcc:vac
 sc:d usc
 
 
Index: loncom/auth/rolesplain.tab
diff -u loncom/auth/rolesplain.tab:1.46 loncom/auth/rolesplain.tab:1.47
--- loncom/auth/rolesplain.tab:1.46	Thu Oct  6 16:20:15 2016
+++ loncom/auth/rolesplain.tab	Mon Oct 10 03:02:57 2016
@@ -86,6 +86,7 @@
 usc:Upload bubblesheet data
 rar:Receive ad hoc role in course or community
 dcd:Display detailed information in course catalog  
+vac:View information about user activity
 dcc:Display information about course creation and requests
 pfo:Print for other users and entire course
 pav:Advanced printing options (with answers, discussions, all foils, ...)


More information about the LON-CAPA-cvs mailing list