File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.48: download - view: text, annotated - select for diffs
Mon Nov 9 03:50:27 2009 UTC (14 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Accommodate Communities.
- More concise wording
- Links to course's 'Automated Enrollment Manager' via role switcher.
- For Courses use pick_box() in interface for modification of institutional code,
    default authentication and owner.
- Eliminate unused code.

    1: # The LearningOnline Network with CAPA
    2: # handler for DC-only modifiable course settings
    3: #
    4: # $Id: lonmodifycourse.pm,v 1.48 2009/11/09 03:50:27 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: package Apache::lonmodifycourse;
   29: 
   30: use strict;
   31: use Apache::Constants qw(:common :http);
   32: use Apache::lonnet;
   33: use Apache::loncommon;
   34: use Apache::lonhtmlcommon;
   35: use Apache::lonlocal;
   36: use Apache::lonuserutils;
   37: use Apache::lonpickcourse;
   38: use lib '/home/httpd/lib/perl';
   39: use LONCAPA;
   40: 
   41: sub get_dc_settable {
   42:     my ($type) = @_;
   43:     if ($type eq 'Community') {
   44:         return ('courseowner');
   45:     } else {
   46:         return ('courseowner','coursecode','authtype','autharg');
   47:     }
   48: }
   49: 
   50: sub autoenroll_keys {
   51:     my $internals = ['coursecode','courseowner','authtype','autharg','autoadds','autodrops',
   52:                          'autostart','autoend','sectionnums','crosslistings'];
   53:     my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
   54:     return ($internals,$accessdates);
   55: }
   56: 
   57: sub catalog_settable {
   58:     my ($confhash) = @_;
   59:     my @settable;
   60:     if (ref($confhash) eq 'HASH') {
   61:         if ($confhash->{'togglecats'} ne 'crs') {
   62:             push(@settable,'togglecats');
   63:         }
   64:         if ($confhash->{'categorize'} ne 'crs') {
   65:             push(@settable,'categorize');
   66:         }
   67:     } else {
   68:         push(@settable,('togglecats','categorize'));
   69:     }
   70:     return @settable;
   71: }
   72: 
   73: sub get_enrollment_settings {
   74:     my ($cdom,$cnum) = @_;
   75:     my ($internals,$accessdates) = &autoenroll_keys();
   76:     my @items;
   77:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { 
   78:         @items = map { 'internal.'.$_; } (@{$internals});
   79:         push(@items,@{$accessdates});
   80:     }
   81:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
   82:     my %enrollvar;
   83:     $enrollvar{'autharg'} = '';
   84:     $enrollvar{'authtype'} = '';
   85:     foreach my $item (keys(%settings)) {
   86:         if ($item =~ m/^internal\.(.+)$/) {
   87:             my $type = $1;
   88:             if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
   89:                 if ($settings{$item} == 1) {
   90:                     $enrollvar{$type} = "ON";
   91:                 } else {
   92:                     $enrollvar{$type} = "OFF";
   93:                 }
   94:             } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
   95:                 if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
   96:                     $enrollvar{$type} = &mt('No end date');
   97:                 } else {
   98:                     $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
   99:                 }
  100:             } elsif ($type eq "sectionnums") {
  101:                 $enrollvar{$type} = $settings{$item};
  102:                 $enrollvar{$type} =~ s/,/, /g;
  103:             } elsif ($type eq "authtype"
  104:                      || $type eq "autharg"    || $type eq "coursecode"
  105:                      || $type eq "crosslistings") {
  106:                 $enrollvar{$type} = $settings{$item};
  107:             } elsif ($type eq 'courseowner') {
  108:                 if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
  109:                     $enrollvar{$type} = $settings{$item};
  110:                 } else {
  111:                     if ($settings{$item} ne '') {
  112:                         $enrollvar{$type} = $settings{$item}.':'.$cdom;
  113:                     }
  114:                 }
  115:             }
  116:         } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
  117:             my $type = $1;
  118:             if ( ($type eq 'end') && ($settings{$item} == 0) ) {
  119:                 $enrollvar{$item} = &mt('No end date');
  120:             } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
  121:                 $enrollvar{$item} = 'When enrolled';
  122:             } else {
  123:                 $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
  124:             }
  125:         }
  126:     }
  127:     return %enrollvar;
  128: }
  129: 
  130: sub print_course_search_page {
  131:     my ($r,$dom,$domdesc) = @_;
  132:     my $action = '/adm/modifycourse';
  133:     my $type = $env{'form.type'};
  134:     if (!defined($env{'form.type'})) {
  135:         $type = 'Course';
  136:     }
  137:     &print_header($r,$type);
  138:     my $filterlist = ['descriptfilter',
  139:                       'instcodefilter','ownerfilter',
  140:                       'coursefilter'];
  141:     my $filter = {};
  142:     my ($numtitles,$cctitle,$dctitle);
  143:     my $ccrole = 'cc';
  144:     if ($type eq 'Community') {
  145:         $ccrole = 'co';
  146:     }
  147:     $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
  148:     $dctitle = &Apache::lonnet::plaintext('dc');
  149:     $r->print(&Apache::lonpickcourse::js_changer());
  150:     if ($type eq 'Community') {
  151:         $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
  152:     } else {
  153:         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
  154:     }   
  155:     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
  156:                              undef,undef,$filter,$action,\$numtitles,'modifycourse'));
  157:     if ($type eq 'Community') {
  158:         $r->print(&mt('Actions available after searching for a community:').'<ul>'.
  159:                   '<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
  160:                   '<li>'.&mt('View or modify community settings which only a [_1] may modify.',$dctitle).
  161:                   '</li>'."\n".'</ul>');
  162:     } else {
  163:         $r->print(&mt('Actions available after searching for a course:').'<ul>'.
  164:                   '<li>'.&mt('Enter the course with the role of [_1]',$cctitle).'</li>'."\n".
  165:                   '<li>'.&mt('View or modify course settings which only a [_1] may modify.',$dctitle).
  166:                   '</li>'."\n".'</ul>');
  167:     }
  168: }
  169: 
  170: sub print_course_selection_page {
  171:     my ($r,$dom,$domdesc) = @_;
  172:     my $type = $env{'form.type'};
  173:     if (!defined($type)) {
  174:         $type = 'Course';
  175:     }
  176:     &print_header($r,$type);
  177: 
  178: # Criteria for course search 
  179:     my $filterlist = ['descriptfilter',
  180:                       'instcodefilter','ownerfilter',
  181:                       'ownerdomfilter','coursefilter'];
  182:     my %filter;
  183:     my $action = '/adm/modifycourse';
  184:     my $dctitle = &Apache::lonnet::plaintext('dc');
  185:     my $numtitles;
  186:     $r->print(&Apache::lonpickcourse::js_changer());
  187:     $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
  188:     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
  189:                                        undef,undef,\%filter,$action,\$numtitles));
  190:     $filter{'domainfilter'} = $dom;
  191:     my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
  192:                                                          \%filter,$numtitles);
  193:     &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
  194:                                                     %courses);
  195:     return;
  196: }
  197: 
  198: sub print_modification_menu {
  199:     my ($r,$cdesc,$domdesc,$dom,$type) = @_;
  200:     &print_header($r,$type);
  201:     my ($ccrole,$setquota_text,$setparams_text,$cat_text);
  202:     if ($type eq 'Community') {
  203:         $ccrole = 'co';
  204:     } else {
  205:         $ccrole = 'cc';
  206:     } 
  207:     my $action = '/adm/modifycourse';
  208:     if ($type eq 'Community') {
  209:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
  210:         $setparams_text = 'View/Modify community owner';
  211:         $cat_text = 'View/Modify catalog settings for community';
  212:     } else {
  213:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
  214:         $setparams_text = 'View/Modify course owner, institutional code, and default authentication';
  215:         $cat_text = 'View/Modify catalog settings for course'; 
  216:     }
  217:     my @menu =
  218:         (
  219:           { text => $setparams_text,
  220:              phase => 'setparms',
  221:           },
  222:           { text  => 'View/Modify quota for group portfolio files',
  223:             phase => 'setquota',
  224:           }
  225:     );
  226:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
  227:     my @additional_params = &catalog_settable($domconf{'coursecategories'});
  228:     if (@additional_params > 0) {
  229:         push (@menu, { text => $cat_text,
  230:                        phase => 'catsettings',
  231:                      });
  232:     }
  233:     unless ($type eq 'Community') {
  234:         push(@menu,
  235:            { text  => 'Display current settings for automated enrollment',
  236:             phase => 'viewparms',
  237:            }
  238:         );
  239:     }
  240:     my $menu_html = '<h3>'.&mt('View/Modify settings for: ').
  241:                     ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n";
  242:     if ($type eq 'Community') {
  243:         $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:');
  244:     } else {
  245:         $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:');
  246:     }
  247:     $menu_html .= '<ul>';
  248:     if ($type eq 'Community') {
  249:         $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>';
  250:     } else {
  251:         $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'.
  252:                        '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>';
  253:     }
  254:     $menu_html .= '<li>'.$setquota_text.'</li>'."\n";
  255:     foreach my $item (@additional_params) {
  256:         if ($type eq 'Community') {
  257:             if ($item eq 'togglecats') {
  258:                 $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&phase=display">','</a>').'</li>'."\n";
  259:             } elsif ($item eq 'categorize') {
  260:                 $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&phase=display">','</a>').'</li>'."\n";
  261:             }
  262:         } else {
  263:             if ($item eq 'togglecats') {
  264:                 $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&phase=display">','</a>').'</li>'."\n";
  265:             } elsif ($item eq 'categorize') {
  266:                 $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&phase=display">','</a>').'</li>'."\n";
  267:             }
  268:         }
  269:     }
  270:     $menu_html .= ' </ul>
  271: <form name="menu" method="post" action="'.$action.'" />'."\n".
  272:     &hidden_form_elements();
  273:     foreach my $menu_item (@menu) {
  274:         $menu_html.='<h3>';
  275:         $menu_html.=
  276:                 qq|<a href="javascript:changePage(document.menu,'$menu_item->{'phase'}')">|;
  277:         $menu_html.= &mt($menu_item->{'text'}).'</a>';
  278:         $menu_html.='</h3>';
  279:     }
  280:     
  281:     $r->print($menu_html);
  282:     return;
  283: }
  284: 
  285: sub print_ccrole_selected {
  286:     my ($r,$type) = @_;
  287:     &print_header($r,$type);
  288:     my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
  289:     $r->print('<form name="ccrole" method="post" action="/adm/roles">
  290: <input type="hidden" name="selectrole" value="1" />
  291: <input type="hidden" name="newrole" value="cc./'.$cdom.'/'.$cnum.'" />
  292: </form>');
  293: }
  294: 
  295: sub print_settings_display {
  296:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
  297:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
  298:     my %longtype = &course_settings_descrip($type);
  299:     my %lt = &Apache::lonlocal::texthash(
  300:             'valu' => 'Current value',
  301:             'cour' => 'Current settings are:',
  302:             'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
  303:             'dcon' => 'Modifiable only by Domain Coordinator',
  304:             'back' => 'Pick another action',
  305:     );
  306:     my $ccrole = 'cc';
  307:     if ($type eq 'Community') {
  308:        $ccrole = 'co';
  309:     }
  310:     my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
  311:     my $dctitle = &Apache::lonnet::plaintext('dc');
  312:     my @modifiable_params = &get_dc_settable($type);
  313:     my ($internals,$accessdates) = &autoenroll_keys();
  314:     my @items;
  315:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
  316:         @items =  (@{$internals},@{$accessdates});
  317:     }
  318:     my $disp_table = &Apache::loncommon::start_data_table()."\n".
  319:                      &Apache::loncommon::start_data_table_header_row()."\n".
  320:                      "<th>&nbsp;</th>\n".
  321:                      "<th>$lt{'valu'}</th>\n".
  322:                      "<th>$lt{'dcon'}</th>\n".
  323:                      &Apache::loncommon::end_data_table_header_row()."\n";
  324:     foreach my $item (@items) {
  325:         $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
  326:                        "<td><b>$longtype{$item}</b></td>\n".
  327:                        "<td>$enrollvar{$item}</td>\n";
  328:         if (grep(/^\Q$item\E$/,@modifiable_params)) {
  329:             $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n"; 
  330:         } else {
  331:             $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
  332:         }
  333:         $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
  334:     }
  335:     $disp_table .= &Apache::loncommon::end_data_table()."\n";
  336:     &print_header($r,$type);
  337:     my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
  338:     my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
  339:                                          '=1&destinationurl=/adm/populate','&<>"'); 
  340:     $r->print('<h3>'.&mt('Current automated enrollment settings for:').
  341:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
  342:               '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
  343:               '<p>'.$lt{'cose'}.'<ul>'.
  344:               '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',$cctitle,'<a href="'.$escuri.'">','</a>').'</li>'.
  345:               '<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".
  346:               '</li></ul></p>'.
  347:               '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
  348:               '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
  349:               &hidden_form_elements().
  350:               '</p></form>'
  351:      );
  352: }
  353: 
  354: sub print_setquota {
  355:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
  356:     my %lt = &Apache::lonlocal::texthash(
  357:                 'cquo' => 'Disk space for storage of group portfolio files for:',
  358:                 'gpqu' => 'Course portfolio files disk space',
  359:                 'modi' => 'Save',
  360:                 'back' => 'Pick another action',
  361:     );
  362:     if ($type eq 'Community') {
  363:         $lt{'gpqu'} = &mt('Community portfolio files disk space');
  364:     }
  365:     my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
  366:     my $coursequota = $settings{'internal.coursequota'};
  367:     if ($coursequota eq '') {
  368:         $coursequota = 20;
  369:     }
  370:     &print_header($r,$type);
  371:     my $hidden_elements = &hidden_form_elements();
  372:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
  373:     $r->print(<<ENDDOCUMENT);
  374: <form action="/adm/modifycourse" method="post" name="setquota">
  375: <h3>$lt{'cquo'} <span class="LC_nobreak">$cdesc</span></h3>
  376: <p>
  377: $helpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb &nbsp;&nbsp;&nbsp;&nbsp;
  378: <input type="button" onClick="javascript:verify_quota(this.form)" value="$lt{'modi'}" />
  379: </p>
  380: $hidden_elements
  381: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
  382: </form>
  383: ENDDOCUMENT
  384:     return;
  385: }
  386: 
  387: sub print_catsettings {
  388:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
  389:     &print_header($r,$type);
  390:     my %lt = &Apache::lonlocal::texthash(
  391:                                          'back'    => 'Pick another action',
  392:                                          'catset'  => 'Catalog Settings for Course',
  393:                                          'visi'    => 'Visibility in Course/Community Catalog',
  394:                                          'exclude' => 'Exclude from course catalog:',
  395:                                          'categ'   => 'Categorize Course',
  396:                                          'assi'    => 'Assign one or more categories and/or subcategories to this course.'
  397:                                         );
  398:     if ($type eq 'Community') {
  399:         $lt{'catset'} = &mt('Catalog Settings for Community');
  400:         $lt{'exclude'} = &mt('Exclude from course catalog');
  401:         $lt{'categ'} = &mt('Categorize Community');
  402:         $lt{'assi'} = &mt('Assign one or more categories and/or subcategories to this community.');
  403:     }
  404:     $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
  405:               '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
  406:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
  407:     my @cat_params = &catalog_settable($domconf{'coursecategories'});
  408:     if (@cat_params > 0) {
  409:         my %currsettings = 
  410:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
  411:         if (grep(/^togglecats$/,@cat_params)) {
  412:             my $excludeon = '';
  413:             my $excludeoff = ' checked="checked" ';
  414:             if ($currsettings{'hidefromcat'} eq 'yes') {
  415:                 $excludeon = $excludeoff;
  416:                 $excludeoff = ''; 
  417:             }
  418:             $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
  419:                       $lt{'exclude'}.
  420:                       '&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>');
  421:             if ($type eq 'Community') {
  422:                 $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."));
  423:             } else {
  424:                 $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>'.
  425:                           '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
  426:                           '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
  427:             }
  428:             $r->print('</ul></p>');
  429:         }
  430:         if (grep(/^categorize$/,@cat_params)) {
  431:             $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
  432:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
  433:                 my $cathash = $domconf{'coursecategories'}{'cats'};
  434:                 if (ref($cathash) eq 'HASH') {
  435:                     $r->print($lt{'assi'}.'<br /><br />'.
  436:                               &Apache::loncommon::assign_categories_table($cathash,
  437:                                                      $currsettings{'categories'}));
  438:                 } else {
  439:                     $r->print(&mt('No categories defined for this domain'));
  440:                 }
  441:             } else {
  442:                 $r->print(&mt('No categories defined for this domain'));
  443:             }
  444:             unless ($type eq 'Community') { 
  445:                 $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>');
  446:             }
  447:         }
  448:         $r->print('<p><input type="button" name="chgcatsettings" value="'.
  449:                   &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
  450:     } else {
  451:         $r->print('<span class="LC_warning">');
  452:         if ($type eq 'Community') {
  453:             $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
  454:         } else {
  455:             $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
  456:         }
  457:         $r->print('</span><br /><br />'."\n".
  458:                   '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
  459:                   $lt{'back'}.'</a>');
  460:     }
  461:     $r->print(&hidden_form_elements().'</form>'."\n");
  462:     return;
  463: }
  464: 
  465: sub print_course_modification_page {
  466:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
  467:     my %lt=&Apache::lonlocal::texthash(
  468:             'actv' => "Active",
  469:             'inac' => "Inactive",
  470:             'ownr' => "Owner",
  471:             'name' => "Name",
  472:             'unme' => "Username:Domain",
  473:             'stus' => "Status",
  474:             'nocc' => 'There is currently no owner set for this course.',
  475:             'gobt' => "Save",
  476:     );
  477:     my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname);
  478:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
  479:     if ($type eq 'Community') {
  480:         $ccrole = 'co';
  481:         $lt{'nocc'} = &mt('There is currently no owner set for this community.');
  482:     } else {
  483:         $ccrole ='cc';
  484:         ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar);
  485:     }
  486:     $ccname = &Apache::lonnet::plaintext($ccrole,$type);
  487:     my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
  488:     my (@local_ccs,%cc_status,%pname);
  489:     foreach my $item (keys(%roleshash)) {
  490:         my ($uname,$udom) = split(/:/,$item);
  491:         if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
  492:             push(@local_ccs,$uname.':'.$udom);
  493:             $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
  494:             $cc_status{$uname.':'.$udom} = $lt{'actv'};
  495:         }
  496:     }
  497:     if (($enrollvar{'courseowner'} ne '') && 
  498:         (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
  499:         push(@local_ccs,$enrollvar{'courseowner'});
  500:         my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
  501:         $pname{$enrollvar{'courseowner'}} = 
  502:                          &Apache::loncommon::plainname($owneruname,$ownerdom);
  503:         my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
  504:                                                               $cdom,$cnum,$ccrole);
  505:         if ($active_cc eq 'active') {
  506:             $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
  507:         } else {
  508:             $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
  509:         }
  510:     }
  511:     @local_ccs = sort(@local_ccs);
  512:     if (@local_ccs == 0) {
  513:         $ownertable = $lt{'nocc'};
  514:     } else {
  515:         my $numlocalcc = scalar(@local_ccs);
  516:         $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
  517:                       &Apache::loncommon::start_data_table()."\n".
  518:                       &Apache::loncommon::start_data_table_header_row()."\n".
  519:                       '<th>'.$lt{'ownr'}.'</th>'.
  520:                       '<th>'.$lt{'name'}.'</th>'.
  521:                       '<th>'.$lt{'unme'}.'</th>'.
  522:                       '<th>'.$lt{'stus'}.'</th>'.
  523:                       &Apache::loncommon::end_data_table_header_row()."\n";
  524:         foreach my $cc (@local_ccs) {
  525:             $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
  526:             if ($cc eq $enrollvar{'courseowner'}) {
  527:                   $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
  528:             } else {
  529:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
  530:             }
  531:             $ownertable .= 
  532:                  '<td>'.$pname{$cc}.'</td>'."\n".
  533:                  '<td>'.$cc.'</td>'."\n".
  534:                  '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
  535:                  &Apache::loncommon::end_data_table_row()."\n";
  536:         }
  537:         $ownertable .= &Apache::loncommon::end_data_table();
  538:     }
  539:     &print_header($r,$type,$javascript_validations);
  540:     my $dctitle = &Apache::lonnet::plaintext('dc');
  541:     my $mainheader = &modifiable_only_title($type);
  542:     my $hidden_elements = &hidden_form_elements();
  543:     $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
  544:               '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
  545:               &Apache::lonhtmlcommon::start_pick_box());
  546:     if ($type eq 'Community') {
  547:         $r->print(&Apache::lonhtmlcommon::row_title(
  548:                   &Apache::loncommon::help_open_topic('Modify_Community_Owner').
  549:                   '&nbsp;'.&mt('Community Owner'))."\n");
  550:     } else {
  551:         $r->print(&Apache::lonhtmlcommon::row_title(
  552:                       &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
  553:                       '&nbsp;'.&mt('Course Code'))."\n".
  554:                   '<input type="text" size="10" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
  555:                   &Apache::lonhtmlcommon::row_closure().
  556:                   &Apache::lonhtmlcommon::row_title(
  557:                      &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
  558:                      '&nbsp;'.&mt('Default Authentication method'))."\n".
  559:                   $authenitems."\n".
  560:                   &Apache::lonhtmlcommon::row_closure().
  561:                   &Apache::lonhtmlcommon::row_title(
  562:                       &Apache::loncommon::help_open_topic('Modify_Course_Owner').
  563:                       '&nbsp;'.&mt('Course Owner'))."\n");
  564:     }
  565:     $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure(1).
  566:               &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements.
  567:               '<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
  568:     if ($type eq 'Community') {
  569:         $r->print('this.form.submit();"');
  570:     } else {
  571:         $r->print('javascript:verify_message(this.form);"');
  572:     }
  573:     $r->print('value="'.$lt{'gobt'}.'" /></p></form>');
  574:     return;
  575: }
  576: 
  577: sub modifiable_only_title {
  578:     my ($type) = @_;
  579:     my $dctitle = &Apache::lonnet::plaintext('dc');
  580:     if ($type eq 'Community') {
  581:         return &mt('Community settings modifiable only by [_1] for:',$dctitle);
  582:     } else {
  583:         return &mt('Course settings modifiable only by [_1] for:',$dctitle);
  584:     }
  585: }
  586: 
  587: sub gather_authenitems {
  588:     my ($cdom,$enrollvar) = @_;
  589:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
  590:     my $curr_authtype = '';
  591:     my $curr_authfield = '';
  592:     if (ref($enrollvar) eq 'HASH') {
  593:         if ($enrollvar->{'authtype'} =~ /^krb/) {
  594:             $curr_authtype = 'krb';
  595:         } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
  596:             $curr_authtype = 'int';
  597:         } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
  598:             $curr_authtype = 'loc';
  599:         }
  600:     }
  601:     unless ($curr_authtype eq '') {
  602:         $curr_authfield = $curr_authtype.'arg';
  603:     }
  604:     my $javascript_validations = 
  605:         &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
  606:                                                       $curr_authtype,$curr_authfield);
  607:     my %param = ( formname => 'document.'.$env{'form.phase'},
  608:            kerb_def_dom => $krbdefdom,
  609:            kerb_def_auth => $krbdef,
  610:            mode => 'modifycourse',
  611:            curr_authtype => $curr_authtype,
  612:            curr_autharg => $enrollvar->{'autharg'}
  613:         );
  614:     my (%authform,$authenitems);
  615:     $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
  616:     $authform{'int'} = &Apache::loncommon::authform_internal(%param);
  617:     $authform{'loc'} = &Apache::loncommon::authform_local(%param);
  618:     foreach my $item ('krb','int','loc') {
  619:         if ($authform{$item} ne '') {
  620:             $authenitems .= $authform{$item}.'<br />';
  621:         }
  622:     }
  623:     return($javascript_validations,$authenitems);
  624: }
  625: 
  626: sub modify_course {
  627:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
  628:     my %longtype = &course_settings_descrip($type);
  629:     my @items = ('internal.courseowner','description');
  630:     unless ($type eq 'Community') {
  631:         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
  632:                      'internal.sectionnums','internal.crosslistings'));
  633:     }
  634:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
  635:     my $description = $settings{'description'};
  636:     my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,%cenv,%changed,
  637:         @changes,@nochanges,@sections,@xlists,@warnings);
  638:     my @modifiable_params = &get_dc_settable($type);
  639:     foreach my $param (@modifiable_params) {
  640:         $currattr{$param} = $settings{'internal.'.$param};
  641:     }
  642:     if ($type eq 'Community') {
  643:         %changed = ( owner  => 0 );
  644:         $ccrole = 'co';
  645:     } else {
  646:         %changed = ( code  => 0,
  647:                      owner => 0,
  648:                    );
  649:         $ccrole = 'cc';
  650:         unless ($settings{'internal.sectionnums'} eq '') {
  651:             if ($settings{'internal.sectionnums'} =~ m/,/) {
  652:                 @sections = split/,/,$settings{'internal.sectionnums'};
  653:             } else {
  654:                 $sections[0] = $settings{'internal.sectionnums'};
  655:             }
  656:         }
  657:         unless ($settings{'internal.crosslistings'} eq'') {
  658:             if ($settings{'internal.crosslistings'} =~ m/,/) {
  659:                 @xlists = split/,/,$settings{'internal.crosslistings'};
  660:             } else {
  661:                 $xlists[0] = $settings{'internal.crosslistings'};
  662:             }
  663:         }
  664:         if ($env{'form.login'} eq 'krb') {
  665:             $newattr{'authtype'} = $env{'form.login'};
  666:             $newattr{'authtype'} .= $env{'form.krbver'};
  667:             $newattr{'autharg'} = $env{'form.krbarg'};
  668:         } elsif ($env{'form.login'} eq 'int') {
  669:             $newattr{'authtype'} ='internal';
  670:             if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
  671:                 $newattr{'autharg'} = $env{'form.intarg'};
  672:             }
  673:         } elsif ($env{'form.login'} eq 'loc') {
  674:             $newattr{'authtype'} = 'localauth';
  675:             if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
  676:                 $newattr{'autharg'} = $env{'form.locarg'};
  677:             }
  678:         }
  679:         if ( $newattr{'authtype'}=~ /^krb/) {
  680:             if ($newattr{'autharg'}  eq '') {
  681:                 push(@warnings,
  682:                            &mt('As you did not include the default Kerberos domain'
  683:                           .' to be used for authentication in this class, the'
  684:                           .' institutional data used by the automated'
  685:                           .' enrollment process must include the Kerberos'
  686:                           .' domain for each new student.'));
  687:             }
  688:         }
  689: 
  690:         if ( exists($env{'form.coursecode'}) ) {
  691:             $newattr{'coursecode'}=$env{'form.coursecode'};
  692:             unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
  693:                 $changed{'code'} = 1;
  694:             }
  695:         }
  696:     }
  697: 
  698:     if ( exists($env{'form.courseowner'}) ) {
  699:         $newattr{'courseowner'}=$env{'form.courseowner'};
  700:         unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
  701:             $changed{'owner'} = 1;
  702:         } 
  703:     }
  704: 
  705:     if ($changed{'owner'} || $changed{'code'}) { 
  706:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
  707:                                                     undef,undef,'.');
  708:         if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
  709:             if ($changed{'code'}) {
  710:                 $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
  711:             }
  712:             if ($changed{'owner'}) {
  713:                 $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
  714:             }
  715:             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
  716:             my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
  717:         }
  718:     }
  719:     foreach my $param (@modifiable_params) {
  720:         if ($currattr{$param} eq $newattr{$param}) {
  721:             push(@nochanges,$param);
  722:         } else {
  723:             $cenv{'internal.'.$param} = $newattr{$param};
  724:             push(@changes,$param);
  725:         }
  726:     }
  727:     if (@changes > 0) {
  728:         $chgresponse = &mt("The following settings have been changed:<br/><ul>");
  729:     }
  730:     if (@nochanges > 0) {
  731:         $nochgresponse = &mt("The following settings remain unchanged:<br/><ul>");
  732:     }
  733:     if (@changes > 0) {
  734:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
  735:         if ($putreply !~ /^ok$/) {
  736:             $response = '<p class="LC_error">'.
  737:                         &mt('There was a problem processing your requested changes.').'<br />';
  738:             if ($type eq 'Community') {
  739:                 $response .= &mt('Settings for this community have been left unchanged.');
  740:             } else {
  741:                 $response .= &mt('Settings for this course have been left unchanged.');
  742:             }
  743:             $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
  744:         } else {
  745:             foreach my $attr (@modifiable_params) {
  746:                 if (grep/^\Q$attr\E$/,@changes) {
  747: 	            $chgresponse .= '<li>'.$longtype{$attr}.' '.&mt('now set to:').' "'.$newattr{$attr}.'".</li>';
  748:                 } else {
  749: 	            $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to:').' "'.$currattr{$attr}.'".</li>';
  750:                 }
  751:             }
  752:             if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
  753:                 if ( $newattr{'courseowner'} eq '') {
  754: 	            push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
  755:                                    '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
  756:                 } else {
  757: 	            if (@sections > 0) {
  758:                         if ($changed{'code'}) {
  759: 	                    foreach my $sec (@sections) {
  760: 		                if ($sec =~ m/^(.+):/) {
  761:                                     my $instsec = $1;
  762: 		                    my $inst_course_id = $newattr{'coursecode'}.$1;
  763:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
  764: 			            if ($course_check eq 'ok') {
  765:                                         my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
  766: 			                unless ($outcome eq 'ok') {
  767:                                
  768: 				            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/>');
  769: 			                }
  770: 			            } else {
  771:                                         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));
  772: 			            }
  773: 		                } else {
  774: 			            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));
  775: 		                }
  776: 		            }
  777: 	                } elsif ($changed{'owner'}) {
  778:                             foreach my $sec (@sections) {
  779:                                 if ($sec =~ m/^(.+):/) {
  780:                                     my $instsec = $1;
  781:                                     my $inst_course_id = $newattr{'coursecode'}.$instsec;
  782:                                     my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
  783:                                     unless ($outcome eq 'ok') {
  784:                                         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));
  785:                                     }
  786:                                 } else {
  787:                                     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));
  788:                                 }
  789:                             }
  790:                         }
  791: 	            } else {
  792: 	                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'}));
  793: 	            }
  794: 	            if ( (@xlists > 0) && ($changed{'owner'}) ) {
  795: 	                foreach my $xlist (@xlists) {
  796: 		            if ($xlist =~ m/^(.+):/) {
  797:                                 my $instxlist = $1;
  798:                                 my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'});
  799: 		                unless ($outcome eq 'ok') {
  800: 			            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));
  801: 		                }
  802: 		            }
  803: 	                }
  804: 	            }
  805:                 }
  806:             }
  807:         }
  808:     } else {
  809:         foreach my $attr (@modifiable_params) {
  810:             $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to').' "'.$currattr{$attr}.'".</li>';
  811:         }
  812:     }
  813: 
  814:     if (@changes > 0) {
  815:         $chgresponse .= "</ul><br/><br/>";
  816:     }
  817:     if (@nochanges > 0) {
  818:         $nochgresponse .=  "</ul><br/><br/>";
  819:     }
  820:     my ($warning,$numwarnings);
  821:     my $numwarnings = scalar(@warnings); 
  822:     if ($numwarnings) {
  823:         $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
  824:         foreach my $warn (@warnings) {
  825:             $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
  826:         }
  827:         $warning .= '</ul></p>';
  828:     }
  829:     if ($response) {
  830:         $reply = $response;
  831:     } else {
  832:         $reply = $chgresponse.$nochgresponse.$warning;
  833:     }
  834:     &print_header($r,$type);
  835:     my $mainheader = &modifiable_only_title($type);
  836:     $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
  837:              '<p>'.$reply.'</p>'."\n".
  838:              '<form action="/adm/modifycourse" method="post" name="processparms">'.
  839:              &hidden_form_elements().
  840:              '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
  841:              &mt('Pick another action').'</a>';
  842:     if ($numwarnings) {
  843:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
  844:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
  845:                                              '=1&destinationurl=/adm/populate','&<>"');
  846: 
  847:         $reply .= '<br /><a href="'.$escuri.'">'.
  848:                   &mt('Go to Automated Enrollment Manager for course').'</a>';
  849:     }
  850:     $reply .= '</form>';
  851:     $r->print($reply);
  852:     return;
  853: }
  854: 
  855: sub modify_quota {
  856:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
  857:     &print_header($r,$type);
  858:     $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
  859:               '<h3>'.&mt('Disk space for storage of group portfolio files for:').
  860:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
  861:     my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
  862:     my $defaultquota = 20;
  863:     if ($env{'form.coursequota'} ne '') {
  864:         my $newquota = $env{'form.coursequota'};
  865:         if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
  866:             $newquota = $1;
  867:             if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
  868:                 $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] Mb.',$env{'form.coursequota'}));
  869:             } else {
  870:                 my %cenv = (
  871:                            'internal.coursequota' => $env{'form.coursequota'},
  872:                            );
  873:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
  874:                                                     $cnum);
  875:                 if (($oldsettings{'internal.coursequota'} eq '') && 
  876:                     ($env{'form.coursequota'} == $defaultquota)) {
  877:                     if ($type eq 'Community') {
  878:                          $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] Mb.',$defaultquota));
  879:                     } else {
  880:                          $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] Mb.',$defaultquota));
  881:                     }
  882:                 } else {
  883:                     if ($putreply eq 'ok') {
  884:                         my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
  885:                         $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] Mb.',$updatedsettings{'internal.coursequota'}));
  886:                         my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
  887:                         if ($usage >= $updatedsettings{'internal.coursequota'}) {
  888:                             my $newoverquota;
  889:                             if ($usage < $oldsettings{'internal.coursequota'}) {
  890:                                 $newoverquota = 'now';
  891:                             }
  892:                             $r->print('<p>');
  893:                             if ($type eq 'Community') {
  894:                                 $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
  895:                                           &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.'));
  896:                             } else {
  897:                                 $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
  898:                                           &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.'));
  899:                             }
  900:                             $r->print('</p>');
  901:                         }
  902:                     } else {
  903:                         $r->print(&mt('An error occurred storing the quota for group portfolio files: ').
  904:                                   $putreply);
  905:                     }
  906:                 }
  907:             }
  908:         } else {
  909:             $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
  910:         }
  911:     }
  912:     $r->print('<p>'.
  913:               '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
  914:               &mt('Pick another action').'</a>');
  915:     $r->print(&hidden_form_elements().'</form>');
  916:     return;
  917: }
  918: 
  919: sub modify_catsettings {
  920:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
  921:     &print_header($r,$type);
  922:     my ($ccrole,%desc);
  923:     if ($type eq 'Community') {
  924:         $desc{'hidefromcat'} = &mt('Excluded from community catalog');
  925:         $desc{'categories'} = &mt('Assigned categories for this community');
  926:         $ccrole = 'co';
  927:     } else {
  928:         $desc{'hidefromcat'} = &mt('Excluded from course catalog');
  929:         $desc{'categories'} = &mt('Assigned categories for this course');
  930:         $ccrole = 'cc';
  931:     }
  932:     $r->print('
  933: <form action="/adm/modifycourse" method="post" name="processcat">
  934: <h3>'.&mt('Category settings').'</h3>');
  935:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
  936:     my @cat_params = &catalog_settable($domconf{'coursecategories'});
  937:     if (@cat_params > 0) {
  938:         my (%cenv,@changes,@nochanges);
  939:         my %currsettings =
  940:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
  941:         my (@newcategories,%showitem); 
  942:         if (grep(/^togglecats$/,@cat_params)) {
  943:             if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
  944:                 push(@changes,'hidefromcat');
  945:                 $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
  946:             } else {
  947:                 push(@nochanges,'hidefromcat');
  948:             }
  949:             if ($env{'form.hidefromcat'} eq 'yes') {
  950:                 $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
  951:             } else {
  952:                 $showitem{'hidefromcat'} = '"'.&mt('No').'"';
  953:             }
  954:         }
  955:         if (grep(/^categorize$/,@cat_params)) {
  956:             my (@cats,@trails,%allitems,%idx,@jsarray);
  957:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
  958:                 my $cathash = $domconf{'coursecategories'}{'cats'};
  959:                 if (ref($cathash) eq 'HASH') {
  960:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
  961:                                                            \%allitems,\%idx,\@jsarray);
  962:                 }
  963:             }
  964:             @newcategories =  &Apache::loncommon::get_env_multiple('form.usecategory');
  965:             if (@newcategories == 0) {
  966:                 $showitem{'categories'} = '"'.&mt('None').'"';
  967:             } else {
  968:                 $showitem{'categories'} = '<ul>';
  969:                 foreach my $item (@newcategories) {
  970:                     $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
  971:                 }
  972:                 $showitem{'categories'} .= '</ul>';
  973:             }
  974:             my $catchg = 0;
  975:             if ($currsettings{'categories'} ne '') {
  976:                 my @currcategories = split('&',$currsettings{'categories'});
  977:                 foreach my $cat (@currcategories) {
  978:                     if (!grep(/^\Q$cat\E$/,@newcategories)) {
  979:                         $catchg = 1;
  980:                         last;
  981:                     }
  982:                 }
  983:                 if (!$catchg) {
  984:                     foreach my $cat (@newcategories) {
  985:                         if (!grep(/^\Q$cat\E$/,@currcategories)) {
  986:                             $catchg = 1;
  987:                             last;                     
  988:                         } 
  989:                     } 
  990:                 }
  991:             } else {
  992:                 if (@newcategories > 0) {
  993:                     $catchg = 1;
  994:                 }
  995:             }
  996:             if ($catchg) {
  997:                 $cenv{'categories'} = join('&',@newcategories);
  998:                 push(@changes,'categories');
  999:             } else {
 1000:                 push(@nochanges,'categories');
 1001:             }
 1002:             if (@changes > 0) {
 1003:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
 1004:                 if ($putreply eq 'ok') {
 1005:                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
 1006:                                                                 $cnum,undef,undef,'.');
 1007:                     if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
 1008:                         if (grep(/^hidefromcat$/,@changes)) {
 1009:                             $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
 1010:                         }
 1011:                         if (grep(/^categories$/,@changes)) {
 1012:                             $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
 1013:                         }
 1014:                         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
 1015:                         my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
 1016:                     }
 1017:                     $r->print(&mt('The following changes occurred:').'<ul>');
 1018:                     foreach my $item (@changes) {
 1019:                         $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
 1020:                     }
 1021:                     $r->print('</ul><br />');
 1022:                 }
 1023:             }
 1024:             if (@nochanges > 0) {
 1025:                 $r->print(&mt('The following were unchanged:').'<ul>');
 1026:                 foreach my $item (@nochanges) {
 1027:                     $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
 1028:                 }
 1029:                 $r->print('</ul>');
 1030:             }
 1031:         }
 1032:     } else {
 1033:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
 1034:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
 1035:                                              '=1&destinationurl=/adm/courseprefs','&<>"');
 1036:         if ($type eq 'Community') {
 1037:             $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 />');
 1038:         } else {
 1039:             $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 />');
 1040:         }
 1041:     }
 1042:     $r->print('<br />'."\n".
 1043:               '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
 1044:               &mt('Pick another action').'</a>');
 1045:     $r->print(&hidden_form_elements().'</form>');
 1046:     return;
 1047: }
 1048: 
 1049: sub print_header {
 1050:     my ($r,$type,$javascript_validations) = @_;
 1051:     my $phase = "start";
 1052:     if ( exists($env{'form.phase'}) ) {
 1053:         $phase = $env{'form.phase'};
 1054:     }
 1055:     my $js = qq|
 1056: <script type="text/javascript">
 1057: function changePage(formname,newphase) {
 1058:     formname.phase.value = newphase;
 1059:     if (newphase == 'processparms') {
 1060:         return;
 1061:     }
 1062:     formname.submit();
 1063: }
 1064: </script>
 1065: |;
 1066:     if ($phase eq 'setparms') {
 1067: 	$js .= qq|
 1068: <script  type="text/javascript">
 1069: $javascript_validations
 1070: </script>
 1071: |;
 1072:     } elsif ($phase eq 'courselist') {
 1073:         $js .= qq|
 1074: <script type="text/javascript">
 1075: function gochoose(cname,cdom,cdesc) {
 1076:     document.courselist.pickedcourse.value = cdom+'_'+cname;
 1077:     document.courselist.submit();
 1078: }
 1079: </script>
 1080: |;
 1081:     } elsif ($phase eq 'setquota') {
 1082:         $js .= <<'ENDSCRIPT';
 1083: <script type="text/javascript">
 1084: function verify_quota(formname) {
 1085:     var newquota = formname.coursequota.value; 
 1086:     var num_reg = /^\s*(\d+\.?\d*|\.\d+)\s*$/;
 1087:     if (num_reg.test(newquota)) {
 1088:         changePage(formname,'processquota');
 1089:     } else {
 1090:         alert("The quota you entered contained invalid characters.\nYou must enter a number");
 1091:     }
 1092:     return;
 1093: }
 1094: </script>
 1095: ENDSCRIPT
 1096:     }
 1097:     my $starthash;
 1098:     if ($env{'form.phase'} eq 'ccrole') {
 1099:         $starthash = {
 1100:            add_entries => {'onload' => "javascript:document.ccrole.submit();"},
 1101:                      };
 1102:     }
 1103:     $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
 1104: 					     $js,$starthash));
 1105:     my $bread_text = "View/Modify Courses/Communities";
 1106:     if ($type eq 'Community') {
 1107:         $bread_text = 'Community Settings';
 1108:     } else {
 1109:         $bread_text = 'Course Settings';
 1110:     }
 1111:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
 1112:     return;
 1113: }
 1114: 
 1115: sub print_footer {
 1116:     my ($r) = @_;
 1117:     $r->print('<br />'.&Apache::loncommon::end_page());
 1118:     return;
 1119: }
 1120: 
 1121: sub check_course {
 1122:     my ($r,$dom,$domdesc) = @_;
 1123:     my ($ok_course,$description,$instcode,$owner);
 1124:     my %args = (
 1125:                  one_time => 1,
 1126:                );
 1127:     my %coursehash = 
 1128:         &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
 1129:     my $cnum = $coursehash{'num'};
 1130:     my $cdom = $coursehash{'domain'};
 1131:     if ($cdom eq $dom) {
 1132:         my $description;
 1133:         my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
 1134:                                                       $cnum,undef,undef,'.');
 1135:         if (keys(%courseIDs) > 0) {
 1136:             $ok_course = 'ok';
 1137:             my ($instcode,$owner);
 1138:             if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
 1139:                 $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
 1140:                 $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
 1141:                 $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};          
 1142:             } else {
 1143:                 ($description,$instcode,$owner) = 
 1144:                                    split(/:/,$courseIDs{$cdom.'_'.$cnum});
 1145:             }
 1146:             $description = &unescape($description);
 1147:             $instcode = &unescape($instcode);
 1148:             if ($instcode) {
 1149:                 $description .= " ($instcode)";
 1150:             }
 1151:             return ($ok_course,$description);
 1152:         }
 1153:     }
 1154: }
 1155: 
 1156: sub course_settings_descrip {
 1157:     my ($type) = @_;
 1158:     my %longtype;
 1159:     if ($type eq 'Community') {
 1160:          %longtype = &Apache::lonlocal::texthash(
 1161:                       'courseowner' => "Username:domain of community owner",
 1162:          );
 1163: 
 1164:     } else {
 1165:          %longtype = &Apache::lonlocal::texthash(
 1166:                       'authtype' => 'Default authentication method',
 1167:                       'autharg'  => 'Default authentication parameter',
 1168:                       'autoadds' => 'Automated adds',
 1169:                       'autodrops' => 'Automated drops',
 1170:                       'autostart' => 'Date of first automated enrollment',
 1171:                       'autoend' => 'Date of last automated enrollment',
 1172:                       'default_enrollment_start_date' => 'Date of first student access',
 1173:                       'default_enrollment_end_date' => 'Date of last student access',
 1174:                       'coursecode' => 'Official course code',
 1175:                       'courseowner' => "Username:domain of course owner",
 1176:                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
 1177:                       'sectionnums' => 'Course section number:LON-CAPA section',
 1178:                       'crosslistings' => 'Crosslisted class:LON-CAPA section',
 1179:          );
 1180:     }
 1181:     return %longtype;
 1182: }
 1183: 
 1184: sub hidden_form_elements {
 1185:     my $hidden_elements = 
 1186:       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
 1187:           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
 1188:           'locarg','krbarg','krbver','counter','hidefromcat','usecategory'])."\n".
 1189:           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
 1190:     return $hidden_elements;
 1191: }
 1192: 
 1193: sub handler {
 1194:     my $r = shift;
 1195:     if ($r->header_only) {
 1196:         &Apache::loncommon::content_type($r,'text/html');
 1197:         $r->send_http_header;
 1198:         return OK;
 1199:     }
 1200:     my $dom = $env{'request.role.domain'};
 1201:     my $domdesc = &Apache::lonnet::domain($dom,'description');
 1202:     if (&Apache::lonnet::allowed('ccc',$dom)) {
 1203:         &Apache::loncommon::content_type($r,'text/html');
 1204:         $r->send_http_header;
 1205: 
 1206:         &Apache::lonhtmlcommon::clear_breadcrumbs();
 1207: 
 1208:         my $phase = $env{'form.phase'};
 1209:         if ($env{'form.updater'}) {
 1210:             $phase = '';
 1211:         }
 1212:         if ($phase eq '') {
 1213:             &Apache::lonhtmlcommon::add_breadcrumb
 1214:             ({href=>"/adm/modifycourse",
 1215:               text=>"Course/Community search"});
 1216:             &print_course_search_page($r,$dom,$domdesc);
 1217:         } else {
 1218:             my $firstform = $phase;
 1219:             if ($phase eq 'courselist') {
 1220:                 $firstform = 'filterpicker';
 1221:             }
 1222:             my $choose_text;
 1223:             my $type = $env{'form.type'};
 1224:             if ($type eq '') {
 1225:                 $type = 'Course';
 1226:             }
 1227:             if ($type eq 'Community') {
 1228:                 $choose_text = "Choose a community";
 1229:             } else {
 1230:                 $choose_text = "Choose a course";
 1231:             } 
 1232:             &Apache::lonhtmlcommon::add_breadcrumb
 1233:             ({href=>"javascript:changePage(document.$firstform,'')",
 1234:               text=>"Course/Community search"},
 1235:               {href=>"javascript:changePage(document.$phase,'courselist')",
 1236:               text=>$choose_text});
 1237:             if ($phase eq 'courselist') {
 1238:                 &print_course_selection_page($r,$dom,$domdesc);
 1239:             } else {
 1240:                 my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
 1241:                 if ($checked eq 'ok') {
 1242:                     my $enter_text;
 1243:                     if ($type eq 'Community') {
 1244:                         $enter_text = 'Enter community';
 1245:                     } else {
 1246:                         $enter_text = 'Enter course';
 1247:                     }
 1248:                     if ($phase eq 'menu') {
 1249:                         &Apache::lonhtmlcommon::add_breadcrumb
 1250:                         ({href=>"javascript:changePage(document.$phase,'menu')",
 1251:                           text=>"Pick action"});
 1252:                         &print_modification_menu($r,$cdesc,$domdesc,$dom,$type);
 1253:                     } elsif ($phase eq 'ccrole') {
 1254:                         &Apache::lonhtmlcommon::add_breadcrumb
 1255:                          ({href=>"javascript:changePage(document.$phase,'ccrole')",
 1256:                            text=>$enter_text});
 1257:                         &print_ccrole_selected($r,$type);
 1258:                     } else {
 1259:                         &Apache::lonhtmlcommon::add_breadcrumb
 1260:                         ({href=>"javascript:changePage(document.$phase,'menu')",
 1261:                           text=>"Pick action"});
 1262:                         my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
 1263:                         if ($phase eq 'setquota') {
 1264:                             &Apache::lonhtmlcommon::add_breadcrumb
 1265:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1266:                               text=>"Set quota"});
 1267:                             &print_setquota($r,$cdom,$cnum,$cdesc,$type);
 1268:                         } elsif ($phase eq 'processquota') { 
 1269:                             &Apache::lonhtmlcommon::add_breadcrumb
 1270:                             ({href=>"javascript:changePage(document.$phase,'setquota')",
 1271:                               text=>"Set quota"});
 1272:                             &Apache::lonhtmlcommon::add_breadcrumb
 1273:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1274:                               text=>"Result"});
 1275:                             &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 1276:                         } elsif ($phase eq 'viewparms') {  
 1277:                             &Apache::lonhtmlcommon::add_breadcrumb
 1278:                             ({href=>"javascript:changePage(document.$phase,'viewparms')",
 1279:                               text=>"Display settings"});
 1280:                             &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
 1281:                         } elsif ($phase eq 'setparms') {
 1282:                             &Apache::lonhtmlcommon::add_breadcrumb
 1283:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1284:                               text=>"Change settings"});
 1285:                             &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type);
 1286:                         } elsif ($phase eq 'processparms') {
 1287:                             &Apache::lonhtmlcommon::add_breadcrumb
 1288:                             ({href=>"javascript:changePage(document.$phase,'setparms')",
 1289:                               text=>"Change settings"});
 1290:                             &Apache::lonhtmlcommon::add_breadcrumb
 1291:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1292:                               text=>"Result"});
 1293:                             &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 1294:                         } elsif ($phase eq 'catsettings') {
 1295:                             &Apache::lonhtmlcommon::add_breadcrumb
 1296:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1297:                               text=>"Catalog settings"});
 1298:                             &print_catsettings($r,$cdom,$cnum,$cdesc,$type);
 1299:                         } elsif ($phase eq 'processcat') {
 1300:                             &Apache::lonhtmlcommon::add_breadcrumb
 1301:                             ({href=>"javascript:changePage(document.$phase,'catsettings')",
 1302:                               text=>"Catalog settings"});
 1303:                             &Apache::lonhtmlcommon::add_breadcrumb
 1304:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
 1305:                               text=>"Result"});
 1306:                             &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
 1307:                         }
 1308:                     }
 1309:                 } else {
 1310:                     $r->print('<span class="LC_error">');
 1311:                     if ($type eq 'Community') {
 1312:                         $r->print(&mt('The course you selected is not a valid course in this domain'));
 1313:                     } else {
 1314:                         $r->print(&mt('The community you selected is not a valid community in this domain'));
 1315:                     }
 1316:                     $r->print(" ($domdesc)</span>");
 1317:                 }
 1318:             }
 1319:         }
 1320:         &print_footer($r);
 1321:     } else {
 1322:         $env{'user.error.msg'}=
 1323:         "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
 1324:         return HTTP_NOT_ACCEPTABLE;
 1325:     }
 1326:     return OK;
 1327: }
 1328: 
 1329: 1;
 1330: __END__

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