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

1.3       raeburn     1: # Copyright Michigan State University Board of Trustees
                      2: #
                      3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      4: #
                      5: # LON-CAPA is free software; you can redistribute it and/or modify
                      6: # it under the terms of the GNU General Public License as published by
                      7: # the Free Software Foundation; either version 2 of the License, or
                      8: # (at your option) any later version.
                      9: #
                     10: # LON-CAPA is distributed in the hope that it will be useful,
                     11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     13: # GNU General Public License for more details.
                     14: #
                     15: # You should have received a copy of the GNU General Public License
                     16: # along with LON-CAPA; if not, write to the Free Software
                     17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     18: #
                     19: # /home/httpd/html/adm/gpl.txt
                     20: #
                     21: # http://www.lon-capa.org/
                     22: #
1.1       raeburn    23: package Apache::lonmodifycourse;
                     24: 
                     25: use strict;
                     26: use Apache::Constants qw(:common :http);
                     27: use Apache::lonnet;
                     28: use Apache::loncommon;
                     29: use Apache::lonlocal;
                     30: use Apache::londropadd;
                     31: use LONCAPA::Enrollment;
                     32: use lib '/home/httpd/lib/perl';
                     33: use localenroll;
                     34: 
                     35: sub print_course_selection_page {
                     36:     my ($r,$tasklongref) = @_;
                     37:     my $dom = $ENV{'user.domain'};
                     38:     my %lt=&Apache::lonlocal::texthash(
1.2       raeburn    39:                     'csae' => "Course settings for automated enrollment",
                     40:                     'unst' => "Unlike standard LON-CAPA course parameters, such as course description, feedback addresses, and top level map, which are displayed and/or modified using the 'Course Environment Parameters' screen, settings that control automated enrollment based on classlist data available from your institution's student information system are handled differently.  Automated enrollment settings fall into two groups: (a) settings that can be modified by a Course Coordinator using the Automated Enrollment Manager and (b)  settings that may only be modified by a Domain Coordinator via the 'View/Modify Course settings' menu accessed from this page.", 
                     41:                     'chcs' => "Choose the course for which you wish to view/modify automated enrollment settings from the select box below and click 'Go' to proceed.",
                     42:                     'eaen' =>  "Each entry in the select box contains: <b>course code</b> -- <b>course title</b> ------- <b>course owner</b>, and entries are ordered alphabetically by course code.",
                     43:                     'psac' => "Please select a course",
1.1       raeburn    44:                     'ccrs' => "Choose a course",
                     45:                     'gobt' => "Go"
                     46:     );
                     47:                                                                                       
                     48: # Determine the courses
                     49:     my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
                     50:     &print_header($r,$tasklongref);
                     51:     $r->print(<<ENDBLOCK);
1.2       raeburn    52: <form action="/adm/modifycourse" method="post" name="cmod">
1.3       raeburn    53: <h3>$lt{'csae'}</h3>
1.2       raeburn    54: <p>$lt{'unst'}
1.1       raeburn    55: </p><p>$lt{'chcs'}
1.2       raeburn    56: <br/>$lt{'eaen'}
                     57: </p><p>
1.1       raeburn    58: <b>$lt{'ccrs'}:</b>
                     59: <select name="course">
1.2       raeburn    60:  <option value="0" />$lt{'psac'}
1.1       raeburn    61:  <option value="-1" />---------------------------------------------------
                     62: ENDBLOCK
                     63:     my $iter = 0;
                     64:     my @codes = ();
                     65:     my %courses = (); 
                     66:     foreach my $key (sort keys %courseIDs) {
                     67: # Get current code
                     68:         my $crs;
                     69:         my $currcode;
                     70:         if ($key =~ m/^($dom)_(\w+)$/) {
                     71:             $crs = $2;
                     72:             my %settings = &Apache::lonnet::get('environment',['internal.coursecode'],$dom,$crs);
                     73:             if (defined($settings{'internal.coursecode'}) ) {
                     74:                 $currcode = $settings{'internal.coursecode'};
                     75:                 if ($currcode eq '') {
                     76:                     $currcode = "___".$iter;
                     77:                     $iter ++;
                     78:                 }
                     79: 	    } else {
                     80:                 $currcode = "___".$iter;
                     81:                 $iter ++;
                     82:             }
                     83:         } else {
                     84:             $currcode = "___".$iter;
                     85:             $iter ++;
                     86:         }
                     87:         unless (grep/^$currcode$/,@codes) {
                     88:             push @codes,$currcode;
                     89:             @{$courses{$currcode}} = ();
                     90:         }
                     91:         push @{$courses{$currcode}}, $key;
                     92:     }
                     93:     foreach my $code (sort @codes) { 
                     94:         foreach my $item (@{$courses{$code}}) { 
                     95:             my $crs;
                     96:             my $owner;
                     97:             my $ownername;
                     98:             my $description;
                     99:             my $showcode = '';
                    100:             unless ($code =~m/^___\d+$/) {  $showcode = $code; }
                    101:             if ($item =~ m/^($dom)_(\w+)$/) {
                    102:                 $crs = $2;
                    103:                 $description = $courseIDs{$item};
                    104: # Get course owner
                    105:                 my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
                    106:                 if ( defined($settings{'internal.courseowner'}) ) {
                    107:                     $owner = $settings{'internal.courseowner'};
                    108:                     $ownername = &Apache::loncommon::plainname($owner,$dom);
                    109:                 }
                    110:                 $r->print("<option value=\"$crs\">$showcode -- $description ---------- $ownername");
                    111:             }
                    112:         }
                    113:     }
                    114:     $r->print("</select>
                    115: &nbsp;
                    116: <input type=\"hidden\" name=\"action\" value=\"display\" />
                    117: <input type=\"button\" onClick=\"this.form.submit()\" value=\"$lt{'gobt'}\" />
                    118: </p>
                    119: </form>");
                    120:     &print_footer($r);
                    121:     return;
                    122: }
                    123: 
                    124: sub print_course_modification_page {
                    125:     my ($r,$tasklongref,$typeref) = @_;
                    126:     my %enrollvar = ();
1.3       raeburn   127:     my $javascript_validations;
                    128:     my $course = '';
                    129:     my $dom = $ENV{'user.domain'};
                    130:     if ( defined($ENV{'form.course'}) ) {
                    131:         $course = $ENV{'form.course'};
                    132:     }
                    133:     my $ok_course = 'ok';
                    134:     if ( ($course == -1) || ($course == '-2') || ($course eq '') ) {
                    135:         $ok_course = 'invalid';
                    136:     } else {
                    137:         $ok_course = &check_course($dom,$course);
                    138:     }
                    139: 
                    140:     unless ($ok_course eq 'ok') {
                    141:         &print_header($r,$tasklongref,'',\$javascript_validations);
                    142:         my $reply = "<br/>".&mt("The LON-CAPA course selected was not a valid course for this domain");
                    143:         $r->print($reply);
                    144:         &print_footer($r);
                    145:         return;
                    146:     }
                    147: 
1.1       raeburn   148:     my @bgcolors=("#eeeeee","#cccccc");
                    149:     my $ownertable;
1.2       raeburn   150:     my %lt=&Apache::lonlocal::texthash(
                    151:             'actv' => "Active",
                    152:             'inac' => "Inactive",
                    153:             'ccor' => "Course Coordinator",
                    154:             'noen' => "No end date",
                    155:             'ownr' => "Owner",
                    156:             'name' => "Name",
                    157:             'unme' => "Username",
                    158:             'stus' => "Status",
                    159:             'aecs' => "Automated Enrollment Course Settings",
                    160:             '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 ",
                    161:             'aenm' => "Automated Enrollment Manager",
                    162:             'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.",
                    163:             'caes' => 'Current automated enrollment settings',
                    164:             'cour' => "Course settings that control automated enrollment in this LON-CAPA course
                    165: are currently:",
                    166:             'cset' => "Course setting",
                    167:             'valu' => "Current value",
                    168:             '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.",    
                    169:             'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change
                    170: 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).",
                    171:             'mkch' => "Make changes to course settings set by Domain Coordinator",
                    172:             'ccod' => "Course Code",
                    173:             '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.",
                    174:             'cown' => "Course Owner",
                    175:             '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.",
                    176:             'tabl' => 'The table below contains a list of active course coordinators in this course, who are from this domain',
                    177:             'usrd' => 'Use the radio buttons to select a different course owner.',
                    178:             'deam' => "Default Authentication method",
                    179:             '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.",
                    180:             'gobt' => "Modify settings",
                    181:     );
                    182: 
1.1       raeburn   183:     my %settings = &Apache::lonnet::dump('environment',$dom,$course);
1.2       raeburn   184:     $enrollvar{'autharg'} = '';
                    185:     $enrollvar{'authtype'} = '';
1.1       raeburn   186:     foreach my $item (keys %settings) {
                    187:         if ($item =~ m/^internal\.(.+)$/) {
                    188:             if ( ($1 eq "autoadds") || ($1 eq "autodrops") ) {
                    189: 	        if ($settings{$item} == 1) {
                    190: 	            $enrollvar{$1} = "ON";
                    191: 	        } else {
                    192: 	            $enrollvar{$1} = "OFF";
                    193: 	        }
                    194:             } elsif ( ($1 eq "autostart") || ($1 eq "autoend") ) {
                    195: 	        if ( ($1 eq "autoend") && ($settings{$item} == 0) ) {
1.2       raeburn   196: 	            $enrollvar{$1} = $lt{'noen'};
1.1       raeburn   197: 	        } else {
                    198: 	            $enrollvar{$1} = localtime($settings{$item});
                    199: 	        }
1.7     ! raeburn   200:             } elsif ($1 eq "courseowner" || $1 eq "authtype" || $1 eq "autharg" || $1 eq "sectionnums" || $1 eq "coursecode") {
1.1       raeburn   201: 	        $enrollvar{$1} = $settings{$item};
                    202:             }
                    203:         }
                    204:     }
                    205: 
                    206:     my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$course);
                    207:     my @local_ccs = ();
                    208:     my %cc_status = ();
                    209:     my %pname = ();
                    210:     my $active_cc;
                    211:     foreach (@coursepersonnel) {
                    212:         my @roleinfo = split/:/,$_;
                    213:         if ( ($roleinfo[0] eq 'cc')  && ($roleinfo[2] eq $dom) )  {
                    214:             unless (grep/^$roleinfo[1]$/,@local_ccs) {
                    215:                 $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$course,'cc');
                    216:                 if ($active_cc eq 'ok') {
                    217:                     push @local_ccs, $roleinfo[1];
                    218:                     $pname{$roleinfo[1]} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
1.2       raeburn   219:                     $cc_status{$roleinfo[1]} = $lt{'actv'};
1.1       raeburn   220:                 }
                    221:             }
                    222:         }
                    223:     }
                    224:     unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') )  {
