File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.6: download - view: text, annotated - select for diffs
Sat Apr 8 19:05:44 2017 UTC (7 years ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2
- For 2.11
  - Backport 1.92

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

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