File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.86: download - view: text, annotated - select for diffs
Wed Oct 5 13:59:46 2016 UTC (7 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Domain configuration (Support Settings) allows custom course role(s) to be
  defined which will be available for domain helpdesk staff to select as
  ad hoc role(s) via "View a course or community" in main menu.

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

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