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

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

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