[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonmodifycourse.pm selfenroll.pm

raeburn raeburn at source.lon-capa.org
Sun Mar 30 22:31:05 EDT 2014


raeburn		Mon Mar 31 02:31:05 2014 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm lonmodifycourse.pm selfenroll.pm 
  Log:
  - Where a course is set for configuration of one or more self-enrollment
    settings by a DC instead of by course personnel, DC's modify course 
    menu includes access to self-enrollment configuration.
  - Self-enrollment supports option to queue request, pending validation
    by external site (e.g., separate payment site for e-commerce).
  - &get_selfenroll_titles() removed from loncreateuser.pm (use subroutine
    in lonuserutils.pm instead). 
  
  
-------------- next part --------------
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.397 loncom/interface/loncreateuser.pm:1.398
--- loncom/interface/loncreateuser.pm:1.397	Wed Mar 26 18:18:24 2014
+++ loncom/interface/loncreateuser.pm	Mon Mar 31 02:31:05 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.397 2014/03/26 18:18:24 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.398 2014/03/31 02:31:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4975,25 +4975,48 @@
                      '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'); 
         }
     } elsif ($env{'form.action'} eq 'selfenroll') {
-        push(@{$brcrum},
-                {href => '/adm/createuser?action=selfenroll',
-                 text => "Configure Self-enrollment",
-                 help => 'Course_Self_Enrollment'});
-        if (!exists($env{'form.state'})) {
-            $args = { bread_crumbs           => $brcrum,
-                      bread_crumbs_component => 'Configure Self-enrollment'};
-            $r->print(&header(undef,$args));
-            $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
-            &print_selfenroll_menu($r,$context,$permission);
-        } elsif ($env{'form.state'} eq 'done') {
-            push (@{$brcrum},
-                      {href=>'/adm/createuser?action=selfenroll',
-                       text=>"Result"});
-            $args = { bread_crumbs           => $brcrum,
-                      bread_crumbs_component => 'Self-enrollment result'};
-            $r->print(&header(undef,$args));
-            $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
-            &update_selfenroll_config($r,$context,$permission);
+        if ($permission->{selfenrolladmin}) {
+            my $cid = $env{'request.course.id'};
+            my $cdom = $env{'course.'.$cid.'.domain'};
+            my $cnum = $env{'course.'.$cid.'.num'};
+            my %currsettings = (
+                selfenroll_types              => $env{'course.'.$cid.'.internal.selfenroll_types'},
+                selfenroll_registered         => $env{'course.'.$cid.'.internal.selfenroll_registered'},
+                selfenroll_section            => $env{'course.'.$cid.'.internal.selfenroll_section'},
+                selfenroll_notifylist         => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
+                selfenroll_approval           => $env{'course.'.$cid.'.internal.selfenroll_approval'},
+                selfenroll_limit              => $env{'course.'.$cid.'.internal.selfenroll_limit'},
+                selfenroll_cap                => $env{'course.'.$cid.'.internal.selfenroll_cap'},
+                selfenroll_start_date         => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
+                selfenroll_end_date           => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
+                selfenroll_start_access       => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
+                selfenroll_end_access         => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
+                default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
+                default_enrollment_end_date   => $env{'course.'.$cid.'.default_enrollment_end_date'},
+            );
+            push(@{$brcrum},
+                    {href => '/adm/createuser?action=selfenroll',
+                     text => "Configure Self-enrollment",
+                     help => 'Course_Self_Enrollment'});
+            if (!exists($env{'form.state'})) {
+                $args = { bread_crumbs           => $brcrum,
+                          bread_crumbs_component => 'Configure Self-enrollment'};
+                $r->print(&header(undef,$args));
+                $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
+                &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
+            } elsif ($env{'form.state'} eq 'done') {
+                push (@{$brcrum},
+                          {href=>'/adm/createuser?action=selfenroll',
+                           text=>"Result"});
+                $args = { bread_crumbs           => $brcrum,
+                          bread_crumbs_component => 'Self-enrollment result'};
+                $r->print(&header(undef,$args));
+                $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
+                &update_selfenroll_config($r,$cid,$cdom,$cnum,\%currsettings);
+            }
+        } else {
+            $r->print(&header(undef,{'no_nav_bar' => 1}).
+                     '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
         }
     } elsif ($env{'form.action'} eq 'selfenrollqueue') {
         push(@{$brcrum},
@@ -5443,12 +5466,12 @@
         );
         if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
             push(@{ $menu[2]->{items} },
-                    {   
+                    {
                      linktext => 'Enrollment Requests',
                      icon => 'selfenrl-queue.png',
                      #help => 'Course_Approve_Selfenroll',
                      url => '/adm/createuser?action=selfenrollqueue',
-                     permission => $permission->{'cusr'},
+                     permission => $permission->{'selfenrolladmin'},
                      linktitle =>'Approve or reject enrollment requests.',
                     },
             );
@@ -5474,7 +5497,7 @@
                  icon => 'self_enroll.png',
                  #help => 'Course_Self_Enrollment',
                  url => '/adm/createuser?action=selfenroll',
-                 permission => $permission->{'cusr'},
+                 permission => $permission->{'selfenrolladmin'},
                  linktitle => 'Configure user self-enrollment.',
                 },
             );
@@ -5511,11 +5534,11 @@
 }
 
 sub print_selfenroll_menu {
-    my ($r,$context,$permission) = @_;
+    my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_;
     my $crstype = &Apache::loncommon::course_type();
-    my $formname = 'enrollstudent';
+    my $formname = 'selfenroll';
     my $nolink = 1;
-    my ($row,$lt) = &get_selfenroll_titles();
+    my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
     my $groupslist = &Apache::lonuserutils::get_groupslist();
     my $setsec_js = 
         &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
@@ -5634,7 +5657,7 @@
             }
         } else {
             if (document.$formname.selfenroll_activate.checked) {
-                var num = document.enrollstudent.selfenroll_activate.value;
+                var num = document.$formname.selfenroll_activate.value;
                 countfail = check_types(num,countfail,needaction)
             }
         }
@@ -5681,6 +5704,26 @@
     return countfail;
 }
 
