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

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'};
                    491:     } elsif ($ENV{'form.login'} eq 'int') {
                    492:         $newattr{'authtype'} ='internal';
                    493:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
                    494:             $newattr{'autharg'} = $ENV{'form.intarg'};
                    495:         }
                    496:     } elsif ($ENV{'form.login'} eq 'loc') {
                    497:         $newattr{'authtype'} = 'localauth';
                    498:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
                    499:             $newattr{'autharg'} = $ENV{'form.locarg'};
                    500:         }
                    501:     }
                    502:     if ( $newattr{'authtype'}=~ /^krb/) {
                    503:         if ($newattr{'autharg'}  eq '') {
1.2       raeburn   504:             $warning = qq(<font color="red" size="+1">).
                    505: 	    &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   506:         }
                    507:     }
                    508: 
                    509:     if ( exists($ENV{'form.courseowner'}) ) {
                    510:          my $ownerparam = 'username_'.$ENV{'form.courseowner'};
                    511:          if ( exists($ENV{"form.$ownerparam"}) ) {  
                    512:             $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
                    513:             unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
                    514:                 $changeowner = 1;
                    515:             }
                    516:         } 
                    517:     }
                    518: 													      
                    519:     if ( exists($ENV{'form.coursecode'}) ) {
                    520:         $newattr{'coursecode'}=$ENV{'form.coursecode'};
                    521:         unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
                    522:             $changecode = 1;
1.10      raeburn   523:             my $courseid_entry = &Apache::lonnet::escape($dom.'_'.$crs).'='.&Apache::lonnet::escape($description).'='.&Apache::lonnet::escape($ENV{'form.coursecode'});
                    524:             &Apache::lonnet::courseidput($dom,$courseid_entry,&Apache::lonnet::homeserver($crs,$dom));
1.1       raeburn   525:         }
                    526:     }
                    527: 
                    528:     foreach (@params) {
                    529:         if ($currattr{$_} eq $newattr{$_}) {
                    530:             push @nochanges, $_;
                    531:         } else {
                    532:             my $attr = 'internal.'.$_;
                    533:             $cenv{$attr} = $newattr{$_};
                    534:             push @changes, $_;
                    535:         }
                    536:     }
                    537: 
                    538:     if (@changes > 0) {
1.2       raeburn   539:         $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
1.1       raeburn   540:     }
                    541:     if (@nochanges > 0) { 
1.2       raeburn   542:         $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
1.1       raeburn   543:     }
                    544:     if (@changes > 0) { 
                    545:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                    546:         if ($putreply !~ /^ok$/) {
1.2       raeburn   547:             $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   548:         } else {
                    549:             foreach my $attr (@params) {
                    550:                 if (grep/^$attr$/,@changes) {
1.2       raeburn   551: 	            $chgresponse .= "<li>$$typeref{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
1.1       raeburn   552:                 } else {
1.2       raeburn   553: 	            $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
1.1       raeburn   554:                 }
                    555:             }
                    556:             if ($changecode || $changeowner) {
                    557:                 if ( $newattr{'courseowner'} eq '') {
1.2       raeburn   558: 	            $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   559:                 } else {
                    560: 	            if (@sections > 0) {
1.2       raeburn   561:                         if ($changecode) {
                    562: 	                    foreach my $sec (@sections) {
                    563: 		                if ($sec =~ m/^(.+):/) {
1.8       raeburn   564: 		                    my $inst_course_id = $newattr{'coursecode'}.$1;
                    565:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($crs,$dom,$inst_course_id);
1.7       raeburn   566: 			            if ($course_check eq 'ok') {
1.8       raeburn   567:                                         my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
1.1       raeburn   568: 			                unless ($outcome eq 'ok') { 
1.2       raeburn   569: 				            $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   570: 			                }
                    571: 			            } else {
1.2       raeburn   572: 			                $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   573: 			            }
                    574: 		                } else {
1.2       raeburn   575: 			            $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   576: 		                }
                    577: 		            }
1.4       raeburn   578: 	                } elsif ($changeowner) {
                    579:                             foreach my $sec (@sections) {
                    580:                                 if ($sec =~ m/^(.+):/) {
1.8       raeburn   581:                                     my $inst_course_id = $newattr{'coursecode'}.$1;
                    582:                                     my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
1.4       raeburn   583:                                     unless ($outcome eq 'ok') {
                    584:                                         $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/>");
                    585:                                     }
                    586:                                 } else {
                    587:                                     $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/>");
                    588:                                 }
                    589:                             }
                    590:                         }
1.1       raeburn   591: 	            } else {
1.2       raeburn   592: 	                $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   593: 	            }
                    594: 	            if ( (@xlists > 0) && ($changeowner) ) {
                    595: 	                foreach my $xlist (@xlists) {
                    596: 		            if ($xlist =~ m/^(.+):/) {
1.8       raeburn   597:                                 my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$1,$newattr{'courseowner'});
1.1       raeburn   598: 		                unless ($outcome eq 'ok') {
1.2       raeburn   599: 			            $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   600: 		                }
                    601: 		            } 
                    602: 	                }
                    603: 	            }
                    604:                 }
                    605:             }
                    606:         }
