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

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

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