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

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

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