Annotation of loncom/interface/lonmodifycourse.pm, revision 1.82

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

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