File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.69: download - view: text, annotated - select for diffs
Thu Mar 13 14:46:46 2014 UTC (10 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Moving &build_filters(), &timebased_select_form, &js_changer()
  from lonpickcourse.pm to loncommon.pm to facilitate re-use.

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

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