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

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

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