+function toggleNotify() {
+    var selfenrollApproval = 0;
+    if (document.$formname.selfenroll_approval.length) {
+        for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
+            if (document.$formname.selfenroll_approval[i].checked) {
+                selfenrollApproval = document.$formname.selfenroll_approval[i].value;
+                break;        
+            }
+        }
+    }
+    if (document.getElementById('notified')) {
+        if (selfenrollApproval == 0) {
+            document.getElementById('notified').style.display='none';
+        } else {
+            document.getElementById('notified').style.display='block';
+        }
+    }
+    return;
+}
+
 function getIndexByName(item) {
     for (var i=0;i<document.$formname.elements.length;i++) {
         if (document.$formname.elements[i].name == item) {
@@ -5690,8 +5733,6 @@
     return -1;
 }
 ENDSCRIPT
-    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 
     my $output = '<script type="text/javascript">'."\n".
                  '// <![CDATA['."\n".
@@ -5717,7 +5758,11 @@
             $output .= '</p>';
         }
     }
-    $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
+    my $actionhref = '/adm/createuser';
+    if ($context eq 'domain') {
+        $actionhref = '/adm/modifycourse';
+    }
+    $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
                &Apache::lonhtmlcommon::start_pick_box();
     if (ref($row) eq 'ARRAY') {
         foreach my $item (@{$row}) {
@@ -5727,7 +5772,10 @@
             }
             $output .= &Apache::lonhtmlcommon::row_title($title);
             if ($item eq 'types') {
-                my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
+                my $curr_types;
+                if (ref($currsettings) eq 'HASH') {
+                    $curr_types = $currsettings->{'selfenroll_types'};
+                }
                 my $showdomdesc = 1;
                 my $includeempty = 1;
                 my $num = 0;
@@ -5792,7 +5840,11 @@
                            .&Apache::loncommon::end_data_table();
             } elsif ($item eq 'registered') {
                 my ($regon,$regoff);
-                if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
+                my $registered;
+                if (ref($currsettings) eq 'HASH') {
+                    $registered = $currsettings->{'selfenroll_registered'};
+                }
+                if ($registered) {
                     $regon = ' checked="checked" ';
                     $regoff = ' ';
                 } else {
@@ -5805,13 +5857,16 @@
                            '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
                            &mt('No').'</label>';
             } elsif ($item eq 'enroll_dates') {
-                my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'};
-                my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'};
-                if ($starttime eq '') {
-                    $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
-                }
-                if ($endtime eq '') {
-                    $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
+                my ($starttime,$endtime);
+                if (ref($currsettings) eq 'HASH') {
+                    $starttime = $currsettings->{'selfenroll_start_date'};
+                    $endtime = $currsettings->{'selfenroll_end_date'};
+                    if ($starttime eq '') {
+                        $starttime = $currsettings->{'default_enrollment_start_date'};
+                    }
+                    if ($endtime eq '') {
+                        $endtime = $currsettings->{'default_enrollment_end_date'};
+                    }
                 }
                 my $startform =
                     &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
@@ -5821,13 +5876,16 @@
                                       undef,undef,undef,undef,undef,undef,undef,$nolink);
                 $output .= &selfenroll_date_forms($startform,$endform);
             } elsif ($item eq 'access_dates') {
-                my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'};
-                my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'};
-                if ($starttime eq '') {
-                    $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
-                }
-                if ($endtime eq '') {
-                    $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
+                my ($starttime,$endtime);
+                if (ref($currsettings) eq 'HASH') {
+                    $starttime = $currsettings->{'selfenroll_start_access'};
+                    $endtime = $currsettings->{'selfenroll_end_access'};
+                    if ($starttime eq '') {
+                        $starttime = $currsettings->{'default_enrollment_start_date'};
+                    }
+                    if ($endtime eq '') {
+                        $endtime = $currsettings->{'default_enrollment_end_date'};
+                    }
                 }
                 my $startform =
                     &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
@@ -5837,7 +5895,10 @@
                                       undef,undef,undef,undef,undef,undef,undef,$nolink);
                 $output .= &selfenroll_date_forms($startform,$endform);
             } elsif ($item eq 'section') {
-                my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'}; 
+                my $currsec;
+                if (ref($currsettings) eq 'HASH') {
+                    $currsec = $currsettings->{'selfenroll_section'};
+                }
                 my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                 my $newsecval;
                 if ($currsec ne 'none' && $currsec ne '') {
@@ -5857,21 +5918,22 @@
                            '<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" ';
+                my ($currnotified,$currapproval,%appchecked);
+                my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
+                if (ref($currsettings) eq 'HASH') { 
+                    $currnotified = $currsettings->{'selfenroll_notifylist'};
+                    $currapproval = $currsettings->{'selfenroll_approval'};
+                }
+                if ($currapproval !~ /^[012]$/) {
+                    $currapproval = 0;
+                }
+                $appchecked{$currapproval} = ' checked="checked"';
+                for my $i (0..2) {
+                    $output .= '<label>'.
+                               '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
+                               $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}.
+                               '</label>'.(' 'x2);
                 }
-                $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);
                 my $ccrole = 'cc';
@@ -5890,7 +5952,13 @@
                     }
                 }
                 if (@ccs) {
-                    $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
+                    my $style;
+                    unless ($currapproval) {
+                        $style = ' style="display: none;"'; 
+                    }
+                    $output .= '<br /><div id="notified"'.$style.'>'.
+                               &mt('Personnel to be notified when an 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;
@@ -5918,14 +5986,15 @@
                         }
                     }
                     $output .= &Apache::loncommon::end_data_table_row().
-                               &Apache::loncommon::end_data_table();
+                               &Apache::loncommon::end_data_table().
+                               '</div>';
                 }
             } 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'};
-                $nolimit = ' checked="checked" ';
+                my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
+                if (ref($currsettings) eq 'HASH') {
+                    $currlim = $currsettings->{'selfenroll_limit'};
+                    $currcap = $currsettings->{'selfenroll_cap'};
+                }
                 if ($currlim eq 'allstudents') {
                     $crslimit = ' checked="checked" ';
                     $selflimit = ' ';
@@ -5937,6 +6006,7 @@
                 } else {
                     $crslimit = ' ';
                     $selflimit = ' ';
+                    $nolimit = ' checked="checked" ';
                 }
                 $output .= '<table><tr><td><label>'.
                            '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
@@ -5956,7 +6026,8 @@
     $output .= &Apache::lonhtmlcommon::end_pick_box().
                '<br /><input type="button" name="selfenrollconf" value="'
                .&mt('Save').'" onclick="validate_types(this.form);" />'
-               .'<input type="hidden" name="action" value="selfenroll" /></form>';
+               .'<input type="hidden" name="action" value="selfenroll" />'.
+               $additional.'</form>';
     $r->print($output);
     return;
 }
