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

1.4       albertel    1: # automated enrollment configuration handler
1.12    ! raeburn     2: # $Id: lonpopulate.pm,v 1.11 2004/04/16 13:26:44 albertel 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 {
1.12    ! raeburn   210:   my ($r,$realm,$dom,$crs,$tasktitleref,$homeserver,$server) = @_;
1.1       raeburn   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") {
1.12    ! raeburn   644:       my @sections = ();
        !           645:       @sections = &Apache::lonnet::auto_get_sections($homeserver,$enrollvar{coursecode});
1.1       raeburn   646:       my @storedsections = ();
                    647:       my @currsections = ();
                    648:       my %sec_id = ();
                    649:       if ($enrollvar{sectionnums} =~ m/,/) {
                    650:           @storedsections = split/,/,$enrollvar{sectionnums};
                    651:       } else {
                    652:           $storedsections[0] = $enrollvar{sectionnums};
                    653:       }
                    654:       foreach (@storedsections) {
                    655:           if ($_ =~ m/^(\w+):(\w*)$/) {
                    656:               push @currsections, $1;
                    657:               $sec_id{$1} = $2;
                    658:           }
                    659:       }
                    660:       if (@sections > 0) {
1.8       raeburn   661:           my $secshow = @sections;
                    662:           $r->print("
1.1       raeburn   663:             <form name=\"enter\" method=\"post\"><br/>
                    664:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    665:              <tr>
                    666:               <td align=\"left\">
                    667:                <b>$$tasktitleref{$action}</b><br/>
                    668:                Your institution's course catalog includes $secshow sections for course code: $enrollvar{coursecode}.
                    669:               </td>
                    670:              </tr>
                    671:              <tr>
1.5       raeburn   672:               <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
                    673: your changes.</td>
1.1       raeburn   674:              </tr>
                    675:             </table>
                    676:             <br/>
1.7       raeburn   677:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    678:              <tr bgcolor=\"#CCCCFF\">
                    679:               <td><b>Section</b></td>
                    680:               <td><b>Current status</b></td>              
                    681:               <td><b>LON-CAPA section/group ID</b></td>
                    682:               <td><b>Enrollment in this course?</b></td>
                    683:              </tr>
1.8       raeburn   684:           ");
                    685:           for (my $i=0; $i<@sections; $i++) {
                    686:               my $colflag = $i%2;
                    687:               my $shrflag = 0;
                    688:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.5       raeburn   689:                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" /></td>
1.1       raeburn   690:                    <td>
1.8       raeburn   691:               ");
                    692:               if (grep/^$sections[$i]$/,@currsections) {
                    693:                   $r->print("Enrollment active");
                    694:                   $shrflag = 1;
                    695:               } else {
                    696:                   $r->print("Enrollment inactive");
                    697:               }
                    698:               if ($shrflag) {
                    699:                   $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>"); 
                    700:               } else {
                    701:                   $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   702:               }
1.8       raeburn   703:           }
                    704:           $r->print("
1.7       raeburn   705:             </table>
                    706:             <br/>
                    707:             <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
                    708:              <tr> 
                    709:               <td align=\"right\">
                    710:                <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />
                    711:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    712:               </td>
                    713:              </tr>
                    714:             </table>
                    715:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    716:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    717:             </form>
1.8       raeburn   718:           ");
1.1       raeburn   719:       } else {
                    720:           $r->print("
                    721:             <form name=\"enter\" method=\"post\"><br/>
                    722:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    723:              <tr>
                    724:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    725:           ");
                    726:           if (@currsections) {
                    727:               my $secshow = @currsections;
                    728:               $r->print("
1.7       raeburn   729:                 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   730:               </td>
                    731:              </tr>
                    732:             </table>
                    733:             <br/>
                    734:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    735:              <tr>
                    736:               <td>
                    737:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    738:                 <tr bgcolor=\"#CCCCFF\">
                    739:                  <td><b>Enrollment?</b></td>
                    740:                  <td><b>Section</b></td>
                    741:                  <td><b>LON-CAPA section/groupID</b></td>
                    742:                 </tr>
                    743:               ");
                    744:               for (my $j=0; $j<@currsections; $j++) {
                    745:                   my $colflag = $j%2;
                    746:                   $r->print("
                    747:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    748:                  <td><input type=\"checkbox\" name=\"sec_$j\" checked=\"true\"/></td>
                    749:                  <td>$currsections[$j]</td>
                    750:                  <td><input type=\"text\" name=\"secgp_$j\" size=\"10\" value=\"$sec_id{$currsections[$j]}\"></td>
                    751:                 </tr> 
                    752:                   ");
                    753:               }
                    754:               $r->print("  </table>
                    755:               </td>
                    756:              </tr>
                    757:             </table>
                    758:               ");
                    759:           } else {
                    760:               $r->print("
                    761:                 Currently no sections of $realm ($enrollvar{coursecode}) are contributing enrollment to the LON-CAPA class roster.
                    762:               </td>
                    763:              </tr>
                    764:             </table>
                    765:               ");
                    766:           }
                    767:           $r->print("   
                    768:             <br/>
                    769:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    770:              <tr>
                    771:               <td align=\"left\">
                    772:                <b>Add enrollment from additional sections.</b><br/>
                    773:                Number of new sections to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numsec\" value=\"0\" />
                    774:               </td>
                    775:              </tr>
                    776:             </table>
                    777:             <br/>
                    778:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    779:              <tr>
                    780:               <td align=\"right\">
                    781:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    782:               </td>
                    783:              </tr>
                    784:             </table>
                    785:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    786:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    787:             </form> 
                    788:           ");
                    789:       }
                    790:   } elsif ($action eq "photos") {
                    791:       my @photosets = ("OFF","ON");
                    792:       $r->print("
                    793:                   <form name=\"enter\" method=\"post\"><br/>
                    794:                   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    795:                    <tr>
                    796:                     <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    797:                        Currently: Student photo import:  <i>$photosets[$enrollvar{showphotos}]</i>
                    798:                     </td>
                    799:                    </tr>
                    800:                   </table>
                    801:                   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    802:                     <tr>
                    803:                      <td>
                    804:                          Automatic import of student photos from institutional data repository:&nbsp;&nbsp;
                    805: 
                    806:       ");
                    807:       if ($enrollvar{showphotos}) {
                    808:           $r->print("
                    809:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    810:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" />&nbsp;No
                    811:           ");
                    812:       } else {
                    813:           $r->print("
                    814:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    815:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" checked=\"true\" />&nbsp;No
                    816:           ");
                    817:       }
                    818:       $r->print("
                    819:                      </td>
                    820:                     </tr>
                    821:                     <tr>
                    822:                      <td>
                    823:                       <font color=\"#888888\">
                    824: 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.  
                    825:                       </font>
                    826:                      </td>
                    827:                     </tr>
                    828:                     <tr>
                    829:                      </td>&nbsp;</td>
                    830:                     </tr>
                    831:                     <tr>
                    832:                      <td align=\"right\">
                    833:                       <input type=\"button\" name=\"showphotos\" value=\"Go\" onClick=\"process('photos')\">
                    834:                      </td>
                    835:                     </tr>
                    836:                    </table>
                    837:                    <input type=\"hidden\" name=\"action\" value=\"$action\">
                    838:                    <input type=\"hidden\" name=\"state\" value=\"process\">
                    839:                    </form>
                    840:       ");
                    841:   } elsif ($action eq "updatenow") {
                    842:       $r->print("
                    843:                    <form name=\"enter\" method=\"post\"><br/>
                    844: 		   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    845: 		    <tr>
                    846: 		     <td align=\"left\"><b>$$tasktitleref{$action}</b>
                    847: 		     </td>
                    848:                     </tr>
                    849: 		   </table>
                    850: 		   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    851: 		    <tr>
                    852: 		     <td>
                    853: 	              Add any students currently included in institutional classlist(s) but not enrolled in your LON-CAPA course. 
                    854: 		      <input type=\"radio\" name=\"updateadds\" value=\"1\">&nbsp;Yes&nbsp;
                    855: 		      <input type=\"radio\" name=\"updateadds\" value=\"0\">&nbsp;No&nbsp;
                    856:                      </td>
                    857:                     </tr>
                    858:                     <tr>
                    859:                      <td>
                    860:  	              Expire students previously added by nightly enrollment process, but no longer listed in institutional  classlist(s).                  
                    861:                 <input type=\"radio\" name=\"updatedrops\" value=\"1\">&nbsp;Yes&nbsp;
                    862:                 <input type=\"radio\" name=\"updatedrops\" value=\"0\">&nbsp;No&nbsp;<br/>
                    863:               </td>
                    864:              </tr>
                    865:              <tr>
                    866:               <td>
                    867:                <font color=\"#888888\">
                    868: 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.
                    869:                </font>
                    870:               </td>
                    871:              </tr>
                    872:              <tr>
                    873:               <td align=\"right\">
                    874:                <input type=\"button\" name=\"updatenow\" value=\"Go\" onClick=\"process('updatenow')\">
                    875:               </td>
                    876:              </tr>
                    877: 	    </table>
                    878:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    879:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    880:             </form>
                    881:       ");
                    882:   }
                    883: }
                    884: 
                    885: ###############################################################
                    886: sub print_doc_base {
                    887:   my $r = shift;
                    888:   $r->print(<<ENDBASE);
                    889:   </td>
                    890:  </tr>
                    891: </table>
                    892: <br/>
                    893: </body>
                    894: </html> 
                    895: ENDBASE
                    896: }
                    897:  
                    898: ###################################################################
                    899: sub print_chgsettings_response {
                    900:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.10      raeburn   901:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
                    902:   my $currend = '';
                    903:   my $currstart = '';
                    904:   my $currsecs = '';
                    905:   my $currxlists = '';
                    906:   my $curradds = '';
                    907:   my $currdrops = '';
                    908:   if ( defined($settings{'internal.autoadds'}) ) {
                    909:       $curradds = $settings{'internal.autoadds'};
                    910:   }
                    911:   if ( defined($settings{'internal.autodrops'}) ) {
                    912:       $currdrops = $settings{'internal.autodrops'};
                    913:   }
                    914:   if ( defined($settings{'internal.autostart'}) ) {
                    915:       $currstart = $settings{'internal.autostart'};
                    916:   }
                    917:   if ( defined($settings{'internal.autoend'}) ) {
                    918:       $currend = $settings{'internal.autoend'};
                    919:   }
                    920:   if ( defined($settings{'internal.sectionnums'}) ) {
                    921:       $currsecs = $settings{'internal.sectionnums'};
                    922:   }
                    923:   if ( defined($settings{'internal.crosslistings'}) ) {
                    924:       $currxlists = $settings{'internal.crosslistings'}
                    925:   }
1.1       raeburn   926:   my $autoadds = '';
                    927:   my $autodrops = '';
                    928: 
                    929:   if ( exists($ENV{'form.autoadds'}) ) {
                    930:       $autoadds=$ENV{'form.autoadds'};
                    931:   }
                    932:   if ( exists($ENV{'form.autodrops'}) ) {
                    933:       $autodrops=$ENV{'form.autodrops'};
                    934:   }
                    935: 
                    936:   my $response = "";
1.10      raeburn   937:   my $warning = "";
                    938:   my $warn_prefix = "";
                    939:   my $warn_suffix = "";
                    940:   my $warnfiller = "";
1.1       raeburn   941:   my %cenv = ('internal.autoadds' => $autoadds,
                    942:               'internal.autodrops' => $autodrops);
                    943:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                    944:   if ($reply !~ /^ok$/) {
                    945:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                    946:   } else {
                    947:       if ($autoadds) {
                    948:           if ($curradds) {
                    949:               $response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
                    950:           } else {
                    951:               $response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
1.10      raeburn   952:           }
1.1       raeburn   953:       } else {
                    954:           if ($curradds) {
                    955:               $response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
                    956:           } else {
                    957:               $response = "Nightly additions based on classlist changes still <b>disabled</b><br/>";
                    958:           }
                    959:       }
                    960:       if ($autodrops) {
                    961:           if ($currdrops) {
                    962:               $response .= "Nightly removals based on classlist changes still <b>enabled</b><br>";
                    963:           } else {
                    964:               $response .= "Nightly removals based on classlist changes now <b>enabled</b><br/>";
                    965:           }
                    966:       } else {
                    967:           if ($currdrops) {
                    968:               $response .= "Nightly removals based on classlist changes now <b>disabled</b><br>";
                    969:           } else {
                    970:               $response .= "Nightly removals based on classlist changes still <b>disabled</b>";
                    971:           }
                    972:       }
1.10      raeburn   973:       if ($autoadds || $autodrops) {
                    974:           $warning = &warning_message($dom,$crs,$action);
                    975:           $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you indicated that nightly ";
                    976:           $warn_suffix = " should be enabled, additional action is required.<br/>";
                    977:       }
                    978:       if ($autoadds) {
                    979:           if ($autodrops) {
                    980:               $warnfiller = "adds and drops";
                    981:           } else {
                    982:               $warnfiller = "adds";
                    983:           }
                    984:       } else {
                    985:           if ($autodrops) {
                    986:               $warnfiller = "drops";
                    987:           }
                    988:       }
                    989:       unless ($warning eq '') {
                    990:           $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
                    991:       }
1.1       raeburn   992:   }
                    993:   &print_reply($r,$response,$$tasktitleref{$action});
                    994:   return;
                    995: }
                    996: 
                    997: sub print_setdates_response {
                    998:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                    999:   my %settings = &Apache::lonnet::get('environment',['internal.autostart','internal.autoend'],$dom,$crs);
                   1000:   my $currstart = $settings{'internal.autostart'};
                   1001:   my $currend = $settings{'internal.autoend'};
                   1002:   my $response = '';
                   1003:   my ($autostart,$autoend) = &get_dates_from_form();
                   1004:   my $showstart = localtime($autostart);
                   1005:   my $showend = '';
1.10      raeburn  1006:   my $warning = '';
                   1007:   my $warn_prefix = '';
1.1       raeburn  1008:   if ($autoend) {
                   1009:       $showend = localtime($autoend);
                   1010:   } else {
                   1011:       $showend = "'No end date'";
                   1012:   } 
                   1013: 
                   1014:   my %cenv = ('internal.autostart' => $autostart,
                   1015:               'internal.autoend' => $autoend);
                   1016:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1017:   if ($reply !~ /^ok$/) {
                   1018:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1019:   } else {
                   1020:       if ($currstart == $autostart) {
                   1021:           $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
                   1022:       } else {
                   1023:           $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
                   1024:       } 
                   1025:       if ($currend == $autoend) {
                   1026:           $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
                   1027:       } else {
1.9       raeburn  1028:           $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
1.1       raeburn  1029:       }
                   1030:  
                   1031: # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.
                   1032: 
                   1033:       my $rosterupdated = 0;
                   1034:       my $firstaccess = "";
                   1035:       my $nextupdate = "";
                   1036:       my $lastupdate = "";
                   1037: 
                   1038:       my $nowstamp = time;
                   1039:       my @date_list=localtime(time);
                   1040:       my $cur_year = $date_list[5];
                   1041:       my $curday = $date_list[3];
                   1042:       my $curmonth = $date_list[4];
                   1043:       my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1044:       my $nextmidnt = 86400 + $lastmidnt;
                   1045: 
1.10      raeburn  1046:       my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
1.1       raeburn  1047:       my $lastupdate = $todayupdate - 86400;
                   1048:       if ($nowstamp < $todayupdate) {
                   1049:           $nextupdate = "today";
                   1050:       } else {
                   1051:           $nextupdate = "tomorrow";
                   1052:       }
                   1053:       if ($currstart < $lastupdate) {
                   1054:           $rosterupdated = 1;
                   1055:       }
                   1056:       if ($autostart < $nextmidnt ) {
                   1057:           if ( $autostart >= $lastmidnt) {
                   1058:               $firstaccess = "today";
                   1059:           } else {
                   1060:               $firstaccess = "a date prior to today";
                   1061:           }
                   1062:           if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
1.10      raeburn  1063:               $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  1064:           }
                   1065:       }
1.10      raeburn  1066:       $warning = &warning_message($dom,$crs,$action);
                   1067:       $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/>";
                   1068:       unless ($warning eq '') {
                   1069:           $response .= $warn_prefix.$warning;
                   1070:       }
1.1       raeburn  1071:   }
                   1072:   &print_reply($r,$response,$$tasktitleref{$action});
                   1073:   return;
                   1074: }
                   1075: 
                   1076: sub print_notify_response {
                   1077:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1078: 
                   1079: # Get current settings
                   1080:   my %settings = &Apache::lonnet::get('environment',['internal.notifylist','internal.coursecode'],$dom,$crs);
                   1081:   my $notifylist = $settings{'internal.notifylist'};
                   1082:   my $coursecode = $settings{'internal.coursecode'};
                   1083:   my @currpeople = ();
                   1084:   my $notify = 0;
                   1085:   my @people = ();
1.7       raeburn  1086:   my $peoplestr = "";
                   1087:   my $response = "";
                   1088:   my $noprocess = 0;
1.1       raeburn  1089: 
                   1090:   if ($notifylist =~ m/,/) {
                   1091:       @currpeople = split/,/,$notifylist;
                   1092:   } else {
1.7       raeburn  1093:       $currpeople[0] = $notifylist;
1.1       raeburn  1094:   }
                   1095:   my $currcount = 0;
                   1096:   foreach  (@currpeople) {
                   1097:       unless ($_ eq '') { $currcount ++; } 
                   1098:   }
                   1099: 
                   1100:   if ( exists($ENV{'form.notify'}) ) {
                   1101:       $notify=$ENV{'form.notify'};
                   1102:   }
1.7       raeburn  1103:   if ( exists($ENV{'form.notifyshow'}) ) {
                   1104:       my $notifyshow = $ENV{'form.notifyshow'};
                   1105:       for (my $i=0; $i<$notifyshow; $i++) {
                   1106:           if ( exists($ENV{"form.note_$i"}) ) {
                   1107:               if ( exists($ENV{"form.notifyname_$i"}) ) {
                   1108:                   unless ( $ENV{"form.notifyname_$i"} eq '' ) {
                   1109:                       push @people, $ENV{"form.notifyname_$i"};
                   1110:                   }
                   1111:               }
                   1112:           }
                   1113:       }
                   1114:       if ($notify) { $peoplestr = join(",",@people); }
1.1       raeburn  1115:   } else {
                   1116:       if ($notify) {
1.7       raeburn  1117:           if ($currcount) {
                   1118:               $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/>.";
                   1119:               $peoplestr = $notifylist;
                   1120:               @people = @currpeople;
                   1121:               $noprocess = 1;
                   1122:           }
                   1123:       }
                   1124:   }
                   1125:   unless ($noprocess == 1) {
                   1126:       my %cenv = ('internal.notifylist' => $peoplestr);
                   1127:       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1128:       if ($reply !~ /^ok$/) {
                   1129:            $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
                   1130:       } else {
                   1131:           if ($notify) {
                   1132:               if (@people) {
                   1133:                   if ($currcount) {
                   1134:                       $response .= "Notification of enrollment changes still <b>enabled</b><br/>";
                   1135:                   } else {
                   1136:                       $response .= "Notification of enrollment changes now <b>enabled</b><br/>";
                   1137:                   }
                   1138:                   $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";
                   1139:                   foreach my $person (@people) {
                   1140:                       $response .= "<li>$person</li>\n";
                   1141:                   }
                   1142:                   $response .= "</ul>\n";
                   1143:               } else {
                   1144:                   $response = "Notification of enrollment changes was <b> not enabled</b> as no course coordinators were selected as recipients.<br/>";
                   1145:               }
                   1146:           } else {
1.1       raeburn  1147:               if ($currcount) {
1.7       raeburn  1148:                   $response = "Notification of enrollment changes now <b>disabled</b><br/>";
1.1       raeburn  1149:               } else {
1.7       raeburn  1150:                   $response = "Notification of enrollment changes still <b>disabled</b><br/>";
1.1       raeburn  1151:               }
                   1152:           }
                   1153:       }
                   1154:   }
                   1155:   &print_reply($r,$response,$$tasktitleref{$action});
                   1156:   return;
                   1157: }
                   1158: 
                   1159: sub print_crosslistings_menu () {
1.12    ! raeburn  1160:   my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
1.1       raeburn  1161:   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
                   1162:   my @currxlists = ();
                   1163:   my @xlists = ();
                   1164:   my $crosscount = 0;
                   1165:   my $removecount = 0;
                   1166:   my $xliststr = '';
                   1167:   my $response = '';
                   1168:   my $coursecode = $settings{'internal.coursecode'};
                   1169:   if ($settings{'internal.crosslistings'} =~ m/,/) {
                   1170:       @currxlists = split/,/,$settings{'internal.crosslistings'};
                   1171:   } elsif ($settings{'internal.crosslistings'} ne '') {
                   1172:       $currxlists[0] = $settings{'internal.crosslistings'};
                   1173:   }
                   1174: 
                   1175:   if (@currxlists > 0) {
                   1176:       for (my $i=0; $i<@currxlists; $i++) {
                   1177:           my $xlist = "cross_".$i;
                   1178:           my $gp = "gp_".$i;
                   1179:           if ( exists($ENV{"form.$xlist"}) ) {
                   1180:               my $xlistentry = '';
                   1181:               if ($currxlists[$i] =~ m/^(\w+:)/) {
                   1182:                   $xlistentry = $1;
                   1183:               }
                   1184:               if ( exists($ENV{"form.$gp"}) ) {
                   1185:                   $xlistentry .= $ENV{"form.$gp"};
                   1186:               }
                   1187:               push @xlists,$xlistentry;
                   1188:               $crosscount ++;
                   1189:           } else {
                   1190:               $removecount ++;
                   1191:           }
                   1192:       }
                   1193:   }
                   1194: 
                   1195:   if ($crosscount > 1) {
                   1196:       $xliststr = join(",",@xlists);
                   1197:   } else {
                   1198:       $xliststr = $xlists[0];
                   1199:   }
                   1200:   my %cenv = ('internal.crosslistings' => $xliststr);
                   1201:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1202:   if ($reply !~ /^ok$/) {
                   1203:       $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1204:   } else {
                   1205:       if ($removecount > 0) {
1.5       raeburn  1206:           $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.1       raeburn  1207:       }
                   1208:       if ($crosscount > 0) {
                   1209:           $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";
                   1210:           foreach (@xlists) {
                   1211:               my ($xlist,$gp) = split/:/,$_;
                   1212:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1213:           }
                   1214:           $response .= "</ul><br/>\n";
                   1215:       }
                   1216:   }
                   1217:   if ( exists($ENV{'form.numcross'}) ) {
                   1218:       my $numcross = $ENV{'form.numcross'};
                   1219:       if ($numcross > 0) {
                   1220:           my @bgcolors=("#eeeeee","#cccccc");
                   1221:           $response .= qq(
                   1222:            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/>
                   1223:            <form name="enter" method="post">
                   1224:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1225:              <tr>
                   1226:               <td>
                   1227:                <table border="0" cellspacing="3" cellpadding="3">
                   1228:                 <tr bgcolor="#CCCCFF" align="left">
                   1229:                  <td><b>Crosslisting</b></td>
                   1230:                  <td><b>LON-CAPA section/groupID</b></td>
                   1231:                 </tr>
                   1232:           );
                   1233:           for (my $i=0; $i<$numcross; $i++) {
                   1234:               my $colflag = $i%2;
                   1235:               $response .= qq(
                   1236:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1237:                  <td><input type="text" size="15" name="newcross_$i" /></td>
                   1238:                  <td><input type="text" size="10" name="newgroupid_$i" /></td>
                   1239:                 </tr>
                   1240:               );
                   1241:           }
                   1242:           $response .= qq(  </table>
                   1243:               </td>
                   1244:              </tr>
                   1245:              <tr>
                   1246:               <td align="right">
                   1247:                <input type="button" name="newcross" value="Go" onClick="process('newcross')" />
                   1248:               </td>
                   1249:              </tr>
                   1250:             </table>
                   1251:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\">
                   1252:             <input type=\"hidden\" name=\"action\" value=\"newcross\">
                   1253:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1254:             </form>
                   1255:           );
                   1256:       }
                   1257:   }
                   1258:   &print_reply($r,$response,$$tasktitleref{$action});
                   1259:   return;
                   1260: }
                   1261: 
                   1262: sub print_crosslistings_response () {
1.12    ! raeburn  1263:   my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
1.5       raeburn  1264:   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1265:   my @currxlists = ();
                   1266:   my @xlists = ();
                   1267:   my @allxlists = ();
1.5       raeburn  1268:   my @badxlists = ();
                   1269:   my @badowner = ();
1.1       raeburn  1270:   my $numcross = 0;
                   1271:   my $xliststr =  $settings{'internal.crosslistings'};
                   1272:   my $coursecode = $settings{'internal.coursecode'};
1.5       raeburn  1273:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1274:   my $response = '';
1.10      raeburn  1275:   my $warning = '';
                   1276:   my $warn_prefix = '';
1.1       raeburn  1277: 
                   1278:   if ($xliststr =~ m/,/) {
                   1279:       @allxlists = split/,/,$xliststr;
                   1280:   } else {
                   1281:       unless ($xliststr eq '') { $allxlists[0] = $xliststr; }
                   1282:   }
                   1283: 
                   1284:   if ( exists($ENV{'form.numcross'}) ) {
                   1285:       $numcross = $ENV{'form.numcross'};
                   1286:   }
                   1287: 
                   1288:   if ($numcross > 0) {
                   1289:       for (my $i=0; $i<$numcross; $i++) {
                   1290:           my $xl = "newcross_".$i;
                   1291:           my $gp = "newgroupid_".$i;
                   1292:           if ( exists($ENV{"form.$xl"}) ) {
1.12    ! raeburn  1293:               my $coursecheck = '';
        !          1294: #              if ($homeserver eq $server) {
        !          1295: #                  $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"});
        !          1296: #              } else {
        !          1297:                   $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$ENV{"form.$xl"});
        !          1298: #              }
1.5       raeburn  1299:               if ($coursecheck eq 'ok') {
1.12    ! raeburn  1300:                   my $addcheck = '';
        !          1301: #                  if ($homeserver eq $server) {
        !          1302: #                      $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner);
        !          1303: #                  } else {
        !          1304:                       $addcheck = &Apache::lonnet::auto_new_course($homeserver,$ENV{"form.$xl"},$owner);
        !          1305: #                  }
1.5       raeburn  1306:                   if ($addcheck eq 'ok') {
                   1307:                      push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                   1308:                   } else {
                   1309:                      push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
1.12    ! raeburn  1310:                   }
1.5       raeburn  1311:               } else {
1.6       raeburn  1312:                   push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck;
1.5       raeburn  1313:               }
1.1       raeburn  1314:           }
                   1315:       }
                   1316:       push @allxlists, @xlists;
                   1317:   }
                   1318: 
                   1319:   if (@xlists > 0 ) {
                   1320:       unless ($xliststr eq '') { $xliststr .= ","; }
                   1321:       if (@xlists > 1) {
                   1322:           $xliststr .= join(",",@xlists);
                   1323:       } else {
                   1324:           $xliststr .= $xlists[0];
                   1325:       }
                   1326:       my %cenv = ('internal.crosslistings' => $xliststr);
                   1327:       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1328:       if ($reply !~ /^ok$/) {
1.6       raeburn  1329:           $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  1330:       } else {
                   1331:           $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  1332:           foreach (@allxlists) {
                   1333:               my ($xlist,$gp) = split/:/,$_;
                   1334:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1335:           }
                   1336:           $response .= "</ul><br/><br/>\n";
                   1337:       }
                   1338:   } else {
                   1339:       if ($xliststr =~ m/:/) {
                   1340:           my @oldxlists = ();
                   1341:           if ($xliststr =~ m/,/) {
                   1342:               @oldxlists = split/,/,$xliststr;
                   1343:           } else {
                   1344:               $oldxlists[0] = $xliststr;
                   1345:           }
                   1346:           $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1347:           foreach (@oldxlists) {
                   1348:               my ($xlist,$gp) = split/:/,$_;
                   1349:               $response .= "<li>$xlist - ID: $gp</li>\n";
                   1350:           }
                   1351:           $response .= "</ul><br/><br/>\n";
1.1       raeburn  1352:       }
                   1353:   }
1.5       raeburn  1354:   if (@badxlists > 0) {
                   1355:       $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";
                   1356:       foreach (@badxlists) {
1.6       raeburn  1357:           my ($xlist,$gp,$prob) = split/:/,$_;
                   1358:           $response .= "<li>$xlist - ID: $gp - Error: $prob</li>\n";
1.5       raeburn  1359:       }
                   1360:       $response .= "</ul><br/><br/>\n";
                   1361:   }
                   1362: 
                   1363:   if (@badowner > 0) {
                   1364:       $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";
                   1365:       foreach (@badowner) {
                   1366:           my ($xlist,$gp) = split/:/,$_;
                   1367:           $response .= "<li>$xlist - ID: $gp</li>\n";
                   1368:       }
                   1369:       $response .= "</ul><br/><br/>\n";
                   1370:   }
1.1       raeburn  1371: 
1.10      raeburn  1372:   if (@allxlists > 0) {
                   1373:       $warning = &warning_message($dom,$crs,$action);
                   1374:       $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/>";
                   1375:       unless ($warning eq '') {
                   1376:           $response .= $warn_prefix.$warning;
                   1377:       }
                   1378:   }
                   1379: 
1.1       raeburn  1380:   &print_reply($r,$response,$$tasktitleref{$action});
                   1381:   return;
                   1382: }
                   1383: 
                   1384: sub print_sections_menu () {
1.12    ! raeburn  1385:   my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
1.8       raeburn  1386:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1387:   my @currsections = ();
                   1388:   my @sections = ();
1.8       raeburn  1389:   my @badowner = ();
                   1390:   my @badsections = ();
1.1       raeburn  1391:   my $seccount = 0;
                   1392:   my $removecount = 0;
1.6       raeburn  1393:   my $addcount = 0;
1.1       raeburn  1394:   my $secstr = '';
                   1395:   my $response = '';
1.10      raeburn  1396:   my $warning = "";
                   1397:   my $warn_prefix = "";
1.1       raeburn  1398:   my $coursecode = $settings{'internal.coursecode'};
1.8       raeburn  1399:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1400:   if ($settings{'internal.sectionnums'} =~ m/,/) {
                   1401:       @currsections = split/,/,$settings{'internal.sectionnums'};
                   1402:   } elsif ($settings{'internal.sectionnums'} ne '') {
                   1403:       $currsections[0] = $settings{'internal.sectionnums'};
                   1404:   }
1.6       raeburn  1405: 
                   1406:   if ( exists($ENV{'form.secshow'}) ) {
1.8       raeburn  1407:       for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
                   1408:           my $gp = "loncapasec_".$i;
                   1409:           my $secnum = "secnum_".$i;
                   1410:           my $sec = "sec_".$i;
                   1411:           if ( exists( $ENV{"form.$sec"} ) ) {
                   1412:               my $secentry;
                   1413:               if ( exists( $ENV{"form.$secnum"} ) ) { 
                   1414:                   $secentry = $ENV{"form.$secnum"}.':';
                   1415:               }
                   1416:               if ( exists( $ENV{"form.$gp"} ) ) {
                   1417:                   $secentry .= $ENV{"form.$gp"};
                   1418:               }
                   1419:               if ( grep/^$ENV{"form.$secnum"}:/,@currsections) {
                   1420:                   push @sections, $secentry;
                   1421:                   $seccount ++;
                   1422:               } else {
                   1423:                   my $newsec = $coursecode.$ENV{"form.$secnum"};
1.12    ! raeburn  1424:                   my $coursecheck = '';
        !          1425: #                  if ($homeserver eq $server) {
        !          1426: #                      $coursecheck = &localenroll::validate_courseID($newsec);
        !          1427: #                  } else  {
        !          1428:                       $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
        !          1429: #                  }
1.8       raeburn  1430:                   if ($coursecheck eq 'ok') {
1.12    ! raeburn  1431:                       my $addcheck = '';
        !          1432: #                      if ($homeserver eq $server) {
        !          1433: #                          $addcheck = &localenroll::new_course($newsec,$owner);
        !          1434: #                      } else {
        !          1435:                           $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
        !          1436: #                      }
1.8       raeburn  1437:                       if ($addcheck eq 'ok') {
                   1438:                           push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                   1439:                           $seccount ++;
                   1440:                           $addcount ++;
                   1441:                       } else {
                   1442:                           push @badowner,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                   1443:                       }
                   1444:                   } else {
                   1445:                       push @badsections, $ENV{"form.$secnum"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                   1446:                   }
                   1447:               }
                   1448:           }
                   1449:       }
                   1450:       if (@currsections > 0) {
                   1451:           for (my $i=0; $i<@currsections; $i++) {
                   1452:               if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   1453:                   my $oldsec  = $1;
                   1454:                   unless (grep/^$oldsec/,@sections) {
                   1455:                       $removecount ++;
                   1456:                   }
                   1457:               }
                   1458:           }
                   1459:       }
1.6       raeburn  1460:   } elsif (@currsections > 0) {
1.1       raeburn  1461:       for (my $i=0; $i<@currsections; $i++) {
                   1462:           my $sec = "sec_".$i;
                   1463:           my $gp = "secgp_".$i;
                   1464:           if ( exists($ENV{"form.$sec"}) ) {
                   1465:               my $secentry = '';
1.6       raeburn  1466:               if ($currsections[$i] =~ m/^(\w+:)/ ) {
1.1       raeburn  1467:                   $secentry = $1;
                   1468:               }
                   1469:               if ( exists($ENV{"form.$gp"}) ) {
                   1470:                   $secentry .= $ENV{"form.$gp"};
                   1471:               }
                   1472:               push @sections,$secentry;
                   1473:               $seccount ++;
                   1474:           } else {
                   1475:               $removecount ++;
                   1476:           }
                   1477:       }
                   1478:   }
                   1479:                                                                                                      
                   1480:   if ($seccount > 1) {
                   1481:       $secstr = join(",",@sections);
                   1482:   } else {
                   1483:       $secstr = $sections[0];
                   1484:   }
                   1485:   my %cenv = ('internal.sectionnums' => $secstr);
                   1486:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1487:   if ($reply !~ /^ok$/) {
                   1488:        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1489:   } else {
                   1490:       if ($removecount > 0) {
                   1491:           $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/>";
                   1492:       }
1.6       raeburn  1493:       if ($addcount > 0) {
                   1494:           $response .= "A total of $addcount sections have been added to the list of
                   1495: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
                   1496:       }
1.1       raeburn  1497:       if ($seccount > 0) { 
1.6       raeburn  1498:           $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  1499:           foreach (@sections) {
                   1500:               my ($sec,$gp) = split/:/,$_;
                   1501:               $response .= "<li>$sec  - ID: $gp</li>\n";
                   1502:           }
                   1503:           $response .= "</ul><br/>\n";
                   1504:       }
                   1505:   }
                   1506: 
1.8       raeburn  1507:   if (@badsections > 0) {
                   1508:       $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";
                   1509:       foreach (@badsections) {
                   1510:           my ($secnum,$gp,$prob) = split/:/,$_;
                   1511:           $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
                   1512:       }
                   1513:       $response .= "</ul><br/><br/>\n";
                   1514:   }
                   1515: 
                   1516:   if (@badowner > 0) {
                   1517:       $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";
                   1518:       foreach (@badowner) {
                   1519:           my ($secnum,$gp) = split/:/,$_;
                   1520:           $response .= "<li>$secnum - ID: $gp</li>\n";
                   1521:       }
                   1522:       $response .= "</ul><br/><br/>\n";
                   1523:   }
                   1524: 
1.10      raeburn  1525:   if ($seccount > 0) {
                   1526:       $warning = &warning_message($dom,$crs,$action);
                   1527:       $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/>";
                   1528:       unless ($warning eq '') {
                   1529:           $response .= $warn_prefix.$warning;
                   1530:       }
                   1531:   }
                   1532: 
1.1       raeburn  1533:   if ( exists($ENV{'form.numsec'}) ) {
                   1534:       my $numsec = $ENV{'form.numsec'};
                   1535:       if ($numsec > 0) {
                   1536:           my @bgcolors=("#eeeeee","#cccccc");
                   1537:           $response .= qq(
                   1538:            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/> 
                   1539:            <form name="enter" method="post">
                   1540:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1541:              <tr>
                   1542:               <td>
                   1543:                <table border="0" cellspacing="3" cellpadding="3">
                   1544:                 <tr bgcolor="#CCCCFF" align="left">
                   1545:                  <td><b>Section number</b></td>
                   1546:                  <td><b>LON-CAPA section/groupID</b></td>
                   1547:                 </tr>
                   1548:           );
                   1549:           for (my $i=0; $i<$numsec; $i++) {
                   1550:               my $colflag = $i%2;
                   1551:               $response .= qq(
                   1552:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1553:                  <td><input type="text" size="15" name="newsec_$i" /></td>
                   1554:                  <td><input type="text" size="10" name="newsecgp_$i" /></td>
                   1555:                 </tr>
                   1556:               );
                   1557:           }
                   1558:           $response .= qq(  </table>
                   1559:               </td>
                   1560:              </tr>
                   1561:              <tr>
                   1562:               <td align="right">
                   1563:                <input type="button" name="newsections" value="Go" onClick="process('newsections')" />
                   1564:               </td>
                   1565:              </tr>
                   1566:             </table>
                   1567:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\">
                   1568:             <input type=\"hidden\" name=\"action\" value=\"newsections\">
                   1569:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1570:             </form>
                   1571:           );
                   1572:       }
                   1573:   }
                   1574:   &print_reply($r,$response,$$tasktitleref{$action});
                   1575:   return;
                   1576: }
                   1577: 
                   1578: sub print_sections_response () {
1.12    ! raeburn  1579:   my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
1.8       raeburn  1580:   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
1.1       raeburn  1581:   my @currsections = ();
                   1582:   my @sections = ();
                   1583:   my @allsections = ();
1.8       raeburn  1584:   my @badowner = ();
                   1585:   my @badsections = ();
1.1       raeburn  1586:   my $numsec = 0;
                   1587:   my $secstr =  $settings{'internal.sectionnums'};
                   1588:   my $coursecode = $settings{'internal.coursecode'};
1.8       raeburn  1589:   my $owner = $settings{'internal.courseowner'};
1.1       raeburn  1590:   my $response = '';
1.8       raeburn  1591:   my $putreply = '';
1.10      raeburn  1592:   my $warning = '';
                   1593:   my $warn_prefix = '';
1.1       raeburn  1594:   if ($secstr =~ m/,/) {
                   1595:       @allsections = split/,/,$secstr;
                   1596:   } else {
                   1597:       unless ($secstr eq '') { $allsections[0] = $secstr; }
                   1598:   }
                   1599: 
                   1600:   if ( exists($ENV{'form.numsec'}) ) {
                   1601:       $numsec = $ENV{'form.numsec'};
                   1602:   }
1.8       raeburn  1603: 
1.1       raeburn  1604:   if ($numsec > 0) {
                   1605:       for (my $i=0; $i<$numsec; $i++) {
                   1606:           my $sec = "newsec_".$i;
                   1607:           my $gp = "newsecgp_".$i;
                   1608:           if ( exists($ENV{"form.$sec"}) ) {
1.8       raeburn  1609:               unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) {
                   1610:                   my $newsec = $coursecode.$ENV{"form.$sec"};
1.12    ! raeburn  1611:                   my $coursecheck = '';
        !          1612: #                  if ($homeserver eq $server) {
        !          1613: #                      $coursecheck = &localenroll::validate_courseID($newsec);
        !          1614: #                  } else {
        !          1615:                       $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
        !          1616: #                  }
1.8       raeburn  1617:                   if ($coursecheck eq 'ok') {
1.12    ! raeburn  1618:                       my $addcheck = '';
        !          1619: #                      if ($homeserver eq $server) {
        !          1620: #                          $addcheck = &localenroll::new_course($newsec,$owner);
        !          1621: #                      } else {
        !          1622:                           $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
        !          1623: #                      }
1.8       raeburn  1624:                       if ($addcheck eq 'ok') {
                   1625:                           push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                   1626:                       } else {
                   1627:                           push @badowner,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                   1628:                       }
                   1629:                   } else {
                   1630:                       push @badsections, $ENV{"form.$sec"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                   1631:                   }
                   1632:               }
1.1       raeburn  1633:           }
                   1634:       }
                   1635:       push @allsections, @sections;
                   1636:   }
1.8       raeburn  1637: 
1.1       raeburn  1638:   if (@sections > 0 ) {
                   1639:       unless ($secstr eq '') { $secstr .= ","; } 
                   1640:       if (@sections > 1) {
                   1641:           $secstr .= join(",",@sections);
                   1642:       } else {
                   1643:           $secstr .= $sections[0];
                   1644:       }
                   1645:       my %cenv = ('internal.sectionnums' => $secstr);
1.8       raeburn  1646:       $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1647:       if ($putreply !~ /^ok$/) {
                   1648:           $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1649:       }
                   1650:   }
                   1651: 
                   1652:   if ($putreply =~ /^ok/) {
                   1653:       $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";
                   1654:       foreach (@allsections) {
                   1655:           my ($sec,$gp) = split/:/,$_;
                   1656:           $response .= "<li>$sec - ID: $gp</li>\n";
                   1657:       }
                   1658:       $response .= "</ul><br/><br/>\n";
                   1659:   }
                   1660: 
                   1661:   if (@badsections > 0) {
                   1662:       $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";
                   1663:       foreach (@badsections) {
                   1664:           my ($secnum,$gp,$prob) = split/:/,$_;
                   1665:           $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
1.1       raeburn  1666:       }
1.8       raeburn  1667:       $response .= "</ul><br/><br/>\n";
1.1       raeburn  1668:   }
1.8       raeburn  1669: 
                   1670:   if (@badowner > 0) {
                   1671:       $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";
                   1672:       foreach (@badowner) {
                   1673:           my ($secnum,$gp) = split/:/,$_;
                   1674:           $response .= "<li>$secnum - ID: $gp</li>\n";
                   1675:       }
                   1676:       $response .= "</ul><br/><br/>\n";
1.1       raeburn  1677:   }
1.8       raeburn  1678: 
1.10      raeburn  1679:   if (@allsections > 0) {
                   1680:       $warning = &warning_message($dom,$crs,$action);
                   1681:       $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/>";
                   1682:       unless ($warning eq '') {
                   1683:           $response .= $warn_prefix.$warning;
                   1684:       }
                   1685:   }
                   1686: 
1.1       raeburn  1687:   &print_reply($r,$response,$$tasktitleref{$action});
                   1688:   return;
                   1689: }
                   1690: 
                   1691: sub print_photos_response () {
                   1692:   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1693:   my %settings = &Apache::lonnet::get('environment',['internal.showphotos'],$dom,$crs);
                   1694:   my $currphotos = $settings{'internal.showphotos'};
                   1695:   my $showphotos = '';
                   1696:   if ( exists($ENV{'form.showphotos'}) ) {
                   1697:       $showphotos=$ENV{'form.showphotos'};
                   1698:   }
1.8       raeburn  1699: 
1.1       raeburn  1700:   my $response = "";
                   1701:   my %cenv = ('internal.showphotos' => $showphotos);
                   1702:   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1703:   if ($reply !~ /^ok$/) {
                   1704:       $response = "There was a problem processing your requested change. The student photo import setting for this course has been left unchanged.<br/>";
                   1705:   } else {
                   1706:       if ($showphotos) {
                   1707:           if ($currphotos) {
                   1708:               $response = "Retrieval of student photos is still <b>enabled</b><br/>";
                   1709:           } else {
                   1710:               $response = "Retrieval of student photos in now <b>enabled</b><br/>";
                   1711:           }
                   1712:       } else {
                   1713:           if ($currphotos) {
                   1714:               $response = "Retrieval of student photos is now <b>disabled</b><br/>";
                   1715:           } else {
                   1716:               $response = "Retrieval of student photos is still <b>disabled</b><br/>";
                   1717:           }
                   1718:       }
                   1719:   }
                   1720:   &print_reply($r,$response,$$tasktitleref{$action});
                   1721:   return;
                   1722: }
                   1723: 
                   1724: sub print_update_result () {
1.12    ! raeburn  1725:   my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
1.1       raeburn  1726:   my $response = '';
                   1727:   my $updateadds = 0;
                   1728:   my $updatedrops = 0;
                   1729:   my $changecount = 0;
                   1730:   my %affiliates = ();
                   1731:   my %reply = ();
                   1732:   my @allcourses = ();
                   1733:   my %LC_code = ();
                   1734:   my $logmsg = '';
1.5       raeburn  1735:   my $newusermsg = '';
1.1       raeburn  1736: 
                   1737:   my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.autostart','internal.autoend'],$dom,$crs);
                   1738:   my $coursecode = $settings{'internal.coursecode'};
                   1739:   my $authtype = $settings{'internal.authtype'};
                   1740:   my $autharg = $settings{'internal.autharg'};
                   1741:   my $autostart = $settings{'internal.autostart'};
                   1742:   my $autoend = $settings{'internal.autoend'};
                   1743:  
                   1744:   if ( exists($ENV{'form.updateadds'}) ) {
                   1745:       $updateadds = $ENV{'form.updateadds'};
                   1746:   }
                   1747:   if ( exists($ENV{'form.updatedrops'}) ) {
                   1748:       $updatedrops = $ENV{'form.updatedrops'};
                   1749:   }
                   1750:   if (!$updateadds && !$updatedrops) {
                   1751:       $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.";
                   1752:   } elsif ($coursecode eq '') {
                   1753:       $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";
                   1754:   } else {
                   1755: # Get complete list of course sections to update
                   1756:       my @currsections = ();
                   1757:       my @currxlists = ();
                   1758: 
                   1759:       if ($settings{'internal.sectionnums'} =~ m/,/) {
                   1760:           @currsections = split/,/,$settings{'internal.sectionnums'};
                   1761:       } elsif ($settings{'internal.sectionnums'} ne '') {
                   1762:           $currsections[0] = $settings{'internal.sectionnums'};
                   1763:       }
                   1764: 
                   1765:       if ($settings{'internal.crosslistings'} =~ m/,/) {
                   1766:           @currxlists = split/,/,$settings{'internal.crosslistings'};
                   1767:       } elsif ($settings{'internal.crosslistings'} ne '') {
                   1768:           $currxlists[0] = $settings{'internal.crosslistings'};
                   1769:       }
                   1770:                                                                                                      
                   1771:       if (@currxlists > 0) {
                   1772:           foreach (@currxlists) {
                   1773:               if (m/^(\w+):(\w*)$/) {
                   1774:                   unless (grep/^$1$/,@allcourses) { 
                   1775:                       push @allcourses,$1;
                   1776:                       $LC_code{$1} = $2; 
                   1777:                   }
                   1778:               }
                   1779:           }
                   1780:       }
                   1781: 
                   1782:       if (@currsections > 0) {
                   1783:           foreach (@currsections) {
                   1784:               if (m/^(\w+):(\w*)$/) {
                   1785:                   my $sec = $coursecode.$1;
                   1786:                   my $gp = $2;
                   1787:                   unless (grep/^$sec$/,@allcourses) { 
                   1788:                       push @allcourses,$sec;
                   1789:                       $LC_code{$sec} = $gp; 
                   1790:                   }
                   1791:               }
                   1792:           }
                   1793:       }
                   1794: 
                   1795:       if (@allcourses > 0) {
                   1796:           @{$affiliates{$crs}} = @allcourses;
1.12    ! raeburn  1797: #          if ($homeserver eq $server) {
        !          1798: #              &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
        !          1799: #          } else {
        !          1800:               &Apache::lonnet::fetch_enrollment_query($homeserver,$dom,\%affiliates,\%reply);
        !          1801: #          }
1.1       raeburn  1802:           if ($reply{$crs} > 0) {
1.5       raeburn  1803:               ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
1.1       raeburn  1804:           } else {
                   1805:               $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.";
                   1806:           }  
                   1807:       } else {
                   1808:           $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)";
                   1809:       }
                   1810:   }
                   1811:   unless ($logmsg eq '') {
                   1812:       my $loglength = length($logmsg);
                   1813:       $logmsg = substr($logmsg,0,$loglength-4);
                   1814:       $logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   1815:   }
1.5       raeburn  1816:   unless ($newusermsg eq '') {
                   1817:       $newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
                   1818:       $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/>";
                   1819:   }
                   1820:   $response .= $logmsg.$newusermsg;
1.1       raeburn  1821:   &print_reply($r,$response,$$tasktitleref{$action});
                   1822:   return;
1.10      raeburn  1823: }
                   1824: 
                   1825: sub warning_message {
                   1826:     my ($dom,$crs,$caller) = @_;
                   1827:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   1828:     my $currend = '';
                   1829:     my $currstart = '';
                   1830:     my $currsecs = '';
                   1831:     my $currxlists = '';
                   1832:     my $warning = '';
                   1833:     my $curradds = '';
                   1834:     my $currdrops = '';
                   1835:     if ( defined($settings{'internal.autoadds'}) ) {
                   1836:         $curradds = $settings{'internal.autoadds'};
                   1837:     }
                   1838:     if (defined($settings{'internal.autodrops'}) ) {
                   1839:         $currdrops = $settings{'internal.autodrops'};
                   1840:     }
                   1841:     if ( defined($settings{'internal.autostart'}) ) {
                   1842:         $currstart = $settings{'internal.autostart'};
                   1843:     }
                   1844:     if ( defined($settings{'internal.autoend'}) ) {
                   1845:         $currend = $settings{'internal.autoend'};
                   1846:     }
                   1847:     if ( defined($settings{'internal.sectionnums'}) ) {
                   1848:         $currsecs = $settings{'internal.sectionnums'};
                   1849:     }
                   1850:     if ( defined($settings{'internal.crosslistings'}) ) {
                   1851:         $currxlists = $settings{'internal.crosslistings'}
                   1852:     }
                   1853:     unless ($caller eq 'setdates') {
                   1854:         if ( ($currstart eq '') && ($currend eq '') )  {
                   1855:             $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>";
                   1856:         }
                   1857:     }
                   1858:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   1859:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   1860:             $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/>";
                   1861:         }
                   1862:     }
                   1863:     unless ( $caller eq 'chgsettings') {
                   1864:         if ( (!$curradds) && (!$currdrops) ) {
                   1865:             $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/>.";
                   1866:         }
                   1867:     }
                   1868:     return $warning;
1.1       raeburn  1869: }
                   1870: 
                   1871: sub print_reply () {
                   1872:   my ($r,$response,$caller) = @_;
                   1873:   $r->print("
                   1874:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   1875:              <tr>
                   1876:               <tr align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
                   1877:               </td>
                   1878:              </tr>
                   1879:             </table>
                   1880:   ");
                   1881:   return;
                   1882: }
                   1883: 
                   1884: sub setup_date_selectors {
                   1885:     my ($starttime,$endtime) = @_;
                   1886:     if (! defined($starttime)) {
                   1887:         $starttime = time;
                   1888:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                   1889:                             '.default_enrollment_start_date'})) {
                   1890:             $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
                   1891:                                   '.default_enrollment_start_date'};
                   1892:         }
                   1893:     }
                   1894:     if (! defined($endtime)) {
                   1895:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
                   1896:         if (exists($ENV{'course.'.$ENV{'request.course.id'}.
                   1897:                             '.default_enrollment_end_date'})) {
                   1898:             $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
                   1899:                                 '.default_enrollment_end_date'};
                   1900:         }
                   1901:     }
                   1902:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   1903:                                                             'startdate',
                   1904:                                                             $starttime);
                   1905:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   1906:                                                           'enddate',
                   1907:                                                           $endtime);
                   1908:     return ($startdateform,$enddateform);
                   1909: }
                   1910: 
                   1911: sub get_dates_from_form {
                   1912:     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   1913:     my $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
                   1914:     if ( exists ($ENV{'form.no_end_date'}) ) {
                   1915:         $enddate = 0;
                   1916:     }
                   1917:     return ($startdate,$enddate);
                   1918: }
                   1919: 
                   1920: sub date_setting_table {
                   1921:     my ($starttime,$endtime) = @_;
                   1922:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime);
                   1923:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
                   1924:     if (defined($endtime) && $endtime == 0) {
                   1925:         $perpetual .= ' checked';
                   1926:     }
                   1927:     $perpetual.= ' />'.' no ending date</nobr>';
                   1928:     my $start_table = '';
                   1929:     $start_table .= "<table>\n";
                   1930:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   1931:         '<td>'.$startform.'</td>'.
                   1932:         '<td>&nbsp;</td>'."</tr>\n";
                   1933:     $start_table .= "</table>";
                   1934:     my $end_table = '';
                   1935:     $end_table .= "<table>\n";
                   1936:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   1937:         '<td>'.$endform.'</td>'.
                   1938:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   1939:     $end_table .= "</table>\n";
                   1940:     return ($start_table, $end_table);
                   1941: }
                   1942: 
                   1943: ###################################################################
                   1944: sub handler {
                   1945:     my $r = shift;
                   1946:     if ($r->header_only) {
                   1947:         $r->content_type('text/html');
                   1948:         $r->send_http_header;
                   1949:         return OK;
                   1950:     }
                   1951:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   1952:     #  Needs to be in a course
                   1953:     if (! (($ENV{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   1954:         # Not in a course, or not allowed to modify parms
                   1955:         $ENV{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
                   1956:         return HTTP_NOT_ACCEPTABLE; 
                   1957:     }
                   1958:     # Start page
                   1959:     $r->content_type('text/html');
                   1960:     $r->send_http_header;
                   1961: 
                   1962:     my @tasks = ("information","chgsettings","setdates","notify","crosslist","sections","photos","updatenow");
                   1963:                                                                                  
                   1964:     my %tasklong = (
                   1965:                information => "Task information",
                   1966:                chgsettings => "Automated adds/drops",
                   1967:                setdates => "Change enrollment dates",
                   1968:                notify => "Notification of changes",
                   1969:                crosslist => "Change crosslistings",
                   1970:                sections => "Section settings",
                   1971:                photos => "Student photos",
                   1972:                updatenow => "Update roster now",
                   1973:                newcross => "Add crosslistings",
                   1974:                newsections => "Add sections"
                   1975:     );
                   1976:                                                                                  
                   1977:     my %tasktitle = (
                   1978:                chgsettings => "Changes to nightly automated enrollments",
                   1979:                setdates => "Changes to first and/or last automated enrollment dates",
                   1980:                notify => "Notification of enrollment changes",
                   1981:                crosslist => "Changes to crosslistings",
                   1982:                sections => "Changes to section settings",
                   1983:                photos => "Automatic import of student photos",
                   1984:                updatenow => "Immediate course roster update",
                   1985:                newcross => "Adding new crosslisted courses",
                   1986:                newsections => "Adding new course sections"
                   1987:     );
                   1988: 
                   1989:     my $realm = '';
                   1990:     if ( exists($ENV{'request.course.id'}) ) {
                   1991:         $realm= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                   1992:     }
                   1993:     unless ($realm) { $realm='&nbsp;'; }
                   1994:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1995:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   1996:     
                   1997:     #
                   1998:     # Main switch on form.action and form.state, as appropriate
                   1999:     #
                   2000: 
                   2001:     my $action = "information";
                   2002:     if ( exists($ENV{'form.action'}) ) {
                   2003:         $action = $ENV{'form.action'};
                   2004:     }
                   2005:     my $state = "choose";
                   2006: 
                   2007:     if ( exists($ENV{'form.state'}) ) {
                   2008:         $state = $ENV{'form.state'};
                   2009:     }
                   2010: 
                   2011:     if ($action eq "information") {
                   2012:         $r->print(&header()); 
                   2013:     } else {
                   2014:         if ($state eq "choose") {
                   2015:             $r->print(&choose_header());
                   2016:         } else {
                   2017:             if ($action eq "crosslist") {
                   2018:                 if ( exists($ENV{'form.numcross'}) ) {
                   2019:                     if ( $ENV{'form.numcross'} > 0 ) {
                   2020:                         $r->print(&choose_header());
                   2021:                     } else {
                   2022:                         $r->print(&header());
                   2023:                     }
                   2024:                 } else {
                   2025:                     $r->print(&header());
                   2026:                 }
                   2027:             } elsif ($action eq "sections") {
                   2028:                 if ( exists($ENV{'form.numsec'}) ) {
                   2029:                     if ( $ENV{'form.numsec'} > 0 ) {
                   2030:                         $r->print(&choose_header());
                   2031:                     } else {
                   2032:                         $r->print(&header());
                   2033:                     }
                   2034:                 } else {
                   2035:                     $r->print(&header());
                   2036:                 }
                   2037:             } else {
                   2038:                 $r->print(&header());
                   2039:             }
                   2040:         }
                   2041:     }
1.12    ! raeburn  2042: 
        !          2043: # Determine course home server and current server
        !          2044:     my $homeserver = &Apache::lonnet::homeserver($crs,$dom);
        !          2045:     my $server = $Apache::lonnet::perlvar{'lonHostID'};
1.1       raeburn  2046:   
                   2047:     my $reply = 0;
                   2048:     unless ($state eq "choose") { $reply = 1; }
                   2049: 
                   2050:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   2051:     &print_navmenu($r,\@tasks,\%tasklong);
                   2052:     
                   2053:     if (($state eq "choose") || ($action eq "information")) {
1.12    ! raeburn  2054:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle,$homeserver,$server);
1.1       raeburn  2055:     } elsif ($action eq "chgsettings") {
                   2056:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2057:     } elsif ($action eq "setdates") {
                   2058:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2059:     } elsif ($action eq "notify") {
                   2060:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2061:     } elsif ($action eq "sections") {
1.12    ! raeburn  2062:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
1.1       raeburn  2063:     } elsif ($action eq "crosslist") {
1.12    ! raeburn  2064:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
1.1       raeburn  2065:     } elsif ($action eq "updatenow") {
1.12    ! raeburn  2066:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
1.1       raeburn  2067:     } elsif ($action eq "photos") {
                   2068:         &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2069:     } elsif ($action eq "newcross") {
1.12    ! raeburn  2070:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);    
1.1       raeburn  2071:     } elsif ($action eq "newsections") {
1.12    ! raeburn  2072:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
1.1       raeburn  2073:     }
                   2074:     &print_doc_base($r);  
                   2075:     return OK;
                   2076: }
                   2077: ###################################################################
                   2078: 1;

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