1.6       raeburn   225:         push @local_ccs, $enrollvar{'courseowner'};
1.2       raeburn   226:         $pname{$enrollvar{'courseowner'}} =  &Apache::loncommon::plainname($enrollvar{'courseowner'},$dom);
                    227:         $active_cc = &LONCAPA::Enrollment::check_user_status($dom,$enrollvar{'coursecode'},$dom,$course,'cc');
1.1       raeburn   228:         if ($active_cc eq 'ok') {
1.2       raeburn   229:             $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1       raeburn   230:         } else {
1.2       raeburn   231:             $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1       raeburn   232:         }
                    233:     }
                    234:     my $numlocalcc = @local_ccs;
1.2       raeburn   235:     my $bodytag=&Apache::loncommon::bodytag(&mt("Modify Course Settings"));
                    236:     my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
1.1       raeburn   237:     my $defdom=$ENV{'request.role.domain'};
                    238:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($defdom);
1.2       raeburn   239:     my $curr_authtype = '';
                    240:     my $curr_authfield = '';
                    241:     if ($enrollvar{'authtype'} =~ /^krb/) {
                    242:         $curr_authtype = 'krb';
                    243:     } elsif ($enrollvar{'authtype'} eq 'internal' ) {
                    244:         $curr_authtype = 'int';
                    245:     } elsif ($enrollvar{'authtype'} eq 'localauth' ) {
                    246:         $curr_authtype = 'loc';
                    247:     }
                    248:     unless ($curr_authtype eq '') {
                    249:         $curr_authfield = $curr_authtype.'arg';
                    250:     } 