@@ -5966,10 +6037,10 @@
     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
     my ($cathash,%settable, at vismsgs,$cansetvis);
     my %visactions = &Apache::lonlocal::texthash(
-                   vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
+                   vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
                    gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
-                   miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
-                   yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
+                   miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
+                   yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
                    coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
                    make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
                    take => 'Take the following action to ensure the course appears in the Catalog:',
@@ -7265,19 +7336,18 @@
 }
 
 sub update_selfenroll_config {
-    my ($r,$context,$permission) = @_;
-    my ($row,$lt) = &get_selfenroll_titles();
-    my %curr_groups = &Apache::longroup::coursegroups();
+    my ($r,$cid,$cdom,$cnum,$currsettings) = @_;
+    return unless (ref($currsettings) eq 'HASH');
+    my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
+    my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
     my (%changes,%warning);
-    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
     my $curr_types;
     if (ref($row) eq 'ARRAY') {
         foreach my $item (@{$row}) {
             if ($item eq 'enroll_dates') {
                 my (%currenrolldate,%newenrolldate);
                 foreach my $type ('start','end') {
-                    $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'};
+                    $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
                     $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
                     if ($newenrolldate{$type} ne $currenrolldate{$type}) {
                         $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
@@ -7286,15 +7356,14 @@
             } elsif ($item eq 'access_dates') {
                 my (%currdate,%newdate);
                 foreach my $type ('start','end') {
-                    $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'};
+                    $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
                     $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
                     if ($newdate{$type} ne $currdate{$type}) {
                         $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
                     }
                 }
             } elsif ($item eq 'types') {
-                $curr_types =
-                    $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
+                $curr_types = $currsettings->{'selfenroll_'.$item};
                 if ($env{'form.selfenroll_all'}) {
                     if ($curr_types ne '*') {
                         $changes{'internal.selfenroll_types'} = '*';
@@ -7363,9 +7432,9 @@
                 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'};
+                my $currlimit =  $currsettings->{'selfenroll_limit'};
                 $currlimit = 'none' if ($currlimit eq '');
-                my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
+                my $currcap = $currsettings->{'selfenroll_cap'};
                 if ($newlimit ne $currlimit) {
                     if ($newlimit ne 'none') {
                         if ($newcap =~ /^\d+$/) {
@@ -7374,7 +7443,8 @@
                             }
                             $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.'); 
+                            $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'} = '';
@@ -7386,13 +7456,14 @@
                             $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.');
+                        $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, at newnotified);
-                my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
-                my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'};
+                my $currapproval = $currsettings->{'selfenroll_approval'};
+                my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
                 if ($currnotifylist ne '') {
                     @currnotified = split(/,/,$currnotifylist);
                     @currnotified = sort(@currnotified);
@@ -7428,14 +7499,14 @@
                     }
                 }
             } else {
-                my $curr_val = 
-                    $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
+                my $curr_val = $currsettings->{'selfenroll_'.$item};
                 my $newval = $env{'form.selfenroll_'.$item};
                 if ($item eq 'section') {
                     $newval = $env{'form.sections'};
                     if (defined($curr_groups{$newval})) {
                         $newval = $curr_val;
-                        $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
+                        $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
+                                          &mt('Group names and section names must be distinct');
                     } elsif ($newval eq 'all') {
                         $newval = $curr_val;
                         $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
@@ -7465,11 +7536,10 @@
                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
                                                                 $cnum,undef,undef,'Course');
                     my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
-                    if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
+                    if (ref($crsinfo{$cid}) eq 'HASH') {
                         foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
                             if (exists($changes{'internal.'.$item})) {
-                                $crsinfo{$env{'request.course.id'}}{$item} = 
-                                    $changes{'internal.'.$item};
+                                $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
                             }
                         }
                         my $crsputresult =
@@ -7506,7 +7576,7 @@
                             if ($changes{'internal.selfenroll_cap'} ne '') {
                                 $newcap = $changes{'internal.selfenroll_cap'}
                             } else {
-                                $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'};
+                                $newcap = $currsettings->{'selfenroll_cap'};
                             }
                             if ($changes{'internal.selfenroll_limit'} eq 'none') {
                                 $newval = &mt('No limit');
@@ -7516,7 +7586,7 @@
                             } 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'};
+                                my $currlimit =  $currsettings->{'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') {
@@ -7528,24 +7598,24 @@
                     } elsif ($item eq 'approval') {
                         if ((exists($changes{'internal.selfenroll_approval'})) ||
                             (exists($changes{'internal.selfenroll_notifylist'}))) {
+                            my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
                             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'};
+                                $newnotify = $currsettings->{'selfenroll_notifylist'};
                             }
-                            if ($changes{'internal.selfenroll_approval'}) {
-                                $newval = &mt('Yes');
-                            } elsif ($changes{'internal.selfenroll_approval'} eq '0') {
-                                $newval = &mt('No');
+                            if (exists($changes{'internal.selfenroll_approval'})) {
+                                if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
+                                    $changes{'internal.selfenroll_approval'} = '0';
+                                }
+                                $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
                             } else {
-                                my $currapproval = 
-                                    $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'};
-                                if ($currapproval) {
-                                    $newval = &mt('Yes');
-                                } else {
-                                    $newval = &mt('No');
+                                my $currapproval = $currsettings->{'selfenroll_approval'}; 
+                                if ($currapproval !~ /^[012]$/) {
+                                    $currapproval = 0;
                                 }
+                                $newval = $selfdescs{'approval'}{$currapproval};
                             }
                             $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
                             if ($newnotify) {
@@ -7576,13 +7646,16 @@
                     }
                 }
                 $r->print('</ul>');
-                my %newenvhash;
-                foreach my $key (keys(%changes)) {
-                    $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key};
+                if ($env{'course.'.$cid.'.description'} ne '') {
+                    my %newenvhash;
+                    foreach my $key (keys(%changes)) {
+                        $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
+                    }
+                    &Apache::lonnet::appenv(\%newenvhash);
                 }
-                &Apache::lonnet::appenv(\%newenvhash);
             } else {
-                $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult));
+                $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
+                          &mt('The error was: [_1].',$putresult));
             }
         } else {
             $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
@@ -7608,21 +7681,6 @@
     return;
 }
 
-sub get_selfenroll_titles {
-    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);
-}
-
 #---------------------------------------------- end functions for &phase_two
 
 #--------------------------------- functions for &phase_two and &phase_three
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.71 loncom/interface/lonmodifycourse.pm:1.72
--- loncom/interface/lonmodifycourse.pm:1.71	Mon Mar 31 01:37:28 2014
+++ loncom/interface/lonmodifycourse.pm	Mon Mar 31 02:31:05 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.71 2014/03/31 01:37:28 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.72 2014/03/31 02:31:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -34,16 +34,17 @@
 use Apache::lonhtmlcommon;
 use Apache::lonlocal;
 use Apache::lonuserutils;
+use Apache::loncreateuser;
 use Apache::lonpickcourse;
 use lib '/home/httpd/lib/perl';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
 
 sub get_dc_settable {
     my ($type,$cdom) = @_;
     if ($type eq 'Community') {
-        return ('courseowner');
+        return ('courseowner','selfenrollmgrdc','selfenrollmgrcc');
     } else {
-        my @items = ('courseowner','coursecode','authtype','autharg');
+        my @items = ('courseowner','coursecode','authtype','autharg','selfenrollmgrdc','selfenrollmgrcc');
         if (&showcredits($cdom)) {
             push(@items,'defaultcredits');
         }
@@ -122,6 +123,8 @@
                 if (&showcredits($cdom)) {
                     $enrollvar{$type} = $settings{$item};
                 }
+            } elsif ($type eq 'selfenrollmgr') {
+                $enrollvar{$type} = $settings{$item};    
             } elsif ($type eq 'courseowner') {
                 if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
                     $enrollvar{$type} = $settings{$item};
@@ -252,9 +255,9 @@
         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
         $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
         if (&showcredits($dom)) {
-            $setparams_text = 'View/Modify course owner, institutional code, and default authentication and credits';
+            $setparams_text = 'View/Modify course owner, institutional code, default authentication, credits, and self-enrollment';
         } else {
-            $setparams_text = 'View/Modify course owner, institutional code, and default authentication';
+            $setparams_text = 'View/Modify course owner, institutional code, default authentication, and self-enrollment';
         }
         $cat_text = 'View/Modify catalog settings for course';
     }
@@ -263,6 +266,17 @@
     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
     my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
 
+    sub manage_selfenrollment {
+        my ($cdom,$cnum,$type,$coursehash) = @_;
+        my ($managed_by_cc,$managed_by_dc) = &Apache::lonuserutils::selfenrollment_administration($cdom,$cnum,$type,$coursehash);
+        if (ref($managed_by_dc) eq 'ARRAY') {
+            if (@{$managed_by_dc}) {
+                return 1;
+            } 
+        }
+        return 0;
+    }
+
     sub phaseurl {
         my $phase = shift;
         return "javascript:changePage(document.menu,'$phase')"
@@ -310,6 +324,14 @@
                 icon => 'roles.png',
                 linktitle => ''
             },
+            {
+                linktext => 'View/Modify Self-Enrollment configuration',
+                icon => 'self_enroll.png',
+                #help => 'Course_Self_Enrollment',
+                url => &phaseurl('selfenroll'),
+                permission => &manage_selfenrollment($cdom,$cnum,$type,$coursehash),
+                linktitle => 'Configure user self-enrollment.',
+            },
         ]
         },
         );
@@ -326,16 +348,18 @@
     }
     $menu_html .= '</p>'."\n".'<ul>';
     if ($type eq 'Community') {
-        $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>';
+        $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>'."\n".
+                      '<li>'.&mt('Override defaults for who configures self-enrollment for this specific community').'</li>'."\n";
     } else {
-        $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'.
-                       '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>';
+        $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'."\n".
+                       '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>'."\n";
         if (&showcredits($dom)) {
-            $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>';
+            $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>'."\n";
         }
+        $menu_html .= ' <li>'.&mt('Override defaults for who configures self-enrollment for this specific course.').'</li>'."\n";
     }
-    $menu_html .= '<li>'.$setquota_text.'</li>'.
-                  '<li>'.$setuploadquota_text.'</li>'.
+    $menu_html .= '<li>'.$setquota_text.'</li>'."\n".
+                  '<li>'.$setuploadquota_text.'</li>'."\n".
                   '<li>'.$anon_text.'</li>'."\n";
     foreach my $item (@additional_params) {
         if ($type eq 'Community') {
@@ -425,9 +449,9 @@
               '<p>'.$lt{'cose'}.'<ul>'.
               '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',$cctitle,'<a href="'.$escuri.'">','</a>').'</li>');
     if (&showcredits($cdom)) {
-        $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, and default authentication and credits[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
+        $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, credits, and self-enrollment[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
     } else {
-        $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, and default authentication[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
+        $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, and self-enrollment[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
     }
     $r->print('</li></ul></p>'.
               '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
@@ -461,15 +485,8 @@
     }
     if ($uploadquota eq '') {
         my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
-        if ($type eq 'Community') {
-            $uploadquota = $domdefs{$lctype.'quota'};
-        } elsif ($settings{'internal.coursecode'}) {
-            $uploadquota = $domdefs{'officialquota'};
-        } elsif ($settings{'internal.textbook'}) {
-            $uploadquota = $domdefs{'textbookquota'};
-        } else {
-            $uploadquota = $domdefs{'unofficialquota'};
-        }
+        my $quotatype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$type,\%settings);
+        $uploadquota = $domdefs{$quotatype.'quota'};
         if ($uploadquota eq '') {
             $uploadquota = $staticdefaults{'uploadquota'};
         }
@@ -617,7 +634,7 @@
 }
 
 sub print_course_modification_page {
-    my ($r,$cdom,$cnum,$cdesc,$type) = @_;
+    my ($r,$cdom,$cnum,$cdesc,$crstype) = @_;
     my %lt=&Apache::lonlocal::texthash(
             'actv' => "Active",
             'inac' => "Inactive",
@@ -627,17 +644,28 @@
             'stus' => "Status",
             'nocc' => 'There is currently no owner set for this course.',
             'gobt' => "Save",
+            'sett' => 'Setting',
+            'domd' => 'Domain default',
+            'whom' => 'Who configures',  
     );
     my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname);
     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
-    if ($type eq 'Community') {
+    my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
+                                                       'internal.selfenrollmgrdc','internal.selfenrollmgrcc'],
+                                        $cdom,$cnum);
+    my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
+    my @specific_managebydc = split(/,/,$settings{'internal.selfenrollmgrdc'});
+    my @specific_managebycc = split(/,/,$settings{'internal.selfenrollmgrcc'});
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+    my @default_managebydc = split(/,/,$domdefaults{$type.'selfenrolladmdc'});
+    if ($crstype eq 'Community') {
         $ccrole = 'co';
         $lt{'nocc'} = &mt('There is currently no owner set for this community.');
     } else {
         $ccrole ='cc';
         ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar);
     }
-    $ccname = &Apache::lonnet::plaintext($ccrole,$type);
+    $ccname = &Apache::lonnet::plaintext($ccrole,$crstype);
     my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
     my (@local_ccs,%cc_status,%pname);
     foreach my $item (keys(%roleshash)) {
@@ -690,14 +718,14 @@
         }
         $ownertable .= &Apache::loncommon::end_data_table();
     }
-    &print_header($r,$type,$javascript_validations);
+    &print_header($r,$crstype,$javascript_validations);
     my $dctitle = &Apache::lonnet::plaintext('dc');
-    my $mainheader = &modifiable_only_title($type);
+    my $mainheader = &modifiable_only_title($crstype);
     my $hidden_elements = &hidden_form_elements();
     $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
               '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
               &Apache::lonhtmlcommon::start_pick_box());
