--- loncom/interface/loncreateuser.pm 2008/05/29 04:10:50 1.240
+++ loncom/interface/loncreateuser.pm 2008/06/03 01:13:27 1.241
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.240 2008/05/29 04:10:50 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.241 2008/06/03 01:13:27 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2981,7 +2981,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
@@ -2989,7 +2989,8 @@ 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') {
@@ -3178,8 +3179,10 @@ sub print_selfenroll_menu {
$setsec_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.') | ';
+ 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);
+ if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+ $output .= '';
+ }
+ return $output;
+}
+
sub selfenroll_date_forms {
my ($startform,$endform) = @_;
my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
@@ -4138,13 +4260,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') {
@@ -4165,13 +4287,47 @@ 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;
+ }
+ } elsif ($curr_types eq '') {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_0');
+ if (@types > 0) {
+ $changes{'internal.selfenroll_types'} = $env{'form.selfenroll_dom_0'}.':'.join(',',@types);
+ }
+ } else {
+ my @entries = split(/;/,$curr_types);
+ my $num = 0;
+ my @latesttypes;
+ my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
+ my $newnum = 0;
+ for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
+ if (!grep(/^$j$/,@deletedoms)) {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
+ @types = sort(@types);
+ my $typestr = join(',',@types);
+ $latesttypes[$newnum] = $env{'form.selfenroll_dom_'.$j}.':'.$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') {
@@ -4185,7 +4341,7 @@ sub update_selfenroll_config {
if ($newval ne $curr_val) {
$changes{'internal.selfenroll_'.$item} = $newval;
}
- }
+ }
}
if (keys(%warning) > 0) {
foreach my $item (@{$row}) {
@@ -4239,8 +4395,15 @@ sub update_selfenroll_config {
}
} 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');
+ }
+ }
+ $r->print(''.&mt('[_1] set to "[_2]".',$title,$newval).''."\n");
}
}
}
@@ -4259,18 +4422,20 @@ sub update_selfenroll_config {
} else {
$r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
}
+ if ($env{'form.selfenroll_newdom'} ne '') {
+ &print_selfenroll_menu($r,$context,$permission);
+ }
return;
}
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?',
enroll_dates => 'Dates self-enrollment available',
access_dates => 'Access dates for self-enrolled users',
- section => 'Section',
+ section => 'Section assigned to self-enrolled users',
);
return (\@row,\%lt);
}