1.3       raeburn   251:     $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
1.2       raeburn   252:     my %param = ( formname => 'document.cmod',
1.1       raeburn   253: 	   kerb_def_dom => $krbdefdom,
1.2       raeburn   254: 	   kerb_def_auth => $krbdef,
                    255:            mode => 'modifycourse',
                    256:            curr_authtype => $curr_authtype,
                    257:            curr_autharg => $enrollvar{'autharg'} 
1.1       raeburn   258: 	);
                    259:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
                    260:     my $intform = &Apache::loncommon::authform_internal(%param);
                    261:     my $locform = &Apache::loncommon::authform_local(%param);
                    262: 
                    263:     my $disp_table = qq|<table border="0" cellpadding="0" cellspacing="0">
                    264:                 <tr>
                    265:                  <td width="100%" bgcolor="#000000">
                    266:                   <table width="100%" border="0" cellpadding="1" cellspacing="0">
                    267:                    <tr>
                    268:                     <td width="100%" bgcolor="#000000">
                    269:                      <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
                    270:                       <tr bgcolor="#CCCC99" align="center">
                    271: 	               <td><b>$lt{'cset'}</b></td>
                    272: 	               <td><b>$lt{'valu'}</b></td>
                    273: 	              </tr>
                    274:     |;
                    275:     my $iter = 0;
                    276:     foreach my $key (sort keys %enrollvar) {
                    277:         my $colflag = $iter%2;
                    278:         $disp_table .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    279: 		 <td>$$typeref{$key}</td>
                    280: 		 <td>$enrollvar{$key}</td>
                    281: 		</tr>";
1.6       raeburn   282:         $iter ++;
1.1       raeburn   283:     }
                    284:     $disp_table .= "</table>
                    285:                    </td>
                    286:                   </tr>
                    287:                  </table>
                    288:                 </td>
                    289:                </tr>
                    290:               </table>";
                    291: 
                    292:     if ($numlocalcc == 0) {
1.2       raeburn   293:         $ownertable = $lt{'nocc'};
1.1       raeburn   294:     }
1.2       raeburn   295: 
1.1       raeburn   296:     if ($numlocalcc > 0) {
                    297:         @local_ccs = sort @local_ccs;
                    298:         $ownertable = qq(
                    299:             <input type="hidden" name="numlocalcc" value="$numlocalcc" />
                    300:             <table>
                    301:              <tr>
                    302:                <td>$lt{'tabl'} ($dom). $lt{'usrd'}
                    303:               </td>
                    304:              </tr>
                    305:              <tr><td>&nbsp;</td></tr>
                    306:              <tr>
                    307:               <td>
                    308:                <table border="0" cellpadding="0" cellspacing="0">
                    309:                 <tr>
                    310:                  <td width="100%" bgcolor="#000000">
                    311:                   <table width="100%" border="0" cellpadding="1" cellspacing="0">
                    312:                    <tr>
                    313:                     <td width="100%" bgcolor="#000000">
                    314:                      <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
                    315:                       <tr bgcolor="#CCCC99" align="center">
1.2       raeburn   316:                        <td><b>$lt{'ownr'}</b></td>
                    317:                        <td><b>$lt{'name'}</b></td>
                    318:                        <td><b>$lt{'unme'}</b></td>
                    319:                        <td><b>$lt{'stus'}</b></td>
1.1       raeburn   320:                       </tr>
                    321:         );
                    322:         for (my $i=0; $i<@local_ccs; $i++) {
                    323:             my $colflag = $i%2;
                    324:             $ownertable .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">";
                    325:             if ($local_ccs[$i] eq $enrollvar{'courseowner'}) {
                    326:                   $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" checked=\"true\"/></td>";
                    327:             } else {
                    328:                 $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" /></td>";
                    329:             }
                    330:             $ownertable .= "
                    331:                  <td>$pname{$local_ccs[$i]}</td>
                    332:                  <td><input type=\"hidden\" name=\"username_$i\" value=\"$local_ccs[$i]\" />$local_ccs[$i]</td>
1.2       raeburn   333:                  <td>$cc_status{$local_ccs[$i]} $lt{'ccor'}</td></tr>";
1.1       raeburn   334:         }
                    335:         $ownertable .= "</table>
                    336:                     </td>
                    337:                    </tr>
                    338:                   </table>
                    339:                  </td>
                    340:                 </tr>
                    341:                </table>
                    342:               </td>
                    343:              </tr>
                    344:             </table>";
                    345:     }
                    346:     &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations);
                    347:     $r->print(<<ENDDOCUMENT);
                    348: <form action="/adm/modifycourse" method="post" name="cmod">