-    if ($type eq 'Community') {
+    if ($crstype eq 'Community') {
         $r->print(&Apache::lonhtmlcommon::row_title(
                   &Apache::loncommon::help_open_topic('Modify_Community_Owner').
                   ' '.&mt('Community Owner'))."\n");
@@ -705,7 +733,7 @@
         $r->print(&Apache::lonhtmlcommon::row_title(
                       &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
                       ' '.&mt('Course Code'))."\n".
-                  '<input type="text" size="10" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
+                  '<input type="text" size="15" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
                   &Apache::lonhtmlcommon::row_closure());
         if (&showcredits($cdom)) {
             $r->print(&Apache::lonhtmlcommon::row_title(
@@ -723,10 +751,59 @@
                    &Apache::loncommon::help_open_topic('Modify_Course_Owner').
                       ' '.&mt('Course Owner'))."\n");
     }
-    $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure(1).
+    my ($cctitle,$rolename,$currmanages,$ccchecked,$dcchecked,$defaultchecked);
+    my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
+    if ($type eq 'Community') {
+        $cctitle = &mt('Community personnel');
+    } else {
+        $cctitle = &mt('Course personnel');
+    }
+
+    $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure().
+              &Apache::lonhtmlcommon::row_title(
+              &Apache::loncommon::help_open_topic('Modify_Course_Selfenrolladmin').
+                  ' '.&mt('Self-enrollment configuration')).
+              &Apache::loncommon::start_data_table()."\n".
+              &Apache::loncommon::start_data_table_header_row()."\n".
+              '<th>'.$lt{'sett'}.'</th>'.
+              '<th>'.$lt{'domd'}.'</th>'.
+              '<th>'.$lt{'whom'}.'</th>'.
+              &Apache::loncommon::end_data_table_header_row()."\n");
+    my %optionname;
+    $optionname{''} = &mt('Use domain default'); 
+    $optionname{'0'} = $dctitle;
+    $optionname{'1'} = $cctitle;
+    foreach my $item (@{$selfenrollrows}) {
+        my %checked;
+        my $default = $cctitle;
+        if (grep(/^\Q$item\E$/, at default_managebydc)) {
+            $default = $dctitle;
+        }
+        if (grep(/^\Q$item\E$/, at specific_managebydc)) {
+            $checked{'0'} = ' checked="checked"';
+        } elsif (grep(/^\Q$item\E$/, at specific_managebycc)) {
+            $checked{'1'} = ' checked="checked"';
+        } else {
+            $checked{''} = ' checked="checked"';
+        } 
+        $r->print(&Apache::loncommon::start_data_table_row()."\n".
+                 '<td>'.$selfenrolltitles->{$item}.'</td>'."\n".
+                 '<td>'.&mt('[_1] configures',$default).'</td>'."\n".
+                 '<td>');
+        foreach my $option ('','0','1') {  
+            $r->print('<span class="LC_nobreak"><label>'.
+                      '<input type="radio" name="selfenrollmgr_'.$item.'" '.
+                      'value="'.$option.'"'.$checked{$option}.' />'.
+                      $optionname{$option}.'</label></span><br />');
+        }
+        $r->print('</td>'."\n".
+                  &Apache::loncommon::end_data_table_row()."\n");
+    }
+    $r->print(&Apache::loncommon::end_data_table()."\n".
+              '<br />'.&Apache::lonhtmlcommon::row_closure(1).
               &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements.
               '<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
-    if ($type eq 'Community') {
+    if ($crstype eq 'Community') {
         $r->print('this.form.submit();"');
     } else {
         $r->print('javascript:verify_message(this.form);"');
@@ -735,6 +812,61 @@
     return;
 }
 
+sub print_selfenrollconfig {
+    my ($r,$type,$cdesc,$coursehash) = @_;
+    return unless(ref($coursehash) eq 'HASH');
+    my $cnum = $coursehash->{'num'};
+    my $cdom = $coursehash->{'domain'};
+    my %currsettings = &get_selfenroll_settings($coursehash);
+    &print_header($r,$type);
+    $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
+              '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
+    &Apache::loncreateuser::print_selfenroll_menu($r,'domain',$env{'form.pickedcourse'},
+                                                  $cdom,$cnum,\%currsettings,
+                                                  &hidden_form_elements());
+    return;
+}
+
+sub modify_selfenrollconfig {
+    my ($r,$type,$cdesc,$coursehash) = @_;
+    return unless(ref($coursehash) eq 'HASH');
+    my $cnum = $coursehash->{'num'};
+    my $cdom = $coursehash->{'domain'};
+    my %currsettings = &get_selfenroll_settings($coursehash);
+    &print_header($r,$type);
+    $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
+             '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
+    $r->print('<form action="/adm/modifycourse" method="post" name="selfenroll">'."\n".
+              &hidden_form_elements().'<br />');
+    &Apache::loncreateuser::update_selfenroll_config($r,$env{'form.pickedcourse'},
+                                                     $cdom,$cnum,\%currsettings);
+    $r->print('</form>');
+    return;
+}
+
+sub get_selfenroll_settings {
+    my ($coursehash) = @_;
+    my %currsettings;
+    if (ref($coursehash) eq 'HASH') {
+        %currsettings = (
+            selfenroll_types              => $coursehash->{'internal.selfenroll_types'},
+            selfenroll_registered         => $coursehash->{'internal.selfenroll_registered'},
+            selfenroll_section            => $coursehash->{'internal.selfenroll_section'},
+            selfenroll_notifylist         => $coursehash->{'internal.selfenroll_notifylist'},
+            selfenroll_approval           => $coursehash->{'internal.selfenroll_approval'},
+            selfenroll_limit              => $coursehash->{'internal.selfenroll_limit'},
+            selfenroll_cap                => $coursehash->{'internal.selfenroll_cap'},
+            selfenroll_start_date         => $coursehash->{'internal.selfenroll_start_date'},
+            selfenroll_end_date           => $coursehash->{'internal.selfenroll_end_date'},
+            selfenroll_start_access       => $coursehash->{'internal.selfenroll_start_access'},
+            selfenroll_end_access         => $coursehash->{'internal.selfenroll_end_access'},
+            default_enrollment_start_date => $coursehash->{'default_enrollment_start_date'},
+            default_enrollment_end_date   => $coursehash->{'default_enrollment_end_date'},
+        );
+    }
+    return %currsettings;
+}
+
 sub modifiable_only_title {
     my ($type) = @_;
     my $dctitle = &Apache::lonnet::plaintext('dc');
@@ -788,7 +920,9 @@
     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
     my %longtype = &course_settings_descrip($type);
     my @items = ('internal.courseowner','description','internal.co-owners',
-                 'internal.pendingco-owners');
+                 'internal.pendingco-owners','internal.selfenrollmgrdc',
+                 'internal.selfenrollmgrcc');
+    my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
     unless ($type eq 'Community') {
         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
                      'internal.sectionnums','internal.crosslistings'));
@@ -863,8 +997,31 @@
             $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
             $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
         }
+    }
+
+    my @newmgrdc = ();
+    my @newmgrcc = ();
+    my @currmgrdc = split(/,/,$currattr{'selfenrollmgrdc'});
+    my @currmgrcc = split(/,/,$currattr{'selfenrollmgrcc'});
 
