File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.45: download - view: text, annotated - select for diffs
Tue Jun 9 13:26:35 2009 UTC (15 years ago) by bisitz
Branches: MAIN
CVS tags: bz5969, HEAD, BZ5971-printing-apage
- Corrected nested HTML tags structure (<form> / <p>)
- Corrected unbalanced tags (added </p> to menu; removed </p> from kerberos warning)
- Replaced hardcoded font color by appropriate warning style (kerberos warning)
- Removed unused color variables
- Optimized &mt usage
- Added some line breaks for better code readability

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

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