1.3       raeburn   349: <h3>$lt{'aecs'}</h3>
1.1       raeburn   350: $lt{'cose'}<a href="/adm/populate">$lt{'aenm'}</a>$lt{'andb'}
                    351: <p>
                    352: <table width="100%" cellspacing="0" cellpadding="0">
                    353:  <tr>
                    354:   <td bgcolor="#CCCC99">&nbsp;</td>
                    355:   <td align="left" bgcolor="#CCCC99"><h3>$lt{'caes'}</h3></td>
                    356:  </tr>
                    357: </table>
                    358: <p>
                    359: $lt{'cour'}
                    360: </p><p>
                    361: $disp_table
                    362: <br/<br/>
                    363: </p><p>
                    364: 
                    365: <table width="100%" cellspacing="0" cellpadding="0">
                    366:  <tr>
                    367:   <td bgcolor="#CCCC99">&nbsp;</td>
                    368:   <td align="left" bgcolor="#CCCC99">
                    369:    <h3>$lt{'mkch'}</h3>
                    370:   </td>
                    371:  </tr>
                    372: </table>
                    373: </p><p>
1.2       raeburn   374: <table width="100%" cellspacing="6" cellpadding="6">
                    375:  <tr>
                    376:   <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. Click the <b>"$lt{'gobt'}"</b> button to save your changes.</td>
                    377:  </tr>
