File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.9.2.4: download - view: text, annotated - select for diffs
Mon Sep 4 20:46:02 2023 UTC (10 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 1.101

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

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