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

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.101   ! raeburn     4: # $Id: lonmodifycourse.pm,v 1.100 2023/06/05 02:22:29 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.95      raeburn    42: my $registered_cleanup;
                     43: my $modified_dom;
                     44: 
1.28      raeburn    45: sub get_dc_settable {
1.60      raeburn    46:     my ($type,$cdom) = @_;
1.83      raeburn    47:     if ($type eq 'Community') {
1.72      raeburn    48:         return ('courseowner','selfenrollmgrdc','selfenrollmgrcc');
1.48      raeburn    49:     } else {
1.85      raeburn    50:         my @items = ('courseowner','coursecode','authtype','autharg','selfenrollmgrdc',
                     51:                      'selfenrollmgrcc','mysqltables');
1.60      raeburn    52:         if (&showcredits($cdom)) {
                     53:             push(@items,'defaultcredits');
                     54:         }
1.94      raeburn    55:         my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
                     56:         if (($passwdconf{'crsownerchg'}) && ($type ne 'Placement')) {
                     57:             push(@items,'nopasswdchg');
                     58:         }
1.60      raeburn    59:         return @items;
1.48      raeburn    60:     }
                     61: }
                     62: 
                     63: sub autoenroll_keys {
1.60      raeburn    64:     my $internals = ['coursecode','courseowner','authtype','autharg','defaultcredits',
                     65:                      'autoadds','autodrops','autostart','autoend','sectionnums',
1.84      raeburn    66:                      'crosslistings','co-owners','autodropfailsafe'];
1.48      raeburn    67:     my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
                     68:     return ($internals,$accessdates);
1.28      raeburn    69: }
                     70: 
1.38      raeburn    71: sub catalog_settable {
1.49      raeburn    72:     my ($confhash,$type) = @_;
1.38      raeburn    73:     my @settable;
                     74:     if (ref($confhash) eq 'HASH') {
1.49      raeburn    75:         if ($type eq 'Community') {
                     76:             if ($confhash->{'togglecatscomm'} ne 'comm') {
                     77:                 push(@settable,'togglecats');
                     78:             }
                     79:             if ($confhash->{'categorizecomm'} ne 'comm') {
                     80:                 push(@settable,'categorize');
                     81:             }
1.81      raeburn    82:         } elsif ($type eq 'Placement') {
                     83:             if ($confhash->{'togglecatsplace'} ne 'place') {
                     84:                 push(@settable,'togglecats');
                     85:             }
                     86:             if ($confhash->{'categorizeplace'} ne 'place') {
                     87:                 push(@settable,'categorize');
                     88:             }
1.49      raeburn    89:         } else {
                     90:             if ($confhash->{'togglecats'} ne 'crs') {
                     91:                 push(@settable,'togglecats');
                     92:             }
                     93:             if ($confhash->{'categorize'} ne 'crs') {
                     94:                 push(@settable,'categorize');
                     95:             }
1.38      raeburn    96:         }
                     97:     } else {
                     98:         push(@settable,('togglecats','categorize'));
                     99:     }
                    100:     return @settable;
                    101: }
                    102: 
1.28      raeburn   103: sub get_enrollment_settings {
                    104:     my ($cdom,$cnum) = @_;
1.48      raeburn   105:     my ($internals,$accessdates) = &autoenroll_keys();
                    106:     my @items;
                    107:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { 
                    108:         @items = map { 'internal.'.$_; } (@{$internals});
                    109:         push(@items,@{$accessdates});
                    110:     }
1.94      raeburn   111:     push(@items,'internal.nopasswdchg');
1.48      raeburn   112:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1.28      raeburn   113:     my %enrollvar;
                    114:     $enrollvar{'autharg'} = '';
                    115:     $enrollvar{'authtype'} = '';
1.48      raeburn   116:     foreach my $item (keys(%settings)) {
1.28      raeburn   117:         if ($item =~ m/^internal\.(.+)$/) {
                    118:             my $type = $1;
                    119:             if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
                    120:                 if ($settings{$item} == 1) {
                    121:                     $enrollvar{$type} = "ON";
                    122:                 } else {
                    123:                     $enrollvar{$type} = "OFF";
1.10      raeburn   124:                 }
1.28      raeburn   125:             } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
                    126:                 if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
1.48      raeburn   127:                     $enrollvar{$type} = &mt('No end date');
1.28      raeburn   128:                 } else {
1.48      raeburn   129:                     $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
1.14      raeburn   130:                 }
1.50      raeburn   131:             } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
1.28      raeburn   132:                 $enrollvar{$type} = $settings{$item};
                    133:                 $enrollvar{$type} =~ s/,/, /g;
                    134:             } elsif ($type eq "authtype"
                    135:                      || $type eq "autharg"    || $type eq "coursecode"
1.84      raeburn   136:                      || $type eq "crosslistings" || $type eq "selfenrollmgr"
1.94      raeburn   137:                      || $type eq "autodropfailsafe" || $type eq 'nopasswdchg') {
1.28      raeburn   138:                 $enrollvar{$type} = $settings{$item};
1.60      raeburn   139:             } elsif ($type eq 'defaultcredits') {
                    140:                 if (&showcredits($cdom)) {
                    141:                     $enrollvar{$type} = $settings{$item};
                    142:                 }
1.28      raeburn   143:             } elsif ($type eq 'courseowner') {
                    144:                 if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
                    145:                     $enrollvar{$type} = $settings{$item};
                    146:                 } else {
                    147:                     if ($settings{$item} ne '') {
                    148:                         $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26      raeburn   149:                     }
1.1       raeburn   150:                 }
1.28      raeburn   151:             }
                    152:         } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
                    153:             my $type = $1;
                    154:             if ( ($type eq 'end') && ($settings{$item} == 0) ) {
1.48      raeburn   155:                 $enrollvar{$item} = &mt('No end date');
1.28      raeburn   156:             } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
                    157:                 $enrollvar{$item} = 'When enrolled';
                    158:             } else {
1.48      raeburn   159:                 $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
1.1       raeburn   160:             }
                    161:         }
                    162:     }
1.28      raeburn   163:     return %enrollvar;
                    164: }
                    165: 
                    166: sub print_course_search_page {
                    167:     my ($r,$dom,$domdesc) = @_;
1.48      raeburn   168:     my $action = '/adm/modifycourse';
                    169:     my $type = $env{'form.type'};
                    170:     if (!defined($env{'form.type'})) {
                    171:         $type = 'Course';
                    172:     }
                    173:     &print_header($r,$type);
1.70      raeburn   174:     my ($filterlist,$filter) = &get_filters($dom);
1.56      raeburn   175:     my ($numtitles,$cctitle,$dctitle,@codetitles);
1.48      raeburn   176:     my $ccrole = 'cc';
                    177:     if ($type eq 'Community') {
                    178:         $ccrole = 'co';
1.46      raeburn   179:     }
1.48      raeburn   180:     $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.46      raeburn   181:     $dctitle = &Apache::lonnet::plaintext('dc');
1.70      raeburn   182:     $r->print(&Apache::loncommon::js_changer());
1.48      raeburn   183:     if ($type eq 'Community') {
                    184:         $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
1.81      raeburn   185:     } elsif ($type eq 'Placement') {
                    186:         $r->print('<h3>'.&mt('Search for a placement test in the [_1] domain',$domdesc).'</h3>');
1.48      raeburn   187:     } else {
                    188:         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
1.69      raeburn   189:     }
                    190:     $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
                    191:                                                 \$numtitles,'modifycourse',undef,undef,undef,
1.70      raeburn   192:                                                 \@codetitles,$dom));
1.87      raeburn   193: 
1.86      raeburn   194:     my ($actiontext,$roleoption,$settingsoption);
1.48      raeburn   195:     if ($type eq 'Community') {
1.86      raeburn   196:         $actiontext = &mt('Actions available after searching for a community:');
1.81      raeburn   197:     } elsif ($type eq 'Placement') {
1.86      raeburn   198:         $actiontext = &mt('Actions available after searching for a placement test:')
                    199:     } else {
                    200:         $actiontext = &mt('Actions available after searching for a course:');
1.48      raeburn   201:     }
1.86      raeburn   202:     if (&Apache::lonnet::allowed('ccc',$dom)) {
                    203:        if ($type eq 'Community') {
                    204:            $roleoption = &mt('Enter the community with the role of [_1]',$cctitle);
                    205:            $settingsoption = &mt('View or modify community settings which only a [_1] may modify.',$dctitle);
                    206:        } elsif ($type eq 'Placement') {
                    207:            $roleoption = &mt('Enter the placement test with the role of [_1]',$cctitle);
                    208:            $settingsoption = &mt('View or modify placement test settings which only a [_1] may modify.',$dctitle);
                    209:        } else {
                    210:            $roleoption = &mt('Enter the course with the role of [_1]',$cctitle);
                    211:            $settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle);
                    212:        }
                    213:     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
1.90      raeburn   214:         my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom);
                    215:         if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
                    216:             if (@{$roles_by_num} > 1) {
1.86      raeburn   217:                 if ($type eq 'Community') {
1.90      raeburn   218:                     $roleoption = &mt('Enter the community with one of the available ad hoc roles');
1.86      raeburn   219:                 } elsif ($type eq 'Placement') {
1.90      raeburn   220:                     $roleoption = &mt('Enter the placement test with one of the available ad hoc roles.');
1.86      raeburn   221:                 } else {
1.90      raeburn   222:                     $roleoption = &mt('Enter the course with one of the available ad hoc roles.');
1.86      raeburn   223:                 }
                    224:             } else {
1.90      raeburn   225:                 my $rolename = $description->{$roles_by_num->[0]};
1.86      raeburn   226:                 if ($type eq 'Community') {
1.90      raeburn   227:                     $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename);
1.86      raeburn   228:                 } elsif ($type eq 'Placement') {
1.90      raeburn   229:                     $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$rolename);
1.86      raeburn   230:                 } else {
1.90      raeburn   231:                     $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename);
1.86      raeburn   232:                 }
                    233:             }
                    234:         }
                    235:         if ($type eq 'Community') {
                    236:             $settingsoption = &mt('View community settings which only a [_1] may modify.',$dctitle);
                    237:         } elsif ($type eq 'Placement') {
                    238:             $settingsoption = &mt('View placement test settings which only a [_1] may modify.',$dctitle);
                    239:         } else {
                    240:             $settingsoption = &mt('View course settings which only a [_1] may modify.',$dctitle);
                    241:         }
                    242:     }
                    243:     $r->print($actiontext.'<ul>');
                    244:     if ($roleoption) {
                    245:         $r->print('<li>'.$roleoption.'</li>'."\n");
                    246:     }
                    247:     $r->print('<li>'.$settingsoption.'</li>'."\n".'</ul>');
1.69      raeburn   248:     return;
1.28      raeburn   249: }
                    250: 
                    251: sub print_course_selection_page {
1.90      raeburn   252:     my ($r,$dom,$domdesc,$permission) = @_;
1.48      raeburn   253:     my $type = $env{'form.type'};
                    254:     if (!defined($type)) {
                    255:         $type = 'Course';
                    256:     }
                    257:     &print_header($r,$type);
1.28      raeburn   258: 
1.90      raeburn   259:     if ($permission->{'adhocrole'} eq 'custom') {
                    260:         my %lt = &Apache::lonlocal::texthash(
                    261:             title    => 'Ad hoc role selection',
                    262:             preamble => 'Please choose an ad hoc role in the course.',
                    263:             cancel   => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
                    264:         );
                    265:         my %jslt = &Apache::lonlocal::texthash (
                    266:             none => 'You are not eligible to use an ad hoc role for the selected course',
                    267:             ok   => 'OK',
                    268:             exit => 'Cancel',
                    269:         );
                    270:         &js_escape(\%jslt);
                    271:         $r->print(<<"END");
                    272: <script type="text/javascript">
                    273: // <![CDATA[
                    274: \$(document).ready(function(){
                    275:     \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
                    276: });
                    277: 
                    278: function gochoose(cname,cdom,cdesc) {
                    279:     document.courselist.pickedcourse.value = cdom+'_'+cname;
                    280:     \$("#LC_choose_adhoc").empty();
                    281:     var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
                    282:     if (pickedaction == 'adhocrole') {
                    283:         var http = new XMLHttpRequest();
                    284:         var url = "/adm/pickcourse";
                    285:         var params = "cid="+cdom+"_"+cname+"&context=adhoc";
                    286:         http.open("POST", url, true);
                    287:         http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    288:         http.onreadystatechange = function() {
                    289:             if (http.readyState == 4 && http.status == 200) {
                    290:                 var data = \$.parseJSON(http.responseText);
                    291:                 var len = data.roles.length;
                    292:                 if (len == '' || len == null || len == 0) {
                    293:                     alert('$jslt{none}');
                    294:                 } else {
                    295:                     if (len == 1) {
                    296:                         \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
                    297:                         document.courselist.submit();
                    298:                     } else {
                    299:                         var str = '';
1.92      raeburn   300:                         \$("#LC_choose_adhoc").empty();
1.90      raeburn   301:                         for (var i=0; i<data.roles.length; i++) {
                    302:                             \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span>&nbsp;&nbsp;</span>")
                    303:                             .appendTo("#LC_choose_adhoc");
                    304:                         }
1.92      raeburn   305:                         \$( "#LC_adhocrole_chooser" ).toggle( true );
1.90      raeburn   306:                         \$( "#LC_get_role_0").prop("checked", true);
                    307:                         \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
                    308:                         \$( "#LC_adhocrole_chooser" ).dialog("open");
                    309:                         \$( "#LC_adhocrole_chooser" ).dialog({
                    310:                             height: 400,
                    311:                             width: 500,
                    312:                             modal: true,
                    313:                             resizable: false,
                    314:                             buttons: [
                    315:                                   {
                    316:                                    text: "$jslt{'ok'}",
                    317:                                    click: function() {
                    318:                                             var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
                    319:                                             \$( '[name="adhocrole"]' )[0].value = rolename;
                    320:                                             document.courselist.submit();
                    321:                                         }
                    322:                                   },
                    323:                                   {
                    324:                                    text: "$jslt{'exit'}",
                    325:                                    click: function() {
                    326:                                         \$("#LC_adhocrole_chooser").dialog( "close" );
                    327:                                        }
                    328:                                   }
                    329:                             ],
                    330:                         });
                    331:                         \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
                    332:                             event.preventDefault();
                    333:                             var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
                    334:                             \$( '[name="adhocrole"]' )[0].value = rolename;
                    335:                             document.courselist.submit();
                    336:                             \$("#LC_adhocrole_chooser").dialog( "close" );
                    337:                         });
                    338:                     }
                    339:                 }
                    340:             }
                    341:         }
                    342:         http.send(params);
                    343:     } else {
                    344:         document.courselist.submit();
                    345:     }
                    346:     return;
                    347: }
                    348: // ]]>
                    349: </script>
                    350: 
1.92      raeburn   351: <div id="LC_adhocrole_chooser" title="$lt{'title'}" style="display:none">
1.90      raeburn   352:   <p>$lt{'preamble'}</p>
                    353:   <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
                    354:     <div id="LC_choose_adhoc">
                    355:     </div>
                    356:     <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
                    357:     <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
                    358:   </form>
                    359:   <p>$lt{'cancel'}</p>
                    360: </div>
                    361: END
                    362:     } elsif ($permission->{'adhocrole'} eq 'coord') {
                    363:         $r->print(<<"END");
                    364: <script type="text/javascript">
                    365: // <![CDATA[
                    366: 
                    367: function gochoose(cname,cdom,cdesc) {
                    368:     document.courselist.pickedcourse.value = cdom+'_'+cname;
                    369:     document.courselist.submit();
                    370:     return;
                    371: }
                    372: 
                    373: // ]]>
                    374: </script>
                    375: END
                    376:     }
                    377: 
                    378: # Criteria for course search
1.69      raeburn   379:     my ($filterlist,$filter) = &get_filters();
1.28      raeburn   380:     my $action = '/adm/modifycourse';
                    381:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.56      raeburn   382:     my ($numtitles,@codetitles);
1.70      raeburn   383:     $r->print(&Apache::loncommon::js_changer());
1.48      raeburn   384:     $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
1.69      raeburn   385:     $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
                    386:                                                 \$numtitles,'modifycourse',undef,undef,undef,
1.70      raeburn   387:                                                 \@codetitles,$dom,$env{'form.form'}));
                    388:     my %courses = &Apache::loncommon::search_courses($dom,$type,$filter,$numtitles,
                    389:                                                      undef,undef,undef,\@codetitles);
1.46      raeburn   390:     &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
1.86      raeburn   391:                                                     $dom,undef,%courses);
1.1       raeburn   392:     return;
                    393: }
                    394: 
1.69      raeburn   395: sub get_filters {
1.70      raeburn   396:     my ($dom) = @_;
1.69      raeburn   397:     my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
                    398:                       'ownerdomfilter','coursefilter','sincefilter');
                    399:     # created filter
1.70      raeburn   400:     my $loncaparev = &Apache::lonnet::get_server_loncaparev($dom);
1.69      raeburn   401:     if ($loncaparev ne 'unknown_cmd') {
                    402:         push(@filterlist,'createdfilter');
                    403:     }
                    404:     my %filter;
                    405:     foreach my $item (@filterlist) {
                    406:         $filter{$item} = $env{'form.'.$item};
                    407:     }
                    408:     return (\@filterlist,\%filter);
                    409: }
                    410: 
1.28      raeburn   411: sub print_modification_menu {
1.86      raeburn   412:     my ($r,$cdesc,$domdesc,$dom,$type,$cid,$coursehash,$permission) = @_;
1.48      raeburn   413:     &print_header($r,$type);
1.88      raeburn   414:     my ($ccrole,$categorytitle,$setquota_text,$setuploadquota_text,$cdom,$cnum);
1.71      raeburn   415:     if (ref($coursehash) eq 'HASH') {
                    416:         $cdom = $coursehash->{'domain'};
                    417:         $cnum = $coursehash->{'num'};
                    418:     } else {
                    419:          ($cdom,$cnum) = split(/_/,$cid);
                    420:     }
1.48      raeburn   421:     if ($type eq 'Community') {
                    422:         $ccrole = 'co';
                    423:     } else {
                    424:         $ccrole = 'cc';
1.61      raeburn   425:     }
1.88      raeburn   426:     my %linktext;
                    427:     if ($permission->{'setparms'} eq 'edit') {
                    428:         %linktext = (
                    429:                       'setquota'      => 'View/Modify quotas for group portfolio files, and for uploaded content',
                    430:                       'setanon'       => 'View/Modify responders threshold for anonymous survey submissions display',
                    431:                       'selfenroll'    => 'View/Modify Self-Enrollment configuration',
                    432:                       'setpostsubmit' => 'View/Modify submit button behavior, post-submission',
1.97      raeburn   433:                       'setltiauth'    => 'View/Modify re-authentication requirement for LTI launch of deep-linked item',
1.99      raeburn   434:                       'setexttool'    => 'View/Modify External Tools permissions',
1.88      raeburn   435:                     );
                    436:     } else {
                    437:         %linktext = (
                    438:                       'setquota'      => 'View quotas for group portfolio files, and for uploaded content',
                    439:                       'setanon'       => 'View responders threshold for anonymous survey submissions display',
                    440:                       'selfenroll'    => 'View Self-Enrollment configuration',
                    441:                       'setpostsubmit' => 'View submit button behavior, post-submission',
1.97      raeburn   442:                       'setltiauth'    => 'View re-authentication requirement for LTI launch of deep-linked item',
1.99      raeburn   443:                       'setexttool'    => 'View External Tools permissions',
1.88      raeburn   444:                     );
                    445:     }
1.48      raeburn   446:     if ($type eq 'Community') {
1.88      raeburn   447:         if ($permission->{'setparms'} eq 'edit') { 
                    448:             $categorytitle = 'View/Modify Community Settings';
                    449:             $linktext{'setparms'} = 'View/Modify community owner';
                    450:             $linktext{'catsettings'} = 'View/Modify catalog settings for community';
                    451:         } else {
                    452:             $categorytitle = 'View Community Settings';
                    453:             $linktext{'setparms'} = 'View community owner';
                    454:             $linktext{'catsettings'} = 'View catalog settings for community';
                    455:         }
1.48      raeburn   456:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
1.61      raeburn   457:         $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); 
1.48      raeburn   458:     } else {
1.88      raeburn   459:         if ($permission->{'setparms'} eq 'edit') {
                    460:             $categorytitle = 'View/Modify Course Settings';
                    461:             $linktext{'catsettings'} = 'View/Modify catalog settings for course';
                    462:             if (($type ne 'Placement') && (&showcredits($dom))) {
                    463:                 $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
                    464:             } else {
                    465:                 $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, self-enrollment and table lifetime';
                    466:             }
                    467:         } else {
                    468:             $categorytitle = 'View Course Settings';
                    469:             $linktext{'catsettings'} = 'View catalog settings for course';
                    470:             if (($type ne 'Placement') && (&showcredits($dom))) {
                    471:                 $linktext{'setparms'} = 'View course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
                    472:             } else {
                    473:                 $linktext{'setparms'} = 'View course owner, institutional code, default authentication, self-enrollment and table lifetime';
                    474:             }
                    475:         }
1.48      raeburn   476:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
1.61      raeburn   477:         $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
1.48      raeburn   478:     }
1.75      raeburn   479:     my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
                    480:     my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.'); 
