File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.60: download - view: text, annotated - select for diffs
Fri Mar 1 05:01:26 2013 UTC (11 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- DC can modify course default credits value if domain configuration set
  to show credits for official or unofficial courses.

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

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