File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.73: download - view: text, annotated - select for diffs
Mon Apr 28 22:20:13 2014 UTC (10 years ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0_RC3, version_2_11_0, HEAD
- Display of self-enrollment settings, and saving of changes takes into
  account domain configuration (or course-specific configuration) which
  determine which self-enrollment settings in a course can be set by a CC.

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

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