1.85      raeburn   481:     my $mysqltables_text = &mt('Override default for lifetime of "temporary" MySQL tables containing student performance data.');
1.99      raeburn   482:     my $ltiauth_text = &mt('Override default for requirement for re-authentication for LTI-limited launch of deep-linked item.');
                    483:     my $exttool_text = &mt('Override default permissions for external tools use for this specific course.');
1.88      raeburn   484:     $linktext{'viewparms'} = 'Display current settings for automated enrollment';
1.54      bisitz    485: 
1.38      raeburn   486:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1.49      raeburn   487:     my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
1.54      bisitz    488: 
1.72      raeburn   489:     sub manage_selfenrollment {
1.86      raeburn   490:         my ($cdom,$cnum,$type,$coursehash,$permission) = @_;
                    491:         if ($permission->{'selfenroll'}) {
                    492:             my ($managed_by_cc,$managed_by_dc) = &Apache::lonuserutils::selfenrollment_administration($cdom,$cnum,$type,$coursehash);
                    493:             if (ref($managed_by_dc) eq 'ARRAY') {
                    494:                 if (@{$managed_by_dc}) {
                    495:                     return 1;
1.87      raeburn   496:                 }
1.86      raeburn   497:             }
1.72      raeburn   498:         }
                    499:         return 0;
                    500:     }
                    501: 
1.54      bisitz    502:     sub phaseurl {
                    503:         my $phase = shift;
                    504:         return "javascript:changePage(document.menu,'$phase')"
1.38      raeburn   505:     }
1.54      bisitz    506:     my @menu =
                    507:         ({  categorytitle => $categorytitle,
                    508:         items => [
                    509:             {
1.88      raeburn   510:                 linktext => $linktext{'setparms'},
1.54      bisitz    511:                 url => &phaseurl('setparms'),
1.86      raeburn   512:                 permission => $permission->{'setparms'},
1.54      bisitz    513:                 #help => '',
1.55      bisitz    514:                 icon => 'crsconf.png',
1.54      bisitz    515:                 linktitle => ''
                    516:             },
                    517:             {
1.88      raeburn   518:                 linktext => $linktext{'setquota'},
1.54      bisitz    519:                 url => &phaseurl('setquota'),
1.86      raeburn   520:                 permission => $permission->{'setquota'},
1.54      bisitz    521:                 #help => '',
1.55      bisitz    522:                 icon => 'groupportfolioquota.png',
1.54      bisitz    523:                 linktitle => ''
                    524:             },
                    525:             {
1.88      raeburn   526:                 linktext => $linktext{'setanon'},
1.57      raeburn   527:                 url => &phaseurl('setanon'),
1.86      raeburn   528:                 permission => $permission->{'setanon'},
1.57      raeburn   529:                 #help => '',
                    530:                 icon => 'anonsurveythreshold.png',
                    531:                 linktitle => ''
                    532:             },
                    533:             {
1.88      raeburn   534:                 linktext => $linktext{'catsettings'},
1.54      bisitz    535:                 url => &phaseurl('catsettings'),
1.86      raeburn   536:                 permission => (($permission->{'catsettings'}) && (@additional_params > 0)),
1.54      bisitz    537:                 #help => '',
1.55      bisitz    538:                 icon => 'ccatconf.png',
1.54      bisitz    539:                 linktitle => ''
                    540:             },
                    541:             {
1.88      raeburn   542:                 linktext => $linktext{'viewparms'},
1.54      bisitz    543:                 url => &phaseurl('viewparms'),
1.86      raeburn   544:                 permission => ($permission->{'viewparms'} && ($type ne 'Community') && ($type ne 'Placement')),
1.54      bisitz    545:                 #help => '',
1.55      bisitz    546:                 icon => 'roles.png',
1.54      bisitz    547:                 linktitle => ''
                    548:             },
1.72      raeburn   549:             {
1.89      raeburn   550:                 linktext => $linktext{'selfenroll'},
1.72      raeburn   551:                 icon => 'self_enroll.png',
                    552:                 #help => 'Course_Self_Enrollment',
                    553:                 url => &phaseurl('selfenroll'),
1.86      raeburn   554:                 permission => &manage_selfenrollment($cdom,$cnum,$type,$coursehash,$permission),
1.72      raeburn   555:                 linktitle => 'Configure user self-enrollment.',
                    556:             },
1.75      raeburn   557:             {
1.88      raeburn   558:                 linktext => $linktext{'setpostsubmit'},
1.75      raeburn   559:                 icon => 'emblem-readonly.png',
                    560:                 #help => '',
                    561:                 url => &phaseurl('setpostsubmit'),
1.86      raeburn   562:                 permission => $permission->{'setpostsubmit'},
1.75      raeburn   563:                 linktitle => '',
                    564:             },
1.97      raeburn   565:             {
                    566:                 linktext => $linktext{'setltiauth'},
                    567:                 icon => 'system-lock-screen.png',
                    568:                 #help => '',
                    569:                 url => &phaseurl('setltiauth'),
                    570:                 permission => $permission->{'setltiauth'},
                    571:                 linktitle => '',
                    572:             },
1.99      raeburn   573:             {
                    574:                 linktext => $linktext{'setexttool'},
                    575:                 icon => 'exttool.png',
                    576:                 #help => '',
                    577:                 url => &phaseurl('setexttool'),
                    578:                 permission => $permission->{'setexttool'},
                    579:                 linktitle => '',
                    580:             },
1.54      bisitz    581:         ]
                    582:         },
1.48      raeburn   583:         );
1.54      bisitz    584: 
                    585:     my $menu_html =
                    586:         '<h3>'
                    587:        .&mt('View/Modify settings for: [_1]',
                    588:                 '<span class="LC_nobreak">'.$cdesc.'</span>')
                    589:        .'</h3>'."\n".'<p>';
1.48      raeburn   590:     if ($type eq 'Community') {
                    591:         $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:');
                    592:     } else {
                    593:         $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:');
                    594:     }
1.54      bisitz    595:     $menu_html .= '</p>'."\n".'<ul>';
1.48      raeburn   596:     if ($type eq 'Community') {
1.72      raeburn   597:         $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>'."\n".
                    598:                       '<li>'.&mt('Override defaults for who configures self-enrollment for this specific community').'</li>'."\n";
1.48      raeburn   599:     } else {
1.72      raeburn   600:         $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'."\n".
                    601:                        '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>'."\n";
1.81      raeburn   602:         if (($type ne 'Placement') && &showcredits($dom)) {
1.72      raeburn   603:             $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>'."\n";
1.60      raeburn   604:         }
1.72      raeburn   605:         $menu_html .= ' <li>'.&mt('Override defaults for who configures self-enrollment for this specific course.').'</li>'."\n";
1.48      raeburn   606:     }
1.85      raeburn   607:     $menu_html .= '<li>'.$mysqltables_text.'</li>'."\n".
                    608:                   '<li>'.$setquota_text.'</li>'."\n".
1.72      raeburn   609:                   '<li>'.$setuploadquota_text.'</li>'."\n".
1.75      raeburn   610:                   '<li>'.$anon_text.'</li>'."\n".
1.97      raeburn   611:                   '<li>'.$postsubmit_text.'</li>'."\n".
1.100     raeburn   612:                   '<li>'.$ltiauth_text.'</li>'."\n".
1.99      raeburn   613:                   '<li>'.$exttool_text.'</li>'."\n";
1.86      raeburn   614:     my ($categories_link_start,$categories_link_end);
1.88      raeburn   615:     if ($permission->{'catsettings'} eq 'edit') {
1.86      raeburn   616:         $categories_link_start = '<a href="/adm/domainprefs?actions=coursecategories&amp;phase=display">';
                    617:         $categories_link_end = '</a>';
                    618:     }
1.38      raeburn   619:     foreach my $item (@additional_params) {
1.48      raeburn   620:         if ($type eq 'Community') {
                    621:             if ($item eq 'togglecats') {
1.86      raeburn   622:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a community from the catalog (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48      raeburn   623:             } elsif ($item eq 'categorize') {
1.86      raeburn   624:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a community (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48      raeburn   625:             }
                    626:         } else {
                    627:             if ($item eq 'togglecats') {
1.86      raeburn   628:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a course from the course catalog (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48      raeburn   629:             } elsif ($item eq 'categorize') {
1.86      raeburn   630:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a course (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48      raeburn   631:             }
1.38      raeburn   632:         }
                    633:     }
1.54      bisitz    634:     $menu_html .=
                    635:         ' </ul>'
                    636:        .'<form name="menu" method="post" action="/adm/modifycourse">'
                    637:        ."\n"
                    638:        .&hidden_form_elements();
1.28      raeburn   639:     
                    640:     $r->print($menu_html);
1.54      bisitz    641:     $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
                    642:     $r->print('</form>');
1.28      raeburn   643:     return;
                    644: }
                    645: 
1.86      raeburn   646: sub print_adhocrole_selected {
1.90      raeburn   647:     my ($r,$type,$permission) = @_;
1.48      raeburn   648:     &print_header($r,$type);
1.37      raeburn   649:     my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1.86      raeburn   650:     my ($newrole,$selectrole);
1.90      raeburn   651:     if ($permission->{'adhocrole'} eq 'coord') {
1.86      raeburn   652:         if ($type eq 'Community') {
                    653:             $newrole = "co./$cdom/$cnum";
                    654:         } else {
                    655:             $newrole = "cc./$cdom/$cnum";
                    656:         }
                    657:         $selectrole = 1;
1.90      raeburn   658:     } elsif ($permission->{'adhocrole'} eq 'custom') {
                    659:         my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1);      
                    660:         if (ref($okroles) eq 'ARRAY') {
                    661:             my $possrole = $env{'form.adhocrole'}; 
                    662:             if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) {
                    663:                 my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
                    664:                 $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
                    665:                 $selectrole = 1;
1.86      raeburn   666:             }
                    667:         }
                    668:     }
                    669:     if ($selectrole) {
                    670:         $r->print('<form name="adhocrole" method="post" action="/adm/roles">
                    671: <input type="hidden" name="selectrole" value="'.$selectrole.'" />
                    672: <input type="hidden" name="newrole" value="'.$newrole.'" />
1.37      raeburn   673: </form>');
1.86      raeburn   674:     } else {
                    675:         $r->print('<form name="ccrole" method="post" action="/adm/modifycourse">'.
                    676:                   '</form>');
                    677:     }
                    678:     return;
1.37      raeburn   679: }
                    680: 
1.28      raeburn   681: sub print_settings_display {
1.86      raeburn   682:     my ($r,$cdom,$cnum,$cdesc,$type,$permission) = @_;
1.28      raeburn   683:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.48      raeburn   684:     my %longtype = &course_settings_descrip($type);
1.28      raeburn   685:     my %lt = &Apache::lonlocal::texthash(
1.48      raeburn   686:             'valu' => 'Current value',
                    687:             'cour' => 'Current settings are:',
                    688:             'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
                    689:             'dcon' => 'Modifiable only by Domain Coordinator',
                    690:             'back' => 'Pick another action',
1.28      raeburn   691:     );
1.48      raeburn   692:     my $ccrole = 'cc';
                    693:     if ($type eq 'Community') {
                    694:        $ccrole = 'co';
                    695:     }
                    696:     my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.28      raeburn   697:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.60      raeburn   698:     my @modifiable_params = &get_dc_settable($type,$cdom);
1.48      raeburn   699:     my ($internals,$accessdates) = &autoenroll_keys();
                    700:     my @items;
                    701:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
                    702:         @items =  (@{$internals},@{$accessdates});
                    703:     }
1.28      raeburn   704:     my $disp_table = &Apache::loncommon::start_data_table()."\n".
                    705:                      &Apache::loncommon::start_data_table_header_row()."\n".
1.48      raeburn   706:                      "<th>&nbsp;</th>\n".
1.28      raeburn   707:                      "<th>$lt{'valu'}</th>\n".
                    708:                      "<th>$lt{'dcon'}</th>\n".
                    709:                      &Apache::loncommon::end_data_table_header_row()."\n";
1.48      raeburn   710:     foreach my $item (@items) {
1.96      raeburn   711:         my $shown = $enrollvar{$item};
                    712:         if ($item eq 'crosslistings') {
                    713:             my (@xlists,@lcsecs);
                    714:             foreach my $entry (split(/,/,$enrollvar{$item})) {
                    715:                 my ($xlist,$lc_sec) = split(/:/,$entry);
                    716:                 push(@xlists,$xlist);
                    717:                 push(@lcsecs,$lc_sec);
                    718:             }
                    719:             if (@xlists) {
                    720:                 my $crskey = $cnum.':'.$enrollvar{'coursecode'};
                    721:                 my %reformatted =
                    722:                     &Apache::lonnet::auto_instsec_reformat($cdom,'declutter',
                    723:                                                            {$crskey => \@xlists});
                    724:                 if (ref($reformatted{$crskey}) eq 'ARRAY') {
                    725:                     my @show;
                    726:                     my @xlcodes = @{$reformatted{$crskey}};
                    727:                     for (my $i=0; $i<@xlcodes; $i++) {
                    728:                         push(@show,$xlcodes[$i].':'.$lcsecs[$i]);
                    729:                     }
                    730:                     if (@show) {
                    731:                         $shown = join(',',@show);
                    732:                     }
                    733:                 }
                    734:             }
                    735:         }
1.28      raeburn   736:         $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
1.48      raeburn   737:                        "<td><b>$longtype{$item}</b></td>\n".
1.96      raeburn   738:                        "<td>$shown</td>\n";
1.48      raeburn   739:         if (grep(/^\Q$item\E$/,@modifiable_params)) {
1.50      raeburn   740:             $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
1.28      raeburn   741:         } else {
1.48      raeburn   742:             $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
1.28      raeburn   743:         }
                    744:         $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3       raeburn   745:     }
1.28      raeburn   746:     $disp_table .= &Apache::loncommon::end_data_table()."\n";
1.48      raeburn   747:     &print_header($r,$type);
1.86      raeburn   748:     my ($enroll_link_start,$enroll_link_end,$setparms_link_start,$setparms_link_end);
                    749:     if (&Apache::lonnet::allowed('ccc',$cdom)) {
                    750:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                    751:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                    752:                                              '=1&destinationurl=/adm/populate','&<>"');
                    753:         $enroll_link_start = '<a href="'.$escuri.'">';
                    754:         $enroll_link_end = '</a>';
                    755:     }
                    756:     if ($permission->{'setparms'}) {
                    757:         $setparms_link_start = '<a href="javascript:changePage(document.viewparms,'."'setparms'".');">';
                    758:         $setparms_link_end = '</a>';
                    759:     }
1.48      raeburn   760:     $r->print('<h3>'.&mt('Current automated enrollment settings for:').
                    761:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
                    762:               '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
                    763:               '<p>'.$lt{'cose'}.'<ul>'.
1.86      raeburn   764:               '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',
                    765:                          $cctitle,$enroll_link_start,$enroll_link_end).'</li>');
1.60      raeburn   766:     if (&showcredits($cdom)) {
1.86      raeburn   767:         $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, credits, and self-enrollment[_3].',$dctitle,$setparms_link_start,$setparms_link_end)."\n");
1.60      raeburn   768:     } else {
1.86      raeburn   769:         $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, and self-enrollment[_3].',$dctitle,$setparms_link_start,$setparms_link_end)."\n");
1.60      raeburn   770:     }
                    771:     $r->print('</li></ul></p>'.
1.48      raeburn   772:               '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
                    773:               '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
                    774:               &hidden_form_elements().
                    775:               '</p></form>'
1.86      raeburn   776:     );
1.28      raeburn   777: }
1.3       raeburn   778: 
1.28      raeburn   779: sub print_setquota {
1.88      raeburn   780:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.61      raeburn   781:     my $lctype = lc($type);
                    782:     my $headline = &mt("Set disk space quotas for $lctype: [_1]",
                    783:                      '<span class="LC_nobreak">'.$cdesc.'</span>');
1.28      raeburn   784:     my %lt = &Apache::lonlocal::texthash(
1.61      raeburn   785:                 'gpqu' => 'Disk space for storage of group portfolio files',
                    786:                 'upqu' => 'Disk space for storage of content directly uploaded to course via Content Editor',
1.42      schafran  787:                 'modi' => 'Save',
1.48      raeburn   788:                 'back' => 'Pick another action',
1.28      raeburn   789:     );
1.61      raeburn   790:     my %staticdefaults = (
                    791:                            coursequota   => 20,
                    792:                            uploadquota   => 500,
                    793:                          );
1.68      raeburn   794:     my %settings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota','internal.coursecode'],
1.61      raeburn   795:                                         $cdom,$cnum);
1.28      raeburn   796:     my $coursequota = $settings{'internal.coursequota'};
1.61      raeburn   797:     my $uploadquota = $settings{'internal.uploadquota'};
1.101   ! raeburn   798:     if (($uploadquota eq '') || ($coursequota eq '')) {
1.61      raeburn   799:         my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1.72      raeburn   800:         my $quotatype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$type,\%settings);
1.61      raeburn   801:         if ($uploadquota eq '') {
1.101   ! raeburn   802:             $uploadquota = $domdefs{$quotatype.'quota'};
        !           803:             if ($uploadquota eq '') {
        !           804:                 $uploadquota = $staticdefaults{'uploadquota'};
        !           805:             }
        !           806:         }
        !           807:         if ($coursequota eq '') {
        !           808:             $coursequota = $domdefs{$quotatype.'coursequota'};
        !           809:             if ($coursequota eq '') {
        !           810:                 $coursequota = $staticdefaults{'coursequota'};
        !           811:             }
1.61      raeburn   812:         }
1.3       raeburn   813:     }
1.48      raeburn   814:     &print_header($r,$type);
1.28      raeburn   815:     my $hidden_elements = &hidden_form_elements();
1.61      raeburn   816:     my $porthelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
                    817:     my $uploadhelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Upload_Quota');
1.88      raeburn   818:     my ($disabled,$submit);
                    819:     if ($readonly) {
                    820:         $disabled = ' disabled="disabled"';
                    821:     } else {
                    822:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
                    823:     }
1.28      raeburn   824:     $r->print(<<ENDDOCUMENT);
1.57      raeburn   825: <form action="/adm/modifycourse" method="post" name="setquota" onsubmit="return verify_quota();">
1.61      raeburn   826: <h3>$headline</h3>
                    827: <p><span class="LC_nobreak">
1.88      raeburn   828: $porthelpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" $disabled /> MB
1.61      raeburn   829: </span>
                    830: <br />
                    831: <span class="LC_nobreak">
1.88      raeburn   832: $uploadhelpitem $lt{'upqu'}: <input type="text" size="4" name="uploadquota" value="$uploadquota" $disabled /> MB
1.61      raeburn   833: </span>
                    834: </p>
1.28      raeburn   835: <p>
1.88      raeburn   836: $submit
1.28      raeburn   837: </p>
                    838: $hidden_elements
                    839: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
                    840: </form>
                    841: ENDDOCUMENT
                    842:     return;
                    843: }
1.3       raeburn   844: 
1.57      raeburn   845: sub print_set_anonsurvey_threshold {
1.88      raeburn   846:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.57      raeburn   847:     my %lt = &Apache::lonlocal::texthash(
                    848:                 'resp' => 'Responder threshold for anonymous survey submissions display:',
                    849:                 'sufa' => 'Anonymous survey submissions displayed when responders exceeds',
                    850:                 'modi' => 'Save',
                    851:                 'back' => 'Pick another action',
                    852:     );
                    853:     my %settings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
                    854:     my $threshold = $settings{'internal.anonsurvey_threshold'};
                    855:     if ($threshold eq '') {
                    856:         my %domconfig = 
                    857:             &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                    858:         if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                    859:             $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                    860:             if ($threshold eq '') {
                    861:                 $threshold = 10;
                    862:             }
                    863:         } else {
                    864:             $threshold = 10;
                    865:         }
                    866:     }
                    867:     &print_header($r,$type);
                    868:     my $hidden_elements = &hidden_form_elements();
1.88      raeburn   869:     my ($disabled,$submit);
                    870:     if ($readonly) {
                    871:         $disabled = ' disabled="disabled"'; 
                    872:     } else {
                    873:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
                    874:     }
