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

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

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