--- loncom/interface/lonuserutils.pm 2016/10/14 23:26:21 1.177
+++ loncom/interface/lonuserutils.pm 2017/08/08 15:34:32 1.186
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.177 2016/10/14 23:26:21 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.186 2017/08/08 15:34:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -943,8 +943,14 @@ sub print_upload_manager_footer {
&Apache::lonhtmlcommon::row_closure();
}
+ my ($trustedref,$untrustedref);
+ if ($context eq 'course') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+ } elsif ($context eq 'author') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+ }
$Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
- .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
+ .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trustedref,$untrustedref)
.&Apache::lonhtmlcommon::row_closure();
$Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
@@ -2307,7 +2313,7 @@ sub courses_selector {
my $allidlist = $idlist{$codetitles[0]};
$jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
$jscript .= $scripttext;
- $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
+ $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
}
}
my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
@@ -2572,9 +2578,13 @@ function username_display_launch(usernam
}
}
}
- if (target == 'modify') {
+ if ((target == 'modify') || (target == 'activity')) {
+ var nextaction = 'singleuser';
+ if (target == 'activity') {
+ nextaction = 'accesslogs';
+ }
if (document.$formname.userwin.checked == true) {
- var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';
+ var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
modifywin = window.open(url,'',options,1);
modifywin.focus();
@@ -2583,7 +2593,7 @@ function username_display_launch(usernam
document.$formname.srchterm.value=username;
document.$formname.srchdomain.value=domain;
document.$formname.phase.value='get_user_info';
- document.$formname.action.value = 'singleuser';
+ document.$formname.action.value = nextaction;
document.$formname.submit();
}
}
@@ -2629,6 +2639,7 @@ END
'owin' => "Open in a new window",
'modify' => "Modify a user's information",
'track' => "View a user's recent activity",
+ 'activity' => "View a user's access log",
);
my %lt = (%coltxt,%acttxt);
my $rolefilter = $env{'form.showrole'};
@@ -2719,12 +2730,17 @@ END
if ($permission->{'cusr'}) {
unshift (@linkdests,'modify');
}
- if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
- &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
- $env{'request.course.sec'})) {
- push(@linkdests,'track');
+ if ($context eq 'course') {
+ if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
+ &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
+ $env{'request.course.sec'})) {
+ push(@linkdests,'track');
+ }
+ } elsif ($context eq 'domain') {
+ if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
+ push(@linkdests,'activity');
+ }
}
-
$output .= '
';
my $usernamelink = $env{'form.usernamelink'};
if ($usernamelink eq '') {
@@ -2747,7 +2763,7 @@ END
.''.$lt{'owin'}
.' | ';
}
- $output .= "\n".'
'."\n".
+ $output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
if ($mode eq 'autoenroll') {
@@ -2993,6 +3009,12 @@ END
} (keys(%$userlist));
}
my $rowcount = 0;
+ my $disabled;
+ if ($mode eq 'autoenroll') {
+ unless ($permission->{'cusr'}) {
+ $disabled = ' disabled="disabled"';
+ }
+ }
foreach my $user (@sorted_users) {
my %in;
my $sdata = $userlist->{$user};
@@ -3029,16 +3051,16 @@ END
if ($mode eq 'autoenroll') {
my $cellentry;
if ($in{'type'} eq 'auto') {
- $cellentry = ''.&mt('auto').' ';
+ $cellentry = ''.&mt('auto').' ';
$autocount ++;
} else {
- $cellentry = ''.&mt('manual').' | |
';
+ $cellentry = '';
@@ -3085,7 +3107,14 @@ END
}
if ($showcheckbox) {
$r->print(' | | ');
+ 'actionlist" value="'.
+ &HTML::Entities::encode($checkval,'&<>"').'" />');
+ foreach my $item ('start','end') {
+ $r->print('');
+ }
+ $r->print('');
} else {
$r->print(' | ');
}
@@ -3099,8 +3128,6 @@ END
foreach my $item (@cols) {
if ($item eq 'username') {
$r->print(''.&print_username_link($mode,\%in).' | ');
- } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
- $r->print(''.$in{$item}.' | '."\n");
} elsif ($item eq 'status') {
my $showitem = $in{$item};
if (defined($ltstatus{$in{$item}})) {
@@ -4117,17 +4144,19 @@ sub upfile_drop_add {
$fieldstype{$field.'_choice'} = 'scalar';
}
&Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
- my ($cid,$crstype,$setting);
+ my ($cid,$crstype,$setting,$crsdom);
if ($context eq 'domain') {
$setting = $env{'form.roleaction'};
}
if ($env{'request.course.id'} ne '') {
$cid = $env{'request.course.id'};
$crstype = &Apache::loncommon::course_type();
+ $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
} elsif ($setting eq 'course') {
if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
$cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
$crstype = &Apache::loncommon::course_type($cid);
+ $crsdom = $env{'form.dcdomain'};
}
}
my ($startdate,$enddate) = &get_dates_from_form();
@@ -4138,7 +4167,43 @@ sub upfile_drop_add {
my $defdom=$env{'request.role.domain'};
my $domain;
if ($env{'form.defaultdomain'} ne '') {
- $domain = $env{'form.defaultdomain'};
+ if (($context eq 'course') || ($setting eq 'course')) {
+ unless ($env{'form.defaultdomain'} eq $crsdom) {
+ if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Enrollment of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ return;
+ }
+ } elsif ($context eq 'author') {
+ unless ($env{'form.defaultdomain'} eq $defdom) {
+ if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
+ (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Addition of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ return;
+ }
+ } elsif (($context eq 'domain') && ($setting eq 'domain')) {
+ unless ($env{'form.defaultdomain'} eq $defdom) {
+ if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Addition of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ }
+ }
} else {
$domain = $defdom;
}
@@ -4322,6 +4387,7 @@ sub upfile_drop_add {
# Get new users list
my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
my $counter = -1;
+ my (%willtrust,%trustchecked);
foreach my $line (@userdata) {
$counter ++;
my @secs;
@@ -4369,6 +4435,28 @@ sub upfile_drop_add {
'"'.$entries{$fields{'domain'}}.'"',
$fname,$mname,$lname,$gen);
next;
+ } elsif ($entries{$fields{'domain'}} ne $domain) {
+ my $possdom = $entries{$fields{'domain'}};
+ if ($context eq 'course' || $setting eq 'course') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
+ $trustchecked{$possdom} = 1;
+ }
+ } elsif ($context eq 'author') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
+ }
+ if ($willtrust{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
+ }
+ }
+ unless ($willtrust{$possdom}) {
+ $disallow{$counter} =
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$possdom.'"',
+ $fname,$mname,$lname,$gen);
+ next;
+ }
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -5416,13 +5504,13 @@ sub set_login {
}
sub course_sections {
- my ($sections_count,$role,$current_sec) = @_;
+ my ($sections_count,$role,$current_sec,$disabled) = @_;
my $output = '';
my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
my $numsec = scalar(@sections);
my $is_selected = ' selected="selected"';
if ($numsec <= 1) {
- $output = '