1.57      raeburn   875:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Anonsurvey_Threshold');
                    876:     $r->print(<<ENDDOCUMENT);
                    877: <form action="/adm/modifycourse" method="post" name="setanon" onsubmit="return verify_anon_threshold();">
                    878: <h3>$lt{'resp'} <span class="LC_nobreak">$cdesc</span></h3>
                    879: <p>
1.88      raeburn   880: $helpitem $lt{'sufa'}: <input type="text" size="4" name="threshold" value="$threshold" $disabled /> &nbsp;&nbsp;&nbsp;&nbsp;
                    881: $submit
1.57      raeburn   882: </p>
                    883: $hidden_elements
                    884: <a href="javascript:changePage(document.setanon,'menu')">$lt{'back'}</a>
                    885: </form>
                    886: ENDDOCUMENT
                    887:     return;
                    888: }
                    889: 
1.75      raeburn   890: sub print_postsubmit_config {
1.88      raeburn   891:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.75      raeburn   892:     my %lt = &Apache::lonlocal::texthash (
                    893:                 'conf' => 'Configure submit button behavior after student makes a submission',
                    894:                 'disa' => 'Disable submit button/keypress following student submission',
                    895:                 'nums' => 'Number of seconds submit is disabled',
                    896:                 'modi' => 'Save',
                    897:                 'back' => 'Pick another action',
                    898:                 'yes'  => 'Yes',
                    899:                 'no'   => 'No',
                    900:     );
                    901:     my %settings = &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout',
                    902:                                                        'internal.coursecode','internal.textbook'],$cdom,$cnum);
                    903:     my $postsubmit = $settings{'internal.postsubmit'};
                    904:     if ($postsubmit eq '') {
                    905:         my %domconfig =
                    906:             &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                    907:         $postsubmit = 1; 
                    908:         if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                    909:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                    910:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                    911:                     $postsubmit = 0; 
                    912:                 }
                    913:             }
                    914:         }
                    915:     }
                    916:     my ($checkedon,$checkedoff,$display);
                    917:     if ($postsubmit) {
                    918:         $checkedon = 'checked="checked"';
                    919:         $display = 'block';
                    920:     } else {
                    921:         $checkedoff = 'checked="checked"';
                    922:         $display = 'none';
                    923:     }
                    924:     my $postsubtimeout = $settings{'internal.postsubtimeout'};
                    925:     my $default = &domain_postsubtimeout($cdom,$type,\%settings);
                    926:     my $zero = &mt('(Enter 0 to disable until next page reload, or leave blank to use the domain default: [_1])',$default);
                    927:     if ($postsubtimeout eq '') {
                    928:         $postsubtimeout = $default;
                    929:     }
                    930:     &print_header($r,$type);
                    931:     my $hidden_elements = &hidden_form_elements();
1.88      raeburn   932:     my ($disabled,$submit);
                    933:     if ($readonly) {
                    934:         $disabled = ' disabled="disabled"';
                    935:     } else {
                    936:         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
                    937:     }
1.75      raeburn   938:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Postsubmit_Config');
                    939:     $r->print(<<ENDDOCUMENT);
                    940: <form action="/adm/modifycourse" method="post" name="setpostsubmit" onsubmit="return verify_postsubmit();">
                    941: <h3>$lt{'conf'} <span class="LC_nobreak">($cdesc)</span></h3>
                    942: <p>
                    943: $helpitem $lt{'disa'}: 
1.88      raeburn   944: <label><input type="radio" name="postsubmit" $checkedon onclick="togglePostsubmit('studentsubmission');" value="1" $disabled />
1.75      raeburn   945: $lt{'yes'}</label>&nbsp;&nbsp;
1.89      raeburn   946: <label><input type="radio" name="postsubmit" $checkedoff onclick="togglePostsubmit('studentsubmission');" value="0" $disabled />
1.75      raeburn   947: $lt{'no'}</label>
                    948: <div id="studentsubmission" style="display: $display">
1.88      raeburn   949: $lt{'nums'} <input type="text" name="postsubtimeout" value="$postsubtimeout" $disabled /><br />
1.75      raeburn   950: $zero</div>
                    951: <br />     
1.88      raeburn   952: $submit
1.75      raeburn   953: </p>
                    954: $hidden_elements
                    955: <a href="javascript:changePage(document.setpostsubmit,'menu')">$lt{'back'}</a>
                    956: </form>
                    957: ENDDOCUMENT
                    958:     return;
                    959: }
                    960: 
                    961: sub domain_postsubtimeout {
                    962:     my ($cdom,$type,$settings) = @_;
                    963:     return unless (ref($settings) eq 'HASH'); 
1.99      raeburn   964:     my $lctype = &get_lctype($type,$settings);
1.75      raeburn   965:     my %domconfig =
                    966:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                    967:     my $postsubtimeout = 60;
                    968:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                    969:         if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                    970:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                    971:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype} ne '') {
                    972:                     $postsubtimeout = $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype};
                    973:                 }
                    974:             }
                    975:         }
                    976:     }
                    977:     return $postsubtimeout;
                    978: }
                    979: 
1.99      raeburn   980: sub get_lctype {
                    981:     my ($type,$settings) = @_;
                    982:     my $lctype = lc($type);
                    983:     unless (($type eq 'Community') || ($type eq 'Placement')) {
                    984:         $lctype = 'unofficial';
                    985:         if (ref($settings) eq 'HASH') {
                    986:             if ($settings->{'internal.coursecode'}) {
                    987:                 $lctype = 'official';
                    988:             } elsif ($settings->{'internal.textbook'}) {
                    989:                 $lctype = 'textbook';
                    990:             }
                    991:         }
                    992:     }
                    993:     return $lctype;
                    994: }
                    995: 
1.38      raeburn   996: sub print_catsettings {
1.88      raeburn   997:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.48      raeburn   998:     &print_header($r,$type);
1.38      raeburn   999:     my %lt = &Apache::lonlocal::texthash(
1.48      raeburn  1000:                                          'back'    => 'Pick another action',
                   1001:                                          'catset'  => 'Catalog Settings for Course',
                   1002:                                          'visi'    => 'Visibility in Course/Community Catalog',
                   1003:                                          'exclude' => 'Exclude from course catalog:',
                   1004:                                          'categ'   => 'Categorize Course',
                   1005:                                          'assi'    => 'Assign one or more categories and/or subcategories to this course.'
1.38      raeburn  1006:                                         );
1.48      raeburn  1007:     if ($type eq 'Community') {
                   1008:         $lt{'catset'} = &mt('Catalog Settings for Community');
                   1009:         $lt{'exclude'} = &mt('Exclude from course catalog');
                   1010:         $lt{'categ'} = &mt('Categorize Community');
1.49      raeburn  1011:         $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
1.48      raeburn  1012:     }
1.38      raeburn  1013:     $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
1.48      raeburn  1014:               '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
1.38      raeburn  1015:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49      raeburn  1016:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38      raeburn  1017:     if (@cat_params > 0) {
1.88      raeburn  1018:         my $disabled;
                   1019:         if ($readonly) {
                   1020:             $disabled = ' disabled="disabled"';
                   1021:         }
1.38      raeburn  1022:         my %currsettings = 
                   1023:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
                   1024:         if (grep(/^togglecats$/,@cat_params)) {
                   1025:             my $excludeon = '';
                   1026:             my $excludeoff = ' checked="checked" ';
                   1027:             if ($currsettings{'hidefromcat'} eq 'yes') {
                   1028:                 $excludeon = $excludeoff;
                   1029:                 $excludeoff = ''; 
                   1030:             }
1.48      raeburn  1031:             $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
                   1032:                       $lt{'exclude'}.
1.88      raeburn  1033:                       '&nbsp;<label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.$disabled.' />'.&mt('Yes').'</label>&nbsp;&nbsp;&nbsp;<label><input name="hidefromcat" type="radio" value="" '.$excludeoff.$disabled.' />'.&mt('No').'</label><br /><p>');
1.48      raeburn  1034:             if ($type eq 'Community') {
                   1035:                 $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  1036:             } elsif ($type eq 'Placement') {
                   1037:                 $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  1038:             } else {
                   1039:                 $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>'.
                   1040:                           '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
                   1041:                           '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
                   1042:             }
                   1043:             $r->print('</ul></p>');
1.38      raeburn  1044:         }
                   1045:         if (grep(/^categorize$/,@cat_params)) {
1.48      raeburn  1046:             $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
1.38      raeburn  1047:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
                   1048:                 my $cathash = $domconf{'coursecategories'}{'cats'};
                   1049:                 if (ref($cathash) eq 'HASH') {
1.48      raeburn  1050:                     $r->print($lt{'assi'}.'<br /><br />'.
1.38      raeburn  1051:                               &Apache::loncommon::assign_categories_table($cathash,
1.88      raeburn  1052:                                                      $currsettings{'categories'},$type,$disabled));
1.38      raeburn  1053:                 } else {
                   1054:                     $r->print(&mt('No categories defined for this domain'));
                   1055:                 }
                   1056:             } else {
                   1057:                 $r->print(&mt('No categories defined for this domain'));
                   1058:             }
1.81      raeburn  1059:             unless (($type eq 'Community') || ($type eq 'Placement')) { 
1.48      raeburn  1060:                 $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>');
                   1061:             }
1.38      raeburn  1062:         }
1.88      raeburn  1063:         unless ($readonly) {
                   1064:             $r->print('<p><input type="button" name="chgcatsettings" value="'.
                   1065:                       &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
                   1066:         }
1.38      raeburn  1067:     } else {
1.48      raeburn  1068:         $r->print('<span class="LC_warning">');
                   1069:         if ($type eq 'Community') {
                   1070:             $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
                   1071:         } else {
                   1072:             $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
                   1073:         }
                   1074:         $r->print('</span><br /><br />'."\n".
1.38      raeburn  1075:                   '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
                   1076:                   $lt{'back'}.'</a>');
                   1077:     }
                   1078:     $r->print(&hidden_form_elements().'</form>'."\n");
                   1079:     return;
                   1080: }
                   1081: 
1.28      raeburn  1082: sub print_course_modification_page {
1.88      raeburn  1083:     my ($r,$cdom,$cnum,$cdesc,$crstype,$readonly) = @_;
1.2       raeburn  1084:     my %lt=&Apache::lonlocal::texthash(
                   1085:             'actv' => "Active",
                   1086:             'inac' => "Inactive",
                   1087:             'ownr' => "Owner",
                   1088:             'name' => "Name",
1.26      raeburn  1089:             'unme' => "Username:Domain",
1.2       raeburn  1090:             'stus' => "Status",
1.48      raeburn  1091:             'nocc' => 'There is currently no owner set for this course.',
1.32      raeburn  1092:             'gobt' => "Save",
1.72      raeburn  1093:             'sett' => 'Setting',
                   1094:             'domd' => 'Domain default',
                   1095:             'whom' => 'Who configures',  
1.2       raeburn  1096:     );
1.88      raeburn  1097:     my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname,$disabled);
1.48      raeburn  1098:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.72      raeburn  1099:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
1.85      raeburn  1100:                                                        'internal.selfenrollmgrdc','internal.selfenrollmgrcc',
1.89      raeburn  1101:                                                        'internal.mysqltables'],$cdom,$cnum);
1.72      raeburn  1102:     my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
                   1103:     my @specific_managebydc = split(/,/,$settings{'internal.selfenrollmgrdc'});
                   1104:     my @specific_managebycc = split(/,/,$settings{'internal.selfenrollmgrcc'});
                   1105:     my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1.94      raeburn  1106:     my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
1.72      raeburn  1107:     my @default_managebydc = split(/,/,$domdefaults{$type.'selfenrolladmdc'});
                   1108:     if ($crstype eq 'Community') {
1.48      raeburn  1109:         $ccrole = 'co';
                   1110:         $lt{'nocc'} = &mt('There is currently no owner set for this community.');
                   1111:     } else {
                   1112:         $ccrole ='cc';
1.88      raeburn  1113:         ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar,$readonly);
1.48      raeburn  1114:     }
1.72      raeburn  1115:     $ccname = &Apache::lonnet::plaintext($ccrole,$crstype);
1.88      raeburn  1116:     if ($readonly) {
                   1117:        $disabled = ' disabled="disabled"';
                   1118:     }
1.48      raeburn  1119:     my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
                   1120:     my (@local_ccs,%cc_status,%pname);
                   1121:     foreach my $item (keys(%roleshash)) {
                   1122:         my ($uname,$udom) = split(/:/,$item);
                   1123:         if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
                   1124:             push(@local_ccs,$uname.':'.$udom);
                   1125:             $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
                   1126:             $cc_status{$uname.':'.$udom} = $lt{'actv'};
1.1       raeburn  1127:         }
                   1128:     }
1.48      raeburn  1129:     if (($enrollvar{'courseowner'} ne '') && 
                   1130:         (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
                   1131:         push(@local_ccs,$enrollvar{'courseowner'});
1.26      raeburn  1132:         my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
                   1133:         $pname{$enrollvar{'courseowner'}} = 
                   1134:                          &Apache::loncommon::plainname($owneruname,$ownerdom);
1.48      raeburn  1135:         my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
                   1136:                                                               $cdom,$cnum,$ccrole);
1.19      raeburn  1137:         if ($active_cc eq 'active') {
1.2       raeburn  1138:             $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1       raeburn  1139:         } else {
1.2       raeburn  1140:             $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1       raeburn  1141:         }
                   1142:     }
1.48      raeburn  1143:     @local_ccs = sort(@local_ccs);
                   1144:     if (@local_ccs == 0) {
                   1145:         $ownertable = $lt{'nocc'};
                   1146:     } else {
                   1147:         my $numlocalcc = scalar(@local_ccs);
                   1148:         $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
                   1149:                       &Apache::loncommon::start_data_table()."\n".
                   1150:                       &Apache::loncommon::start_data_table_header_row()."\n".
                   1151:                       '<th>'.$lt{'ownr'}.'</th>'.
                   1152:                       '<th>'.$lt{'name'}.'</th>'.
                   1153:                       '<th>'.$lt{'unme'}.'</th>'.
                   1154:                       '<th>'.$lt{'stus'}.'</th>'.
                   1155:                       &Apache::loncommon::end_data_table_header_row()."\n";
                   1156:         foreach my $cc (@local_ccs) {
                   1157:             $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
                   1158:             if ($cc eq $enrollvar{'courseowner'}) {
1.88      raeburn  1159:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked"'.$disabled.' /></td>'."\n";
1.48      raeburn  1160:             } else {
1.88      raeburn  1161:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'"'.$disabled.' /></td>'."\n";
1.48      raeburn  1162:             }
                   1163:             $ownertable .= 
                   1164:                  '<td>'.$pname{$cc}.'</td>'."\n".
                   1165:                  '<td>'.$cc.'</td>'."\n".
                   1166:                  '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
                   1167:                  &Apache::loncommon::end_data_table_row()."\n";
                   1168:         }
                   1169:         $ownertable .= &Apache::loncommon::end_data_table();
                   1170:     }
1.72      raeburn  1171:     &print_header($r,$crstype,$javascript_validations);
1.48      raeburn  1172:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.72      raeburn  1173:     my $mainheader = &modifiable_only_title($crstype);
1.48      raeburn  1174:     my $hidden_elements = &hidden_form_elements();
                   1175:     $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
                   1176:               '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
                   1177:               &Apache::lonhtmlcommon::start_pick_box());
1.72      raeburn  1178:     if ($crstype eq 'Community') {
1.48      raeburn  1179:         $r->print(&Apache::lonhtmlcommon::row_title(
                   1180:                   &Apache::loncommon::help_open_topic('Modify_Community_Owner').
1.94      raeburn  1181:                   '&nbsp;'.&mt('Community Owner'))."\n".
                   1182:                   $ownertable."\n".&Apache::lonhtmlcommon::row_closure());
1.48      raeburn  1183:     } else {
                   1184:         $r->print(&Apache::lonhtmlcommon::row_title(
                   1185:                       &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
                   1186:                       '&nbsp;'.&mt('Course Code'))."\n".
1.91      raeburn  1187:                   '<input type="text" size="15" name="coursecode" value="'.$enrollvar{'coursecode'}.'"'.$disabled.' />'.
1.60      raeburn  1188:                   &Apache::lonhtmlcommon::row_closure());
1.83      raeburn  1189:         if (($crstype eq 'Course') && (&showcredits($cdom))) {
1.60      raeburn  1190:             $r->print(&Apache::lonhtmlcommon::row_title(
                   1191:                           &Apache::loncommon::help_open_topic('Modify_Course_Credithours').
1.94      raeburn  1192:                           '&nbsp;'.&mt('Credits (students)'))."\n".
1.88      raeburn  1193:                       '<input type="text" size="3" name="defaultcredits" value="'.$enrollvar{'defaultcredits'}.'"'.$disabled.' />'.
1.60      raeburn  1194:                       &Apache::lonhtmlcommon::row_closure());
1.83      raeburn  1195:         }
                   1196:         $r->print(&Apache::lonhtmlcommon::row_title(
                   1197:                       &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
                   1198:                       '&nbsp;'.&mt('Default Authentication method'))."\n".
                   1199:                   $authenitems."\n".
                   1200:                   &Apache::lonhtmlcommon::row_closure().
                   1201:                   &Apache::lonhtmlcommon::row_title(
1.94      raeburn  1202:                       &Apache::loncommon::help_open_topic('Modify_Course_Owner').
                   1203:                       '&nbsp;'.&mt('Course Owner'))."\n".
                   1204:                   $ownertable."\n".&Apache::lonhtmlcommon::row_closure());
                   1205:         if (($passwdconf{'crsownerchg'}) && ($type ne 'Placement')) {
                   1206:             my $checked;
                   1207:             if ($enrollvar{'nopasswdchg'}) {
                   1208:                 $checked = ' checked="checked"';
                   1209:             }
                   1210:             $r->print(&Apache::lonhtmlcommon::row_title(
                   1211:                          &Apache::loncommon::help_open_topic('Modify_Course_Chgpasswd').
                   1212:                          '&nbsp;'.&mt('Changing passwords (internal)'))."\n".
                   1213:                          '<label><input type="checkbox" value="1" name="nopasswdchg"'.$checked.$disabled.' />'.
                   1214:                          &mt('Disable changing password for users with student role by course owner').'<label>'."\n".
                   1215:                          &Apache::lonhtmlcommon::row_closure());
                   1216:         }
1.48      raeburn  1217:     }
1.72      raeburn  1218:     my ($cctitle,$rolename,$currmanages,$ccchecked,$dcchecked,$defaultchecked);
                   1219:     my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
                   1220:     if ($type eq 'Community') {
                   1221:         $cctitle = &mt('Community personnel');
                   1222:     } else {
                   1223:         $cctitle = &mt('Course personnel');
                   1224:     }
                   1225: 
1.94      raeburn  1226:     $r->print(&Apache::lonhtmlcommon::row_title(
1.72      raeburn  1227:               &Apache::loncommon::help_open_topic('Modify_Course_Selfenrolladmin').
                   1228:                   '&nbsp;'.&mt('Self-enrollment configuration')).
                   1229:               &Apache::loncommon::start_data_table()."\n".
                   1230:               &Apache::loncommon::start_data_table_header_row()."\n".
                   1231:               '<th>'.$lt{'sett'}.'</th>'.
                   1232:               '<th>'.$lt{'domd'}.'</th>'.
                   1233:               '<th>'.$lt{'whom'}.'</th>'.
                   1234:               &Apache::loncommon::end_data_table_header_row()."\n");
                   1235:     my %optionname;
                   1236:     $optionname{''} = &mt('Use domain default'); 
                   1237:     $optionname{'0'} = $dctitle;
                   1238:     $optionname{'1'} = $cctitle;
                   1239:     foreach my $item (@{$selfenrollrows}) {
                   1240:         my %checked;
                   1241:         my $default = $cctitle;
                   1242:         if (grep(/^\Q$item\E$/,@default_managebydc)) {
                   1243:             $default = $dctitle;
                   1244:         }
                   1245:         if (grep(/^\Q$item\E$/,@specific_managebydc)) {
                   1246:             $checked{'0'} = ' checked="checked"';
                   1247:         } elsif (grep(/^\Q$item\E$/,@specific_managebycc)) {
                   1248:             $checked{'1'} = ' checked="checked"';
                   1249:         } else {
                   1250:             $checked{''} = ' checked="checked"';
                   1251:         } 
                   1252:         $r->print(&Apache::loncommon::start_data_table_row()."\n".
                   1253:                  '<td>'.$selfenrolltitles->{$item}.'</td>'."\n".
                   1254:                  '<td>'.&mt('[_1] configures',$default).'</td>'."\n".
                   1255:                  '<td>');
                   1256:         foreach my $option ('','0','1') {  
                   1257:             $r->print('<span class="LC_nobreak"><label>'.
                   1258:                       '<input type="radio" name="selfenrollmgr_'.$item.'" '.
1.88      raeburn  1259:                       'value="'.$option.'"'.$checked{$option}.$disabled.' />'.
1.72      raeburn  1260:                       $optionname{$option}.'</label></span><br />');
                   1261:         }
                   1262:         $r->print('</td>'."\n".
                   1263:                   &Apache::loncommon::end_data_table_row()."\n");
                   1264:     }
                   1265:     $r->print(&Apache::loncommon::end_data_table()."\n".
1.85      raeburn  1266:               '<br />'.&Apache::lonhtmlcommon::row_closure().
                   1267:               &Apache::lonhtmlcommon::row_title(
                   1268:               &Apache::loncommon::help_open_topic('Modify_Course_Table_Lifetime').
                   1269:               '&nbsp;'.&mt('"Temporary" Tables Lifetime (s)'))."\n".
1.88      raeburn  1270:               '<input type="text" size="10" name="mysqltables" value="'.$settings{'internal.mysqltables'}.'"'.$disabled.' />'.
1.85      raeburn  1271:               &Apache::lonhtmlcommon::row_closure(1).
1.88      raeburn  1272:               &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements);
                   1273:     unless ($readonly) {
                   1274:         $r->print('<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
                   1275:         if ($crstype eq 'Community') {
                   1276:             $r->print('this.form.submit();"');
                   1277:         } else {
                   1278:             $r->print('javascript:verify_message(this.form);"');
                   1279:         }
                   1280:         $r->print(' value="'.$lt{'gobt'}.'" />');
1.48      raeburn  1281:     }
1.88      raeburn  1282:     $r->print('</p></form>');
1.48      raeburn  1283:     return;
                   1284: }
                   1285: 
