File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.88: download - view: text, annotated - select for diffs
Wed Nov 9 14:04:41 2016 UTC (7 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Domain Helpdesk (with rar priv) can view (but not edit) course settings
  set/modified by a Domain Coordinator.

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

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