File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.71: download - view: text, annotated - select for diffs
Mon Mar 31 01:37:28 2014 UTC (10 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Modify &check_course() to return additional item (ref to %coursehash),
  and eliminate passing of unused request object.

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

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