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

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

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