File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.5: download - view: text, annotated - select for diffs
Sun Jan 22 19:23:35 2017 UTC (7 years, 4 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.90, 1.91

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

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