1.72      raeburn  1286: sub print_selfenrollconfig {
1.88      raeburn  1287:     my ($r,$type,$cdesc,$coursehash,$readonly) = @_;
1.72      raeburn  1288:     return unless(ref($coursehash) eq 'HASH');
                   1289:     my $cnum = $coursehash->{'num'};
                   1290:     my $cdom = $coursehash->{'domain'};
                   1291:     my %currsettings = &get_selfenroll_settings($coursehash);
                   1292:     &print_header($r,$type);
                   1293:     $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
                   1294:               '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
                   1295:     &Apache::loncreateuser::print_selfenroll_menu($r,'domain',$env{'form.pickedcourse'},
                   1296:                                                   $cdom,$cnum,\%currsettings,
1.88      raeburn  1297:                                                   &hidden_form_elements(),$readonly);
1.72      raeburn  1298:     return;
                   1299: }
                   1300: 
1.97      raeburn  1301: sub print_set_ltiauth {
                   1302:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
                   1303:     my %lt = &Apache::lonlocal::texthash(
                   1304:                 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item',
                   1305:                 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)',
                   1306:                 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters',
                   1307:                 'used' => 'Use domain default',
                   1308:                 'cour' => 'Use course-specific setting',
                   1309:                 'curd' => 'Current domain default is',
                   1310:                 'valu' => 'Value for this course',
                   1311:                 'modi' => 'Save',
                   1312:                 'back' => 'Pick another action',
                   1313:     );
                   1314:     my ($domdef,$checkeddom,$checkedcrs,$domdefdisplay,$divsty,$authok,$authno);
                   1315:     $domdef = 0;
1.99      raeburn  1316:     $checkeddom = ' checked="checked"';
1.97      raeburn  1317:     $domdefdisplay = $lt{'logi'}; 
                   1318:     $divsty = 'display:none';
1.99      raeburn  1319:     $authno = ' checked="checked"';
1.97      raeburn  1320:     my %domconfig =
                   1321:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                   1322:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   1323:         $domdef = $domconfig{'coursedefaults'}{'ltiauth'};
                   1324:     }
                   1325:     if ($domdef) {
                   1326:         $domdefdisplay = $lt{'link'};
                   1327:     }
                   1328:     my %settings = &Apache::lonnet::get('environment',['internal.ltiauth'],$cdom,$cnum);
                   1329:     my $ltiauth = $settings{'internal.ltiauth'};
                   1330: 
                   1331:     if ($ltiauth ne '') {
                   1332:         $checkedcrs = $checkeddom;
                   1333:         $checkeddom = '';
                   1334:         $divsty = 'display:inline-block';
                   1335:         if ($ltiauth) {
1.99      raeburn  1336:             $authok = ' checked="checked"';
1.97      raeburn  1337:         }
                   1338:     }
                   1339:     &print_header($r,$type);
                   1340:     my $hidden_elements = &hidden_form_elements();
                   1341:     my ($disabled,$submit);
                   1342:     if ($readonly) {
                   1343:         $disabled = ' disabled="disabled"';
                   1344:     } else {
                   1345:         $submit = '<input type="button" onclick="javascript:changePage(this.form,'."'processltiauth'".');" value="'.$lt{'modi'}.'" />';
                   1346:     }
                   1347:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_LTI_Authen');
                   1348:     $r->print(<<ENDDOCUMENT);
                   1349: <form action="/adm/modifycourse" method="post" name="setltiauth">
                   1350: <h3>$helpitem $lt{'requ'} <span class="LC_nobreak">$cdesc</span></h3>
1.98      raeburn  1351: <p><span class="LC_nobreak">$lt{'curd'}: <span style="font-style:italic">$domdefdisplay</span></span</p>
1.97      raeburn  1352: <p><span class="LC_nobreak">
1.99      raeburn  1353: <label><input type="radio" name="ltiauthset" value="dom" onclick="toggleLTIOptions(this.form);"$checkeddom$disabled />$lt{'used'}</label></span><br />
1.97      raeburn  1354: <span class="LC_nobreak">
1.99      raeburn  1355: <label><input type="radio" name="ltiauthset" value="course" onclick="toggleLTIOptions(this.form);"$checkedcrs$disabled />$lt{'cour'}</label></span>
1.97      raeburn  1356: <fieldset id="crsltiauth" style="$divsty">
                   1357: <legend>$lt{'valu'}</legend>
                   1358: <span class="LC_nobreak">
1.99      raeburn  1359: <label><input type="radio" name="ltiauth" value="0"$authno$disabled />$lt{'logi'}</label>
1.97      raeburn  1360: </span><br />
                   1361: <span class="LC_nobreak">
1.99      raeburn  1362: <label><input type="radio" name="ltiauth" value="1"$authok$disabled />$lt{'link'}</label>
1.97      raeburn  1363: </span>
                   1364: </fieldset>
                   1365: $submit
                   1366: </p>
                   1367: $hidden_elements
                   1368: <a href="javascript:changePage(document.setltiauth,'menu')">$lt{'back'}</a>
                   1369: </form>
                   1370: ENDDOCUMENT
                   1371:     return;
                   1372: }
                   1373: 
1.99      raeburn  1374: sub print_set_exttool {
                   1375:     my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
                   1376:     my %titles = &exttool_titles($type);
                   1377:     my ($domdef,$domdefdom,$checkeddom,$checkedcrs,$domdefdisplay,$divsty);
                   1378:     $domdef = 0;
                   1379:     $domdefdom = 1;
                   1380:     $checkeddom = ' checked="checked"';
                   1381:     $divsty = 'display:none';
                   1382:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode',
                   1383:                                         'internal.textbook'],$cdom,$cnum);
                   1384:     my $lctype = &get_lctype($type,\%settings);
                   1385:     my %domconfig =
                   1386:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                   1387:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   1388:         if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
                   1389:             if (exists($domconfig{'coursedefaults'}{'exttool'}{$lctype})) {
                   1390:                 $domdef = $domconfig{'coursedefaults'}{'exttool'}{$lctype};
                   1391:             }
                   1392:         }
                   1393:         if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
                   1394:             if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) {
                   1395:                 $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype};
                   1396:             }
                   1397:         }
                   1398:     }
                   1399:     if ($domdef && $domdefdom) {
                   1400:         $domdefdisplay = $titles{'both'};
                   1401:     } elsif ($domdef) {
                   1402:         $domdefdisplay = $titles{'crs'};
                   1403:     } elsif ($domdefdom) {
                   1404:         $domdefdisplay = $titles{'dom'}; 
                   1405:     } else {
                   1406:         $domdefdisplay = $titles{'none'};
                   1407:     }
                   1408:     my %settings = &Apache::lonnet::get('environment',['internal.exttool'],$cdom,$cnum);
                   1409:     my $crsexttool = $settings{'internal.exttool'};
                   1410:     my %crschecked = (
                   1411:                          both => ' checked="checked"',
                   1412:                          dom  => '',
                   1413:                          crs => '',
                   1414:                          none => '',
                   1415:                      ); 
                   1416:     if ($crsexttool ne '') {
                   1417:         $checkedcrs = $checkeddom;
                   1418:         $checkeddom = '';
                   1419:         $divsty = 'display:inline-block';
                   1420:         foreach my $option ('both','dom','crs','none') {
                   1421:             if ($crsexttool eq $option) {
                   1422:                 $crschecked{$option} = ' checked="checked"'; 
                   1423:             } else {
                   1424:                 $crschecked{$option} = '';
                   1425:             }
                   1426:         }
                   1427:     }
                   1428:     &print_header($r,$type);
                   1429:     my $hidden_elements = &hidden_form_elements();
                   1430:     my ($disabled,$submit);
                   1431:     if ($readonly) {
                   1432:         $disabled = ' disabled="disabled"';
                   1433:     } else {
                   1434:         $submit = '<input type="button" onclick="javascript:changePage(this.form,'."'processexttool'".');" value="'.$titles{'modi'}.'" />';
                   1435:     }
                   1436:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_External_Tool');
                   1437:     $r->print(<<ENDDOCUMENT);
                   1438: <form action="/adm/modifycourse" method="post" name="setexttool">
                   1439: <h3>$helpitem $titles{'extt'}</h3>
                   1440: <h4><span class="LC_nobreak">$type: $cdesc</span></h4>
                   1441: <p><span class="LC_nobreak">$titles{'curd'}: <span style="font-style:italic">$domdefdisplay</span></span</p>
                   1442: <p><span class="LC_nobreak">
                   1443: <label><input type="radio" name="exttoolset" value="dom" onclick="toggleExtToolOptions(this.form);"$checkeddom$disabled />$titles{'used'}</label></span><br />
                   1444: <span class="LC_nobreak">
                   1445: <label><input type="radio" name="exttoolset" value="course" onclick="toggleExtToolOptions(this.form);"$checkedcrs$disabled />$titles{'cour'}</label></span>
                   1446: <fieldset id="crsexttool" style="$divsty">
                   1447: <legend>$titles{'valu'}</legend>
                   1448: <span class="LC_nobreak">
                   1449: <label><input type="radio" name="exttool" value="both"$crschecked{'both'}$disabled />$titles{'both'}</label>
                   1450: </span><br />
                   1451: <span class="LC_nobreak">
                   1452: <label><input type="radio" name="exttool" value="dom"$crschecked{'dom'}$disabled />$titles{'dom'}</label>
                   1453: </span><br />
                   1454: <span class="LC_nobreak">
                   1455: <label><input type="radio" name="exttool" value="crs"$crschecked{'crs'}$disabled />$titles{'crs'}</label>
                   1456: </span><br />
                   1457: <span class="LC_nobreak">
                   1458: <label><input type="radio" name="exttool" value="none"$crschecked{'none'}$disabled />$titles{'none'}</label>
                   1459: </span>
                   1460: </fieldset><br />
                   1461: $submit
                   1462: </p>
                   1463: $hidden_elements
                   1464: <a href="javascript:changePage(document.setexttool,'menu')">$titles{'back'}</a>
                   1465: </form>
                   1466: ENDDOCUMENT
                   1467:     return;
                   1468: }
                   1469: 
                   1470: sub exttool_titles {
                   1471:     my ($type) = @_;
                   1472:     my %titles = &Apache::lonlocal::texthash(
                   1473:                 'extt' => 'External Tool permissions',
                   1474:                 'none' => 'Use of external tools not permitted',
                   1475:                 'crs' => 'Only external tools defined in course may be used',
                   1476:                 'dom' => 'Only external tools defined in domain may be used',
                   1477:                 'both' => 'External tools defined/configured in either domain or course may be used',
                   1478:                 'used' => 'Use domain default',
                   1479:                 'cour' => 'Use course-specific setting',
                   1480:                 'curd' => 'Current domain default is',
                   1481:                 'valu' => 'Value for this course',
                   1482:                 'modi' => 'Save',
                   1483:                 'back' => 'Pick another action',
                   1484:     );
                   1485:     if ($type eq 'Community') {
                   1486:         $titles{'crs'} = &mt('Only external tools defined in community may be used');
                   1487:         $titles{'both'} = &mt('External tools defined/configured in either domain or community may be used');
                   1488:         $titles{'cour'} = &mt('Use community-specific setting');
                   1489:         $titles{'valu'} = &mt('Value for this community');
                   1490:     }
                   1491:     return %titles;
                   1492: }
                   1493: 
1.72      raeburn  1494: sub modify_selfenrollconfig {
                   1495:     my ($r,$type,$cdesc,$coursehash) = @_;
                   1496:     return unless(ref($coursehash) eq 'HASH');
                   1497:     my $cnum = $coursehash->{'num'};
                   1498:     my $cdom = $coursehash->{'domain'};
                   1499:     my %currsettings = &get_selfenroll_settings($coursehash);
                   1500:     &print_header($r,$type);
                   1501:     $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
                   1502:              '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
                   1503:     $r->print('<form action="/adm/modifycourse" method="post" name="selfenroll">'."\n".
                   1504:               &hidden_form_elements().'<br />');
                   1505:     &Apache::loncreateuser::update_selfenroll_config($r,$env{'form.pickedcourse'},
1.73      raeburn  1506:                                                      $cdom,$cnum,'domain',$type,\%currsettings);
1.72      raeburn  1507:     $r->print('</form>');
                   1508:     return;
                   1509: }
                   1510: 
                   1511: sub get_selfenroll_settings {
                   1512:     my ($coursehash) = @_;
                   1513:     my %currsettings;
                   1514:     if (ref($coursehash) eq 'HASH') {
                   1515:         %currsettings = (
                   1516:             selfenroll_types              => $coursehash->{'internal.selfenroll_types'},
                   1517:             selfenroll_registered         => $coursehash->{'internal.selfenroll_registered'},
                   1518:             selfenroll_section            => $coursehash->{'internal.selfenroll_section'},
                   1519:             selfenroll_notifylist         => $coursehash->{'internal.selfenroll_notifylist'},
                   1520:             selfenroll_approval           => $coursehash->{'internal.selfenroll_approval'},
                   1521:             selfenroll_limit              => $coursehash->{'internal.selfenroll_limit'},
                   1522:             selfenroll_cap                => $coursehash->{'internal.selfenroll_cap'},
                   1523:             selfenroll_start_date         => $coursehash->{'internal.selfenroll_start_date'},
                   1524:             selfenroll_end_date           => $coursehash->{'internal.selfenroll_end_date'},
                   1525:             selfenroll_start_access       => $coursehash->{'internal.selfenroll_start_access'},
                   1526:             selfenroll_end_access         => $coursehash->{'internal.selfenroll_end_access'},
                   1527:             default_enrollment_start_date => $coursehash->{'default_enrollment_start_date'},
                   1528:             default_enrollment_end_date   => $coursehash->{'default_enrollment_end_date'},
1.73      raeburn  1529:             uniquecode                    => $coursehash->{'internal.uniquecode'},
1.72      raeburn  1530:         );
                   1531:     }
                   1532:     return %currsettings;
                   1533: }
                   1534: 
1.48      raeburn  1535: sub modifiable_only_title {
                   1536:     my ($type) = @_;
                   1537:     my $dctitle = &Apache::lonnet::plaintext('dc');
                   1538:     if ($type eq 'Community') {
                   1539:         return &mt('Community settings modifiable only by [_1] for:',$dctitle);
                   1540:     } else {
                   1541:         return &mt('Course settings modifiable only by [_1] for:',$dctitle);
                   1542:     }
                   1543: }
1.24      albertel 1544: 
1.48      raeburn  1545: sub gather_authenitems {
1.88      raeburn  1546:     my ($cdom,$enrollvar,$readonly) = @_;
1.28      raeburn  1547:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2       raeburn  1548:     my $curr_authtype = '';
                   1549:     my $curr_authfield = '';
1.48      raeburn  1550:     if (ref($enrollvar) eq 'HASH') {
                   1551:         if ($enrollvar->{'authtype'} =~ /^krb/) {
                   1552:             $curr_authtype = 'krb';
                   1553:         } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
                   1554:             $curr_authtype = 'int';
                   1555:         } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
                   1556:             $curr_authtype = 'loc';
1.93      raeburn  1557:         } elsif ($enrollvar->{'authtype'} eq 'lti' ) {
                   1558:             $curr_authtype = 'lti';
1.48      raeburn  1559:         }
1.2       raeburn  1560:     }
                   1561:     unless ($curr_authtype eq '') {
                   1562:         $curr_authfield = $curr_authtype.'arg';
1.33      raeburn  1563:     }
1.48      raeburn  1564:     my $javascript_validations = 
                   1565:         &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
                   1566:                                                       $curr_authtype,$curr_authfield);
1.35      raeburn  1567:     my %param = ( formname => 'document.'.$env{'form.phase'},
1.48      raeburn  1568:            kerb_def_dom => $krbdefdom,
                   1569:            kerb_def_auth => $krbdef,
1.2       raeburn  1570:            mode => 'modifycourse',
                   1571:            curr_authtype => $curr_authtype,
1.88      raeburn  1572:            curr_autharg => $enrollvar->{'autharg'},
                   1573:            readonly => $readonly,
1.48      raeburn  1574:         );
1.32      raeburn  1575:     my (%authform,$authenitems);
                   1576:     $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
                   1577:     $authform{'int'} = &Apache::loncommon::authform_internal(%param);
                   1578:     $authform{'loc'} = &Apache::loncommon::authform_local(%param);
1.93      raeburn  1579:     $authform{'lti'} = &Apache::loncommon::authform_lti(%param);
                   1580:     foreach my $item ('krb','int','loc','lti') {
1.32      raeburn  1581:         if ($authform{$item} ne '') {
                   1582:             $authenitems .= $authform{$item}.'<br />';
                   1583:         }
1.1       raeburn  1584:     }
1.48      raeburn  1585:     return($javascript_validations,$authenitems);
1.1       raeburn  1586: }
                   1587: 
                   1588: sub modify_course {
1.30      raeburn  1589:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.48      raeburn  1590:     my %longtype = &course_settings_descrip($type);
1.50      raeburn  1591:     my @items = ('internal.courseowner','description','internal.co-owners',
1.72      raeburn  1592:                  'internal.pendingco-owners','internal.selfenrollmgrdc',
1.85      raeburn  1593:                  'internal.selfenrollmgrcc','internal.mysqltables');
1.72      raeburn  1594:     my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
1.81      raeburn  1595:     unless (($type eq 'Community') || ($type eq 'Placement')) {
1.48      raeburn  1596:         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
                   1597:                      'internal.sectionnums','internal.crosslistings'));
1.60      raeburn  1598:         if (&showcredits($cdom)) {  
                   1599:             push(@items,'internal.defaultcredits');
                   1600:         }
1.94      raeburn  1601:         my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
                   1602:         if ($passwdconf{'crsownerchg'}) {
                   1603:             push(@items,'internal.nopasswdchg');
                   1604:         }
1.1       raeburn  1605:     }
1.48      raeburn  1606:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
                   1607:     my $description = $settings{'description'};
1.60      raeburn  1608:     my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,
                   1609:         %cenv,%changed,@changes,@nochanges,@sections,@xlists,@warnings);
                   1610:     my @modifiable_params = &get_dc_settable($type,$cdom);
