Annotation of loncom/interface/lonmodifycourse.pm, revision 1.44

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

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