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

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

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