File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.9.2.5: download - view: text, annotated - select for diffs
Tue Sep 5 03:50:51 2023 UTC (8 months, 2 weeks ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.79.2.9: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.102 and 1.103.

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

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