File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.79.2.4: download - view: text, annotated - select for diffs
Thu Nov 10 21:57:10 2016 UTC (7 years, 8 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  - Backport 1.87, 1.88, 1.89

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

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