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

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

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