File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.81: download - view: text, annotated - select for diffs
Mon Apr 4 01:09:48 2016 UTC (8 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6808. New course container -- "Placement" for Placement Tests.

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

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