1.28      raeburn  1611:     foreach my $param (@modifiable_params) {
1.48      raeburn  1612:         $currattr{$param} = $settings{'internal.'.$param};
1.1       raeburn  1613:     }
1.48      raeburn  1614:     if ($type eq 'Community') {
                   1615:         %changed = ( owner  => 0 );
                   1616:         $ccrole = 'co';
                   1617:     } else {
                   1618:         %changed = ( code  => 0,
                   1619:                      owner => 0,
1.94      raeburn  1620:                      passwd => 0,
1.48      raeburn  1621:                    );
                   1622:         $ccrole = 'cc';
                   1623:         unless ($settings{'internal.sectionnums'} eq '') {
                   1624:             if ($settings{'internal.sectionnums'} =~ m/,/) {
                   1625:                 @sections = split/,/,$settings{'internal.sectionnums'};
                   1626:             } else {
                   1627:                 $sections[0] = $settings{'internal.sectionnums'};
                   1628:             }
                   1629:         }
1.60      raeburn  1630:         unless ($settings{'internal.crosslistings'} eq '') {
1.48      raeburn  1631:             if ($settings{'internal.crosslistings'} =~ m/,/) {
                   1632:                 @xlists = split/,/,$settings{'internal.crosslistings'};
                   1633:             } else {
                   1634:                 $xlists[0] = $settings{'internal.crosslistings'};
                   1635:             }
                   1636:         }
                   1637:         if ($env{'form.login'} eq 'krb') {
                   1638:             $newattr{'authtype'} = $env{'form.login'};
                   1639:             $newattr{'authtype'} .= $env{'form.krbver'};
                   1640:             $newattr{'autharg'} = $env{'form.krbarg'};
                   1641:         } elsif ($env{'form.login'} eq 'int') {
                   1642:             $newattr{'authtype'} ='internal';
                   1643:             if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
                   1644:                 $newattr{'autharg'} = $env{'form.intarg'};
                   1645:             }
                   1646:         } elsif ($env{'form.login'} eq 'loc') {
                   1647:             $newattr{'authtype'} = 'localauth';
                   1648:             if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                   1649:                 $newattr{'autharg'} = $env{'form.locarg'};
                   1650:             }
1.93      raeburn  1651:         } elsif ($env{'form.login'} eq 'lti') {
                   1652:             $newattr{'authtype'} = 'lti';
1.48      raeburn  1653:         }
                   1654:         if ( $newattr{'authtype'}=~ /^krb/) {
                   1655:             if ($newattr{'autharg'}  eq '') {
                   1656:                 push(@warnings,
                   1657:                            &mt('As you did not include the default Kerberos domain'
1.45      bisitz   1658:                           .' to be used for authentication in this class, the'
                   1659:                           .' institutional data used by the automated'
                   1660:                           .' enrollment process must include the Kerberos'
1.48      raeburn  1661:                           .' domain for each new student.'));
                   1662:             }
                   1663:         }
                   1664: 
                   1665:         if ( exists($env{'form.coursecode'}) ) {
                   1666:             $newattr{'coursecode'}=$env{'form.coursecode'};
                   1667:             unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
                   1668:                 $changed{'code'} = 1;
                   1669:             }
1.1       raeburn  1670:         }
1.85      raeburn  1671:         if ( exists($env{'form.mysqltables'}) ) {
                   1672:             $newattr{'mysqltables'} = $env{'form.mysqltables'};
                   1673:             $newattr{'mysqltables'} =~ s/\D+//g;
                   1674:         }
1.94      raeburn  1675:         if ($type ne 'Placement') {
                   1676:             if (&showcredits($cdom) && exists($env{'form.defaultcredits'})) {
                   1677:                 $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
                   1678:                 $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
                   1679:             }
                   1680:             if (grep(/^nopasswdchg$/,@modifiable_params)) {
                   1681:                 if ($env{'form.nopasswdchg'}) {
                   1682:                     $newattr{'nopasswdchg'} = 1;
                   1683:                     unless ($currattr{'nopasswdchg'}) {
                   1684:                         $changed{'passwd'} = 1;
                   1685:                     }
                   1686:                 } elsif ($currattr{'nopasswdchg'}) {
                   1687:                     $changed{'passwd'} = 1;
                   1688:                 }
                   1689:             }
1.60      raeburn  1690:         }
1.72      raeburn  1691:     }
                   1692: 
                   1693:     my @newmgrdc = ();
                   1694:     my @newmgrcc = ();
                   1695:     my @currmgrdc = split(/,/,$currattr{'selfenrollmgrdc'});
                   1696:     my @currmgrcc = split(/,/,$currattr{'selfenrollmgrcc'});
1.60      raeburn  1697: 
1.72      raeburn  1698:     foreach my $item (@{$selfenrollrows}) {
                   1699:         if ($env{'form.selfenrollmgr_'.$item} eq '0') {
                   1700:             push(@newmgrdc,$item);
                   1701:         } elsif ($env{'form.selfenrollmgr_'.$item} eq '1') {
                   1702:             push(@newmgrcc,$item);
                   1703:         }
                   1704:     }
                   1705: 
                   1706:     $newattr{'selfenrollmgrdc'}=join(',',@newmgrdc);
                   1707:     $newattr{'selfenrollmgrcc'}=join(',',@newmgrcc);
                   1708: 
                   1709:     my $cctitle;
                   1710:     if ($type eq 'Community') {
                   1711:         $cctitle = &mt('Community personnel');
                   1712:     } else {
                   1713:         $cctitle = &mt('Course personnel');
1.1       raeburn  1714:     }
1.72      raeburn  1715:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.1       raeburn  1716: 
1.16      albertel 1717:     if ( exists($env{'form.courseowner'}) ) {
                   1718:         $newattr{'courseowner'}=$env{'form.courseowner'};
1.14      raeburn  1719:         unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38      raeburn  1720:             $changed{'owner'} = 1;
1.1       raeburn  1721:         } 
                   1722:     }
1.48      raeburn  1723: 
1.94      raeburn  1724:     if ($changed{'owner'} || $changed{'code'} || $changed{'passwd'}) {
1.38      raeburn  1725:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
                   1726:                                                     undef,undef,'.');
                   1727:         if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1.48      raeburn  1728:             if ($changed{'code'}) {
                   1729:                 $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
                   1730:             }
                   1731:             if ($changed{'owner'}) {
                   1732:                 $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
                   1733:             }
1.94      raeburn  1734:             if ($changed{'passwd'}) {
                   1735:                 if ($env{'form.nopasswdchg'}) {
                   1736:                     $crsinfo{$env{'form.pickedcourse'}}{'nopasswdchg'} = 1;
                   1737:                 } else {
                   1738:                     delete($crsinfo{'nopasswdchg'});
                   1739:                 }
                   1740:             }
1.38      raeburn  1741:             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
                   1742:             my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1.94      raeburn  1743:             if (($putres eq 'ok') && (($changed{'owner'} || $changed{'code'}))) {
1.50      raeburn  1744:                 &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
1.95      raeburn  1745:                 if ($changed{'code'}) {
                   1746:                     &Apache::lonnet::devalidate_cache_new('instcats',$cdom);
                   1747:                     # Update cache of self-cataloging courses on institution's server(s).
                   1748:                     if (&Apache::lonnet::shared_institution($cdom)) {
                   1749:                         unless ($registered_cleanup) {
                   1750:                             my $handlers = $r->get_handlers('PerlCleanupHandler');
                   1751:                             $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
                   1752:                             $registered_cleanup=1;
                   1753:                             $modified_dom = $cdom;
                   1754:                         }
                   1755:                     }
                   1756:                 }
1.50      raeburn  1757:             }
1.38      raeburn  1758:         }
1.14      raeburn  1759:     }
1.28      raeburn  1760:     foreach my $param (@modifiable_params) {
                   1761:         if ($currattr{$param} eq $newattr{$param}) {
                   1762:             push(@nochanges,$param);
1.1       raeburn  1763:         } else {
1.48      raeburn  1764:             $cenv{'internal.'.$param} = $newattr{$param};
1.28      raeburn  1765:             push(@changes,$param);
1.1       raeburn  1766:         }
                   1767:     }
                   1768:     if (@changes > 0) {
1.62      bisitz   1769:         $chgresponse = &mt('The following settings have been changed:').'<br/><ul>';
1.1       raeburn  1770:     }
1.48      raeburn  1771:     if (@nochanges > 0) {
1.62      bisitz   1772:         $nochgresponse = &mt('The following settings remain unchanged:').'<br/><ul>';
1.1       raeburn  1773:     }
1.33      raeburn  1774:     if (@changes > 0) {
1.28      raeburn  1775:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1       raeburn  1776:         if ($putreply !~ /^ok$/) {
1.48      raeburn  1777:             $response = '<p class="LC_error">'.
                   1778:                         &mt('There was a problem processing your requested changes.').'<br />';
                   1779:             if ($type eq 'Community') {
                   1780:                 $response .= &mt('Settings for this community have been left unchanged.');
                   1781:             } else {
                   1782:                 $response .= &mt('Settings for this course have been left unchanged.');
                   1783:             }
                   1784:             $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
1.1       raeburn  1785:         } else {
1.72      raeburn  1786:             if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
                   1787:                 my %newenv;
                   1788:                 map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes;   
                   1789:                 &Apache::lonnet::appenv(\%newenv);
                   1790:             }
1.28      raeburn  1791:             foreach my $attr (@modifiable_params) {
1.48      raeburn  1792:                 if (grep/^\Q$attr\E$/,@changes) {
1.72      raeburn  1793:                     my $shown = $newattr{$attr};
                   1794:                     if ($attr eq 'selfenrollmgrdc') {
                   1795:                         $shown = &selfenroll_config_status(\@newmgrdc,$selfenrolltitles);
                   1796:                     } elsif ($attr eq 'selfenrollmgrcc') {
                   1797:                         $shown = &selfenroll_config_status(\@newmgrcc,$selfenrolltitles);
                   1798:                     } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
                   1799:                         $shown = &mt('None');
1.85      raeburn  1800:                     } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
                   1801:                         $shown = &mt('domain default');
1.94      raeburn  1802:                     } elsif ($attr eq 'nopasswdchg') {
                   1803:                         if ($shown) {
                   1804:                             $shown = &mt('Yes');
                   1805:                         } else {
                   1806:                             $shown = &mt('No');
                   1807:                         }
1.72      raeburn  1808:                     }
                   1809:                     $chgresponse .= '<li>'.&mt('[_1] now set to: [_2]',$longtype{$attr},$shown).'</li>';
1.1       raeburn  1810:                 } else {
1.72      raeburn  1811:                     my $shown = $currattr{$attr};
                   1812:                     if ($attr eq 'selfenrollmgrdc') {
                   1813:                         $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
                   1814:                     } elsif ($attr eq 'selfenrollmgrcc') {
                   1815:                         $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
                   1816:                     } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
                   1817:                         $shown = &mt('None');
1.85      raeburn  1818:                     } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
                   1819:                         $shown = &mt('domain default');
1.94      raeburn  1820:                     } elsif ($attr eq 'nopasswdchg') {
                   1821:                         if ($shown) {
                   1822:                             $shown = &mt('Yes');
                   1823:                         } else {
                   1824:                             $shown = &mt('No');
                   1825:                         }
1.72      raeburn  1826:                     }
                   1827:                     $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
1.1       raeburn  1828:                 }
                   1829:             }
1.81      raeburn  1830:             if (($type ne 'Community') && ($type ne 'Placement') && ($changed{'code'} || $changed{'owner'})) {
1.1       raeburn  1831:                 if ( $newattr{'courseowner'} eq '') {
1.48      raeburn  1832: 	            push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
                   1833:                                    '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
1.1       raeburn  1834:                 } else {
1.59      raeburn  1835:                     my %crsenv = &Apache::lonnet::get('environment',['internal.co-owners'],$cdom,$cnum);
                   1836:                     my $coowners = $crsenv{'internal.co-owners'};
1.1       raeburn  1837: 	            if (@sections > 0) {
1.38      raeburn  1838:                         if ($changed{'code'}) {
1.2       raeburn  1839: 	                    foreach my $sec (@sections) {
                   1840: 		                if ($sec =~ m/^(.+):/) {
1.48      raeburn  1841:                                     my $instsec = $1;
1.8       raeburn  1842: 		                    my $inst_course_id = $newattr{'coursecode'}.$1;
1.28      raeburn  1843:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7       raeburn  1844: 			            if ($course_check eq 'ok') {
1.58      raeburn  1845:                                         my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.48      raeburn  1846: 			                unless ($outcome eq 'ok') {
                   1847:                                
1.53      raeburn  1848: 				            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  1849: 			                }
                   1850: 			            } else {
1.53      raeburn  1851:                                         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  1852: 			            }
                   1853: 		                } else {
1.48      raeburn  1854: 			            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  1855: 		                }
                   1856: 		            }
1.38      raeburn  1857: 	                } elsif ($changed{'owner'}) {
1.4       raeburn  1858:                             foreach my $sec (@sections) {
                   1859:                                 if ($sec =~ m/^(.+):/) {
1.48      raeburn  1860:                                     my $instsec = $1;
                   1861:                                     my $inst_course_id = $newattr{'coursecode'}.$instsec;
1.58      raeburn  1862:                                     my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.4       raeburn  1863:                                     unless ($outcome eq 'ok') {
1.53      raeburn  1864:                                         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  1865:                                     }
                   1866:                                 } else {
1.53      raeburn  1867:                                     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  1868:                                 }
                   1869:                             }
                   1870:                         }
1.1       raeburn  1871: 	            } else {
1.53      raeburn  1872: 	                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  1873: 	            }
1.38      raeburn  1874: 	            if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1       raeburn  1875: 	                foreach my $xlist (@xlists) {
                   1876: 		            if ($xlist =~ m/^(.+):/) {
1.48      raeburn  1877:                                 my $instxlist = $1;
1.58      raeburn  1878:                                 my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'},$coowners);
1.1       raeburn  1879: 		                unless ($outcome eq 'ok') {
1.48      raeburn  1880: 			            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  1881: 		                }
1.28      raeburn  1882: 		            }
1.1       raeburn  1883: 	                }
                   1884: 	            }
                   1885:                 }
                   1886:             }
                   1887:         }
1.2       raeburn  1888:     } else {
1.28      raeburn  1889:         foreach my $attr (@modifiable_params) {
1.72      raeburn  1890:             my $shown = $currattr{$attr};
                   1891:             if ($attr eq 'selfenrollmgrdc') {
                   1892:                 $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
                   1893:             } elsif ($attr eq 'selfenrollmgrcc') {
                   1894:                 $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
                   1895:             } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
                   1896:                 $shown = &mt('None');
1.85      raeburn  1897:             } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
                   1898:                 $shown = &mt('domain default');
1.72      raeburn  1899:             }
                   1900:             $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
1.2       raeburn  1901:         }
1.1       raeburn  1902:     }
                   1903: 
                   1904:     if (@changes > 0) {
                   1905:         $chgresponse .= "</ul><br/><br/>";
                   1906:     }
                   1907:     if (@nochanges > 0) {
                   1908:         $nochgresponse .=  "</ul><br/><br/>";
                   1909:     }
1.48      raeburn  1910:     my ($warning,$numwarnings);
                   1911:     my $numwarnings = scalar(@warnings); 
                   1912:     if ($numwarnings) {
                   1913:         $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
                   1914:         foreach my $warn (@warnings) {
                   1915:             $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
                   1916:         }
                   1917:         $warning .= '</ul></p>';
1.1       raeburn  1918:     }
1.48      raeburn  1919:     if ($response) {
                   1920:         $reply = $response;
                   1921:     } else {
1.1       raeburn  1922:         $reply = $chgresponse.$nochgresponse.$warning;
                   1923:     }
1.48      raeburn  1924:     &print_header($r,$type);
                   1925:     my $mainheader = &modifiable_only_title($type);
                   1926:     $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
                   1927:              '<p>'.$reply.'</p>'."\n".
1.28      raeburn  1928:              '<form action="/adm/modifycourse" method="post" name="processparms">'.
1.66      bisitz   1929:              &hidden_form_elements();
                   1930:     my @actions =
                   1931:         ('<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
                   1932:                  &mt('Pick another action').'</a>');
1.48      raeburn  1933:     if ($numwarnings) {
                   1934:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                   1935:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                   1936:                                              '=1&destinationurl=/adm/populate','&<>"');
                   1937: 
1.66      bisitz   1938:         push(@actions, '<a href="'.$escuri.'">'.
                   1939:                   &mt('Go to Automated Enrollment Manager for course').'</a>');
1.48      raeburn  1940:     }
1.66      bisitz   1941:     $reply .= &Apache::lonhtmlcommon::actionbox(\@actions).'</form>';
1.3       raeburn  1942:     $r->print($reply);
1.28      raeburn  1943:     return;
                   1944: }
                   1945: 
1.72      raeburn  1946: sub selfenroll_config_status {
                   1947:     my ($items,$selfenrolltitles) = @_;
                   1948:     my $shown;
                   1949:     if ((ref($items) eq 'ARRAY') && (ref($selfenrolltitles) eq 'HASH')) {
                   1950:         if (@{$items} > 0) {
                   1951:             $shown = '<ul>';
                   1952:             foreach my $item (@{$items}) {
                   1953:                 $shown .= '<li>'.$selfenrolltitles->{$item}.'</li>';
                   1954:             }
                   1955:             $shown .= '</ul>';
                   1956:         } else {
                   1957:             $shown = &mt('None');
                   1958:         }
                   1959:     }
                   1960:     return $shown;
                   1961: }
                   1962: 
1.50      raeburn  1963: sub update_coowners {
                   1964:     my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
                   1965:     return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
                   1966:     my %designhash = &Apache::loncommon::get_domainconf($cdom);
                   1967:     my (%cchash,$autocoowners);
                   1968:     if ($designhash{$cdom.'.autoassign.co-owners'}) {
                   1969:         $autocoowners = 1;
                   1970:         %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
                   1971:     }
                   1972:     if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
                   1973:         my $oldowner_to_coowner;
1.51      raeburn  1974:         my @types = ('co-owners');
1.50      raeburn  1975:         if (($newattr->{'coursecode'}) && ($autocoowners)) {
                   1976:             my $oldowner = $settings->{'internal.courseowner'};
                   1977:             if ($cchash{$oldowner.':cc'}) {
1.51      raeburn  1978:                 my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
                   1979:                 if ($result eq 'valid') {
                   1980:                     if ($settings->{'internal.co-owner'}) {
                   1981:                         my @current = split(',',$settings->{'internal.co-owners'});
                   1982:                         unless (grep(/^\Q$oldowner\E$/,@current)) {
                   1983:                             $oldowner_to_coowner = 1;
                   1984:                         }
                   1985:                     } else {
1.50      raeburn  1986:                         $oldowner_to_coowner = 1;
                   1987:                     }
                   1988:                 }
                   1989:             }
1.51      raeburn  1990:         } else {
                   1991:             push(@types,'pendingco-owners');
1.50      raeburn  1992:         }
1.51      raeburn  1993:         foreach my $type (@types) {
1.50      raeburn  1994:             if ($settings->{'internal.'.$type}) {
                   1995:                 my @current = split(',',$settings->{'internal.'.$type});
                   1996:                 my $newowner = $newattr->{'courseowner'};
                   1997:                 my @newvalues = ();
                   1998:                 if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
                   1999:                     foreach my $person (@current) {
                   2000:                         unless ($person eq $newowner) {
                   2001:                             push(@newvalues,$person);
                   2002:                         }
                   2003:                     }
                   2004:                 } else {
                   2005:                     @newvalues = @current;
                   2006:                 }
                   2007:                 if ($oldowner_to_coowner) {
                   2008:                     push(@newvalues,$settings->{'internal.courseowner'});
                   2009:                     @newvalues = sort(@newvalues);
                   2010:                 }
                   2011:                 my $newownstr = join(',',@newvalues);
                   2012:                 if ($newownstr ne $settings->{'internal.'.$type}) {
                   2013:                     if ($type eq 'co-owners') {
                   2014:                         my $deleted = '';
                   2015:                         unless (@newvalues) {
                   2016:                             $deleted = 1;
                   2017:                         }
                   2018:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
                   2019:                                                         $deleted,@newvalues);
                   2020:                     } else {
                   2021:                         my $pendingcoowners;
                   2022:                         my $cid = $cdom.'_'.$cnum;
                   2023:                         if (@newvalues) {
                   2024:                             $pendingcoowners = join(',',@newvalues);
                   2025:                             my %pendinghash = (
                   2026:                                 'internal.pendingco-owners' => $pendingcoowners,
                   2027:                             );
1.52      raeburn  2028:                             my $putresult = &Apache::lonnet::put('environment',\%pendinghash,$cdom,$cnum);
1.50      raeburn  2029:                             if ($putresult eq 'ok') {
                   2030:                                 if ($env{'course.'.$cid.'.num'} eq $cnum) {
1.52      raeburn  2031:                                     &Apache::lonnet::appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
1.50      raeburn  2032:                                 }
                   2033:                             }
                   2034:                         } else {
                   2035:                             my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
                   2036:                             if ($delresult eq 'ok') {
                   2037:                                 if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
                   2038:                                     &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
                   2039:                                 }
                   2040:                             }
                   2041:                         }
                   2042:                     }
                   2043:                 } elsif ($oldowner_to_coowner) {
                   2044:                     &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                   2045:                                          $settings->{'internal.courseowner'});
                   2046: 
                   2047:                 }
                   2048:             } elsif ($oldowner_to_coowner) {
                   2049:                 &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                   2050:                                      $settings->{'internal.courseowner'});
                   2051:             }
                   2052:         }
                   2053:     }
                   2054:     if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
                   2055:         if ($newattr->{'coursecode'} ne '') {
                   2056:             my %designhash = &Apache::loncommon::get_domainconf($cdom);
                   2057:             if ($designhash{$cdom.'.autoassign.co-owners'}) {
                   2058:                 my @newcoowners = ();
                   2059:                 if ($settings->{'internal.co-owners'}) {
1.58      raeburn  2060:                     my @currcoown = split(',',$settings->{'internal.co-owners'});
1.50      raeburn  2061:                     my ($updatecoowners,$delcoowners);
                   2062:                     foreach my $person (@currcoown) {
1.51      raeburn  2063:                         my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
1.50      raeburn  2064:                         if ($result eq 'valid') {
                   2065:                             push(@newcoowners,$person);
                   2066:                         }
                   2067:                     }
                   2068:                     foreach my $item (sort(keys(%cchash))) {
                   2069:                         my ($uname,$udom,$urole) = split(':',$item);
1.51      raeburn  2070:                         next if ($uname.':'.$udom eq $newattr->{'courseowner'});
1.50      raeburn  2071:                         unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
1.51      raeburn  2072:                             my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
                   2073:                             if ($result eq 'valid') {
                   2074:                                 push(@newcoowners,$uname.':'.$udom);
                   2075:                             }
1.50      raeburn  2076:                         }
                   2077:                     }
                   2078:                     if (@newcoowners) {
                   2079:                         my $coowners = join(',',sort(@newcoowners));
                   2080:                         unless ($coowners eq $settings->{'internal.co-owners'}) {
                   2081:                             $updatecoowners = 1;
                   2082:                         }
                   2083:                     } else {
                   2084:                         $delcoowners = 1;
                   2085:                     }
                   2086:                     if ($updatecoowners || $delcoowners) {
                   2087:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
                   2088:                                                         $delcoowners,@newcoowners);
                   2089:                     }
                   2090:                 } else {
                   2091:                     foreach my $item (sort(keys(%cchash))) {
                   2092:                         my ($uname,$udom,$urole) = split(':',$item);
                   2093:                         push(@newcoowners,$uname.':'.$udom);
                   2094:                     }
                   2095:                     if (@newcoowners) {
                   2096:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                   2097:                                                         @newcoowners);
                   2098:                     }
                   2099:                 }
                   2100:             }
                   2101:         }
                   2102:     }
                   2103:     return;
                   2104: }
                   2105: 
