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

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

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