1.1       raeburn   378:  <tr>
                    379:   <td width="50%" valign="top">
1.2       raeburn   380:    <b>$lt{'ccod'}:</b>&nbsp;&nbsp;
1.1       raeburn   381:     <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
                    382:     $lt{'ccus'}
                    383:   </td>
                    384:   <td width="50%" valign="top" rowspan="2">
1.2       raeburn   385:    <b>$lt{'cown'}:</b><br/><br/>
                    386:    $ownertable
                    387:    <br/><br/>
1.1       raeburn   388:    $lt{'cous'}
                    389:   </td>
                    390:  </tr>
                    391:  <tr>
                    392:   <td width="50%" valign="top">
1.2       raeburn   393:    <b>$lt{'deam'}:</b><br/><br/>
                    394:    $krbform
                    395:    <br/>
                    396:    $intform
                    397:    <br/>
                    398:    $locform
                    399:    <br/>
                    400:    <br/>
1.1       raeburn   401:    $lt{'deus'}.
                    402:    </td>
                    403:    <td width="50%">&nbsp;</td>
                    404:  </tr>
                    405: </table>
                    406: <br/><br/>
                    407: <table width="90%" cellpadding="5" cellspacing="0">
                    408:  <tr>
                    409:   <td align="right">
                    410:    <input type="hidden" name="course" value="$course" />
                    411:    <input type="hidden" name="action" value="process" />
                    412:    <input type="button" onClick="verify_message(this.form)" value="$lt{'gobt'}" />
                    413:   </td>
                    414:  </tr>
                    415: </table>
                    416: </form>
                    417: <br/>
                    418: <br/>
                    419: ENDDOCUMENT
                    420:     &print_footer($r);