1.28      raeburn  2106: sub modify_quota {
1.48      raeburn  2107:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2108:     &print_header($r,$type);
1.61      raeburn  2109:     my $lctype = lc($type);
                   2110:     my $headline = &mt("Disk space quotas for $lctype: [_1]",
                   2111:                      '<span class="LC_nobreak">'.$cdesc.'</span>');
1.48      raeburn  2112:     $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
1.61      raeburn  2113:               '<h3>'.$headline.'</h3>');
                   2114:     my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
                   2115:     my %staticdefaults = (
                   2116:                            coursequota   => 20,
                   2117:                            uploadquota   => 500,
                   2118:                          );
                   2119:     my %default;
                   2120:     $default{'coursequota'} = $staticdefaults{'coursequota'};
                   2121:     my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
                   2122:     $default{'uploadquota'} = $domdefs{'uploadquota'};
                   2123:     if ($default{'uploadquota'} eq '') {
                   2124:         $default{'uploadquota'} = $staticdefaults{'uploadquota'};
                   2125:     }
                   2126:     my (%cenv,%showresult);
                   2127:     foreach my $item ('coursequota','uploadquota') {
                   2128:         if ($env{'form.'.$item} ne '') {
                   2129:             my $newquota = $env{'form.'.$item};
                   2130:             if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
                   2131:                 $newquota = $1;
                   2132:                 if ($oldsettings{'internal.'.$item} == $newquota) {
                   2133:                     if ($item eq 'coursequota') {
                   2134:                         $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] MB.',$newquota).'<br />');
                   2135:                     } else {
                   2136:                         $r->print(&mt('The disk space allocated for files uploaded via the Content Editor remains unchanged as [_1] MB.',$newquota).'<br />');
                   2137:                     }
                   2138:                 } else {
                   2139:                     $cenv{'internal.'.$item} = $newquota;
                   2140:                     $showresult{$item} = 1;
                   2141:                 }
1.28      raeburn  2142:             } else {
1.61      raeburn  2143:                 if ($item eq 'coursequota') { 
                   2144:                     $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'<br />');
                   2145:                 } else {
                   2146:                     $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'<br />');
                   2147: 
                   2148:                 }
                   2149:             }
                   2150:         }
                   2151:     }
                   2152:     if (keys(%cenv)) {
                   2153:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
                   2154:                                             $cnum);
                   2155:         foreach my $key (sort(keys(%showresult))) {
                   2156:             if (($oldsettings{'internal.'.$key} eq '') && 
                   2157:                 ($env{'form.'.$key} == $default{$key})) {
                   2158:                 if ($key eq 'uploadquota') {
                   2159:                     if ($type eq 'Community') {
                   2160:                         $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.',
                   2161:                                       $default{$key}).'<br />');
                   2162:                     } else {
                   2163:                         $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.',
                   2164:                                       $default{$key}).'<br />');
                   2165:                     }
                   2166:                 } else { 
1.48      raeburn  2167:                     if ($type eq 'Community') {
1.61      raeburn  2168:                         $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.',
                   2169:                                       $default{$key}).'<br />');
1.48      raeburn  2170:                     } else {
1.61      raeburn  2171:                         $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] MB.',
                   2172:                                       $default{$key}).'<br />');
1.48      raeburn  2173:                     }
1.61      raeburn  2174:                 }
                   2175:                 delete($showresult{$key});
                   2176:             }
                   2177:         }
                   2178:         if ($putreply eq 'ok') {
                   2179:             my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
                   2180:             if ($showresult{'coursequota'}) {
                   2181:                 $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] MB.',
                   2182:                               '<b>'.$updatedsettings{'internal.coursequota'}.'</b>').'<br />');
                   2183:                 my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
                   2184:                 if ($usage >= $updatedsettings{'internal.coursequota'}) {
                   2185:                     my $newoverquota;
                   2186:                     if ($usage < $oldsettings{'internal.coursequota'}) {
                   2187:                         $newoverquota = 'now';
                   2188:                     }
                   2189:                     $r->print('<p>');
                   2190:                     if ($type eq 'Community') {
1.67      bisitz   2191:                         $r->print(&mt("Disk usage $newoverquota exceeds the quota for this community.").' '.
1.61      raeburn  2192:                                   &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  2193:                     } else {
1.67      bisitz   2194:                         $r->print(&mt("Disk usage $newoverquota exceeds the quota for this course.").' '.
1.61      raeburn  2195:                                   &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  2196:                     }
1.61      raeburn  2197:                     $r->print('</p>');
1.28      raeburn  2198:                 }
                   2199:             }
1.61      raeburn  2200:             if ($showresult{'uploadquota'}) {
                   2201:                 $r->print(&mt('The disk space allocated for content uploaded directly via the Content Editor is now: [_1] MB.',
                   2202:                               '<b>'.$updatedsettings{'internal.uploadquota'}.'</b>').'<br />');
                   2203:             }
1.28      raeburn  2204:         } else {
1.63      raeburn  2205:             $r->print(&mt('An error occurred storing the quota(s) for group portfolio files and/or uploaded content: ').
1.61      raeburn  2206:                       $putreply);
1.28      raeburn  2207:         }
                   2208:     }
1.48      raeburn  2209:     $r->print('<p>'.
                   2210:               '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
                   2211:               &mt('Pick another action').'</a>');
1.28      raeburn  2212:     $r->print(&hidden_form_elements().'</form>');
                   2213:     return;
1.1       raeburn  2214: }
                   2215: 
1.57      raeburn  2216: sub modify_anonsurvey_threshold {
                   2217:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2218:     &print_header($r,$type);
                   2219:     $r->print('<form action="/adm/modifycourse" method="post" name="processthreshold">'."\n".
                   2220:               '<h3>'.&mt('Responder threshold required for display of anonymous survey submissions:').
                   2221:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
                   2222:     my %oldsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
                   2223:     my %domconfig =
                   2224:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                   2225:     my $defaultthreshold; 
                   2226:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   2227:         $defaultthreshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   2228:         if ($defaultthreshold eq '') {
                   2229:             $defaultthreshold = 10;
                   2230:         }
                   2231:     } else {
                   2232:         $defaultthreshold = 10;
                   2233:     }
                   2234:     if ($env{'form.threshold'} eq '') {
                   2235:         $r->print(&mt('The proposed responder threshold for display of anonymous survey submissions was blank, so the threshold is unchanged.'));
                   2236:     } else {
                   2237:         my $newthreshold = $env{'form.threshold'};
                   2238:         if ($newthreshold =~ /^\s*(\d+)\s*$/) {
                   2239:             $newthreshold = $1;
                   2240:             if ($oldsettings{'internal.anonsurvey_threshold'} eq $env{'form.threshold'}) {
                   2241:                 $r->print(&mt('Responder threshold for anonymous survey submissions display remains unchanged: [_1].',$env{'form.threshold'}));
                   2242:             } else {
                   2243:                 my %cenv = (
                   2244:                            'internal.anonsurvey_threshold' => $env{'form.threshold'},
                   2245:                            );
                   2246:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
                   2247:                                                     $cnum);
1.72      raeburn  2248:                 if ($putreply eq 'ok') {
                   2249:                     if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
                   2250:                         &Apache::lonnet::appenv(
                   2251:                            {'course.'.$cdom.'_'.$cnum.'.internal.anonsurvey_threshold' => $env{'form.threshold'}});
                   2252:                     }
                   2253:                 }
1.57      raeburn  2254:                 if (($oldsettings{'internal.anonsurvey_threshold'} eq '') &&
                   2255:                     ($env{'form.threshold'} == $defaultthreshold)) {
                   2256:                     $r->print(&mt('The responder threshold for display of anonymous survey submissions is the default for this domain: [_1].',$defaultthreshold));
                   2257:                 } else {
                   2258:                     if ($putreply eq 'ok') {
                   2259:                         my %updatedsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
                   2260:                         $r->print(&mt('The responder threshold for display of anonymous survey submissions is now: [_1].','<b>'.$updatedsettings{'internal.anonsurvey_threshold'}.'</b>'));
                   2261:                     } else {
                   2262:                         $r->print(&mt('An error occurred storing the responder threshold for anonymous submissions display: ').
                   2263:                                   $putreply);
                   2264:                     }
                   2265:                 }
                   2266:             }
                   2267:         } else {
                   2268:             $r->print(&mt('The proposed responder threshold for display of anonymous submissions contained invalid characters, so the threshold is unchanged.'));
                   2269:         }
                   2270:     }
                   2271:     $r->print('<p>'.
                   2272:               '<a href="javascript:changePage(document.processthreshold,'."'menu'".')">'.
1.75      raeburn  2273:               &mt('Pick another action').'</a></p>');
                   2274:     $r->print(&hidden_form_elements().'</form>');
                   2275:     return;
                   2276: }
                   2277: 
                   2278: sub modify_postsubmit_config {
                   2279:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2280:     &print_header($r,$type);
                   2281:     my %lt = &Apache::lonlocal::texthash(
                   2282:                 subb => 'Submit button behavior after student makes a submission:',
                   2283:                 unch => 'Post submission behavior of the Submit button is unchanged.',
                   2284:                 erro => 'An error occurred when saving your proposed changes.',
                   2285:                 inva => 'An invalid response was recorded.',
                   2286:                 pick => 'Pick another action',
                   2287:              );
                   2288:     $r->print('<form action="/adm/modifycourse" method="post" name="processpostsubmit">'."\n".
                   2289:               '<h3>'.$lt{'subb'}.' <span class="LC_nobreak">('.$cdesc.')</span></h3><br />');
                   2290:     my %oldsettings = 
                   2291:         &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout','internal.coursecode','internal.textbook'],$cdom,$cnum);
                   2292:     my $postsubmit = $env{'form.postsubmit'};
                   2293:     if ($postsubmit eq '1') {
                   2294:         my $postsubtimeout = $env{'form.postsubtimeout'};
                   2295:         $postsubtimeout =~ s/[^\d\.]+//g;
                   2296:         if (($oldsettings{'internal.postsubmit'} eq $postsubmit) && ($oldsettings{'internal.postsubtimeout'} eq $postsubtimeout)) {
                   2297:             $r->print($lt{'unch'}); 
                   2298:         } else {
                   2299:             my %cenv = (
                   2300:                          'internal.postsubmit' => $postsubmit,
                   2301:                        );
                   2302:             if ($postsubtimeout eq '') {
                   2303:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                   2304:                 if ($putreply eq 'ok') {
                   2305:                     my $defaulttimeout = &domain_postsubtimeout($cdom,$type,\%oldsettings);
                   2306:                     $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));
                   2307:                     if (exists($oldsettings{'internal.postsubtimeout'})) {
                   2308:                         &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);
                   2309:                     }
                   2310:                 } else {
                   2311:                     $r->print($lt{'erro'});
                   2312:                 }
                   2313:             } else { 
                   2314:                 $cenv{'internal.postsubtimeout'} = $postsubtimeout;
                   2315:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                   2316:                 if ($putreply eq 'ok') {
                   2317:                     if ($postsubtimeout eq '0') {
                   2318:                         $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.')); 
                   2319:                     } else {
                   2320:                         $r->print(&mt('Submit button will be disabled after student submission for [quant,_1,second].',$postsubtimeout));
                   2321:                     }
                   2322:                 } else {
                   2323:                     $r->print($lt{'erro'});
                   2324:                 }
                   2325:             }
                   2326:         }
                   2327:     } elsif ($postsubmit eq '0') {
                   2328:         if ($oldsettings{'internal.postsubmit'} eq $postsubmit) {
                   2329:             $r->print($lt{'unch'});
                   2330:         } else {
                   2331:             if (exists($oldsettings{'internal.postsubtimeout'})) {
                   2332:                 &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);  
                   2333:             }
                   2334:             my %cenv = (
                   2335:                          'internal.postsubmit' => $postsubmit,
                   2336:                        );
                   2337:             my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                   2338:             if ($putreply eq 'ok') {
1.76      droeschl 2339:                 $r->print(&mt('Submit button will not be disabled after student submission'));
1.75      raeburn  2340:             } else {
                   2341:                 $r->print($lt{'erro'});
                   2342:             }
                   2343:         }
                   2344:     } else {
                   2345:         $r->print($lt{'inva'}.' '.$lt{'unch'});
                   2346:     }
                   2347:     $r->print('<p>'.
                   2348:               '<a href="javascript:changePage(document.processpostsubmit,'."'menu'".')">'.
                   2349:               &mt('Pick another action').'</a></p>');
1.57      raeburn  2350:     $r->print(&hidden_form_elements().'</form>');
                   2351:     return;
                   2352: }
                   2353: 
1.38      raeburn  2354: sub modify_catsettings {
1.48      raeburn  2355:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2356:     &print_header($r,$type);
                   2357:     my ($ccrole,%desc);
                   2358:     if ($type eq 'Community') {
                   2359:         $desc{'hidefromcat'} = &mt('Excluded from community catalog');
                   2360:         $desc{'categories'} = &mt('Assigned categories for this community');
                   2361:         $ccrole = 'co';
                   2362:     } else {
                   2363:         $desc{'hidefromcat'} = &mt('Excluded from course catalog');
                   2364:         $desc{'categories'} = &mt('Assigned categories for this course');
                   2365:         $ccrole = 'cc';
                   2366:     }
1.38      raeburn  2367:     $r->print('
                   2368: <form action="/adm/modifycourse" method="post" name="processcat">
                   2369: <h3>'.&mt('Category settings').'</h3>');
                   2370:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49      raeburn  2371:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38      raeburn  2372:     if (@cat_params > 0) {
                   2373:         my (%cenv,@changes,@nochanges);
                   2374:         my %currsettings =
                   2375:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
                   2376:         my (@newcategories,%showitem); 
                   2377:         if (grep(/^togglecats$/,@cat_params)) {
                   2378:             if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
                   2379:                 push(@changes,'hidefromcat');
                   2380:                 $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
                   2381:             } else {
                   2382:                 push(@nochanges,'hidefromcat');
                   2383:             }
                   2384:             if ($env{'form.hidefromcat'} eq 'yes') {
                   2385:                 $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
                   2386:             } else {
                   2387:                 $showitem{'hidefromcat'} = '"'.&mt('No').'"';
                   2388:             }
                   2389:         }
                   2390:         if (grep(/^categorize$/,@cat_params)) {
                   2391:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   2392:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
                   2393:                 my $cathash = $domconf{'coursecategories'}{'cats'};
                   2394:                 if (ref($cathash) eq 'HASH') {
                   2395:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   2396:                                                            \%allitems,\%idx,\@jsarray);
                   2397:                 }
                   2398:             }
                   2399:             @newcategories =  &Apache::loncommon::get_env_multiple('form.usecategory');
                   2400:             if (@newcategories == 0) {
                   2401:                 $showitem{'categories'} = '"'.&mt('None').'"';
                   2402:             } else {
                   2403:                 $showitem{'categories'} = '<ul>';
                   2404:                 foreach my $item (@newcategories) {
                   2405:                     $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
                   2406:                 }
                   2407:                 $showitem{'categories'} .= '</ul>';
                   2408:             }
                   2409:             my $catchg = 0;
                   2410:             if ($currsettings{'categories'} ne '') {
                   2411:                 my @currcategories = split('&',$currsettings{'categories'});
                   2412:                 foreach my $cat (@currcategories) {
                   2413:                     if (!grep(/^\Q$cat\E$/,@newcategories)) {
                   2414:                         $catchg = 1;
                   2415:                         last;
                   2416:                     }
                   2417:                 }
                   2418:                 if (!$catchg) {
                   2419:                     foreach my $cat (@newcategories) {
                   2420:                         if (!grep(/^\Q$cat\E$/,@currcategories)) {
                   2421:                             $catchg = 1;
                   2422:                             last;                     
                   2423:                         } 
                   2424:                     } 
                   2425:                 }
                   2426:             } else {
                   2427:                 if (@newcategories > 0) {
                   2428:                     $catchg = 1;
                   2429:                 }
                   2430:             }
                   2431:             if ($catchg) {
                   2432:                 $cenv{'categories'} = join('&',@newcategories);
                   2433:                 push(@changes,'categories');
                   2434:             } else {
                   2435:                 push(@nochanges,'categories');
                   2436:             }
                   2437:             if (@changes > 0) {
                   2438:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                   2439:                 if ($putreply eq 'ok') {
1.72      raeburn  2440:                     if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
                   2441:                         my %newenvhash;
                   2442:                         foreach my $item (@changes) {
                   2443:                             $newenvhash{'course.'.$cdom.'_'.$cnum.'.'.$item} = $cenv{$item};
                   2444:                         }
                   2445:                         &Apache::lonnet::appenv(\%newenvhash);
                   2446:                     }
1.38      raeburn  2447:                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
                   2448:                                                                 $cnum,undef,undef,'.');
                   2449:                     if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
                   2450:                         if (grep(/^hidefromcat$/,@changes)) {
                   2451:                             $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
                   2452:                         }
                   2453:                         if (grep(/^categories$/,@changes)) {
                   2454:                             $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
                   2455:                         }
                   2456:                         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
                   2457:                         my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
                   2458:                     }
1.48      raeburn  2459:                     $r->print(&mt('The following changes occurred:').'<ul>');
1.38      raeburn  2460:                     foreach my $item (@changes) {
1.48      raeburn  2461:                         $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38      raeburn  2462:                     }
                   2463:                     $r->print('</ul><br />');
                   2464:                 }
                   2465:             }
                   2466:             if (@nochanges > 0) {
1.48      raeburn  2467:                 $r->print(&mt('The following were unchanged:').'<ul>');
1.38      raeburn  2468:                 foreach my $item (@nochanges) {
1.48      raeburn  2469:                     $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38      raeburn  2470:                 }
                   2471:                 $r->print('</ul>');
                   2472:             }
                   2473:         }
                   2474:     } else {
1.48      raeburn  2475:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                   2476:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                   2477:                                              '=1&destinationurl=/adm/courseprefs','&<>"');
                   2478:         if ($type eq 'Community') {
                   2479:             $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 />');
                   2480:         } else {
                   2481:             $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 />');
                   2482:         }
1.38      raeburn  2483:     }
                   2484:     $r->print('<br />'."\n".
                   2485:               '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
1.48      raeburn  2486:               &mt('Pick another action').'</a>');
1.38      raeburn  2487:     $r->print(&hidden_form_elements().'</form>');
                   2488:     return;
                   2489: }
                   2490: 