1.2       raeburn   607:     } else {
                    608:         foreach my $attr (@params) {
1.8       raeburn   609:             $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to")." \"".$currattr{$attr}."\".</li>";
1.2       raeburn   610:         }
1.1       raeburn   611:     }
                    612: 
1.2       raeburn   613: 
1.1       raeburn   614:     if (@changes > 0) {
                    615:         $chgresponse .= "</ul><br/><br/>";
                    616:     }
                    617:     if (@nochanges > 0) {
                    618:         $nochgresponse .=  "</ul><br/><br/>";
                    619:     }
                    620:     unless ($warning eq '') {
1.2       raeburn   621:         $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   622:     }
                    623:     if ($response eq '') {
                    624:         $reply = $chgresponse.$nochgresponse.$warning;
                    625:     } else {
                    626:         $reply = $response;
                    627:     }
                    628:     &print_header($r,$tasklongref,$description);
1.3       raeburn   629:     $reply = "<h3>".&mt("Automated Enrollment Course Settings")."</h3><table><tr><td>".$reply."</td></tr></table>";
                    630:     $r->print($reply);
1.1       raeburn   631:     &print_footer($r);
                    632:     return; 
                    633: }
                    634: 
                    635: sub print_header {
                    636:     my ($r,$tasklongref,$description,$javascriptref) = @_;
1.2       raeburn   637:     my %lt =&Apache::lonlocal::texthash(
1.1       raeburn   638:              'vmcs' => 'View/Modify Course Settings',
                    639:              'chco' => 'Choose a course',
                    640:              'main' => 'Main Menu',
                    641:              'comg' => 'Course Manager',
                    642:              );
                    643:     my $action = "start";
                    644:     if ( exists($ENV{'form.action'}) ) {
                    645:         $action = $ENV{'form.action'};
                    646:     }
                    647:     if ( ($description eq '') || (!defined($description)) ) {
                    648:         $description = $lt{'comg'};
                    649:     }
                    650:     my $page = '';
                    651:     my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
                    652:     if ($action eq 'start') {  
                    653:         $page = "<b>$lt{'chco'}</b>";
                    654:     } else {
                    655:         $page =  '<a href="/adm/modifycourse">'.$lt{'chco'}.'</a>';
                    656:         if ( $action eq 'process' ) {
                    657:             my $course = $ENV{'form.course'};
                    658:             $page .= "-&gt; <a href=\"/adm/modifycourse?action=display&course=$course\">".$$tasklongref{'display'}."</a> -&gt; <b>$$tasklongref{$action}</b> ";
                    659:         } else {
                    660:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>";
                    661:         }
                    662:     }
                    663:     $r->print("
                    664: <html>
                    665: <head>");
                    666:     if ($action eq 'display') {
                    667:         $r->print("
                    668: <script language=\"JavaScript\" type=\"text/javascript\">
                    669: $$javascriptref
                    670: </script>");
                    671:     }
                    672:     $r->print(<<ENDTHIS);
                    673: <title>The LearningOnline Network with CAPA</title>
                    674: </head>
                    675: $bodytag
                    676: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    677:  <tr>
                    678:   <td bgcolor="#CCCC99">
                    679:    <font size="2"><a href="/adm/menu">$lt{'main'}</a> -&gt; $page</font><br/>
                    680:   </td>
                    681:   <td align="right" bgcolor="#CCCC99" valign="top">
                    682:    <font size="+1">$description &nbsp;</font>
                    683:   </td>
                    684:  </tr>
                    685: </table>
                    686: ENDTHIS
1.5       raeburn   687:     return;
1.1       raeburn   688: }
                    689: 
                    690: sub print_footer {
1.5       raeburn   691:     my $r = shift;
                    692:     $r->print(<<ENDBASE);
1.1       raeburn   693: <br/>
                    694: </body>
                    695: </html>
                    696: ENDBASE
1.5       raeburn   697:     return;
1.3       raeburn   698: }
                    699: 
                    700: sub check_course {
                    701:     my ($dom,$course) = @_;
                    702:     my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
                    703:     foreach my $key (sort keys %courseIDs) {
                    704:         if ($key =~ m/^($dom)_(\w+)$/) {
1.5       raeburn   705:             if ($2 eq $course) {
                    706:                 return 'ok';
                    707:             }
1.3       raeburn   708:         }
                    709:     }
1.5       raeburn   710:     return 'invalid course';
1.1       raeburn   711: }
                    712: 
                    713: 
                    714: sub handler {
                    715:     my $r = shift;
                    716:     if ($r->header_only) {
                    717:         &Apache::loncommon::content_type($r,'text/html');
                    718:         $r->send_http_header;
                    719:         return OK;
                    720:     }
                    721:                                                                                   
                    722:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
                    723:         &Apache::loncommon::content_type($r,'text/html');
                    724:         $r->send_http_header;
                    725: 
                    726:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']);
                    727:         my $dom = $ENV{'user.domain'};
1.2       raeburn   728:         my %longtype=&Apache::lonlocal::texthash(
1.1       raeburn   729:                        'authtype' => 'Default authentication method',
                    730:                        'autharg'  => 'Default authentication parameter',
                    731:                        'autoadds' => 'Automated adds',
                    732:                        'autodrops' => 'Automated drops',
1.9       raeburn   733:                        'autostart' => 'Date of first automated enrollment',
                    734:                        'autoend' => 'Date of last automated enrollment',
                    735:                        'default_enrollment_start_date' => 'Date of first student access',
                    736:                        'default_enrollment_end_date' => 'Date of last student access',
1.1       raeburn   737:                        'coursecode' => 'Official course code',
                    738:                        'courseowner' => "Username of course owner (\@$dom)",
                    739:                        'notifylist' => 'Course Coordinators to be notified of enrollment changes',
                    740:                        'sectionnums' => 'Course section number(:groupID)',
                    741:                        'crosslistings' => 'Crosslisted class(:groupID)',
                    742:                       );
                    743: 
1.2       raeburn   744:         my %tasklong = &Apache::lonlocal::texthash(
1.1       raeburn   745:                         'display' => 'View/modify settings',
                    746:                         'process'  => 'Results of changes',
                    747:                        );
                    748:                                                                                   
                    749:         if ($ENV{'form.action'} eq 'process') {
                    750:             &modify_course($r,\%tasklong,\%longtype);
                    751:         } elsif ($ENV{'form.action'} eq 'display')  {
                    752:             &print_course_modification_page($r,\%tasklong,\%longtype);
                    753:         } else {
                    754:             &print_course_selection_page($r,\%tasklong);
                    755:         }
                    756:     } else {
                    757:         $ENV{'user.error.msg'}=
1.2       raeburn   758:         "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
1.1       raeburn   759:         return HTTP_NOT_ACCEPTABLE;
                    760:     }
                    761:     return OK;
                    762: }
                    763: 
                    764: 1;
                    765: __END__

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