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

1.1     ! raeburn     1: package Apache::lonmodifycourse;
        !             2: 
        !             3: use strict;
        !             4: use Apache::Constants qw(:common :http);
        !             5: use Apache::lonnet;
        !             6: use Apache::loncommon;
        !             7: use Apache::lonlocal;
        !             8: use Apache::londropadd;
        !             9: use LONCAPA::Enrollment;
        !            10: use lib '/home/httpd/lib/perl';
        !            11: use localenroll;
        !            12: 
        !            13: sub print_course_selection_page {
        !            14:     my ($r,$tasklongref) = @_;
        !            15:     my $dom = $ENV{'user.domain'};
        !            16:     my %lt=&Apache::lonlocal::texthash(
        !            17:                     'incs' => "Internal course settings",
        !            18:                     'stat' => "Although the majority of course settings for LON-CAPA courses may be modified by a Course Coordinator, there are a small number of settings which may only be modified by a Domain Coordinator.  These particular course parameters control automated student enrollment in LON-CAPA courses based on classlist data available from your institution's student information system.",
        !            19:                     'chcs' => "Once you have chosen the course for which you wish to view/modify internal settings, click 'Go' to proceed",
        !            20:                     'ccrs' => "Choose a course",
        !            21:                     'gobt' => "Go"
        !            22:     );
        !            23:                                                                                       
        !            24: # Determine the courses
        !            25:     my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
        !            26:     &print_header($r,$tasklongref);
        !            27:     $r->print(<<ENDBLOCK);
        !            28: <form action="/adm/modifycourse" method="post" name="cmods">
        !            29: <h2>$lt{'incs'}</h2>
        !            30: <p>$lt{'stat'}
        !            31: </p><p>$lt{'chcs'}
        !            32: </p>
        !            33: <b>$lt{'ccrs'}:</b>
        !            34: <select name="course">
        !            35:  <option value="0" />Please select a course
        !            36:  <option value="-1" />---------------------------------------------------
        !            37: ENDBLOCK
        !            38:     my $iter = 0;
        !            39:     my @codes = ();
        !            40:     my %courses = (); 
        !            41:     foreach my $key (sort keys %courseIDs) {
        !            42: # Get current code
        !            43:         my $crs;
        !            44:         my $currcode;
        !            45:         if ($key =~ m/^($dom)_(\w+)$/) {
        !            46:             $crs = $2;
        !            47:             my %settings = &Apache::lonnet::get('environment',['internal.coursecode'],$dom,$crs);
        !            48:             if (defined($settings{'internal.coursecode'}) ) {
        !            49:                 $currcode = $settings{'internal.coursecode'};
        !            50:                 if ($currcode eq '') {
        !            51:                     $currcode = "___".$iter;
        !            52:                     $iter ++;
        !            53:                 }
        !            54: 	    } else {
        !            55:                 $currcode = "___".$iter;
        !            56:                 $iter ++;
        !            57:             }
        !            58:         } else {
        !            59:             $currcode = "___".$iter;
        !            60:             $iter ++;
        !            61:         }
        !            62:         unless (grep/^$currcode$/,@codes) {
        !            63:             push @codes,$currcode;
        !            64:             @{$courses{$currcode}} = ();
        !            65:         }
        !            66:         push @{$courses{$currcode}}, $key;
        !            67:     }
        !            68:     foreach my $code (sort @codes) { 
        !            69:         foreach my $item (@{$courses{$code}}) { 
        !            70:             my $crs;
        !            71:             my $owner;
        !            72:             my $ownername;
        !            73:             my $description;
        !            74:             my $showcode = '';
        !            75:             unless ($code =~m/^___\d+$/) {  $showcode = $code; }
        !            76:             if ($item =~ m/^($dom)_(\w+)$/) {
        !            77:                 $crs = $2;
        !            78:                 $description = $courseIDs{$item};
        !            79: # Get course owner
        !            80:                 my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
        !            81:                 if ( defined($settings{'internal.courseowner'}) ) {
        !            82:                     $owner = $settings{'internal.courseowner'};
        !            83:                     $ownername = &Apache::loncommon::plainname($owner,$dom);
        !            84:                 }
        !            85:                 $r->print("<option value=\"$crs\">$showcode -- $description ---------- $ownername");
        !            86:             }
        !            87:         }
        !            88:     }
        !            89:     $r->print("</select>
        !            90: &nbsp;
        !            91: <input type=\"hidden\" name=\"action\" value=\"display\" />
        !            92: <input type=\"button\" onClick=\"this.form.submit()\" value=\"$lt{'gobt'}\" />
        !            93: </p>
        !            94: </form>");
        !            95:     &print_footer($r);
        !            96:     return;
        !            97: }
        !            98: 
        !            99: sub print_course_modification_page {
        !           100:     my ($r,$tasklongref,$typeref) = @_;
        !           101:     my %enrollvar = ();
        !           102:     my @bgcolors=("#eeeeee","#cccccc");
        !           103:     my $course = $ENV{'form.course'};
        !           104:     my $dom = $ENV{'user.domain'};
        !           105:     my $ownertable;
        !           106:     my %settings = &Apache::lonnet::dump('environment',$dom,$course);
        !           107:     foreach my $item (keys %settings) {
        !           108:         if ($item =~ m/^internal\.(.+)$/) {
        !           109:             if ( ($1 eq "autoadds") || ($1 eq "autodrops") ) {
        !           110: 	        if ($settings{$item} == 1) {
        !           111: 	            $enrollvar{$1} = "ON";
        !           112: 	        } else {
        !           113: 	            $enrollvar{$1} = "OFF";
        !           114: 	        }
        !           115:             } elsif ( ($1 eq "autostart") || ($1 eq "autoend") ) {
        !           116: 	        if ( ($1 eq "autoend") && ($settings{$item} == 0) ) {
        !           117: 	            $enrollvar{$1} = "No end date";
        !           118: 	        } else {
        !           119: 	            $enrollvar{$1} = localtime($settings{$item});
        !           120: 	        }
        !           121:             } else {
        !           122: 	        $enrollvar{$1} = $settings{$item};
        !           123:             }
        !           124:         }
        !           125:     }
        !           126: 
        !           127:     my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$course);
        !           128:     my @local_ccs = ();
        !           129:     my %cc_status = ();
        !           130:     my %pname = ();
        !           131:     my $active_cc;
        !           132:     foreach (@coursepersonnel) {
        !           133:         my @roleinfo = split/:/,$_;
        !           134:         if ( ($roleinfo[0] eq 'cc')  && ($roleinfo[2] eq $dom) )  {
        !           135:             unless (grep/^$roleinfo[1]$/,@local_ccs) {
        !           136:                 $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$course,'cc');
        !           137:                 if ($active_cc eq 'ok') {
        !           138:                     push @local_ccs, $roleinfo[1];
        !           139:                     $pname{$roleinfo[1]} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
        !           140:                     $cc_status{$roleinfo[1]} = 'Active';
        !           141:                 }
        !           142:             }
        !           143:         }
        !           144:     }
        !           145:     unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') )  {
        !           146:         push @local_ccs, $enrollvar{'coursecode'};
        !           147:         my ($puname,$pdom) = split/\@/,$enrollvar{'courseowner'};
        !           148:         $pname{$enrollvar{'courseowner'}} =  &Apache::loncommon::plainname($puname,$pdom);
        !           149:         $active_cc = &LONCAPA::Enrollment::check_user_status($pdom,$enrollvar{'coursecode'},$dom,$course,'cc');
        !           150:         if ($active_cc eq 'ok') {
        !           151:             $cc_status{$enrollvar{'courseowner'}} = 'Active';
        !           152:         } else {
        !           153:             $cc_status{$enrollvar{'courseowner'}} = 'Inactive';
        !           154:         }
        !           155:     }
        !           156:     my $numlocalcc = @local_ccs;
        !           157:     my $bodytag=&Apache::loncommon::bodytag('Modify Course Settings');
        !           158:     my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt('Help on Modifying Courses'));
        !           159:     my $defdom=$ENV{'request.role.domain'};
        !           160:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($defdom);
        !           161:     my $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom);
        !           162:     my %param = ( formname => 'document.cmods',
        !           163: 	   kerb_def_dom => $krbdefdom,
        !           164: 	   kerb_def_auth => $krbdef
        !           165: 	);
        !           166:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
        !           167:     my $sellink=&Apache::loncommon::selectstudent_link
        !           168: 				('cmod','crsown','ccdomain');
        !           169:     my $krbform = &Apache::loncommon::authform_kerberos(%param);
        !           170:     my $intform = &Apache::loncommon::authform_internal(%param);
        !           171:     my $locform = &Apache::loncommon::authform_local(%param);
        !           172:     my %lt=&Apache::lonlocal::texthash(
        !           173: 	    'aecs' => "Automated Enrollment Course Settings",
        !           174:             '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 ", 
        !           175:             'aenm' => "Automated Enrollment Manager",
        !           176:             'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.",
        !           177:             'caes' => 'Current automated enrollment settings',
        !           178: 	    'cour' => "Course settings that control automated enrollment in this LON-CAPA course are currently:",
        !           179: 	    'cset' => "Course setting",
        !           180: 	    'valu' => "Current value",
        !           181: 	    'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change all settings except course code, course owner, and default authentication method for students added to your course (who are also new to the LON-CAPA system at this domain).",
        !           182: 	    'mkch' => "Make changes to course settings set by Domain Coordinator", 
        !           183: 	    'ccod' => "Course Code",
        !           184: 	    'ccus' => "The course code is used during automated enrollment to map the internal LON-CAPA course ID for this course to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution.",
        !           185: 	    'cown' => "Course Owner",
        !           186: 	    'cous' => "The course owner is used in the retrieval of class lists from your institution's student information system when access to class lists data incorporates validation of instructor status.",
        !           187:             'tabl' => 'The table below contains a list of active course coordinators in this course,
        !           188: who are from this domain', 
        !           189:             'usrd' => 'Use the radio buttons to select a different course owner.', 
        !           190: 	    'deam' => "Default Authentication method",
        !           191: 	    'deus' => "The default authentication method, and default authentication parameter (domain, initial password or argument) are used when automatic enrollment of students in a course requires addition of new user accounts in your domain, and the class list file contains empty entries for the &lt;authtype&gt; and &lt;autharg&gt; properties for the new student.",
        !           192: 	    'gobt' => "Modify settings",
        !           193:     );
        !           194: 
        !           195:     my $disp_table = qq|<table border="0" cellpadding="0" cellspacing="0">
        !           196:                 <tr>
        !           197:                  <td width="100%" bgcolor="#000000">
        !           198:                   <table width="100%" border="0" cellpadding="1" cellspacing="0">
        !           199:                    <tr>
        !           200:                     <td width="100%" bgcolor="#000000">
        !           201:                      <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
        !           202:                       <tr bgcolor="#CCCC99" align="center">
        !           203: 	               <td><b>$lt{'cset'}</b></td>
        !           204: 	               <td><b>$lt{'valu'}</b></td>
        !           205: 	              </tr>
        !           206:     |;
        !           207:     my $iter = 0;
        !           208:     foreach my $key (sort keys %enrollvar) {
        !           209:         my $colflag = $iter%2;
        !           210:         $disp_table .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
        !           211: 		 <td>$$typeref{$key}</td>
        !           212: 		 <td>$enrollvar{$key}</td>
        !           213: 		</tr>";
        !           214:        $iter ++;
        !           215:     }
        !           216:     $disp_table .= "</table>
        !           217:                    </td>
        !           218:                   </tr>
        !           219:                  </table>
        !           220:                 </td>
        !           221:                </tr>
        !           222:               </table>";
        !           223: 
        !           224:     if ($numlocalcc == 0) {
        !           225:         $ownertable = "No course coordinators";
        !           226:     }
        !           227:     if ($numlocalcc > 0) {
        !           228:         @local_ccs = sort @local_ccs;
        !           229:         $ownertable = qq(
        !           230:             <input type="hidden" name="numlocalcc" value="$numlocalcc" />
        !           231:             <table>
        !           232:              <tr>
        !           233:                <td>$lt{'tabl'} ($dom). $lt{'usrd'}
        !           234:               </td>
        !           235:              </tr>
        !           236:              <tr><td>&nbsp;</td></tr>
        !           237:              <tr>
        !           238:               <td>
        !           239:                <table border="0" cellpadding="0" cellspacing="0">
        !           240:                 <tr>
        !           241:                  <td width="100%" bgcolor="#000000">
        !           242:                   <table width="100%" border="0" cellpadding="1" cellspacing="0">
        !           243:                    <tr>
        !           244:                     <td width="100%" bgcolor="#000000">
        !           245:                      <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
        !           246:                       <tr bgcolor="#CCCC99" align="center">
        !           247:                        <td><b>Owner</b></td>
        !           248:                        <td><b>Name</b></td>
        !           249:                        <td><b>Username</b></td>
        !           250:                        <td><b>Status</b></td>
        !           251:                       </tr>
        !           252:         );
        !           253:         for (my $i=0; $i<@local_ccs; $i++) {
        !           254:             my $colflag = $i%2;
        !           255:             $ownertable .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">";
        !           256:             if ($local_ccs[$i] eq $enrollvar{'courseowner'}) {
        !           257:                   $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" checked=\"true\"/></td>";
        !           258:             } else {
        !           259:                 $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" /></td>";
        !           260:             }
        !           261:             $ownertable .= "
        !           262:                  <td>$pname{$local_ccs[$i]}</td>
        !           263:                  <td><input type=\"hidden\" name=\"username_$i\" value=\"$local_ccs[$i]\" />$local_ccs[$i]</td>
        !           264:                  <td>$cc_status{$local_ccs[$i]} Course Coordinator</td></tr>";
        !           265:         }
        !           266:         $ownertable .= "</table>
        !           267:                     </td>
        !           268:                    </tr>
        !           269:                   </table>
        !           270:                  </td>
        !           271:                 </tr>
        !           272:                </table>
        !           273:               </td>
        !           274:              </tr>
        !           275:             </table>";
        !           276:     }
        !           277:     &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations);
        !           278:     $r->print(<<ENDDOCUMENT);
        !           279: <form action="/adm/modifycourse" method="post" name="cmod">
        !           280: <h2>$lt{'aecs'}</h2>
        !           281: $lt{'cose'}<a href="/adm/populate">$lt{'aenm'}</a>$lt{'andb'}
        !           282: <p>
        !           283: <table width="100%" cellspacing="0" cellpadding="0">
        !           284:  <tr>
        !           285:   <td bgcolor="#CCCC99">&nbsp;</td>
        !           286:   <td align="left" bgcolor="#CCCC99"><h3>$lt{'caes'}</h3></td>
        !           287:  </tr>
        !           288: </table>
        !           289: <p>
        !           290: $lt{'cour'}
        !           291: </p><p>
        !           292: $disp_table
        !           293: <br/<br/>
        !           294: </p><p>
        !           295: 
        !           296: <table width="100%" cellspacing="0" cellpadding="0">
        !           297:  <tr>
        !           298:   <td bgcolor="#CCCC99">&nbsp;</td>
        !           299:   <td align="left" bgcolor="#CCCC99">
        !           300:    <h3>$lt{'mkch'}</h3>
        !           301:   </td>
        !           302:  </tr>
        !           303: </table>
        !           304: </p><p>
        !           305: <table width="100%" cellspacing="3" cellpadding="8">
        !           306:  <tr>
        !           307:   <td width="50%" valign="top">
        !           308:    <b>$lt{'ccod'}</b>
        !           309:     <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
        !           310:     $lt{'ccus'}
        !           311:   </td>
        !           312:   <td width="50%" valign="top" rowspan="2">
        !           313:    <b>$lt{'cown'}</b><br/><br/>
        !           314:    $lt{'cous'}
        !           315:    <br/><br/>
        !           316:    $ownertable
        !           317:   </td>
        !           318:  </tr>
        !           319:  <tr>
        !           320:   <td width="50%" valign="top">
        !           321:    <b>$lt{'deam'}.</b><br/><br/>
        !           322:    $lt{'deus'}.
        !           323: </p><p>
        !           324: $krbform
        !           325: <br />
        !           326: $intform
        !           327: <br />
        !           328: $locform
        !           329:    </td>
        !           330:    <td width="50%">&nbsp;</td>
        !           331:  </tr>
        !           332: </table>
        !           333: <br/><br/>
        !           334: <table width="90%" cellpadding="5" cellspacing="0">
        !           335:  <tr>
        !           336:   <td align="right">
        !           337:    <input type="hidden" name="course" value="$course" />
        !           338:    <input type="hidden" name="action" value="process" />
        !           339:    <input type="button" onClick="verify_message(this.form)" value="$lt{'gobt'}" />
        !           340:   </td>
        !           341:  </tr>
        !           342: </table>
        !           343: </form>
        !           344: <br/>
        !           345: <br/>
        !           346: ENDDOCUMENT
        !           347:     &print_footer($r);
        !           348: }
        !           349: 
        !           350: sub modify_course {
        !           351:     my ($r,$tasklongref,$typeref) = @_;
        !           352:     my $dom = $ENV{'user.domain'};
        !           353:     my $crs = $ENV{'form.course'};
        !           354:     my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistngs','description'],$dom,$crs);
        !           355:     my %currattr = ();
        !           356:     my %newattr = ();
        !           357:     my %cenv = ();
        !           358:     my $response;
        !           359:     my $chgresponse;
        !           360:     my $nochgresponse;
        !           361:     my $warning;
        !           362:     my $reply;
        !           363:     my @changes = ();
        !           364:     my @nochanges = ();
        !           365:     my @sections = ();
        !           366:     my @xlists = ();
        !           367:     my $changecode = 0;
        !           368:     my $changeowner = 0;
        !           369:     unless ($settings{'internal.sectionnums'} eq'') {
        !           370:         if ($settings{'internal.sectionnums'} =~ m/,/) {
        !           371:             @sections = split/,/,$settings{'internal.sectionnums'};
        !           372:         } else {
        !           373:             $sections[0] = $settings{'internal.sectionnums'};
        !           374:         }
        !           375:     }
        !           376:     unless ($settings{'internal.crosslistings'} eq'') {
        !           377:         if ($settings{'internal.crosslistings'} =~ m/,/) {
        !           378:             @xlists = split/,/,$settings{'internal.crosslistings'};
        !           379:         } else {
        !           380:             $xlists[0] = $settings{'internal.crosslistings'};
        !           381:         }
        !           382:     }
        !           383: 
        !           384:     my @params = ('courseowner','coursecode','authtype','autharg');
        !           385:     foreach (@params) {
        !           386:         my $attr = 'internal.'.$_;
        !           387:         $currattr{$_} = $settings{$attr};
        !           388:     }
        !           389: 
        !           390:     my $description = $settings{'description'};
        !           391:     my %cenv = ();
        !           392: 
        !           393:     if ($ENV{'form.login'} eq 'krb') {
        !           394:         $newattr{'authtype'} = $ENV{'form.login'};
        !           395:         $newattr{'authtype'} .= $ENV{'form.krbver'};
        !           396:         $newattr{'autharg'} = $ENV{'form.krbarg'};
        !           397:     } elsif ($ENV{'form.login'} eq 'int') {
        !           398:         $newattr{'authtype'} ='internal';
        !           399:         if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
        !           400:             $newattr{'autharg'} = $ENV{'form.intarg'};
        !           401:         }
        !           402:     } elsif ($ENV{'form.login'} eq 'loc') {
        !           403:         $newattr{'authtype'} = 'localauth';
        !           404:         if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
        !           405:             $newattr{'autharg'} = $ENV{'form.locarg'};
        !           406:         }
        !           407:     }
        !           408:     if ( $newattr{'authtype'}=~ /^krb/) {
        !           409:         if ($newattr{'autharg'}  eq '') {
        !           410:             $warning = qq('<font color="red" size="+1">'.
        !           411: 	    &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').'</font></p>');
        !           412:         }
        !           413:     }
        !           414: 
        !           415:     if ( exists($ENV{'form.courseowner'}) ) {
        !           416:          my $ownerparam = 'username_'.$ENV{'form.courseowner'};
        !           417:          if ( exists($ENV{"form.$ownerparam"}) ) {  
        !           418:             $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
        !           419:             unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
        !           420:                 $changeowner = 1;
        !           421:             }
        !           422:         } 
        !           423:     }
        !           424: 													      
        !           425:     if ( exists($ENV{'form.coursecode'}) ) {
        !           426:         $newattr{'coursecode'}=$ENV{'form.coursecode'};
        !           427:         unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
        !           428:             $changecode = 1;
        !           429:         }
        !           430:     }
        !           431: 
        !           432:     foreach (@params) {
        !           433:         if ($currattr{$_} eq $newattr{$_}) {
        !           434:             push @nochanges, $_;
        !           435:         } else {
        !           436:             my $attr = 'internal.'.$_;
        !           437:             $cenv{$attr} = $newattr{$_};
        !           438:             push @changes, $_;
        !           439:         }
        !           440:     }
        !           441: 
        !           442:     if (@changes > 0) {
        !           443:         $chgresponse = "The following automated enrollment parameters have been changed:<br/><ul>";
        !           444:     }
        !           445:     if (@nochanges > 0) { 
        !           446:         $nochgresponse = "The following automated enrollment parameters remain unchanged:<br/><ul>";
        !           447:     }
        !           448:     if (@changes > 0) { 
        !           449:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !           450:         if ($putreply !~ /^ok$/) {
        !           451:             $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !           452:         } else {
        !           453:             foreach my $attr (@params) {
        !           454:                 if (grep/^$attr$/,@changes) {
        !           455: 	            $chgresponse .= "<li>$$typeref{$attr} now set to $newattr{$attr}.</li>";
        !           456:                 } else {
        !           457: 	            $nochgresponse .= "<li>$$typeref{$attr} still set to $currattr{$attr}.</li>";
        !           458:                 }
        !           459:             }
        !           460:             if ($changecode || $changeowner) {
        !           461:                 if ( $newattr{'courseowner'} eq '') {
        !           462: 	            $warning .= "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/>";
        !           463:                 } else {
        !           464: 	            if (@sections > 0) {
        !           465: 	                foreach my $sec (@sections) {
        !           466: 		            if ($sec =~ m/^(.+):/) {
        !           467: 		                my $course_id = $newattr{'coursecode'}.$1;
        !           468: 		                if ($changecode) {
        !           469: #			            my $course_check = &localenroll::validate_courseID($course_id);
        !           470:                                     my $course_check = 'ok';
        !           471: 			            if ($course_check eq 'ok') {  
        !           472: #                                        my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
        !           473: 			                my $outcome = 'ok';
        !           474: 			                unless ($outcome eq 'ok') { 
        !           475: 				            $warning .= "If automatic enrollment is enabled for LON-CAPA course: $description, automated enrollment may fail for $newattr{'coursecode'} - section $1 for the following reason: $outcome.<br/>";
        !           476: 			                }
        !           477: 			            } else {
        !           478: 			                $warning .= "If automatic enrollment is enabled for LON-CAPA course: $description, automated enrollment may fail for $newattr{'coursecode'} - section $1 for the following reason: $course_check.<br/>";
        !           479: 			            }
        !           480: 		                } else {
        !           481: 			            $warning .= "If automatic enrollment is enabled for LON-CAPA course: $description, automated enrollment may fail for $newattr{'coursecode'} - section $sec because this is not a valid section entry.<br/>";
        !           482: 		                }
        !           483: 		            }
        !           484: 	                } 
        !           485: 	            } else {
        !           486: 	                $warning .= "As no section numbers are currently listed for LON-CAPA course: $description, automated enrollment will not occur for any sections of coursecode: $newattr{'coursecode'}.<br/>";
        !           487: 	            }
        !           488: 	            if ( (@xlists > 0) && ($changeowner) ) {
        !           489: 	                foreach my $xlist (@xlists) {
        !           490: 		            if ($xlist =~ m/^(.+):/) {
        !           491: #                                my $outcome = &localenroll::new_course($1,$newattr{'courseowner'});
        !           492: 		                my $outcome = 'ok';
        !           493: 		                unless ($outcome eq 'ok') {
        !           494: 			            $warning .= "If automatic enrollment is enabled for LON-CAPA course: $description, automated enrollment may fail for crosslisted class: $1 for the following reason: $outcome.<br/>";
        !           495: 		                }
        !           496: 		            } 
        !           497: 	                }
        !           498: 	            }
        !           499:                 }
        !           500:             }
        !           501:         }
        !           502:     }
        !           503: 
        !           504:     if (@changes > 0) {
        !           505:         $chgresponse .= "</ul><br/><br/>";
        !           506:     }
        !           507:     if (@nochanges > 0) {
        !           508:         $nochgresponse .=  "</ul><br/><br/>";
        !           509:     }
        !           510:     unless ($warning eq '') {
        !           511:         $warning = "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;
        !           512:     }
        !           513:     if ($response eq '') {
        !           514:         $reply = $chgresponse.$nochgresponse.$warning;
        !           515:     } else {
        !           516:         $reply = $response;
        !           517:     }
        !           518:     &print_header($r,$tasklongref,$description);
        !           519:     $r->print("<table><tr><td>$reply</td></tr></table");
        !           520:     &print_footer($r);
        !           521:     return; 
        !           522: }
        !           523: 
        !           524: sub print_header {
        !           525:     my ($r,$tasklongref,$description,$javascriptref) = @_;
        !           526:     my %lt = (
        !           527:              'vmcs' => 'View/Modify Course Settings',
        !           528:              'chco' => 'Choose a course',
        !           529:              'main' => 'Main Menu',
        !           530:              'comg' => 'Course Manager',
        !           531:              );
        !           532:     my $action = "start";
        !           533:     if ( exists($ENV{'form.action'}) ) {
        !           534:         $action = $ENV{'form.action'};
        !           535:     }
        !           536:     if ( ($description eq '') || (!defined($description)) ) {
        !           537:         $description = $lt{'comg'};
        !           538:     }
        !           539:     my $page = '';
        !           540:     my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
        !           541:     if ($action eq 'start') {  
        !           542:         $page = "<b>$lt{'chco'}</b>";
        !           543:     } else {
        !           544:         $page =  '<a href="/adm/modifycourse">'.$lt{'chco'}.'</a>';
        !           545:         if ( $action eq 'process' ) {
        !           546:             my $course = $ENV{'form.course'};
        !           547:             $page .= "-&gt; <a href=\"/adm/modifycourse?action=display&course=$course\">".$$tasklongref{'display'}."</a> -&gt; <b>$$tasklongref{$action}</b> ";
        !           548:         } else {
        !           549:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>";
        !           550:         }
        !           551:     }
        !           552:     $r->print("
        !           553: <html>
        !           554: <head>");
        !           555:     if ($action eq 'display') {
        !           556:         $r->print("
        !           557: <script language=\"JavaScript\" type=\"text/javascript\">
        !           558: $$javascriptref
        !           559: </script>");
        !           560:     }
        !           561:     $r->print(<<ENDTHIS);
        !           562: <title>The LearningOnline Network with CAPA</title>
        !           563: </head>
        !           564: $bodytag
        !           565: <table width="100%" border="0" cellpadding="0" cellspacing="0">
        !           566:  <tr>
        !           567:   <td bgcolor="#CCCC99">
        !           568:    <font size="2"><a href="/adm/menu">$lt{'main'}</a> -&gt; $page</font><br/>
        !           569:   </td>
        !           570:   <td align="right" bgcolor="#CCCC99" valign="top">
        !           571:    <font size="+1">$description &nbsp;</font>
        !           572:   </td>
        !           573:  </tr>
        !           574: </table>
        !           575: ENDTHIS
        !           576: }
        !           577: 
        !           578: sub print_footer {
        !           579:   my $r = shift;
        !           580:   $r->print(<<ENDBASE);
        !           581: <br/>
        !           582: </body>
        !           583: </html>
        !           584: ENDBASE
        !           585: }
        !           586: 
        !           587: 
        !           588: sub handler {
        !           589:     my $r = shift;
        !           590:     if ($r->header_only) {
        !           591:         &Apache::loncommon::content_type($r,'text/html');
        !           592:         $r->send_http_header;
        !           593:         return OK;
        !           594:     }
        !           595:                                                                                   
        !           596:     if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
        !           597:         &Apache::loncommon::content_type($r,'text/html');
        !           598:         $r->send_http_header;
        !           599: 
        !           600:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']);
        !           601:         my $dom = $ENV{'user.domain'};
        !           602:         my %longtype = (
        !           603:                        'authtype' => 'Default authentication method',
        !           604:                        'autharg'  => 'Default authentication parameter',
        !           605:                        'autoadds' => 'Automated adds',
        !           606:                        'autodrops' => 'Automated drops',
        !           607:                        'autostart' => 'Date of first enrollment',
        !           608:                        'autoend' => 'Date of last enrollment',
        !           609:                        'coursecode' => 'Official course code',
        !           610:                        'courseowner' => "Username of course owner (\@$dom)",
        !           611:                        'notifylist' => 'Course Coordinators to be notified of enrollment changes',
        !           612:                        'sectionnums' => 'Course section number(:groupID)',
        !           613:                        'crosslistings' => 'Crosslisted class(:groupID)',
        !           614:                       );
        !           615: 
        !           616:         my %tasklong = (
        !           617:                         'display' => 'View/modify settings',
        !           618:                         'process'  => 'Results of changes',
        !           619:                        );
        !           620:                                                                                   
        !           621:         if ($ENV{'form.action'} eq 'process') {
        !           622:             &modify_course($r,\%tasklong,\%longtype);
        !           623:         } elsif ($ENV{'form.action'} eq 'display')  {
        !           624:             &print_course_modification_page($r,\%tasklong,\%longtype);
        !           625:         } else {
        !           626:             &print_course_selection_page($r,\%tasklong);
        !           627:         }
        !           628:     } else {
        !           629:         $ENV{'user.error.msg'}=
        !           630:         "/adm/createcourse:ccc:0:0:Cannot modify course settings";
        !           631:         return HTTP_NOT_ACCEPTABLE;
        !           632:     }
        !           633:     return OK;
        !           634: }
        !           635: 
        !           636: 1;
        !           637: __END__

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