File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.67: download - view: text, annotated - select for diffs
Thu Feb 27 11:44:40 2014 UTC (10 years, 2 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Internationalization: Proper translation string compilation

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

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