+    foreach my $item (@{$selfenrollrows}) {
+        if ($env{'form.selfenrollmgr_'.$item} eq '0') {
+            push(@newmgrdc,$item);
+        } elsif ($env{'form.selfenrollmgr_'.$item} eq '1') {
+            push(@newmgrcc,$item);
+        }
+    }
+
+    $newattr{'selfenrollmgrdc'}=join(',', at newmgrdc);
+    $newattr{'selfenrollmgrcc'}=join(',', at newmgrcc);
+
+    my $cctitle;
+    if ($type eq 'Community') {
+        $cctitle = &mt('Community personnel');
+    } else {
+        $cctitle = &mt('Course personnel');
     }
+    my $dctitle = &Apache::lonnet::plaintext('dc');
 
     if ( exists($env{'form.courseowner'}) ) {
         $newattr{'courseowner'}=$env{'form.courseowner'};
@@ -916,11 +1073,32 @@
             }
             $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
         } else {
+            if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
+                my %newenv;
+                map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes;   
+                &Apache::lonnet::appenv(\%newenv);
+            }
             foreach my $attr (@modifiable_params) {
                 if (grep/^\Q$attr\E$/, at changes) {
-	            $chgresponse .= '<li>'.$longtype{$attr}.' '.&mt('now set to:').' "'.$newattr{$attr}.'".</li>';
+                    my $shown = $newattr{$attr};
+                    if ($attr eq 'selfenrollmgrdc') {
+                        $shown = &selfenroll_config_status(\@newmgrdc,$selfenrolltitles);
+                    } elsif ($attr eq 'selfenrollmgrcc') {
+                        $shown = &selfenroll_config_status(\@newmgrcc,$selfenrolltitles);
+                    } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
+                        $shown = &mt('None');
+                    }
+                    $chgresponse .= '<li>'.&mt('[_1] now set to: [_2]',$longtype{$attr},$shown).'</li>';
                 } else {
-	            $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to:').' "'.$currattr{$attr}.'".</li>';
+                    my $shown = $currattr{$attr};
+                    if ($attr eq 'selfenrollmgrdc') {
+                        $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
+                    } elsif ($attr eq 'selfenrollmgrcc') {
+                        $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
+                    } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
+                        $shown = &mt('None');
+                    }
+                    $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
                 }
             }
             if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