1.97      raeburn  2491: sub modify_ltiauth {
                   2492:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2493:     my %lt = &Apache::lonlocal::texthash(
                   2494:                 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item',
                   2495:                 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)',
                   2496:                 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters',
                   2497:                 'used' => 'Use domain default',
                   2498:                 'cour' => 'Use course-specific setting',
                   2499:                 'modi' => 'Save',
                   2500:                 'back' => 'Pick another action',
                   2501:     );
                   2502:     &print_header($r,$type);
                   2503:     $r->print('<form action="/adm/modifycourse" method="post" name="processltiauth">'."\n".
                   2504:               '<h3>'.$lt{'requ'}.
                   2505:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
                   2506:     my %oldsettings = &Apache::lonnet::get('environment',['internal.ltiauth'],$cdom,$cnum);
                   2507:     my $oldltiauth = $oldsettings{'internal.ltiauth'};
                   2508:     my $domdef;
                   2509:     my %domconfig =
                   2510:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                   2511:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   2512:         $domdef = $domconfig{'coursedefaults'}{'ltiauth'};
                   2513:     }
                   2514:     my ($newltiauth,$nochange,$change,$status,$error,$ltiauth);
                   2515:     if ($env{'form.ltiauthset'} eq 'dom') {
                   2516:         if ($oldltiauth eq '') {
                   2517:             $nochange = 1;
                   2518:         } else {
                   2519:             $change = 1;
                   2520:         }
                   2521:     } elsif ($env{'form.ltiauthset'} eq 'course') {
                   2522:         if ($env{'form.ltiauth'} =~ /^0|1$/) { 
                   2523:             $newltiauth = $env{'form.ltiauth'};
                   2524:         }
                   2525:         if ($oldltiauth == $newltiauth) {
                   2526:             $nochange = 1;
                   2527:         } else {
                   2528:             $change = 1;
                   2529:         }
                   2530:     }
                   2531:     if ($change) {
                   2532:         if ($newltiauth ne '') {
                   2533:             my %cenv = (
                   2534:                          'internal.ltiauth' => $newltiauth,
                   2535:                        );
                   2536:             if (&Apache::lonnet::put('environment',\%cenv,$cdom,$cnum) eq 'ok') {
                   2537:                 if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
                   2538:                     &Apache::lonnet::appenv(
                   2539:                        {'course.'.$cdom.'_'.$cnum.'.internal.ltiauth' => $newltiauth});
                   2540:                 }
                   2541:             } else {
                   2542:                 $error = 1;
                   2543:             }
                   2544:         } else {
                   2545:             if (&Apache::lonnet::del('environment',['internal.ltiauth'],$cdom,$cnum) eq 'ok') {
                   2546:                 if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.ltiauth'})) {
                   2547:                     &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.internal.ltiauth');
                   2548:                 }
                   2549:             } else {
                   2550:                 $error = 1;
                   2551:             }
                   2552:         }
                   2553:     }
                   2554:     if ($error) {
                   2555:         $nochange = 1;
                   2556:     }
                   2557:     if ($nochange) {
                   2558:         $ltiauth = $oldltiauth;
                   2559:     } else {
                   2560:         $ltiauth = $newltiauth;
                   2561:     }
                   2562:     if ($ltiauth eq '') {
                   2563:         $status = $lt{'used'}.': ';
                   2564:         if ($domdef) {
                   2565:             $status .= '<span style="font-style:italic">'.$lt{'link'}.'</span>';
                   2566:         } else {
                   2567:             $status .= '<span style="font-style:italic">'.$lt{'logi'}.'</span>';
                   2568:         }
                   2569:     } else {
                   2570:         $status = $lt{'cour'}.': ';
                   2571:         if ($ltiauth) {
                   2572:             $status .= '<span style="font-style:italic">'.$lt{'link'}.'</span>';
                   2573:         } else {
                   2574:             $status .= '<span style="font-style:italic">'.$lt{'logi'}.'</span>';
                   2575:         }
                   2576:     }
                   2577:     if ($error) {
                   2578:         $r->print('<p class="LC_warning">'.&mt('An error occurred when saving your changes').'</p>');
                   2579:     }
                   2580:     $r->print('<p>');
                   2581:     if ($nochange) {
                   2582:         $r->print(&mt('Re-authentication requirement for LTI launch of deep-linked item is unchanged'));
                   2583:     } elsif ($change) {
                   2584:         $r->print(&mt('Re-authentication requirement for LTI launch of deep-linked changed'));
                   2585:     }
                   2586:     $r->print('<br />'.$status);
                   2587:     $r->print('</p><p>'.
                   2588:               '<a href="javascript:changePage(document.processltiauth,'."'menu'".')">'.
1.99      raeburn  2589:               $lt{'back'}.'</a></p>');
                   2590:     $r->print(&hidden_form_elements().'</form>');
                   2591:     return;
                   2592: }
                   2593: 
                   2594: sub modify_exttool {
                   2595:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   2596:     my %titles = &exttool_titles($type);
                   2597:     &print_header($r,$type);
                   2598:     $r->print('<form action="/adm/modifycourse" method="post" name="processexttool">'."\n".
                   2599:               '<h3>'.$titles{'extt'}.'</h3>'.
                   2600:               '<h4><span class="LC_nobreak">'.$type.': '.$cdesc.'</span></h4>');
                   2601:     my %oldsettings = &Apache::lonnet::get('environment',['internal.exttool'],$cdom,$cnum);
                   2602:     my $oldcrsexttool = $oldsettings{'internal.exttool'};
                   2603:     my $domdefdom = 1;
                   2604:     my $domdef = 0;
                   2605:     my $domdefdisplay;
                   2606:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode',
                   2607:                                         'internal.textbook'],$cdom,$cnum);
                   2608:     my $lctype = &get_lctype($type,\%settings);
                   2609:     my %domconfig =
                   2610:         &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
                   2611:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   2612:         if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
                   2613:             if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) {
                   2614:                 $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype};
                   2615:             }
                   2616:         }
                   2617:         if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
                   2618:             if (exists($domconfig{'coursedefaults'}{'exttool'}{$lctype})) {
                   2619:                 $domdef = $domconfig{'coursedefaults'}{'exttool'}{$lctype};
                   2620:             }
                   2621:         }
                   2622:     }
                   2623:     if ($domdef && $domdefdom) {
                   2624:         $domdefdisplay = $titles{'both'};
                   2625:     } elsif ($domdef) {
                   2626:         $domdefdisplay = $titles{'crs'};
                   2627:     } elsif ($domdefdom) {
                   2628:         $domdefdisplay = $titles{'dom'};
                   2629:     } else {
                   2630:         $domdefdisplay = $titles{'none'};
                   2631:     }
                   2632:     my ($newcrsexttool,$nochange,$change,$status,$error,$exttool);
                   2633:     if ($env{'form.exttoolset'} eq 'dom') {
                   2634:         if ($oldcrsexttool eq '') {
                   2635:             $nochange = 1;
                   2636:         } else {
                   2637:             $change = 1;
                   2638:         }
                   2639:     } elsif ($env{'form.exttoolset'} eq 'course') {
                   2640:         if ($env{'form.exttool'} =~ /^both|dom|crs|none$/) {
                   2641:             $newcrsexttool = $env{'form.exttool'};
                   2642:         }
                   2643:         if ($oldcrsexttool eq $newcrsexttool) {
                   2644:             $nochange = 1;
                   2645:         } else {
                   2646:             $change = 1;
                   2647:         }
                   2648:     }
                   2649:     if ($change) {
                   2650:         if ($newcrsexttool ne '') {
                   2651:             my %cenv = (
                   2652:                          'internal.exttool' => $newcrsexttool,
                   2653:                        );
                   2654:             if (&Apache::lonnet::put('environment',\%cenv,$cdom,$cnum) eq 'ok') {
                   2655:                 if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
                   2656:                     &Apache::lonnet::appenv(
                   2657:                        {'course.'.$cdom.'_'.$cnum.'.internal.exttool' => $newcrsexttool});
                   2658:                 }
                   2659:             } else {
                   2660:                 $error = 1;
                   2661:             }
                   2662:         } else {
                   2663:             if (&Apache::lonnet::del('environment',['internal.exttool'],$cdom,$cnum) eq 'ok') {
                   2664:                 if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.exttool'})) {
                   2665:                     &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.internal.exttool');
                   2666:                 }
                   2667:             } else {
                   2668:                 $error = 1;
                   2669:             }
                   2670:         }
                   2671:     }
                   2672:     if ($error) {
                   2673:         $nochange = 1;
                   2674:     }
                   2675:     if ($nochange) {
                   2676:         $exttool = $oldcrsexttool;
                   2677:     } else {
                   2678:         $exttool = $newcrsexttool;
                   2679:     }
                   2680:     if ($exttool eq '') {
                   2681:         $status = $titles{'used'}.': <span style="font-style:italic">'.$domdefdisplay.'</span>';
                   2682:     } else {
                   2683:         $status = $titles{'cour'}.': <span style="font-style:italic">'.$titles{$exttool}.'</span>';
                   2684:     }
                   2685:     if ($error) {
                   2686:         $r->print('<p class="LC_warning">'.&mt('An error occurred when saving your changes').'</p>');
                   2687:     }
                   2688:     $r->print('<p>');
                   2689:     if ($nochange) {
                   2690:         $r->print(&mt('External Tool permissions unchanged'));
                   2691:     } elsif ($change) {
                   2692:         $r->print(&mt('External Tool permissions changed'));
                   2693:     }
                   2694:     $r->print('<br />'.$status);
                   2695:     $r->print('</p><p>'.
                   2696:               '<a href="javascript:changePage(document.processexttool,'."'menu'".')">'.
                   2697:               $titles{'back'}.'</a></p>');
1.97      raeburn  2698:     $r->print(&hidden_form_elements().'</form>');
                   2699:     return;
                   2700: }
                   2701: 
1.1       raeburn  2702: sub print_header {
1.48      raeburn  2703:     my ($r,$type,$javascript_validations) = @_;
1.28      raeburn  2704:     my $phase = "start";
                   2705:     if ( exists($env{'form.phase'}) ) {
                   2706:         $phase = $env{'form.phase'};
                   2707:     }
                   2708:     my $js = qq|
1.60      raeburn  2709: 
1.28      raeburn  2710: function changePage(formname,newphase) {
                   2711:     formname.phase.value = newphase;
                   2712:     if (newphase == 'processparms') {
                   2713:         return;
1.1       raeburn  2714:     }
1.28      raeburn  2715:     formname.submit();
                   2716: }
1.60      raeburn  2717: 
1.28      raeburn  2718: |;
                   2719:     if ($phase eq 'setparms') {
1.60      raeburn  2720: 	$js .= $javascript_validations;
1.28      raeburn  2721:     } elsif ($phase eq 'courselist') {
1.90      raeburn  2722:         $js .= <<"ENDJS";
1.60      raeburn  2723: function hide_searching() {
                   2724:     if (document.getElementById('searching')) {
                   2725:         document.getElementById('searching').style.display = 'none';
                   2726:     }
                   2727:     return;
                   2728: }
                   2729: 
1.90      raeburn  2730: ENDJS
1.28      raeburn  2731:     } elsif ($phase eq 'setquota') {
1.57      raeburn  2732:         my $invalid = &mt('The quota you entered contained invalid characters.');
                   2733:         my $alert = &mt('You must enter a number');
1.78      damieng  2734:         &js_escape(\$invalid);
                   2735:         &js_escape(\$alert);
1.57      raeburn  2736:         my $regexp = '/^\s*(\d+\.?\d*|\.\d+)\s*$/';
                   2737:         $js .= <<"ENDSCRIPT";
1.60      raeburn  2738: 
1.57      raeburn  2739: function verify_quota() {
1.101   ! raeburn  2740:     var newcoursequota = document.setquota.coursequota.value;
        !          2741:     var newuploadquota = document.setquota.uploadquota.value;
1.57      raeburn  2742:     var num_reg = $regexp;
1.101   ! raeburn  2743:     if ((num_reg.test(newcoursequota)) && (num_reg.test(newuploadquota))) {
1.57      raeburn  2744:         changePage(document.setquota,'processquota');
1.1       raeburn  2745:     } else {
1.57      raeburn  2746:         alert("$invalid\\n$alert");
                   2747:         return false;
1.1       raeburn  2748:     }
1.57      raeburn  2749:     return true;
                   2750: }
1.60      raeburn  2751: 
1.57      raeburn  2752: ENDSCRIPT
                   2753:     } elsif ($phase eq 'setanon') {
                   2754:         my $invalid = &mt('The responder threshold you entered is invalid.');
                   2755:         my $alert = &mt('You must enter a positive integer.');
1.78      damieng  2756:         &js_escape(\$invalid);
                   2757:         &js_escape(\$alert);
1.57      raeburn  2758:         my $regexp = ' /^\s*\d+\s*$/';
                   2759:         $js .= <<"ENDSCRIPT";
1.60      raeburn  2760: 
1.57      raeburn  2761: function verify_anon_threshold() {
                   2762:     var newthreshold = document.setanon.threshold.value;
                   2763:     var num_reg = $regexp;
                   2764:     if (num_reg.test(newthreshold)) {
                   2765:         if (newthreshold > 0) {
                   2766:             changePage(document.setanon,'processthreshold');
                   2767:         } else {
                   2768:             alert("$invalid\\n$alert");
                   2769:             return false;
                   2770:         }
                   2771:     } else {
                   2772:         alert("$invalid\\n$alert");
                   2773:         return false;
                   2774:     }
                   2775:     return true;
1.28      raeburn  2776: }
1.60      raeburn  2777: 
1.28      raeburn  2778: ENDSCRIPT
1.75      raeburn  2779:     } elsif ($phase eq 'setpostsubmit') {
                   2780:         my $invalid = &mt('The choice entered for disabling the submit button is invalid.');
                   2781:         my $invalidtimeout = &mt('The timeout you entered for disabling the submit button is invalid.');
                   2782:         my $alert = &mt('Enter one of: a positive integer, 0 (for no timeout), or leave blank to use domain default');
1.78      damieng  2783:         &js_escape(\$invalid);
                   2784:         &js_escape(\$invalidtimeout);
                   2785:         &js_escape(\$alert);
1.75      raeburn  2786:         my $regexp = ' /^\s*\d+\s*$/';
                   2787: 
                   2788:         $js .= <<"ENDSCRIPT"; 
                   2789: 
                   2790: function verify_postsubmit() {
                   2791:     var optionsElement = document.setpostsubmit.postsubmit;
                   2792:     var verified = '';
                   2793:     if (optionsElement.length) {
                   2794:         var currval;
                   2795:         for (var i=0; i<optionsElement.length; i++) {
                   2796:             if (optionsElement[i].checked) {
                   2797:                currval = optionsElement[i].value;
                   2798:             }
                   2799:         }
                   2800:         if (currval == 1) {
                   2801:             var newtimeout = document.setpostsubmit.postsubtimeout.value;
                   2802:             if (newtimeout == '') {
                   2803:                 verified = 'ok';
                   2804:             } else {
                   2805:                 var num_reg = $regexp;
                   2806:                 if (num_reg.test(newtimeout)) {
                   2807:                     if (newtimeout>= 0) {
                   2808:                         verified = 'ok';
                   2809:                     } else {
                   2810:                         alert("$invalidtimeout\\n$alert");
                   2811:                         return false;
                   2812:                     }
                   2813:                 } else {
                   2814:                     alert("$invalid\\n$alert");
                   2815:                     return false;
                   2816:                 }
                   2817:             }
                   2818:         } else {
                   2819:             if (currval == 0) {
                   2820:                verified = 'ok'; 
                   2821:             } else {
                   2822:                alert('$invalid');
                   2823:                return false;
                   2824:             }
                   2825:         }
                   2826:         if (verified == 'ok') {
                   2827:             changePage(document.setpostsubmit,'processpostsubmit');
                   2828:             return true;
                   2829:         }
                   2830:     }
                   2831:     return false;
                   2832: }
                   2833: 
                   2834: function togglePostsubmit(caller) {
                   2835:     var optionsElement = document.setpostsubmit.postsubmit;
                   2836:     if (document.getElementById(caller)) {
                   2837:         var divitem = document.getElementById(caller);
                   2838:         var optionsElement = document.setpostsubmit.postsubmit; 
                   2839:         if (optionsElement.length) {
                   2840:             var currval;
                   2841:             for (var i=0; i<optionsElement.length; i++) {
                   2842:                 if (optionsElement[i].checked) {
                   2843:                    currval = optionsElement[i].value;
                   2844:                 }
                   2845:             }
                   2846:             if (currval == 1) {
                   2847:                 divitem.style.display = 'block';
                   2848:             } else {
                   2849:                 divitem.style.display = 'none';
                   2850:             }
                   2851:         }
1.1       raeburn  2852:     }
1.75      raeburn  2853:     return;
                   2854: }
1.60      raeburn  2855: 
1.75      raeburn  2856: ENDSCRIPT
                   2857: 
1.97      raeburn  2858:     } elsif ($phase eq 'setltiauth') {
                   2859:         $js .= <<"ENDJS";
                   2860: function toggleLTIOptions(form) {
                   2861:     var radioname = 'ltiauthset';
                   2862:     var divid = 'crsltiauth';
                   2863:     var num = form.elements[radioname].length;
                   2864:     if (num) {
                   2865:         var setvis = '';
                   2866:         for (var i=0; i<num; i++) {
                   2867:             if (form.elements[radioname][i].checked) {
                   2868:                 if (form.elements[radioname][i].value == 'course') {
                   2869:                     if (document.getElementById(divid)) {
                   2870:                         document.getElementById(divid).style.display = 'inline-block';
                   2871:                     }
                   2872:                     setvis = 1;
                   2873:                 }
                   2874:                 break;
                   2875:             }
                   2876:         }
                   2877:         if (!setvis) {
                   2878:             if (document.getElementById(divid)) {
                   2879:                 document.getElementById(divid).style.display = 'none';
                   2880:             }
                   2881:         }
                   2882:     }
                   2883:     return;
                   2884: }
                   2885: 
                   2886: ENDJS
1.99      raeburn  2887:     } elsif ($phase eq 'setexttool') {
                   2888:         $js .= <<"ENDJS";
                   2889: function toggleExtToolOptions(form) {
                   2890:     var radioname = 'exttoolset';
                   2891:     var divid = 'crsexttool';
                   2892:     var num = form.elements[radioname].length;
                   2893:     if (num) {
                   2894:         var setvis = '';
                   2895:         for (var i=0; i<num; i++) {
                   2896:             if (form.elements[radioname][i].checked) {
                   2897:                 if (form.elements[radioname][i].value == 'course') {
                   2898:                     if (document.getElementById(divid)) {
                   2899:                         document.getElementById(divid).style.display = 'inline-block';
                   2900:                     }
                   2901:                     setvis = 1;
                   2902:                 }
                   2903:                 break;
                   2904:             }
                   2905:         }
                   2906:         if (!setvis) {
                   2907:             if (document.getElementById(divid)) {
                   2908:                 document.getElementById(divid).style.display = 'none';
                   2909:             }
                   2910:         }
                   2911:     }
                   2912:     return;
                   2913: }
                   2914: 
                   2915: ENDJS
1.75      raeburn  2916:     }
1.37      raeburn  2917:     my $starthash;
1.86      raeburn  2918:     if ($env{'form.phase'} eq 'adhocrole') {
1.37      raeburn  2919:         $starthash = {
1.86      raeburn  2920:            add_entries => {'onload' => "javascript:document.adhocrole.submit();"},
1.37      raeburn  2921:                      };
1.60      raeburn  2922:     } elsif ($phase eq 'courselist') {
                   2923:         $starthash = {
1.74      musolffc 2924:            add_entries => {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"},
1.60      raeburn  2925:                      };
1.97      raeburn  2926:     } elsif ($env{'form.phase'} eq 'setltiauth') {
                   2927:         $starthash = {
                   2928:            add_entries => {'onload' => "toggleLTIOptions(document.setltiauth);"},
                   2929:                      };
1.99      raeburn  2930:     } elsif ($env{'form.phase'} eq 'setexttool') {
                   2931:         $starthash = {
                   2932:            add_entries => {'onload' => "toggleExtToolOptions(document.setexttool);"},
                   2933:                      };
1.37      raeburn  2934:     }
1.48      raeburn  2935:     $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
1.60      raeburn  2936: 					     &Apache::lonhtmlcommon::scripttag($js),
                   2937:                                              $starthash));
