File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.9.2.2: download - view: text, annotated - select for diffs
Sun Feb 20 19:22:30 2022 UTC (2 years, 3 months 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.98

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

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