@@ -983,7 +1161,15 @@
         }
     } else {
         foreach my $attr (@modifiable_params) {
-            $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to').' "'.$currattr{$attr}.'".</li>';
+            my $shown = $currattr{$attr};
+            if ($attr eq 'selfenrollmgrdc') {
+                $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
+            } elsif ($attr eq 'selfenrollmgrcc') {
+                $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
+            } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
+                $shown = &mt('None');
+            }
+            $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
         }
     }
 
@@ -1029,6 +1215,23 @@
     return;
 }
 
+sub selfenroll_config_status {
+    my ($items,$selfenrolltitles) = @_;
+    my $shown;
+    if ((ref($items) eq 'ARRAY') && (ref($selfenrolltitles) eq 'HASH')) {
+        if (@{$items} > 0) {
+            $shown = '<ul>';
+            foreach my $item (@{$items}) {
+                $shown .= '<li>'.$selfenrolltitles->{$item}.'</li>';
+            }
+            $shown .= '</ul>';
+        } else {
+            $shown = &mt('None');
+        }
+    }
+    return $shown;
+}
+
 sub update_coowners {
     my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
     return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
@@ -1314,6 +1517,12 @@
                            );
                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
                                                     $cnum);
+                if ($putreply eq 'ok') {
+                    if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
+                        &Apache::lonnet::appenv(
+                           {'course.'.$cdom.'_'.$cnum.'.internal.anonsurvey_threshold' => $env{'form.threshold'}});
+                    }
+                }
                 if (($oldsettings{'internal.anonsurvey_threshold'} eq '') &&
                     ($env{'form.threshold'} == $defaultthreshold)) {
                     $r->print(&mt('The responder threshold for display of anonymous survey submissions is the default for this domain: [_1].',$defaultthreshold));
@@ -1424,6 +1633,13 @@
             if (@changes > 0) {
                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                 if ($putreply eq 'ok') {
+                    if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
+                        my %newenvhash;
+                        foreach my $item (@changes) {
+                            $newenvhash{'course.'.$cdom.'_'.$cnum.'.'.$item} = $cenv{$item};
+                        }
+                        &Apache::lonnet::appenv(\%newenvhash);
+                    }
                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
                                                                 $cnum,undef,undef,'.');
                     if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
@@ -1614,8 +1830,10 @@
     my %longtype;
     if ($type eq 'Community') {
          %longtype = &Apache::lonlocal::texthash(
-                      'courseowner' => "Username:domain of community owner",
-                      'co-owners'   => "Username:domain of each co-owner",
+                      'courseowner'      => "Username:domain of community owner",
+                      'co-owners'        => "Username:domain of each co-owner",
+                      'selfenrollmgrdc'  => "Community-specific self-enrollment configuration by Domain Coordinator",
+                      'selfenrollmgrcc'  => "Community-specific self-enrollment configuration by Community personnel",
          );
     } else {
          %longtype = &Apache::lonlocal::texthash(
@@ -1633,7 +1851,10 @@
                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
                       'sectionnums' => 'Course section number:LON-CAPA section',
                       'crosslistings' => 'Crosslisted class:LON-CAPA section',
-                      'defaultcredits' => 'Credits', 
+                      'defaultcredits' => 'Credits',
+                      'selfenrollmgrdc'  => "Course-specific self-enrollment configuration by Domain Coordinator",
+                      'selfenrollmgrcc'  => "Course-specific self-enrollment configuration by Course personnel",
+
          );
     }
     return %longtype;
@@ -1644,7 +1865,8 @@
       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
           'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
-          'threshold','defaultcredits','uploadquota'])."\n".
+          'threshold','defaultcredits','uploadquota','selfenrollmgrdc','selfenrollmgrcc',
+          'action','state','currsec_st','sections','newsec'],['^selfenrollmgr_'])."\n".
           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
     return $hidden_elements;
 }