1.48      raeburn  2938:     my $bread_text = "View/Modify Courses/Communities";
                   2939:     if ($type eq 'Community') {
                   2940:         $bread_text = 'Community Settings';
1.81      raeburn  2941:     } elsif ($type eq 'Placement') {
                   2942:         $bread_text = 'Placement Test Settings';
1.41      raeburn  2943:     } else {
1.48      raeburn  2944:         $bread_text = 'Course Settings';
1.41      raeburn  2945:     }
1.48      raeburn  2946:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5       raeburn  2947:     return;
1.1       raeburn  2948: }
                   2949: 
                   2950: sub print_footer {
1.23      albertel 2951:     my ($r) = @_;
                   2952:     $r->print('<br />'.&Apache::loncommon::end_page());
1.5       raeburn  2953:     return;
1.3       raeburn  2954: }
                   2955: 
                   2956: sub check_course {
1.71      raeburn  2957:     my ($dom,$domdesc) = @_;
                   2958:     my ($ok_course,$description,$instcode);
                   2959:     my %coursehash;
                   2960:     if ($env{'form.pickedcourse'} =~ /^$match_domain\_$match_courseid$/) {
                   2961:         my %args;
                   2962:         unless ($env{'course.'.$env{'form.pickedcourse'}.'.description'}) {
                   2963:             %args = (
                   2964:                       'one_time'      => 1,
                   2965:                       'freshen_cache' => 1,
                   2966:                     );
                   2967:         }
                   2968:         %coursehash =
                   2969:            &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
                   2970:         my $cnum = $coursehash{'num'};
                   2971:         my $cdom = $coursehash{'domain'};
                   2972:         $description = $coursehash{'description'};
                   2973:         $instcode = $coursehash{'internal.coursecode'};
                   2974:         if ($instcode) {
                   2975:             $description .= " ($instcode)";
                   2976:         }
                   2977:         if (($cdom eq $dom) && ($cnum =~ /^$match_courseid$/)) {
                   2978:             my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
                   2979:                                                           $cnum,undef,undef,'.');
                   2980:             if ($courseIDs{$cdom.'_'.$cnum}) {
                   2981:                 $ok_course = 'ok';
1.5       raeburn  2982:             }
1.3       raeburn  2983:         }
                   2984:     }
1.71      raeburn  2985:     return ($ok_course,$description,\%coursehash);
1.1       raeburn  2986: }
                   2987: 
1.28      raeburn  2988: sub course_settings_descrip {
1.48      raeburn  2989:     my ($type) = @_;
                   2990:     my %longtype;
                   2991:     if ($type eq 'Community') {
                   2992:          %longtype = &Apache::lonlocal::texthash(
1.72      raeburn  2993:                       'courseowner'      => "Username:domain of community owner",
                   2994:                       'co-owners'        => "Username:domain of each co-owner",
                   2995:                       'selfenrollmgrdc'  => "Community-specific self-enrollment configuration by Domain Coordinator",
                   2996:                       'selfenrollmgrcc'  => "Community-specific self-enrollment configuration by Community personnel",
1.85      raeburn  2997:                       'mysqltables'      => '"Temporary" student performance tables lifetime (seconds)',
1.48      raeburn  2998:          );
                   2999:     } else {
                   3000:          %longtype = &Apache::lonlocal::texthash(
1.28      raeburn  3001:                       'authtype' => 'Default authentication method',
                   3002:                       'autharg'  => 'Default authentication parameter',
                   3003:                       'autoadds' => 'Automated adds',
                   3004:                       'autodrops' => 'Automated drops',
                   3005:                       'autostart' => 'Date of first automated enrollment',
                   3006:                       'autoend' => 'Date of last automated enrollment',
                   3007:                       'default_enrollment_start_date' => 'Date of first student access',
                   3008:                       'default_enrollment_end_date' => 'Date of last student access',
                   3009:                       'coursecode' => 'Official course code',
                   3010:                       'courseowner' => "Username:domain of course owner",
1.50      raeburn  3011:                       'co-owners'   => "Username:domain of each co-owner",
1.28      raeburn  3012:                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1.48      raeburn  3013:                       'sectionnums' => 'Course section number:LON-CAPA section',
                   3014:                       'crosslistings' => 'Crosslisted class:LON-CAPA section',
1.72      raeburn  3015:                       'defaultcredits' => 'Credits',
1.84      raeburn  3016:                       'autodropfailsafe' => "Failsafe section enrollment count",
1.72      raeburn  3017:                       'selfenrollmgrdc'  => "Course-specific self-enrollment configuration by Domain Coordinator",
                   3018:                       'selfenrollmgrcc'  => "Course-specific self-enrollment configuration by Course personnel",
1.85      raeburn  3019:                       'mysqltables'      => '"Temporary" student performance tables lifetime (seconds)',
1.94      raeburn  3020:                       'nopasswdchg' => 'Disable changing password for users with student role by course owner',
1.48      raeburn  3021:          );
                   3022:     }
1.28      raeburn  3023:     return %longtype;
                   3024: }
                   3025: 
                   3026: sub hidden_form_elements {
                   3027:     my $hidden_elements = 
1.46      raeburn  3028:       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
1.37      raeburn  3029:           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.57      raeburn  3030:           'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
1.75      raeburn  3031:           'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
                   3032:           'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
1.99      raeburn  3033:           'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset',
                   3034:           'exttoolset','exttool'],['^selfenrollmgr_','^selfenroll_'])."\n".
1.37      raeburn  3035:           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28      raeburn  3036:     return $hidden_elements;
                   3037: }
1.1       raeburn  3038: 
1.60      raeburn  3039: sub showcredits {
                   3040:     my ($dom) = @_;
                   3041:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.79      raeburn  3042:     if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.60      raeburn  3043:         return 1;
                   3044:     }
                   3045: }
                   3046: 
1.86      raeburn  3047: sub get_permission {
                   3048:     my ($dom) = @_;
                   3049:     my ($allowed,%permission);
1.94      raeburn  3050:     my %passwdconf = &Apache::lonnet::get_passwdconf($dom);
1.86      raeburn  3051:     if (&Apache::lonnet::allowed('ccc',$dom)) {
                   3052:         $allowed = 1;
                   3053:         %permission = (
1.88      raeburn  3054:             setquota          => 'edit',
                   3055:             processquota      => 'edit',
                   3056:             setanon           => 'edit',
                   3057:             processthreshold  => 'edit',
                   3058:             setpostsubmit     => 'edit',
                   3059:             processpostsubmit => 'edit',
                   3060:             viewparms         => 'view',
                   3061:             setparms          => 'edit',
                   3062:             processparms      => 'edit',
                   3063:             catsettings       => 'edit',
                   3064:             processcat        => 'edit',
                   3065:             selfenroll        => 'edit',
1.90      raeburn  3066:             adhocrole         => 'coord',
1.97      raeburn  3067:             setltiauth        => 'edit',
                   3068:             processltiauth    => 'edit',
1.99      raeburn  3069:             setexttool        => 'edit',
                   3070:             processexttool    => 'edit',
1.86      raeburn  3071:         );
1.94      raeburn  3072:         if ($passwdconf{'crsownerchg'}) {
                   3073:             $permission{passwdchg} = 'edit';
                   3074:         }
1.86      raeburn  3075:     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
                   3076:         $allowed = 1;
                   3077:         %permission = (
1.88      raeburn  3078:             setquota      => 'view',
                   3079:             viewparms     => 'view',
                   3080:             setanon       => 'view',
                   3081:             setpostsubmit => 'view',
                   3082:             setparms      => 'view',
                   3083:             catsettings   => 'view',
                   3084:             selfenroll    => 'view',
1.90      raeburn  3085:             adhocrole     => 'custom',
1.97      raeburn  3086:             setltiauth    => 'view',
1.99      raeburn  3087:             setexttool    => 'view',
1.86      raeburn  3088:         );
1.94      raeburn  3089:         if ($passwdconf{'crsownerchg'}) {
                   3090:             $permission{passwdchg} = 'view';
                   3091:         }
1.86      raeburn  3092:     }
                   3093:     return ($allowed,\%permission);
                   3094: }
                   3095: 
1.95      raeburn  3096: sub devalidate_remote_instcats {
                   3097:     if ($modified_dom ne '') {
                   3098:         my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
                   3099:         my %thismachine;
                   3100:         map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   3101:         if (keys(%servers)) {
                   3102:             foreach my $server (keys(%servers)) {
                   3103:                 next if ($thismachine{$server});
                   3104:                 &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
                   3105:             }
                   3106:         }
                   3107:         $modified_dom = '';
                   3108:     }
                   3109:     return;
                   3110: }
                   3111: 
1.1       raeburn  3112: sub handler {
                   3113:     my $r = shift;
                   3114:     if ($r->header_only) {
                   3115:         &Apache::loncommon::content_type($r,'text/html');
                   3116:         $r->send_http_header;
                   3117:         return OK;
                   3118:     }
1.72      raeburn  3119: 
1.95      raeburn  3120:     $registered_cleanup=0;
                   3121:     $modified_dom = '';
                   3122: 
1.28      raeburn  3123:     my $dom = $env{'request.role.domain'};
1.31      albertel 3124:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.86      raeburn  3125:     my ($allowed,$permission) = &get_permission($dom);
                   3126:     if ($allowed) {
1.1       raeburn  3127:         &Apache::loncommon::content_type($r,'text/html');
                   3128:         $r->send_http_header;
                   3129: 
1.28      raeburn  3130:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                   3131: 
                   3132:         my $phase = $env{'form.phase'};
1.46      raeburn  3133:         if ($env{'form.updater'}) {
                   3134:             $phase = '';
                   3135:         }
1.37      raeburn  3136:         if ($phase eq '') {
                   3137:             &Apache::lonhtmlcommon::add_breadcrumb
1.28      raeburn  3138:             ({href=>"/adm/modifycourse",
1.48      raeburn  3139:               text=>"Course/Community search"});
1.28      raeburn  3140:             &print_course_search_page($r,$dom,$domdesc);
1.1       raeburn  3141:         } else {
1.37      raeburn  3142:             my $firstform = $phase;
                   3143:             if ($phase eq 'courselist') {
                   3144:                 $firstform = 'filterpicker';
1.48      raeburn  3145:             }
                   3146:             my $choose_text;
                   3147:             my $type = $env{'form.type'};
                   3148:             if ($type eq '') {
                   3149:                 $type = 'Course';
                   3150:             }
                   3151:             if ($type eq 'Community') {
                   3152:                 $choose_text = "Choose a community";
1.81      raeburn  3153:             } elsif ($type eq 'Placement') {
                   3154:                 $choose_text = "Choose a placement test";
1.48      raeburn  3155:             } else {
                   3156:                 $choose_text = "Choose a course";
1.37      raeburn  3157:             } 
1.28      raeburn  3158:             &Apache::lonhtmlcommon::add_breadcrumb
1.37      raeburn  3159:             ({href=>"javascript:changePage(document.$firstform,'')",
1.48      raeburn  3160:               text=>"Course/Community search"},
1.37      raeburn  3161:               {href=>"javascript:changePage(document.$phase,'courselist')",
1.48      raeburn  3162:               text=>$choose_text});
1.28      raeburn  3163:             if ($phase eq 'courselist') {
1.90      raeburn  3164:                 &print_course_selection_page($r,$dom,$domdesc,$permission);
1.28      raeburn  3165:             } else {
1.71      raeburn  3166:                 my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc);
1.28      raeburn  3167:                 if ($checked eq 'ok') {
1.48      raeburn  3168:                     my $enter_text;
                   3169:                     if ($type eq 'Community') {
                   3170:                         $enter_text = 'Enter community';
1.81      raeburn  3171:                     } elsif ($type eq 'Placement') {
                   3172:                         $enter_text = 'Enter placement test'; 
1.48      raeburn  3173:                     } else {
                   3174:                         $enter_text = 'Enter course';
                   3175:                     }
1.28      raeburn  3176:                     if ($phase eq 'menu') {
1.37      raeburn  3177:                         &Apache::lonhtmlcommon::add_breadcrumb
                   3178:                         ({href=>"javascript:changePage(document.$phase,'menu')",
                   3179:                           text=>"Pick action"});
1.71      raeburn  3180:                         &print_modification_menu($r,$cdesc,$domdesc,$dom,$type,
1.86      raeburn  3181:                                                  $env{'form.pickedcourse'},$coursehash,
                   3182:                                                  $permission);
                   3183:                     } elsif ($phase eq 'adhocrole') {
1.37      raeburn  3184:                         &Apache::lonhtmlcommon::add_breadcrumb
1.86      raeburn  3185:                          ({href=>"javascript:changePage(document.$phase,'adhocrole')",
1.48      raeburn  3186:                            text=>$enter_text});
1.90      raeburn  3187:                         &print_adhocrole_selected($r,$type,$permission);
1.28      raeburn  3188:                     } else {
1.37      raeburn  3189:                         &Apache::lonhtmlcommon::add_breadcrumb
                   3190:                         ({href=>"javascript:changePage(document.$phase,'menu')",
                   3191:                           text=>"Pick action"});
1.28      raeburn  3192:                         my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1.88      raeburn  3193:                         my ($readonly,$linktext);
                   3194:                         if ($permission->{$phase} eq 'view') {
                   3195:                            $readonly = 1; 
                   3196:                         }
1.86      raeburn  3197:                         if (($phase eq 'setquota') && ($permission->{'setquota'})) {
1.88      raeburn  3198:                             if ($permission->{'setquota'} eq 'view') {
                   3199:                                 $linktext = 'Set quota'; 
                   3200:                             } else {
                   3201:                                 $linktext = 'Display quota';
                   3202:                             }
1.28      raeburn  3203:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3204:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89      raeburn  3205:                               text=>$linktext});
1.88      raeburn  3206:                             &print_setquota($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86      raeburn  3207:                         } elsif (($phase eq 'processquota') && ($permission->{'processquota'})) { 
1.28      raeburn  3208:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3209:                             ({href=>"javascript:changePage(document.$phase,'setquota')",
                   3210:                               text=>"Set quota"});
                   3211:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3212:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3213:                               text=>"Result"});
1.48      raeburn  3214:                             &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86      raeburn  3215:                         } elsif (($phase eq 'setanon') && ($permission->{'setanon'})) {
1.57      raeburn  3216:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3217:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3218:                               text=>"Threshold for anonymous submissions display"});
1.88      raeburn  3219:                             &print_set_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86      raeburn  3220:                         } elsif (($phase eq 'processthreshold') && ($permission->{'processthreshold'})) {
1.57      raeburn  3221:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3222:                             ({href=>"javascript:changePage(document.$phase,'setanon')",
                   3223:                               text=>"Threshold for anonymous submissions display"});
                   3224:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3225:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3226:                               text=>"Result"});
                   3227:                             &modify_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86      raeburn  3228:                         } elsif (($phase eq 'setpostsubmit') && ($permission->{'setpostsubmit'})) {
1.88      raeburn  3229:                             if ($permission->{'setpostsubmit'} eq 'view') {
                   3230:                                 $linktext = 'Submit button behavior post-submission';
                   3231:                             } else {
                   3232:                                 $linktext = 'Configure submit button behavior post-submission';
                   3233:                             }
1.75      raeburn  3234:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3235:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89      raeburn  3236:                               text=>$linktext});
1.88      raeburn  3237:                             &print_postsubmit_config($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86      raeburn  3238:                         } elsif (($phase eq 'processpostsubmit') && ($permission->{'processpostsubmit'})) {
1.75      raeburn  3239:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3240:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3241:                               text=>"Result"});
                   3242:                             &modify_postsubmit_config($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86      raeburn  3243:                         } elsif (($phase eq 'viewparms') && ($permission->{'viewparms'})) {
1.28      raeburn  3244:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3245:                             ({href=>"javascript:changePage(document.$phase,'viewparms')",
                   3246:                               text=>"Display settings"});
1.86      raeburn  3247:                             &print_settings_display($r,$cdom,$cnum,$cdesc,$type,$permission);
                   3248:                         } elsif (($phase eq 'setparms') && ($permission->{'setparms'})) {
1.88      raeburn  3249:                             if ($permission->{'setparms'} eq 'view') {
                   3250:                                 $linktext = 'Display settings';
                   3251:                             } else {
                   3252:                                 $linktext = 'Change settings';
                   3253:                             }
1.28      raeburn  3254:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3255:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89      raeburn  3256:                               text=>$linktext});
1.88      raeburn  3257:                             &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86      raeburn  3258:                         } elsif (($phase eq 'processparms') && ($permission->{'processparms'})) {
1.28      raeburn  3259:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3260:                             ({href=>"javascript:changePage(document.$phase,'setparms')",
                   3261:                               text=>"Change settings"});
                   3262:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3263:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3264:                               text=>"Result"});
1.30      raeburn  3265:                             &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86      raeburn  3266:                         } elsif (($phase eq 'catsettings') && ($permission->{'catsettings'})) {
1.38      raeburn  3267:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3268:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3269:                               text=>"Catalog settings"});
1.88      raeburn  3270:                             &print_catsettings($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86      raeburn  3271:                         } elsif (($phase eq 'processcat') && ($permission->{'processcat'})) {
1.38      raeburn  3272:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3273:                             ({href=>"javascript:changePage(document.$phase,'catsettings')",
                   3274:                               text=>"Catalog settings"});
                   3275:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3276:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3277:                               text=>"Result"});
1.48      raeburn  3278:                             &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86      raeburn  3279:                         } elsif (($phase eq 'selfenroll') && ($permission->{'selfenroll'})) {
1.72      raeburn  3280:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3281:                             ({href => "javascript:changePage(document.$phase,'$phase')",
                   3282:                               text => "Self-enrollment settings"});
                   3283:                             if (!exists($env{'form.state'})) {
1.88      raeburn  3284:                                 &print_selfenrollconfig($r,$type,$cdesc,$coursehash,$readonly);
1.72      raeburn  3285:                             } elsif ($env{'form.state'} eq 'done') {
                   3286:                                 &Apache::lonhtmlcommon::add_breadcrumb 
                   3287:                                 ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3288:                                   text=>"Result"});
                   3289:                                 &modify_selfenrollconfig($r,$type,$cdesc,$coursehash);
                   3290:                             }
1.97      raeburn  3291:                         } elsif (($phase eq 'setltiauth') && ($permission->{'setltiauth'})) {
                   3292:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3293:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   3294:                               text=>"Requirement for re-authentication for LTI launch of deep-linked item"});
                   3295:                             &print_set_ltiauth($r,$cdom,$cnum,$cdesc,$type,$readonly);
                   3296:                         } elsif (($phase eq 'processltiauth') && ($permission->{'processltiauth'})) {
                   3297:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3298:                             ({href=>"javascript:changePage(document.$phase,'setltiauth')",
1.99      raeburn  3299:                               text=>"Requirement for re-authentication for LTI launch of deep-linked item"},
                   3300:                              {href=>"javascript:changePage(document.$phase,'$phase')",
                   3301:                               text=>"Result"});
                   3302:                             &modify_ltiauth($r,$cdom,$cnum,$cdesc,$domdesc,$type);
                   3303:                         } elsif (($phase eq 'setexttool') && ($permission->{'setexttool'})) {
1.97      raeburn  3304:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3305:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
1.99      raeburn  3306:                               text=>"External Tool permission"});
                   3307:                             &print_set_exttool($r,$cdom,$cnum,$cdesc,$type,$readonly);
                   3308:                         } elsif (($phase eq 'processexttool') && ($permission->{'processexttool'})) {
                   3309:                             &Apache::lonhtmlcommon::add_breadcrumb
                   3310:                             ({href=>"javascript:changePage(document.$phase,'setexttool')",
                   3311:                               text=>"External Tool permission"},
                   3312:                              {href=>"javascript:changePage(document.$phase,'$phase')",
1.97      raeburn  3313:                               text=>"Result"});
1.99      raeburn  3314:                             &modify_exttool($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28      raeburn  3315:                         }
                   3316:                     }
                   3317:                 } else {
1.48      raeburn  3318:                     $r->print('<span class="LC_error">');
                   3319:                     if ($type eq 'Community') {
1.72      raeburn  3320:                         $r->print(&mt('The community you selected is not a valid community in this domain'));
1.81      raeburn  3321:                     } elsif ($type eq 'Placement') {
                   3322:                         $r->print(&mt('The course you selected is not a valid placement test in this domain'));
1.72      raeburn  3323:                     } else {
1.48      raeburn  3324:                         $r->print(&mt('The course you selected is not a valid course in this domain'));
                   3325:                     }
                   3326:                     $r->print(" ($domdesc)</span>");
1.28      raeburn  3327:                 }
                   3328:             }
1.1       raeburn  3329:         }
1.28      raeburn  3330:         &print_footer($r);
1.1       raeburn  3331:     } else {
1.16      albertel 3332:         $env{'user.error.msg'}=
1.48      raeburn  3333:         "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
1.1       raeburn  3334:         return HTTP_NOT_ACCEPTABLE;
                   3335:     }
                   3336:     return OK;
                   3337: }
                   3338: 
                   3339: 1;
                   3340: __END__

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