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

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

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