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

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

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