File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.3: download - view: text, annotated - select for diffs
Sun Oct 23 02:24:51 2016 UTC (7 years, 7 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.86

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

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