File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.57.2.1: download - view: text, annotated - select for diffs
Sat Sep 11 21:36:00 2010 UTC (13 years, 8 months ago) by raeburn
Branches: GCI_3
Diff to branchpoint 1.57: preferred, unified
- Customization for GCI_3.
  - Changes in 1.56 excluded from version for GCI_3.

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

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