File:  [LON-CAPA] / loncom / interface / lonmodifycourse.pm
Revision 1.47: download - view: text, annotated - select for diffs
Fri Oct 23 16:14:43 2009 UTC (14 years, 8 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Consistent wording "Course Catalog" -> "Course/Community Catalog"

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

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