@@ -1664,8 +1886,10 @@
         $r->send_http_header;
         return OK;
     }
+
     my $dom = $env{'request.role.domain'};
     my $domdesc = &Apache::lonnet::domain($dom,'description');
+
     if (&Apache::lonnet::allowed('ccc',$dom)) {
         &Apache::loncommon::content_type($r,'text/html');
         $r->send_http_header;
@@ -1786,14 +2010,26 @@
                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                               text=>"Result"});
                             &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
+                        } elsif ($phase eq 'selfenroll') {
+                            &Apache::lonhtmlcommon::add_breadcrumb
+                            ({href => "javascript:changePage(document.$phase,'$phase')",
+                              text => "Self-enrollment settings"});
+                            if (!exists($env{'form.state'})) {
+                                &print_selfenrollconfig($r,$type,$cdesc,$coursehash);
+                            } elsif ($env{'form.state'} eq 'done') {
+                                &Apache::lonhtmlcommon::add_breadcrumb 
+                                ({href=>"javascript:changePage(document.$phase,'$phase')",
+                                  text=>"Result"});
+                                &modify_selfenrollconfig($r,$type,$cdesc,$coursehash);
+                            }
                         }
                     }
                 } else {
                     $r->print('<span class="LC_error">');
                     if ($type eq 'Community') {
-                        $r->print(&mt('The course you selected is not a valid course in this domain'));
-                    } else {
                         $r->print(&mt('The community you selected is not a valid community in this domain'));
+                    } else {
+                        $r->print(&mt('The course you selected is not a valid course in this domain'));
                     }
                     $r->print(" ($domdesc)</span>");
                 }
Index: loncom/interface/selfenroll.pm
diff -u loncom/interface/selfenroll.pm:1.27 loncom/interface/selfenroll.pm:1.28
--- loncom/interface/selfenroll.pm:1.27	Wed May 16 21:19:39 2012
+++ loncom/interface/selfenroll.pm	Mon Mar 31 02:31:05 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow users to self-enroll in a course
 #
-# $Id: selfenroll.pm,v 1.27 2012/05/16 21:19:39 droeschl Exp $
+# $Id: selfenroll.pm,v 1.28 2014/03/31 02:31:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::lonlocal;
 use Apache::createaccount;
 use Apache::loncoursequeueadmin;
+use Apache::lonuserutils;
 use LONCAPA qw(:DEFAULT :match);
 
 sub handler {
@@ -83,7 +84,7 @@
         $knownuser,$selfenroll_access_start,$selfenroll_access_end,
         $selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc,
         $selfenroll_approval,$selfenroll_limit,$selfenroll_cap,
-        $selfenroll_notifylist,$owner);
+        $selfenroll_notifylist,$owner,$crstype);
     $selfenroll_types = $coursehash{'internal.selfenroll_types'};
     $selfenroll_registered =  $coursehash{'internal.selfenroll_registered'};
     $selfenroll_section = $coursehash{'internal.selfenroll_section'};
@@ -94,6 +95,10 @@
     $selfenroll_approval = $coursehash{'internal.selfenroll_approval'};
     $selfenroll_notifylist = $coursehash{'internal.selfenroll_notifylist'};
     $owner = $coursehash{'internal.courseowner'};