1.5       raeburn   421:     return;
1.1       raeburn   422: }
                    423: 
                    424: sub modify_course {
                    425:     my ($r,$tasklongref,$typeref) = @_;
                    426:     my $dom = $ENV{'user.domain'};
                    427:     my $crs = $ENV{'form.course'};
1.7     ! raeburn   428:     my $homeserver = &Apache::lonnet::homeserver($crs,$dom);
        !           429:     my $server = $Apache::lonnet::perlvar{'lonHostID'};
1.3       raeburn   430: 
                    431:     unless ( &check_course($dom,$crs) eq 'ok' ) {
                    432:         &print_header($r,$tasklongref);
                    433:         my $reply = "<br/>".&mt("The LON-CAPA course selected was not a valid course for this domain");
                    434:         $r->print($reply);
                    435:         &print_footer($r);
                    436:         return;
                    437:     }
                    438: 
1.2       raeburn   439:     my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$dom,$crs);
1.1       raeburn   440:     my %currattr = ();
                    441:     my %newattr = ();
                    442:     my %cenv = ();
                    443:     my $response;
                    444:     my $chgresponse;
                    445:     my $nochgresponse;
                    446:     my $warning;
                    447:     my $reply;
                    448:     my @changes = ();
                    449:     my @nochanges = ();
                    450:     my @sections = ();
                    451:     my @xlists = ();
                    452:     my $changecode = 0;
                    453:     my $changeowner = 0;
                    454:     unless ($settings{'internal.sectionnums'} eq'') {
                    455:         if ($settings{'internal.sectionnums'} =~ m/,/) {
                    456:             @sections = split/,/,$settings{'internal.sectionnums'};
                    457:         } else {
                    458:             $sections[0] = $settings{'internal.sectionnums'};
                    459:         }
                    460:     }
                    461:     unless ($settings{'internal.crosslistings'} eq'') {
                    462:         if ($settings{'internal.crosslistings'} =~ m/,/) {
                    463:             @xlists = split/,/,$settings{'internal.crosslistings'};
                    464:         } else {
                    465:             $xlists[0] = $settings{'internal.crosslistings'};
                    466:         }
                    467:     }
                    468: 
                    469:     my @params = ('courseowner','coursecode','authtype','autharg');
                    470:     foreach (@params) {
                    471:         my $attr = 'internal.'.$_;
                    472:         $currattr{$_} = $settings{$attr};
                    473:     }
                    474: 
                    475:     my $description = $settings{'description'};
                    476:     my %cenv = ();
                    477: 
                    478:     if ($ENV{'form.login'} eq 'krb') {
                    479:         $newattr{'authtype'} = $ENV{'form.login'};
                    480:         $newattr{'authtype'} .= $ENV{'form.krbver'};
                    481:         $newattr{'autharg'} = $ENV{'form.krbarg'};
1.2       raeburn   482:         $newattr{'autharg'} =~ tr/a-z/A-Z/; 
1.1       raeburn   483:     } elsif ($ENV{'form.login'} eq 'int') {
                    484:         $newattr{'authtype'} ='internal';
                    485:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                    486:             $newattr{'autharg'} = $ENV{'form.intarg'};
                    487:         }
                    488:     } elsif ($ENV{'form.login'} eq 'loc') {
                    489:         $newattr{'authtype'} = 'localauth';
                    490:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                    491:             $newattr{'autharg'} = $ENV{'form.locarg'};
                    492:         }
                    493:     }
                    494:     if ( $newattr{'authtype'}=~ /^krb/) {
                    495:         if ($newattr{'autharg'}  eq '') {
1.2       raeburn   496:             $warning = qq(<font color="red" size="+1">).
                    497: 	    &mt("As you did not include the default Kerberos domain to be used for authentication in this class, the institutional data used by the automated enrollment process must include the Kerberos domain for each new student").qq(</font></p>);
1.1       raeburn   498:         }
                    499:     }
                    500: 
                    501:     if ( exists($ENV{'form.courseowner'}) ) {
                    502:          my $ownerparam = 'username_'.$ENV{'form.courseowner'};
                    503:          if ( exists($ENV{"form.$ownerparam"}) ) {  
                    504:             $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
                    505:             unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
                    506:                 $changeowner = 1;
                    507:             }
                    508:         } 
                    509:     }
                    510: 													      
                    511:     if ( exists($ENV{'form.coursecode'}) ) {
                    512:         $newattr{'coursecode'}=$ENV{'form.coursecode'};
                    513:         unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
                    514:             $changecode = 1;
                    515:         }
                    516:     }
                    517: 
                    518:     foreach (@params) {
                    519:         if ($currattr{$_} eq $newattr{$_}) {
                    520:             push @nochanges, $_;
                    521:         } else {
                    522:             my $attr = 'internal.'.$_;
                    523:             $cenv{$attr} = $newattr{$_};
                    524:             push @changes, $_;
                    525:         }
                    526:     }
                    527: 
                    528:     if (@changes > 0) {
1.2       raeburn   529:         $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
1.1       raeburn   530:     }
                    531:     if (@nochanges > 0) { 
1.2       raeburn   532:         $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
1.1       raeburn   533:     }
                    534:     if (@changes > 0) { 
                    535:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                    536:         if ($putreply !~ /^ok$/) {
1.2       raeburn   537:             $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>");
1.1       raeburn   538:         } else {
                    539:             foreach my $attr (@params) {
                    540:                 if (grep/^$attr$/,@changes) {
1.2       raeburn   541: 	            $chgresponse .= "<li>$$typeref{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
1.1       raeburn   542:                 } else {
1.2       raeburn   543: 	            $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
1.1       raeburn   544:                 }
                    545:             }
                    546:             if ($changecode || $changeowner) {
                    547:                 if ( $newattr{'courseowner'} eq '') {
1.2       raeburn   548: 	            $warning .= &mt("There is no owner associated with this LON-CAPA course.  If automated enrollment in LON-CAPA courses at your institution requires validation of course owners, automated enrollment will fail for this course.<br/>");
1.1       raeburn   549:                 } else {
                    550: 	            if (@sections > 0) {
1.2       raeburn   551:                         if ($changecode) {
                    552: 	                    foreach my $sec (@sections) {
                    553: 		                if ($sec =~ m/^(.+):/) {
                    554: 		                    my $course_id = $newattr{'coursecode'}.$1;
1.7     ! raeburn   555:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($homeserver,$course_id);
        !           556: 			            if ($course_check eq 'ok') {
        !           557:                                         my $outcome = &Apache::lonnet::auto_new_course($homeserver,$course_id,$newattr{'courseowner'});
1.1       raeburn   558: 			                unless ($outcome eq 'ok') { 
1.2       raeburn   559: 				            $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $outcome.<br/>");
1.1       raeburn   560: 			                }
                    561: 			            } else {
1.2       raeburn   562: 			                $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $course_check.<br/>");
1.1       raeburn   563: 			            }
                    564: 		                } else {
1.2       raeburn   565: 			            $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $sec because this is not a valid section entry.<br/>");
1.1       raeburn   566: 		                }
                    567: 		            }
1.4       raeburn   568: 	                } elsif ($changeowner) {
                    569:                             foreach my $sec (@sections) {
                    570:                                 if ($sec =~ m/^(.+):/) {
                    571:                                     my $course_id = $newattr{'coursecode'}.$1;
1.7     ! raeburn   572:                                     my $outcome = &Apache::lonnet::auto_new_course($homeserver,$course_id,$newattr{'courseowner'});
1.4       raeburn   573:                                     unless ($outcome eq 'ok') {
                    574:                                         $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/>");
                    575:                                     }
                    576:                                 } else {
                    577:                                     $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/>");
                    578:                                 }
                    579:                             }
                    580:                         }
1.1       raeburn   581: 	            } else {
1.2       raeburn   582: 	                $warning .= &mt("As no section numbers are currently listed for LON-CAPA course: ").$description.&mt(", automated enrollment will not occur for any sections of coursecode: ").$newattr{'coursecode'}."<br/>";
1.1       raeburn   583: 	            }
                    584: 	            if ( (@xlists > 0) && ($changeowner) ) {
                    585: 	                foreach my $xlist (@xlists) {
                    586: 		            if ($xlist =~ m/^(.+):/) {
1.7     ! raeburn   587:                                 my $outcome = &Apache::lonnet::auto_new_course($homeserver,$1,$newattr{'courseowner'});
1.1       raeburn   588: 		                unless ($outcome eq 'ok') {
1.2       raeburn   589: 			            $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for crosslisted class: ").$1.&mt(" for the following reason: $outcome.<br/>");
1.1       raeburn   590: 		                }
                    591: 		            } 
                    592: 	                }
                    593: 	            }
                    594:                 }
                    595:             }
                    596:         }
1.2       raeburn   597:     } else {
                    598:         foreach my $attr (@params) {
                    599:             $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
                    600:         }
1.1       raeburn   601:     }
                    602: 
