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

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

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