File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.96: download - view: text, annotated - select for diffs
Tue Jun 15 20:52:26 2021 UTC (2 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Support customization in localenroll.pm to eliminate ambiguity in extraction
  of institutional section from institutional course section for automated
  enrollment.

    1: # The LearningOnline Network with CAPA
    2: # handler for DC-only modifiable course settings
    3: #
    4: # $Id: lonmodifycourse.pm,v 1.96 2021/06/15 20:52:26 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: package Apache::lonmodifycourse;
   29: 
   30: use strict;
   31: use Apache::Constants qw(:common :http);
   32: use Apache::lonnet;
   33: use Apache::loncommon;
   34: use Apache::lonhtmlcommon;
   35: use Apache::lonlocal;
   36: use Apache::lonuserutils;
   37: use Apache::loncreateuser;
   38: use Apache::lonpickcourse;
   39: use lib '/home/httpd/lib/perl';
   40: use LONCAPA qw(:DEFAULT :match);
   41: 
   42: my $registered_cleanup;
   43: my $modified_dom;
   44: 
   45: sub get_dc_settable {
   46:     my ($type,$cdom) = @_;
   47:     if ($type eq 'Community') {
   48:         return ('courseowner','selfenrollmgrdc','selfenrollmgrcc');
   49:     } else {
   50:         my @items = ('courseowner','coursecode','authtype','autharg','selfenrollmgrdc',
   51:                      'selfenrollmgrcc','mysqltables');
   52:         if (&showcredits($cdom)) {
   53:             push(@items,'defaultcredits');
   54:         }
   55:         my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
   56:         if (($passwdconf{'crsownerchg'}) && ($type ne 'Placement')) {
   57:             push(@items,'nopasswdchg');
   58:         }
   59:         return @items;
   60:     }
   61: }
   62: 
   63: sub autoenroll_keys {
   64:     my $internals = ['coursecode','courseowner','authtype','autharg','defaultcredits',
   65:                      'autoadds','autodrops','autostart','autoend','sectionnums',
   66:                      'crosslistings','co-owners','autodropfailsafe'];
   67:     my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
   68:     return ($internals,$accessdates);
   69: }
   70: 
   71: sub catalog_settable {
   72:     my ($confhash,$type) = @_;
   73:     my @settable;
   74:     if (ref($confhash) eq 'HASH') {
   75:         if ($type eq 'Community') {
   76:             if ($confhash->{'togglecatscomm'} ne 'comm') {
   77:                 push(@settable,'togglecats');
   78:             }
   79:             if ($confhash->{'categorizecomm'} ne 'comm') {
   80:                 push(@settable,'categorize');
   81:             }
   82:         } elsif ($type eq 'Placement') {
   83:             if ($confhash->{'togglecatsplace'} ne 'place') {
   84:                 push(@settable,'togglecats');
   85:             }
   86:             if ($confhash->{'categorizeplace'} ne 'place') {
   87:                 push(@settable,'categorize');
   88:             }
   89:         } else {
   90:             if ($confhash->{'togglecats'} ne 'crs') {
   91:                 push(@settable,'togglecats');
   92:             }
   93:             if ($confhash->{'categorize'} ne 'crs') {
   94:                 push(@settable,'categorize');
   95:             }
   96:         }
   97:     } else {
   98:         push(@settable,('togglecats','categorize'));
   99:     }
  100:     return @settable;
  101: }
  102: 
  103: sub get_enrollment_settings {
  104:     my ($cdom,$cnum) = @_;
  105:     my ($internals,$accessdates) = &autoenroll_keys();
  106:     my @items;
  107:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { 
  108:         @items = map { 'internal.'.$_; } (@{$internals});
  109:         push(@items,@{$accessdates});
  110:     }
  111:     push(@items,'internal.nopasswdchg');
  112:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
  113:     my %enrollvar;
  114:     $enrollvar{'autharg'} = '';
  115:     $enrollvar{'authtype'} = '';
  116:     foreach my $item (keys(%settings)) {
  117:         if ($item =~ m/^internal\.(.+)$/) {
  118:             my $type = $1;
  119:             if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
  120:                 if ($settings{$item} == 1) {
  121:                     $enrollvar{$type} = "ON";
  122:                 } else {
  123:                     $enrollvar{$type} = "OFF";
  124:                 }
  125:             } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
  126:                 if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
  127:                     $enrollvar{$type} = &mt('No end date');
  128:                 } else {
  129:                     $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
  130:                 }
  131:             } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
  132:                 $enrollvar{$type} = $settings{$item};
  133:                 $enrollvar{$type} =~ s/,/, /g;
  134:             } elsif ($type eq "authtype"
  135:                      || $type eq "autharg"    || $type eq "coursecode"
  136:                      || $type eq "crosslistings" || $type eq "selfenrollmgr"
  137:                      || $type eq "autodropfailsafe" || $type eq 'nopasswdchg') {
  138:                 $enrollvar{$type} = $settings{$item};
  139:             } elsif ($type eq 'defaultcredits') {
  140:                 if (&showcredits($cdom)) {
  141:                     $enrollvar{$type} = $settings{$item};
  142:                 }
  143:             } elsif ($type eq 'courseowner') {
  144:                 if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
  145:                     $enrollvar{$type} = $settings{$item};
  146:                 } else {
  147:                     if ($settings{$item} ne '') {
  148:                         $enrollvar{$type} = $settings{$item}.':'.$cdom;
  149:                     }
  150:                 }
  151:             }
  152:         } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
  153:             my $type = $1;
  154:             if ( ($type eq 'end') && ($settings{$item} == 0) ) {
  155:                 $enrollvar{$item} = &mt('No end date');
  156:             } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
  157:                 $enrollvar{$item} = 'When enrolled';
  158:             } else {
  159:                 $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
  160:             }
  161:         }
  162:     }
  163:     return %enrollvar;
  164: }
  165: 
  166: sub print_course_search_page {
  167:     my ($r,$dom,$domdesc) = @_;
  168:     my $action = '/adm/modifycourse';
  169:     my $type = $env{'form.type'};
  170:     if (!defined($env{'form.type'})) {
  171:         $type = 'Course';
  172:     }
  173:     &print_header($r,$type);
  174:     my ($filterlist,$filter) = &get_filters($dom);
  175:     my ($numtitles,$cctitle,$dctitle,@codetitles);
  176:     my $ccrole = 'cc';
  177:     if ($type eq 'Community') {
  178:         $ccrole = 'co';
  179:     }
  180:     $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
  181:     $dctitle = &Apache::lonnet::plaintext('dc');
  182:     $r->print(&Apache::loncommon::js_changer());
  183:     if ($type eq 'Community') {
  184:         $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
  185:     } elsif ($type eq 'Placement') {
  186:         $r->print('<h3>'.&mt('Search for a placement test in the [_1] domain',$domdesc).'</h3>');
  187:     } else {
  188:         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
  189:     }
  190:     $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
  191:                                                 \$numtitles,'modifycourse',undef,undef,undef,
  192:                                                 \@codetitles,$dom));
  193: 
  194:     my ($actiontext,$roleoption,$settingsoption);
  195:     if ($type eq 'Community') {
  196:         $actiontext = &mt('Actions available after searching for a community:');
  197:     } elsif ($type eq 'Placement') {
  198:         $actiontext = &mt('Actions available after searching for a placement test:')
  199:     } else {
  200:         $actiontext = &mt('Actions available after searching for a course:');
  201:     }
  202:     if (&Apache::lonnet::allowed('ccc',$dom)) {
  203:        if ($type eq 'Community') {
  204:            $roleoption = &mt('Enter the community with the role of [_1]',$cctitle);
  205:            $settingsoption = &mt('View or modify community settings which only a [_1] may modify.',$dctitle);
  206:        } elsif ($type eq 'Placement') {
  207:            $roleoption = &mt('Enter the placement test with the role of [_1]',$cctitle);
  208:            $settingsoption = &mt('View or modify placement test settings which only a [_1] may modify.',$dctitle);
  209:        } else {
  210:            $roleoption = &mt('Enter the course with the role of [_1]',$cctitle);
  211:            $settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle);
  212:        }
  213:     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
  214:         my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom);
  215:         if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
  216:             if (@{$roles_by_num} > 1) {
  217:                 if ($type eq 'Community') {
  218:                     $roleoption = &mt('Enter the community with one of the available ad hoc roles');
  219:                 } elsif ($type eq 'Placement') {
  220:                     $roleoption = &mt('Enter the placement test with one of the available ad hoc roles.');
  221:                 } else {
  222:                     $roleoption = &mt('Enter the course with one of the available ad hoc roles.');
  223:                 }
  224:             } else {
  225:                 my $rolename = $description->{$roles_by_num->[0]};
  226:                 if ($type eq 'Community') {
  227:                     $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename);
  228:                 } elsif ($type eq 'Placement') {
  229:                     $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$rolename);
  230:                 } else {
  231:                     $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename);
  232:                 }
  233:             }
  234:         }
  235:         if ($type eq 'Community') {
  236:             $settingsoption = &mt('View community settings which only a [_1] may modify.',$dctitle);
  237:         } elsif ($type eq 'Placement') {
  238:             $settingsoption = &mt('View placement test settings which only a [_1] may modify.',$dctitle);
  239:         } else {
  240:             $settingsoption = &mt('View course settings which only a [_1] may modify.',$dctitle);
  241:         }
  242:     }
  243:     $r->print($actiontext.'<ul>');
  244:     if ($roleoption) {
  245:         $r->print('<li>'.$roleoption.'</li>'."\n");
  246:     }
  247:     $r->print('<li>'.$settingsoption.'</li>'."\n".'</ul>');
  248:     return;
  249: }
  250: 
  251: sub print_course_selection_page {
  252:     my ($r,$dom,$domdesc,$permission) = @_;
  253:     my $type = $env{'form.type'};
  254:     if (!defined($type)) {
  255:         $type = 'Course';
  256:     }
  257:     &print_header($r,$type);
  258: 
  259:     if ($permission->{'adhocrole'} eq 'custom') {
  260:         my %lt = &Apache::lonlocal::texthash(
  261:             title    => 'Ad hoc role selection',
  262:             preamble => 'Please choose an ad hoc role in the course.',
  263:             cancel   => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
  264:         );
  265:         my %jslt = &Apache::lonlocal::texthash (
  266:             none => 'You are not eligible to use an ad hoc role for the selected course',
  267:             ok   => 'OK',
  268:             exit => 'Cancel',
  269:         );
  270:         &js_escape(\%jslt);
  271:         $r->print(<<"END");
  272: <script type="text/javascript">
  273: // <![CDATA[
  274: \$(document).ready(function(){
  275:     \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
  276: });
  277: 
  278: function gochoose(cname,cdom,cdesc) {
  279:     document.courselist.pickedcourse.value = cdom+'_'+cname;
  280:     \$("#LC_choose_adhoc").empty();
  281:     var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
  282:     if (pickedaction == 'adhocrole') {
  283:         var http = new XMLHttpRequest();
  284:         var url = "/adm/pickcourse";
  285:         var params = "cid="+cdom+"_"+cname+"&context=adhoc";
  286:         http.open("POST", url, true);
  287:         http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  288:         http.onreadystatechange = function() {
  289:             if (http.readyState == 4 && http.status == 200) {
  290:                 var data = \$.parseJSON(http.responseText);
  291:                 var len = data.roles.length;
  292:                 if (len == '' || len == null || len == 0) {
  293:                     alert('$jslt{none}');
  294:                 } else {
  295:                     if (len == 1) {
  296:                         \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
  297:                         document.courselist.submit();
  298:                     } else {
  299:                         var str = '';
  300:                         \$("#LC_choose_adhoc").empty();
  301:                         for (var i=0; i<data.roles.length; i++) {
  302:                             \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span>&nbsp;&nbsp;</span>")
  303:                             .appendTo("#LC_choose_adhoc");
  304:                         }
  305:                         \$( "#LC_adhocrole_chooser" ).toggle( true );
  306:                         \$( "#LC_get_role_0").prop("checked", true);
  307:                         \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
  308:                         \$( "#LC_adhocrole_chooser" ).dialog("open");
  309:                         \$( "#LC_adhocrole_chooser" ).dialog({
  310:                             height: 400,
  311:                             width: 500,
  312:                             modal: true,
  313:                             resizable: false,
  314:                             buttons: [
  315:                                   {
  316:                                    text: "$jslt{'ok'}",
  317:                                    click: function() {
  318:                                             var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
  319:                                             \$( '[name="adhocrole"]' )[0].value = rolename;
  320:                                             document.courselist.submit();
  321:                                         }
  322:                                   },
  323:                                   {
  324:                                    text: "$jslt{'exit'}",
  325:                                    click: function() {
  326:                                         \$("#LC_adhocrole_chooser").dialog( "close" );
  327:                                        }
  328:                                   }
  329:                             ],
  330:                         });
  331:                         \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
  332:                             event.preventDefault();
  333:                             var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
  334:                             \$( '[name="adhocrole"]' )[0].value = rolename;
  335:                             document.courselist.submit();
  336:                             \$("#LC_adhocrole_chooser").dialog( "close" );
  337:                         });
  338:                     }
  339:                 }
  340:             }
  341:         }
  342:         http.send(params);
  343:     } else {
  344:         document.courselist.submit();
  345:     }
  346:     return;
  347: }
  348: // ]]>
  349: </script>
  350: 
  351: <div id="LC_adhocrole_chooser" title="$lt{'title'}" style="display:none">
  352:   <p>$lt{'preamble'}</p>
  353:   <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
  354:     <div id="LC_choose_adhoc">
  355:     </div>
  356:     <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
  357:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
  358:   </form>
  359:   <p>$lt{'cancel'}</p>
  360: </div>
  361: END
  362:     } elsif ($permission->{'adhocrole'} eq 'coord') {
  363:         $r->print(<<"END");
  364: <script type="text/javascript">
  365: // <![CDATA[
  366: 
  367: function gochoose(cname,cdom,cdesc) {
  368:     document.courselist.pickedcourse.value = cdom+'_'+cname;
  369:     document.courselist.submit();
  370:     return;
  371: }
  372: 
  373: // ]]>
  374: </script>
  375: END
  376:     }
  377: 
  378: # Criteria for course search
  379:     my ($filterlist,$filter) = &get_filters();
  380:     my $action = '/adm/modifycourse';
  381:     my $dctitle = &Apache::lonnet::plaintext('dc');
  382:     my ($numtitles,@codetitles);
  383:     $r->print(&Apache::loncommon::js_changer());
  384:     $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
  385:     $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
  386:                                                 \$numtitles,'modifycourse',undef,undef,undef,
  387:                                                 \@codetitles,$dom,$env{'form.form'}));
  388:     my %courses = &Apache::loncommon::search_courses($dom,$type,$filter,$numtitles,
  389:                                                      undef,undef,undef,\@codetitles);
  390:     &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
  391:                                                     $dom,undef,%courses);
  392:     return;
  393: }
  394: 
  395: sub get_filters {
  396:     my ($dom) = @_;
  397:     my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
  398:                       'ownerdomfilter','coursefilter','sincefilter');
  399:     # created filter
  400:     my $loncaparev = &Apache::lonnet::get_server_loncaparev($dom);
  401:     if ($loncaparev ne 'unknown_cmd') {
  402:         push(@filterlist,'createdfilter');
  403:     }
  404:     my %filter;
  405:     foreach my $item (@filterlist) {
  406:         $filter{$item} = $env{'form.'.$item};
  407:     }
  408:     return (\@filterlist,\%filter);
  409: }
  410: 
  411: sub print_modification_menu {
  412:     my ($r,$cdesc,$domdesc,$dom,$type,$cid,$coursehash,$permission) = @_;
  413:     &print_header($r,$type);
  414:     my ($ccrole,$categorytitle,$setquota_text,$setuploadquota_text,$cdom,$cnum);
  415:     if (ref($coursehash) eq 'HASH') {
  416:         $cdom = $coursehash->{'domain'};
  417:         $cnum = $coursehash->{'num'};
  418:     } else {
  419:          ($cdom,$cnum) = split(/_/,$cid);
  420:     }
  421:     if ($type eq 'Community') {
  422:         $ccrole = 'co';
  423:     } else {
  424:         $ccrole = 'cc';
  425:     }
  426:     my %linktext;
  427:     if ($permission->{'setparms'} eq 'edit') {
  428:         %linktext = (
  429:                       'setquota'      => 'View/Modify quotas for group portfolio files, and for uploaded content',
  430:                       'setanon'       => 'View/Modify responders threshold for anonymous survey submissions display',
  431:                       'selfenroll'    => 'View/Modify Self-Enrollment configuration',
  432:                       'setpostsubmit' => 'View/Modify submit button behavior, post-submission',
  433:                     );
  434:     } else {
  435:         %linktext = (
  436:                       'setquota'      => 'View quotas for group portfolio files, and for uploaded content',
  437:                       'setanon'       => 'View responders threshold for anonymous survey submissions display',
  438:                       'selfenroll'    => 'View Self-Enrollment configuration',
  439:                       'setpostsubmit' => 'View submit button behavior, post-submission',
  440:                     );
  441:     }
  442:     if ($type eq 'Community') {
  443:         if ($permission->{'setparms'} eq 'edit') { 
  444:             $categorytitle = 'View/Modify Community Settings';
  445:             $linktext{'setparms'} = 'View/Modify community owner';
  446:             $linktext{'catsettings'} = 'View/Modify catalog settings for community';
  447:         } else {
  448:             $categorytitle = 'View Community Settings';
  449:             $linktext{'setparms'} = 'View community owner';
  450:             $linktext{'catsettings'} = 'View catalog settings for community';
  451:         }
  452:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
  453:         $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); 
  454:     } else {
  455:         if ($permission->{'setparms'} eq 'edit') {
  456:             $categorytitle = 'View/Modify Course Settings';
  457:             $linktext{'catsettings'} = 'View/Modify catalog settings for course';
  458:             if (($type ne 'Placement') && (&showcredits($dom))) {
  459:                 $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
  460:             } else {
  461:                 $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, self-enrollment and table lifetime';
  462:             }
  463:         } else {
  464:             $categorytitle = 'View Course Settings';
  465:             $linktext{'catsettings'} = 'View catalog settings for course';
  466:             if (($type ne 'Placement') && (&showcredits($dom))) {
  467:                 $linktext{'setparms'} = 'View course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
  468:             } else {
  469:                 $linktext{'setparms'} = 'View course owner, institutional code, default authentication, self-enrollment and table lifetime';
  470:             }
  471:         }
  472:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
  473:         $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
  474:     }
  475:     my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
  476:     my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.'); 
  477:     my $mysqltables_text = &mt('Override default for lifetime of "temporary" MySQL tables containing student performance data.');
  478:     $linktext{'viewparms'} = 'Display current settings for automated enrollment';
  479: 
  480:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
  481:     my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
  482: 
  483:     sub manage_selfenrollment {
  484:         my ($cdom,$cnum,$type,$coursehash,$permission) = @_;
  485:         if ($permission->{'selfenroll'}) {
  486:             my ($managed_by_cc,$managed_by_dc) = &Apache::lonuserutils::selfenrollment_administration($cdom,$cnum,$type,$coursehash);
  487:             if (ref($managed_by_dc) eq 'ARRAY') {
  488:                 if (@{$managed_by_dc}) {
  489:                     return 1;
  490:                 }
  491:             }
  492:         }
  493:         return 0;
  494:     }
  495: 
  496:     sub phaseurl {
  497:         my $phase = shift;
  498:         return "javascript:changePage(document.menu,'$phase')"
  499:     }
  500:     my @menu =
  501:         ({  categorytitle => $categorytitle,
  502:         items => [
  503:             {
  504:                 linktext => $linktext{'setparms'},
  505:                 url => &phaseurl('setparms'),
  506:                 permission => $permission->{'setparms'},
  507:                 #help => '',
  508:                 icon => 'crsconf.png',
  509:                 linktitle => ''
  510:             },
  511:             {
  512:                 linktext => $linktext{'setquota'},
  513:                 url => &phaseurl('setquota'),
  514:                 permission => $permission->{'setquota'},
  515:                 #help => '',
  516:                 icon => 'groupportfolioquota.png',
  517:                 linktitle => ''
  518:             },
  519:             {
  520:                 linktext => $linktext{'setanon'},
  521:                 url => &phaseurl('setanon'),
  522:                 permission => $permission->{'setanon'},
  523:                 #help => '',
  524:                 icon => 'anonsurveythreshold.png',
  525:                 linktitle => ''
  526:             },
  527:             {
  528:                 linktext => $linktext{'catsettings'},
  529:                 url => &phaseurl('catsettings'),
  530:                 permission => (($permission->{'catsettings'}) && (@additional_params > 0)),
  531:                 #help => '',
  532:                 icon => 'ccatconf.png',
  533:                 linktitle => ''
  534:             },
  535:             {
  536:                 linktext => $linktext{'viewparms'},
  537:                 url => &phaseurl('viewparms'),
  538:                 permission => ($permission->{'viewparms'} && ($type ne 'Community') && ($type ne 'Placement')),
  539:                 #help => '',
  540:                 icon => 'roles.png',
  541:                 linktitle => ''
  542:             },
  543:             {
  544:                 linktext => $linktext{'selfenroll'},
  545:                 icon => 'self_enroll.png',
  546:                 #help => 'Course_Self_Enrollment',
  547:                 url => &phaseurl('selfenroll'),
  548:                 permission => &manage_selfenrollment($cdom,$cnum,$type,$coursehash,$permission),
  549:                 linktitle => 'Configure user self-enrollment.',
  550:             },
  551:             {
  552:                 linktext => $linktext{'setpostsubmit'},
  553:                 icon => 'emblem-readonly.png',
  554:                 #help => '',
  555:                 url => &phaseurl('setpostsubmit'),
  556:                 permission => $permission->{'setpostsubmit'},
  557:                 linktitle => '',
  558:             },
  559:         ]
  560:         },
  561:         );
  562: 
  563:     my $menu_html =
  564:         '<h3>'
  565:        .&mt('View/Modify settings for: [_1]',
  566:                 '<span class="LC_nobreak">'.$cdesc.'</span>')
  567:        .'</h3>'."\n".'<p>';
  568:     if ($type eq 'Community') {
  569:         $menu_html .= &mt('Although almost all community settings can be modified by a Coordinator, the following may only be set or modified by a Domain Coordinator:');
  570:     } else {
  571:         $menu_html .= &mt('Although almost all course settings can be modified by a Course Coordinator, the following may only be set or modified by a Domain Coordinator:');
  572:     }
  573:     $menu_html .= '</p>'."\n".'<ul>';
  574:     if ($type eq 'Community') {
  575:         $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>'."\n".
  576:                       '<li>'.&mt('Override defaults for who configures self-enrollment for this specific community').'</li>'."\n";
  577:     } else {
  578:         $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'."\n".
  579:                        '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>'."\n";
  580:         if (($type ne 'Placement') && &showcredits($dom)) {
  581:             $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>'."\n";
  582:         }
  583:         $menu_html .= ' <li>'.&mt('Override defaults for who configures self-enrollment for this specific course.').'</li>'."\n";
  584:     }
  585:     $menu_html .= '<li>'.$mysqltables_text.'</li>'."\n".
  586:                   '<li>'.$setquota_text.'</li>'."\n".
  587:                   '<li>'.$setuploadquota_text.'</li>'."\n".
  588:                   '<li>'.$anon_text.'</li>'."\n".
  589:                   '<li>'.$postsubmit_text.'</li>'."\n";
  590:     my ($categories_link_start,$categories_link_end);
  591:     if ($permission->{'catsettings'} eq 'edit') {
  592:         $categories_link_start = '<a href="/adm/domainprefs?actions=coursecategories&amp;phase=display">';
  593:         $categories_link_end = '</a>';
  594:     }
  595:     foreach my $item (@additional_params) {
  596:         if ($type eq 'Community') {
  597:             if ($item eq 'togglecats') {
  598:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a community from the catalog (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
  599:             } elsif ($item eq 'categorize') {
  600:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a community (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
  601:             }
  602:         } else {
  603:             if ($item eq 'togglecats') {
  604:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a course from the course catalog (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
  605:             } elsif ($item eq 'categorize') {
  606:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a course (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
  607:             }
  608:         }
  609:     }
  610:     $menu_html .=
  611:         ' </ul>'
  612:        .'<form name="menu" method="post" action="/adm/modifycourse">'
  613:        ."\n"
  614:        .&hidden_form_elements();
  615:     
  616:     $r->print($menu_html);
  617:     $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
  618:     $r->print('</form>');
  619:     return;
  620: }
  621: 
  622: sub print_adhocrole_selected {
  623:     my ($r,$type,$permission) = @_;
  624:     &print_header($r,$type);
  625:     my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
  626:     my ($newrole,$selectrole);
  627:     if ($permission->{'adhocrole'} eq 'coord') {
  628:         if ($type eq 'Community') {
  629:             $newrole = "co./$cdom/$cnum";
  630:         } else {
  631:             $newrole = "cc./$cdom/$cnum";
  632:         }
  633:         $selectrole = 1;
  634:     } elsif ($permission->{'adhocrole'} eq 'custom') {
  635:         my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1);      
  636:         if (ref($okroles) eq 'ARRAY') {
  637:             my $possrole = $env{'form.adhocrole'}; 
  638:             if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) {
  639:                 my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
  640:                 $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
  641:                 $selectrole = 1;
  642:             }
  643:         }
  644:     }
  645:     if ($selectrole) {
  646:         $r->print('<form name="adhocrole" method="post" action="/adm/roles">
  647: <input type="hidden" name="selectrole" value="'.$selectrole.'" />
  648: <input type="hidden" name="newrole" value="'.$newrole.'" />
  649: </form>');
  650:     } else {
  651:         $r->print('<form name="ccrole" method="post" action="/adm/modifycourse">'.
  652:                   '</form>');
  653:     }
  654:     return;
  655: }
  656: 
  657: sub print_settings_display {
  658:     my ($r,$cdom,$cnum,$cdesc,$type,$permission) = @_;
  659:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
  660:     my %longtype = &course_settings_descrip($type);
  661:     my %lt = &Apache::lonlocal::texthash(
  662:             'valu' => 'Current value',
  663:             'cour' => 'Current settings are:',
  664:             'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
  665:             'dcon' => 'Modifiable only by Domain Coordinator',
  666:             'back' => 'Pick another action',
  667:     );
  668:     my $ccrole = 'cc';
  669:     if ($type eq 'Community') {
  670:        $ccrole = 'co';
  671:     }
  672:     my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
  673:     my $dctitle = &Apache::lonnet::plaintext('dc');
  674:     my @modifiable_params = &get_dc_settable($type,$cdom);
  675:     my ($internals,$accessdates) = &autoenroll_keys();
  676:     my @items;
  677:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
  678:         @items =  (@{$internals},@{$accessdates});
  679:     }
  680:     my $disp_table = &Apache::loncommon::start_data_table()."\n".
  681:                      &Apache::loncommon::start_data_table_header_row()."\n".
  682:                      "<th>&nbsp;</th>\n".
  683:                      "<th>$lt{'valu'}</th>\n".
  684:                      "<th>$lt{'dcon'}</th>\n".
  685:                      &Apache::loncommon::end_data_table_header_row()."\n";
  686:     foreach my $item (@items) {
  687:         my $shown = $enrollvar{$item};
  688:         if ($item eq 'crosslistings') {
  689:             my (@xlists,@lcsecs);
  690:             foreach my $entry (split(/,/,$enrollvar{$item})) {
  691:                 my ($xlist,$lc_sec) = split(/:/,$entry);
  692:                 push(@xlists,$xlist);
  693:                 push(@lcsecs,$lc_sec);
  694:             }
  695:             if (@xlists) {
  696:                 my $crskey = $cnum.':'.$enrollvar{'coursecode'};
  697:                 my %reformatted =
  698:                     &Apache::lonnet::auto_instsec_reformat($cdom,'declutter',
  699:                                                            {$crskey => \@xlists});
  700:                 if (ref($reformatted{$crskey}) eq 'ARRAY') {
  701:                     my @show;
  702:                     my @xlcodes = @{$reformatted{$crskey}};
  703:                     for (my $i=0; $i<@xlcodes; $i++) {
  704:                         push(@show,$xlcodes[$i].':'.$lcsecs[$i]);
  705:                     }
  706:                     if (@show) {
  707:                         $shown = join(',',@show);
  708:                     }
  709:                 }
  710:             }
  711:         }
  712:         $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
  713:                        "<td><b>$longtype{$item}</b></td>\n".
  714:                        "<td>$shown</td>\n";
  715:         if (grep(/^\Q$item\E$/,@modifiable_params)) {
  716:             $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
  717:         } else {
  718:             $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
  719:         }
  720:         $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
  721:     }
  722:     $disp_table .= &Apache::loncommon::end_data_table()."\n";
  723:     &print_header($r,$type);
  724:     my ($enroll_link_start,$enroll_link_end,$setparms_link_start,$setparms_link_end);
  725:     if (&Apache::lonnet::allowed('ccc',$cdom)) {
  726:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
  727:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
  728:                                              '=1&destinationurl=/adm/populate','&<>"');
  729:         $enroll_link_start = '<a href="'.$escuri.'">';
  730:         $enroll_link_end = '</a>';
  731:     }
  732:     if ($permission->{'setparms'}) {
  733:         $setparms_link_start = '<a href="javascript:changePage(document.viewparms,'."'setparms'".');">';
  734:         $setparms_link_end = '</a>';
  735:     }
  736:     $r->print('<h3>'.&mt('Current automated enrollment settings for:').
  737:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
  738:               '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
  739:               '<p>'.$lt{'cose'}.'<ul>'.
  740:               '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',
  741:                          $cctitle,$enroll_link_start,$enroll_link_end).'</li>');
  742:     if (&showcredits($cdom)) {
  743:         $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,$setparms_link_start,$setparms_link_end)."\n");
  744:     } else {
  745:         $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, and self-enrollment[_3].',$dctitle,$setparms_link_start,$setparms_link_end)."\n");
  746:     }
  747:     $r->print('</li></ul></p>'.
  748:               '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
  749:               '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
  750:               &hidden_form_elements().
  751:               '</p></form>'
  752:     );
  753: }
  754: 
  755: sub print_setquota {
  756:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
  757:     my $lctype = lc($type);
  758:     my $headline = &mt("Set disk space quotas for $lctype: [_1]",
  759:                      '<span class="LC_nobreak">'.$cdesc.'</span>');
  760:     my %lt = &Apache::lonlocal::texthash(
  761:                 'gpqu' => 'Disk space for storage of group portfolio files',
  762:                 'upqu' => 'Disk space for storage of content directly uploaded to course via Content Editor',
  763:                 'modi' => 'Save',
  764:                 'back' => 'Pick another action',
  765:     );
  766:     my %staticdefaults = (
  767:                            coursequota   => 20,
  768:                            uploadquota   => 500,
  769:                          );
  770:     my %settings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota','internal.coursecode'],
  771:                                         $cdom,$cnum);
  772:     my $coursequota = $settings{'internal.coursequota'};
  773:     my $uploadquota = $settings{'internal.uploadquota'};
  774:     if ($coursequota eq '') {
  775:         $coursequota = $staticdefaults{'coursequota'};
  776:     }
  777:     if ($uploadquota eq '') {
  778:         my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
  779:         my $quotatype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$type,\%settings);
  780:         $uploadquota = $domdefs{$quotatype.'quota'};
  781:         if ($uploadquota eq '') {
  782:             $uploadquota = $staticdefaults{'uploadquota'};
  783:         }
  784:     }
  785:     &print_header($r,$type);
  786:     my $hidden_elements = &hidden_form_elements();
  787:     my $porthelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
  788:     my $uploadhelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Upload_Quota');
  789:     my ($disabled,$submit);
  790:     if ($readonly) {
  791:         $disabled = ' disabled="disabled"';
  792:     } else {
  793:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
  794:     }
  795:     $r->print(<<ENDDOCUMENT);
  796: <form action="/adm/modifycourse" method="post" name="setquota" onsubmit="return verify_quota();">
  797: <h3>$headline</h3>
  798: <p><span class="LC_nobreak">
  799: $porthelpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" $disabled /> MB
  800: </span>
  801: <br />
  802: <span class="LC_nobreak">
  803: $uploadhelpitem $lt{'upqu'}: <input type="text" size="4" name="uploadquota" value="$uploadquota" $disabled /> MB
  804: </span>
  805: </p>
  806: <p>
  807: $submit
  808: </p>
  809: $hidden_elements
  810: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
  811: </form>
  812: ENDDOCUMENT
  813:     return;
  814: }
  815: 
  816: sub print_set_anonsurvey_threshold {
  817:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
  818:     my %lt = &Apache::lonlocal::texthash(
  819:                 'resp' => 'Responder threshold for anonymous survey submissions display:',
  820:                 'sufa' => 'Anonymous survey submissions displayed when responders exceeds',
  821:                 'modi' => 'Save',
  822:                 'back' => 'Pick another action',
  823:     );
  824:     my %settings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
  825:     my $threshold = $settings{'internal.anonsurvey_threshold'};
  826:     if ($threshold eq '') {
  827:         my %domconfig = 
  828:             &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
  829:         if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
  830:             $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
  831:             if ($threshold eq '') {
  832:                 $threshold = 10;
  833:             }
  834:         } else {
  835:             $threshold = 10;
  836:         }
  837:     }
  838:     &print_header($r,$type);
  839:     my $hidden_elements = &hidden_form_elements();
  840:     my ($disabled,$submit);
  841:     if ($readonly) {
  842:         $disabled = ' disabled="disabled"'; 
  843:     } else {
  844:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
  845:     }
  846:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Anonsurvey_Threshold');
  847:     $r->print(<<ENDDOCUMENT);
  848: <form action="/adm/modifycourse" method="post" name="setanon" onsubmit="return verify_anon_threshold();">
  849: <h3>$lt{'resp'} <span class="LC_nobreak">$cdesc</span></h3>
  850: <p>
  851: $helpitem $lt{'sufa'}: <input type="text" size="4" name="threshold" value="$threshold" $disabled /> &nbsp;&nbsp;&nbsp;&nbsp;
  852: $submit
  853: </p>
  854: $hidden_elements
  855: <a href="javascript:changePage(document.setanon,'menu')">$lt{'back'}</a>
  856: </form>
  857: ENDDOCUMENT
  858:     return;
  859: }
  860: 
  861: sub print_postsubmit_config {
  862:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
  863:     my %lt = &Apache::lonlocal::texthash (
  864:                 'conf' => 'Configure submit button behavior after student makes a submission',
  865:                 'disa' => 'Disable submit button/keypress following student submission',
  866:                 'nums' => 'Number of seconds submit is disabled',
  867:                 'modi' => 'Save',
  868:                 'back' => 'Pick another action',
  869:                 'yes'  => 'Yes',
  870:                 'no'   => 'No',
  871:     );
  872:     my %settings = &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout',
  873:                                                        'internal.coursecode','internal.textbook'],$cdom,$cnum);
  874:     my $postsubmit = $settings{'internal.postsubmit'};
  875:     if ($postsubmit eq '') {
  876:         my %domconfig =
  877:             &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
  878:         $postsubmit = 1; 
  879:         if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
  880:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
  881:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
  882:                     $postsubmit = 0; 
  883:                 }
  884:             }
  885:         }
  886:     }
  887:     my ($checkedon,$checkedoff,$display);
  888:     if ($postsubmit) {
  889:         $checkedon = 'checked="checked"';
  890:         $display = 'block';
  891:     } else {
  892:         $checkedoff = 'checked="checked"';
  893:         $display = 'none';
  894:     }
  895:     my $postsubtimeout = $settings{'internal.postsubtimeout'};
  896:     my $default = &domain_postsubtimeout($cdom,$type,\%settings);
  897:     my $zero = &mt('(Enter 0 to disable until next page reload, or leave blank to use the domain default: [_1])',$default);
  898:     if ($postsubtimeout eq '') {
  899:         $postsubtimeout = $default;
  900:     }
  901:     &print_header($r,$type);
  902:     my $hidden_elements = &hidden_form_elements();
  903:     my ($disabled,$submit);
  904:     if ($readonly) {
  905:         $disabled = ' disabled="disabled"';
  906:     } else {
  907:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
  908:     }
  909:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Postsubmit_Config');
  910:     $r->print(<<ENDDOCUMENT);
  911: <form action="/adm/modifycourse" method="post" name="setpostsubmit" onsubmit="return verify_postsubmit();">
  912: <h3>$lt{'conf'} <span class="LC_nobreak">($cdesc)</span></h3>
  913: <p>
  914: $helpitem $lt{'disa'}: 
  915: <label><input type="radio" name="postsubmit" $checkedon onclick="togglePostsubmit('studentsubmission');" value="1" $disabled />
  916: $lt{'yes'}</label>&nbsp;&nbsp;
  917: <label><input type="radio" name="postsubmit" $checkedoff onclick="togglePostsubmit('studentsubmission');" value="0" $disabled />
  918: $lt{'no'}</label>
  919: <div id="studentsubmission" style="display: $display">
  920: $lt{'nums'} <input type="text" name="postsubtimeout" value="$postsubtimeout" $disabled /><br />
  921: $zero</div>
  922: <br />     
  923: $submit
  924: </p>
  925: $hidden_elements
  926: <a href="javascript:changePage(document.setpostsubmit,'menu')">$lt{'back'}</a>
  927: </form>
  928: ENDDOCUMENT
  929:     return;
  930: }
  931: 
  932: sub domain_postsubtimeout {
  933:     my ($cdom,$type,$settings) = @_;
  934:     return unless (ref($settings) eq 'HASH'); 
  935:     my $lctype = lc($type);
  936:     unless (($type eq 'Community') || ($type eq 'Placement')) {
  937:         $lctype = 'unofficial';
  938:         if ($settings->{'internal.coursecode'}) {
  939:             $lctype = 'official';
  940:         } elsif ($settings->{'internal.textbook'}) {
  941:             $lctype = 'textbook';
  942:         }
  943:     }
  944:     my %domconfig =
  945:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
  946:     my $postsubtimeout = 60;
  947:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
  948:         if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
  949:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
  950:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype} ne '') {
  951:                     $postsubtimeout = $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype};
  952:                 }
  953:             }
  954:         }
  955:     }
  956:     return $postsubtimeout;
  957: }
  958: 
  959: sub print_catsettings {
  960:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
  961:     &print_header($r,$type);
  962:     my %lt = &Apache::lonlocal::texthash(
  963:                                          'back'    => 'Pick another action',
  964:                                          'catset'  => 'Catalog Settings for Course',
  965:                                          'visi'    => 'Visibility in Course/Community Catalog',
  966:                                          'exclude' => 'Exclude from course catalog:',
  967:                                          'categ'   => 'Categorize Course',
  968:                                          'assi'    => 'Assign one or more categories and/or subcategories to this course.'
  969:                                         );
  970:     if ($type eq 'Community') {
  971:         $lt{'catset'} = &mt('Catalog Settings for Community');
  972:         $lt{'exclude'} = &mt('Exclude from course catalog');
  973:         $lt{'categ'} = &mt('Categorize Community');
  974:         $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
  975:     }
  976:     $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
  977:               '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
  978:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
  979:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
  980:     if (@cat_params > 0) {
  981:         my $disabled;
  982:         if ($readonly) {
  983:             $disabled = ' disabled="disabled"';
  984:         }
  985:         my %currsettings = 
  986:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
  987:         if (grep(/^togglecats$/,@cat_params)) {
  988:             my $excludeon = '';
  989:             my $excludeoff = ' checked="checked" ';
  990:             if ($currsettings{'hidefromcat'} eq 'yes') {
  991:                 $excludeon = $excludeoff;
  992:                 $excludeoff = ''; 
  993:             }
  994:             $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
  995:                       $lt{'exclude'}.
  996:                       '&nbsp;<label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.$disabled.' />'.&mt('Yes').'</label>&nbsp;&nbsp;&nbsp;<label><input name="hidefromcat" type="radio" value="" '.$excludeoff.$disabled.' />'.&mt('No').'</label><br /><p>');
  997:             if ($type eq 'Community') {
  998:                 $r->print(&mt("If a community has been categorized using at least one of the categories defined for communities in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
  999:             } elsif ($type eq 'Placement') {
 1000:                 $r->print(&mt("If a placement test has been categorized using at least one of the categories defined for placement tests in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
 1001:             } else {
 1002:                 $r->print(&mt("Unless excluded, a course will be listed in the domain's publicly accessible Course/Community Catalog, if at least one of the following applies").':<ul>'.
 1003:                           '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
 1004:                           '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
 1005:             }
 1006:             $r->print('</ul></p>');
 1007:         }
 1008:         if (grep(/^categorize$/,@cat_params)) {
 1009:             $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
 1010:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
 1011:                 my $cathash = $domconf{'coursecategories'}{'cats'};
 1012:                 if (ref($cathash) eq 'HASH') {
 1013:                     $r->print($lt{'assi'}.'<br /><br />'.
 1014:                               &Apache::loncommon::assign_categories_table($cathash,
 1015:                                                      $currsettings{'categories'},$type,$disabled));
 1016:                 } else {
 1017:                     $r->print(&mt('No categories defined for this domain'));
 1018:                 }
 1019:             } else {
 1020:                 $r->print(&mt('No categories defined for this domain'));
 1021:             }
 1022:             unless (($type eq 'Community') || ($type eq 'Placement')) { 
 1023:                 $r->print('<p>'.&mt('If auto-cataloging based on institutional code is enabled in the domain, a course will continue to be listed in the catalog of official courses, in addition to receiving a listing under any manually assigned categor(ies).').'</p>');
 1024:             }
 1025:         }
 1026:         unless ($readonly) {
 1027:             $r->print('<p><input type="button" name="chgcatsettings" value="'.
 1028:                       &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
 1029:         }
 1030:     } else {
 1031:         $r->print('<span class="LC_warning">');
 1032:         if ($type eq 'Community') {
 1033:             $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
 1034:         } else {
 1035:             $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
 1036:         }
 1037:         $r->print('</span><br /><br />'."\n".
 1038:                   '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
 1039:                   $lt{'back'}.'</a>');
 1040:     }
 1041:     $r->print(&hidden_form_elements().'</form>'."\n");
 1042:     return;
 1043: }
 1044: 
 1045: sub print_course_modification_page {
 1046:     my ($r,$cdom,$cnum,$cdesc,$crstype,$readonly) = @_;
 1047:     my %lt=&Apache::lonlocal::texthash(
 1048:             'actv' => "Active",
 1049:             'inac' => "Inactive",
 1050:             'ownr' => "Owner",
 1051:             'name' => "Name",
 1052:             'unme' => "Username:Domain",
 1053:             'stus' => "Status",
 1054:             'nocc' => 'There is currently no owner set for this course.',
 1055:             'gobt' => "Save",
 1056:             'sett' => 'Setting',
 1057:             'domd' => 'Domain default',
 1058:             'whom' => 'Who configures',  
 1059:     );
 1060:     my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname,$disabled);
 1061:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
 1062:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
 1063:                                                        'internal.selfenrollmgrdc','internal.selfenrollmgrcc',
 1064:                                                        'internal.mysqltables'],$cdom,$cnum);
 1065:     my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
 1066:     my @specific_managebydc = split(/,/,$settings{'internal.selfenrollmgrdc'});
 1067:     my @specific_managebycc = split(/,/,$settings{'internal.selfenrollmgrcc'});
 1068:     my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
 1069:     my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
 1070:     my @default_managebydc = split(/,/,$domdefaults{$type.'selfenrolladmdc'});
 1071:     if ($crstype eq 'Community') {
 1072:         $ccrole = 'co';
 1073:         $lt{'nocc'} = &mt('There is currently no owner set for this community.');
 1074:     } else {
 1075:         $ccrole ='cc';
 1076:         ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar,$readonly);
 1077:     }
 1078:     $ccname = &Apache::lonnet::plaintext($ccrole,$crstype);
 1079:     if ($readonly) {
 1080:        $disabled = ' disabled="disabled"';
 1081:     }
 1082:     my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
 1083:     my (@local_ccs,%cc_status,%pname);
 1084:     foreach my $item (keys(%roleshash)) {
 1085:         my ($uname,$udom) = split(/:/,$item);
 1086:         if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
 1087:             push(@local_ccs,$uname.':'.$udom);
 1088:             $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
 1089:             $cc_status{$uname.':'.$udom} = $lt{'actv'};
 1090:         }
 1091:     }
 1092:     if (($enrollvar{'courseowner'} ne '') && 
 1093:         (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
 1094:         push(@local_ccs,$enrollvar{'courseowner'});
 1095:         my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
 1096:         $pname{$enrollvar{'courseowner'}} = 
 1097:                          &Apache::loncommon::plainname($owneruname,$ownerdom);
 1098:         my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
 1099:                                                               $cdom,$cnum,$ccrole);
 1100:         if ($active_cc eq 'active') {
 1101:             $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
 1102:         } else {
 1103:             $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
 1104:         }
 1105:     }
 1106:     @local_ccs = sort(@local_ccs);
 1107:     if (@local_ccs == 0) {
 1108:         $ownertable = $lt{'nocc'};
 1109:     } else {
 1110:         my $numlocalcc = scalar(@local_ccs);
 1111:         $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
 1112:                       &Apache::loncommon::start_data_table()."\n".
 1113:                       &Apache::loncommon::start_data_table_header_row()."\n".
 1114:                       '<th>'.$lt{'ownr'}.'</th>'.
 1115:                       '<th>'.$lt{'name'}.'</th>'.
 1116:                       '<th>'.$lt{'unme'}.'</th>'.
 1117:                       '<th>'.$lt{'stus'}.'</th>'.
 1118:                       &Apache::loncommon::end_data_table_header_row()."\n";
 1119:         foreach my $cc (@local_ccs) {
 1120:             $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
 1121:             if ($cc eq $enrollvar{'courseowner'}) {
 1122:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked"'.$disabled.' /></td>'."\n";
 1123:             } else {
 1124:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'"'.$disabled.' /></td>'."\n";
 1125:             }
 1126:             $ownertable .= 
 1127:                  '<td>'.$pname{$cc}.'</td>'."\n".
 1128:                  '<td>'.$cc.'</td>'."\n".
 1129:                  '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
 1130:                  &Apache::loncommon::end_data_table_row()."\n";
 1131:         }
 1132:         $ownertable .= &Apache::loncommon::end_data_table();
 1133:     }
 1134:     &print_header($r,$crstype,$javascript_validations);
 1135:     my $dctitle = &Apache::lonnet::plaintext('dc');
 1136:     my $mainheader = &modifiable_only_title($crstype);
 1137:     my $hidden_elements = &hidden_form_elements();
 1138:     $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
 1139:               '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
 1140:               &Apache::lonhtmlcommon::start_pick_box());
 1141:     if ($crstype eq 'Community') {
 1142:         $r->print(&Apache::lonhtmlcommon::row_title(
 1143:                   &Apache::loncommon::help_open_topic('Modify_Community_Owner').
 1144:                   '&nbsp;'.&mt('Community Owner'))."\n".
 1145:                   $ownertable."\n".&Apache::lonhtmlcommon::row_closure());
 1146:     } else {
 1147:         $r->print(&Apache::lonhtmlcommon::row_title(
 1148:                       &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
 1149:                       '&nbsp;'.&mt('Course Code'))."\n".
 1150:                   '<input type="text" size="15" name="coursecode" value="'.$enrollvar{'coursecode'}.'"'.$disabled.' />'.
 1151:                   &Apache::lonhtmlcommon::row_closure());
 1152:         if (($crstype eq 'Course') && (&showcredits($cdom))) {
 1153:             $r->print(&Apache::lonhtmlcommon::row_title(
 1154:                           &Apache::loncommon::help_open_topic('Modify_Course_Credithours').
 1155:                           '&nbsp;'.&mt('Credits (students)'))."\n".
 1156:                       '<input type="text" size="3" name="defaultcredits" value="'.$enrollvar{'defaultcredits'}.'"'.$disabled.' />'.
 1157:                       &Apache::lonhtmlcommon::row_closure());
 1158:         }
 1159:         $r->print(&Apache::lonhtmlcommon::row_title(
 1160:                       &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
 1161:                       '&nbsp;'.&mt('Default Authentication method'))."\n".
 1162:                   $authenitems."\n".
 1163:                   &Apache::lonhtmlcommon::row_closure().
 1164:                   &Apache::lonhtmlcommon::row_title(
 1165:                       &Apache::loncommon::help_open_topic('Modify_Course_Owner').
 1166:                       '&nbsp;'.&mt('Course Owner'))."\n".
 1167:                   $ownertable."\n".&Apache::lonhtmlcommon::row_closure());
 1168:         if (($passwdconf{'crsownerchg'}) && ($type ne 'Placement')) {
 1169:             my $checked;
 1170:             if ($enrollvar{'nopasswdchg'}) {
 1171:                 $checked = ' checked="checked"';
 1172:             }
 1173:             $r->print(&Apache::lonhtmlcommon::row_title(
 1174:                          &Apache::loncommon::help_open_topic('Modify_Course_Chgpasswd').
 1175:                          '&nbsp;'.&mt('Changing passwords (internal)'))."\n".
 1176:                          '<label><input type="checkbox" value="1" name="nopasswdchg"'.$checked.$disabled.' />'.
 1177:                          &mt('Disable changing password for users with student role by course owner').'<label>'."\n".
 1178:                          &Apache::lonhtmlcommon::row_closure());
 1179:         }
 1180:     }
 1181:     my ($cctitle,$rolename,$currmanages,$ccchecked,$dcchecked,$defaultchecked);
 1182:     my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
 1183:     if ($type eq 'Community') {
 1184:         $cctitle = &mt('Community personnel');
 1185:     } else {
 1186:         $cctitle = &mt('Course personnel');
 1187:     }
 1188: 
 1189:     $r->print(&Apache::lonhtmlcommon::row_title(
 1190:               &Apache::loncommon::help_open_topic('Modify_Course_Selfenrolladmin').
 1191:                   '&nbsp;'.&mt('Self-enrollment configuration')).
 1192:               &Apache::loncommon::start_data_table()."\n".
 1193:               &Apache::loncommon::start_data_table_header_row()."\n".
 1194:               '<th>'.$lt{'sett'}.'</th>'.
 1195:               '<th>'.$lt{'domd'}.'</th>'.
 1196:               '<th>'.$lt{'whom'}.'</th>'.
 1197:               &Apache::loncommon::end_data_table_header_row()."\n");
 1198:     my %optionname;
 1199:     $optionname{''} = &mt('Use domain default'); 
 1200:     $optionname{'0'} = $dctitle;
 1201:     $optionname{'1'} = $cctitle;
 1202:     foreach my $item (@{$selfenrollrows}) {
 1203:         my %checked;
 1204:         my $default = $cctitle;
 1205:         if (grep(/^\Q$item\E$/,@default_managebydc)) {
 1206:             $default = $dctitle;
 1207:         }
 1208:         if (grep(/^\Q$item\E$/,@specific_managebydc)) {
 1209:             $checked{'0'} = ' checked="checked"';
 1210:         } elsif (grep(/^\Q$item\E$/,@specific_managebycc)) {
 1211:             $checked{'1'} = ' checked="checked"';
 1212:         } else {
 1213:             $checked{''} = ' checked="checked"';
 1214:         } 
 1215:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
 1216:                  '<td>'.$selfenrolltitles->{$item}.'</td>'."\n".
 1217:                  '<td>'.&mt('[_1] configures',$default).'</td>'."\n".
 1218:                  '<td>');
 1219:         foreach my $option ('','0','1') {  
 1220:             $r->print('<span class="LC_nobreak"><label>'.
 1221:                       '<input type="radio" name="selfenrollmgr_'.$item.'" '.
 1222:                       'value="'.$option.'"'.$checked{$option}.$disabled.' />'.
 1223:                       $optionname{$option}.'</label></span><br />');
 1224:         }
 1225:         $r->print('</td>'."\n".
 1226:                   &Apache::loncommon::end_data_table_row()."\n");
 1227:     }
 1228:     $r->print(&Apache::loncommon::end_data_table()."\n".
 1229:               '<br />'.&Apache::lonhtmlcommon::row_closure().
 1230:               &Apache::lonhtmlcommon::row_title(
 1231:               &Apache::loncommon::help_open_topic('Modify_Course_Table_Lifetime').
 1232:               '&nbsp;'.&mt('"Temporary" Tables Lifetime (s)'))."\n".
 1233:               '<input type="text" size="10" name="mysqltables" value="'.$settings{'internal.mysqltables'}.'"'.$disabled.' />'.
 1234:               &Apache::lonhtmlcommon::row_closure(1).
 1235:               &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements);
 1236:     unless ($readonly) {
 1237:         $r->print('<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
 1238:         if ($crstype eq 'Community') {
 1239:             $r->print('this.form.submit();"');
 1240:         } else {
 1241:             $r->print('javascript:verify_message(this.form);"');
 1242:         }
 1243:         $r->print(' value="'.$lt{'gobt'}.'" />');
 1244:     }
 1245:     $r->print('</p></form>');
 1246:     return;
 1247: }
 1248: 
 1249: sub print_selfenrollconfig {
 1250:     my ($r,$type,$cdesc,$coursehash,$readonly) = @_;
 1251:     return unless(ref($coursehash) eq 'HASH');
 1252:     my $cnum = $coursehash->{'num'};
 1253:     my $cdom = $coursehash->{'domain'};
 1254:     my %currsettings = &get_selfenroll_settings($coursehash);
 1255:     &print_header($r,$type);
 1256:     $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
 1257:               '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
 1258:     &Apache::loncreateuser::print_selfenroll_menu($r,'domain',$env{'form.pickedcourse'},
 1259:                                                   $cdom,$cnum,\%currsettings,
 1260:                                                   &hidden_form_elements(),$readonly);
 1261:     return;
 1262: }
 1263: 
 1264: sub modify_selfenrollconfig {
 1265:     my ($r,$type,$cdesc,$coursehash) = @_;
 1266:     return unless(ref($coursehash) eq 'HASH');
 1267:     my $cnum = $coursehash->{'num'};
 1268:     my $cdom = $coursehash->{'domain'};
 1269:     my %currsettings = &get_selfenroll_settings($coursehash);
 1270:     &print_header($r,$type);
 1271:     $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
 1272:              '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
 1273:     $r->print('<form action="/adm/modifycourse" method="post" name="selfenroll">'."\n".
 1274:               &hidden_form_elements().'<br />');
 1275:     &Apache::loncreateuser::update_selfenroll_config($r,$env{'form.pickedcourse'},
 1276:                                                      $cdom,$cnum,'domain',$type,\%currsettings);
 1277:     $r->print('</form>');
 1278:     return;
 1279: }
 1280: 
 1281: sub get_selfenroll_settings {
 1282:     my ($coursehash) = @_;
 1283:     my %currsettings;
 1284:     if (ref($coursehash) eq 'HASH') {
 1285:         %currsettings = (
 1286:             selfenroll_types              => $coursehash->{'internal.selfenroll_types'},
 1287:             selfenroll_registered         => $coursehash->{'internal.selfenroll_registered'},
 1288:             selfenroll_section            => $coursehash->{'internal.selfenroll_section'},
 1289:             selfenroll_notifylist         => $coursehash->{'internal.selfenroll_notifylist'},
 1290:             selfenroll_approval           => $coursehash->{'internal.selfenroll_approval'},
 1291:             selfenroll_limit              => $coursehash->{'internal.selfenroll_limit'},
 1292:             selfenroll_cap                => $coursehash->{'internal.selfenroll_cap'},
 1293:             selfenroll_start_date         => $coursehash->{'internal.selfenroll_start_date'},
 1294:             selfenroll_end_date           => $coursehash->{'internal.selfenroll_end_date'},
 1295:             selfenroll_start_access       => $coursehash->{'internal.selfenroll_start_access'},
 1296:             selfenroll_end_access         => $coursehash->{'internal.selfenroll_end_access'},
 1297:             default_enrollment_start_date => $coursehash->{'default_enrollment_start_date'},
 1298:             default_enrollment_end_date   => $coursehash->{'default_enrollment_end_date'},
 1299:             uniquecode                    => $coursehash->{'internal.uniquecode'},
 1300:         );
 1301:     }
 1302:     return %currsettings;
 1303: }
 1304: 
 1305: sub modifiable_only_title {
 1306:     my ($type) = @_;
 1307:     my $dctitle = &Apache::lonnet::plaintext('dc');
 1308:     if ($type eq 'Community') {
 1309:         return &mt('Community settings modifiable only by [_1] for:',$dctitle);
 1310:     } else {
 1311:         return &mt('Course settings modifiable only by [_1] for:',$dctitle);
 1312:     }
 1313: }
 1314: 
 1315: sub gather_authenitems {
 1316:     my ($cdom,$enrollvar,$readonly) = @_;
 1317:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
 1318:     my $curr_authtype = '';
 1319:     my $curr_authfield = '';
 1320:     if (ref($enrollvar) eq 'HASH') {
 1321:         if ($enrollvar->{'authtype'} =~ /^krb/) {
 1322:             $curr_authtype = 'krb';
 1323:         } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
 1324:             $curr_authtype = 'int';
 1325:         } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
 1326:             $curr_authtype = 'loc';
 1327:         } elsif ($enrollvar->{'authtype'} eq 'lti' ) {
 1328:             $curr_authtype = 'lti';
 1329:         }
 1330:     }
 1331:     unless ($curr_authtype eq '') {
 1332:         $curr_authfield = $curr_authtype.'arg';
 1333:     }
 1334:     my $javascript_validations = 
 1335:         &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
 1336:                                                       $curr_authtype,$curr_authfield);
 1337:     my %param = ( formname => 'document.'.$env{'form.phase'},
 1338:            kerb_def_dom => $krbdefdom,
 1339:            kerb_def_auth => $krbdef,
 1340:            mode => 'modifycourse',
 1341:            curr_authtype => $curr_authtype,
 1342:            curr_autharg => $enrollvar->{'autharg'},
 1343:            readonly => $readonly,
 1344:         );
 1345:     my (%authform,$authenitems);
 1346:     $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
 1347:     $authform{'int'} = &Apache::loncommon::authform_internal(%param);
 1348:     $authform{'loc'} = &Apache::loncommon::authform_local(%param);
 1349:     $authform{'lti'} = &Apache::loncommon::authform_lti(%param);
 1350:     foreach my $item ('krb','int','loc','lti') {
 1351:         if ($authform{$item} ne '') {
 1352:             $authenitems .= $authform{$item}.'<br />';
 1353:         }
 1354:     }
 1355:     return($javascript_validations,$authenitems);
 1356: }
 1357: 
 1358: sub modify_course {
 1359:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
 1360:     my %longtype = &course_settings_descrip($type);
 1361:     my @items = ('internal.courseowner','description','internal.co-owners',
 1362:                  'internal.pendingco-owners','internal.selfenrollmgrdc',
 1363:                  'internal.selfenrollmgrcc','internal.mysqltables');
 1364:     my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
 1365:     unless (($type eq 'Community') || ($type eq 'Placement')) {
 1366:         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
 1367:                      'internal.sectionnums','internal.crosslistings'));
 1368:         if (&showcredits($cdom)) {  
 1369:             push(@items,'internal.defaultcredits');
 1370:         }
 1371:         my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
 1372:         if ($passwdconf{'crsownerchg'}) {
 1373:             push(@items,'internal.nopasswdchg');
 1374:         }
 1375:     }
 1376:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
 1377:     my $description = $settings{'description'};
 1378:     my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,
 1379:         %cenv,%changed,@changes,@nochanges,@sections,@xlists,@warnings);
 1380:     my @modifiable_params = &get_dc_settable($type,$cdom);
 1381:     foreach my $param (@modifiable_params) {
 1382:         $currattr{$param} = $settings{'internal.'.$param};
 1383:     }
 1384:     if ($type eq 'Community') {
 1385:         %changed = ( owner  => 0 );
 1386:         $ccrole = 'co';
 1387:     } else {
 1388:         %changed = ( code  => 0,
 1389:                      owner => 0,
 1390:                      passwd => 0,
 1391:                    );
 1392:         $ccrole = 'cc';
 1393:         unless ($settings{'internal.sectionnums'} eq '') {
 1394:             if ($settings{'internal.sectionnums'} =~ m/,/) {
 1395:                 @sections = split/,/,$settings{'internal.sectionnums'};
 1396:             } else {
 1397:                 $sections[0] = $settings{'internal.sectionnums'};
 1398:             }
 1399:         }
 1400:         unless ($settings{'internal.crosslistings'} eq '') {
 1401:             if ($settings{'internal.crosslistings'} =~ m/,/) {
 1402:                 @xlists = split/,/,$settings{'internal.crosslistings'};
 1403:             } else {
 1404:                 $xlists[0] = $settings{'internal.crosslistings'};
 1405:             }
 1406:         }
 1407:         if ($env{'form.login'} eq 'krb') {
 1408:             $newattr{'authtype'} = $env{'form.login'};
 1409:             $newattr{'authtype'} .= $env{'form.krbver'};
 1410:             $newattr{'autharg'} = $env{'form.krbarg'};
 1411:         } elsif ($env{'form.login'} eq 'int') {
 1412:             $newattr{'authtype'} ='internal';
 1413:             if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
 1414:                 $newattr{'autharg'} = $env{'form.intarg'};
 1415:             }
 1416:         } elsif ($env{'form.login'} eq 'loc') {
 1417:             $newattr{'authtype'} = 'localauth';
 1418:             if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
 1419:                 $newattr{'autharg'} = $env{'form.locarg'};
 1420:             }
 1421:         } elsif ($env{'form.login'} eq 'lti') {
 1422:             $newattr{'authtype'} = 'lti';
 1423:         }
 1424:         if ( $newattr{'authtype'}=~ /^krb/) {
 1425:             if ($newattr{'autharg'}  eq '') {
 1426:                 push(@warnings,
 1427:                            &mt('As you did not include the default Kerberos domain'
 1428:                           .' to be used for authentication in this class, the'
 1429:                           .' institutional data used by the automated'
 1430:                           .' enrollment process must include the Kerberos'
 1431:                           .' domain for each new student.'));
 1432:             }
 1433:         }
 1434: 
 1435:         if ( exists($env{'form.coursecode'}) ) {
 1436:             $newattr{'coursecode'}=$env{'form.coursecode'};
 1437:             unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
 1438:                 $changed{'code'} = 1;
 1439:             }
 1440:         }
 1441:         if ( exists($env{'form.mysqltables'}) ) {
 1442:             $newattr{'mysqltables'} = $env{'form.mysqltables'};
 1443:             $newattr{'mysqltables'} =~ s/\D+//g;
 1444:         }
 1445:         if ($type ne 'Placement') {
 1446:             if (&showcredits($cdom) && exists($env{'form.defaultcredits'})) {
 1447:                 $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
 1448:                 $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
 1449:             }
 1450:             if (grep(/^nopasswdchg$/,@modifiable_params)) {
 1451:                 if ($env{'form.nopasswdchg'}) {
 1452:                     $newattr{'nopasswdchg'} = 1;
 1453:                     unless ($currattr{'nopasswdchg'}) {
 1454:                         $changed{'passwd'} = 1;
 1455:                     }
 1456:                 } elsif ($currattr{'nopasswdchg'}) {
 1457:                     $changed{'passwd'} = 1;
 1458:                 }
 1459:             }
 1460:         }
 1461:     }
 1462: 
 1463:     my @newmgrdc = ();
 1464:     my @newmgrcc = ();
 1465:     my @currmgrdc = split(/,/,$currattr{'selfenrollmgrdc'});
 1466:     my @currmgrcc = split(/,/,$currattr{'selfenrollmgrcc'});
 1467: 
 1468:     foreach my $item (@{$selfenrollrows}) {
 1469:         if ($env{'form.selfenrollmgr_'.$item} eq '0') {
 1470:             push(@newmgrdc,$item);
 1471:         } elsif ($env{'form.selfenrollmgr_'.$item} eq '1') {
 1472:             push(@newmgrcc,$item);
 1473:         }
 1474:     }
 1475: 
 1476:     $newattr{'selfenrollmgrdc'}=join(',',@newmgrdc);
 1477:     $newattr{'selfenrollmgrcc'}=join(',',@newmgrcc);
 1478: 
 1479:     my $cctitle;
 1480:     if ($type eq 'Community') {
 1481:         $cctitle = &mt('Community personnel');
 1482:     } else {
 1483:         $cctitle = &mt('Course personnel');
 1484:     }
 1485:     my $dctitle = &Apache::lonnet::plaintext('dc');
 1486: 
 1487:     if ( exists($env{'form.courseowner'}) ) {
 1488:         $newattr{'courseowner'}=$env{'form.courseowner'};
 1489:         unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
 1490:             $changed{'owner'} = 1;
 1491:         } 
 1492:     }
 1493: 
 1494:     if ($changed{'owner'} || $changed{'code'} || $changed{'passwd'}) {
 1495:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
 1496:                                                     undef,undef,'.');
 1497:         if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
 1498:             if ($changed{'code'}) {
 1499:                 $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
 1500:             }
 1501:             if ($changed{'owner'}) {
 1502:                 $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
 1503:             }
 1504:             if ($changed{'passwd'}) {
 1505:                 if ($env{'form.nopasswdchg'}) {
 1506:                     $crsinfo{$env{'form.pickedcourse'}}{'nopasswdchg'} = 1;
 1507:                 } else {
 1508:                     delete($crsinfo{'nopasswdchg'});
 1509:                 }
 1510:             }
 1511:             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
 1512:             my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
 1513:             if (($putres eq 'ok') && (($changed{'owner'} || $changed{'code'}))) {
 1514:                 &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
 1515:                 if ($changed{'code'}) {
 1516:                     &Apache::lonnet::devalidate_cache_new('instcats',$cdom);
 1517:                     # Update cache of self-cataloging courses on institution's server(s).
 1518:                     if (&Apache::lonnet::shared_institution($cdom)) {
 1519:                         unless ($registered_cleanup) {
 1520:                             my $handlers = $r->get_handlers('PerlCleanupHandler');
 1521:                             $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
 1522:                             $registered_cleanup=1;
 1523:                             $modified_dom = $cdom;
 1524:                         }
 1525:                     }
 1526:                 }
 1527:             }
 1528:         }
 1529:     }
 1530:     foreach my $param (@modifiable_params) {
 1531:         if ($currattr{$param} eq $newattr{$param}) {
 1532:             push(@nochanges,$param);
 1533:         } else {
 1534:             $cenv{'internal.'.$param} = $newattr{$param};
 1535:             push(@changes,$param);
 1536:         }
 1537:     }
 1538:     if (@changes > 0) {
 1539:         $chgresponse = &mt('The following settings have been changed:').'<br/><ul>';
 1540:     }
 1541:     if (@nochanges > 0) {
 1542:         $nochgresponse = &mt('The following settings remain unchanged:').'<br/><ul>';
 1543:     }
 1544:     if (@changes > 0) {
 1545:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 1546:         if ($putreply !~ /^ok$/) {
 1547:             $response = '<p class="LC_error">'.
 1548:                         &mt('There was a problem processing your requested changes.').'<br />';
 1549:             if ($type eq 'Community') {
 1550:                 $response .= &mt('Settings for this community have been left unchanged.');
 1551:             } else {
 1552:                 $response .= &mt('Settings for this course have been left unchanged.');
 1553:             }
 1554:             $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
 1555:         } else {
 1556:             if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
 1557:                 my %newenv;
 1558:                 map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes;   
 1559:                 &Apache::lonnet::appenv(\%newenv);
 1560:             }
 1561:             foreach my $attr (@modifiable_params) {
 1562:                 if (grep/^\Q$attr\E$/,@changes) {
 1563:                     my $shown = $newattr{$attr};
 1564:                     if ($attr eq 'selfenrollmgrdc') {
 1565:                         $shown = &selfenroll_config_status(\@newmgrdc,$selfenrolltitles);
 1566:                     } elsif ($attr eq 'selfenrollmgrcc') {
 1567:                         $shown = &selfenroll_config_status(\@newmgrcc,$selfenrolltitles);
 1568:                     } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
 1569:                         $shown = &mt('None');
 1570:                     } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
 1571:                         $shown = &mt('domain default');
 1572:                     } elsif ($attr eq 'nopasswdchg') {
 1573:                         if ($shown) {
 1574:                             $shown = &mt('Yes');
 1575:                         } else {
 1576:                             $shown = &mt('No');
 1577:                         }
 1578:                     }
 1579:                     $chgresponse .= '<li>'.&mt('[_1] now set to: [_2]',$longtype{$attr},$shown).'</li>';
 1580:                 } else {
 1581:                     my $shown = $currattr{$attr};
 1582:                     if ($attr eq 'selfenrollmgrdc') {
 1583:                         $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
 1584:                     } elsif ($attr eq 'selfenrollmgrcc') {
 1585:                         $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
 1586:                     } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
 1587:                         $shown = &mt('None');
 1588:                     } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
 1589:                         $shown = &mt('domain default');
 1590:                     } elsif ($attr eq 'nopasswdchg') {
 1591:                         if ($shown) {
 1592:                             $shown = &mt('Yes');
 1593:                         } else {
 1594:                             $shown = &mt('No');
 1595:                         }
 1596:                     }
 1597:                     $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
 1598:                 }
 1599:             }
 1600:             if (($type ne 'Community') && ($type ne 'Placement') && ($changed{'code'} || $changed{'owner'})) {
 1601:                 if ( $newattr{'courseowner'} eq '') {
 1602: 	            push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
 1603:                                    '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
 1604:                 } else {
 1605:                     my %crsenv = &Apache::lonnet::get('environment',['internal.co-owners'],$cdom,$cnum);
 1606:                     my $coowners = $crsenv{'internal.co-owners'};
 1607: 	            if (@sections > 0) {
 1608:                         if ($changed{'code'}) {
 1609: 	                    foreach my $sec (@sections) {
 1610: 		                if ($sec =~ m/^(.+):/) {
 1611:                                     my $instsec = $1;
 1612: 		                    my $inst_course_id = $newattr{'coursecode'}.$1;
 1613:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
 1614: 			            if ($course_check eq 'ok') {
 1615:                                         my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
 1616: 			                unless ($outcome eq 'ok') {
 1617:                                
 1618: 				            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome).'<br/>');
 1619: 			                }
 1620: 			            } else {
 1621:                                         push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$course_check));
 1622: 			            }
 1623: 		                } else {
 1624: 			            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3], because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
 1625: 		                }
 1626: 		            }
 1627: 	                } elsif ($changed{'owner'}) {
 1628:                             foreach my $sec (@sections) {
 1629:                                 if ($sec =~ m/^(.+):/) {
 1630:                                     my $instsec = $1;
 1631:                                     my $inst_course_id = $newattr{'coursecode'}.$instsec;
 1632:                                     my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
 1633:                                     unless ($outcome eq 'ok') {
 1634:                                         push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome));
 1635:                                     }
 1636:                                 } else {
 1637:                                     push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3], because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
 1638:                                 }
 1639:                             }
 1640:                         }
 1641: 	            } else {
 1642: 	                push(@warnings,&mt('As no section numbers are currently listed for "[_1]", automated enrollment will not occur for any sections of institutional course code: "[_2]".',$description,$newattr{'coursecode'}));
 1643: 	            }
 1644: 	            if ( (@xlists > 0) && ($changed{'owner'}) ) {
 1645: 	                foreach my $xlist (@xlists) {
 1646: 		            if ($xlist =~ m/^(.+):/) {
 1647:                                 my $instxlist = $1;
 1648:                                 my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'},$coowners);
 1649: 		                unless ($outcome eq 'ok') {
 1650: 			            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for crosslisted class "[_2]" for the following reason: "[_3]".',$description,$instxlist,$outcome));
 1651: 		                }
 1652: 		            }
 1653: 	                }
 1654: 	            }
 1655:                 }
 1656:             }
 1657:         }
 1658:     } else {
 1659:         foreach my $attr (@modifiable_params) {
 1660:             my $shown = $currattr{$attr};
 1661:             if ($attr eq 'selfenrollmgrdc') {
 1662:                 $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
 1663:             } elsif ($attr eq 'selfenrollmgrcc') {
 1664:                 $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
 1665:             } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
 1666:                 $shown = &mt('None');
 1667:             } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
 1668:                 $shown = &mt('domain default');
 1669:             }
 1670:             $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
 1671:         }
 1672:     }
 1673: 
 1674:     if (@changes > 0) {
 1675:         $chgresponse .= "</ul><br/><br/>";
 1676:     }
 1677:     if (@nochanges > 0) {
 1678:         $nochgresponse .=  "</ul><br/><br/>";
 1679:     }
 1680:     my ($warning,$numwarnings);
 1681:     my $numwarnings = scalar(@warnings); 
 1682:     if ($numwarnings) {
 1683:         $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
 1684:         foreach my $warn (@warnings) {
 1685:             $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
 1686:         }
 1687:         $warning .= '</ul></p>';
 1688:     }
 1689:     if ($response) {
 1690:         $reply = $response;
 1691:     } else {
 1692:         $reply = $chgresponse.$nochgresponse.$warning;
 1693:     }
 1694:     &print_header($r,$type);
 1695:     my $mainheader = &modifiable_only_title($type);
 1696:     $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
 1697:              '<p>'.$reply.'</p>'."\n".
 1698:              '<form action="/adm/modifycourse" method="post" name="processparms">'.
 1699:              &hidden_form_elements();
 1700:     my @actions =
 1701:         ('<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
 1702:                  &mt('Pick another action').'</a>');
 1703:     if ($numwarnings) {
 1704:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
 1705:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
 1706:                                              '=1&destinationurl=/adm/populate','&<>"');
 1707: 
 1708:         push(@actions, '<a href="'.$escuri.'">'.
 1709:                   &mt('Go to Automated Enrollment Manager for course').'</a>');
 1710:     }
 1711:     $reply .= &Apache::lonhtmlcommon::actionbox(\@actions).'</form>';
 1712:     $r->print($reply);
 1713:     return;
 1714: }
 1715: 
 1716: sub selfenroll_config_status {
 1717:     my ($items,$selfenrolltitles) = @_;
 1718:     my $shown;
 1719:     if ((ref($items) eq 'ARRAY') && (ref($selfenrolltitles) eq 'HASH')) {
 1720:         if (@{$items} > 0) {
 1721:             $shown = '<ul>';
 1722:             foreach my $item (@{$items}) {
 1723:                 $shown .= '<li>'.$selfenrolltitles->{$item}.'</li>';
 1724:             }
 1725:             $shown .= '</ul>';
 1726:         } else {
 1727:             $shown = &mt('None');
 1728:         }
 1729:     }
 1730:     return $shown;
 1731: }
 1732: 
 1733: sub update_coowners {
 1734:     my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
 1735:     return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
 1736:     my %designhash = &Apache::loncommon::get_domainconf($cdom);
 1737:     my (%cchash,$autocoowners);
 1738:     if ($designhash{$cdom.'.autoassign.co-owners'}) {
 1739:         $autocoowners = 1;
 1740:         %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
 1741:     }
 1742:     if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
 1743:         my $oldowner_to_coowner;
 1744:         my @types = ('co-owners');
 1745:         if (($newattr->{'coursecode'}) && ($autocoowners)) {
 1746:             my $oldowner = $settings->{'internal.courseowner'};
 1747:             if ($cchash{$oldowner.':cc'}) {
 1748:                 my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
 1749:                 if ($result eq 'valid') {
 1750:                     if ($settings->{'internal.co-owner'}) {
 1751:                         my @current = split(',',$settings->{'internal.co-owners'});
 1752:                         unless (grep(/^\Q$oldowner\E$/,@current)) {
 1753:                             $oldowner_to_coowner = 1;
 1754:                         }
 1755:                     } else {
 1756:                         $oldowner_to_coowner = 1;
 1757:                     }
 1758:                 }
 1759:             }
 1760:         } else {
 1761:             push(@types,'pendingco-owners');
 1762:         }
 1763:         foreach my $type (@types) {
 1764:             if ($settings->{'internal.'.$type}) {
 1765:                 my @current = split(',',$settings->{'internal.'.$type});
 1766:                 my $newowner = $newattr->{'courseowner'};
 1767:                 my @newvalues = ();
 1768:                 if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
 1769:                     foreach my $person (@current) {
 1770:                         unless ($person eq $newowner) {
 1771:                             push(@newvalues,$person);
 1772:                         }
 1773:                     }
 1774:                 } else {
 1775:                     @newvalues = @current;
 1776:                 }
 1777:                 if ($oldowner_to_coowner) {
 1778:                     push(@newvalues,$settings->{'internal.courseowner'});
 1779:                     @newvalues = sort(@newvalues);
 1780:                 }
 1781:                 my $newownstr = join(',',@newvalues);
 1782:                 if ($newownstr ne $settings->{'internal.'.$type}) {
 1783:                     if ($type eq 'co-owners') {
 1784:                         my $deleted = '';
 1785:                         unless (@newvalues) {
 1786:                             $deleted = 1;
 1787:                         }
 1788:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
 1789:                                                         $deleted,@newvalues);
 1790:                     } else {
 1791:                         my $pendingcoowners;
 1792:                         my $cid = $cdom.'_'.$cnum;
 1793:                         if (@newvalues) {
 1794:                             $pendingcoowners = join(',',@newvalues);
 1795:                             my %pendinghash = (
 1796:                                 'internal.pendingco-owners' => $pendingcoowners,
 1797:                             );
 1798:                             my $putresult = &Apache::lonnet::put('environment',\%pendinghash,$cdom,$cnum);
 1799:                             if ($putresult eq 'ok') {
 1800:                                 if ($env{'course.'.$cid.'.num'} eq $cnum) {
 1801:                                     &Apache::lonnet::appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
 1802:                                 }
 1803:                             }
 1804:                         } else {
 1805:                             my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
 1806:                             if ($delresult eq 'ok') {
 1807:                                 if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
 1808:                                     &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
 1809:                                 }
 1810:                             }
 1811:                         }
 1812:                     }
 1813:                 } elsif ($oldowner_to_coowner) {
 1814:                     &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
 1815:                                          $settings->{'internal.courseowner'});
 1816: 
 1817:                 }
 1818:             } elsif ($oldowner_to_coowner) {
 1819:                 &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
 1820:                                      $settings->{'internal.courseowner'});
 1821:             }
 1822:         }
 1823:     }
 1824:     if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
 1825:         if ($newattr->{'coursecode'} ne '') {
 1826:             my %designhash = &Apache::loncommon::get_domainconf($cdom);
 1827:             if ($designhash{$cdom.'.autoassign.co-owners'}) {
 1828:                 my @newcoowners = ();
 1829:                 if ($settings->{'internal.co-owners'}) {
 1830:                     my @currcoown = split(',',$settings->{'internal.co-owners'});
 1831:                     my ($updatecoowners,$delcoowners);
 1832:                     foreach my $person (@currcoown) {
 1833:                         my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
 1834:                         if ($result eq 'valid') {
 1835:                             push(@newcoowners,$person);
 1836:                         }
 1837:                     }
 1838:                     foreach my $item (sort(keys(%cchash))) {
 1839:                         my ($uname,$udom,$urole) = split(':',$item);
 1840:                         next if ($uname.':'.$udom eq $newattr->{'courseowner'});
 1841:                         unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
 1842:                             my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
 1843:                             if ($result eq 'valid') {
 1844:                                 push(@newcoowners,$uname.':'.$udom);
 1845:                             }
 1846:                         }
 1847:                     }
 1848:                     if (@newcoowners) {
 1849:                         my $coowners = join(',',sort(@newcoowners));
 1850:                         unless ($coowners eq $settings->{'internal.co-owners'}) {
 1851:                             $updatecoowners = 1;
 1852:                         }
 1853:                     } else {
 1854:                         $delcoowners = 1;
 1855:                     }
 1856:                     if ($updatecoowners || $delcoowners) {
 1857:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
 1858:                                                         $delcoowners,@newcoowners);
 1859:                     }
 1860:                 } else {
 1861:                     foreach my $item (sort(keys(%cchash))) {
 1862:                         my ($uname,$udom,$urole) = split(':',$item);
 1863:                         push(@newcoowners,$uname.':'.$udom);
 1864:                     }
 1865:                     if (@newcoowners) {
 1866:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
 1867:                                                         @newcoowners);
 1868:                     }
 1869:                 }
 1870:             }
 1871:         }
 1872:     }
 1873:     return;
 1874: }
 1875: 
 1876: sub modify_quota {
 1877:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
 1878:     &print_header($r,$type);
 1879:     my $lctype = lc($type);
 1880:     my $headline = &mt("Disk space quotas for $lctype: [_1]",
 1881:                      '<span class="LC_nobreak">'.$cdesc.'</span>');
 1882:     $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
 1883:               '<h3>'.$headline.'</h3>');
 1884:     my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
 1885:     my %staticdefaults = (
 1886:                            coursequota   => 20,
 1887:                            uploadquota   => 500,
 1888:                          );
 1889:     my %default;
 1890:     $default{'coursequota'} = $staticdefaults{'coursequota'};
 1891:     my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
 1892:     $default{'uploadquota'} = $domdefs{'uploadquota'};
 1893:     if ($default{'uploadquota'} eq '') {
 1894:         $default{'uploadquota'} = $staticdefaults{'uploadquota'};
 1895:     }
 1896:     my (%cenv,%showresult);
 1897:     foreach my $item ('coursequota','uploadquota') {
 1898:         if ($env{'form.'.$item} ne '') {
 1899:             my $newquota = $env{'form.'.$item};
 1900:             if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
 1901:                 $newquota = $1;
 1902:                 if ($oldsettings{'internal.'.$item} == $newquota) {
 1903:                     if ($item eq 'coursequota') {
 1904:                         $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] MB.',$newquota).'<br />');
 1905:                     } else {
 1906:                         $r->print(&mt('The disk space allocated for files uploaded via the Content Editor remains unchanged as [_1] MB.',$newquota).'<br />');
 1907:                     }
 1908:                 } else {
 1909:                     $cenv{'internal.'.$item} = $newquota;
 1910:                     $showresult{$item} = 1;
 1911:                 }
 1912:             } else {
 1913:                 if ($item eq 'coursequota') { 
 1914:                     $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'<br />');
 1915:                 } else {
 1916:                     $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'<br />');
 1917: 
 1918:                 }
 1919:             }
 1920:         }
 1921:     }
 1922:     if (keys(%cenv)) {
 1923:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
 1924:                                             $cnum);
 1925:         foreach my $key (sort(keys(%showresult))) {
 1926:             if (($oldsettings{'internal.'.$key} eq '') && 
 1927:                 ($env{'form.'.$key} == $default{$key})) {
 1928:                 if ($key eq 'uploadquota') {
 1929:                     if ($type eq 'Community') {
 1930:                         $r->print(&mt('The disk space allocated for files uploaded to this community via the Content Editor is the default quota for this domain: [_1] MB.',
 1931:                                       $default{$key}).'<br />');
 1932:                     } else {
 1933:                         $r->print(&mt('The disk space allocated for files uploaded to this course via the Content Editor is the default quota for this domain: [_1] MB.',
 1934:                                       $default{$key}).'<br />');
 1935:                     }
 1936:                 } else { 
 1937:                     if ($type eq 'Community') {
 1938:                         $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.',
 1939:                                       $default{$key}).'<br />');
 1940:                     } else {
 1941:                         $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] MB.',
 1942:                                       $default{$key}).'<br />');
 1943:                     }
 1944:                 }
 1945:                 delete($showresult{$key});
 1946:             }
 1947:         }
 1948:         if ($putreply eq 'ok') {
 1949:             my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
 1950:             if ($showresult{'coursequota'}) {
 1951:                 $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] MB.',
 1952:                               '<b>'.$updatedsettings{'internal.coursequota'}.'</b>').'<br />');
 1953:                 my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
 1954:                 if ($usage >= $updatedsettings{'internal.coursequota'}) {
 1955:                     my $newoverquota;
 1956:                     if ($usage < $oldsettings{'internal.coursequota'}) {
 1957:                         $newoverquota = 'now';
 1958:                     }
 1959:                     $r->print('<p>');
 1960:                     if ($type eq 'Community') {
 1961:                         $r->print(&mt("Disk usage $newoverquota exceeds the quota for this community.").' '.
 1962:                                   &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the community will not be possible until some files have been deleted, and total usage is below community quota.'));
 1963:                     } else {
 1964:                         $r->print(&mt("Disk usage $newoverquota exceeds the quota for this course.").' '.
 1965:                                   &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the course will not be possible until some files have been deleted, and total usage is below course quota.'));
 1966:                     }
 1967:                     $r->print('</p>');
 1968:                 }
 1969:             }
 1970:             if ($showresult{'uploadquota'}) {
 1971:                 $r->print(&mt('The disk space allocated for content uploaded directly via the Content Editor is now: [_1] MB.',
 1972:                               '<b>'.$updatedsettings{'internal.uploadquota'}.'</b>').'<br />');
 1973:             }
 1974:         } else {
 1975:             $r->print(&mt('An error occurred storing the quota(s) for group portfolio files and/or uploaded content: ').
 1976:                       $putreply);
 1977:         }
 1978:     }
 1979:     $r->print('<p>'.
 1980:               '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
 1981:               &mt('Pick another action').'</a>');
 1982:     $r->print(&hidden_form_elements().'</form>');
 1983:     return;
 1984: }
 1985: 
 1986: sub modify_anonsurvey_threshold {
 1987:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
 1988:     &print_header($r,$type);
 1989:     $r->print('<form action="/adm/modifycourse" method="post" name="processthreshold">'."\n".
 1990:               '<h3>'.&mt('Responder threshold required for display of anonymous survey submissions:').
 1991:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
 1992:     my %oldsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
 1993:     my %domconfig =
 1994:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
 1995:     my $defaultthreshold; 
 1996:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 1997:         $defaultthreshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
 1998:         if ($defaultthreshold eq '') {
 1999:             $defaultthreshold = 10;
 2000:         }
 2001:     } else {
 2002:         $defaultthreshold = 10;
 2003:     }
 2004:     if ($env{'form.threshold'} eq '') {
 2005:         $r->print(&mt('The proposed responder threshold for display of anonymous survey submissions was blank, so the threshold is unchanged.'));
 2006:     } else {
 2007:         my $newthreshold = $env{'form.threshold'};
 2008:         if ($newthreshold =~ /^\s*(\d+)\s*$/) {
 2009:             $newthreshold = $1;
 2010:             if ($oldsettings{'internal.anonsurvey_threshold'} eq $env{'form.threshold'}) {
 2011:                 $r->print(&mt('Responder threshold for anonymous survey submissions display remains unchanged: [_1].',$env{'form.threshold'}));
 2012:             } else {
 2013:                 my %cenv = (
 2014:                            'internal.anonsurvey_threshold' => $env{'form.threshold'},
 2015:                            );
 2016:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
 2017:                                                     $cnum);
 2018:                 if ($putreply eq 'ok') {
 2019:                     if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
 2020:                         &Apache::lonnet::appenv(
 2021:                            {'course.'.$cdom.'_'.$cnum.'.internal.anonsurvey_threshold' => $env{'form.threshold'}});
 2022:                     }
 2023:                 }
 2024:                 if (($oldsettings{'internal.anonsurvey_threshold'} eq '') &&
 2025:                     ($env{'form.threshold'} == $defaultthreshold)) {
 2026:                     $r->print(&mt('The responder threshold for display of anonymous survey submissions is the default for this domain: [_1].',$defaultthreshold));
 2027:                 } else {
 2028:                     if ($putreply eq 'ok') {
 2029:                         my %updatedsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
 2030:                         $r->print(&mt('The responder threshold for display of anonymous survey submissions is now: [_1].','<b>'.$updatedsettings{'internal.anonsurvey_threshold'}.'</b>'));
 2031:                     } else {
 2032:                         $r->print(&mt('An error occurred storing the responder threshold for anonymous submissions display: ').
 2033:                                   $putreply);
 2034:                     }
 2035:                 }
 2036:             }
 2037:         } else {
 2038:             $r->print(&mt('The proposed responder threshold for display of anonymous submissions contained invalid characters, so the threshold is unchanged.'));
 2039:         }
 2040:     }
 2041:     $r->print('<p>'.
 2042:               '<a href="javascript:changePage(document.processthreshold,'."'menu'".')">'.
 2043:               &mt('Pick another action').'</a></p>');
 2044:     $r->print(&hidden_form_elements().'</form>');
 2045:     return;
 2046: }
 2047: 
 2048: sub modify_postsubmit_config {
 2049:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
 2050:     &print_header($r,$type);
 2051:     my %lt = &Apache::lonlocal::texthash(
 2052:                 subb => 'Submit button behavior after student makes a submission:',
 2053:                 unch => 'Post submission behavior of the Submit button is unchanged.',
 2054:                 erro => 'An error occurred when saving your proposed changes.',
 2055:                 inva => 'An invalid response was recorded.',
 2056:                 pick => 'Pick another action',
 2057:              );
 2058:     $r->print('<form action="/adm/modifycourse" method="post" name="processpostsubmit">'."\n".
 2059:               '<h3>'.$lt{'subb'}.' <span class="LC_nobreak">('.$cdesc.')</span></h3><br />');
 2060:     my %oldsettings = 
 2061:         &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout','internal.coursecode','internal.textbook'],$cdom,$cnum);
 2062:     my $postsubmit = $env{'form.postsubmit'};
 2063:     if ($postsubmit eq '1') {
 2064:         my $postsubtimeout = $env{'form.postsubtimeout'};
 2065:         $postsubtimeout =~ s/[^\d\.]+//g;
 2066:         if (($oldsettings{'internal.postsubmit'} eq $postsubmit) && ($oldsettings{'internal.postsubtimeout'} eq $postsubtimeout)) {
 2067:             $r->print($lt{'unch'}); 
 2068:         } else {
 2069:             my %cenv = (
 2070:                          'internal.postsubmit' => $postsubmit,
 2071:                        );
 2072:             if ($postsubtimeout eq '') {
 2073:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 2074:                 if ($putreply eq 'ok') {
 2075:                     my $defaulttimeout = &domain_postsubtimeout($cdom,$type,\%oldsettings);
 2076:                     $r->print(&mt('The proposed duration for disabling the Submit button post-submission was blank, so the domain default of [quant,_1,second] will be used.',$defaulttimeout));
 2077:                     if (exists($oldsettings{'internal.postsubtimeout'})) {
 2078:                         &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);
 2079:                     }
 2080:                 } else {
 2081:                     $r->print($lt{'erro'});
 2082:                 }
 2083:             } else { 
 2084:                 $cenv{'internal.postsubtimeout'} = $postsubtimeout;
 2085:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 2086:                 if ($putreply eq 'ok') {
 2087:                     if ($postsubtimeout eq '0') {
 2088:                         $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.')); 
 2089:                     } else {
 2090:                         $r->print(&mt('Submit button will be disabled after student submission for [quant,_1,second].',$postsubtimeout));
 2091:                     }
 2092:                 } else {
 2093:                     $r->print($lt{'erro'});
 2094:                 }
 2095:             }
 2096:         }
 2097:     } elsif ($postsubmit eq '0') {
 2098:         if ($oldsettings{'internal.postsubmit'} eq $postsubmit) {
 2099:             $r->print($lt{'unch'});
 2100:         } else {
 2101:             if (exists($oldsettings{'internal.postsubtimeout'})) {
 2102:                 &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);  
 2103:             }
 2104:             my %cenv = (
 2105:                          'internal.postsubmit' => $postsubmit,
 2106:                        );
 2107:             my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 2108:             if ($putreply eq 'ok') {
 2109:                 $r->print(&mt('Submit button will not be disabled after student submission'));
 2110:             } else {
 2111:                 $r->print($lt{'erro'});
 2112:             }
 2113:         }
 2114:     } else {
 2115:         $r->print($lt{'inva'}.' '.$lt{'unch'});
 2116:     }
 2117:     $r->print('<p>'.
 2118:               '<a href="javascript:changePage(document.processpostsubmit,'."'menu'".')">'.
 2119:               &mt('Pick another action').'</a></p>');
 2120:     $r->print(&hidden_form_elements().'</form>');
 2121:     return;
 2122: }
 2123: 
 2124: sub modify_catsettings {
 2125:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
 2126:     &print_header($r,$type);
 2127:     my ($ccrole,%desc);
 2128:     if ($type eq 'Community') {
 2129:         $desc{'hidefromcat'} = &mt('Excluded from community catalog');
 2130:         $desc{'categories'} = &mt('Assigned categories for this community');
 2131:         $ccrole = 'co';
 2132:     } else {
 2133:         $desc{'hidefromcat'} = &mt('Excluded from course catalog');
 2134:         $desc{'categories'} = &mt('Assigned categories for this course');
 2135:         $ccrole = 'cc';
 2136:     }
 2137:     $r->print('
 2138: <form action="/adm/modifycourse" method="post" name="processcat">
 2139: <h3>'.&mt('Category settings').'</h3>');
 2140:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
 2141:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
 2142:     if (@cat_params > 0) {
 2143:         my (%cenv,@changes,@nochanges);
 2144:         my %currsettings =
 2145:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
 2146:         my (@newcategories,%showitem); 
 2147:         if (grep(/^togglecats$/,@cat_params)) {
 2148:             if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
 2149:                 push(@changes,'hidefromcat');
 2150:                 $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
 2151:             } else {
 2152:                 push(@nochanges,'hidefromcat');
 2153:             }
 2154:             if ($env{'form.hidefromcat'} eq 'yes') {
 2155:                 $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
 2156:             } else {
 2157:                 $showitem{'hidefromcat'} = '"'.&mt('No').'"';
 2158:             }
 2159:         }
 2160:         if (grep(/^categorize$/,@cat_params)) {
 2161:             my (@cats,@trails,%allitems,%idx,@jsarray);
 2162:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
 2163:                 my $cathash = $domconf{'coursecategories'}{'cats'};
 2164:                 if (ref($cathash) eq 'HASH') {
 2165:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 2166:                                                            \%allitems,\%idx,\@jsarray);
 2167:                 }
 2168:             }
 2169:             @newcategories =  &Apache::loncommon::get_env_multiple('form.usecategory');
 2170:             if (@newcategories == 0) {
 2171:                 $showitem{'categories'} = '"'.&mt('None').'"';
 2172:             } else {
 2173:                 $showitem{'categories'} = '<ul>';
 2174:                 foreach my $item (@newcategories) {
 2175:                     $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
 2176:                 }
 2177:                 $showitem{'categories'} .= '</ul>';
 2178:             }
 2179:             my $catchg = 0;
 2180:             if ($currsettings{'categories'} ne '') {
 2181:                 my @currcategories = split('&',$currsettings{'categories'});
 2182:                 foreach my $cat (@currcategories) {
 2183:                     if (!grep(/^\Q$cat\E$/,@newcategories)) {
 2184:                         $catchg = 1;
 2185:                         last;
 2186:                     }
 2187:                 }
 2188:                 if (!$catchg) {
 2189:                     foreach my $cat (@newcategories) {
 2190:                         if (!grep(/^\Q$cat\E$/,@currcategories)) {
 2191:                             $catchg = 1;
 2192:                             last;                     
 2193:                         } 
 2194:                     } 
 2195:                 }
 2196:             } else {
 2197:                 if (@newcategories > 0) {
 2198:                     $catchg = 1;
 2199:                 }
 2200:             }
 2201:             if ($catchg) {
 2202:                 $cenv{'categories'} = join('&',@newcategories);
 2203:                 push(@changes,'categories');
 2204:             } else {
 2205:                 push(@nochanges,'categories');
 2206:             }
 2207:             if (@changes > 0) {
 2208:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 2209:                 if ($putreply eq 'ok') {
 2210:                     if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
 2211:                         my %newenvhash;
 2212:                         foreach my $item (@changes) {
 2213:                             $newenvhash{'course.'.$cdom.'_'.$cnum.'.'.$item} = $cenv{$item};
 2214:                         }
 2215:                         &Apache::lonnet::appenv(\%newenvhash);
 2216:                     }
 2217:                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
 2218:                                                                 $cnum,undef,undef,'.');
 2219:                     if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
 2220:                         if (grep(/^hidefromcat$/,@changes)) {
 2221:                             $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
 2222:                         }
 2223:                         if (grep(/^categories$/,@changes)) {
 2224:                             $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
 2225:                         }
 2226:                         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
 2227:                         my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
 2228:                     }
 2229:                     $r->print(&mt('The following changes occurred:').'<ul>');
 2230:                     foreach my $item (@changes) {
 2231:                         $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
 2232:                     }
 2233:                     $r->print('</ul><br />');
 2234:                 }
 2235:             }
 2236:             if (@nochanges > 0) {
 2237:                 $r->print(&mt('The following were unchanged:').'<ul>');
 2238:                 foreach my $item (@nochanges) {
 2239:                     $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
 2240:                 }
 2241:                 $r->print('</ul>');
 2242:             }
 2243:         }
 2244:     } else {
 2245:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
 2246:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
 2247:                                              '=1&destinationurl=/adm/courseprefs','&<>"');
 2248:         if ($type eq 'Community') {
 2249:             $r->print(&mt('Category settings for communities in this domain should be modified in community context (via "[_1]Community Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
 2250:         } else {
 2251:             $r->print(&mt('Category settings for courses in this domain should be modified in course context (via "[_1]Course Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
 2252:         }
 2253:     }
 2254:     $r->print('<br />'."\n".
 2255:               '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
 2256:               &mt('Pick another action').'</a>');
 2257:     $r->print(&hidden_form_elements().'</form>');
 2258:     return;
 2259: }
 2260: 
 2261: sub print_header {
 2262:     my ($r,$type,$javascript_validations) = @_;
 2263:     my $phase = "start";
 2264:     if ( exists($env{'form.phase'}) ) {
 2265:         $phase = $env{'form.phase'};
 2266:     }
 2267:     my $js = qq|
 2268: 
 2269: function changePage(formname,newphase) {
 2270:     formname.phase.value = newphase;
 2271:     if (newphase == 'processparms') {
 2272:         return;
 2273:     }
 2274:     formname.submit();
 2275: }
 2276: 
 2277: |;
 2278:     if ($phase eq 'setparms') {
 2279: 	$js .= $javascript_validations;
 2280:     } elsif ($phase eq 'courselist') {
 2281:         $js .= <<"ENDJS";
 2282: function hide_searching() {
 2283:     if (document.getElementById('searching')) {
 2284:         document.getElementById('searching').style.display = 'none';
 2285:     }
 2286:     return;
 2287: }
 2288: 
 2289: ENDJS
 2290:     } elsif ($phase eq 'setquota') {
 2291:         my $invalid = &mt('The quota you entered contained invalid characters.');
 2292:         my $alert = &mt('You must enter a number');
 2293:         &js_escape(\$invalid);
 2294:         &js_escape(\$alert);
 2295:         my $regexp = '/^\s*(\d+\.?\d*|\.\d+)\s*$/';
 2296:         $js .= <<"ENDSCRIPT";
 2297: 
 2298: function verify_quota() {
 2299:     var newquota = document.setquota.coursequota.value; 
 2300:     var num_reg = $regexp;
 2301:     if (num_reg.test(newquota)) {
 2302:         changePage(document.setquota,'processquota');
 2303:     } else {
 2304:         alert("$invalid\\n$alert");
 2305:         return false;
 2306:     }
 2307:     return true;
 2308: }
 2309: 
 2310: ENDSCRIPT
 2311:     } elsif ($phase eq 'setanon') {
 2312:         my $invalid = &mt('The responder threshold you entered is invalid.');
 2313:         my $alert = &mt('You must enter a positive integer.');
 2314:         &js_escape(\$invalid);
 2315:         &js_escape(\$alert);
 2316:         my $regexp = ' /^\s*\d+\s*$/';
 2317:         $js .= <<"ENDSCRIPT";
 2318: 
 2319: function verify_anon_threshold() {
 2320:     var newthreshold = document.setanon.threshold.value;
 2321:     var num_reg = $regexp;
 2322:     if (num_reg.test(newthreshold)) {
 2323:         if (newthreshold > 0) {
 2324:             changePage(document.setanon,'processthreshold');
 2325:         } else {
 2326:             alert("$invalid\\n$alert");
 2327:             return false;
 2328:         }
 2329:     } else {
 2330:         alert("$invalid\\n$alert");
 2331:         return false;
 2332:     }
 2333:     return true;
 2334: }
 2335: 
 2336: ENDSCRIPT
 2337:     } elsif ($phase eq 'setpostsubmit') {
 2338:         my $invalid = &mt('The choice entered for disabling the submit button is invalid.');
 2339:         my $invalidtimeout = &mt('The timeout you entered for disabling the submit button is invalid.');
 2340:         my $alert = &mt('Enter one of: a positive integer, 0 (for no timeout), or leave blank to use domain default');
 2341:         &js_escape(\$invalid);
 2342:         &js_escape(\$invalidtimeout);
 2343:         &js_escape(\$alert);
 2344:         my $regexp = ' /^\s*\d+\s*$/';
 2345: 
 2346:         $js .= <<"ENDSCRIPT"; 
 2347: 
 2348: function verify_postsubmit() {
 2349:     var optionsElement = document.setpostsubmit.postsubmit;
 2350:     var verified = '';
 2351:     if (optionsElement.length) {
 2352:         var currval;
 2353:         for (var i=0; i<optionsElement.length; i++) {
 2354:             if (optionsElement[i].checked) {
 2355:                currval = optionsElement[i].value;
 2356:             }
 2357:         }
 2358:         if (currval == 1) {
 2359:             var newtimeout = document.setpostsubmit.postsubtimeout.value;
 2360:             if (newtimeout == '') {
 2361:                 verified = 'ok';
 2362:             } else {
 2363:                 var num_reg = $regexp;
 2364:                 if (num_reg.test(newtimeout)) {
 2365:                     if (newtimeout>= 0) {
 2366:                         verified = 'ok';
 2367:                     } else {
 2368:                         alert("$invalidtimeout\\n$alert");
 2369:                         return false;
 2370:                     }
 2371:                 } else {
 2372:                     alert("$invalid\\n$alert");
 2373:                     return false;
 2374:                 }
 2375:             }
 2376:         } else {
 2377:             if (currval == 0) {
 2378:                verified = 'ok'; 
 2379:             } else {
 2380:                alert('$invalid');
 2381:                return false;
 2382:             }
 2383:         }
 2384:         if (verified == 'ok') {
 2385:             changePage(document.setpostsubmit,'processpostsubmit');
 2386:             return true;
 2387:         }
 2388:     }
 2389:     return false;
 2390: }
 2391: 
 2392: function togglePostsubmit(caller) {
 2393:     var optionsElement = document.setpostsubmit.postsubmit;
 2394:     if (document.getElementById(caller)) {
 2395:         var divitem = document.getElementById(caller);
 2396:         var optionsElement = document.setpostsubmit.postsubmit; 
 2397:         if (optionsElement.length) {
 2398:             var currval;
 2399:             for (var i=0; i<optionsElement.length; i++) {
 2400:                 if (optionsElement[i].checked) {
 2401:                    currval = optionsElement[i].value;
 2402:                 }
 2403:             }
 2404:             if (currval == 1) {
 2405:                 divitem.style.display = 'block';
 2406:             } else {
 2407:                 divitem.style.display = 'none';
 2408:             }
 2409:         }
 2410:     }
 2411:     return;
 2412: }
 2413: 
 2414: ENDSCRIPT
 2415: 
 2416:     }
 2417:     my $starthash;
 2418:     if ($env{'form.phase'} eq 'adhocrole') {
 2419:         $starthash = {
 2420:            add_entries => {'onload' => "javascript:document.adhocrole.submit();"},
 2421:                      };
 2422:     } elsif ($phase eq 'courselist') {
 2423:         $starthash = {
 2424:            add_entries => {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"},
 2425:                      };
 2426:     }
 2427:     $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
 2428: 					     &Apache::lonhtmlcommon::scripttag($js),
 2429:                                              $starthash));
 2430:     my $bread_text = "View/Modify Courses/Communities";
 2431:     if ($type eq 'Community') {
 2432:         $bread_text = 'Community Settings';
 2433:     } elsif ($type eq 'Placement') {
 2434:         $bread_text = 'Placement Test Settings';
 2435:     } else {
 2436:         $bread_text = 'Course Settings';
 2437:     }
 2438:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
 2439:     return;
 2440: }
 2441: 
 2442: sub print_footer {
 2443:     my ($r) = @_;
 2444:     $r->print('<br />'.&Apache::loncommon::end_page());
 2445:     return;
 2446: }
 2447: 
 2448: sub check_course {
 2449:     my ($dom,$domdesc) = @_;
 2450:     my ($ok_course,$description,$instcode);
 2451:     my %coursehash;
 2452:     if ($env{'form.pickedcourse'} =~ /^$match_domain\_$match_courseid$/) {
 2453:         my %args;
 2454:         unless ($env{'course.'.$env{'form.pickedcourse'}.'.description'}) {
 2455:             %args = (
 2456:                       'one_time'      => 1,
 2457:                       'freshen_cache' => 1,
 2458:                     );
 2459:         }
 2460:         %coursehash =
 2461:            &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
 2462:         my $cnum = $coursehash{'num'};
 2463:         my $cdom = $coursehash{'domain'};
 2464:         $description = $coursehash{'description'};
 2465:         $instcode = $coursehash{'internal.coursecode'};
 2466:         if ($instcode) {
 2467:             $description .= " ($instcode)";
 2468:         }
 2469:         if (($cdom eq $dom) && ($cnum =~ /^$match_courseid$/)) {
 2470:             my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
 2471:                                                           $cnum,undef,undef,'.');
 2472:             if ($courseIDs{$cdom.'_'.$cnum}) {
 2473:                 $ok_course = 'ok';
 2474:             }
 2475:         }
 2476:     }
 2477:     return ($ok_course,$description,\%coursehash);
 2478: }
 2479: 
 2480: sub course_settings_descrip {
 2481:     my ($type) = @_;
 2482:     my %longtype;
 2483:     if ($type eq 'Community') {
 2484:          %longtype = &Apache::lonlocal::texthash(
 2485:                       'courseowner'      => "Username:domain of community owner",
 2486:                       'co-owners'        => "Username:domain of each co-owner",
 2487:                       'selfenrollmgrdc'  => "Community-specific self-enrollment configuration by Domain Coordinator",
 2488:                       'selfenrollmgrcc'  => "Community-specific self-enrollment configuration by Community personnel",
 2489:                       'mysqltables'      => '"Temporary" student performance tables lifetime (seconds)',
 2490:          );
 2491:     } else {
 2492:          %longtype = &Apache::lonlocal::texthash(
 2493:                       'authtype' => 'Default authentication method',
 2494:                       'autharg'  => 'Default authentication parameter',
 2495:                       'autoadds' => 'Automated adds',
 2496:                       'autodrops' => 'Automated drops',
 2497:                       'autostart' => 'Date of first automated enrollment',
 2498:                       'autoend' => 'Date of last automated enrollment',
 2499:                       'default_enrollment_start_date' => 'Date of first student access',
 2500:                       'default_enrollment_end_date' => 'Date of last student access',
 2501:                       'coursecode' => 'Official course code',
 2502:                       'courseowner' => "Username:domain of course owner",
 2503:                       'co-owners'   => "Username:domain of each co-owner",
 2504:                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
 2505:                       'sectionnums' => 'Course section number:LON-CAPA section',
 2506:                       'crosslistings' => 'Crosslisted class:LON-CAPA section',
 2507:                       'defaultcredits' => 'Credits',
 2508:                       'autodropfailsafe' => "Failsafe section enrollment count",
 2509:                       'selfenrollmgrdc'  => "Course-specific self-enrollment configuration by Domain Coordinator",
 2510:                       'selfenrollmgrcc'  => "Course-specific self-enrollment configuration by Course personnel",
 2511:                       'mysqltables'      => '"Temporary" student performance tables lifetime (seconds)',
 2512:                       'nopasswdchg' => 'Disable changing password for users with student role by course owner',
 2513:          );
 2514:     }
 2515:     return %longtype;
 2516: }
 2517: 
 2518: sub hidden_form_elements {
 2519:     my $hidden_elements = 
 2520:       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
 2521:           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
 2522:           'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
 2523:           'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
 2524:           'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
 2525:           'sections','newsec','mysqltables','nopasswdchg'],
 2526:           ['^selfenrollmgr_','^selfenroll_'])."\n".
 2527:           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
 2528:     return $hidden_elements;
 2529: }
 2530: 
 2531: sub showcredits {
 2532:     my ($dom) = @_;
 2533:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 2534:     if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
 2535:         return 1;
 2536:     }
 2537: }
 2538: 
 2539: sub get_permission {
 2540:     my ($dom) = @_;
 2541:     my ($allowed,%permission);
 2542:     my %passwdconf = &Apache::lonnet::get_passwdconf($dom);
 2543:     if (&Apache::lonnet::allowed('ccc',$dom)) {
 2544:         $allowed = 1;
 2545:         %permission = (
 2546:             setquota          => 'edit',
 2547:             processquota      => 'edit',
 2548:             setanon           => 'edit',
 2549:             processthreshold  => 'edit',
 2550:             setpostsubmit     => 'edit',
 2551:             processpostsubmit => 'edit',
 2552:             viewparms         => 'view',
 2553:             setparms          => 'edit',
 2554:             processparms      => 'edit',
 2555:             catsettings       => 'edit',
 2556:             processcat        => 'edit',
 2557:             selfenroll        => 'edit',
 2558:             adhocrole         => 'coord',
 2559:         );
 2560:         if ($passwdconf{'crsownerchg'}) {
 2561:             $permission{passwdchg} = 'edit';
 2562:         }
 2563:     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
 2564:         $allowed = 1;
 2565:         %permission = (
 2566:             setquota      => 'view',
 2567:             viewparms     => 'view',
 2568:             setanon       => 'view',
 2569:             setpostsubmit => 'view',
 2570:             setparms      => 'view',
 2571:             catsettings   => 'view',
 2572:             selfenroll    => 'view',
 2573:             adhocrole     => 'custom',
 2574:         );
 2575:         if ($passwdconf{'crsownerchg'}) {
 2576:             $permission{passwdchg} = 'view';
 2577:         }
 2578:     }
 2579:     return ($allowed,\%permission);
 2580: }
 2581: 
 2582: sub devalidate_remote_instcats {
 2583:     if ($modified_dom ne '') {
 2584:         my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
 2585:         my %thismachine;
 2586:         map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
 2587:         if (keys(%servers)) {
 2588:             foreach my $server (keys(%servers)) {
 2589:                 next if ($thismachine{$server});
 2590:                 &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
 2591:             }
 2592:         }
 2593:         $modified_dom = '';
 2594:     }
 2595:     return;
 2596: }
 2597: 
 2598: sub handler {
 2599:     my $r = shift;
 2600:     if ($r->header_only) {
 2601:         &Apache::loncommon::content_type($r,'text/html');
 2602:         $r->send_http_header;
 2603:         return OK;
 2604:     }
 2605: 
 2606:     $registered_cleanup=0;
 2607:     $modified_dom = '';
 2608: 
 2609:     my $dom = $env{'request.role.domain'};
 2610:     my $domdesc = &Apache::lonnet::domain($dom,'description');
 2611:     my ($allowed,$permission) = &get_permission($dom);
 2612:     if ($allowed) {
 2613:         &Apache::loncommon::content_type($r,'text/html');
 2614:         $r->send_http_header;
 2615: 
 2616:         &Apache::lonhtmlcommon::clear_breadcrumbs();
 2617: 
 2618:         my $phase = $env{'form.phase'};
 2619:         if ($env{'form.updater'}) {
 2620:             $phase = '';
 2621:         }
 2622:         if ($phase eq '') {
 2623:             &Apache::lonhtmlcommon::add_breadcrumb
 2624:             ({href=>"/adm/modifycourse",
 2625:               text=>"Course/Community search"});
 2626:             &print_course_search_page($r,$dom,$domdesc);
 2627:         } else {
 2628:             my $firstform = $phase;
 2629:             if ($phase eq 'courselist') {
 2630:                 $firstform = 'filterpicker';
 2631:             }
 2632:             my $choose_text;
 2633:             my $type = $env{'form.type'};
 2634:             if ($type eq '') {
 2635:                 $type = 'Course';
 2636:             }
 2637:             if ($type eq 'Community') {
 2638:                 $choose_text = "Choose a community";
 2639:             } elsif ($type eq 'Placement') {
 2640:                 $choose_text = "Choose a placement test";
 2641:             } else {
 2642:                 $choose_text = "Choose a course";
 2643:             } 
 2644:             &Apache::lonhtmlcommon::add_breadcrumb
 2645:             ({href=>"javascript:changePage(document.$firstform,'')",
 2646:               text=>"Course/Community search"},
 2647:               {href=>"javascript:changePage(document.$phase,'courselist')",
 2648:               text=>$choose_text});
 2649:             if ($phase eq 'courselist') {
 2650:                 &print_course_selection_page($r,$dom,$domdesc,$permission);
 2651:             } else {
 2652:                 my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc);
 2653:                 if ($checked eq 'ok') {
 2654:                     my $enter_text;
 2655:                     if ($type eq 'Community') {
 2656:                         $enter_text = 'Enter community';
 2657:                     } elsif ($type eq 'Placement') {
 2658:                         $enter_text = 'Enter placement test'; 
 2659:                     } else {
 2660:                         $enter_text = 'Enter course';
 2661:                     }
 2662:                     if ($phase eq 'menu') {
 2663:                         &Apache::lonhtmlcommon::add_breadcrumb
 2664:                         ({href=>"javascript:changePage(document.$phase,'menu')",
 2665:                           text=>"Pick action"});
 2666:                         &print_modification_menu($r,$cdesc,$domdesc,$dom,$type,
 2667:                                                  $env{'form.pickedcourse'},$coursehash,
 2668:                                                  $permission);
 2669:                     } elsif ($phase eq 'adhocrole') {
 2670:                         &Apache::lonhtmlcommon::add_breadcrumb
 2671:                          ({href=>"javascript:changePage(document.$phase,'adhocrole')",
 2672:                            text=>$enter_text});
 2673:                         &print_adhocrole_selected($r,$type,$permission);
 2674:                     } else {
 2675:                         &Apache::lonhtmlcommon::add_breadcrumb
 2676:                         ({href=>"javascript:changePage(document.$phase,'menu')",
 2677:                           text=>"Pick action"});
 2678:                         my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
 2679:                         my ($readonly,$linktext);
 2680:                         if ($permission->{$phase} eq 'view') {
 2681:                            $readonly = 1; 
 2682:                         }
 2683:                         if (($phase eq 'setquota') && ($permission->{'setquota'})) {
 2684:                             if ($permission->{'setquota'} eq 'view') {
 2685:                                 $linktext = 'Set quota'; 
 2686:                             } else {
 2687:                                 $linktext = 'Display quota';
 2688:                             }
 2689:                             &Apache::lonhtmlcommon::add_breadcrumb
 2690:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2691:                               text=>$linktext});
 2692:                             &print_setquota($r,$cdom,$cnum,$cdesc,$type,$readonly);
 2693:                         } elsif (($phase eq 'processquota') && ($permission->{'processquota'})) { 
 2694:                             &Apache::lonhtmlcommon::add_breadcrumb
 2695:                             ({href=>"javascript:changePage(document.$phase,'setquota')",
 2696:                               text=>"Set quota"});
 2697:                             &Apache::lonhtmlcommon::add_breadcrumb
 2698:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2699:                               text=>"Result"});
 2700:                             &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 2701:                         } elsif (($phase eq 'setanon') && ($permission->{'setanon'})) {
 2702:                             &Apache::lonhtmlcommon::add_breadcrumb
 2703:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2704:                               text=>"Threshold for anonymous submissions display"});
 2705:                             &print_set_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$type,$readonly);
 2706:                         } elsif (($phase eq 'processthreshold') && ($permission->{'processthreshold'})) {
 2707:                             &Apache::lonhtmlcommon::add_breadcrumb
 2708:                             ({href=>"javascript:changePage(document.$phase,'setanon')",
 2709:                               text=>"Threshold for anonymous submissions display"});
 2710:                             &Apache::lonhtmlcommon::add_breadcrumb
 2711:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2712:                               text=>"Result"});
 2713:                             &modify_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 2714:                         } elsif (($phase eq 'setpostsubmit') && ($permission->{'setpostsubmit'})) {
 2715:                             if ($permission->{'setpostsubmit'} eq 'view') {
 2716:                                 $linktext = 'Submit button behavior post-submission';
 2717:                             } else {
 2718:                                 $linktext = 'Configure submit button behavior post-submission';
 2719:                             }
 2720:                             &Apache::lonhtmlcommon::add_breadcrumb
 2721:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2722:                               text=>$linktext});
 2723:                             &print_postsubmit_config($r,$cdom,$cnum,$cdesc,$type,$readonly);
 2724:                         } elsif (($phase eq 'processpostsubmit') && ($permission->{'processpostsubmit'})) {
 2725:                             &Apache::lonhtmlcommon::add_breadcrumb
 2726:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2727:                               text=>"Result"});
 2728:                             &modify_postsubmit_config($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 2729:                         } elsif (($phase eq 'viewparms') && ($permission->{'viewparms'})) {
 2730:                             &Apache::lonhtmlcommon::add_breadcrumb
 2731:                             ({href=>"javascript:changePage(document.$phase,'viewparms')",
 2732:                               text=>"Display settings"});
 2733:                             &print_settings_display($r,$cdom,$cnum,$cdesc,$type,$permission);
 2734:                         } elsif (($phase eq 'setparms') && ($permission->{'setparms'})) {
 2735:                             if ($permission->{'setparms'} eq 'view') {
 2736:                                 $linktext = 'Display settings';
 2737:                             } else {
 2738:                                 $linktext = 'Change settings';
 2739:                             }
 2740:                             &Apache::lonhtmlcommon::add_breadcrumb
 2741:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2742:                               text=>$linktext});
 2743:                             &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type,$readonly);
 2744:                         } elsif (($phase eq 'processparms') && ($permission->{'processparms'})) {
 2745:                             &Apache::lonhtmlcommon::add_breadcrumb
 2746:                             ({href=>"javascript:changePage(document.$phase,'setparms')",
 2747:                               text=>"Change settings"});
 2748:                             &Apache::lonhtmlcommon::add_breadcrumb
 2749:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2750:                               text=>"Result"});
 2751:                             &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 2752:                         } elsif (($phase eq 'catsettings') && ($permission->{'catsettings'})) {
 2753:                             &Apache::lonhtmlcommon::add_breadcrumb
 2754:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2755:                               text=>"Catalog settings"});
 2756:                             &print_catsettings($r,$cdom,$cnum,$cdesc,$type,$readonly);
 2757:                         } elsif (($phase eq 'processcat') && ($permission->{'processcat'})) {
 2758:                             &Apache::lonhtmlcommon::add_breadcrumb
 2759:                             ({href=>"javascript:changePage(document.$phase,'catsettings')",
 2760:                               text=>"Catalog settings"});
 2761:                             &Apache::lonhtmlcommon::add_breadcrumb
 2762:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 2763:                               text=>"Result"});
 2764:                             &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 2765:                         } elsif (($phase eq 'selfenroll') && ($permission->{'selfenroll'})) {
 2766:                             &Apache::lonhtmlcommon::add_breadcrumb
 2767:                             ({href => "javascript:changePage(document.$phase,'$phase')",
 2768:                               text => "Self-enrollment settings"});
 2769:                             if (!exists($env{'form.state'})) {
 2770:                                 &print_selfenrollconfig($r,$type,$cdesc,$coursehash,$readonly);
 2771:                             } elsif ($env{'form.state'} eq 'done') {
 2772:                                 &Apache::lonhtmlcommon::add_breadcrumb 
 2773:                                 ({href=>"javascript:changePage(document.$phase,'$phase')",
 2774:                                   text=>"Result"});
 2775:                                 &modify_selfenrollconfig($r,$type,$cdesc,$coursehash);
 2776:                             }
 2777:                         }
 2778:                     }
 2779:                 } else {
 2780:                     $r->print('<span class="LC_error">');
 2781:                     if ($type eq 'Community') {
 2782:                         $r->print(&mt('The community you selected is not a valid community in this domain'));
 2783:                     } elsif ($type eq 'Placement') {
 2784:                         $r->print(&mt('The course you selected is not a valid placement test in this domain'));
 2785:                     } else {
 2786:                         $r->print(&mt('The course you selected is not a valid course in this domain'));
 2787:                     }
 2788:                     $r->print(" ($domdesc)</span>");
 2789:                 }
 2790:             }
 2791:         }
 2792:         &print_footer($r);
 2793:     } else {
 2794:         $env{'user.error.msg'}=
 2795:         "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
 2796:         return HTTP_NOT_ACCEPTABLE;
 2797:     }
 2798:     return OK;
 2799: }
 2800: 
 2801: 1;
 2802: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>