[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm
raeburn
raeburn@source.lon-capa.org
Tue, 03 Feb 2009 05:28:00 -0000
This is a MIME encoded message
--raeburn1233638880
Content-Type: text/plain
raeburn Tue Feb 3 05:28:00 2009 EDT
Modified files:
/loncom/interface loncreateuser.pm
Log:
- Bug 5558.
- Course Coordinators can set an enrollment limit, which when reached will prevent new self-enrollments.
- Course Coordinators can require all self-enrollment requests to be approved, and can specify which CCs should be notified when a self-enrollment request needs to be approved.
--raeburn1233638880
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090203052800.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.275 loncom/interface/loncreateuser.pm:1.276
--- loncom/interface/loncreateuser.pm:1.275 Mon Feb 2 00:12:01 2009
+++ loncom/interface/loncreateuser.pm Tue Feb 3 05:28:00 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.275 2009/02/02 00:12:01 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.276 2009/02/03 05:28:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3952,6 +3952,95 @@
'<input type="hidden" name="sections" value="" />'."\n".
'<input type="hidden" name="state" value="done" />'."\n".
'</td></tr></table>'."\n";
+ } elsif ($item eq 'approval') {
+ my ($appon,$appoff);
+ my $cid = $env{'request.course.id'};
+ my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
+ if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
+ $appon = ' checked="checked" ';
+ $appoff = ' ';
+ } else {
+ $appon = ' ';
+ $appoff = ' checked="checked" ';
+ }
+ $output .= '<label>'.
+ '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'.
+ &mt('Yes').'</label> <label>'.
+ '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'.
+ &mt('No').'</label>';
+ my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
+ my (@ccs,%notified);
+ if ($advhash{'cc'}) {
+ @ccs = split(/,/,$advhash{'cc'});
+ }
+ if ($currnotified) {
+ foreach my $current (split(/,/,$currnotified)) {
+ $notified{$current} = 1;
+ if (!grep(/^\Q$current\E$/,@ccs)) {
+ push(@ccs,$current);
+ }
+ }
+ }
+ if (@ccs) {
+ $output .= '<br />'.&mt('Personnel to be notified when a self-enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row();
+ my $count = 0;
+ my $numcols = 4;
+ foreach my $cc (sort(@ccs)) {
+ my $notifyon;
+ my ($ccuname,$ccudom) = split(/:/,$cc);
+ if ($notified{$cc}) {
+ $notifyon = ' checked="checked" ';
+ }
+ if ($count && !$count%$numcols) {
+ $output .= &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row()
+ }
+ $output .= '<td><span class="LC_nobreak"><label>'.
+ '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
+ &Apache::loncommon::plainname($ccuname,$ccudom).
+ '</label></span></td>';
+ $count;
+ }
+ my $rem = $count%$numcols;
+ if ($rem) {
+ my $emptycols = $numcols - $rem;
+ for (my $i=0; $i<$emptycols; $i++) {
+ $output .= '<td> </td>';
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ }
+ } elsif ($item eq 'limit') {
+ my ($crslimit,$selflimit,$nolimit);
+ my $cid = $env{'request.course.id'};
+ my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
+ my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
+ my $nolimit = ' checked="checked" ';
+ if ($currlim eq 'allstudents') {
+ $crslimit = ' checked="checked" ';
+ $selflimit = ' ';
+ $nolimit = ' ';
+ } elsif ($currlim eq 'selfenrolled') {
+ $crslimit = ' ';
+ $selflimit = ' checked="checked" ';
+ $nolimit = ' ';
+ } else {
+ $crslimit = ' ';
+ $selflimit = ' ';
+ }
+ $output .= '<table><tr><td><label>'.
+ '<input type="radio" name="selfenroll_limit" value="0"'.$nolimit.'/>'.
+ &mt('No limit').'</label></td><td><label>'.
+ '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
+ &mt('Limit by total students').'</label></td><td><label>'.
+ '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
+ &mt('Limit by total self-enrolled students').
+ '</td></tr><tr>'.
+ '<td> </td><td colspan="2"><span class="LC_nobreak">'.
+ (' 'x3).&mt('Maximum number allowed: ').
+ '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
}
$output .= &Apache::lonhtmlcommon::row_closure(1);
}
@@ -5159,6 +5248,74 @@
$changes{'internal.selfenroll_types'} = $selfenroll_types;
}
}
+ } elsif ($item eq 'limit') {
+ my $newlimit = $env{'form.selfenroll_limit'};
+ my $newcap = $env{'form.selfenroll_cap'};
+ $newcap =~s/\s+//g;
+ my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
+ $currlimit = 'none' if ($currlimit eq '');
+ my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
+ if ($newlimit ne $currlimit) {
+ if ($newlimit ne 'none') {
+ if ($newcap =~ /^\d+$/) {
+ if ($newcap ne $currcap) {
+ $changes{'internal.selfenroll_cap'} = $newcap;
+ }
+ $changes{'internal.selfenroll_limit'} = $newlimit;
+ } else {
+ $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
+ }
+ } elsif ($currcap ne '') {
+ $changes{'internal.selfenroll_cap'} = '';
+ $changes{'internal.selfenroll_limit'} = $newlimit;
+ }
+ } elsif ($currlimit ne 'none') {
+ if ($newcap =~ /^\d+$/) {
+ if ($newcap ne $currcap) {
+ $changes{'internal.selfenroll_cap'} = $newcap;
+ }
+ } else {
+ $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
+ }
+ }
+ } elsif ($item eq 'approval') {
+ my (@currnotified,@newnotified);
+ my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
+ my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
+ if ($currnotifylist ne '') {
+ @currnotified = split(/,/,$currnotifylist);
+ @currnotified = sort(@currnotified);
+ }
+ my $newapproval = $env{'form.selfenroll_approval'};
+ @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
+ @newnotified = sort(@newnotified);
+ if ($newapproval ne $currapproval) {
+ $changes{'internal.selfenroll_approval'} = $newapproval;
+ if (!$newapproval) {
+ if ($currnotifylist ne '') {
+ $changes{'internal.selfenroll_notifylist'} = '';
+ }
+ } else {
+ my @differences =
+ &compare_arrays(\@currnotified,\@newnotified);
+ if (@differences > 0) {
+ if (@newnotified > 0) {
+ $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
+ } else {
+ $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
+ }
+ }
+ }
+ } else {
+ my @differences = &compare_arrays(\@currnotified,\@newnotified);
+ if (@differences > 0) {
+ if (@newnotified > 0) {
+ $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
+ } else {
+ $changes{'internal.selfenroll_notifylist'} = '';
+ }
+ }
+ }
} else {
my $curr_val =
$env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
@@ -5231,6 +5388,62 @@
$title,$type,$newdate).'</li>');
}
}
+ } elsif ($item eq 'limit') {
+ if ((exists($changes{'internal.selfenroll_limit'})) ||
+ (exists($changes{'internal.selfenroll_cap'}))) {
+ my ($newval,$newcap);
+ if ($changes{'internal.selfenroll_cap'} ne '') {
+ $newcap = $changes{'internal.selfenroll_cap'}
+ } else {
+ $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
+ }
+ if ($changes{'internal.selfenroll_limit'} eq 'none') {
+ $newval = &mt('No limit');
+ } elsif ($changes{'internal.selfenroll_limit'} eq
+ 'allstudents') {
+ $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
+ } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
+ $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
+ } else {
+ my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'};
+ if ($currlimit eq 'allstudents') {
+ $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
+ } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
+ $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap);
+ }
+ }
+ $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
+ }
+ } elsif ($item eq 'approval') {
+ if ((exists($changes{'internal.selfenroll_approval'})) ||
+ (exists($changes{'internal.selfenroll_notifylist'}))) {
+ my ($newval,$newnotify);
+ if (exists($changes{'internal.selfenroll_notifylist'})) {
+ $newnotify = $changes{'internal.selfenroll_notifylist'};
+ } else {
+ $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
+ }
+ if ($changes{'internal.selfenroll_approval'}) {
+ $newval = &mt('Yes');
+ } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
+ $newval = &mt('No');
+ } else {
+ my $currapproval =
+ $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
+ if ($currapproval) {
+ $newval = &mt('Yes');
+ } else {
+ $newval = &mt('No');
+ }
+ }
+ $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
+ if ($newnotify) {
+ $r->print('<br />'.&mt('The following will be notified when a self-enrollment request needs approval, or has been approved: [_1].',$newnotify));
+ } else {
+ $r->print('<br />'.&mt('No notifications sent when a self-enrollment request needs approval, or has been approved.'));
+ }
+ $r->print('</li>'."\n");
+ }
} else {
if (exists($changes{'internal.selfenroll_'.$item})) {
my $newval = $changes{'internal.selfenroll_'.$item};
@@ -5284,14 +5497,33 @@
return;
}
+sub compare_arrays {
+ my ($arrayref1,$arrayref2) = @_;
+ my (@difference,%count);
+ @difference = ();
+ %count = ();
+ if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
+ foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
+ foreach my $element (keys(%count)) {
+ if ($count{$element} == 1) {
+ push(@difference,$element);
+ }
+ }
+ }
+ return @difference;
+}
+
sub get_selfenroll_titles {
- my @row = ('types','registered','enroll_dates','access_dates','section');
+ my @row = ('types','registered','enroll_dates','access_dates','section',
+ 'approval','limit');
my %lt = &Apache::lonlocal::texthash (
types => 'Users allowed to self-enroll in this course',
registered => 'Restrict self-enrollment to students officially registered for the course',
enroll_dates => 'Dates self-enrollment available',
access_dates => 'Course access dates assigned to self-enrolling users',
section => 'Section assigned to self-enrolling users',
+ approval => 'Self-enrollment requests need approval?',
+ limit => 'Enrollment limit',
);
return (\@row,\%lt);
}
--raeburn1233638880--