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

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

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