--- loncom/interface/loncreateuser.pm 2008/03/12 02:45:06 1.238
+++ loncom/interface/loncreateuser.pm 2008/07/13 09:53:16 1.254
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.238 2008/03/12 02:45:06 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.254 2008/07/13 09:53:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1396,18 +1396,31 @@ sub modify_login_block {
}
sub personal_data_display {
- my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
- my ($output,$showforceid,%userenv,%canmodify);
+ my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
+ my ($output,$showforceid,%userenv,%canmodify,@inststatuses);
my @userinfo = ('firstname','middlename','lastname','generation',
'permanentemail','id');
+ my $rowcount = 0;
+ my $editable = 0;
+ if ($context eq 'selfcreate') {
+ if (ref($inst_results) eq 'HASH') {
+ @inststatuses = &get_inststatuses($inst_results);
+ if (@inststatuses == 0) {
+ @inststatuses = ('default');
+ }
+ $rolesarray = \@inststatuses;
+ }
+ }
if (!$newuser) {
# Get the users information
%userenv = &Apache::lonnet::get('environment',
['firstname','middlename','lastname','generation',
'permanentemail','id'],$ccdomain,$ccuname);
+ }
+ if ((!$newuser) || ($context eq 'selfcreate')) {
%canmodify =
&Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
- \@userinfo);
+ \@userinfo,$rolesarray);
}
my %lt=&Apache::lonlocal::texthash(
'pd' => "Personal Data",
@@ -1432,40 +1445,78 @@ sub personal_data_display {
&Apache::lonhtmlcommon::start_pick_box();
foreach my $item (@userinfo) {
my $rowtitle = $lt{$item};
+ my $hiderow = 0;
if ($item eq 'generation') {
$rowtitle = $genhelp.$rowtitle;
}
- $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+ my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
if ($newuser) {
if (ref($inst_results) eq 'HASH') {
if ($inst_results->{$item} ne '') {
- $output .= ' '.$inst_results->{$item};
+ $row .= ' '.$inst_results->{$item};
} else {
- $output .= ' ';
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= ' ';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= ' ';
+ }
}
} else {
- $output .= ' ';
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= ' ';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= ' ';
+ }
}
} else {
if ($canmodify{$item}) {
- $output .= ' ';
+ $row .= ' ';
} else {
- $output .= $userenv{$item};
+ $row .= $userenv{$item};
}
if ($item eq 'id') {
$showforceid = $canmodify{$item};
}
}
- $output .= &Apache::lonhtmlcommon::row_closure(1);
+ $row .= &Apache::lonhtmlcommon::row_closure(1);
+ if (!$hiderow) {
+ $output .= $row;
+ $rowcount ++;
+ }
}
$output .= &Apache::lonhtmlcommon::end_pick_box();
if (wantarray) {
- return ($output,$showforceid);
+ if ($context eq 'selfcreate') {
+ return($output,$rowcount,$editable);
+ } else {
+ return ($output,$showforceid);
+ }
} else {
return $output;
}
}
+sub get_inststatuses {
+ my ($insthashref) = @_;
+ my @inststatuses = ();
+ if (ref($insthashref) eq 'HASH') {
+ if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
+ @inststatuses = @{$insthashref->{'inststatus'}};
+ }
+ }
+ return @inststatuses;
+}
+
# ================================================================= Phase Three
sub update_user_data {
my ($r,$context) = @_;
@@ -2041,13 +2092,14 @@ END
&mt('Contact your helpdesk for more information.',"javascript:helpMenu('display')").' ');
}
$r->print($no_forceid_alert.
- &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
+ &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules));
}
if ($env{'form.action'} eq 'singlestudent') {
- &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
- $r->print('
'. &mt('Enroll Another Student').'
');
+ &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context);
+ $r->print(''.
+ &mt('Enroll Another Student').'
');
} else {
- my @rolechanges = &update_roles($r);
+ my @rolechanges = &update_roles($r,$context);
if ($namechanged) {
if ($context eq 'course') {
if (@userroles > 0) {
@@ -2068,14 +2120,17 @@ END
if ($env{'form.popup'}) {
$r->print(''.&mt('Close window').'
');
} else {
- $r->print(''.&mt('Modify this user: ([_1]) ',$userinfo).' '.(' 'x5).''.&mt('Create/Modify Another User').'
');
+ $r->print(''
+ .&mt('Modify this user: [_1]',''.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.') ').' '
+ .(' 'x5).''
+ .&mt('Create/Modify Another User').'
');
}
}
$r->print(&Apache::loncommon::end_page());
}
sub update_roles {
- my ($r) = @_;
+ my ($r,$context) = @_;
my $now=time;
my @rolechanges;
my %disallowed;
@@ -2091,7 +2146,7 @@ sub update_roles {
my $result =
&Apache::lonnet::revokerole($env{'form.ccdomain'},
$env{'form.ccuname'},
- $scope,$role);
+ $scope,$role,'','',$context);
$r->print(&mt('Revoking [_1] in [_2]: [_3]',
$role,$scope,''.$result.' ').' ');
if ($role eq 'st') {
@@ -2110,7 +2165,7 @@ sub update_roles {
$r->print(&mt('Revoking custom role:').
' '.$4.' by '.$3.':'.$2.' in '.$1.': '.
&Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$3,$4).
+ $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
' ');
if (!grep(/^cr$/,@rolechanges)) {
push(@rolechanges,'cr');
@@ -2123,7 +2178,8 @@ sub update_roles {
my $result =
&Apache::lonnet::assignrole($env{'form.ccdomain'},
$env{'form.ccuname'},
- $scope,$role,$now,0,1);
+ $scope,$role,$now,0,1,'',
+ $context);
$r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
''.$result.' ').' ');
if ($role eq 'st') {
@@ -2144,7 +2200,7 @@ sub update_roles {
$rolename,$rnam,$rdom,$url).': '.
&Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
- 0,1).' ');
+ 0,1,$context).' ');
if (!grep(/^cr$/,@rolechanges)) {
push(@rolechanges,'cr');
}
@@ -2176,7 +2232,8 @@ sub update_roles {
}
} else {
my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$url,$role,0,$now);
+ $env{'form.ccuname'},$url,$role,0,$now,'','',
+ $context);
$output = &mt('Re-enabling [_1] in [_2]: [_3] ',
$role,$url,$result).' ';
}
@@ -2190,7 +2247,7 @@ sub update_roles {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
my $result = &Apache::lonnet::assigncustomrole(
$env{'form.ccdomain'}, $env{'form.ccuname'},
- $url,$rdom,$rnam,$rolename,0,$now);
+ $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
$r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5] ',
$rolename,$rnam,$rdom,$url,$result).' ');
if (!grep(/^cr$/,@rolechanges)) {
@@ -2217,7 +2274,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2228,7 +2285,7 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
}
}
if (!grep(/^cr$/,@rolechanges)) {
@@ -2250,7 +2307,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2264,13 +2321,13 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
}
}
if (!grep(/^\Q$three\E$/,@rolechanges)) {
@@ -2292,19 +2349,19 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
} else {
my $emptysec = 0;
foreach my $sec (sort {$a cmp $b} keys %sections) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
}
}
if (!grep(/^\Q$two\E$/,@rolechanges)) {
@@ -2332,7 +2389,7 @@ sub update_roles {
}
sub enroll_single_student {
- my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
+ my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
$r->print(''.&mt('Enrolling Student').' ');
# Remove non alphanumeric values from section
@@ -2347,7 +2404,7 @@ sub enroll_single_student {
$env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
$env{'form.cmiddlename'},$env{'form.clastname'},
$env{'form.generation'},$env{'form.sections'},$enddate,
- $startdate,'manual',undef,$env{'request.course.id'});
+ $startdate,'manual',undef,$env{'request.course.id'},'',$context);
if ($enroll_result =~ /^ok/) {
$r->print(&mt('[_1] enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
if ($env{'form.sections'} ne '') {
@@ -2667,7 +2724,7 @@ sub make_button_code {
}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
- my ($r) = @_;
+ my ($r,$context) = @_;
my $rolename=$env{'form.rolename'};
$rolename=~s/[^A-Za-z0-9]//gs;
if (!$rolename) {
@@ -2742,7 +2799,7 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
$r->print(''.&mt('Create or edit another custom role').'
');
@@ -2886,7 +2943,7 @@ sub handler {
}
} elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
if ($env{'form.phase'} eq 'set_custom_roles') {
- &set_custom_role($r);
+ &set_custom_role($r,$context);
} else {
&custom_role_editor($r);
}
@@ -2978,7 +3035,7 @@ sub handler {
if (!exists($env{'form.state'})) {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
'Course_Self_Enrollment'));
-
+ $r->print(''.&mt('Self-enrollment with a student role').' '."\n");
&print_selfenroll_menu($r,$context,$permission);
} elsif ($env{'form.state'} eq 'done') {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2986,9 +3043,19 @@ sub handler {
text=>"Result"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
'Course_Self_Enrollment'));
- &update_selfenroll_config($r,$context);
+ $r->print(''.&mt('Self-enrollment with a student role').' '."\n");
+ &update_selfenroll_config($r,$context,$permission);
}
$r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'changelogs') {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=changelogs',
+ text=>"User Management Logs"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
+ 'Course_User_Logs'));
+ &print_userchangelogs_display($r,$context,$permission);
+ $r->print(&Apache::loncommon::end_page());
} else {
$r->print(&header());
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
@@ -3092,7 +3159,7 @@ sub print_main_menu {
});
if (!exists($permission->{'cusr_section'})) {
push(@courselinks,
- { text => 'Automated Student Enrollment Manager',
+ { text => 'Automated Enrollment Manager',
help => 'Course_Automated_Enrollment',
permission => (&Apache::lonnet::auto_run($cnum,$cdom)
&& $permission->{'cusr'}),
@@ -3109,7 +3176,17 @@ sub print_main_menu {
help => 'Course_Manage_Group',
permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=cusr',
- });
+ },
+ { text => 'View Change Logs',
+ help => 'Course_User_Logs',
+ action => 'changelogs',
+ permission => $permission->{'cusr'},
+ },);
+# { text => 'View Log-in History',
+# help => 'Course_User_Logins',
+# action => 'logins',
+# permission => $permission->{'cusr'},
+# });
push(@menu,@courselinks);
}
my $menu_html = '';
@@ -3152,12 +3229,185 @@ sub print_selfenroll_menu {
my $groupslist = &Apache::lonuserutils::get_groupslist();
my $setsec_js =
&Apache::lonuserutils::setsections_javascript($formname,$groupslist);
+ my %alerts = &Apache::lonlocal::texthash(
+ acto => 'Activation of self-enrollment was selected for the following domain(s)',
+ butn => 'but no user types have been checked.',
+ wilf => "Please uncheck 'activate' or check at least one type.",
+ );
+ my $selfenroll_js = <<"ENDSCRIPT";
+function update_types(caller,num) {
+ var delidx = getIndexByName('selfenroll_delete');
+ var actidx = getIndexByName('selfenroll_activate');
+ if (caller == 'selfenroll_all') {
+ var selall;
+ for (var i=0; i 0) {
+ var msg = "$alerts{'acto'}\\n";
+ var loopend = needaction.length -1;
+ if (loopend > 0) {
+ for (var m=0; m'."\n".
- $setsec_js."\n".
+ $setsec_js."\n".$selfenroll_js."\n".
''."\n".
''.$lt->{'selfenroll'}.' '."\n".
- '';
+ ' '
+ .' ';
$r->print($output);
return;
}
+sub new_selfenroll_dom_row {
+ my ($newdom,$num) = @_;
+ my $domdesc = &Apache::lonnet::domain($newdom);
+ my $output;
+ if ($domdesc ne '') {
+ $output .= &Apache::loncommon::start_data_table_row()
+ .''.&mt('Domain:').' '.$domdesc
+ .' ('.$newdom.') '
+ .' '
+ .&mt('Activate').' ';
+ my @currinsttypes;
+ $output .= ''.&mt('User types:').' '
+ .&selfenroll_inst_types($num,$newdom,\@currinsttypes).' '
+ .&Apache::loncommon::end_data_table_row();
+ }
+ return $output;
+}
+
+sub selfenroll_inst_types {
+ my ($num,$currdom,$currinsttypes) = @_;
+ my $output;
+ my $numinrow = 4;
+ my $count = 0;
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
+ my $othervalue = 'any';
+ if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+ if (keys(%{$usertypes}) > 0) {
+ $othervalue = 'other';
+ }
+ $output .= '';
+ }
+ return $output;
+}
+
sub selfenroll_date_forms {
my ($startform,$endform) = @_;
my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
- &Apache::lonhtmlcommon::row_title(&mt('Starts'),
+ &Apache::lonhtmlcommon::row_title(&mt('Start date'),
'LC_oddrow_value')."\n".
$startform."\n".
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::row_title(&mt('Ends'),
+ &Apache::lonhtmlcommon::row_title(&mt('End date'),
'LC_oddrow_value')."\n".
$endform."\n".
&Apache::lonhtmlcommon::row_closure(1).
@@ -3264,6 +3654,241 @@ sub selfenroll_date_forms {
return $output;
}
+sub print_userchangelogs_display {
+ my ($r,$context,$permission) = @_;
+ my $formname = 'roleslog';
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
+ if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
+
+ $r->print('');
+ return;
+}
+
+sub role_display_filter {
+ my ($formname,$cdom,$cnum,$curr,$version) = @_;
+ my $context = 'course';
+ my $nolink = 1;
+ my $output = ''.
+ ''.&mt('Changes/page:').' '.
+ &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
+ (&mt('all'),5,10,20,50,100,1000,10000)).
+ ' ';
+ my $startform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
+ $curr->{'rolelog_start_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my $endform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
+ $curr->{'rolelog_end_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my %lt = &rolechg_contexts();
+ $output .= ''.&mt('Window during which changes occurred:').' '.&mt('After:').
+ ' '.$startform.' '.&mt('Before:').' '.
+ $endform.'
'.
+ ''.&mt('Role:').' '.
+ '{'role'} eq 'any') {
+ $output .= ' selected="selected"';
+ }
+ $output .= '>'.&mt('Any').' '."\n";
+ my @roles = &Apache::lonuserutils::course_roles($context,undef,1);
+ foreach my $role (@roles) {
+ my $plrole;
+ if ($role eq 'cr') {
+ $plrole = &mt('Custom Role');
+ } else {
+ $plrole=&Apache::lonnet::plaintext($role);
+ }
+ my $selstr = '';
+ if ($role eq $curr->{'role'}) {
+ $selstr = ' selected="selected"';
+ }
+ $output .= ' '.$plrole.' ';
+ }
+ $output .= ' '.
+ &mt('Context:').' ';
+ foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll') {
+ my $selstr = '';
+ if ($curr->{'chgcontext'} eq $chgtype) {
+ $output .= $selstr = ' selected="selected"';
+ }
+ if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
+ next if (!&Apache::lonnet::auto_run($cnum,$cdom));
+ }
+ $output .= ''.$lt{$chgtype}.' '."\n";
+ }
+ $output .= '
'.
+ ''.
+ &mt('[_1]Note:[_2] Only changes made from servers running LON-CAPA 2.6.99.0 or later are displayed.');
+ if ($version) {
+ $output .= ' '.&mt('This server is version [_3].','',' ',$version); }
+ $output .= ' ';
+ return $output;
+}
+
+sub rolechg_contexts {
+ my %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ auto => 'Automated enrollment',
+ updatenow => 'Roster Update',
+ createcourse => 'Course Creation',
+ course => 'User Management in course',
+ domain => 'User Management in domain',
+ selfenroll => 'Self-enrolled',
+ );
+ return %lt;
+}
+
#-------------------------------------------------- functions for &phase_two
sub user_search_result {
my ($context,$srch) = @_;
@@ -3296,7 +3921,13 @@ sub user_search_result {
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
($srch->{'srchin'} eq 'alc')) {
if ($srch->{'srchby'} eq 'uname') {
- if ($srch->{'srchterm'} !~ /^$match_username$/) {
+ my $unamecheck = $srch->{'srchterm'};
+ if ($srch->{'srchtype'} eq 'contains') {
+ if ($unamecheck !~ /^\w/) {
+ $unamecheck = 'a'.$unamecheck;
+ }
+ }
+ if ($unamecheck !~ /^$match_username$/) {
$response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
}
}
@@ -3887,13 +4518,13 @@ ENDTIMEENTRY
}
sub update_selfenroll_config {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my ($row,$lt) = &get_selfenroll_titles();
- my $groupslist = &Apache::lonuserutils::get_groupslist();
+ my %curr_groups = &Apache::longroup::coursegroups();
my (%changes,%warning);
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $r->print(''.$lt->{'selfenroll'}.' '."\n");
+ my $curr_types;
if (ref($row) eq 'ARRAY') {
foreach my $item (@{$row}) {
if ($item eq 'enroll_dates') {
@@ -3914,13 +4545,78 @@ sub update_selfenroll_config {
$changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
}
}
+ } elsif ($item eq 'types') {
+ $curr_types =
+ $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
+ if ($env{'form.selfenroll_all'}) {
+ if ($curr_types ne '*') {
+ $changes{'internal.selfenroll_types'} = '*';
+ } else {
+ next;
+ }
+ } else {
+ my %currdoms;
+ my @entries = split(/;/,$curr_types);
+ my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
+ my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
+ my $newnum = 0;
+ my @latesttypes;
+ foreach my $num (@activations) {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
+ if (@types > 0) {
+ @types = sort(@types);
+ my $typestr = join(',',@types);
+ my $typedom = $env{'form.selfenroll_dom_'.$num};
+ $latesttypes[$newnum] = $typedom.':'.$typestr;
+ $currdoms{$typedom} = 1;
+ $newnum ++;
+ }
+ }
+ for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) { if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
+ if (@types > 0) {
+ @types = sort(@types);
+ my $typestr = join(',',@types);
+ my $typedom = $env{'form.selfenroll_dom_'.$j};
+ $latesttypes[$newnum] = $typedom.':'.$typestr;
+ $currdoms{$typedom} = 1;
+ $newnum ++;
+ }
+ }
+ }
+ if ($env{'form.selfenroll_newdom'} ne '') {
+ my $typedom = $env{'form.selfenroll_newdom'};
+ if ((!defined($currdoms{$typedom})) &&
+ (&Apache::lonnet::domain($typedom) ne '')) {
+ my $typestr;
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($typedom);
+ my $othervalue = 'any';
+ if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+ if (@{$types} > 0) {
+ $othervalue = 'other';
+ $typestr = join(',',(@{$types},$othervalue));
+ }
+ $typestr = $othervalue;
+ } else {
+ $typestr = $othervalue;
+ }
+ $latesttypes[$newnum] = $typedom.':'.$typestr;
+ $newnum ++ ;
+ }
+ }
+ my $selfenroll_types = join(';',@latesttypes);
+ if ($selfenroll_types ne $curr_types) {
+ $changes{'internal.selfenroll_types'} = $selfenroll_types;
+ }
+ }
} else {
my $curr_val =
$env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
my $newval = $env{'form.selfenroll_'.$item};
if ($item eq 'section') {
$newval = $env{'form.sections'};
- if (grep(/^\Q$newval\E$/,keys(%{$groupslist}))) {
+ if (defined($curr_groups{$newval})) {
$newval = $curr_val;
$warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').' '.&mt('Group names and section names must be distinct');
} elsif ($newval eq 'all') {
@@ -3934,7 +4630,7 @@ sub update_selfenroll_config {
if ($newval ne $curr_val) {
$changes{'internal.selfenroll_'.$item} = $newval;
}
- }
+ }
}
if (keys(%warning) > 0) {
foreach my $item (@{$row}) {
@@ -3974,7 +4670,7 @@ sub update_selfenroll_config {
foreach my $type ('start','end') {
if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
- $r->print(''.&mt('[_1]: [_2] set to "[_3]".',
+ $r->print(' '.&mt('[_1]: "[_2]" set to "[_3]".',
$title,$type,$newdate).' ');
}
}
@@ -3982,14 +4678,27 @@ sub update_selfenroll_config {
foreach my $type ('start','end') {
if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
- $r->print(''.&mt('[_1]: [_2] set to "[_3]".',
+ $r->print(' '.&mt('[_1]: "[_2]" set to "[_3]".',
$title,$type,$newdate).' ');
}
}
} else {
if (exists($changes{'internal.selfenroll_'.$item})) {
- $r->print(''.&mt('[_1] set to "[_2]".',$title,
- $changes{'internal.selfenroll_'.$item}).' '."\n");
+ my $newval = $changes{'internal.selfenroll_'.$item};
+ if ($item eq 'types') {
+ if ($newval eq '') {
+ $newval = &mt('None');
+ } elsif ($newval eq '*') {
+ $newval = &mt('Any user in any domain');
+ }
+ } elsif ($item eq 'registered') {
+ if ($newval eq '1') {
+ $newval = &mt('Yes');
+ } elsif ($newval eq '0') {
+ $newval = &mt('No');
+ }
+ }
+ $r->print(''.&mt('"[_1]" set to "[_2]".',$title,$newval).' '."\n");
}
}
}
@@ -4003,10 +4712,10 @@ sub update_selfenroll_config {
$r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').' '.&mt('The error was: [_1].',$putresult));
}
} else {
- $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
+ $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
}
} else {
- $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
+ $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
}
return;
}
@@ -4014,12 +4723,11 @@ sub update_selfenroll_config {
sub get_selfenroll_titles {
my @row = ('types','registered','enroll_dates','access_dates','section');
my %lt = &Apache::lonlocal::texthash (
- selfenroll => 'Self-enrollment with a student role',
types => 'Users allowed to self-enroll in this course',
- registered => 'Restrict self-enrollment to registered students?',
+ registered => 'Restrict self-enrollment to students officially registered for the course',
enroll_dates => 'Dates self-enrollment available',
- access_dates => 'Access dates for self-enrolled users',
- section => 'Section',
+ access_dates => 'Course access dates for self-enrolled users',
+ section => 'Section assigned to self-enrolled users',
);
return (\@row,\%lt);
}