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

1.4       albertel    1: # automated enrollment configuration handler
1.15    ! albertel    2: # $Id: lonpopulate.pm,v 1.14 2004/06/17 18:31:24 raeburn Exp $
1.4       albertel    3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
1.1       raeburn    26: package Apache::lonpopulate;
                     27: 
                     28: use strict;
                     29: use lib qw(/home/httpd/lib/perl);
1.7       raeburn    30: use Apache::lonnet;
                     31: use Apache::loncommon;
                     32: use Apache::lonhtmlcommon;
1.3       albertel   33: use Apache::lonlocal;
1.14      raeburn    34: use Apache::loncoursedata;
1.1       raeburn    35: use Apache::Constants qw(:common :http REDIRECT);
                     36: use Time::Local;
1.7       raeburn    37: use LONCAPA::Enrollment;
1.1       raeburn    38: use localenroll;
                     39: 
                     40: ###############################################################
                     41: sub header {
                     42:     my $bodytag=&Apache::loncommon::bodytag('Classlist Manager');
                     43:     return(<<ENDHEAD);
                     44: <html>
                     45: <head>
                     46: <title>LON-CAPA Classlist Manager</title>
                     47: </head>
                     48: $bodytag
                     49: ENDHEAD
                     50: }
                     51: 
                     52: ###############################################################
                     53: 
                     54: sub choose_header {
                     55:     my $bodytag=&Apache::loncommon::bodytag('Classlist Manager');
                     56:     my $scripttag = qq|
                     57: <script language='javascript' type='text/javascript'>
                     58: <!--
                     59: function process(calling) {
                     60:  var checker = 1
                     61:  var rad1 = 0
                     62:  var rad2 = 0
                     63:  var formName = document.forms.enter
1.14      raeburn    64:  if (calling == "viewclass") {
                     65:      formName = document.forms.studentform
                     66:  }
1.1       raeburn    67:  formName.action.value = calling
                     68:  if (calling == "chgsettings") {
                     69:    for (var j=0; j<formName.autoadds.length; j++) {
                     70:        if (formName.autoadds[j].checked) {
                     71:            rad1 = 1
                     72:        }
                     73:    }
                     74:    for (var k=0; k<formName.autodrops.length; k++) {
                     75:        if (formName.autodrops[k].checked) {
                     76:            rad2 = 1
                     77:        }
                     78:    }
                     79:    if (rad1 == 0) {
                     80:        alert("You must check either 'Enable' or 'Disable' for nightly additions based on classlist changes")
                     81:        checker = 0
                     82:    }
                     83:    if (rad2 == 0) {
                     84:        alert("You must check either 'Enable' or 'Disable' for nightly removals based on classlist changes")
                     85:        checker = 0
                     86:    }
                     87:  }
                     88:  if (calling == "updatenow") {
                     89:      var enrolldis
                     90:      var unenrolldis
                     91:      for (var j=0; j<formName.updateadds.length; j++) {
                     92:          if (formName.updateadds[j].value == 0) {
                     93:              enrolldis = j
                     94:          }
                     95:          if (formName.updateadds[j].checked) {
                     96:              rad1 = 1
                     97:          }
                     98:      }
                     99:      for (var k=0; k<formName.updatedrops.length; k++) {
                    100:          if (formName.updatedrops[k].value == 0) {
                    101:              unenrolldis = k 
                    102:          }
                    103:          if (formName.updatedrops[k].checked) {
                    104:              rad2 = 1
                    105:          }
                    106:      }
                    107:      if (rad1 == 0) {
                    108:          alert("You must check either 'Enable' or 'Disable' for nightly additions based on classlist changes")
                    109:          checker = 0
                    110:      }
                    111:      if (rad2 == 0) {
                    112:          alert("You must check either 'Enable' or 'Disable' for nightly removals based on classlist changes")
                    113:          checker = 0
                    114:      }
                    115:      if (formName.updatedrops[unenrolldis].checked && formName.updateadds[enrolldis].checked ) {
                    116:          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")
                    117:          checker = 0
                    118:      }
                    119:  }
1.14      raeburn   120:  if (calling == "viewclass") {
                    121:      document.forms.studentform.state.value = "process";
                    122:      checker = 1;    
                    123:  } 
1.1       raeburn   124:  if (checker == 1) {  
                    125:      formName.submit();
                    126:  }
                    127: }
                    128: // End hiding -->
                    129: </script>
                    130: |;
                    131:     return(<<ENDHEAD);
                    132: <html>
                    133: <head>
                    134: <title>LON-CAPA Classlist Manager</title>
                    135: $scripttag
                    136: $bodytag
                    137: ENDHEAD
                    138: }
                    139: 
                    140: sub print_mainbox {
                    141:     my ($r,$tasklongref,$realm,$reply) = @_;
                    142:     my $action = "information";
                    143:     if ( exists($ENV{'form.action'}) ) {
                    144:         $action = $ENV{'form.action'};
                    145:     }
                    146:     my $page = '';
                    147:     if ($action eq "information") {
                    148:         $page = "<b>Automated Enrollment</b>";
                    149:     } else {
                    150:         $page =  '<a href="/adm/populate">Automated Enrollment</a>';
                    151:         if ($reply) {
                    152:             if ($action eq "newcross") {
                    153:                 $action = "crosslist";
                    154:             } elsif ($action eq "newsections") {
                    155:                 $action = "sections"; 
                    156:             }
                    157:             $page .= "-&gt; <a href=\"/adm/populate?action=$action\">".$$tasklongref{$action}."</a> -&gt; <b>result</b>";
                    158:         } else {
                    159:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>"; 
                    160:         }
                    161:     }
                    162:     $r->print(<<ENDTHIS);
                    163: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    164:  <tr>
                    165:   <td bgcolor="#CCCCFF"> 
                    166:    <font size="2"><a href="/adm/menu">$realm</a> -&gt; <a href="/adm/dropadd">Enrollment Manager</a> -&gt; $page</font><br/>
                    167:   </td>
                    168:   <td align="right" bgcolor="#CCCCFF" valign="top">
                    169:    <font size="+1">Automated Enrollment Manager&nbsp;</font>
                    170:   </td>
                    171:  </tr>
                    172: </table>
                    173: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    174:  <tr>
                    175: ENDTHIS
                    176: }
                    177: 
                    178: sub print_navmenu {
                    179:     my ($r,$tasksref,$tasklongref) = @_;
                    180:     my $action = "information";
                    181:     if (exists($ENV{'form.action'}) ) {
                    182:         $action = $ENV{'form.action'};
                    183:     }
                    184:     $r->print(<<ENDONE);
                    185:   <td width="10" valign="top" bgcolor="#DDFFFF">&nbsp;</td>
                    186:   <td width="20%" valign="top" bgcolor="#DDFFFF">
                    187:    <br/>
                    188: ENDONE
                    189:     foreach my $task (@{$tasksref}) {
                    190:         if ($task eq $action) {
                    191:             $r->print(" 
                    192:    <p>
                    193:    <font color=\"#999999\">
                    194:     <b>$$tasklongref{$task}</b><br/>
                    195:    </font>
                    196:    </p>"); 
                    197:         } else {
                    198:             $r->print("
                    199:    <p>
                    200:    <font color=\"#004263\">
                    201:     <b><a href=\"/adm/populate?action=$task\">$$tasklongref{$task}</a></b><br/>
                    202:    </font> 
                    203:    </p>");
                    204: 
                    205:         }
                    206:     }
                    207:     $r->print("
                    208:   <p>&nbsp;</p>
                    209:   </td>
                    210:   <td width=\"10\" valign=\"top\" bgcolor=\"#CCCCFF\">&nbsp;</td>
                    211:   <td width=\"10\" valign=\"top\" bgcolor=\"#FFFFFF\">&nbsp;</td>
                    212:   <td bgcolor=\"#ffffff\" valign=\"top\">");
                    213: }
                    214: 
                    215: ###############################################################
                    216: 
                    217: sub print_main_frame {
1.13      raeburn   218:   my ($r,$realm,$dom,$crs,$tasktitleref) = @_;
1.1       raeburn   219:   my $action = "information";
                    220:   if (exists($ENV{'form.action'}) ) {
                    221:       $action = $ENV{'form.action'};
                    222:   }
                    223: 
                    224: # Get course settings
                    225:   my %enrollvar;
                    226:   my @bgcolors=("#eeeeee","#cccccc");
                    227:   my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
                    228:   foreach my $item (keys %settings) {
                    229:       if ($item =~ m/^internal\.(.+)$/) {
                    230:           $enrollvar{$1} = $settings{$item};
1.14      raeburn   231:       } elsif ($item =~ /^default_enrollment_(start|end)_date$/) {
                    232:           $enrollvar{$item} = $settings{$item};
1.1       raeburn   233:       }
                    234:   }
                    235: 
                    236:   if ($action eq "information") {
                    237:       $r->print(<<ENDONE);
1.2       raeburn   238:           <br/><table border='0' width='100%'>
1.1       raeburn   239:             <tr>
                    240:               <td>&nbsp;</td>
                    241:               <td><b>Use the menu on the left to choose an enrollment management task.</b><br/><br/></td>
                    242:             <tr>
                    243:               <td>&nbsp;</td>
                    244:               <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>
                    245:             </tr>
                    246:             <tr>
                    247:               <td>&nbsp;</td>
                    248:               <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>
                    249:             </tr>
                    250:             <tr>
                    251:               <td>&nbsp;</td>
1.14      raeburn   252:               <td>Use <i>"Change access dates"</i> to change the default start and/or end dates for student roles created by automated enrollment.</td>
                    253:             </tr>
                    254:             <tr>
                    255:               <td>&nbsp;</td>
1.1       raeburn   256:               <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>
                    257:             </tr>
                    258:             <tr>
                    259:               <td>&nbsp;</td>
                    260:               <td>Use <i>"Change crosslisting"</i> to include or exclude enrollment from crosslisted classes.</td>
                    261:             </tr>
                    262:             <tr>
                    263:               <td>&nbsp;</td>
                    264:               <td>Use <i>"Section settings"</i> to make changes to the choice of sections included for enrollment in your LON-CAPA course.</td>
                    265:             </tr>
                    266:               <td>&nbsp;</td>
1.2       raeburn   267:               <td>Use <i>"Student photos"</i> to enable or disable automatic upload of student photos to your course.</td>
1.1       raeburn   268:             </tr>
                    269:             <tr>
                    270:               <td>&nbsp;</td>
                    271:               <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>
                    272:             </tr>
                    273:             <tr>
                    274:              <td colspan='2'>&nbsp;</td>
                    275:             </tr>
                    276:             <tr>
                    277:              <td>&nbsp;</td>
                    278:              <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>
                    279:             </tr>
                    280:           </table>
                    281: ENDONE
                    282:   } elsif ($action eq "chgsettings") {
                    283:       my @autosets = ("OFF","ON");
                    284:       $r->print(<<ENDTWO);
                    285:                   <form name="enter" method="post"><br/>
                    286: 		  <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    287: 		   <tr>
                    288: 		    <td align="left"><b>$$tasktitleref{$action}</b><br/>
                    289: 		       Currently: Nightly adds: <i>$autosets[$enrollvar{autoadds}]</i>, Nightly drops: <i>$autosets[$enrollvar{autodrops}]</i>
                    290: 		    </td>
                    291:                    </tr>
                    292: 		  </table>
                    293: 		  <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    294: 		    <tr>
                    295: 		     <td>
                    296: 		         Additions based on classlist changes:&nbsp;&nbsp;
                    297: ENDTWO
                    298:       if ($enrollvar{autoadds}) {
                    299:           $r->print("
                    300: 			    <input type=\"radio\" name=\"autoadds\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    301: 			    <input type=\"radio\" name=\"autoadds\" value=\"0\" />&nbsp;Disable
                    302:          ");
                    303:       } else {
                    304:           $r->print("
                    305:                             <input type=\"radio\" name=\"autoadds\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    306:                             <input type=\"radio\" name=\"autoadds\" value=\"0\" checked=\"true\" />&nbsp;Disable
                    307:          ");
                    308:       }
                    309:       $r->print("
                    310:               </td>
                    311:              </tr>
                    312:              <tr>
                    313:               <td>
                    314:  	       Removals based on classlist changes:&nbsp;&nbsp;");
                    315:       if ($enrollvar{autodrops}) {
                    316:           $r->print("
                    317:                 <input type=\"radio\" name=\"autodrops\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    318:                 <input type=\"radio\" name=\"autodrops\" value=\"0\" />&nbsp;Disable");
                    319:       } else {
                    320:           $r->print("
                    321:                 <input type=\"radio\" name=\"autodrops\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;
                    322:                 <input type=\"radio\" name=\"autodrops\" value=\"0\" checked=\"true\" />&nbsp;Disable");
                    323:       }
                    324:       $r->print("
                    325:               </td>
                    326:              </tr>
                    327:              <tr>
                    328:               <td>
                    329:                <font color=\"#888888\">
                    330: 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.
                    331:                </font>
                    332:               </td>
                    333:              </tr>
                    334:              <tr>
                    335:               <td align=\"right\">
                    336:                <input type=\"button\" name=\"chgsettings\" value=\"Go\" onClick=\"process('chgsettings')\" />
                    337: 	      </td>
                    338:              </tr>
                    339: 	    </table>
                    340:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    341:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    342:             </form>
                    343:       ");
                    344:   } elsif ($action eq "setdates") {
1.14      raeburn   345:       my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend},$action);
1.10      raeburn   346:       my $oldstartshow = '';
                    347:       my $oldendshow = '';
                    348:       if ( defined($enrollvar{autostart}) ) {
1.14      raeburn   349:           $oldstartshow = &Apache::lonlocal::locallocaltime($enrollvar{autostart});
1.10      raeburn   350:       }
                    351:       if ( defined($enrollvar{autoend}) ) {
1.14      raeburn   352:           $oldendshow = &Apache::lonlocal::locallocaltime($enrollvar{autoend});
1.10      raeburn   353:           if ($enrollvar{autoend} == 0) {
                    354:               $oldendshow = "No ending date";
                    355:           }
                    356:       }
                    357:       my $dateshow;
                    358:       if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
1.14      raeburn   359:          $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 if you plan to utilise automated adds and/or drops in this course.\n";
1.10      raeburn   360:       } else {
                    361:          $dateshow = "Currently: First enrollment: <b><i>$oldstartshow</i></b>, Last enrollment: <b><i>$oldendshow</i></b>\n";
1.1       raeburn   362:       }
                    363:       $r->print(<<ENDTWO);
                    364:                   <form name="enter" method="post"><br/>              
                    365:                   <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    366: 	           <tr>
1.10      raeburn   367: 	            <td align="left"><b>$$tasktitleref{$action}</b><br/><br/>
                    368:                      $dateshow
1.1       raeburn   369: 	            </td>
                    370:                    </tr>
                    371: 	          </table>
                    372:                   <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    373:                    <tr>
                    374:                     <td align="left" colspan="2">
                    375:                      <table border="0" cellspacing="0" cellpadding="2">
                    376:                       <tr>
                    377:                        <td colspan="3">
                    378:                         <i>Set date of first automated enrollment for registered students</i>
                    379:                        </td>
                    380:                       </tr>
                    381:                       <tr>
                    382:                        <td>$start_table
                    383:                        </td>
                    384:                       </tr>
                    385:                      </table>
                    386:                     </td>
                    387:                    </tr>
                    388:                    <tr>
                    389:                     <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>
                    390:                    </tr>
                    391:                    <tr>
                    392:                     <td align="left" colspan="2">
                    393:                      <table border="0' cellspacing="0" cellpadding="2">
                    394:                       <tr>
                    395:                        <td colspan="3">
                    396:                         <i>Set date of last automated enrollment for registered students</i>
                    397:                        </td>
                    398:                       </tr>
                    399:                       <tr>
                    400:                        <td>$end_table
                    401:                        </td>
                    402:                       </tr>
                    403:                      </table>
                    404:                     </td>
                    405:                    </tr>
                    406:                    <tr>
                    407:                     <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>
                    408:                    </tr>
                    409:                   </table>
                    410:                   <table width="100%">
                    411:                    <tr>
                    412:                     <td align="right">
                    413:                       <input type="button" name="setdates" value="Go" onClick="process('setdates')" />
                    414:                     </td>
                    415: 	           </tr>
                    416:                   </table>
1.14      raeburn   417:                   <input type="hidden" name="action" value="$action">
                    418:                   <input type="hidden" name="state" value="process">
                    419:                   </form>
                    420: ENDTWO
                    421:   } elsif ($action eq "setaccess") {
                    422:       &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
                    423:       $r->print(<<ENDTWO);
                    424:                   <table width="100%">
                    425:                    <tr>
                    426:                     <td align="right">
                    427:                       <input type="button" name="$action" value="Go" onClick="process('$action')" />
                    428:                     </td>
                    429:                    </tr>
                    430:                   </table>
                    431:                   <input type="hidden" name="action" value="$action">
                    432:                   <input type="hidden" name="state" value="process">
1.1       raeburn   433:                   </form>
                    434: ENDTWO
                    435:   } elsif ($action eq "notify") {
                    436:       my @notified = ();
                    437:       if ($enrollvar{notifylist} =~ m/,/) {
                    438:           @notified = split/,/,$enrollvar{notifylist};
                    439:       } else {
                    440:           @notified = $enrollvar{notifylist};
                    441:       }
                    442:       my $notifycount = 0;
                    443:       foreach  (@notified) {
                    444:         unless ($_ eq '') { $notifycount ++; } 
                    445:       }
                    446:       my $noteset = '';
                    447:       if ($notifycount) {
                    448:           $noteset = "ON";
                    449:       } else {
                    450:           $noteset = "OFF";
                    451:       }
                    452:     
                    453:       $r->print("
                    454:                   <form name=\"enter\" method=\"post\"><br/>
                    455:                    <table width=\"100%\" border=\"0\" cellpadding=\"6\" cellspacing=\"0\">
                    456:                     <tr>
                    457:                      <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    458:                       Currently: Notification: $noteset
                    459:                      </td>
                    460:                     </tr>
                    461:                    </table>
                    462:                    <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    463:                     <tr>
                    464:                      <td>
                    465:                       Notification of LON-CAPA course roster changes resulting from nightly automated enrollment process?
                    466:       ");
                    467:       if ($notifycount) {
                    468:           $r->print("
                    469:                         <input type=\"radio\" name=\"notify\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    470:                         <input type=\"radio\" name=\"notify\" value=\"0\" />&nbsp;No
                    471:           ");
                    472:       } else {
                    473:           $r->print("
                    474:                         <input type=\"radio\" name=\"notify\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    475:                         <input type=\"radio\" name=\"notify\" value=\"0\" checked=\"true\" />&nbsp;No
                    476:           ");
                    477:       }
                    478:       $r->print("
                    479:               </td>
                    480:              </tr>
                    481:       ");
1.7       raeburn   482:       my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs);
                    483:       my @ccs = ();
                    484:       my @oldccs = ();
                    485:       my %pname = ();
                    486:       my %notifystate = ();
                    487:       foreach (@coursepersonnel) {
                    488:           my @roleinfo = split/:/,$_;
                    489:           if ($roleinfo[0] eq 'cc')  {
                    490:               unless (grep/^$roleinfo[1]\@$roleinfo[2]/,@ccs) {
                    491:                   my $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc');
                    492:                   if ($active_cc eq 'ok') {
                    493:                       push @ccs, "$roleinfo[1]\@$roleinfo[2]";
                    494:                       $pname{"$roleinfo[1]\@$roleinfo[2]"} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
                    495:                       if (grep/^$roleinfo[1]\@$roleinfo[2]$/,@notified) {
                    496:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 1;
                    497:                       } else {
                    498:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 0;
                    499:                       }
1.1       raeburn   500:                   } else {
1.7       raeburn   501:                       push @oldccs, "$roleinfo[1]\@$roleinfo[2]";
1.1       raeburn   502:                   }
                    503:               }
                    504:           }
                    505:       }
1.7       raeburn   506:       if ($notifycount > 0) {
                    507:           foreach my $person (@notified) {
                    508:               unless ( (grep/^$person$/,@ccs) || ($person eq '') || (grep/^$person$/,@oldccs) ) {
                    509:                   push @ccs, $person;
                    510:                   my ($puname,$pdom) = split/\@/,$person;
                    511:                   $pname{$person} =  &Apache::loncommon::plainname($puname,$pdom);
                    512:                   $notifystate{$person} = 1;
                    513:               }
                    514:           }
                    515:       }
                    516:       my $viewer = $ENV{'user.name'}.'@'.$ENV{'user.domain'};
                    517:       unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') )  {
                    518:           push @ccs,$viewer;
                    519:           $pname{$viewer} =  &Apache::loncommon::plainname($ENV{'user.name'},$ENV{'user.domain'});
                    520:           $notifystate{$viewer} = 0;
                    521:       }
                    522: 
                    523:       my $notifyshow = @ccs;
                    524: 
                    525:       if (@ccs > 0) {
                    526:           @ccs = sort @ccs;
1.1       raeburn   527:           $r->print("
                    528:              <tr>
1.7       raeburn   529:                <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   530:               </td>
                    531:              </tr>
                    532:              <tr>
                    533:               <td>
1.7       raeburn   534:                <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    535:                 <tr bgcolor=\"#CCCCFF\">
                    536:                  <td><b>Name</b></td>
                    537:                  <td><b>username</b></td>
                    538:                  <td><b>Current status</b></td>
                    539:                  <td><b>Notification?</b></td>
                    540:                 </tr>
                    541:           ");
                    542:           for (my $i=0; $i<@ccs; $i++) {
                    543:               my $colflag = $i%2;
                    544:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    545:                  <td>$pname{$ccs[$i]}</td>
                    546:                  <td><input type=\"hidden\" name=\"notifyname_$i\" value=\"$ccs[$i]\" />$ccs[$i]</td>
                    547:                  <td>
                    548:               ");
                    549:               if ($notifystate{$ccs[$i]} == 1) {
                    550:                   $r->print("Notification active");
                    551:               } else {
                    552:                   $r->print("Notification inactive");
                    553:               }
                    554:               if ($notifystate{$ccs[$i]} == 1) {
                    555:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" checked=\"true\" /></td></tr>");
                    556:               } else {
                    557:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" /></td></tr>");
                    558:               }
                    559:           }
                    560:           $r->print("
                    561:                </table>
                    562:                <br/>
                    563:                <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    564:                 <tr>
                    565:                  <td align=\"right\">
                    566:                   <input type=\"button\" name=\"notifyset\" value=\"Go\" onClick=\"process('notify')\" />
                    567:                  </td>
                    568:                 </tr>
                    569:                </table>
                    570:               </td>
                    571:              </tr>
1.1       raeburn   572:           ");
1.7       raeburn   573:       } else {
1.1       raeburn   574:           $r->print("
1.7       raeburn   575:              <tr>
                    576:               <td>
                    577:              No course coordinators found.
1.1       raeburn   578:             </td>
1.7       raeburn   579:            </tr>");
1.1       raeburn   580:       }
                    581:       $r->print("
1.7       raeburn   582:           </table>
                    583:           <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\">
                    584:           <input type=\"hidden\" name=\"action\" value=\"$action\">
                    585:           <input type=\"hidden\" name=\"state\" value=\"process\">
                    586:           </form>
1.1       raeburn   587:       ");
                    588:   } elsif ($action eq "crosslist") {
                    589:       my @xlists = ();
                    590:       if ($enrollvar{crosslistings} =~ m/,/) {
                    591:           @xlists = split/,/,$enrollvar{crosslistings};
                    592:       } elsif ($enrollvar{crosslistings} ne '') {
                    593:           $xlists[0] = $enrollvar{crosslistings};
                    594:       }
                    595:       my $cross_str = @xlists;
                    596:       $r->print("
                    597:             <form name=\"enter\" method=\"post\"><br/>
                    598:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    599:              <tr>
                    600:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    601:       ");
                    602:       if ($cross_str > 0) {
                    603:           $r->print("
1.7       raeburn   604:                 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   605:               </td>
                    606:              </tr>
                    607:             </table>
                    608:             <br/>
                    609:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    610:              <tr>
                    611:               <td>
                    612:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    613:                 <tr bgcolor=\"#CCCCFF\" align=\"left\">
                    614:                  <td><b>Enrollment?</b></td>
                    615:                  <td><b>Crosslisted course</b></td>
                    616:                  <td><b>LON-CAPA section/groupID</b></td>
                    617:                 </tr>
                    618:           ");
                    619:           for (my $i=0; $i<@xlists; $i++) {
                    620:               my $xl = '&nbsp;';
                    621:               my $gp = '&nbsp;';
1.14      raeburn   622:               if ($xlists[$i] =~ /(\w+):?(.*)$/) {
1.1       raeburn   623:                   $xl = $1;
                    624:                   $gp = $2;
                    625:               }               
                    626:               my $colflag = $i%2;
                    627:               $r->print("
                    628:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    629:                  <td><input type=\"checkbox\" name=\"cross_$i\" checked=\"true\"/></td>
                    630:                  <td>$xl</td>
                    631:                  <td><input type =\"text\" size=\"10\" name=\"gp_$i\" value=\"$gp\"></td>
                    632:                 </tr> 
                    633:               ");
                    634:           }
                    635:           $r->print("  </table>
                    636:               </td>
                    637:              </tr>
                    638:             </table>
                    639:           ");
                    640:       }
                    641:       else {
                    642:           $r->print("
                    643:                 Currently no crosslisted courses are recorded for $enrollvar{coursecode}.
                    644:               </td>
                    645:              </tr>
                    646:             </table>
                    647:           ");
                    648:       }
                    649:       $r->print("   
                    650:             <br/>
                    651:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    652:              <tr>
                    653:               <td align=\"left\">
                    654:                <b>Add new crosslistings.</b><br/>
                    655:                Number of new crosslistings to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numcross\" value=\"0\" />
                    656:               </td>
                    657:              </tr>
                    658:             </table>
                    659:             <br/>
                    660:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    661:              <tr>
                    662:               <td align=\"right\">
                    663:                <input type=\"button\" name=\"crosslist\" value=\"Go\" onClick=\"process('crosslist')\" />
                    664:               </td>
                    665:              </tr>
                    666:             </table>
                    667:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    668:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    669:             </form> 
                    670:       ");
                    671:   } elsif ($action eq "sections") {
1.12      raeburn   672:       my @sections = ();
1.13      raeburn   673:       @sections = &Apache::lonnet::auto_get_sections($crs,$dom,$enrollvar{coursecode});
1.1       raeburn   674:       my @storedsections = ();
                    675:       my @currsections = ();
                    676:       my %sec_id = ();
                    677:       if ($enrollvar{sectionnums} =~ m/,/) {
                    678:           @storedsections = split/,/,$enrollvar{sectionnums};
                    679:       } else {
                    680:           $storedsections[0] = $enrollvar{sectionnums};
                    681:       }
                    682:       foreach (@storedsections) {
                    683:           if ($_ =~ m/^(\w+):(\w*)$/) {
                    684:               push @currsections, $1;
                    685:               $sec_id{$1} = $2;
                    686:           }
                    687:       }
                    688:       if (@sections > 0) {
1.8       raeburn   689:           my $secshow = @sections;
                    690:           $r->print("
1.1       raeburn   691:             <form name=\"enter\" method=\"post\"><br/>
                    692:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    693:              <tr>
                    694:               <td align=\"left\">
                    695:                <b>$$tasktitleref{$action}</b><br/>
                    696:                Your institution's course catalog includes $secshow sections for course code: $enrollvar{coursecode}.
                    697:               </td>
                    698:              </tr>
                    699:              <tr>
1.5       raeburn   700:               <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
                    701: your changes.</td>
1.1       raeburn   702:              </tr>
                    703:             </table>
                    704:             <br/>
1.7       raeburn   705:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    706:              <tr bgcolor=\"#CCCCFF\">
                    707:               <td><b>Section</b></td>
                    708:               <td><b>Current status</b></td>              
                    709:               <td><b>LON-CAPA section/group ID</b></td>
                    710:               <td><b>Enrollment in this course?</b></td>
                    711:              </tr>
1.8       raeburn   712:           ");
                    713:           for (my $i=0; $i<@sections; $i++) {
                    714:               my $colflag = $i%2;
                    715:               my $shrflag = 0;
                    716:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.5       raeburn   717:                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" /></td>
1.1       raeburn   718:                    <td>
1.8       raeburn   719:               ");
                    720:               if (grep/^$sections[$i]$/,@currsections) {
                    721:                   $r->print("Enrollment active");
                    722:                   $shrflag = 1;
                    723:               } else {
                    724:                   $r->print("Enrollment inactive");
                    725:               }
                    726:               if ($shrflag) {
                    727:                   $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>"); 
                    728:               } else {
                    729:                   $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   730:               }
1.8       raeburn   731:           }
                    732:           $r->print("
1.7       raeburn   733:             </table>
                    734:             <br/>
                    735:             <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
                    736:              <tr> 
                    737:               <td align=\"right\">
                    738:                <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />
                    739:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    740:               </td>
                    741:              </tr>
                    742:             </table>
                    743:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    744:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    745:             </form>
1.8       raeburn   746:           ");
1.1       raeburn   747:       } else {
                    748:           $r->print("
                    749:             <form name=\"enter\" method=\"post\"><br/>
                    750:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    751:              <tr>
                    752:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    753:           ");
                    754:           if (@currsections) {
                    755:               my $secshow = @currsections;
                    756:               $r->print("
1.7       raeburn   757:                 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   758:               </td>
                    759:              </tr>
                    760:             </table>
                    761:             <br/>
                    762:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    763:              <tr>
                    764:               <td>
                    765:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    766:                 <tr bgcolor=\"#CCCCFF\">
                    767:                  <td><b>Enrollment?</b></td>
                    768:                  <td><b>Section</b></td>
                    769:                  <td><b>LON-CAPA section/groupID</b></td>
                    770:                 </tr>
                    771:               ");
                    772:               for (my $j=0; $j<@currsections; $j++) {
                    773:                   my $colflag = $j%2;
                    774:                   $r->print("
                    775:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    776:                  <td><input type=\"checkbox\" name=\"sec_$j\" checked=\"true\"/></td>
                    777:                  <td>$currsections[$j]</td>
                    778:                  <td><input type=\"text\" name=\"secgp_$j\" size=\"10\" value=\"$sec_id{$currsections[$j]}\"></td>
                    779:                 </tr> 
                    780:                   ");
                    781:               }
                    782:               $r->print("  </table>
                    783:               </td>
                    784:              </tr>
                    785:             </table>
                    786:               ");
                    787:           } else {
                    788:               $r->print("
                    789:                 Currently no sections of $realm ($enrollvar{coursecode}) are contributing enrollment to the LON-CAPA class roster.
                    790:               </td>
                    791:              </tr>
                    792:             </table>
                    793:               ");
                    794:           }
                    795:           $r->print("   
                    796:             <br/>
                    797:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    798:              <tr>
                    799:               <td align=\"left\">
                    800:                <b>Add enrollment from additional sections.</b><br/>
                    801:                Number of new sections to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numsec\" value=\"0\" />
                    802:               </td>
                    803:              </tr>
                    804:             </table>
                    805:             <br/>
                    806:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    807:              <tr>
                    808:               <td align=\"right\">
                    809:                <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
                    810:               </td>
                    811:              </tr>
                    812:             </table>
                    813:             <input type=\"hidden\" name=\"action\" value=\"$action\">
                    814:             <input type=\"hidden\" name=\"state\" value=\"process\">
                    815:             </form> 
                    816:           ");
                    817:       }
                    818:   } elsif ($action eq "photos") {
                    819:       my @photosets = ("OFF","ON");
                    820:       $r->print("
                    821:                   <form name=\"enter\" method=\"post\"><br/>
                    822:                   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    823:                    <tr>
                    824:                     <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    825:                        Currently: Student photo import:  <i>$photosets[$enrollvar{showphotos}]</i>
                    826:                     </td>
                    827:                    </tr>
                    828:                   </table>
                    829:                   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    830:                     <tr>
                    831:                      <td>
                    832:                          Automatic import of student photos from institutional data repository:&nbsp;&nbsp;
                    833: 
                    834:       ");
                    835:       if ($enrollvar{showphotos}) {
                    836:           $r->print("
                    837:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    838:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" />&nbsp;No
                    839:           ");
                    840:       } else {
                    841:           $r->print("
                    842:                         <input type=\"radio\" name=\"showphotos\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;
                    843:                         <input type=\"radio\" name=\"showphotos\" value=\"0\" checked=\"true\" />&nbsp;No
                    844:           ");
                    845:       }
                    846:       $r->print("
                    847:                      </td>
                    848:                     </tr>
                    849:                     <tr>
                    850:                      <td>
                    851:                       <font color=\"#888888\">
                    852: 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.  
                    853:                       </font>
                    854:                      </td>
                    855:                     </tr>
                    856:                     <tr>
                    857:                      </td>&nbsp;</td>
                    858:                     </tr>
                    859:                     <tr>
                    860:                      <td align=\"right\">
                    861:                       <input type=\"button\" name=\"showphotos\" value=\"Go\" onClick=\"process('photos')\">
                    862:                      </td>
                    863:                     </tr>
                    864:                    </table>
                    865:                    <input type=\"hidden\" name=\"action\" value=\"$action\">
                    866:                    <input type=\"hidden\" name=\"state\" value=\"process\">
                    867:                    </form>
                    868:       ");
                    869:   } elsif ($action eq "updatenow") {
                    870:       $r->print("
                    871:                    <form name=\"enter\" method=\"post\"><br/>
                    872: 		   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    873: 		    <tr>
                    874: 		     <td align=\"left\"><b>$$tasktitleref{$action}</b>
                    875: 		     </td>
                    876:                     </tr>
                    877: 		   </table>
                    878: 		   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    879: 		    <tr>
                    880: 		     <td>
                    881: 	              Add any students currently included in institutional classlist(s) but not enrolled in your LON-CAPA course. 
                    882: 		      <input type=\"radio\" name=\"updateadds\" value=\"1\">&nbsp;Yes&nbsp;
                    883: 		      <input type=\"radio\" name=\"updateadds\" value=\"0\">&nbsp;No&nbsp;
                    884:                      </td>
                    885:                     </tr>
                    886:                     <tr>
                    887:                      <td>
                    888:  	              Expire students previously added by nightly enrollment process, but no longer listed in institutional  classlist(s).                  
1.14      raeburn   889:                       <input type=\"radio\" name=\"updatedrops\" value=\"1\">&nbsp;Yes&nbsp;
                    890:                       <input type=\"radio\" name=\"updatedrops\" value=\"0\">&nbsp;No&nbsp;<br/>
                    891:                      </td>
                    892:                     </tr>
                    893:                     <tr>
                    894:                      <td><font color=\"#888888\">
1.1       raeburn   895: 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.
1.14      raeburn   896:                       </font>
                    897:                      </td>
                    898:                     </tr>
                    899:                     <tr>
                    900:                      <td>
                    901:       ");
                    902:       &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
                    903:       $r->print("
                    904:                      </td>
                    905:                     </tr>
                    906:                     <tr>
                    907:                      <td align=\"right\">
                    908:                       <input type=\"button\" name=\"updatenow\" value=\"Go\" onClick=\"process('updatenow')\" />
                    909:                      </td>
                    910:                     </tr>
                    911: 	           </table>
                    912:                    <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    913:                    <input type=\"hidden\" name=\"state\" value=\"process\" />
                    914:                   </form>
                    915:       ");
                    916:   } elsif ($action eq 'viewclass') {
                    917:       $r->print("
                    918:                    <form name=\"studentform\" method=\"post\"><br/>
                    919:                    <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    920:                     <tr>
                    921:                      <td align=\"left\"><b>$$tasktitleref{$action}</b>
                    922:                      </td>
                    923:                     </tr>
                    924:                    </table>
                    925:                    <table>
                    926:                     <tr>
                    927:                      <td>
1.1       raeburn   928:       ");
1.14      raeburn   929:       if (! exists($ENV{'form.sortby'})) {
                    930:           $ENV{'form.sortby'} = 'username';
                    931:       }
                    932:       if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
                    933:           $ENV{'form.Status'} = 'Active';
                    934:       }
                    935:       my $status_select = &Apache::lonhtmlcommon::StatusOptions($ENV{'form.Status'});
                    936: #  Get current classlist
                    937:       my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                    938:       if (! defined($classlist)) {
                    939:           $r->print(&mt('There are no students either currently or previously enrolled.').
                    940:                       "\n");
                    941:       } else {
                    942:           $r->print(&mt('Student Status: [_1]',$status_select)."\n");
                    943:           $r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
                    944:               "\n</p>\n");
                    945: 
                    946:           my $studentcount = &Apache::londropadd::show_class_list($r,'autoenroll','nothing',$ENV{'form.Status'},$classlist,$keylist);
                    947:           $r->print("
                    948:                      </td>
                    949:                     </tr>
                    950:           ");
                    951:           if ($studentcount > 0) {
                    952:               $r->print("
                    953:                     <tr>
                    954:                      <td>&nbsp;</td>
                    955:                     </tr>
                    956:                     <tr>
                    957:                      <td align=\"right\">
                    958:                       <input type=\"button\" name=\"viewclass\" value=\"Go\" onClick=\"process('viewclass')\" />
                    959:                      </td>
                    960:                     </tr>
                    961:               ");
                    962:           }
                    963:           $r->print("
                    964:                    </table>
                    965:                    <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    966:                    <input type=\"hidden\" name=\"state\" value=\"choose\" />
                    967:                   </form>
                    968:           ");
                    969:       }
1.1       raeburn   970:   }
                    971: }
                    972: 
1.14      raeburn   973: sub print_accessdate_table {
                    974:     my ($r,$enrollvar,$tasktitleref,$action) = @_;
                    975:     my ($start_table,$end_table) = &date_setting_table($$enrollvar{'default_enrollment_start_date'},$$enrollvar{'default_enrollment_end_date'},$action);
                    976:     my $oldstartshow = '';
                    977:     my $oldendshow = '';
                    978:     if ( defined($$enrollvar{'default_enrollment_start_date'}) ) {
                    979:         $oldstartshow = &Apache::lonlocal::locallocaltime($$enrollvar{'default_enrollment_start_date'});
                    980:     }
                    981:     if ( defined($$enrollvar{'default_enrollment_end_date'}) ) {
                    982:         $oldendshow = &Apache::lonlocal::locallocaltime($$enrollvar{default_enrollment_end_date});
                    983:         if ($$enrollvar{'default_enrollment_end_date'} eq '0') {
                    984:             $oldendshow = "No ending date";
                    985:         }
                    986:     }
                    987:     my %lt =&Apache::lonlocal::texthash(
                    988:          'cuno' => 'Currently NO default first access or last access dates are set.',
                    989:          'ifyo' => 'If you do not set a start date and an end date, then student roles for students added by the automated enrollment process will start immediately when the student is added and will never become inactive.',
                    990:          'ifyd' => 'If you do not set an access start date and an end date, then student roles for new students added when you click "Go" will become active immediately and will never become inactive.',
                    991:          'setf' => 'Set date of first access',
                    992:          'setl' => 'Set date of last access',
                    993:          'freg' => 'for registered students added via automated enrollment',
                    994:          'fnew' => 'for new students added when you update the class roster',
                    995:          'ifad'  => 'If automated adds are enabled, then when students are added their student roles will become active on the date set here for first access, and their roles will become inactive on the date set here for last access.  These default access dates will be overridden for specific students if the institutional classlist data supplied to the automatic enrollment process includes entries for the startdate and enddate fields for those students.'
                    996:     );
                    997:     my $dateshow;
                    998:     if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
                    999:        $dateshow = "<br/><font size='+1'>".&mt('Warning')."</font>.&nbsp;".$lt{'cuno'}." ";
                   1000:        if ($action eq 'setaccess') {
                   1001:            $dateshow .= $lt{'ifyo'}."\n";
                   1002:        } elsif ($action eq 'updatenow') {
                   1003:            $dateshow .= $lt{'ifyd'}."\n";
                   1004:        }
                   1005:     } else {
                   1006:         $dateshow = &mt('Currently: default first access').": <b><i>$oldstartshow</i></b>, ".&mt('default last access').": <b><i>$oldendshow</i></b>\n";
                   1007:     }
                   1008:     if ($action eq 'setaccess') {
                   1009:         $r->print(<<ENDONE);
                   1010:                 <form name="enter" method="post"><br/>
                   1011:                 <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   1012:                  <tr>
                   1013:                   <td align="left"><b>$$tasktitleref{$action}</b>
                   1014:                   <br /><br />
                   1015:                    $dateshow
                   1016:                   </td>
                   1017:                  </tr>
                   1018:                 </table>
                   1019: ENDONE
                   1020:     } elsif ($action eq 'updatenow') {
                   1021:         $r->print("
                   1022:                 <br /><br />$dateshow\n");
                   1023:     }
                   1024:     $r->print(<<ENDTWO);
                   1025:                 <table width="100%" border="0" cellpadding="3" cellspacing="3">
                   1026:                  <tr>
                   1027:                   <td align="left" colspan="2">
                   1028:                    <table border="0" cellspacing="0" cellpadding="2">
                   1029:                     <tr>
                   1030:                      <td colspan="3">
                   1031: ENDTWO
                   1032:       if ($action eq 'setaccess') {
                   1033:           $r->print("<i>$lt{'setf'} $lt{'freg'}</i>");
                   1034:       } elsif ($action eq 'updatenow') {
                   1035:           $r->print("<i>$lt{'setf'} $lt{'fnew'}</i>");
                   1036:       }
                   1037:       $r->print(<<ENDTHREE); 
                   1038:                        </td>
                   1039:                       </tr>
                   1040:                       <tr>
                   1041:                        <td>$start_table
                   1042:                        </td>
                   1043:                       </tr>
                   1044:                      </table>
                   1045:                     </td>
                   1046:                    </tr>
                   1047:                    <tr>
                   1048:                     <td align="left" colspan="2">
1.15    ! albertel 1049:                      <table border="0" cellspacing="0" cellpadding="2">
1.14      raeburn  1050:                       <tr>
                   1051:                        <td colspan="3">
                   1052: ENDTHREE
                   1053:     if ($action eq 'setaccess') {
                   1054:         $r->print("<i>$lt{'setl'} $lt{'freg'}</i>");
                   1055:     } elsif ($action eq 'updatenow') {
                   1056:         $r->print("<i>$lt{'setl'} $lt{'fnew'}</i>");
                   1057:     }
                   1058:     $r->print(<<ENDFOUR); 
                   1059:                        </td>
                   1060:                       </tr>
                   1061:                       <tr>
                   1062:                        <td>$end_table
                   1063:                        </td>
                   1064:                       </tr>
                   1065:                      </table>
                   1066:                     </td>
                   1067:                    </tr>
                   1068: ENDFOUR
                   1069:     if ($action eq 'setaccess') {
                   1070:         $r->print("
                   1071:                    <tr>
                   1072:                     <td colspan=\"2\"><font color=\"#888888\">$lt{'ifad'}</font></td>
                   1073:                    </tr>
                   1074:                   </table>
                   1075:         ");
                   1076:     } elsif ($action eq 'updatenow') {
                   1077:         $r->print("
                   1078:                    </tr>
                   1079:                   </table>
                   1080:         ");
                   1081:     }
                   1082: }
                   1083: 
1.1       raeburn  1084: ###############################################################
                   1085: sub print_doc_base {
1.15    ! albertel 1086:     my $r = shift;
        !          1087:     $r->print(<<ENDBASE);
1.1       raeburn  1088:   </td>
                   1089:  </tr>
                   1090: </table>
                   1091: <br/>
                   1092: </body>
                   1093: </html> 
                   1094: ENDBASE
                   1095: }
                   1096:  
                   1097: ###################################################################
                   1098: sub print_chgsettings_response {
1.15    ! albertel 1099:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1100:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
        !          1101:     my $currend = '';
        !          1102:     my $currstart = '';
        !          1103:     my $currsecs = '';
        !          1104:     my $currxlists = '';
        !          1105:     my $curradds = '';
        !          1106:     my $currdrops = '';
        !          1107:     if ( defined($settings{'internal.autoadds'}) ) {
        !          1108: 	$curradds = $settings{'internal.autoadds'};
        !          1109:     }
        !          1110:     if ( defined($settings{'internal.autodrops'}) ) {
        !          1111: 	$currdrops = $settings{'internal.autodrops'};
        !          1112:     }
        !          1113:     if ( defined($settings{'internal.autostart'}) ) {
        !          1114: 	$currstart = $settings{'internal.autostart'};
        !          1115:     }
        !          1116:     if ( defined($settings{'internal.autoend'}) ) {
        !          1117: 	$currend = $settings{'internal.autoend'};
        !          1118:     }
        !          1119:     if ( defined($settings{'internal.sectionnums'}) ) {
        !          1120: 	$currsecs = $settings{'internal.sectionnums'};
        !          1121:     }
        !          1122:     if ( defined($settings{'internal.crosslistings'}) ) {
        !          1123: 	$currxlists = $settings{'internal.crosslistings'}
        !          1124:     }
        !          1125:     my $autoadds = '';
        !          1126:     my $autodrops = '';
1.1       raeburn  1127: 
1.15    ! albertel 1128:     if ( exists($ENV{'form.autoadds'}) ) {
        !          1129: 	$autoadds=$ENV{'form.autoadds'};
        !          1130:     }
        !          1131:     if ( exists($ENV{'form.autodrops'}) ) {
        !          1132: 	$autodrops=$ENV{'form.autodrops'};
        !          1133:     }
        !          1134: 
        !          1135:     my $response = "";
        !          1136:     my $warning = "";
        !          1137:     my $warn_prefix = "";
        !          1138:     my $warn_suffix = "";
        !          1139:     my $warnfiller = "";
        !          1140:     my %cenv = ('internal.autoadds' => $autoadds,
        !          1141: 		'internal.autodrops' => $autodrops);
        !          1142:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1143:     if ($reply !~ /^ok$/) {
        !          1144: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !          1145:     } else {
        !          1146: 	if ($autoadds) {
        !          1147: 	    if ($curradds) {
        !          1148: 		$response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
        !          1149: 	    } else {
        !          1150: 		$response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
        !          1151: 	    }
        !          1152: 	} else {
        !          1153: 	    if ($curradds) {
        !          1154: 		$response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
        !          1155: 	    } else {
        !          1156: 		$response = "Nightly additions based on classlist changes still <b>disabled</b><br/>";
        !          1157: 	    }
        !          1158: 	}
        !          1159: 	if ($autodrops) {
        !          1160: 	    if ($currdrops) {
        !          1161: 		$response .= "Nightly removals based on classlist changes still <b>enabled</b><br>";
        !          1162: 	    } else {
        !          1163: 		$response .= "Nightly removals based on classlist changes now <b>enabled</b><br/>";
        !          1164: 	    }
        !          1165: 	} else {
        !          1166: 	    if ($currdrops) {
        !          1167: 		$response .= "Nightly removals based on classlist changes now <b>disabled</b><br>";
        !          1168: 	    } else {
        !          1169: 		$response .= "Nightly removals based on classlist changes still <b>disabled</b>";
        !          1170: 	    }
        !          1171: 	}
        !          1172: 	if ($autoadds || $autodrops) {
        !          1173: 	    $warning = &warning_message($dom,$crs,$action);
        !          1174: 	    $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you indicated that nightly ";
        !          1175: 	    $warn_suffix = " should be enabled, additional action is required.<br/>";
        !          1176: 	}
        !          1177: 	if ($autoadds) {
        !          1178: 	    if ($autodrops) {
        !          1179: 		$warnfiller = "adds and drops";
        !          1180: 	    } else {
        !          1181: 		$warnfiller = "adds";
        !          1182: 	    }
        !          1183: 	} else {
        !          1184: 	    if ($autodrops) {
        !          1185: 		$warnfiller = "drops";
        !          1186: 	    }
        !          1187: 	}
        !          1188: 	unless ($warning eq '') {
        !          1189: 	    $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
        !          1190: 	}
        !          1191:     }
        !          1192:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1193:     return;
1.1       raeburn  1194: }
                   1195: 
                   1196: sub print_setdates_response {
1.15    ! albertel 1197:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1198:     my %settings = &Apache::lonnet::get('environment',['internal.autostart','internal.autoend'],$dom,$crs);
        !          1199:     my $currstart = $settings{'internal.autostart'};
        !          1200:     my $currend = $settings{'internal.autoend'};
        !          1201:     my $response = '';
        !          1202:     my ($autostart,$autoend) = &get_dates_from_form();
        !          1203:     my $showstart = &Apache::lonlocal::locallocaltime($autostart);
        !          1204:     my $showend = '';
        !          1205:     my $warning = '';
        !          1206:     my $warn_prefix = '';
        !          1207:     if ($autoend) {
        !          1208: 	$showend = &Apache::lonlocal::locallocaltime($autoend);
        !          1209:     } else {
        !          1210: 	$showend = "'No end date'";
        !          1211:     } 
        !          1212: 
        !          1213:     my %cenv = ('internal.autostart' => $autostart,
        !          1214: 		'internal.autoend' => $autoend);
        !          1215:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1216:     if ($reply !~ /^ok$/) {
        !          1217: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !          1218:     } else {
        !          1219: 	if ($currstart == $autostart) {
        !          1220: 	    $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
        !          1221: 	} else {
        !          1222: 	    $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
        !          1223: 	} 
        !          1224: 	if ($currend == $autoend) {
        !          1225: 	    $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
        !          1226: 	} else {
        !          1227: 	    $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
        !          1228: 	}
1.1       raeburn  1229:  
1.14      raeburn  1230: # Generate message in case where old first enrollment date was later than today, but new first enrollment date is now today or earlier.
1.1       raeburn  1231: 
1.15    ! albertel 1232: 	my $rosterupdated = 0;
        !          1233: 	my $firstaccess = "";
        !          1234: 	my $nextupdate = "";
        !          1235: 	my $lastupdate = "";
        !          1236: 
        !          1237: 	my $nowstamp = time;
        !          1238: 	my @date_list=localtime(time);
        !          1239: 	my $cur_year = $date_list[5];
        !          1240: 	my $curday = $date_list[3];
        !          1241: 	my $curmonth = $date_list[4];
        !          1242: 	my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
        !          1243: 	my $nextmidnt = 86400 + $lastmidnt;
        !          1244: 
        !          1245: 	my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
        !          1246: 	my $lastupdate = $todayupdate - 86400;
        !          1247: 	if ($nowstamp < $todayupdate) {
        !          1248: 	    $nextupdate = "today";
        !          1249: 	} else {
        !          1250: 	    $nextupdate = "tomorrow";
        !          1251: 	}
        !          1252: 	if ($currstart < $lastupdate) {
        !          1253: 	    $rosterupdated = 1;
        !          1254: 	}
        !          1255: 	if ($autostart < $nextmidnt ) {
        !          1256: 	    if ( $autostart >= $lastmidnt) {
        !          1257: 		$firstaccess = "today";
        !          1258: 	    } else {
        !          1259: 		$firstaccess = "a date prior to today";
        !          1260: 	    }
        !          1261: 	    if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
        !          1262: 		$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 immediately enroll registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;
        !          1263: 	    }
        !          1264: 	}
        !          1265: 	$warning = &warning_message($dom,$crs,$action);
        !          1266: 	$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/>";
        !          1267: 	unless ($warning eq '') {
        !          1268: 	    $response .= $warn_prefix.$warning;
        !          1269: 	}
        !          1270:     }
        !          1271:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1272:     return;
1.1       raeburn  1273: }
                   1274: 
1.14      raeburn  1275: sub print_setaccess_response {
1.15    ! albertel 1276:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1277:     my %settings = &Apache::lonnet::get('environment',['default_enrollment_start_date','default_enrollment_end_date','internal.autostart'],$dom,$crs);
        !          1278:     my $currstart = $settings{'default_enrollment_start_date'};
        !          1279:     my $currend = $settings{'default_enrollment_end_date'};
        !          1280:     my $autostart = $settings{'internal.autostart'};
        !          1281:     my $response = '';
        !          1282:     my ($startaccess,$endaccess) = &get_dates_from_form();
        !          1283:     my $showstart = &Apache::lonlocal::locallocaltime($startaccess);
        !          1284:     my $showend = '';
        !          1285:     my $warning = '';
        !          1286:     my $warn_prefix = '';
        !          1287:     if ($endaccess) {
        !          1288: 	$showend = &Apache::lonlocal::locallocaltime($endaccess);
        !          1289:     } else {
        !          1290: 	$showend = "'No end date'";
        !          1291:     }
        !          1292: 
        !          1293:     my %cenv = ('default_enrollment_start_date' => $startaccess,
        !          1294: 		'default_enrollment_end_date' => $endaccess);
        !          1295:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1296:     if ($reply !~ /^ok$/) {
        !          1297: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !          1298:     } else {
        !          1299: 	if ($currstart == $startaccess) {
        !          1300: 	    $response = "The first access date for students added via automated enrollment has been left unchanged as $showstart.<br/>";
        !          1301: 	} else {
        !          1302: 	    $response = "The first access date for students added via automated enrollment has been changed to
1.14      raeburn  1303: $showstart.<br/>";
1.15    ! albertel 1304: 	}
        !          1305: 	if ($currend == $endaccess) {
        !          1306: 	    $response .= "The last access date for students added via automated enrollment has been left unchanged as $showend.<br/>";
        !          1307: 	} else {
        !          1308: 	    $response .= "The last access date for students automated enrollment has been changed to
1.14      raeburn  1309: $showend.<br/>";
1.15    ! albertel 1310: 	}
        !          1311: 	
1.14      raeburn  1312: # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.
1.15    ! albertel 1313: 	
        !          1314: 	my $accessgiven= 0;
        !          1315: 	my $firstaccess = "";
        !          1316: 	my $nextupdate = "";
        !          1317: 	my $lastupdate = "";
        !          1318: 
        !          1319: 	my $nowstamp = time;
        !          1320: 	my @date_list=localtime(time);
        !          1321: 	my $cur_year = $date_list[5];
        !          1322: 	my $curday = $date_list[3];
        !          1323: 	my $curmonth = $date_list[4];
        !          1324: 	my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
        !          1325: 	my $nextmidnt = 86400 + $lastmidnt;
        !          1326: 
        !          1327: 	my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
        !          1328: 	my $tomorrowupdate = $todayupdate + 86400;
        !          1329: 	my $lastupdate = $todayupdate - 86400;
        !          1330: 
        !          1331: 	if ($autostart < $nextmidnt) {
        !          1332: 	    if ($nowstamp < $todayupdate) {
        !          1333: 		$nextupdate = "at 1.30 am today";
        !          1334: 	    } else {
        !          1335: 		$nextupdate = "at 1.30 am tomorrow";
        !          1336: 	    }
        !          1337: 	} else {
        !          1338: 	    my @enrollstart = &Apache::lonlocal::locallocaltime($autostart);
        !          1339: 	    $nextupdate = timelocal(0,30,1,$enrollstart[3],$enrollstart[4],$enrollstart[5]);
        !          1340: 	    unless (($enrollstart[2] < 1) || ($enrollstart[2] == 1 && $enrollstart[1] <=30))  {
        !          1341: 		$nextupdate += 86400; 
        !          1342: 	    }
        !          1343: 	    $nextupdate = &Apache::lonlocal::locallocaltime($nextupdate);
        !          1344: 	}
        !          1345: 	if (($currstart < $lastupdate) && ($autostart < $lastupdate)) {
        !          1346: 	    $accessgiven = 1;
        !          1347: 	}
        !          1348: 	if ($startaccess < $nextmidnt ) {
        !          1349: 	    if ( $startaccess >= $lastmidnt) {
        !          1350: 		$firstaccess = "today";
        !          1351: 	    } else {
        !          1352: 		$firstaccess = "a date prior to today";
        !          1353: 	    }
        !          1354: 	    if (($nowstamp >= $startaccess) && ($accessgiven == 0)) {
        !          1355: 		$response .= qq|<br>Although you have now set the first access date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses $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>|;
        !          1356: 	    }
        !          1357: 	}
        !          1358: 	$warning = &warning_message($dom,$crs,$action);
        !          1359: 	$warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have set default first and last access dates for students who are added via automatic enrollment, additional action is required.<br/>";
        !          1360: 	unless ($warning eq '') {
        !          1361: 	    $response .= $warn_prefix.$warning;
        !          1362: 	}
        !          1363:     }
        !          1364:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1365:     return;
1.14      raeburn  1366: }
                   1367: 
1.1       raeburn  1368: sub print_notify_response {
1.15    ! albertel 1369:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.1       raeburn  1370: 
                   1371: # Get current settings
1.15    ! albertel 1372:     my %settings = &Apache::lonnet::get('environment',['internal.notifylist','internal.coursecode'],$dom,$crs);
        !          1373:     my $notifylist = $settings{'internal.notifylist'};
        !          1374:     my $coursecode = $settings{'internal.coursecode'};
        !          1375:     my @currpeople = ();
        !          1376:     my $notify = 0;
        !          1377:     my @people = ();
        !          1378:     my $peoplestr = "";
        !          1379:     my $response = "";
        !          1380:     my $noprocess = 0;
1.1       raeburn  1381: 
1.15    ! albertel 1382:     if ($notifylist =~ m/,/) {
        !          1383: 	@currpeople = split/,/,$notifylist;
        !          1384:     } else {
        !          1385: 	$currpeople[0] = $notifylist;
        !          1386:     }
        !          1387:     my $currcount = 0;
        !          1388:     foreach  (@currpeople) {
        !          1389: 	unless ($_ eq '') { $currcount ++; } 
        !          1390:     }
        !          1391: 
        !          1392:     if ( exists($ENV{'form.notify'}) ) {
        !          1393: 	$notify=$ENV{'form.notify'};
        !          1394:     }
        !          1395:     if ( exists($ENV{'form.notifyshow'}) ) {
        !          1396: 	my $notifyshow = $ENV{'form.notifyshow'};
        !          1397: 	for (my $i=0; $i<$notifyshow; $i++) {
        !          1398: 	    if ( exists($ENV{"form.note_$i"}) ) {
        !          1399: 		if ( exists($ENV{"form.notifyname_$i"}) ) {
        !          1400: 		    unless ( $ENV{"form.notifyname_$i"} eq '' ) {
        !          1401: 			push @people, $ENV{"form.notifyname_$i"};
        !          1402: 		    }
        !          1403: 		}
        !          1404: 	    }
        !          1405: 	}
        !          1406: 	if ($notify) { $peoplestr = join(",",@people); }
        !          1407:     } else {
        !          1408: 	if ($notify) {
        !          1409: 	    if ($currcount) {
        !          1410: 		$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/>.";
        !          1411: 		$peoplestr = $notifylist;
        !          1412: 		@people = @currpeople;
        !          1413: 		$noprocess = 1;
        !          1414: 	    }
        !          1415: 	}
        !          1416:     }
        !          1417:     unless ($noprocess == 1) {
        !          1418: 	my %cenv = ('internal.notifylist' => $peoplestr);
        !          1419: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1420: 	if ($reply !~ /^ok$/) {
        !          1421: 	    $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
        !          1422: 	} else {
        !          1423: 	    if ($notify) {
        !          1424: 		if (@people) {
        !          1425: 		    if ($currcount) {
        !          1426: 			$response .= "Notification of enrollment changes still <b>enabled</b><br/>";
        !          1427: 		    } else {
        !          1428: 			$response .= "Notification of enrollment changes now <b>enabled</b><br/>";
        !          1429: 		    }
        !          1430: 		    $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";
        !          1431: 		    foreach my $person (@people) {
        !          1432: 			$response .= "<li>$person</li>\n";
        !          1433: 		    }
        !          1434: 		    $response .= "</ul>\n";
        !          1435: 		} else {
        !          1436: 		    $response = "Notification of enrollment changes was <b> not enabled</b> as no course coordinators were selected as recipients.<br/>";
        !          1437: 		}
        !          1438: 	    } else {
        !          1439: 		if ($currcount) {
        !          1440: 		    $response = "Notification of enrollment changes now <b>disabled</b><br/>";
        !          1441: 		} else {
        !          1442: 		    $response = "Notification of enrollment changes still <b>disabled</b><br/>";
        !          1443: 		}
        !          1444: 	    }
        !          1445: 	}
        !          1446:     }
        !          1447:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1448:     return;
1.1       raeburn  1449: }
                   1450: 
                   1451: sub print_crosslistings_menu () {
1.15    ! albertel 1452:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1453:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
        !          1454:     my @currxlists = ();
        !          1455:     my @xlists = ();
        !          1456:     my $crosscount = 0;
        !          1457:     my $removecount = 0;
        !          1458:     my $xliststr = '';
        !          1459:     my $response = '';
        !          1460:     my $coursecode = $settings{'internal.coursecode'};
        !          1461:     if ($settings{'internal.crosslistings'} =~ m/,/) {
        !          1462: 	@currxlists = split/,/,$settings{'internal.crosslistings'};
        !          1463:     } elsif ($settings{'internal.crosslistings'} ne '') {
        !          1464: 	$currxlists[0] = $settings{'internal.crosslistings'};
        !          1465:     }
        !          1466: 
        !          1467:     if (@currxlists > 0) {
        !          1468: 	for (my $i=0; $i<@currxlists; $i++) {
        !          1469: 	    my $xlist = "cross_".$i;
        !          1470: 	    my $gp = "gp_".$i;
        !          1471: 	    if ( exists($ENV{"form.$xlist"}) ) {
        !          1472: 		my $xlistentry = '';
        !          1473: 		if ($currxlists[$i] =~ m/^([^:]+)/) {
        !          1474: 		    $xlistentry = $1.':';
        !          1475: 		}
        !          1476: 		if ( exists($ENV{"form.$gp"}) ) {
        !          1477: 		    $xlistentry .= $ENV{"form.$gp"};
        !          1478: 		}
        !          1479: 		push @xlists,$xlistentry;
        !          1480: 		$crosscount ++;
        !          1481: 	    } else {
        !          1482: 		$removecount ++;
        !          1483: 	    }
        !          1484: 	}
        !          1485:     }
1.1       raeburn  1486: 
1.15    ! albertel 1487:     if ($crosscount > 1) {
        !          1488: 	$xliststr = join(",",@xlists);
        !          1489:     } else {
        !          1490: 	$xliststr = $xlists[0];
        !          1491:     }
        !          1492:     my %cenv = ('internal.crosslistings' => $xliststr);
        !          1493:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1494:     if ($reply !~ /^ok$/) {
        !          1495: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !          1496:     } else {
        !          1497: 	if ($removecount > 0) {
        !          1498: 	    $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
        !          1499: 	}
        !          1500: 	if ($crosscount > 0) {
        !          1501: 	    $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";
        !          1502: 	    foreach (@xlists) {
        !          1503: 		my ($xlist,$gp) = split/:/,$_;
        !          1504: 		$response .= "<li>$xlist - ID: $gp</li>\n";
        !          1505: 	    }
        !          1506: 	    $response .= "</ul><br/>\n";
        !          1507: 	}
        !          1508:     }
        !          1509:     if ( exists($ENV{'form.numcross'}) ) {
        !          1510: 	my $numcross = $ENV{'form.numcross'};
        !          1511: 	if ($numcross > 0) {
        !          1512: 	    my @bgcolors=("#eeeeee","#cccccc");
        !          1513: 	    $response .= qq(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/>
1.1       raeburn  1514:            <form name="enter" method="post">
                   1515:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1516:              <tr>
                   1517:               <td>
                   1518:                <table border="0" cellspacing="3" cellpadding="3">
                   1519:                 <tr bgcolor="#CCCCFF" align="left">
                   1520:                  <td><b>Crosslisting</b></td>
                   1521:                  <td><b>LON-CAPA section/groupID</b></td>
                   1522:                 </tr>
1.15    ! albertel 1523: 			    );
        !          1524: 	    for (my $i=0; $i<$numcross; $i++) {
        !          1525: 		my $colflag = $i%2;
        !          1526: 		$response .= qq(
1.1       raeburn  1527:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1528:                  <td><input type="text" size="15" name="newcross_$i" /></td>
                   1529:                  <td><input type="text" size="10" name="newgroupid_$i" /></td>
                   1530:                 </tr>
1.15    ! albertel 1531: 				);
        !          1532: 	    }
        !          1533: 	    $response .= qq(  </table>
1.1       raeburn  1534:               </td>
                   1535:              </tr>
                   1536:              <tr>
                   1537:               <td align="right">
                   1538:                <input type="button" name="newcross" value="Go" onClick="process('newcross')" />
                   1539:               </td>
                   1540:              </tr>
                   1541:             </table>
                   1542:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\">
                   1543:             <input type=\"hidden\" name=\"action\" value=\"newcross\">
                   1544:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1545:             </form>
1.15    ! albertel 1546: 			      );
        !          1547:         }
        !          1548:     }
        !          1549:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1550:     return;
1.1       raeburn  1551: }
                   1552: 
                   1553: sub print_crosslistings_response () {
1.15    ! albertel 1554:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1555:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
        !          1556:     my @currxlists = ();
        !          1557:     my @xlists = ();
        !          1558:     my @allxlists = ();
        !          1559:     my @badxlists = ();
        !          1560:     my @badowner = ();
        !          1561:     my $numcross = 0;
        !          1562:     my $xliststr =  $settings{'internal.crosslistings'};
        !          1563:     my $coursecode = $settings{'internal.coursecode'};
        !          1564:     my $owner = $settings{'internal.courseowner'};
        !          1565:     my $response = '';
        !          1566:     my $warning = '';
        !          1567:     my $warn_prefix = '';
1.1       raeburn  1568: 
1.15    ! albertel 1569:     if ($xliststr =~ m/,/) {
        !          1570: 	@allxlists = split/,/,$xliststr;
        !          1571:     } else {
        !          1572: 	unless ($xliststr eq '') { $allxlists[0] = $xliststr; }
        !          1573:     }
1.1       raeburn  1574: 
1.15    ! albertel 1575:     if ( exists($ENV{'form.numcross'}) ) {
        !          1576: 	$numcross = $ENV{'form.numcross'};
        !          1577:     }
1.1       raeburn  1578: 
1.15    ! albertel 1579:     if ($numcross > 0) {
        !          1580: 	for (my $i=0; $i<$numcross; $i++) {
        !          1581: 	    my $xl = "newcross_".$i;
        !          1582: 	    my $gp = "newgroupid_".$i;
        !          1583: 	    if ( exists($ENV{"form.$xl"}) ) {
        !          1584: 		my $coursecheck = '';
        !          1585: 		$coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$ENV{"form.$xl"});
        !          1586: 		if ($coursecheck eq 'ok') {
        !          1587: 		    my $addcheck = '';
        !          1588: 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$ENV{"form.$xl"},$owner);
        !          1589: 		    if ($addcheck eq 'ok') {
        !          1590: 			push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
        !          1591: 		    } else {
        !          1592: 			push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
        !          1593: 		    }
        !          1594: 		} else {
        !          1595: 		    push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck;
        !          1596: 		}
        !          1597: 	    }
        !          1598: 	}
        !          1599: 	push @allxlists, @xlists;
        !          1600:     }
        !          1601:     
        !          1602:     if (@xlists > 0 ) {
        !          1603: 	unless ($xliststr eq '') { $xliststr .= ","; }
        !          1604: 	if (@xlists > 1) {
        !          1605: 	    $xliststr .= join(",",@xlists);
        !          1606: 	} else {
        !          1607: 	    $xliststr .= $xlists[0];
        !          1608: 	}
        !          1609: 	my %cenv = ('internal.crosslistings' => $xliststr);
        !          1610: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1611: 	if ($reply !~ /^ok$/) {
        !          1612: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
        !          1613: 	} else {
        !          1614: 	    $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";
        !          1615: 	    foreach (@allxlists) {
        !          1616: 		my ($xlist,$gp) = split/:/,$_;
        !          1617: 		$response .= "<li>$xlist - ID: $gp</li>\n";
        !          1618: 	    }
        !          1619: 	    $response .= "</ul><br/><br/>\n";
        !          1620: 	}
        !          1621:     } else {
        !          1622: 	if ($xliststr =~ m/:/) {
        !          1623: 	    my @oldxlists = ();
        !          1624: 	    if ($xliststr =~ m/,/) {
        !          1625: 		@oldxlists = split/,/,$xliststr;
        !          1626: 	    } else {
        !          1627: 		$oldxlists[0] = $xliststr;
        !          1628: 	    }
        !          1629: 	    $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
        !          1630: 	    foreach (@oldxlists) {
        !          1631: 		my ($xlist,$gp) = split/:/,$_;
        !          1632: 		$response .= "<li>$xlist - ID: $gp</li>\n";
        !          1633: 	    }
        !          1634: 	    $response .= "</ul><br/><br/>\n";
        !          1635: 	}
        !          1636:     }
        !          1637:     if (@badxlists > 0) {
        !          1638: 	$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";
        !          1639: 	foreach (@badxlists) {
        !          1640: 	    my ($xlist,$gp,$prob) = split/:/,$_;
        !          1641: 	    $response .= "<li>$xlist - ID: $gp - Error: $prob</li>\n";
        !          1642: 	}
        !          1643: 	$response .= "</ul><br/><br/>\n";
        !          1644:     }
        !          1645:     
        !          1646:     if (@badowner > 0) {
        !          1647: 	$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";
        !          1648: 	foreach (@badowner) {
        !          1649: 	    my ($xlist,$gp) = split/:/,$_;
        !          1650: 	    $response .= "<li>$xlist - ID: $gp</li>\n";
        !          1651: 	}
        !          1652: 	$response .= "</ul><br/><br/>\n";
        !          1653:     }
1.5       raeburn  1654: 
1.15    ! albertel 1655:     if (@allxlists > 0) {
        !          1656: 	$warning = &warning_message($dom,$crs,$action);
        !          1657: 	$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/>";
        !          1658: 	unless ($warning eq '') {
        !          1659: 	    $response .= $warn_prefix.$warning;
        !          1660: 	}
        !          1661:     }
1.1       raeburn  1662: 
1.15    ! albertel 1663:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1664:     return;
1.1       raeburn  1665: }
                   1666: 
                   1667: sub print_sections_menu () {
1.15    ! albertel 1668:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1669:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
        !          1670:     my @currsections = ();
        !          1671:     my @sections = ();
        !          1672:     my @badowner = ();
        !          1673:     my @badsections = ();
        !          1674:     my $seccount = 0;
        !          1675:     my $removecount = 0;
        !          1676:     my $addcount = 0;
        !          1677:     my $secstr = '';
        !          1678:     my $response = '';
        !          1679:     my $warning = "";
        !          1680:     my $warn_prefix = "";
        !          1681:     my $coursecode = $settings{'internal.coursecode'};
        !          1682:     my $owner = $settings{'internal.courseowner'};
        !          1683:     if ($settings{'internal.sectionnums'} =~ m/,/) {
        !          1684: 	@currsections = split/,/,$settings{'internal.sectionnums'};
        !          1685:     } elsif ($settings{'internal.sectionnums'} ne '') {
        !          1686: 	$currsections[0] = $settings{'internal.sectionnums'};
        !          1687:     }
        !          1688:     
        !          1689:     if ( exists($ENV{'form.secshow'}) ) {
        !          1690: 	for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
        !          1691: 	    my $gp = "loncapasec_".$i;
        !          1692: 	    my $secnum = "secnum_".$i;
        !          1693: 	    my $sec = "sec_".$i;
        !          1694: 	    if ( exists( $ENV{"form.$sec"} ) ) {
        !          1695: 		my $secentry;
        !          1696: 		if ( exists( $ENV{"form.$secnum"} ) ) { 
        !          1697: 		    $secentry = $ENV{"form.$secnum"}.':';
        !          1698: 		}
        !          1699: 		if ( exists( $ENV{"form.$gp"} ) ) {
        !          1700: 		    $secentry .= $ENV{"form.$gp"};
        !          1701: 		}
        !          1702: 		if ( grep/^$ENV{"form.$secnum"}:/,@currsections) {
        !          1703: 		    push @sections, $secentry;
        !          1704: 		    $seccount ++;
        !          1705: 		} else {
        !          1706: 		    my $newsec = $coursecode.$ENV{"form.$secnum"};
        !          1707: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
        !          1708: 		    if ($coursecheck eq 'ok') {
        !          1709: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
        !          1710: 			if ($addcheck eq 'ok') {
        !          1711: 			    push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
        !          1712: 			    $seccount ++;
        !          1713: 			    $addcount ++;
        !          1714: 			} else {
        !          1715: 			    push @badowner,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
        !          1716: 			}
        !          1717: 		    } else {
        !          1718: 			push @badsections, $ENV{"form.$secnum"}.":".$ENV{"form.$gp"}.":".$coursecheck;
        !          1719: 		    }
        !          1720: 		}
        !          1721: 	    }
        !          1722: 	}
        !          1723: 	if (@currsections > 0) {
        !          1724: 	    for (my $i=0; $i<@currsections; $i++) {
        !          1725: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
        !          1726: 		    my $oldsec  = $1;
        !          1727: 		    unless (grep/^$oldsec/,@sections) {
        !          1728: 			$removecount ++;
        !          1729: 		    }
        !          1730: 		}
        !          1731: 	    }
        !          1732: 	}
        !          1733:     } elsif (@currsections > 0) {
        !          1734: 	for (my $i=0; $i<@currsections; $i++) {
        !          1735: 	    my $sec = "sec_".$i;
        !          1736: 	    my $gp = "secgp_".$i;
        !          1737: 	    if ( exists($ENV{"form.$sec"}) ) {
        !          1738: 		my $secentry = '';
        !          1739: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
        !          1740: 		    $secentry = $1;
        !          1741: 		}
        !          1742: 		if ( exists($ENV{"form.$gp"}) ) {
        !          1743: 		    $secentry .= $ENV{"form.$gp"};
        !          1744: 		}
        !          1745: 		push @sections,$secentry;
        !          1746: 		$seccount ++;
        !          1747: 	    } else {
        !          1748: 		$removecount ++;
        !          1749: 	    }
        !          1750: 	}
        !          1751:     }
        !          1752:     
        !          1753:     if ($seccount > 1) {
        !          1754: 	$secstr = join(",",@sections);
        !          1755:     } else {
        !          1756: 	$secstr = $sections[0];
        !          1757:     }
        !          1758:     my %cenv = ('internal.sectionnums' => $secstr);
        !          1759:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1760:     if ($reply !~ /^ok$/) {
        !          1761: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
        !          1762:     } else {
        !          1763: 	if ($removecount > 0) {
        !          1764: 	    $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/>";
        !          1765: 	}
        !          1766: 	if ($addcount > 0) {
        !          1767: 	    $response .= "A total of $addcount sections have been added to the list of
1.6       raeburn  1768: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.15    ! albertel 1769: 	}
        !          1770: 	if ($seccount > 0) { 
        !          1771: 	    $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";
        !          1772: 	    foreach (@sections) {
        !          1773: 		my ($sec,$gp) = split/:/,$_;
        !          1774: 		$response .= "<li>$sec  - ID: $gp</li>\n";
        !          1775: 	    }
        !          1776: 	    $response .= "</ul><br/>\n";
        !          1777: 	}
        !          1778:     }
        !          1779:     
        !          1780:     if (@badsections > 0) {
        !          1781: 	$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";
        !          1782: 	foreach (@badsections) {
        !          1783: 	    my ($secnum,$gp,$prob) = split/:/,$_;
        !          1784: 	    $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
        !          1785: 	}
        !          1786: 	$response .= "</ul><br/><br/>\n";
        !          1787:     }
        !          1788:     
        !          1789:     if (@badowner > 0) {
        !          1790: 	$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";
        !          1791: 	foreach (@badowner) {
        !          1792: 	    my ($secnum,$gp) = split/:/,$_;
        !          1793: 	    $response .= "<li>$secnum - ID: $gp</li>\n";
        !          1794: 	}
        !          1795: 	$response .= "</ul><br/><br/>\n";
        !          1796:     }
        !          1797:     
        !          1798:     if ($seccount > 0) {
        !          1799: 	$warning = &warning_message($dom,$crs,$action);
        !          1800: 	$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/>";
        !          1801: 	unless ($warning eq '') {
        !          1802: 	    $response .= $warn_prefix.$warning;
        !          1803: 	}
        !          1804:     }
        !          1805:     
        !          1806:     if ( exists($ENV{'form.numsec'}) ) {
        !          1807: 	my $numsec = $ENV{'form.numsec'};
        !          1808: 	if ($numsec > 0) {
        !          1809: 	    my @bgcolors=("#eeeeee","#cccccc");
        !          1810: 	    $response .= qq(
        !          1811: 			    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/> 
1.1       raeburn  1812:            <form name="enter" method="post">
                   1813:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1814:              <tr>
                   1815:               <td>
                   1816:                <table border="0" cellspacing="3" cellpadding="3">
                   1817:                 <tr bgcolor="#CCCCFF" align="left">
                   1818:                  <td><b>Section number</b></td>
                   1819:                  <td><b>LON-CAPA section/groupID</b></td>
                   1820:                 </tr>
1.15    ! albertel 1821: 			    );
        !          1822: 	    for (my $i=0; $i<$numsec; $i++) {
        !          1823: 		my $colflag = $i%2;
        !          1824: 		$response .= qq(
1.1       raeburn  1825:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1826:                  <td><input type="text" size="15" name="newsec_$i" /></td>
                   1827:                  <td><input type="text" size="10" name="newsecgp_$i" /></td>
                   1828:                 </tr>
1.15    ! albertel 1829: 				);
        !          1830: 	    }
        !          1831: 	    $response .= qq(  </table>
1.1       raeburn  1832:               </td>
                   1833:              </tr>
                   1834:              <tr>
                   1835:               <td align="right">
                   1836:                <input type="button" name="newsections" value="Go" onClick="process('newsections')" />
                   1837:               </td>
                   1838:              </tr>
                   1839:             </table>
                   1840:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\">
                   1841:             <input type=\"hidden\" name=\"action\" value=\"newsections\">
                   1842:             <input type=\"hidden\" name=\"state\" value=\"process\">
                   1843:             </form>
1.15    ! albertel 1844: 			      );
        !          1845: 	}
        !          1846:     }
        !          1847:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1848:     return;
1.1       raeburn  1849: }
                   1850: 
                   1851: sub print_sections_response () {
1.15    ! albertel 1852:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1853:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
        !          1854:     my @currsections = ();
        !          1855:     my @sections = ();
        !          1856:     my @allsections = ();
        !          1857:     my @badowner = ();
        !          1858:     my @badsections = ();
        !          1859:     my $numsec = 0;
        !          1860:     my $secstr =  $settings{'internal.sectionnums'};
        !          1861:     my $coursecode = $settings{'internal.coursecode'};
        !          1862:     my $owner = $settings{'internal.courseowner'};
        !          1863:     my $response = '';
        !          1864:     my $putreply = '';
        !          1865:     my $warning = '';
        !          1866:     my $warn_prefix = '';
        !          1867:     if ($secstr =~ m/,/) {
        !          1868: 	@allsections = split/,/,$secstr;
        !          1869:     } else {
        !          1870: 	unless ($secstr eq '') { $allsections[0] = $secstr; }
        !          1871:     }
        !          1872:     
        !          1873:     if ( exists($ENV{'form.numsec'}) ) {
        !          1874: 	$numsec = $ENV{'form.numsec'};
        !          1875:     }
        !          1876:     
        !          1877:     if ($numsec > 0) {
        !          1878: 	for (my $i=0; $i<$numsec; $i++) {
        !          1879: 	    my $sec = "newsec_".$i;
        !          1880: 	    my $gp = "newsecgp_".$i;
        !          1881: 	    if ( exists($ENV{"form.$sec"}) ) {
        !          1882: 		unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) {
        !          1883: 		    my $newsec = $coursecode.$ENV{"form.$sec"};
        !          1884: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
        !          1885: 		    if ($coursecheck eq 'ok') {
        !          1886: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
        !          1887: 			if ($addcheck eq 'ok') {
        !          1888: 			    push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
        !          1889: 			} else {
        !          1890: 			    push @badowner,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
        !          1891: 			}
        !          1892: 		    } else {
        !          1893: 			push @badsections, $ENV{"form.$sec"}.":".$ENV{"form.$gp"}.":".$coursecheck;
        !          1894: 		    }
        !          1895: 		}
        !          1896: 	    }
        !          1897: 	}
        !          1898: 	push @allsections, @sections;
        !          1899:     }
        !          1900:     
        !          1901:     if (@sections > 0 ) {
        !          1902: 	unless ($secstr eq '') { $secstr .= ","; } 
        !          1903: 	if (@sections > 1) {
        !          1904: 	    $secstr .= join(",",@sections);
        !          1905: 	} else {
        !          1906: 	    $secstr .= $sections[0];
        !          1907: 	}
        !          1908: 	my %cenv = ('internal.sectionnums' => $secstr);
        !          1909: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1910: 	if ($putreply !~ /^ok$/) {
        !          1911: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
        !          1912: 	}
        !          1913:     }
        !          1914: 
        !          1915:     if ($putreply =~ /^ok/) {
        !          1916: 	$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";
        !          1917: 	foreach (@allsections) {
        !          1918: 	    my ($sec,$gp) = split/:/,$_;
        !          1919: 	    $response .= "<li>$sec - ID: $gp</li>\n";
        !          1920: 	}
        !          1921: 	$response .= "</ul><br/><br/>\n";
        !          1922:     }
        !          1923: 
        !          1924:     if (@badsections > 0) {
        !          1925: 	$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";
        !          1926: 	foreach (@badsections) {
        !          1927: 	    my ($secnum,$gp,$prob) = split/:/,$_;
        !          1928: 	    $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
        !          1929: 	}
        !          1930: 	$response .= "</ul><br/><br/>\n";
        !          1931:     }
        !          1932: 
        !          1933:     if (@badowner > 0) {
        !          1934: 	$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";
        !          1935: 	foreach (@badowner) {
        !          1936: 	    my ($secnum,$gp) = split/:/,$_;
        !          1937: 	    $response .= "<li>$secnum - ID: $gp</li>\n";
        !          1938: 	}
        !          1939: 	$response .= "</ul><br/><br/>\n";
        !          1940:     }
        !          1941: 
        !          1942:     if (@allsections > 0) {
        !          1943: 	$warning = &warning_message($dom,$crs,$action);
        !          1944: 	$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/>";
        !          1945: 	unless ($warning eq '') {
        !          1946: 	    $response .= $warn_prefix.$warning;
        !          1947: 	}
        !          1948:     }
1.1       raeburn  1949: 
1.15    ! albertel 1950:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1951:     return;
1.1       raeburn  1952: }
                   1953: 
                   1954: sub print_photos_response () {
1.15    ! albertel 1955:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1956:     my %settings = &Apache::lonnet::get('environment',['internal.showphotos'],$dom,$crs);
        !          1957:     my $currphotos = $settings{'internal.showphotos'};
        !          1958:     my $showphotos = '';
        !          1959:     if ( exists($ENV{'form.showphotos'}) ) {
        !          1960: 	$showphotos=$ENV{'form.showphotos'};
        !          1961:     }
        !          1962:     
        !          1963:     my $response = "";
        !          1964:     my %cenv = ('internal.showphotos' => $showphotos);
        !          1965:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
        !          1966:     if ($reply !~ /^ok$/) {
        !          1967: 	$response = "There was a problem processing your requested change. The student photo import setting for this course has been left unchanged.<br/>";
        !          1968:     } else {
        !          1969: 	if ($showphotos) {
        !          1970: 	    if ($currphotos) {
        !          1971: 		$response = "Retrieval of student photos is still <b>enabled</b><br/>";
        !          1972: 	    } else {
        !          1973: 		$response = "Retrieval of student photos in now <b>enabled</b><br/>";
        !          1974: 	    }
        !          1975: 	} else {
        !          1976: 	    if ($currphotos) {
        !          1977: 		$response = "Retrieval of student photos is now <b>disabled</b><br/>";
        !          1978: 	    } else {
        !          1979: 		$response = "Retrieval of student photos is still <b>disabled</b><br/>";
        !          1980: 	    }
        !          1981: 	}
        !          1982:     }
        !          1983:     &print_reply($r,$response,$$tasktitleref{$action});
        !          1984:     return;
1.1       raeburn  1985: }
                   1986: 
                   1987: sub print_update_result () {
1.15    ! albertel 1988:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
        !          1989:     my $response = '';
        !          1990:     my $updateadds = 0;
        !          1991:     my $updatedrops = 0;
        !          1992:     my $changecount = 0;
        !          1993:     my %affiliates = ();
        !          1994:     my %reply = ();
        !          1995:     my @allcourses = ();
        !          1996:     my %LC_code = ();
        !          1997:     my $logmsg = '';
        !          1998:     my $newusermsg = '';
        !          1999: 
        !          2000:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg'],$dom,$crs);
        !          2001:     my $coursecode = $settings{'internal.coursecode'};
        !          2002:     my $authtype = $settings{'internal.authtype'};
        !          2003:     my $autharg = $settings{'internal.autharg'};
        !          2004:     my ($startaccess,$endaccess) = &get_dates_from_form();
        !          2005:     
        !          2006:     if ( exists($ENV{'form.updateadds'}) ) {
        !          2007: 	$updateadds = $ENV{'form.updateadds'};
        !          2008:     }
        !          2009:     if ( exists($ENV{'form.updatedrops'}) ) {
        !          2010: 	$updatedrops = $ENV{'form.updatedrops'};
        !          2011:     }
        !          2012:     if (!$updateadds && !$updatedrops) {
        !          2013: 	$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.";
        !          2014:     } elsif ($coursecode eq '') {
        !          2015: 	$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";
        !          2016:     } else {
1.1       raeburn  2017: # Get complete list of course sections to update
1.15    ! albertel 2018: 	my @currsections = ();
        !          2019: 	my @currxlists = ();
        !          2020: 	
        !          2021: 	if ($settings{'internal.sectionnums'} =~ m/,/) {
        !          2022: 	    @currsections = split/,/,$settings{'internal.sectionnums'};
        !          2023: 	} elsif ($settings{'internal.sectionnums'} ne '') {
        !          2024: 	    $currsections[0] = $settings{'internal.sectionnums'};
        !          2025: 	}
        !          2026: 	
        !          2027: 	if ($settings{'internal.crosslistings'} =~ m/,/) {
        !          2028: 	    @currxlists = split/,/,$settings{'internal.crosslistings'};
        !          2029: 	} elsif ($settings{'internal.crosslistings'} ne '') {
        !          2030: 	    $currxlists[0] = $settings{'internal.crosslistings'};
        !          2031: 	}
        !          2032: 	
        !          2033: 	if (@currxlists > 0) {
        !          2034: 	    foreach (@currxlists) {
        !          2035: 		if (m/^(\w+):(\w*)$/) {
        !          2036: 		    unless (grep/^$1$/,@allcourses) { 
        !          2037: 			push @allcourses,$1;
        !          2038: 			$LC_code{$1} = $2; 
        !          2039: 		    }
        !          2040: 		}
        !          2041: 	    }
        !          2042: 	}
        !          2043: 	
        !          2044: 	if (@currsections > 0) {
        !          2045: 	    foreach (@currsections) {
        !          2046: 		if (m/^(\w+):(\w*)$/) {
        !          2047: 		    my $sec = $coursecode.$1;
        !          2048: 		    my $gp = $2;
        !          2049: 		    unless (grep/^$sec$/,@allcourses) { 
        !          2050: 			push @allcourses,$sec;
        !          2051: 			$LC_code{$sec} = $gp; 
        !          2052: 		    }
        !          2053: 		}
        !          2054: 	    }
        !          2055: 	}
        !          2056: 
        !          2057: 	if (@allcourses > 0) {
        !          2058: 	    @{$affiliates{$crs}} = @allcourses;
        !          2059: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
        !          2060: 	    if ($reply{$crs} > 0) {
        !          2061: 		($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
        !          2062: 	    } else {
        !          2063: 		$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.";
        !          2064: 	    }  
        !          2065: 	} else {
        !          2066: 	    $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)";
        !          2067: 	}
        !          2068:     }
        !          2069:     unless ($logmsg eq '') {
        !          2070: 	my $loglength = length($logmsg);
        !          2071: 	$logmsg = substr($logmsg,0,$loglength-4);
        !          2072: 	$logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
        !          2073:     }
        !          2074:     unless ($newusermsg eq '') {
        !          2075: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
        !          2076: 	$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/>";
        !          2077:     }
        !          2078:     $response .= $logmsg.$newusermsg;
        !          2079:     &print_reply($r,$response,$$tasktitleref{$action});
        !          2080:     return;
1.10      raeburn  2081: }
                   2082: 
1.14      raeburn  2083: sub print_viewclass_response {
                   2084:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2085:     my $response;
                   2086:     my $chgtotal = 0;
                   2087:     my $chgok = 0;
                   2088:     my $chgfail = 0;
                   2089:     my $othdom = 0;
                   2090:     my $cid = $dom."_".$crs;
                   2091:     my %chg = ();
                   2092:     my %nochg = ();
                   2093:     my %otherdom = ();
                   2094:     my $modreply = ''; 
                   2095:     my $classlist = &Apache::loncoursedata::get_classlist($cid,$dom,$crs);
                   2096:     my $endidx = &Apache::loncoursedata::CL_END;
                   2097:     my $startidx = &Apache::loncoursedata::CL_START;
                   2098:     my $ididx=&Apache::loncoursedata::CL_ID;
                   2099:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   2100:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
                   2101:     foreach (sort keys %ENV) {
                   2102:         if (/^form\.switch:(.+)$/) {
                   2103:             my $student = $1;
                   2104:             my ($uname,$udom) = split/:/,$student;
                   2105:             my $sdata    = $classlist->{$student};
                   2106:             my $section  = $sdata->[$secidx];
                   2107:             my $uid       = $sdata->[$ididx];
                   2108:             my $start    = $sdata->[$startidx];
                   2109:             my $end      = $sdata->[$endidx];
                   2110:             my $type     = $sdata->[$typeidx];
                   2111:             $chgtotal ++;
                   2112:             my $newtype = 'auto';
                   2113:             my $change = 'auto';
                   2114:             my $oldtype = 'manual';
                   2115:             if ($type eq 'auto') { 
                   2116:                 $oldtype = 'auto';
                   2117:                 $newtype = '';
                   2118:                 $change = 'manual';
                   2119:             }
                   2120:             if ($udom eq $dom) {
                   2121:                 $modreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$newtype,$cid);
                   2122:                 if ($modreply eq 'ok') {
                   2123:                     $chgok ++;
                   2124:                     $chg{$student} = "Changed to $change";
                   2125:                 } else {
                   2126:                     $chgfail ++;
                   2127:                     $nochg{$student} = "Still set to $oldtype";
                   2128:                 } 
                   2129:             } else {
                   2130:                 $othdom ++;
                   2131:                 $otherdom{$student} = "Still set to $oldtype"; 
                   2132:             }
                   2133:         }
                   2134:     }
                   2135:     if ($chgtotal > 0) {
                   2136:         $response = "You requested a change in enrollment type for $chgtotal students.<br /><br />\n";
                   2137:         $classlist = &Apache::loncoursedata::get_classlist($cid,$dom,$crs);
                   2138:         if ($chgok > 0) {
                   2139:             $response .= "The following $chgok changes were successful:<br />";
                   2140:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2141:         }
                   2142:         if ($chgfail > 0) {
                   2143:             $response .= "The following $chgfail students were not modified successfully:&nbsp;<br />";
                   2144:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2145:         }
                   2146:         if ($othdom > 0) {
                   2147:             $response .= "The following $othdom students were not modified because students must be in the same LON-CAPA domain as the course, in order to be set to an enrollment type of 'auto':<br />"; 
                   2148:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2149:         }
                   2150:     }
                   2151:     &print_reply($r,$response,$$tasktitleref{$action});
                   2152:     return;
                   2153: }
                   2154: 
                   2155: sub enrolltype_result {
                   2156:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx) = @_;
                   2157:     my $reply = "
                   2158:             <table border='2'>
                   2159:              <tr>
                   2160:               <th>username</th>
                   2161:               <th>domain</th>
                   2162:               <th>ID</th>
                   2163:               <th>student name</th>
                   2164:               <th>section</th>
                   2165:               <th>start date</th>
                   2166:               <th>end date</th>
                   2167:               <th>enrollment change</th>
                   2168:              </tr>";
                   2169:     foreach (sort keys %{$changes}) {
                   2170:         my $sdata  = $classlist->{$_};
                   2171:         my ($uname,$udom) = split/:/,$_;
                   2172:         my $section  = $sdata->[$secidx];
                   2173:         my $uid      = $sdata->[$ididx];
                   2174:         my $start    = $sdata->[$startidx];
                   2175:         my $end      = $sdata->[$endidx];
                   2176:         my $type     = $sdata->[$typeidx];
                   2177:         if (! defined($start) || $start == 0) {
                   2178:             $start = &mt('none');
                   2179:         } else {
                   2180:             $start = &Apache::lonlocal::locallocaltime($start);
                   2181:         }
                   2182:         if (! defined($end) || $end == 0) {
                   2183:             $end = &mt('none');
                   2184:         } else {
                   2185:             $end = &Apache::lonlocal::locallocaltime($end);
                   2186:         }
                   2187:         if (!defined($section) || ($section eq '')) {
                   2188:             $section eq '&nbsp;';
                   2189:         }
                   2190:         if (!defined($uid) || ($uid eq '')) {
                   2191:             $uid = '&nbsp';
                   2192:         }
                   2193:         $reply .= "
                   2194:              <tr>
                   2195:               <td>$uname</td>
                   2196:               <td>$udom</td>
                   2197:               <td>$uid</td>
                   2198:               <td>".&Apache::loncommon::plainname($uname,$udom)."</td>
                   2199:               <td>$section</td>
                   2200:               <td>$start</td>
                   2201:               <td>$end</td>
                   2202:               <td>$$changes{$_}</td>
                   2203:              </tr>";
                   2204:     }
                   2205:     $reply .= "</table>";
                   2206:     return $reply;
                   2207: }
                   2208: 
1.10      raeburn  2209: sub warning_message {
                   2210:     my ($dom,$crs,$caller) = @_;
                   2211:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   2212:     my $currend = '';
                   2213:     my $currstart = '';
                   2214:     my $currsecs = '';
                   2215:     my $currxlists = '';
                   2216:     my $warning = '';
                   2217:     my $curradds = '';
                   2218:     my $currdrops = '';
                   2219:     if ( defined($settings{'internal.autoadds'}) ) {
                   2220:         $curradds = $settings{'internal.autoadds'};
                   2221:     }
                   2222:     if (defined($settings{'internal.autodrops'}) ) {
                   2223:         $currdrops = $settings{'internal.autodrops'};
                   2224:     }
                   2225:     if ( defined($settings{'internal.autostart'}) ) {
                   2226:         $currstart = $settings{'internal.autostart'};
                   2227:     }
                   2228:     if ( defined($settings{'internal.autoend'}) ) {
                   2229:         $currend = $settings{'internal.autoend'};
                   2230:     }
                   2231:     if ( defined($settings{'internal.sectionnums'}) ) {
                   2232:         $currsecs = $settings{'internal.sectionnums'};
                   2233:     }
                   2234:     if ( defined($settings{'internal.crosslistings'}) ) {
                   2235:         $currxlists = $settings{'internal.crosslistings'}
                   2236:     }
                   2237:     unless ($caller eq 'setdates') {
                   2238:         if ( ($currstart eq '') && ($currend eq '') )  {
                   2239:             $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>";
                   2240:         }
                   2241:     }
                   2242:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   2243:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   2244:             $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/>";
                   2245:         }
                   2246:     }
                   2247:     unless ( $caller eq 'chgsettings') {
                   2248:         if ( (!$curradds) && (!$currdrops) ) {
                   2249:             $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/>.";
                   2250:         }
                   2251:     }
                   2252:     return $warning;
1.1       raeburn  2253: }
                   2254: 
                   2255: sub print_reply () {
                   2256:   my ($r,$response,$caller) = @_;
                   2257:   $r->print("
                   2258:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   2259:              <tr>
1.14      raeburn  2260:               <td align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
1.1       raeburn  2261:              </tr>
                   2262:             </table>
                   2263:   ");
                   2264:   return;
                   2265: }
                   2266: 
                   2267: sub setup_date_selectors {
1.14      raeburn  2268:     my ($starttime,$endtime,$action) = @_;
1.1       raeburn  2269:     if (! defined($starttime)) {
                   2270:         $starttime = time;
1.14      raeburn  2271:         if ($action eq 'setdates') {
                   2272:             if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.1       raeburn  2273:                             '.default_enrollment_start_date'})) {
1.14      raeburn  2274:                 $starttime = $ENV{'course.'.$ENV{'request.course.id'}.
1.1       raeburn  2275:                                   '.default_enrollment_start_date'};
1.14      raeburn  2276:             }
1.1       raeburn  2277:         }
                   2278:     }
                   2279:     if (! defined($endtime)) {
                   2280:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  2281:         if ($action eq 'setdates') {
                   2282:             if (exists($ENV{'course.'.$ENV{'request.course.id'}.
1.1       raeburn  2283:                             '.default_enrollment_end_date'})) {
1.14      raeburn  2284:                 $endtime = $ENV{'course.'.$ENV{'request.course.id'}.
1.1       raeburn  2285:                                 '.default_enrollment_end_date'};
1.14      raeburn  2286:             }
1.1       raeburn  2287:         }
                   2288:     }
                   2289:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2290:                                                             'startdate',
                   2291:                                                             $starttime);
                   2292:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2293:                                                           'enddate',
                   2294:                                                           $endtime);
                   2295:     return ($startdateform,$enddateform);
                   2296: }
                   2297: 
                   2298: sub get_dates_from_form {
1.14      raeburn  2299:     my $startdate;
                   2300:     my $enddate;
                   2301:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   2302:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.1       raeburn  2303:     if ( exists ($ENV{'form.no_end_date'}) ) {
                   2304:         $enddate = 0;
                   2305:     }
                   2306:     return ($startdate,$enddate);
                   2307: }
                   2308: 
                   2309: sub date_setting_table {
1.14      raeburn  2310:     my ($starttime,$endtime,$action) = @_;
                   2311:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime,$action);
1.1       raeburn  2312:     my $perpetual = '<nobr><input type="checkbox" name="no_end_date"';
1.14      raeburn  2313:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || (($action eq 'setaccess' || $action eq 'updatenow') && ($endtime eq '' || $endtime == 0)) ) {
1.1       raeburn  2314:         $perpetual .= ' checked';
                   2315:     }
                   2316:     $perpetual.= ' />'.' no ending date</nobr>';
                   2317:     my $start_table = '';
                   2318:     $start_table .= "<table>\n";
                   2319:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   2320:         '<td>'.$startform.'</td>'.
                   2321:         '<td>&nbsp;</td>'."</tr>\n";
                   2322:     $start_table .= "</table>";
                   2323:     my $end_table = '';
                   2324:     $end_table .= "<table>\n";
                   2325:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   2326:         '<td>'.$endform.'</td>'.
                   2327:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   2328:     $end_table .= "</table>\n";
                   2329:     return ($start_table, $end_table);
                   2330: }
                   2331: 
                   2332: ###################################################################
                   2333: sub handler {
                   2334:     my $r = shift;
                   2335:     if ($r->header_only) {
                   2336:         $r->content_type('text/html');
                   2337:         $r->send_http_header;
                   2338:         return OK;
                   2339:     }
                   2340:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   2341:     #  Needs to be in a course
                   2342:     if (! (($ENV{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'})))) {
                   2343:         # Not in a course, or not allowed to modify parms
                   2344:         $ENV{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
                   2345:         return HTTP_NOT_ACCEPTABLE; 
                   2346:     }
                   2347:     # Start page
                   2348:     $r->content_type('text/html');
                   2349:     $r->send_http_header;
                   2350: 
1.14      raeburn  2351:     my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","viewclass");
1.1       raeburn  2352:                                                                                  
                   2353:     my %tasklong = (
                   2354:                information => "Task information",
                   2355:                chgsettings => "Automated adds/drops",
                   2356:                setdates => "Change enrollment dates",
1.14      raeburn  2357:                setaccess => "Change access dates",
1.1       raeburn  2358:                notify => "Notification of changes",
                   2359:                crosslist => "Change crosslistings",
                   2360:                sections => "Section settings",
                   2361:                photos => "Student photos",
                   2362:                updatenow => "Update roster now",
                   2363:                newcross => "Add crosslistings",
1.14      raeburn  2364:                newsections => "Add sections",
                   2365:                viewclass => "View students and type",
1.1       raeburn  2366:     );
                   2367:                                                                                  
                   2368:     my %tasktitle = (
                   2369:                chgsettings => "Changes to nightly automated enrollments",
                   2370:                setdates => "Changes to first and/or last automated enrollment dates",
1.14      raeburn  2371:                setaccess => "Changes to default start and/or end dates for student access",
1.1       raeburn  2372:                notify => "Notification of enrollment changes",
                   2373:                crosslist => "Changes to crosslistings",
                   2374:                sections => "Changes to section settings",
                   2375:                photos => "Automatic import of student photos",
                   2376:                updatenow => "Immediate course roster update",
                   2377:                newcross => "Adding new crosslisted courses",
1.14      raeburn  2378:                newsections => "Adding new course sections",
                   2379:                viewclass => "Viewing class roster and enrollment type"
1.1       raeburn  2380:     );
                   2381: 
                   2382:     my $realm = '';
                   2383:     if ( exists($ENV{'request.course.id'}) ) {
                   2384:         $realm= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                   2385:     }
                   2386:     unless ($realm) { $realm='&nbsp;'; }
                   2387:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   2388:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   2389:     
                   2390:     #
                   2391:     # Main switch on form.action and form.state, as appropriate
                   2392:     #
                   2393: 
                   2394:     my $action = "information";
                   2395:     if ( exists($ENV{'form.action'}) ) {
                   2396:         $action = $ENV{'form.action'};
                   2397:     }
                   2398:     my $state = "choose";
                   2399: 
                   2400:     if ( exists($ENV{'form.state'}) ) {
                   2401:         $state = $ENV{'form.state'};
                   2402:     }
                   2403: 
                   2404:     if ($action eq "information") {
                   2405:         $r->print(&header()); 
                   2406:     } else {
                   2407:         if ($state eq "choose") {
                   2408:             $r->print(&choose_header());
                   2409:         } else {
                   2410:             if ($action eq "crosslist") {
                   2411:                 if ( exists($ENV{'form.numcross'}) ) {
                   2412:                     if ( $ENV{'form.numcross'} > 0 ) {
                   2413:                         $r->print(&choose_header());
                   2414:                     } else {
                   2415:                         $r->print(&header());
                   2416:                     }
                   2417:                 } else {
                   2418:                     $r->print(&header());
                   2419:                 }
                   2420:             } elsif ($action eq "sections") {
                   2421:                 if ( exists($ENV{'form.numsec'}) ) {
                   2422:                     if ( $ENV{'form.numsec'} > 0 ) {
                   2423:                         $r->print(&choose_header());
                   2424:                     } else {
                   2425:                         $r->print(&header());
                   2426:                     }
                   2427:                 } else {
                   2428:                     $r->print(&header());
                   2429:                 }
                   2430:             } else {
                   2431:                 $r->print(&header());
                   2432:             }
                   2433:         }
                   2434:     }
1.12      raeburn  2435: 
1.1       raeburn  2436:     my $reply = 0;
                   2437:     unless ($state eq "choose") { $reply = 1; }
                   2438: 
                   2439:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   2440:     &print_navmenu($r,\@tasks,\%tasklong);
                   2441:     
                   2442:     if (($state eq "choose") || ($action eq "information")) {
1.13      raeburn  2443:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
1.1       raeburn  2444:     } elsif ($action eq "chgsettings") {
                   2445:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2446:     } elsif ($action eq "setdates") {
                   2447:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  2448:     } elsif ($action eq "setaccess") {
                   2449:         &print_setaccess_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2450:     } elsif ($action eq "notify") {
                   2451:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2452:     } elsif ($action eq "sections") {
1.13      raeburn  2453:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2454:     } elsif ($action eq "crosslist") {
1.13      raeburn  2455:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2456:     } elsif ($action eq "updatenow") {
1.13      raeburn  2457:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2458:     } elsif ($action eq "photos") {
                   2459:         &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2460:     } elsif ($action eq "newcross") {
1.13      raeburn  2461:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
1.1       raeburn  2462:     } elsif ($action eq "newsections") {
1.13      raeburn  2463:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  2464:     } elsif ($action eq "viewclass") {
                   2465:         &print_viewclass_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2466:     }
                   2467:     &print_doc_base($r);  
                   2468:     return OK;
                   2469: }
                   2470: ###################################################################
                   2471: 1;

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