File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.1: download - view: text, annotated - select for diffs
Sun Aug 7 01:32:52 2016 UTC (7 years, 10 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.84

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

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