Annotation of loncom/interface/lonpopulate.pm, revision 1.11

1.4       albertel    1: # automated enrollment configuration handler
1.11    ! albertel    2: # $Id: lonpopulate.pm,v 1.10 2004/01/15 05:56:34 raeburn Exp $
1.4       albertel    3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
1.1       raeburn    26: package Apache::lonpopulate;
                     27: 
                     28: use strict;
                     29: use lib qw(/home/httpd/lib/perl);
1.7       raeburn    30: use Apache::lonnet;
                     31: use Apache::loncommon;
                     32: use Apache::lonhtmlcommon;
1.3       albertel   33: use Apache::lonlocal;
1.1       raeburn    34: use Apache::Constants qw(:common :http REDIRECT);
                     35: use Time::Local;
1.7       raeburn    36: use LONCAPA::Enrollment;
1.1       raeburn    37: use localenroll;
                     38: 
                     39: ###############################################################
                     40: sub header {
                     41:     my $bodytag=&Apache::loncommon::bodytag('Classlist Manager');
                     42:     return(<<ENDHEAD);
                     43: <html>
                     44: <head>
                     45: <title>LON-CAPA Classlist Manager</title>
                     46: </head>
                     47: $bodytag
                     48: ENDHEAD
                     49: }
                     50: 
                     51: ###############################################################
                     52: 
                     53: sub choose_header {
                     54:     my $bodytag=&Apache::loncommon::bodytag('Classlist Manager');
                     55:     my $scripttag = qq|
                     56: <script language='javascript' type='text/javascript'>
                     57: <!--
                     58: function process(calling) {
                     59:  var checker = 1
                     60:  var rad1 = 0
                     61:  var rad2 = 0
                     62:  var formName = document.forms.enter
                     63:  formName.action.value = calling
                     64:  if (calling == "chgsettings") {
                     65:    for (var j=0; j<formName.autoadds.length; j++) {
                     66:        if (formName.autoadds[j].checked) {
                     67:            rad1 = 1
                     68:        }
                     69:    }
                     70:    for (var k=0; k<formName.autodrops.length; k++) {
                     71:        if (formName.autodrops[k].checked) {
                     72:            rad2 = 1
                     73:        }
                     74:    }
                     75:    if (rad1 == 0) {
                     76:        alert("You must check either 'Enable' or 'Disable' for nightly additions based on classlist changes")
                     77:        checker = 0
                     78:    }
                     79:    if (rad2 == 0) {
                     80:        alert("You must check either 'Enable' or 'Disable' for nightly removals based on classlist changes")
                     81:        checker = 0
                     82:    }
                     83:  }
                     84:  if (calling == "updatenow") {
                     85:      var enrolldis
                     86:      var unenrolldis
                     87:      for (var j=0; j<formName.updateadds.length; j++) {
                     88:          if (formName.updateadds[j].value == 0) {
                     89:              enrolldis = j
                     90:          }
                     91:          if (formName.updateadds[j].checked) {
                     92:              rad1 = 1
                     93:          }
                     94:      }
                     95:      for (var k=0; k<formName.updatedrops.length; k++) {
                     96:          if (formName.updatedrops[k].value == 0) {
                     97:              unenrolldis = k 
                     98:          }
                     99:          if (formName.updatedrops[k].checked) {
                    100:              rad2 = 1
                    101:          }
                    102:      }
                    103:      if (rad1 == 0) {
                    104:          alert("You must check either 'Enable' or 'Disable' for nightly additions based on classlist changes")
                    105:          checker = 0
                    106:      }
                    107:      if (rad2 == 0) {
                    108:          alert("You must check either 'Enable' or 'Disable' for nightly removals based on classlist changes")
                    109:          checker = 0
                    110:      }
                    111:      if (formName.updatedrops[unenrolldis].checked && formName.updateadds[enrolldis].checked ) {
                    112:          alert("You have checked 'Disable' for both addition and removal of students\\n in the Registrar's classlist but not in your LON-CAPA course.  \\nHence there is no update to carry out")
                    113:          checker = 0
                    114:      }
                    115:  }
                    116:  if (checker == 1) {  
                    117:      formName.submit();
                    118:  }
                    119: }
                    120: // End hiding -->
                    121: </script>
                    122: |;
                    123:     return(<<ENDHEAD);
                    124: <html>
                    125: <head>
                    126: <title>LON-CAPA Classlist Manager</title>
                    127: $scripttag
                    128: $bodytag
                    129: ENDHEAD
                    130: }
                    131: 
                    132: sub print_mainbox {
                    133:     my ($r,$tasklongref,$realm,$reply) = @_;
                    134:     my $action = "information";
                    135:     if ( exists($ENV{'form.action'}) ) {
                    136:         $action = $ENV{'form.action'};
                    137:     }
                    138:     my $page = '';
                    139:     if ($action eq "information") {
                    140:         $page = "<b>Automated Enrollment</b>";
                    141:     } else {
                    142:         $page =  '<a href="/adm/populate">Automated Enrollment</a>';
                    143:         if ($reply) {
                    144:             if ($action eq "newcross") {
                    145:                 $action = "crosslist";
                    146:             } elsif ($action eq "newsections") {
                    147:                 $action = "sections"; 
                    148:             }
                    149:             $page .= "-&gt; <a href=\"/adm/populate?action=$action\">".$$tasklongref{$action}."</a> -&gt; <b>result</b>";
                    150:         } else {
                    151:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>"; 
                    152:         }
                    153:     }
                    154:     $r->print(<<ENDTHIS);
                    155: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    156:  <tr>
                    157:   <td bgcolor="#CCCCFF"> 
                    158:    <font size="2"><a href="/adm/menu">$realm</a> -&gt; <a href="/adm/dropadd">Enrollment Manager</a> -&gt; $page</font><br/>
                    159:   </td>
                    160:   <td align="right" bgcolor="#CCCCFF" valign="top">
                    161:    <font size="+1">Automated Enrollment Manager&nbsp;</font>
                    162:   </td>
                    163:  </tr>
                    164: </table>
                    165: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    166:  <tr>
                    167: ENDTHIS
                    168: }
                    169: 
                    170: sub print_navmenu {
                    171:     my ($r,$tasksref,$tasklongref) = @_;
                    172:     my $action = "information";
                    173:     if (exists($ENV{'form.action'}) ) {
                    174:         $action = $ENV{'form.action'};
                    175:     }
                    176:     $r->print(<<ENDONE);
                    177:   <td width="10" valign="top" bgcolor="#DDFFFF">&nbsp;</td>
                    178:   <td width="20%" valign="top" bgcolor="#DDFFFF">
                    179:    <br/>
                    180: ENDONE
                    181:     foreach my $task (@{$tasksref}) {
                    182:         if ($task eq $action) {
                    183:             $r->print(" 
                    184:    <p>
                    185:    <font color=\"#999999\">
                    186:     <b>$$tasklongref{$task}</b><br/>
                    187:    </font>
                    188:    </p>"); 
                    189:         } else {
                    190:             $r->print("
                    191:    <p>
                    192:    <font color=\"#004263\">
                    193:     <b><a href=\"/adm/populate?action=$task\">$$tasklongref{$task}</a></b><br/>
                    194:    </font> 
                    195:    </p>");
                    196: 
                    197:         }
                    198:     }
                    199:     $r->print("
                    200:   <p>&nbsp;</p>
                    201:   </td>
                    202:   <td width=\"10\" valign=\"top\" bgcolor=\"#CCCCFF\">&nbsp;</td>
                    203:   <td width=\"10\" valign=\"top\" bgcolor=\"#FFFFFF\">&nbsp;</td>
                    204:   <td bgcolor=\"#ffffff\" valign=\"top\">");
                    205: }
                    206: 
                    207: ###############################################################
                    208: 
                    209: sub print_main_frame {
                    210:   my ($r,$realm,$dom,$crs,$tasktitleref) = @_;
                    211:   my $action = "information";
                    212:   if (exists($ENV{'form.action'}) ) {
                    213:       $action = $ENV{'form.action'};
                    214:   }
                    215: 
                    216: # Get course settings
                    217:   my %enrollvar;
                    218:   my @bgcolors=("#eeeeee","#cccccc");
                    219:   my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
                    220:   foreach my $item (keys %settings) {
                    221:       if ($item =~ m/^internal\.(.+)$/) {
                    222:           $enrollvar{$1} = $settings{$item};
                    223:       }
                    224:   }
                    225: 
                    226:   if ($action eq "information") {
                    227:       $r->print(<<ENDONE);
1.2       raeburn   228:           <br/><table border='0' width='100%'>
1.1       raeburn   229:             <tr>
                    230:               <td>&nbsp;</td>
                    231:               <td><b>Use the menu on the left to choose an enrollment management task.</b><br/><br/></td>
                    232:             <tr>
                    233:               <td>&nbsp;</td>
                    234:               <td>Use <i>"Automated adds/drops"</i> to enable or disable automatic nightly adds or drops in your LON-CAPA course based on instututional enrollment information.</td>
                    235:             </tr>
                    236:             <tr>
                    237:               <td>&nbsp;</td>
                    238:               <td>Use <i>"Change enrollment dates"</i> to change the date of first automated enrollment and/or the date of last automated enrollment for registered students.</td>
                    239:             </tr>
                    240:             <tr>
                    241:               <td>&nbsp;</td>
                    242:               <td>Use <i>"Notification of changes"</i> to enable or disable notification of enrollment changes and to add or remove course coordinators from the recipient list.</td>
                    243:             </tr>
                    244:             <tr>
                    245:               <td>&nbsp;</td>
                    246:               <td>Use <i>"Change crosslisting"</i> to include or exclude enrollment from crosslisted classes.</td>
                    247:             </tr>
                    248:             <tr>
                    249:               <td>&nbsp;</td>
                    250:               <td>Use <i>"Section settings"</i> to make changes to the choice of sections included for enrollment in your LON-CAPA course.</td>
                    251:             </tr>
                    252:               <td>&nbsp;</td>
1.2       raeburn   253:               <td>Use <i>"Student photos"</i> to enable or disable automatic upload of student photos to your course.</td>
1.1       raeburn   254:             </tr>
                    255:             <tr>
                    256:               <td>&nbsp;</td>
                    257:               <td>Use <i>"Update roster now"</i> to add and/or drop students from your course based on the <b>most current</b> institutional classlist information.</td>
                    258:             </tr>
                    259:             <tr>
                    260:              <td colspan='2'>&nbsp;</td>
                    261:             </tr>
                    262:             <tr>
                    263:              <td>&nbsp;</td>
                    264:              <td><b>Note: if automated adds and/or drops are enabled, the nightly enrollment update will ONLY occur once the first enrollment date has been reached.</b></td>
                    265:             </tr>
                    266:           </table>
                    267: ENDONE
                    268:   } elsif ($action eq "chgsettings") {
                    269:       my @autosets = ("OFF","ON");
                    270:       $r->print(<<ENDTWO);
                    271:                   <form name="enter" method="post"><br/>
                    272: 		  <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    273: 		   <tr>
                    274: 		    <td align="left"><b>$$tasktitleref{$action}</b><br/>
                    275: 		       Currently: Nightly adds: <i>$autosets[$enrollvar{autoadds}]</i>, Nightly drops: <i>$autosets[$enrollvar{autodrops}]</i>
                    276: 		    </td>
                    277:                    </tr>
                    278: 		  </table>
                    279: 		  <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    280: 		    <tr>
                    281: 		     <td>
                    282: 		         Additions based on classlist changes:&nbsp;&nbsp;
                    283: ENDTWO
                    284:       if ($enrollvar{autoadds}) {
                    285:           $r->print("
                    286: 			    <input type=\"radio\" name=\"autoadds\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    287: 			    <input type=\"radio\" name=\"autoadds\" value=\"0\" />&nbsp;Disable
                    288:          ");
                    289:       } else {
                    290:           $r->print("
                    291:                             <input type=\"radio\" name=\"autoadds\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    292:                             <input type=\"radio\" name=\"autoadds\" value=\"0\" checked=\"true\" />&nbsp;Disable
                    293:          ");
                    294:       }
                    295:       $r->print("
                    296:               </td>
                    297:              </tr>
                    298:              <tr>
                    299:               <td>
                    300:  	       Removals based on classlist changes:&nbsp;&nbsp;");
                    301:       if ($enrollvar{autodrops}) {
                    302:           $r->print("
                    303:                 <input type=\"radio\" name=\"autodrops\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    304:                 <input type=\"radio\" name=\"autodrops\" value=\"0\" />&nbsp;Disable");
                    305:       } else {
                    306:           $r->print("
                    307:                 <input type=\"radio\" name=\"autodrops\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    308:                 <input type=\"radio\" name=\"autodrops\" value=\"0\" checked=\"true\" />&nbsp;Disable");
                    309:       }
                    310:       $r->print("
                    311:               </td>
                    312:              </tr>
                    313:              <tr>
                    314:               <td>
                    315:                <font color=\"#888888\">
                    316: Note: Any students added manually by course coordinators using the Enrollment Manager will be unaffected by the nightly removal process if you choose to enable it.
                    317:                </font>
                    318:               </td>
                    319:              </tr>
                    320:              <tr>
                    321:               <td align=\"right\">
                    322:                <input type=\"button\" name=\"chgsettings\" value=\"Go\" onClick=\"process('chgsettings')\" />
                    323: 	      </td>
                    324:              </tr>
                    325: 	    </table>
                    326:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    327:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    328:             </form>
                    329:       ");
                    330:   } elsif ($action eq "setdates") {
                    331:       my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend});
1.10      raeburn   332:       my $oldstartshow = '';
                    333:       my $oldendshow = '';
                    334:       if ( defined($enrollvar{autostart}) ) {
                    335:           $oldstartshow = localtime($enrollvar{autostart});
                    336:       }
                    337:       if ( defined($enrollvar{autoend}) ) {
                    338:           $oldendshow = localtime($enrollvar{autoend});
                    339:           if ($enrollvar{autoend} == 0) {
                    340:               $oldendshow = "No ending date";
                    341:           }
                    342:       }
                    343:       my $dateshow;
                    344:       if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
                    345:          $dateshow = "<br/><font size='+1'>Warning</font>. Currently <b>NO</b> first enrollment or last enrollment dates are set. You <b>must</b> use this menu to set a start date and an end date (or check the 'no ending date' checkbox) if you plan to utilise automated adds and/or drops in this course.\n";
                    346:       } else {
                    347:          $dateshow = "Currently: First enrollment: <b><i>$oldstartshow</i></b>, Last enrollment: <b><i>$oldendshow</i></b>\n";
1.1       raeburn   348:       }
                    349:       $r->print(<<ENDTWO);
                    350:                   <form name="enter" method="post"><br/>              
                    351:                   <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    352: 	           <tr>
1.10      raeburn   353: 	            <td align="left"><b>$$tasktitleref{$action}</b><br/><br/>
                    354:                      $dateshow
1.1       raeburn   355: 	            </td>
                    356:                    </tr>
                    357: 	          </table>
                    358:                   <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    359:                    <tr>
                    360:                     <td align="left" colspan="2">
                    361:                      <table border="0" cellspacing="0" cellpadding="2">
                    362:                       <tr>
                    363:                        <td colspan="3">
                    364:                         <i>Set date of first automated enrollment for registered students</i>
                    365:                        </td>
                    366:                       </tr>
                    367:                       <tr>
                    368:                        <td>$start_table
                    369:                        </td>
                    370:                       </tr>
                    371:                      </table>
                    372:                     </td>
                    373:                    </tr>
                    374:                    <tr>
                    375:                     <td colspan="2"><font color="#888888">If automated adds and/or drops are enabled, then your class roster will be automatically updated nightly, once the first enrollment date has been reached. Prior to this date, the class roster will only contain students you have added directly using the standard LON-CAPA enrollment tools</font></td>
                    376:                    </tr>
                    377:                    <tr>
                    378:                     <td align="left" colspan="2">
                    379:                      <table border="0' cellspacing="0" cellpadding="2">
                    380:                       <tr>
                    381:                        <td colspan="3">
                    382:                         <i>Set date of last automated enrollment for registered students</i>
                    383:                        </td>
                    384:                       </tr>
                    385:                       <tr>
                    386:                        <td>$end_table
                    387:                        </td>
                    388:                       </tr>
                    389:                      </table>
                    390:                     </td>
                    391:                    </tr>
                    392:                    <tr>
                    393:                     <td colspan="2"><font color="#888888">If automated adds and/or drops are enabled, then your class roster will be automatically updated nightly, until the last enrollment date has been reached.</font></td>
                    394:                    </tr>
                    395:                   </table>
                    396:                   <table width="100%">
                    397:                    <tr>
                    398:                     <td align="right">
                    399:                       <input type="button" name="setdates" value="Go" onClick="process('setdates')" />
                    400:                     </td>
                    401: 	           </tr>
                    402:                   </table>
                    403:                   <input type=\"hidden\" name=\"action\" value=\"$action\">
                    404:                   <input type=\"hidden\" name=\"state\" value=\"process\">
                    405:                   </form>
                    406: ENDTWO
                    407:   } elsif ($action eq "notify") {
                    408:       my @notified = ();
                    409:       if ($enrollvar{notifylist} =~ m/,/) {
                    410:           @notified = split/,/,$enrollvar{notifylist};
                    411:       } else {
                    412:           @notified = $enrollvar{notifylist};
                    413:       }
                    414:       my $notifycount = 0;
                    415:       foreach  (@notified) {
                    416:         unless ($_ eq '') { $notifycount ++; } 
                    417:       }
                    418:       my $noteset = '';
                    419:       if ($notifycount) {
                    420:           $noteset = "ON";
                    421:       } else {
                    422:           $noteset = "OFF";
                    423:       }
                    424:     
                    425:       $r->print("
                    426:                   <form name=\"enter\" method=\"post\"><br/>
                    427:                    <table width=\"100%\" border=\"0\" cellpadding=\"6\" cellspacing=\"0\">
                    428:                     <tr>
                    429:                      <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    430:                       Currently: Notification: $noteset
                    431:                      </td>
                    432:                     </tr>
                    433:                    </table>
                    434:                    <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    435:                     <tr>
                    436:                      <td>
                    437:                       Notification of LON-CAPA course roster changes resulting from nightly automated enrollment process?
                    438:       ");
                    439:       if ($notifycount) {
                    440:           $r->print("
                    441:                         <input type=\"radio\" name=\"notify\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    442:                         <input type=\"radio\" name=\"notify\" value=\"0\" />&nbsp;No
                    443:           ");
                    444:       } else {
                    445:           $r->print("
                    446:                         <input type=\"radio\" name=\"notify\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    447:                         <input type=\"radio\" name=\"notify\" value=\"0\" checked=\"true\" />&nbsp;No
                    448:           ");
                    449:       }
                    450:       $r->print("
                    451:               </td>
                    452:              </tr>
                    453:       ");
1.7       raeburn   454:       my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs);
                    455:       my @ccs = ();
                    456:       my @oldccs = ();
                    457:       my %pname = ();
                    458:       my %notifystate = ();
                    459:       foreach (@coursepersonnel) {
                    460:           my @roleinfo = split/:/,$_;
                    461:           if ($roleinfo[0] eq 'cc')  {
                    462:               unless (grep/^$roleinfo[1]\@$roleinfo[2]/,@ccs) {
                    463:                   my $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc');
                    464:                   if ($active_cc eq 'ok') {
                    465:                       push @ccs, "$roleinfo[1]\@$roleinfo[2]";
                    466:                       $pname{"$roleinfo[1]\@$roleinfo[2]"} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
                    467:                       if (grep/^$roleinfo[1]\@$roleinfo[2]$/,@notified) {
                    468:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 1;
                    469:                       } else {
                    470:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 0;
                    471:                       }
1.1       raeburn   472:                   } else {
1.7       raeburn   473:                       push @oldccs, "$roleinfo[1]\@$roleinfo[2]";
1.1       raeburn   474:                   }
                    475:               }
                    476:           }
                    477:       }
1.7       raeburn   478:       if ($notifycount > 0) {
                    479:           foreach my $person (@notified) {
                    480:               unless ( (grep/^$person$/,@ccs) || ($person eq '') || (grep/^$person$/,@oldccs) ) {
                    481:                   push @ccs, $person;
                    482:                   my ($puname,$pdom) = split/\@/,$person;
                    483:                   $pname{$person} =  &Apache::loncommon::plainname($puname,$pdom);
                    484:                   $notifystate{$person} = 1;
                    485:               }
                    486:           }
                    487:       }
                    488:       my $viewer = $ENV{'user.name'}.'@'.$ENV{'user.domain'};
                    489:       unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') )  {
                    490:           push @ccs,$viewer;
                    491:           $pname{$viewer} =  &Apache::loncommon::plainname($ENV{'user.name'},$ENV{'user.domain'});
                    492:           $notifystate{$viewer} = 0;
                    493:       }
                    494: 
                    495:       my $notifyshow = @ccs;
                    496: 
                    497:       if (@ccs > 0) {
                    498:           @ccs = sort @ccs;
1.1       raeburn   499:           $r->print("
                    500:              <tr>
1.7       raeburn   501:                <td>The table below contains a list of course coordinators in this course. Uncheck the 'Notification?' checkbox for each person who is to be removed from the list of recipients who are currently informed of roster changes whenever any adds or drops occur during the nightly enrollment check. To include individuals who are not currently recipients, simply check the 'Notification?' checkbox. Click 'Go' to store your changes.
1.1       raeburn   502:               </td>
                    503:              </tr>
                    504:              <tr>
                    505:               <td>
1.7       raeburn   506:                <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    507:                 <tr bgcolor=\"#CCCCFF\">
                    508:                  <td><b>Name</b></td>
                    509:                  <td><b>username</b></td>
                    510:                  <td><b>Current status</b></td>
                    511:                  <td><b>Notification?</b></td>
                    512:                 </tr>
                    513:           ");
                    514:           for (my $i=0; $i<@ccs; $i++) {
                    515:               my $colflag = $i%2;
                    516:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    517:                  <td>$pname{$ccs[$i]}</td>
                    518:                  <td><input type=\"hidden\" name=\"notifyname_$i\" value=\"$ccs[$i]\" />$ccs[$i]</td>
                    519:                  <td>
                    520:               ");
                    521:               if ($notifystate{$ccs[$i]} == 1) {
                    522:                   $r->print("Notification active");
                    523:               } else {
                    524:                   $r->print("Notification inactive");
                    525:               }
                    526:               if ($notifystate{$ccs[$i]} == 1) {
                    527:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" checked=\"true\" /></td></tr>");
                    528:               } else {
                    529:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" /></td></tr>");
                    530:               }
                    531:           }
                    532:           $r->print("
                    533:                </table>
                    534:                <br/>
                    535:                <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    536:                 <tr>
                    537:                  <td align=\"right\">
                    538:                   <input type=\"button\" name=\"notifyset\" value=\"Go\" onClick=\"process('notify')\" />
                    539:                  </td>
                    540:                 </tr>
                    541:                </table>
                    542:               </td>
                    543:              </tr>
1.1       raeburn   544:           ");
1.7       raeburn   545:       } else {
1.1       raeburn   546:           $r->print("
1.7       raeburn   547:              <tr>
                    548:               <td>
                    549:              No course coordinators found.
1.1       raeburn   550:             </td>
1.7       raeburn   551:            </tr>");
1.1       raeburn   552:       }
                    553:       $r->print("
1.7       raeburn   554:           </table>
                    555:           <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\">
                    556:           <input type=\"hidden\" name=\"action\" value=\"$action\">
                    557:           <input type=\"hidden\" name=\"state\" value=\"process\">
                    558:           </form>
1.1       raeburn   559:       ");
                    560:   } elsif ($action eq "crosslist") {
                    561:       my @xlists = ();
                    562:       if ($enrollvar{crosslistings} =~ m/,/) {
                    563:           @xlists = split/,/,$enrollvar{crosslistings};
                    564:       } elsif ($enrollvar{crosslistings} ne '') {
                    565:           $xlists[0] = $enrollvar{crosslistings};
                    566:       }
                    567:       my $cross_str = @xlists;
                    568:       $r->print("
                    569:             <form name=\"enter\" method=\"post\"><br/>
                    570:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    571:              <tr>
                    572:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    573:       ");
                    574:       if ($cross_str > 0) {
                    575:           $r->print("
1.7       raeburn   576:                 Currently, this LON-CAPA course is crosslisted with $cross_str course section(s).  Students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.  For each crosslisting, leave the checkbox checked if you want registered students in that course to be included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise uncheck it. If you wish to change the section/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this crosslisting. If you wish to add new crosslisted courses, enter the number of new courses to add in the textbox at the bottom of the page. You will provide information about each of the new crosslistings on a subsequent page.  Click 'Go' to store your changes.
1.1       raeburn   577:               </td>
                    578:              </tr>
                    579:             </table>
                    580:             <br/>
                    581:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    582:              <tr>
                    583:               <td>
                    584:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    585:                 <tr bgcolor=\"#CCCCFF\" align=\"left\">
                    586:                  <td><b>Enrollment?</b></td>
                    587:                  <td><b>Crosslisted course</b></td>
                    588:                  <td><b>LON-CAPA section/groupID</b></td>
                    589:                 </tr>
                    590:           ");
                    591:           for (my $i=0; $i<@xlists; $i++) {
                    592:               my $xl = '&nbsp;';
                    593:               my $gp = '&nbsp;';
                    594:               if ($xlists[$i] =~ /(\w+):(.+)$/) {
                    595:                   $xl = $1;
                    596:                   $gp = $2;
                    597:               }               
                    598:               my $colflag = $i%2;
                    599:               $r->print("
                    600:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    601:                  <td><input type=\"checkbox\" name=\"cross_$i\" checked=\"true\"/></td>
                    602:                  <td>$xl</td>
                    603:                  <td><input type =\"text\" size=\"10\" name=\"gp_$i\" value=\"$gp\"></td>
                    604:                 </tr> 
                    605:               ");
                    606:           }
                    607:           $r->print("  </table>
                    608:               </td>
                    609:              </tr>
                    610:             </table>
                    611:           ");
                    612:       }
                    613:       else {
                    614:           $r->print("
                    615:                 Currently no crosslisted courses are recorded for $enrollvar{coursecode}.
                    616:               </td>
                    617:              </tr>
                    618:             </table>
                    619:           ");
                    620:       }
                    621:       $r->print("   
                    622:             <br/>
                    623:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    624:              <tr>
                    625:               <td align=\"left\">
                    626:                <b>Add new crosslistings.</b><br/>
                    627:                Number of new crosslistings to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numcross\" value=\"0\" />
                    628:               </td>
                    629:              </tr>
                    630:             </table>
                    631:             <br/>
                    632:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    633:              <tr>
                    634:               <td align=\"right\">
                    635:                <input type=\"button\" name=\"crosslist\" value=\"Go\" onClick=\"process('crosslist')\" />
                    636:               </td>
                    637:              </tr>
                    638:             </table>
                    639:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    640:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    641:             </form> 
                    642:       ");
                    643:   } elsif ($action eq "sections") {
                    644:       my @sections = &localenroll::get_sections($enrollvar{coursecode});
                    645:       my @storedsections = ();
                    646:       my @currsections = ();
                    647:       my %sec_id = ();
                    648:       if ($enrollvar{sectionnums} =~ m/,/) {
                    649:           @storedsections = split/,/,$enrollvar{sectionnums};
                    650:       } else {
                    651:           $storedsections[0] = $enrollvar{sectionnums};
                    652:       }
                    653:       foreach (@storedsections) {
                    654:           if ($_ =~ m/^(\w+):(\w*)$/) {
                    655:               push @currsections, $1;
                    656:               $sec_id{$1} = $2;
                    657:           }
                    658:       }
                    659:       if (@sections > 0) {
1.8       raeburn   660:           my $secshow = @sections;
                    661:           $r->print("
1.1       raeburn   662:             <form name=\"enter\" method=\"post\"><br/>
                    663:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    664:              <tr>
                    665:               <td align=\"left\">
                    666:                <b>$$tasktitleref{$action}</b><br/>
                    667:                Your institution's course catalog includes $secshow sections for course code: $enrollvar{coursecode}.
                    668:               </td>
                    669:              </tr>
                    670:              <tr>
1.5       raeburn   671:               <td>For each section, check the checkbox if you want registered students in that section to be included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise uncheck it. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. To add a new section, check the 'Enrollment in this course?' checkbox, and enter the desired LON-CAPA section/groupID in the appropriate textbox. Click 'Go' to store
                    672: your changes.</td>
1.1       raeburn   673:              </tr>
                    674:             </table>
                    675:             <br/>
1.7       raeburn   676:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    677:              <tr bgcolor=\"#CCCCFF\">
                    678:               <td><b>Section</b></td>
                    679:               <td><b>Current status</b></td>              
                    680:               <td><b>LON-CAPA section/group ID</b></td>
                    681:               <td><b>Enrollment in this course?</b></td>
                    682:              </tr>
1.8       raeburn   683:           ");
                    684:           for (my $i=0; $i<@sections; $i++) {
                    685:               my $colflag = $i%2;
                    686:               my $shrflag = 0;
                    687:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.5       raeburn   688:                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" /></td>
1.1       raeburn   689:                    <td>
1.8       raeburn   690:               ");
                    691:               if (grep/^$sections[$i]$/,@currsections) {
                    692:                   $r->print("Enrollment active");
                    693:                   $shrflag = 1;
                    694:               } else {
                    695:                   $r->print("Enrollment inactive");
                    696:               }
                    697:               if ($shrflag) {
                    698:                   $r->print("</td><td><input type=\"text\" size=\"10\" name=\"loncapasec_$i\" value=\"$sec_id{$sections[$i]}\"></td><td><input type=\"checkbox\" name=\"sec_$i\" checked=\"true\" /></td></tr>"); 
                    699:               } else {
                    700:                   $r->print("</td><td><input type=\"text\" size=\"10\" name=\"loncapasec_$i\" value=\"\"><td><input type=\"checkbox\" name=\"sec_$i\" /></td></tr>");
1.1       raeburn   701:               }
1.8       raeburn   702:           }
                    703:           $r->print("
1.7       raeburn   704:             </table>
                    705:             <br/>
                    706:             <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
                    707:              <tr> 
                    708:               <td align=\"right\">
                    709:                <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />
                    710:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    711:               </td>
                    712:              </tr>
                    713:             </table>
                    714:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    715:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    716:             </form>
1.8       raeburn   717:           ");
1.1       raeburn   718:       } else {
                    719:           $r->print("
                    720:             <form name=\"enter\" method=\"post\"><br/>
                    721:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    722:              <tr>
                    723:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    724:           ");
                    725:           if (@currsections) {
                    726:               my $secshow = @currsections;
                    727:               $r->print("
1.7       raeburn   728:                 Currently, this LON-CAPA course incorporates enrollment from $secshow sections.  Students enrolling in any of these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update. For each section, uncheck the checkbox if you want registered students in that section to cease being included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise leave it checked. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID textbox and enter the new value.  If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes.
1.1       raeburn   729:               </td>
                    730:              </tr>
                    731:             </table>
                    732:             <br/>
                    733:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    734:              <tr>
                    735:               <td>
                    736:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    737:                 <tr bgcolor=\"#CCCCFF\">
                    738:                  <td><b>Enrollment?</b></td>
                    739:                  <td><b>Section</b></td>
                    740:                  <td><b>LON-CAPA section/groupID</b></td>
                    741:                 </tr>
                    742:               ");
                    743:               for (my $j=0; $j<@currsections; $j++) {
                    744:                   my $colflag = $j%2;
                    745:                   $r->print("
                    746:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    747:                  <td><input type=\"checkbox\" name=\"sec_$j\" checked=\"true\"/></td>
                    748:                  <td>$currsections[$j]</td>
                    749:                  <td><input type=\"text\" name=\"secgp_$j\" size=\"10\" value=\"$sec_id{$currsections[$j]}\"></td>
                    750:                 </tr> 
                    751:                   ");
                    752:               }
                    753:               $r->print("  </table>
                    754:               </td>
                    755:              </tr>
                    756:             </table>
                    757:               ");
                    758:           } else {
                    759:               $r->print("
                    760:                 Currently no sections of $realm ($enrollvar{coursecode}) are contributing enrollment to the LON-CAPA class roster.
                    761:               </td>
                    762:              </tr>
                    763:             </table>
                    764:               ");
                    765:           }
                    766:           $r->print("   
                    767:             <br/>
                    768:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    769:              <tr>
                    770:               <td align=\"left\">
                    771:                <b>Add enrollment from additional sections.</b><br/>
                    772:                Number of new sections to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numsec\" value=\"0\" />
                    773:               </td>
                    774:              </tr>
                    775:             </table>
                    776:             <br/>
                    777:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    778:              <tr>
                    779:               <td align=\"right\">
                    780:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    781:               </td>
                    782:              </tr>
                    783:             </table>
                    784:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    785:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    786:             </form> 
                    787:           ");
                    788:       }
                    789:   } elsif ($action eq "photos") {
                    790:       my @photosets = ("OFF","ON");
                    791:       $r->print("
                    792:                   <form name=\"enter\" method=\"post\"><br/>
                    793:                   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    794:                    <tr>
                    795:                     <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    796:                        Currently: Student photo import:  <i>$photosets[$enrollvar{showphotos}]</i>
                    797:                     </td>
                    798:                    </tr>
                    799:                   </table>
                    800:                   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    801:                     <tr>
                    802:                      <td>
                    803:                          Automatic import of student photos from institutional data repository:&nbsp;&nbsp;
                    804: 
                    805:       ");
                    806:       if ($enrollvar{showphotos}) {
                    807:           $r->print("
                    808:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    809:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" />&nbsp;No
                    810:           ");
                    811:       } else {
                    812:           $r->print("
                    813:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    814:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" checked=\"true\" />&nbsp;No
                    815:           ");
                    816:       }
                    817:       $r->print("
                    818:                      </td>
                    819:                     </tr>
                    820:                     <tr>
                    821:                      <td>
                    822:                       <font color=\"#888888\">
                    823: Note: if you enable automatic import of student photos, your course will automatically have access to photos stored by your institution for all officially registered students, via a conduit established by your LON-CAPA domain coordinator.  
                    824:                       </font>
                    825:                      </td>
                    826:                     </tr>
                    827:                     <tr>
                    828:                      </td>&nbsp;</td>
                    829:                     </tr>
                    830:                     <tr>
                    831:                      <td align=\"right\">
                    832:                       <input type=\"button\" name=\"showphotos\" value=\"Go\" onClick=\"process('photos')\">
                    833:                      </td>
                    834:                     </tr>
                    835:                    </table>
                    836:                    <input type=\"hidden\" name=\"action\" value=\"$action\">
                    837:                    <input type=\"hidden\" name=\"state\" value=\"process\">
                    838:                    </form>
                    839:       ");
                    840:   } elsif ($action eq "updatenow") {
                    841:       $r->print("
                    842:                    <form name=\"enter\" method=\"post\"><br/>
                    843: 		   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    844: 		    <tr>
                    845: 		     <td align=\"left\"><b>$$tasktitleref{$action}</b>
                    846: 		     </td>
                    847:                     </tr>
                    848: 		   </table>
                    849: 		   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    850: 		    <tr>
                    851: 		     <td>
                    852: 	              Add any students currently included in institutional classlist(s) but not enrolled in your LON-CAPA course. 
                    853: 		      <input type=\"radio\" name=\"updateadds\" value=\"1\">&nbsp;Yes&nbsp;
                    854: 		      <input type=\"radio\" name=\"updateadds\" value=\"0\">&nbsp;No&nbsp;
                    855:                      </td>
                    856:                     </tr>
                    857:                     <tr>
                    858:                      <td>
                    859:  	              Expire students previously added by nightly enrollment process, but no longer listed in institutional  classlist(s).                  
                    860:                 <input type=\"radio\" name=\"updatedrops\" value=\"1\">&nbsp;Yes&nbsp;
                    861:                 <input type=\"radio\" name=\"updatedrops\" value=\"0\">&nbsp;No&nbsp;<br/>
                    862:               </td>
                    863:              </tr>
                    864:              <tr>
                    865:               <td>
                    866:                <font color=\"#888888\">
                    867: Note: Any students previously added manually by course coordinator(s) using either 'Upload classlist CSV file' or 'Enroll a single user' will be unaffected by the removal process.
                    868:                </font>
                    869:               </td>
                    870:              </tr>
                    871:              <tr>
                    872:               <td align=\"right\">
                    873:                <input type=\"button\" name=\"updatenow\" value=\"Go\" onClick=\"process('updatenow')\">
                    874:               </td>
                    875:              </tr>
                    876: 	    </table>
                    877:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    878:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    879:             </form>
                    880:       ");
                    881:   }
                    882: }
                    883: 
                    884: ###############################################################
                    885: sub print_doc_base {
                    886:   my $r = shift;
                    887:   $r->print(<<ENDBASE);
                    888:   </td>
                    889:  </tr>
                    890: </table>
                    891: <br/>
                    892: </body>
                    893: </html> 
                    894: ENDBASE
                    895: }
                    896:  
                    897: ###################################################################
                    898: sub print_chgsettings_response {
                    899:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.10      raeburn   900:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
                    901:   my $currend = '';
                    902:   my $currstart = '';
                    903:   my $currsecs = '';
                    904:   my $currxlists = '';
                    905:   my $curradds = '';
                    906:   my $currdrops = '';
                    907:   if ( defined($settings{'internal.autoadds'}) ) {
                    908:       $curradds = $settings{'internal.autoadds'};
                    909:   }
                    910:   if ( defined($settings{'internal.autodrops'}) ) {
                    911:       $currdrops = $settings{'internal.autodrops'};
                    912:   }
                    913:   if ( defined($settings{'internal.autostart'}) ) {
                    914:       $currstart = $settings{'internal.autostart'};
                    915:   }
                    916:   if ( defined($settings{'internal.autoend'}) ) {
                    917:       $currend = $settings{'internal.autoend'};
                    918:   }
                    919:   if ( defined($settings{'internal.sectionnums'}) ) {
                    920:       $currsecs = $settings{'internal.sectionnums'};
                    921:   }
                    922:   if ( defined($settings{'internal.crosslistings'}) ) {
                    923:       $currxlists = $settings{'internal.crosslistings'}
                    924:   }
1.1       raeburn   925:   my $autoadds = '';
                    926:   my $autodrops = '';
                    927: 
                    928:   if ( exists($ENV{'form.autoadds'}) ) {
                    929:       $autoadds=$ENV{'form.autoadds'};
                    930:   }
                    931:   if ( exists($ENV{'form.autodrops'}) ) {
                    932:       $autodrops=$ENV{'form.autodrops'};
                    933:   }
                    934: 
                    935:   my $response = "";
1.10      raeburn   936:   my $warning = "";
                    937:   my $warn_prefix = "";
                    938:   my $warn_suffix = "";
                    939:   my $warnfiller = "";
1.1       raeburn   940:   my %cenv = ('internal.autoadds' => $autoadds,
                    941:               'internal.autodrops' => $autodrops);
                    942:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                    943:   if ($reply !~ /^ok$/) {
                    944:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                    945:   } else {
                    946:       if ($autoadds) {
                    947:           if ($curradds) {
                    948:               $response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
                    949:           } else {
                    950:               $response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
1.10      raeburn   951:           }
1.1       raeburn   952:       } else {
                    953:           if ($curradds) {
                    954:               $response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
                    955:           } else {
                    956:               $response = "Nightly additions based on classlist changes still <b>disabled</b><br/>";
                    957:           }
                    958:       }
                    959:       if ($autodrops) {
                    960:           if ($currdrops) {
                    961:               $response .= "Nightly removals based on classlist changes still <b>enabled</b><br>";
                    962:           } else {
                    963:               $response .= "Nightly removals based on classlist changes now <b>enabled</b><br/>";
                    964:           }
                    965:       } else {
                    966:           if ($currdrops) {
                    967:               $response .= "Nightly removals based on classlist changes now <b>disabled</b><br>";
                    968:           } else {
                    969:               $response .= "Nightly removals based on classlist changes still <b>disabled</b>";
                    970:           }
                    971:       }
1.10      raeburn   972:       if ($autoadds || $autodrops) {
                    973:           $warning = &warning_message($dom,$crs,$action);
                    974:           $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you indicated that nightly ";
                    975:           $warn_suffix = " should be enabled, additional action is required.<br/>";
                    976:       }
                    977:       if ($autoadds) {
                    978:           if ($autodrops) {
                    979:               $warnfiller = "adds and drops";
                    980:           } else {
                    981:               $warnfiller = "adds";
                    982:           }
                    983:       } else {
                    984:           if ($autodrops) {
                    985:               $warnfiller = "drops";
                    986:           }
                    987:       }
                    988:       unless ($warning eq '') {
                    989:           $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
                    990:       }
1.1       raeburn   991:   }
                    992:   &print_reply($r,$response,$$tasktitleref{$action});
                    993:   return;
                    994: }
                    995: 
                    996: sub print_setdates_response {
                    997:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                    998:   my %settings = &Apache::lonnet::get('environment',['internal.autostart','internal.autoend'],$dom,$crs);
                    999:   my $currstart = $settings{'internal.autostart'};
                   1000:   my $currend = $settings{'internal.autoend'};
                   1001:   my $response = '';
                   1002:   my ($autostart,$autoend) = &get_dates_from_form();
                   1003:   my $showstart = localtime($autostart);
                   1004:   my $showend = '';
1.10      raeburn  1005:   my $warning = '';
                   1006:   my $warn_prefix = '';
1.1       raeburn  1007:   if ($autoend) {
                   1008:       $showend = localtime($autoend);
                   1009:   } else {
                   1010:       $showend = "'No end date'";
                   1011:   } 
                   1012: 
                   1013:   my %cenv = ('internal.autostart' => $autostart,
                   1014:               'internal.autoend' => $autoend);
                   1015:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1016:   if ($reply !~ /^ok$/) {
                   1017:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1018:   } else {
                   1019:       if ($currstart == $autostart) {
                   1020:           $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
                   1021:       } else {
                   1022:           $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
                   1023:       } 
                   1024:       if ($currend == $autoend) {
                   1025:           $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
                   1026:       } else {
1.9       raeburn  1027:           $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
1.1       raeburn  1028:       }
                   1029:  
                   1030: # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.
                   1031: 
                   1032:       my $rosterupdated = 0;
                   1033:       my $firstaccess = "";
                   1034:       my $nextupdate = "";
                   1035:       my $lastupdate = "";
                   1036: 
                   1037:       my $nowstamp = time;
                   1038:       my @date_list=localtime(time);
                   1039:       my $cur_year = $date_list[5];
                   1040:       my $curday = $date_list[3];
                   1041:       my $curmonth = $date_list[4];
                   1042:       my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1043:       my $nextmidnt = 86400 + $lastmidnt;
                   1044: 
1.10      raeburn  1045:       my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
1.1       raeburn  1046:       my $lastupdate = $todayupdate - 86400;
                   1047:       if ($nowstamp < $todayupdate) {
                   1048:           $nextupdate = "today";
                   1049:       } else {
                   1050:           $nextupdate = "tomorrow";
                   1051:       }
                   1052:       if ($currstart < $lastupdate) {
                   1053:           $rosterupdated = 1;
                   1054:       }
                   1055:       if ($autostart < $nextmidnt ) {
                   1056:           if ( $autostart >= $lastmidnt) {
                   1057:               $firstaccess = "today";
                   1058:           } else {
                   1059:               $firstaccess = "a date prior to today";
                   1060:           }
                   1061:           if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
1.10      raeburn  1062:               $response .= qq|<br>Although you have now set the first enrollment date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses at 1.30 am $nextupdate. If you wish to grant immediate course access for registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;
1.1       raeburn  1063:           }
                   1064:       }
1.10      raeburn  1065:       $warning = &warning_message($dom,$crs,$action);
                   1066:       $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you set a start and end date for auto-enrollment, additional action is required.<br/>";
                   1067:       unless ($warning eq '') {
                   1068:           $response .= $warn_prefix.$warning;
                   1069:       }
1.1       raeburn  1070:   }
                   1071:   &print_reply($r,$response,$$tasktitleref{$action});
                   1072:   return;
                   1073: }
                   1074: 
                   1075: sub print_notify_response {
                   1076:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1077: 
                   1078: # Get current settings
                   1079:   my %settings = &Apache::lonnet::get('environment',['internal.notifylist','internal.coursecode'],$dom,$crs);
                   1080:   my $notifylist = $settings{'internal.notifylist'};
                   1081:   my $coursecode = $settings{'internal.coursecode'};
                   1082:   my @currpeople = ();
                   1083:   my $notify = 0;
                   1084:   my @people = ();
1.7       raeburn  1085:   my $peoplestr = "";
                   1086:   my $response = "";
                   1087:   my $noprocess = 0;
1.1       raeburn  1088: 
                   1089:   if ($notifylist =~ m/,/) {
                   1090:       @currpeople = split/,/,$notifylist;
                   1091:   } else {
1.7       raeburn  1092:       $currpeople[0] = $notifylist;
1.1       raeburn  1093:   }
                   1094:   my $currcount = 0;
                   1095:   foreach  (@currpeople) {
                   1096:       unless ($_ eq '') { $currcount ++; } 
                   1097:   }
                   1098: 
                   1099:   if ( exists($ENV{'form.notify'}) ) {
                   1100:       $notify=$ENV{'form.notify'};
                   1101:   }
1.7       raeburn  1102:   if ( exists($ENV{'form.notifyshow'}) ) {
                   1103:       my $notifyshow = $ENV{'form.notifyshow'};
                   1104:       for (my $i=0; $i<$notifyshow; $i++) {
                   1105:           if ( exists($ENV{"form.note_$i"}) ) {
                   1106:               if ( exists($ENV{"form.notifyname_$i"}) ) {
                   1107:                   unless ( $ENV{"form.notifyname_$i"} eq '' ) {
                   1108:                       push @people, $ENV{"form.notifyname_$i"};
                   1109:                   }
                   1110:               }
                   1111:           }
                   1112:       }
                   1113:       if ($notify) { $peoplestr = join(",",@people); }
1.1       raeburn  1114:   } else {
                   1115:       if ($notify) {
1.7       raeburn  1116:           if ($currcount) {
                   1117:               $response = "There was a problem retrieving the updated list of recipients of notification messages. The notification settings for this course have been left unchanged.<br/>.";
                   1118:               $peoplestr = $notifylist;
                   1119:               @people = @currpeople;
                   1120:               $noprocess = 1;
                   1121:           }
                   1122:       }
                   1123:   }
                   1124:   unless ($noprocess == 1) {
                   1125:       my %cenv = ('internal.notifylist' => $peoplestr);
                   1126:       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1127:       if ($reply !~ /^ok$/) {
                   1128:            $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
                   1129:       } else {
                   1130:           if ($notify) {
                   1131:               if (@people) {
                   1132:                   if ($currcount) {
                   1133:                       $response .= "Notification of enrollment changes still <b>enabled</b><br/>";
                   1134:                   } else {
                   1135:                       $response .= "Notification of enrollment changes now <b>enabled</b><br/>";
                   1136:                   }
                   1137:                   $response .= "<br/>The following will receive notification if there are any changes in enrollment in LON-CAPA course: $realm ($coursecode) as a result of the nightly enrollment check: <br/><ul>\n";
                   1138:                   foreach my $person (@people) {
                   1139:                       $response .= "<li>$person</li>\n";
                   1140:                   }
                   1141:                   $response .= "</ul>\n";
                   1142:               } else {
                   1143:                   $response = "Notification of enrollment changes was <b> not enabled</b> as no course coordinators were selected as recipients.<br/>";
                   1144:               }
                   1145:           } else {
1.1       raeburn  1146:               if ($currcount) {
1.7       raeburn  1147:                   $response = "Notification of enrollment changes now <b>disabled</b><br/>";
1.1       raeburn  1148:               } else {
1.7       raeburn  1149:                   $response = "Notification of enrollment changes still <b>disabled</b><br/>";
1.1       raeburn  1150:               }
                   1151:           }
                   1152:       }
                   1153:   }
                   1154:   &print_reply($r,$response,$$tasktitleref{$action});
                   1155:   return;
                   1156: }
                   1157: 
                   1158: sub print_crosslistings_menu () {
                   1159:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1160:   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
                   1161:   my @currxlists = ();
                   1162:   my @xlists = ();
                   1163:   my $crosscount = 0;
                   1164:   my $removecount = 0;
                   1165:   my $xliststr = '';
                   1166:   my $response = '';
                   1167:   my $coursecode = $settings{'internal.coursecode'};
                   1168:   if ($settings{'internal.crosslistings'} =~ m/,/) {
                   1169:       @currxlists = split/,/,$settings{'internal.crosslistings'};
                   1170:   } elsif ($settings{'internal.crosslistings'} ne '') {
                   1171:       $currxlists[0] = $settings{'internal.crosslistings'};
                   1172:   }
                   1173: 
                   1174:   if (@currxlists > 0) {
                   1175:       for (my $i=0; $i<@currxlists; $i++) {
                   1176:           my $xlist = "cross_".$i;
                   1177:           my $gp = "gp_".$i;
                   1178:           if ( exists($ENV{"form.$xlist"}) ) {
                   1179:               my $xlistentry = '';
                   1180:               if ($currxlists[$i] =~ m/^(\w+:)/) {
                   1181:                   $xlistentry = $1;
                   1182:               }
                   1183:               if ( exists($ENV{"form.$gp"}) ) {
                   1184:                   $xlistentry .= $ENV{"form.$gp"};
                   1185:               }
                   1186:               push @xlists,$xlistentry;
                   1187:               $crosscount ++;
                   1188:           } else {
                   1189:               $removecount ++;
                   1190:           }
                   1191:       }
                   1192:   }
                   1193: 
                   1194:   if ($crosscount > 1) {
                   1195:       $xliststr = join(",",@xlists);
                   1196:   } else {
                   1197:       $xliststr = $xlists[0];
                   1198:   }
                   1199:   my %cenv = ('internal.crosslistings' => $xliststr);
                   1200:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1201:   if ($reply !~ /^ok$/) {
                   1202:       $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1203:   } else {
                   1204:       if ($removecount > 0) {
1.5       raeburn  1205:           $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.1       raeburn  1206:       }
                   1207:       if ($crosscount > 0) {
                   1208:           $response .=  "The $crosscount courses listed below remain crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.<br/><ul>\n";
                   1209:           foreach (@xlists) {
                   1210:               my ($xlist,$gp) = split/:/,$_;
                   1211:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1212:           }
                   1213:           $response .= "</ul><br/>\n";
                   1214:       }
                   1215:   }
                   1216:   if ( exists($ENV{'form.numcross'}) ) {
                   1217:       my $numcross = $ENV{'form.numcross'};
                   1218:       if ($numcross > 0) {
                   1219:           my @bgcolors=("#eeeeee","#cccccc");
                   1220:           $response .= qq(
                   1221:            You indicated that you wish to add an additional $numcross crosslisting(s).  For each new crosslisting enter the insititutional course section code (e.g., fs03zol101001, for section 001 of zol101 for fs03 semester), and the LON-CAPA section/group ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in the crosslisted course section. The LON-CAPA section/group ID can be left blank, if you do not wish to tie a section/group ID to this crosslisting.  The institutional course section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course codes (and section numbers) to your institution's student information system.<br/><br/>
                   1222:            <form name="enter" method="post">
                   1223:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1224:              <tr>
                   1225:               <td>
                   1226:                <table border="0" cellspacing="3" cellpadding="3">
                   1227:                 <tr bgcolor="#CCCCFF" align="left">
                   1228:                  <td><b>Crosslisting</b></td>
                   1229:                  <td><b>LON-CAPA section/groupID</b></td>
                   1230:                 </tr>
                   1231:           );
                   1232:           for (my $i=0; $i<$numcross; $i++) {
                   1233:               my $colflag = $i%2;
                   1234:               $response .= qq(
                   1235:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1236:                  <td><input type="text" size="15" name="newcross_$i" /></td>
                   1237:                  <td><input type="text" size="10" name="newgroupid_$i" /></td>
                   1238:                 </tr>
                   1239:               );
                   1240:           }
                   1241:           $response .= qq(  </table>
                   1242:               </td>
                   1243:              </tr>
                   1244:              <tr>
                   1245:               <td align="right">
                   1246:                <input type="button" name="newcross" value="Go" onClick="process('newcross')" />
                   1247:               </td>
                   1248:              </tr>
                   1249:             </table>
                   1250:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\">
                   1251:             <input type=\"hidden\" name=\"action\" value=\"newcross\">
                   1252:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1253:             </form>
                   1254:           );
                   1255:       }
                   1256:   }
                   1257:   &print_reply($r,$response,$$tasktitleref{$action});
                   1258:   return;
                   1259: }
                   1260: 
                   1261: sub print_crosslistings_response () {
                   1262:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.5       raeburn  1263:   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1264:   my @currxlists = ();
                   1265:   my @xlists = ();
                   1266:   my @allxlists = ();
1.5       raeburn  1267:   my @badxlists = ();
                   1268:   my @badowner = ();
1.1       raeburn  1269:   my $numcross = 0;
                   1270:   my $xliststr =  $settings{'internal.crosslistings'};
                   1271:   my $coursecode = $settings{'internal.coursecode'};
1.5       raeburn  1272:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1273:   my $response = '';
1.10      raeburn  1274:   my $warning = '';
                   1275:   my $warn_prefix = '';
1.1       raeburn  1276: 
                   1277:   if ($xliststr =~ m/,/) {
                   1278:       @allxlists = split/,/,$xliststr;
                   1279:   } else {
                   1280:       unless ($xliststr eq '') { $allxlists[0] = $xliststr; }
                   1281:   }
                   1282: 
                   1283:   if ( exists($ENV{'form.numcross'}) ) {
                   1284:       $numcross = $ENV{'form.numcross'};
                   1285:   }
                   1286: 
                   1287:   if ($numcross > 0) {
                   1288:       for (my $i=0; $i<$numcross; $i++) {
                   1289:           my $xl = "newcross_".$i;
                   1290:           my $gp = "newgroupid_".$i;
                   1291:           if ( exists($ENV{"form.$xl"}) ) {
1.5       raeburn  1292:               my $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"});
                   1293:               if ($coursecheck eq 'ok') {
                   1294:                   my $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner);
                   1295:                   if ($addcheck eq 'ok') {
                   1296:                      push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                   1297:                   } else {
                   1298:                      push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                   1299:                   } 
                   1300:               } else {
1.6       raeburn  1301:                   push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck;
1.5       raeburn  1302:               }
1.1       raeburn  1303:           }
                   1304:       }
                   1305:       push @allxlists, @xlists;
                   1306:   }
                   1307: 
                   1308:   if (@xlists > 0 ) {
                   1309:       unless ($xliststr eq '') { $xliststr .= ","; }
                   1310:       if (@xlists > 1) {
                   1311:           $xliststr .= join(",",@xlists);
                   1312:       } else {
                   1313:           $xliststr .= $xlists[0];
                   1314:       }
                   1315:       my %cenv = ('internal.crosslistings' => $xliststr);
                   1316:       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1317:       if ($reply !~ /^ok$/) {
1.6       raeburn  1318:           $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
1.1       raeburn  1319:       } else {
                   1320:           $response = "The courses listed below are now crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.<br/><ul>\n";
1.6       raeburn  1321:           foreach (@allxlists) {
                   1322:               my ($xlist,$gp) = split/:/,$_;
                   1323:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1324:           }
                   1325:           $response .= "</ul><br/><br/>\n";
                   1326:       }
                   1327:   } else {
                   1328:       if ($xliststr =~ m/:/) {
                   1329:           my @oldxlists = ();
                   1330:           if ($xliststr =~ m/,/) {
                   1331:               @oldxlists = split/,/,$xliststr;
                   1332:           } else {
                   1333:               $oldxlists[0] = $xliststr;
                   1334:           }
                   1335:           $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1336:           foreach (@oldxlists) {
                   1337:               my ($xlist,$gp) = split/:/,$_;
                   1338:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1339:           }
                   1340:           $response .= "</ul><br/><br/>\n";
1.1       raeburn  1341:       }
                   1342:   }
1.5       raeburn  1343:   if (@badxlists > 0) {
                   1344:       $response .= "The courses listed below could not be included in the crosslistings for this LON-CAPA course, because they are not valid courses according to your institution's official schedule of classes and sections.<br/><ul>\n";
                   1345:       foreach (@badxlists) {
1.6       raeburn  1346:           my ($xlist,$gp,$prob) = split/:/,$_;
                   1347:           $response .= "<li>$xlist - ID: $gp - Error: $prob</li>\n";
1.5       raeburn  1348:       }
                   1349:       $response .= "</ul><br/><br/>\n";
                   1350:   }
                   1351: 
                   1352:   if (@badowner > 0) {
                   1353:       $response .= "The courses listed below could not be included in the crosslistings for this LON-CAPA course, because the owner of this course - $owner - does not have rights to view enrollment in those classes as determined by your instititution's policies on access to official classlists.<br/><ul>\n";
                   1354:       foreach (@badowner) {
                   1355:           my ($xlist,$gp) = split/:/,$_;
                   1356:           $response .= "<li>$xlist - ID: $gp</li>\n";
                   1357:       }
                   1358:       $response .= "</ul><br/><br/>\n";
                   1359:   }
1.1       raeburn  1360: 
1.10      raeburn  1361:   if (@allxlists > 0) {
                   1362:       $warning = &warning_message($dom,$crs,$action);
                   1363:       $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected crosslisted courses to contribute enrollment to this course, additional action is required.<br/>";
                   1364:       unless ($warning eq '') {
                   1365:           $response .= $warn_prefix.$warning;
                   1366:       }
                   1367:   }
                   1368: 
1.1       raeburn  1369:   &print_reply($r,$response,$$tasktitleref{$action});
                   1370:   return;
                   1371: }
                   1372: 
                   1373: sub print_sections_menu () {
                   1374:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.8       raeburn  1375:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1376:   my @currsections = ();
                   1377:   my @sections = ();
1.8       raeburn  1378:   my @badowner = ();
                   1379:   my @badsections = ();
1.1       raeburn  1380:   my $seccount = 0;
                   1381:   my $removecount = 0;
1.6       raeburn  1382:   my $addcount = 0;
1.1       raeburn  1383:   my $secstr = '';
                   1384:   my $response = '';
1.10      raeburn  1385:   my $warning = "";
                   1386:   my $warn_prefix = "";
1.1       raeburn  1387:   my $coursecode = $settings{'internal.coursecode'};
1.8       raeburn  1388:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1389:   if ($settings{'internal.sectionnums'} =~ m/,/) {
                   1390:       @currsections = split/,/,$settings{'internal.sectionnums'};
                   1391:   } elsif ($settings{'internal.sectionnums'} ne '') {
                   1392:       $currsections[0] = $settings{'internal.sectionnums'};
                   1393:   }
1.6       raeburn  1394: 
                   1395:   if ( exists($ENV{'form.secshow'}) ) {
1.8       raeburn  1396:       for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
                   1397:           my $gp = "loncapasec_".$i;
                   1398:           my $secnum = "secnum_".$i;
                   1399:           my $sec = "sec_".$i;
                   1400:           if ( exists( $ENV{"form.$sec"} ) ) {
                   1401:               my $secentry;
                   1402:               if ( exists( $ENV{"form.$secnum"} ) ) { 
                   1403:                   $secentry = $ENV{"form.$secnum"}.':';
                   1404:               }
                   1405:               if ( exists( $ENV{"form.$gp"} ) ) {
                   1406:                   $secentry .= $ENV{"form.$gp"};
                   1407:               }
                   1408:               if ( grep/^$ENV{"form.$secnum"}:/,@currsections) {
                   1409:                   push @sections, $secentry;
                   1410:                   $seccount ++;
                   1411:               } else {
                   1412:                   my $newsec = $coursecode.$ENV{"form.$secnum"};
                   1413:                   my $coursecheck = &localenroll::validate_courseID($newsec);
                   1414:                   if ($coursecheck eq 'ok') {
                   1415:                       my $addcheck = &localenroll::new_course($newsec,$owner);
                   1416:                       if ($addcheck eq 'ok') {
                   1417:                           push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                   1418:                           $seccount ++;
                   1419:                           $addcount ++;
                   1420:                       } else {
                   1421:                           push @badowner,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                   1422:                       }
                   1423:                   } else {
                   1424:                       push @badsections, $ENV{"form.$secnum"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                   1425:                   }
                   1426:               }
                   1427:           }
                   1428:       }
                   1429:       if (@currsections > 0) {
                   1430:           for (my $i=0; $i<@currsections; $i++) {
                   1431:               if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   1432:                   my $oldsec  = $1;
                   1433:                   unless (grep/^$oldsec/,@sections) {
                   1434:                       $removecount ++;
                   1435:                   }
                   1436:               }
                   1437:           }
                   1438:       }
1.6       raeburn  1439:   } elsif (@currsections > 0) {
1.1       raeburn  1440:       for (my $i=0; $i<@currsections; $i++) {
                   1441:           my $sec = "sec_".$i;
                   1442:           my $gp = "secgp_".$i;
                   1443:           if ( exists($ENV{"form.$sec"}) ) {
                   1444:               my $secentry = '';
1.6       raeburn  1445:               if ($currsections[$i] =~ m/^(\w+:)/ ) {
1.1       raeburn  1446:                   $secentry = $1;
                   1447:               }
                   1448:               if ( exists($ENV{"form.$gp"}) ) {
                   1449:                   $secentry .= $ENV{"form.$gp"};
                   1450:               }
                   1451:               push @sections,$secentry;
                   1452:               $seccount ++;
                   1453:           } else {
                   1454:               $removecount ++;
                   1455:           }
                   1456:       }
                   1457:   }
                   1458:                                                                                                      
                   1459:   if ($seccount > 1) {
                   1460:       $secstr = join(",",@sections);
                   1461:   } else {
                   1462:       $secstr = $sections[0];
                   1463:   }
                   1464:   my %cenv = ('internal.sectionnums' => $secstr);
                   1465:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1466:   if ($reply !~ /^ok$/) {
                   1467:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1468:   } else {
                   1469:       if ($removecount > 0) {
                   1470:           $response = "A total of $removecount sections have been removed from the list of sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
                   1471:       }
1.6       raeburn  1472:       if ($addcount > 0) {
                   1473:           $response .= "A total of $addcount sections have been added to the list of
                   1474: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
                   1475:       }
1.1       raeburn  1476:       if ($seccount > 0) { 
1.6       raeburn  1477:           $response .= "Students enrolling in the $seccount section(s) listed below will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.<br/><ul>\n";
1.1       raeburn  1478:           foreach (@sections) {
                   1479:               my ($sec,$gp) = split/:/,$_;
                   1480:               $response .= "<li>$sec  - ID: $gp</li>\n";
                   1481:           }
                   1482:           $response .= "</ul><br/>\n";
                   1483:       }
                   1484:   }
                   1485: 
1.8       raeburn  1486:   if (@badsections > 0) {
                   1487:       $response .= "The sections listed below could not be included in the sections for this LON-CAPA course, because they are not valid section numbers according to your institution's official schedule of classes and sections.<br/><ul>\n";
                   1488:       foreach (@badsections) {
                   1489:           my ($secnum,$gp,$prob) = split/:/,$_;
                   1490:           $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
                   1491:       }
                   1492:       $response .= "</ul><br/><br/>\n";
                   1493:   }
                   1494: 
                   1495:   if (@badowner > 0) {
                   1496:       $response .= "The sections listed below could not be included in the sections for this LON-CAPA course, because the owner of this course - $owner - does not have rights to view enrollment in those classes as determined by your instititution's policies on access to official classlists.<br/><ul>\n";
                   1497:       foreach (@badowner) {
                   1498:           my ($secnum,$gp) = split/:/,$_;
                   1499:           $response .= "<li>$secnum - ID: $gp</li>\n";
                   1500:       }
                   1501:       $response .= "</ul><br/><br/>\n";
                   1502:   }
                   1503: 
1.10      raeburn  1504:   if ($seccount > 0) {
                   1505:       $warning = &warning_message($dom,$crs,$action);
                   1506:       $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected sections to contribute enrollment to this course, additional action is required.<br/>";
                   1507:       unless ($warning eq '') {
                   1508:           $response .= $warn_prefix.$warning;
                   1509:       }
                   1510:   }
                   1511: 
1.1       raeburn  1512:   if ( exists($ENV{'form.numsec'}) ) {
                   1513:       my $numsec = $ENV{'form.numsec'};
                   1514:       if ($numsec > 0) {
                   1515:           my @bgcolors=("#eeeeee","#cccccc");
                   1516:           $response .= qq(
                   1517:            You indicated that you wish to incorporate student enrollment in your LON-CAPA course from an additional $numsec section(s).  For each new section enter the insititutional section code (e.g., 004), and the LON-CAPA section/group ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in this particular section. The LON-CAPA section/group ID can be left blank, if you do not wish to designate a section/group ID for this course section.  The institutional section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course section numbers to your institution's student information system.<br/><br/> 
                   1518:            <form name="enter" method="post">
                   1519:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1520:              <tr>
                   1521:               <td>
                   1522:                <table border="0" cellspacing="3" cellpadding="3">
                   1523:                 <tr bgcolor="#CCCCFF" align="left">
                   1524:                  <td><b>Section number</b></td>
                   1525:                  <td><b>LON-CAPA section/groupID</b></td>
                   1526:                 </tr>
                   1527:           );
                   1528:           for (my $i=0; $i<$numsec; $i++) {
                   1529:               my $colflag = $i%2;
                   1530:               $response .= qq(
                   1531:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1532:                  <td><input type="text" size="15" name="newsec_$i" /></td>
                   1533:                  <td><input type="text" size="10" name="newsecgp_$i" /></td>
                   1534:                 </tr>
                   1535:               );
                   1536:           }
                   1537:           $response .= qq(  </table>
                   1538:               </td>
                   1539:              </tr>
                   1540:              <tr>
                   1541:               <td align="right">
                   1542:                <input type="button" name="newsections" value="Go" onClick="process('newsections')" />
                   1543:               </td>
                   1544:              </tr>
                   1545:             </table>
                   1546:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\">
                   1547:             <input type=\"hidden\" name=\"action\" value=\"newsections\">
                   1548:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1549:             </form>
                   1550:           );
                   1551:       }
                   1552:   }
                   1553:   &print_reply($r,$response,$$tasktitleref{$action});
                   1554:   return;
                   1555: }
                   1556: 
                   1557: sub print_sections_response () {
                   1558:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.8       raeburn  1559:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1560:   my @currsections = ();
                   1561:   my @sections = ();
                   1562:   my @allsections = ();
1.8       raeburn  1563:   my @badowner = ();
                   1564:   my @badsections = ();
1.1       raeburn  1565:   my $numsec = 0;
                   1566:   my $secstr =  $settings{'internal.sectionnums'};
                   1567:   my $coursecode = $settings{'internal.coursecode'};
1.8       raeburn  1568:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1569:   my $response = '';
1.8       raeburn  1570:   my $putreply = '';
1.10      raeburn  1571:   my $warning = '';
                   1572:   my $warn_prefix = '';
1.1       raeburn  1573:   if ($secstr =~ m/,/) {
                   1574:       @allsections = split/,/,$secstr;
                   1575:   } else {
                   1576:       unless ($secstr eq '') { $allsections[0] = $secstr; }
                   1577:   }
                   1578: 
                   1579:   if ( exists($ENV{'form.numsec'}) ) {
                   1580:       $numsec = $ENV{'form.numsec'};
                   1581:   }
1.8       raeburn  1582: 
1.1       raeburn  1583:   if ($numsec > 0) {
                   1584:       for (my $i=0; $i<$numsec; $i++) {
                   1585:           my $sec = "newsec_".$i;
                   1586:           my $gp = "newsecgp_".$i;
                   1587:           if ( exists($ENV{"form.$sec"}) ) {
1.8       raeburn  1588:               unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) {
                   1589:                   my $newsec = $coursecode.$ENV{"form.$sec"};
                   1590:                   my $coursecheck = &localenroll::validate_courseID($newsec);
                   1591:                   if ($coursecheck eq 'ok') {
                   1592:                       my $addcheck = &localenroll::new_course($newsec,$owner);
                   1593:                       if ($addcheck eq 'ok') {
                   1594:                           push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                   1595:                       } else {
                   1596:                           push @badowner,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                   1597:                       }
                   1598:                   } else {
                   1599:                       push @badsections, $ENV{"form.$sec"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                   1600:                   }
                   1601:               }
1.1       raeburn  1602:           }
                   1603:       }
                   1604:       push @allsections, @sections;
                   1605:   }
1.8       raeburn  1606: 
1.1       raeburn  1607:   if (@sections > 0 ) {
                   1608:       unless ($secstr eq '') { $secstr .= ","; } 
                   1609:       if (@sections > 1) {
                   1610:           $secstr .= join(",",@sections);
                   1611:       } else {
                   1612:           $secstr .= $sections[0];
                   1613:       }
                   1614:       my %cenv = ('internal.sectionnums' => $secstr);
1.8       raeburn  1615:       $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1616:       if ($putreply !~ /^ok$/) {
                   1617:           $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1618:       }
                   1619:   }
                   1620: 
                   1621:   if ($putreply =~ /^ok/) {
                   1622:       $response = "Students enrolling in the sections listed below will be automatically added to the class roster for LON-CAPA course $realm ($coursecode), if you have chosen to enable a nightly automated enrollment update.<br/><ul>\n";
                   1623:       foreach (@allsections) {
                   1624:           my ($sec,$gp) = split/:/,$_;
                   1625:           $response .= "<li>$sec - ID: $gp</li>\n";
                   1626:       }
                   1627:       $response .= "</ul><br/><br/>\n";
                   1628:   }
                   1629: 
                   1630:   if (@badsections > 0) {
                   1631:       $response .= "The sections listed below could not be included in the sections for this LON-CAPA course, because they are not valid section numbers according to your institution's official schedule of classes and sections.<br/><ul>\n";
                   1632:       foreach (@badsections) {
                   1633:           my ($secnum,$gp,$prob) = split/:/,$_;
                   1634:           $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
1.1       raeburn  1635:       }
1.8       raeburn  1636:       $response .= "</ul><br/><br/>\n";
1.1       raeburn  1637:   }
1.8       raeburn  1638: 
                   1639:   if (@badowner > 0) {
                   1640:       $response .= "The sections listed below could not be included in the sections for this LON-CAPA course, because the owner of this course - $owner - does not have rights to view enrollment in those classes as determined by your instititution's policies on access to official classlists.<br/><ul>\n";
                   1641:       foreach (@badowner) {
                   1642:           my ($secnum,$gp) = split/:/,$_;
                   1643:           $response .= "<li>$secnum - ID: $gp</li>\n";
                   1644:       }
                   1645:       $response .= "</ul><br/><br/>\n";
1.1       raeburn  1646:   }
1.8       raeburn  1647: 
1.10      raeburn  1648:   if (@allsections > 0) {
                   1649:       $warning = &warning_message($dom,$crs,$action);
                   1650:       $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected sections to contribute enrollment to this course, additional action is required.<br/>";
                   1651:       unless ($warning eq '') {
                   1652:           $response .= $warn_prefix.$warning;
                   1653:       }
                   1654:   }
                   1655: 
1.1       raeburn  1656:   &print_reply($r,$response,$$tasktitleref{$action});
                   1657:   return;
                   1658: }
                   1659: 
                   1660: sub print_photos_response () {
                   1661:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1662:   my %settings = &Apache::lonnet::get('environment',['internal.showphotos'],$dom,$crs);
                   1663:   my $currphotos = $settings{'internal.showphotos'};
                   1664:   my $showphotos = '';
                   1665:   if ( exists($ENV{'form.showphotos'}) ) {
                   1666:       $showphotos=$ENV{'form.showphotos'};
                   1667:   }
1.8       raeburn  1668: 
1.1       raeburn  1669:   my $response = "";
                   1670:   my %cenv = ('internal.showphotos' => $showphotos);
                   1671:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1672:   if ($reply !~ /^ok$/) {
                   1673:       $response = "There was a problem processing your requested change. The student photo import setting for this course has been left unchanged.<br/>";
                   1674:   } else {
                   1675:       if ($showphotos) {
                   1676:           if ($currphotos) {
                   1677:               $response = "Retrieval of student photos is still <b>enabled</b><br/>";
                   1678:           } else {
                   1679:               $response = "Retrieval of student photos in now <b>enabled</b><br/>";
                   1680:           }
                   1681:       } else {
                   1682:           if ($currphotos) {
                   1683:               $response = "Retrieval of student photos is now <b>disabled</b><br/>";
                   1684:           } else {
                   1685:               $response = "Retrieval of student photos is still <b>disabled</b><br/>";
                   1686:           }
                   1687:       }
                   1688:   }
                   1689:   &print_reply($r,$response,$$tasktitleref{$action});
                   1690:   return;
                   1691: }
                   1692: 
                   1693: sub print_update_result () {
                   1694:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1695:   my $response = '';
                   1696:   my $updateadds = 0;
                   1697:   my $updatedrops = 0;
                   1698:   my $changecount = 0;
                   1699:   my %affiliates = ();
                   1700:   my %reply = ();
                   1701:   my @allcourses = ();
                   1702:   my %LC_code = ();
                   1703:   my $logmsg = '';
1.5       raeburn  1704:   my $newusermsg = '';
1.1       raeburn  1705: 
                   1706:   my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.autostart','internal.autoend'],$dom,$crs);
                   1707:   my $coursecode = $settings{'internal.coursecode'};
                   1708:   my $authtype = $settings{'internal.authtype'};
                   1709:   my $autharg = $settings{'internal.autharg'};
                   1710:   my $autostart = $settings{'internal.autostart'};
                   1711:   my $autoend = $settings{'internal.autoend'};
                   1712:  
                   1713:   if ( exists($ENV{'form.updateadds'}) ) {
                   1714:       $updateadds = $ENV{'form.updateadds'};
                   1715:   }
                   1716:   if ( exists($ENV{'form.updatedrops'}) ) {
                   1717:       $updatedrops = $ENV{'form.updatedrops'};
                   1718:   }
                   1719:   if (!$updateadds && !$updatedrops) {
                   1720:       $response = "An update of the class roster has not been carried out because you indicated that you wanted to neither add new students, nor expire dropped students based on a comparison between the institutional class lists for the course sections and crosslisted courses that contribure enrollment to this LON-CAPA course.";
                   1721:   } elsif ($coursecode eq '') {
                   1722:       $response = "There was a problem retrieving the course code for this LON-CAPA course.  An update of the class roster has not been carried out, and enrollment remains unchanged";
                   1723:   } else {
                   1724: # Get complete list of course sections to update
                   1725:       my @currsections = ();
                   1726:       my @currxlists = ();
                   1727: 
                   1728:       if ($settings{'internal.sectionnums'} =~ m/,/) {
                   1729:           @currsections = split/,/,$settings{'internal.sectionnums'};
                   1730:       } elsif ($settings{'internal.sectionnums'} ne '') {
                   1731:           $currsections[0] = $settings{'internal.sectionnums'};
                   1732:       }
                   1733: 
                   1734:       if ($settings{'internal.crosslistings'} =~ m/,/) {
                   1735:           @currxlists = split/,/,$settings{'internal.crosslistings'};
                   1736:       } elsif ($settings{'internal.crosslistings'} ne '') {
                   1737:           $currxlists[0] = $settings{'internal.crosslistings'};
                   1738:       }
                   1739:                                                                                                      
                   1740:       if (@currxlists > 0) {
                   1741:           foreach (@currxlists) {
                   1742:               if (m/^(\w+):(\w*)$/) {
                   1743:                   unless (grep/^$1$/,@allcourses) { 
                   1744:                       push @allcourses,$1;
                   1745:                       $LC_code{$1} = $2; 
                   1746:                   }
                   1747:               }
                   1748:           }
                   1749:       }
                   1750: 
                   1751:       if (@currsections > 0) {
                   1752:           foreach (@currsections) {
                   1753:               if (m/^(\w+):(\w*)$/) {
                   1754:                   my $sec = $coursecode.$1;
                   1755:                   my $gp = $2;
                   1756:                   unless (grep/^$sec$/,@allcourses) { 
                   1757:                       push @allcourses,$sec;
                   1758:                       $LC_code{$sec} = $gp; 
                   1759:                   }
                   1760:               }
                   1761:           }
                   1762:       }
                   1763: 
                   1764:       if (@allcourses > 0) {
                   1765:           @{$affiliates{$crs}} = @allcourses;
                   1766:           &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
                   1767:           if ($reply{$crs} > 0) {
1.5       raeburn  1768:               ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
1.1       raeburn  1769:           } else {
                   1770:               $response = "There was a problem retrieving institutional class list data for the course sections and crosslisted courses which contribute enrollment to this course. No updates have been carried out, and the roster remains unchanged.";
                   1771:           }  
                   1772:       } else {
                   1773:           $response = "There are currently no course sections or crosslisted courses designated as contributors to enrollment in this LON-CAPA course. As a result a student roster update has not been carried out for $realm ($coursecode)";
                   1774:       }
                   1775:   }
                   1776:   unless ($logmsg eq '') {
                   1777:       my $loglength = length($logmsg);
                   1778:       $logmsg = substr($logmsg,0,$loglength-4);
                   1779:       $logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   1780:   }
1.5       raeburn  1781:   unless ($newusermsg eq '') {
                   1782:       $newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
                   1783:       $newusermsg = "<br/><br/>The following new system user(s) who was/were created will be using internal authentication with an initial randomly generated password. A valid e-mail address was not available for this/these user(s) so LON-CAPA account credentials could not be sent via e-mail.<br/><ul><li>".$newusermsg."</ul><br/>";
                   1784:   }
                   1785:   $response .= $logmsg.$newusermsg;
1.1       raeburn  1786:   &print_reply($r,$response,$$tasktitleref{$action});
                   1787:   return;
1.10      raeburn  1788: }
                   1789: 
                   1790: sub warning_message {
                   1791:     my ($dom,$crs,$caller) = @_;
                   1792:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   1793:     my $currend = '';
                   1794:     my $currstart = '';
                   1795:     my $currsecs = '';
                   1796:     my $currxlists = '';
                   1797:     my $warning = '';
                   1798:     my $curradds = '';
                   1799:     my $currdrops = '';
                   1800:     if ( defined($settings{'internal.autoadds'}) ) {
                   1801:         $curradds = $settings{'internal.autoadds'};
                   1802:     }
                   1803:     if (defined($settings{'internal.autodrops'}) ) {
                   1804:         $currdrops = $settings{'internal.autodrops'};
                   1805:     }
                   1806:     if ( defined($settings{'internal.autostart'}) ) {
                   1807:         $currstart = $settings{'internal.autostart'};
                   1808:     }
                   1809:     if ( defined($settings{'internal.autoend'}) ) {
                   1810:         $currend = $settings{'internal.autoend'};
                   1811:     }
                   1812:     if ( defined($settings{'internal.sectionnums'}) ) {
                   1813:         $currsecs = $settings{'internal.sectionnums'};
                   1814:     }
                   1815:     if ( defined($settings{'internal.crosslistings'}) ) {
                   1816:         $currxlists = $settings{'internal.crosslistings'}
                   1817:     }
                   1818:     unless ($caller eq 'setdates') {
                   1819:         if ( ($currstart eq '') && ($currend eq '') )  {
                   1820:             $warning = "You <b>must</b> now use <a href='/adm/populate?action=setdates'>Change enrollment dates</a> to set a start date <i>and</i> an end date for the enrollment (or check the 'No end date' checkbox) for the nightly adds process to actually occur.</br></br>";
                   1821:         }
                   1822:     }
                   1823:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   1824:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   1825:             $warning .= "You <b>must</b> now use <a href='/adm/populate?action=sections'>Section settings</a> and/or <a href='/adm/populate?action=crosslist'>Change crosslistings</a> to choose at least one section of the course, or at least one crosslisted course which will contribute enrollment to this LON-CAPA course.  At present there are <b>NO</b> sections or crosslisted courses that are affiliated with this course that are set to contribute to the automated enrollment process.<br/><br/>";
                   1826:         }
                   1827:     }
                   1828:     unless ( $caller eq 'chgsettings') {
                   1829:         if ( (!$curradds) && (!$currdrops) ) {
                   1830:             $warning .= "You <b>must</b> now use <a href='/adm/populate?action=chgsettings'>Automated adds/drops</a> to enable automated adds and/or drops if you want automatic enrollment updates to occur in this course.<br/><br/>.";
                   1831:         }
                   1832:     }
                   1833:     return $warning;
1.1       raeburn  1834: }
                   1835: 
                   1836: sub print_reply () {
                   1837:   my ($r,$response,$caller) = @_;
                   1838:   $r->print("
                   1839:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   1840:              <tr>
                   1841:               <tr align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
                   1842:               </td>
                   1843:              </tr>
                   1844:             </table>
                   1845:   ");
                   1846:   return;
                   1847: }
                   1848: 
                   1849: sub setup_date_selectors {
                   1850:     my ($starttime,$endtime) = @_;
                   1851:     if (! defined($starttime)) {
                   1852:         $starttime = time;
                   1853:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                   1854:                             '.default_enrollment_start_date'})) {
                   1855:             $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
                   1856:                                   '.default_enrollment_start_date'};
                   1857:         }
                   1858:     }
                   1859:     if (! defined($endtime)) {
                   1860:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                   1861:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                   1862:                             '.default_enrollment_end_date'})) {
                   1863:             $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
                   1864:                                 '.default_enrollment_end_date'};
                   1865:         }
                   1866:     }
                   1867:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   1868:                                                             'startdate',
                   1869:                                                             $starttime);
                   1870:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   1871:                                                           'enddate',
                   1872:                                                           $endtime);
                   1873:     return ($startdateform,$enddateform);
                   1874: }
                   1875: 
                   1876: sub get_dates_from_form {
                   1877:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   1878:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                   1879:     if ( exists ($ENV{'form.no_end_date'}) ) {
                   1880:         $enddate = 0;
                   1881:     }
                   1882:     return ($startdate,$enddate);
                   1883: }
                   1884: 
                   1885: sub date_setting_table {
                   1886:     my ($starttime,$endtime) = @_;
                   1887:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime);
                   1888:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
                   1889:     if (defined($endtime) && $endtime == 0) {
                   1890:         $perpetual .= ' checked';
                   1891:     }
                   1892:     $perpetual.= ' />'.' no ending date</nobr>';
                   1893:     my $start_table = '';
                   1894:     $start_table .= "<table>\n";
                   1895:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   1896:         '<td>'.$startform.'</td>'.
                   1897:         '<td>&nbsp;</td>'."</tr>\n";
                   1898:     $start_table .= "</table>";
                   1899:     my $end_table = '';
                   1900:     $end_table .= "<table>\n";
                   1901:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   1902:         '<td>'.$endform.'</td>'.
                   1903:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   1904:     $end_table .= "</table>\n";
                   1905:     return ($start_table, $end_table);
                   1906: }
                   1907: 
                   1908: ###################################################################
                   1909: sub handler {
                   1910:     my $r = shift;
                   1911:     if ($r->header_only) {
                   1912:         $r->content_type('text/html');
                   1913:         $r->send_http_header;
                   1914:         return OK;
                   1915:     }
                   1916:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   1917:     #  Needs to be in a course
                   1918:     if (! (($ENV{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   1919:         # Not in a course, or not allowed to modify parms
                   1920:         $ENV{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
                   1921:         return HTTP_NOT_ACCEPTABLE; 
                   1922:     }
                   1923:     # Start page
                   1924:     $r->content_type('text/html');
                   1925:     $r->send_http_header;
                   1926: 
                   1927:     my @tasks = ("information","chgsettings","setdates","notify","crosslist","sections","photos","updatenow");
                   1928:                                                                                  
                   1929:     my %tasklong = (
                   1930:                information => "Task information",
                   1931:                chgsettings => "Automated adds/drops",
                   1932:                setdates => "Change enrollment dates",
                   1933:                notify => "Notification of changes",
                   1934:                crosslist => "Change crosslistings",
                   1935:                sections => "Section settings",
                   1936:                photos => "Student photos",
                   1937:                updatenow => "Update roster now",
                   1938:                newcross => "Add crosslistings",
                   1939:                newsections => "Add sections"
                   1940:     );
                   1941:                                                                                  
                   1942:     my %tasktitle = (
                   1943:                chgsettings => "Changes to nightly automated enrollments",
                   1944:                setdates => "Changes to first and/or last automated enrollment dates",
                   1945:                notify => "Notification of enrollment changes",
                   1946:                crosslist => "Changes to crosslistings",
                   1947:                sections => "Changes to section settings",
                   1948:                photos => "Automatic import of student photos",
                   1949:                updatenow => "Immediate course roster update",
                   1950:                newcross => "Adding new crosslisted courses",
                   1951:                newsections => "Adding new course sections"
                   1952:     );
                   1953: 
                   1954:     my $realm = '';
                   1955:     if ( exists($ENV{'request.course.id'}) ) {
                   1956:         $realm= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                   1957:     }
                   1958:     unless ($realm) { $realm='&nbsp;'; }
                   1959:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1960:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   1961:     
                   1962:     #
                   1963:     # Main switch on form.action and form.state, as appropriate
                   1964:     #
                   1965: 
                   1966:     my $action = "information";
                   1967:     if ( exists($ENV{'form.action'}) ) {
                   1968:         $action = $ENV{'form.action'};
                   1969:     }
                   1970:     my $state = "choose";
                   1971: 
                   1972:     if ( exists($ENV{'form.state'}) ) {
                   1973:         $state = $ENV{'form.state'};
                   1974:     }
                   1975: 
                   1976:     if ($action eq "information") {
                   1977:         $r->print(&header()); 
                   1978:     } else {
                   1979:         if ($state eq "choose") {
                   1980:             $r->print(&choose_header());
                   1981:         } else {
                   1982:             if ($action eq "crosslist") {
                   1983:                 if ( exists($ENV{'form.numcross'}) ) {
                   1984:                     if ( $ENV{'form.numcross'} > 0 ) {
                   1985:                         $r->print(&choose_header());
                   1986:                     } else {
                   1987:                         $r->print(&header());
                   1988:                     }
                   1989:                 } else {
                   1990:                     $r->print(&header());
                   1991:                 }
                   1992:             } elsif ($action eq "sections") {
                   1993:                 if ( exists($ENV{'form.numsec'}) ) {
                   1994:                     if ( $ENV{'form.numsec'} > 0 ) {
                   1995:                         $r->print(&choose_header());
                   1996:                     } else {
                   1997:                         $r->print(&header());
                   1998:                     }
                   1999:                 } else {
                   2000:                     $r->print(&header());
                   2001:                 }
                   2002:             } else {
                   2003:                 $r->print(&header());
                   2004:             }
                   2005:         }
                   2006:     }
                   2007:   
                   2008:     my $reply = 0;
                   2009:     unless ($state eq "choose") { $reply = 1; }
                   2010: 
                   2011:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   2012:     &print_navmenu($r,\@tasks,\%tasklong);
                   2013:     
                   2014:     if (($state eq "choose") || ($action eq "information")) {
                   2015:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
                   2016:     } elsif ($action eq "chgsettings") {
                   2017:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2018:     } elsif ($action eq "setdates") {
                   2019:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2020:     } elsif ($action eq "notify") {
                   2021:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2022:     } elsif ($action eq "sections") {
                   2023:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2024:     } elsif ($action eq "crosslist") {
                   2025:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2026:     } elsif ($action eq "updatenow") {
                   2027:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2028:     } elsif ($action eq "photos") {
                   2029:         &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2030:     } elsif ($action eq "newcross") {
                   2031:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
                   2032:     } elsif ($action eq "newsections") {
                   2033:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2034:     }
                   2035:     &print_doc_base($r);  
                   2036:     return OK;
                   2037: }
                   2038: ###################################################################
                   2039: 1;

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