1.2       raeburn   603: 
1.1       raeburn   604:     if (@changes > 0) {
                    605:         $chgresponse .= "</ul><br/><br/>";
                    606:     }
                    607:     if (@nochanges > 0) {
                    608:         $nochgresponse .=  "</ul><br/><br/>";
                    609:     }
                    610:     unless ($warning eq '') {
1.2       raeburn   611:         $warning = &mt("The following warning messages were generated as a result of applying the changes you specified to course settings that can affect the automated enrollment process:<br/><br/>").$warning;
1.1       raeburn   612:     }
                    613:     if ($response eq '') {
                    614:         $reply = $chgresponse.$nochgresponse.$warning;
                    615:     } else {
                    616:         $reply = $response;
                    617:     }
                    618:     &print_header($r,$tasklongref,$description);
1.3       raeburn   619:     $reply = "<h3>".&mt("Automated Enrollment Course Settings")."</h3><table><tr><td>".$reply."</td></tr></table>";
                    620:     $r->print($reply);
1.1       raeburn   621:     &print_footer($r);
                    622:     return; 
                    623: }
                    624: 
                    625: sub print_header {
                    626:     my ($r,$tasklongref,$description,$javascriptref) = @_;
1.2       raeburn   627:     my %lt =&Apache::lonlocal::texthash(
1.1       raeburn   628:              'vmcs' => 'View/Modify Course Settings',
                    629:              'chco' => 'Choose a course',
                    630:              'main' => 'Main Menu',
                    631:              'comg' => 'Course Manager',
                    632:              );
                    633:     my $action = "start";
                    634:     if ( exists($ENV{'form.action'}) ) {
                    635:         $action = $ENV{'form.action'};
                    636:     }
                    637:     if ( ($description eq '') || (!defined($description)) ) {
                    638:         $description = $lt{'comg'};
                    639:     }
                    640:     my $page = '';
                    641:     my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
                    642:     if ($action eq 'start') {  
                    643:         $page = "<b>$lt{'chco'}</b>";
                    644:     } else {
                    645:         $page =  '<a href="/adm/modifycourse">'.$lt{'chco'}.'</a>';
                    646:         if ( $action eq 'process' ) {
                    647:             my $course = $ENV{'form.course'};
                    648:             $page .= "-&gt; <a href=\"/adm/modifycourse?action=display&course=$course\">".$$tasklongref{'display'}."</a> -&gt; <b>$$tasklongref{$action}</b> ";
                    649:         } else {
                    650:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>";
                    651:         }
                    652:     }
                    653:     $r->print("
                    654: <html>
                    655: <head>");
                    656:     if ($action eq 'display') {
                    657:         $r->print("
                    658: <script language=\"JavaScript\" type=\"text/javascript\">
                    659: $$javascriptref
                    660: </script>");
                    661:     }
                    662:     $r->print(<<ENDTHIS);
                    663: <title>The LearningOnline Network with CAPA</title>
                    664: </head>
                    665: $bodytag
                    666: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    667:  <tr>
                    668:   <td bgcolor="#CCCC99">
                    669:    <font size="2"><a href="/adm/menu">$lt{'main'}</a> -&gt; $page</font><br/>
                    670:   </td>
                    671:   <td align="right" bgcolor="#CCCC99" valign="top">
                    672:    <font size="+1">$description &nbsp;</font>
                    673:   </td>
                    674:  </tr>
                    675: </table>
                    676: ENDTHIS
1.5       raeburn   677:     return;
1.1       raeburn   678: }
                    679: 
                    680: sub print_footer {
1.5       raeburn   681:     my $r = shift;
                    682:     $r->print(<<ENDBASE);
1.1       raeburn   683: <br/>
                    684: </body>
                    685: </html>
                    686: ENDBASE
1.5       raeburn   687:     return;
1.3       raeburn   688: }
                    689: 
                    690: sub check_course {
                    691:     my ($dom,$course) = @_;
                    692:     my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
                    693:     foreach my $key (sort keys %courseIDs) {
                    694:         if ($key =~ m/^($dom)_(\w+)$/) {
1.5       raeburn   695:             if ($2 eq $course) {
                    696:                 return 'ok';
                    697:             }
1.3       raeburn   698:         }
                    699:     }
1.5       raeburn   700:     return 'invalid course';
1.1       raeburn   701: }
                    702: 
                    703: 
                    704: sub handler {
                    705:     my $r = shift;
                    706:     if ($r->header_only) {
                    707:         &Apache::loncommon::content_type($r,'text/html');
                    708:         $r->send_http_header;
                    709:         return OK;
                    710:     }
                    711:                                                                                   
                    712:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
                    713:         &Apache::loncommon::content_type($r,'text/html');
                    714:         $r->send_http_header;
                    715: 
                    716:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']);
                    717:         my $dom = $ENV{'user.domain'};
1.2       raeburn   718:         my %longtype=&Apache::lonlocal::texthash(
1.1       raeburn   719:                        'authtype' => 'Default authentication method',
                    720:                        'autharg'  => 'Default authentication parameter',
                    721:                        'autoadds' => 'Automated adds',
                    722:                        'autodrops' => 'Automated drops',
                    723:                        'autostart' => 'Date of first enrollment',
                    724:                        'autoend' => 'Date of last enrollment',
                    725:                        'coursecode' => 'Official course code',
                    726:                        'courseowner' => "Username of course owner (\@$dom)",
                    727:                        'notifylist' => 'Course Coordinators to be notified of enrollment changes',
                    728:                        'sectionnums' => 'Course section number(:groupID)',
                    729:                        'crosslistings' => 'Crosslisted class(:groupID)',
                    730:                       );
                    731: 
1.2       raeburn   732:         my %tasklong = &Apache::lonlocal::texthash(
1.1       raeburn   733:                         'display' => 'View/modify settings',
                    734:                         'process'  => 'Results of changes',
                    735:                        );
                    736:                                                                                   
                    737:         if ($ENV{'form.action'} eq 'process') {
                    738:             &modify_course($r,\%tasklong,\%longtype);
                    739:         } elsif ($ENV{'form.action'} eq 'display')  {
                    740:             &print_course_modification_page($r,\%tasklong,\%longtype);
                    741:         } else {
                    742:             &print_course_selection_page($r,\%tasklong);
                    743:         }
                    744:     } else {
                    745:         $ENV{'user.error.msg'}=
1.2       raeburn   746:         "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
1.1       raeburn   747:         return HTTP_NOT_ACCEPTABLE;
                    748:     }
                    749:     return OK;
                    750: }
                    751: 
                    752: 1;
                    753: __END__

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