File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.9.2.3: download - view: text, annotated - select for diffs
Wed Jul 5 18:57:55 2023 UTC (11 months, 1 week ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.79.2.9: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.93, 1.99, 1.100

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

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