+    $crstype = $coursehash{'internal.type'};
+    if ($crstype eq '') {
+        $crstype = 'Course';
+    }
     my $nospace;
     if ($selfenroll_types ne '') {
         my $start = $coursehash{'internal.selfenroll_start_date'};
@@ -227,7 +232,7 @@
         &process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
                              $selfenroll_access_start,$selfenroll_access_end,
                              $selfenroll_section,$now,$selfenroll_approval,
-                             $selfenroll_notifylist,$owner);
+                             $selfenroll_notifylist,$owner,$crstype,$lonhost);
     } elsif ($env{'form.phase'} eq 'login') {
         my $submit_text = &mt('Log in');
         $r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>');
@@ -405,7 +410,7 @@
 sub process_self_enroll {
     my ($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
         $selfenroll_access_start,$selfenroll_access_end,$selfenroll_section,
-        $now,$selfenroll_approval,$selfenroll_notifylist,$owner) = @_;
+        $now,$selfenroll_approval,$selfenroll_notifylist,$owner,$crstype,$lonhost) = @_;
     my $udom = $env{'user.domain'};
     my $uname = $env{'user.name'};
     my $selfenroll = 0;
@@ -436,7 +441,8 @@
             my ($registered,$instsec,$message) = &check_registered($cdom,$cnum);
             $usec = $instsec;
             if (!$registered) {
-                $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.&mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');
+                $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.
+                          &mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');
                 if ($message) {
                     $r->print($message);
                 } else {
@@ -448,7 +454,8 @@
         if ($selfenroll_approval) {
             my $outcome = 
                 &store_selfenroll_request($udom,$uname,$usec,$cdom,$cnum,
-                                          $selfenroll_notifylist,$owner);
+                                          $selfenroll_notifylist,$owner,
+                                          $selfenroll_approval,$crstype,$lonhost);
             $r->print($outcome);
         } else {
             my $enrollresult = 
@@ -526,56 +533,108 @@
 }
 
 sub store_selfenroll_request {
-    my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner) = @_;
+    my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner,
+        $selfenroll_approval,$crstype,$lonhost) = @_;
     my $namespace = 'selfenrollrequests';
     my $output;
     my $now = time;
     my %existing = 
         &Apache::lonnet::get($namespace,[$uname.':'.$udom],$cdom,$cnum);
     if ($existing{$uname.':'.$udom}) {
-        $output = &mt('A self-enrollment request already exists for you for this course.').'<br />'.&mt('Your earlier request is in a queue awaiting action by a Course Coordinator.').
+        $output = &mt('A self-enrollment request already exists for you for this course.').'<br />'.
+                  &mt('Your earlier request is in a queue awaiting action by a Course Coordinator.').
                   '<br /><br />'.&Apache::loncoursequeueadmin::queued_selfenrollment();
     } else {
         my %selfenroll = (
                             $uname.':'.$udom => $now.':'.$usec,
                          );
         my $putresult = &Apache::lonnet::put($namespace,\%selfenroll,$cdom,$cnum);
+        my $status = 'request';
+        if ($selfenroll_approval eq '2') {
+            $status = 'pending';
+        } 
         if ($putresult eq 'ok') {
             my %userenroll = (
                                $cdom.'_'.$cnum =>  {
                                                       timestamp => $now,
                                                       section   => $usec,
-                                                      status    => 'request', 
+                                                      status    => $status,
                                                    });
+            my $token;
+            if ($status eq 'pending') {
+                $token = &Apache::lonnet::tmpput(\%selfenroll,$lonhost);;
+                $userenroll{$cdom.'_'.$cnum}{'token'} = $token;
+            } 
             my $warning;
             my $userresult = &Apache::lonnet::put($namespace,\%userenroll,$udom,$uname);
             if ($userresult ne 'ok') {
                 $warning = &mt('An error occurred saving a personal record of your request.');
             }
-            $output = &mt('Your request for self-enrollment has been recorded.').'<br />'.
-                      &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<br />'.
-                      &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
-            my %emails = &Apache::loncommon::getemails($uname,$udom);
-            if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
-                my $address = $emails{'permanentemail'};
-                if ($address eq '') {
-                    $address = $emails{'notification'};
-                }
-                $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
-            }
-            if ($warning) { 
-                $output .= '<span class="LC_warning">'.$warning.'</span><br />';
-            }
-
-            $output .= &Apache::loncoursequeueadmin::queued_selfenrollment();
-
-            if ($selfenroll_notifylist) {
-                my $fullname = &Apache::loncommon::plainname($uname,$udom);
-                my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
-                my $coursedesc = $courseinfo{'description'};
-                &Apache::loncoursequeueadmin::send_selfserve_notification(
-                    $selfenroll_notifylist,$fullname,$cdom.'_'.$cnum,
-                    $coursedesc,$now,'selfenrollreq',$owner);
+            $output = &mt('Your request for self-enrollment has been recorded.').'<br />';
+            if ($status eq 'pending') {
+                my $coursetype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype); 
+                my %postvalues = (
+                                   'username'   => $env{'user.name'},
+                                   'domain'     => $env{'user.domain'},
+                                   'course'     => $cdom.'_'.$cnum,
+                                   'coursetype' => $coursetype,
+                                   'token'      => $token,
+                                 );
+                my %domconfig = &Apache::lonnet::get_dom('configuration',['selfenrollment'],$cdom);
+                if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
+                    my ($url,$buttontext,$code, at fields);
+                    if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
+                        my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{ 'one_time' => 1});
+                        $postvalues{'uniquecode'} = $courseinfo{'internal.uniquecode'};
+                        $url = $domconfig{'selfenrollment'}{'validation'}{'url'};
+                        if (ref($domconfig{'selfenrollment'}{'validation'}{'fields'}) eq 'ARRAY') {
+                            @fields = @{$domconfig{'selfenrollment'}{'validation'}{'fields'}};
+                        }
+                        $buttontext = $domconfig{'selfenrollment'}{'validation'}{'button'};
+
+                        $output .= $domconfig{'selfenrollment'}{'validation'}{'markup'};
+                        if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
+                            $output .= '<form name="selfenrollvalidation" action="'.$url.'" method="post">'."\n";
+                            foreach my $field (@fields) {
+                                if ($postvalues{$field}) {
+                                    $output .= '<input type="hidden" name="'.$field.'" value="'.$postvalues{$field}.'" />'."\n";
+                                }
+                            }
+                        }
+                        if ($buttontext eq '') {
+                            $buttontext = &mt('Complete my enrollment');
+                        }
+                        $output .= '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
+                                   '</form>'."\n";
+                    }
+                } else {
+                    $status eq 'request';
+                }
+            }
+            if ($status eq 'request') {
+                $output .= &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<br />'.
+                           &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
+                my %emails = &Apache::loncommon::getemails($uname,$udom);
+                if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
+                    my $address = $emails{'permanentemail'};
+                    if ($address eq '') {
+                        $address = $emails{'notification'};
+                    }
+                    $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
+                }
+                if ($warning) { 
+                    $output .= '<span class="LC_warning">'.$warning.'</span><br />';
+                }
+                $output .= &Apache::loncoursequeueadmin::queued_selfenrollment();
+
+                if ($selfenroll_notifylist) {
+                    my $fullname = &Apache::loncommon::plainname($uname,$udom);
+                    my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
+                    my $coursedesc = $courseinfo{'description'};
+                    &Apache::loncoursequeueadmin::send_selfserve_notification(
+                        $selfenroll_notifylist,$fullname,$cdom.'_'.$cnum,
+                        $coursedesc,$now,'selfenrollreq',$owner);
+                }
             }
         } else {
             $output = '<span class="LC_error">'.&mt('An error occurred when recording your request.').'</span>';


More information about the LON-CAPA-cvs mailing list