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

1.4       albertel    1: # automated enrollment configuration handler
1.47    ! albertel    2: # $Id: lonpopulate.pm,v 1.46 2006/08/08 19:02:04 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};
1.44      raeburn   948:       my $user;
                    949:       if ($enrollvar{'courseowner'} =~ /^[^:]+:[^:]+$/) {
                    950:           $user = $env{'user.name'}.':'.$env{'user.domain'};
                    951:       } else {
                    952:           $user = $env{'user.name'};
                    953:       }
1.34      raeburn   954:       if ($result eq 'ok') {
                    955:           if ($perm_reqd eq 'yes') {
                    956:               if (!($enrollvar{'photopermission'} eq 'yes')) {
                    957:                   $can_enable = 0;
                    958:               } else {
1.44      raeburn   959:                   if ($user eq $enrollvar{'courseowner'}) {
1.34      raeburn   960:                       $r->print('
                    961:                     <tr>
                    962:                      <td>'.
1.44      raeburn   963: &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   964:                      </td>
                    965:                     </tr>
1.34      raeburn   966:                       ');
                    967:                   }
                    968:               }
                    969:           }
                    970:       } else {
                    971:           $r->print('
                    972:                     <tr>
                    973:                      <td>'.
1.39      albertel  974: &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   975:                     </td>
                    976:                    </tr>
                    977:                   </form>
                    978:           ');
                    979:           return;
                    980:       }
                    981:       if ($can_enable) {
                    982:           $r->print('
1.1       raeburn   983:                     <tr>
                    984:                      <td>
1.34      raeburn   985:                       <font color="#888888">'.
                    986: &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   987:                       </font>
                    988:                      </td>
                    989:                     </tr>
1.34      raeburn   990: ');
                    991:       } else {
1.44      raeburn   992:           if ($user eq $enrollvar{'courseowner'}) {
1.34      raeburn   993:               $r->print('
                    994:                     <tr>
                    995:                      <td>'.
                    996: &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).'
                    997:                      </td>
                    998:                     </tr>
                    999:                ');
                   1000:           } else {
                   1001:               my ($ownername,$owneremail) = &get_ownerinfo($dom,
                   1002:                                                     $enrollvar{'courseowner'});
1.38      raeburn  1003:               my $emailstr;
                   1004:               if ($owneremail) {
                   1005:                   $emailstr = "(e-mail: $owneremail)";
                   1006:               }
1.34      raeburn  1007:               $r->print('
                   1008:                     <tr>
                   1009:                      <td>'.
1.44      raeburn  1010: &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  1011:                     </td>
                   1012:                    </tr>
                   1013:                   </form>
                   1014:              ');
                   1015:              return;
                   1016:           }
                   1017:       }
                   1018:       $r->print('
1.1       raeburn  1019:                     <tr>
                   1020:                      </td>&nbsp;</td>
                   1021:                     </tr>
                   1022:                     <tr>
1.34      raeburn  1023:                      <td align="right">
1.39      albertel 1024:                       <input type="button" name="showphotos" value="Go" onclick="process('."'photos'".')" />
1.1       raeburn  1025:                      </td>
                   1026:                     </tr>
                   1027:                    </table>
1.39      albertel 1028:                    <input type="hidden" name="action" value="'.$action.'" />
                   1029:                    <input type="hidden" name="state" value="process" />
1.1       raeburn  1030:                    </form>
1.34      raeburn  1031:       ');
1.1       raeburn  1032:   } elsif ($action eq "updatenow") {
                   1033:       $r->print("
                   1034:                    <form name=\"enter\" method=\"post\"><br/>
                   1035: 		   <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   1036: 		    <tr>
                   1037: 		     <td align=\"left\"><b>$$tasktitleref{$action}</b>
                   1038: 		     </td>
                   1039:                     </tr>
                   1040: 		   </table>
                   1041: 		   <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                   1042: 		    <tr>
                   1043: 		     <td>
1.17      raeburn  1044: 	              Add any students currently included in institutional classlist(s) but not enrolled in your LON-CAPA course.<br />  
1.39      albertel 1045: 		      <label><input type=\"radio\" name=\"updateadds\" value=\"1\" />&nbsp;Yes&nbsp;</label>
                   1046:                       <label><input type=\"radio\" name=\"updateadds\" value=\"0\" />&nbsp;No&nbsp;</label>
1.1       raeburn  1047:                      </td>
                   1048:                     </tr>
                   1049:                     <tr>
                   1050:                      <td>
1.17      raeburn  1051:  	              Expire students previously added by nightly enrollment process, but no longer listed in institutional  classlist(s).<br />                  
1.39      albertel 1052:                       <label><input type=\"radio\" name=\"updatedrops\" value=\"1\" />&nbsp;Yes&nbsp;</label>
                   1053:                       <label><input type=\"radio\" name=\"updatedrops\" value=\"0\" />&nbsp;No&nbsp;</label><br />
1.14      raeburn  1054:                      </td>
                   1055:                     </tr>
                   1056:                     <tr>
                   1057:                      <td><font color=\"#888888\">
1.1       raeburn  1058: 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  1059:                       </font>
                   1060:                      </td>
                   1061:                     </tr>
                   1062:                     <tr>
                   1063:                      <td>
                   1064:       ");
                   1065:       &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
                   1066:       $r->print("
                   1067:                      </td>
                   1068:                     </tr>
                   1069:                     <tr>
                   1070:                      <td align=\"right\">
1.39      albertel 1071:                       <input type=\"button\" name=\"updatenow\" value=\"Go\" onclick=\"process('updatenow')\" />
1.14      raeburn  1072:                      </td>
                   1073:                     </tr>
                   1074: 	           </table>
                   1075:                    <input type=\"hidden\" name=\"action\" value=\"$action\" />
                   1076:                    <input type=\"hidden\" name=\"state\" value=\"process\" />
                   1077:                   </form>
                   1078:       ");
1.34      raeburn  1079:   } elsif ($action eq 'updatephotos') {
                   1080:       $r->print("
                   1081:                    <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   1082:                     <tr>
                   1083:                      <td align=\"left\"><b>$$tasktitleref{$action}</b>
                   1084:                      </td>
                   1085:                     </tr><tr><td>");
1.37      raeburn  1086:       if ($enrollvar{'showphoto'}) {
1.35      albertel 1087:           my ($update,$commentary) = &Apache::lonnet::auto_photochoice($crs,
                   1088: 								       $dom);
1.40      raeburn  1089:           if ($update) { 
                   1090:               $r->print('<br />'.$commentary.'<br /><br />
1.34      raeburn  1091: <form name="photoupdate" method="post">
                   1092: <input type ="button" name="retrieve" value="'.&mt('Update photo repository').'"
                   1093: onclick="javascript:document.photoupdate.submit()" />
                   1094: <input type ="hidden" name="action" value="'.$action.'" />
                   1095: <input type ="hidden" name="state" value="process" />
                   1096: </form>');
1.40      raeburn  1097:           } else {
                   1098:               $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);" />');
                   1099:           }
1.34      raeburn  1100:       } else {
                   1101:           $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>');
                   1102:       }
                   1103:       $r->print('</td></tr>
                   1104:                  <tr><td>&nbsp;</td></tr>
                   1105:                 </table>');
1.14      raeburn  1106:   } elsif ($action eq 'viewclass') {
                   1107:       $r->print("
                   1108:                    <form name=\"studentform\" method=\"post\"><br/>
                   1109:                    <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   1110:                     <tr>
                   1111:                      <td align=\"left\"><b>$$tasktitleref{$action}</b>
                   1112:                      </td>
                   1113:                     </tr>
1.16      raeburn  1114:                     <tr>
                   1115:                      <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>
                   1116:                     </tr>
                   1117:                     <tr><td>&nbsp;</td></tr> 
1.14      raeburn  1118:                    </table>
                   1119:                    <table>
                   1120:                     <tr>
                   1121:                      <td>
1.1       raeburn  1122:       ");
1.23      albertel 1123:       if (! exists($env{'form.sortby'})) {
                   1124:           $env{'form.sortby'} = 'username';
1.14      raeburn  1125:       }
1.46      albertel 1126:       if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
1.23      albertel 1127:           $env{'form.Status'} = 'Active';
1.14      raeburn  1128:       }
1.23      albertel 1129:       my $status_select = &Apache::lonhtmlcommon::StatusOptions($env{'form.Status'});
1.14      raeburn  1130: #  Get current classlist
                   1131:       my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
                   1132:       if (! defined($classlist)) {
                   1133:           $r->print(&mt('There are no students either currently or previously enrolled.').
                   1134:                       "\n");
                   1135:       } else {
                   1136:           $r->print(&mt('Student Status: [_1]',$status_select)."\n");
                   1137:           $r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
                   1138:               "\n</p>\n");
                   1139: 
1.23      albertel 1140:           my ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount) = &Apache::londropadd::show_class_list($r,'autoenroll','nothing',$env{'form.Status'},$classlist,$keylist);
1.14      raeburn  1141:           $r->print("
                   1142:                      </td>
                   1143:                     </tr>
                   1144:           ");
                   1145:           if ($studentcount > 0) {
                   1146:               $r->print("
1.16      raeburn  1147:                     <tr><td><table border=\"0\" cellpadding=\"5\"><tr>
                   1148:               ");
                   1149:               my $cellcount = 0;
                   1150:               if ($autocount > 0) {
                   1151:                   $cellcount ++;
                   1152:                   $r->print(<<END);
                   1153:                        <td><fieldset><legend>&nbsp;<b>Change auto</b></legend><input type="button" value="check all" onclick="javascript:checkAll(document.studentform.chgauto)" />&nbsp;&nbsp;
                   1154:                        <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.chgauto)" /></fieldset></td>
                   1155: END
                   1156:               }
                   1157:               if ($manualcount > 0) {
                   1158:                   $cellcount ++;
                   1159:                   $r->print(<<END);
                   1160:                        <td><fieldset><legend>&nbsp;<b>Change manual</b></legend><input type="button" value="check all" onclick="javascript:checkAll(document.studentform.chgmanual)" />&nbsp;&nbsp;
                   1161:                        <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.chgmanual)" /></fieldset></td>
                   1162: END
                   1163:               }
                   1164:               if ($lockcount > 0) {
                   1165:                   if ($cellcount == 2) {
                   1166:                       $r->print("</tr><tr>");
                   1167:                   }
                   1168:                   $cellcount ++;
                   1169:                   $r->print(<<END);
                   1170:                        <td><fieldset><legend>&nbsp;<b>Lock manual</b></legend><input type="button" value="check all" onclick="javascript:checkAll(document.studentform.lockchg)" />&nbsp;&nbsp;
                   1171:                        <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.lockchg)" /></fieldset></td>
                   1172: END
                   1173:               }
                   1174:               if ($unlockcount > 0) {
                   1175:                   if ($cellcount == 2) {
                   1176:                       $r->print("</tr><tr>");
                   1177:                   }
                   1178:                   $cellcount ++;
                   1179:                   $r->print(<<END);
                   1180:                        <td><fieldset><legend>&nbsp;<b>Unlock manual</b></legend><input type="button" value="check all" onclick="javascript:checkAll(document.studentform.unlockchg)" />&nbsp;&nbsp;
                   1181:                        <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.unlockchg)" /></fieldset></td>
                   1182: END
                   1183:               }
                   1184:               $r->print("
                   1185:                        </tr>
                   1186:                       </table>
1.14      raeburn  1187:                      <td>&nbsp;</td>
                   1188:                     </tr>
                   1189:                     <tr>
                   1190:                      <td align=\"right\">
1.39      albertel 1191:                       <input type=\"button\" name=\"viewclass\" value=\"Go\" onclick=\"process('viewclass','$autocount','$manualcount','$lockcount','$unlockcount')\" />
1.14      raeburn  1192:                      </td>
                   1193:                     </tr>
                   1194:               ");
                   1195:           }
                   1196:           $r->print("
                   1197:                    </table>
                   1198:                    <input type=\"hidden\" name=\"action\" value=\"$action\" />
                   1199:                    <input type=\"hidden\" name=\"state\" value=\"choose\" />
                   1200:                   </form>
                   1201:           ");
                   1202:       }
1.1       raeburn  1203:   }
                   1204: }
                   1205: 
1.44      raeburn  1206: sub notifier_tables {
                   1207:     my ($role,$lt,$users,$status,$notifystate,$pname,$notifyshow) = @_;
                   1208:     my $output = &Apache::loncommon::start_data_table();
                   1209:     $output .= &Apache::loncommon::start_data_table_header_row();
                   1210:     $output .= "<th>$$lt{name}</th>
                   1211:                 <th>$$lt{usnm}</th>";
                   1212:     if ($role eq 'cc') {
                   1213:         $output .= "<th>$$lt{coac}</th>";
                   1214:     } 
                   1215:     $output .=  "<th>$$lt{curn}</th>
                   1216:                  <th>$$lt{notf}</th>";
                   1217:     $output .= &Apache::loncommon::end_data_table_header_row();
                   1218:     for (my $i=0; $i<@{$users}; $i++) {
                   1219:         $output .= &Apache::loncommon::start_data_table_row();
                   1220:         $output .= '<td>'.$$pname{$$users[$i]}.'</td>'.
                   1221:                    '<td><input type="hidden" name="notifyname_'.$$notifyshow.
                   1222:                    '" value="'.$$users[$i].'" />'.$$users[$i].'</td>';
                   1223:         if ($role eq 'cc') {
                   1224:             $output .= '<td>'.$$status{$$users[$i]}.'</td>';
                   1225:         }
                   1226:         $output .= '<td>';
                   1227:         if ($$notifystate{$$users[$i]} == 1) {
                   1228:             $output .= $$lt{ntac};
                   1229:         } else {
                   1230:             $output .= $$lt{ntin};
                   1231:         }
                   1232:         $output .= '</td><td><input type="checkbox" name="note_'.$$notifyshow.'"'; 
                   1233:         if ($$notifystate{$$users[$i]} == 1) {
                   1234:             $output .= ' checked="checked"';
                   1235:         }
                   1236:         $output .= ' /></td>';
                   1237:         $output .= &Apache::loncommon::end_data_table_row();
                   1238:         $$notifyshow ++;
                   1239:     }
                   1240:     $output .= &Apache::loncommon::end_data_table();
                   1241:     return $output;
                   1242: }
                   1243: 
1.14      raeburn  1244: sub print_accessdate_table {
                   1245:     my ($r,$enrollvar,$tasktitleref,$action) = @_;
                   1246:     my ($start_table,$end_table) = &date_setting_table($$enrollvar{'default_enrollment_start_date'},$$enrollvar{'default_enrollment_end_date'},$action);
                   1247:     my $oldstartshow = '';
                   1248:     my $oldendshow = '';
                   1249:     if ( defined($$enrollvar{'default_enrollment_start_date'}) ) {
                   1250:         $oldstartshow = &Apache::lonlocal::locallocaltime($$enrollvar{'default_enrollment_start_date'});
                   1251:     }
                   1252:     if ( defined($$enrollvar{'default_enrollment_end_date'}) ) {
                   1253:         $oldendshow = &Apache::lonlocal::locallocaltime($$enrollvar{default_enrollment_end_date});
                   1254:         if ($$enrollvar{'default_enrollment_end_date'} eq '0') {
                   1255:             $oldendshow = "No ending date";
                   1256:         }
                   1257:     }
                   1258:     my %lt =&Apache::lonlocal::texthash(
                   1259:          'cuno' => 'Currently NO default first access or last access dates are set.',
                   1260:          '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.',
                   1261:          '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.',
                   1262:          'setf' => 'Set date of first access',
                   1263:          'setl' => 'Set date of last access',
                   1264:          'freg' => 'for registered students added via automated enrollment',
                   1265:          'fnew' => 'for new students added when you update the class roster',
1.16      raeburn  1266:          '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.',
                   1267:          '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.'
                   1268: 
1.14      raeburn  1269:     );
                   1270:     my $dateshow;
                   1271:     if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
                   1272:        $dateshow = "<br/><font size='+1'>".&mt('Warning')."</font>.&nbsp;".$lt{'cuno'}." ";
                   1273:        if ($action eq 'setaccess') {
                   1274:            $dateshow .= $lt{'ifyo'}."\n";
                   1275:        } elsif ($action eq 'updatenow') {
                   1276:            $dateshow .= $lt{'ifyd'}."\n";
                   1277:        }
                   1278:     } else {
                   1279:         $dateshow = &mt('Currently: default first access').": <b><i>$oldstartshow</i></b>, ".&mt('default last access').": <b><i>$oldendshow</i></b>\n";
                   1280:     }
                   1281:     if ($action eq 'setaccess') {
                   1282:         $r->print(<<ENDONE);
                   1283:                 <form name="enter" method="post"><br/>
                   1284:                 <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   1285:                  <tr>
                   1286:                   <td align="left"><b>$$tasktitleref{$action}</b>
                   1287:                   <br /><br />
                   1288:                    $dateshow
                   1289:                   </td>
                   1290:                  </tr>
                   1291:                 </table>
                   1292: ENDONE
                   1293:     } elsif ($action eq 'updatenow') {
                   1294:         $r->print("
                   1295:                 <br /><br />$dateshow\n");
                   1296:     }
                   1297:     $r->print(<<ENDTWO);
                   1298:                 <table width="100%" border="0" cellpadding="3" cellspacing="3">
                   1299:                  <tr>
                   1300:                   <td align="left" colspan="2">
                   1301:                    <table border="0" cellspacing="0" cellpadding="2">
                   1302:                     <tr>
                   1303:                      <td colspan="3">
                   1304: ENDTWO
                   1305:       if ($action eq 'setaccess') {
                   1306:           $r->print("<i>$lt{'setf'} $lt{'freg'}</i>");
                   1307:       } elsif ($action eq 'updatenow') {
                   1308:           $r->print("<i>$lt{'setf'} $lt{'fnew'}</i>");
                   1309:       }
                   1310:       $r->print(<<ENDTHREE); 
                   1311:                        </td>
                   1312:                       </tr>
                   1313:                       <tr>
                   1314:                        <td>$start_table
                   1315:                        </td>
                   1316:                       </tr>
                   1317:                      </table>
                   1318:                     </td>
                   1319:                    </tr>
                   1320:                    <tr>
                   1321:                     <td align="left" colspan="2">
1.15      albertel 1322:                      <table border="0" cellspacing="0" cellpadding="2">
1.14      raeburn  1323:                       <tr>
                   1324:                        <td colspan="3">
                   1325: ENDTHREE
                   1326:     if ($action eq 'setaccess') {
                   1327:         $r->print("<i>$lt{'setl'} $lt{'freg'}</i>");
                   1328:     } elsif ($action eq 'updatenow') {
                   1329:         $r->print("<i>$lt{'setl'} $lt{'fnew'}</i>");
                   1330:     }
                   1331:     $r->print(<<ENDFOUR); 
                   1332:                        </td>
                   1333:                       </tr>
                   1334:                       <tr>
                   1335:                        <td>$end_table
                   1336:                        </td>
                   1337:                       </tr>
                   1338:                      </table>
                   1339:                     </td>
                   1340:                    </tr>
                   1341: ENDFOUR
                   1342:     if ($action eq 'setaccess') {
                   1343:         $r->print("
                   1344:                    <tr>
                   1345:                     <td colspan=\"2\"><font color=\"#888888\">$lt{'ifad'}</font></td>
                   1346:                    </tr>
1.16      raeburn  1347:                    <tr>
                   1348:                     <td colspan=\"2\">&nbsp;</td>
                   1349:                    </tr>
                   1350:                    <tr>
                   1351:                     <td colspan=\"2\"><b>".&mt('Note').":</b> ".$lt{'ncds'}."</td>
                   1352:                    </tr>
1.14      raeburn  1353:                   </table>
                   1354:         ");
                   1355:     } elsif ($action eq 'updatenow') {
                   1356:         $r->print("
                   1357:                    </tr>
                   1358:                   </table>
                   1359:         ");
                   1360:     }
                   1361: }
                   1362: 
1.1       raeburn  1363: ###############################################################
                   1364: sub print_doc_base {
1.41      albertel 1365:     my ($r) = @_;
1.15      albertel 1366:     $r->print(<<ENDBASE);
1.1       raeburn  1367:   </td>
                   1368:  </tr>
                   1369: </table>
1.41      albertel 1370: <br />
1.1       raeburn  1371: ENDBASE
1.41      albertel 1372:     $r->print(&Apache::loncommon::end_page());
1.1       raeburn  1373: }
                   1374:  
                   1375: ###################################################################
                   1376: sub print_chgsettings_response {
1.15      albertel 1377:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1378:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
                   1379:     my $currend = '';
                   1380:     my $currstart = '';
                   1381:     my $currsecs = '';
                   1382:     my $currxlists = '';
                   1383:     my $curradds = '';
                   1384:     my $currdrops = '';
                   1385:     if ( defined($settings{'internal.autoadds'}) ) {
                   1386: 	$curradds = $settings{'internal.autoadds'};
                   1387:     }
                   1388:     if ( defined($settings{'internal.autodrops'}) ) {
                   1389: 	$currdrops = $settings{'internal.autodrops'};
                   1390:     }
                   1391:     if ( defined($settings{'internal.autostart'}) ) {
                   1392: 	$currstart = $settings{'internal.autostart'};
                   1393:     }
                   1394:     if ( defined($settings{'internal.autoend'}) ) {
                   1395: 	$currend = $settings{'internal.autoend'};
                   1396:     }
                   1397:     if ( defined($settings{'internal.sectionnums'}) ) {
                   1398: 	$currsecs = $settings{'internal.sectionnums'};
                   1399:     }
                   1400:     if ( defined($settings{'internal.crosslistings'}) ) {
                   1401: 	$currxlists = $settings{'internal.crosslistings'}
                   1402:     }
                   1403:     my $autoadds = '';
                   1404:     my $autodrops = '';
1.1       raeburn  1405: 
1.23      albertel 1406:     if ( exists($env{'form.autoadds'}) ) {
                   1407: 	$autoadds=$env{'form.autoadds'};
1.15      albertel 1408:     }
1.23      albertel 1409:     if ( exists($env{'form.autodrops'}) ) {
                   1410: 	$autodrops=$env{'form.autodrops'};
1.15      albertel 1411:     }
                   1412: 
                   1413:     my $response = "";
                   1414:     my $warning = "";
                   1415:     my $warn_prefix = "";
                   1416:     my $warn_suffix = "";
                   1417:     my $warnfiller = "";
                   1418:     my %cenv = ('internal.autoadds' => $autoadds,
                   1419: 		'internal.autodrops' => $autodrops);
                   1420:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1421:     if ($reply !~ /^ok$/) {
                   1422: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1423:     } else {
                   1424: 	if ($autoadds) {
                   1425: 	    if ($curradds) {
                   1426: 		$response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
                   1427: 	    } else {
                   1428: 		$response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
                   1429: 	    }
                   1430: 	} else {
                   1431: 	    if ($curradds) {
                   1432: 		$response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
                   1433: 	    } else {
                   1434: 		$response = "Nightly additions based on classlist changes still <b>disabled</b><br/>";
                   1435: 	    }
                   1436: 	}
                   1437: 	if ($autodrops) {
                   1438: 	    if ($currdrops) {
1.39      albertel 1439: 		$response .= "Nightly removals based on classlist changes still <b>enabled</b><br />";
1.15      albertel 1440: 	    } else {
                   1441: 		$response .= "Nightly removals based on classlist changes now <b>enabled</b><br/>";
                   1442: 	    }
                   1443: 	} else {
                   1444: 	    if ($currdrops) {
1.39      albertel 1445: 		$response .= "Nightly removals based on classlist changes now <b>disabled</b><br />";
1.15      albertel 1446: 	    } else {
                   1447: 		$response .= "Nightly removals based on classlist changes still <b>disabled</b>";
                   1448: 	    }
                   1449: 	}
                   1450: 	if ($autoadds || $autodrops) {
                   1451: 	    $warning = &warning_message($dom,$crs,$action);
                   1452: 	    $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you indicated that nightly ";
                   1453: 	    $warn_suffix = " should be enabled, additional action is required.<br/>";
                   1454: 	}
                   1455: 	if ($autoadds) {
                   1456: 	    if ($autodrops) {
                   1457: 		$warnfiller = "adds and drops";
                   1458: 	    } else {
                   1459: 		$warnfiller = "adds";
                   1460: 	    }
                   1461: 	} else {
                   1462: 	    if ($autodrops) {
                   1463: 		$warnfiller = "drops";
                   1464: 	    }
                   1465: 	}
                   1466: 	unless ($warning eq '') {
                   1467: 	    $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
                   1468: 	}
                   1469:     }
                   1470:     &print_reply($r,$response,$$tasktitleref{$action});
                   1471:     return;
1.1       raeburn  1472: }
                   1473: 
                   1474: sub print_setdates_response {
1.15      albertel 1475:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1476:     my %settings = &Apache::lonnet::get('environment',['internal.autostart','internal.autoend'],$dom,$crs);
                   1477:     my $currstart = $settings{'internal.autostart'};
                   1478:     my $currend = $settings{'internal.autoend'};
                   1479:     my $response = '';
1.19      raeburn  1480:     my $showstart = '';
1.15      albertel 1481:     my $showend = '';
                   1482:     my $warning = '';
                   1483:     my $warn_prefix = '';
1.19      raeburn  1484:     my ($autostart,$autoend) = &get_dates_from_form();
                   1485:     if ( ($autostart eq '') || ($autoend eq '') ) {
                   1486:         $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1487:     } elsif (($autoend > 0) && ($autoend <= $autostart)) {
                   1488:         $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";
                   1489:     } else {       
                   1490:         $showstart = &Apache::lonlocal::locallocaltime($autostart);
                   1491:         if ($autoend) {
                   1492: 	    $showend = &Apache::lonlocal::locallocaltime($autoend);
                   1493:         } else {
                   1494: 	    $showend = "'No end date'";
                   1495:         } 
1.15      albertel 1496: 
1.19      raeburn  1497:         my %cenv = ('internal.autostart' => $autostart,
                   1498:   		    'internal.autoend' => $autoend);
                   1499:         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1500:         if ($reply !~ /^ok$/) {
                   1501: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1502:         } else {
                   1503: 	    if ($currstart == $autostart) {
                   1504: 	        $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
                   1505: 	    } else {
                   1506: 	        $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
                   1507: 	    } 
                   1508: 	    if ($currend == $autoend) {
                   1509: 	        $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
                   1510: 	    } else {
                   1511: 	        $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
                   1512: 	    }
1.1       raeburn  1513:  
1.14      raeburn  1514: # 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  1515: 
1.19      raeburn  1516: 	    my $rosterupdated = 0;
                   1517: 	    my $firstaccess = "";
                   1518: 	    my $nextupdate = "";
                   1519: 	    my $lastupdate = "";
                   1520: 
                   1521: 	    my $nowstamp = time;
                   1522: 	    my @date_list=localtime(time);
                   1523: 	    my $cur_year = $date_list[5];
                   1524: 	    my $curday = $date_list[3];
                   1525: 	    my $curmonth = $date_list[4];
                   1526: 	    my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1527: 	    my $nextmidnt = 86400 + $lastmidnt;
                   1528: 
                   1529: 	    my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
                   1530: 	    my $lastupdate = $todayupdate - 86400;
                   1531: 	    if ($nowstamp < $todayupdate) {
                   1532: 	      $nextupdate = "today";
1.15      albertel 1533: 	    } else {
1.19      raeburn  1534: 	      $nextupdate = "tomorrow";
1.15      albertel 1535: 	    }
1.19      raeburn  1536: 	    if ($currstart < $lastupdate) {
                   1537: 	        $rosterupdated = 1;
1.15      albertel 1538: 	    }
1.19      raeburn  1539: 	    if ($autostart < $nextmidnt ) {
                   1540: 	        if ( $autostart >= $lastmidnt) {
                   1541: 		    $firstaccess = "today";
                   1542: 	        } else {
                   1543: 	  	    $firstaccess = "a date prior to today";
                   1544: 	        }
                   1545: 	        if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
1.39      albertel 1546: 		    $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  1547: 	        }
                   1548: 	    }
                   1549: 	    $warning = &warning_message($dom,$crs,$action);
                   1550: 	    $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/>";
                   1551: 	    unless ($warning eq '') {
                   1552: 	        $response .= $warn_prefix.$warning;
                   1553: 	    }
                   1554:         }
1.15      albertel 1555:     }
                   1556:     &print_reply($r,$response,$$tasktitleref{$action});
                   1557:     return;
1.1       raeburn  1558: }
                   1559: 
1.14      raeburn  1560: sub print_setaccess_response {
1.15      albertel 1561:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1562:     my %settings = &Apache::lonnet::get('environment',['default_enrollment_start_date','default_enrollment_end_date','internal.autostart'],$dom,$crs);
                   1563:     my $currstart = $settings{'default_enrollment_start_date'};
                   1564:     my $currend = $settings{'default_enrollment_end_date'};
                   1565:     my $autostart = $settings{'internal.autostart'};
                   1566:     my $response = '';
                   1567:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.19      raeburn  1568:     if (($startaccess eq '') || ($endaccess eq '')) {
                   1569:         $response = "There was a problem processing your requested changes. The default
                   1570: start and end access dates for this course have been left unchanged.<br/>";
                   1571:     } elsif (($endaccess > 0) && ($endaccess <= $startaccess)) {
                   1572:         $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 1573:     } else {
1.19      raeburn  1574:         my $showstart = &Apache::lonlocal::locallocaltime($startaccess);
                   1575:         my $showend = '';
                   1576:         my $warning = '';
                   1577:         my $warn_prefix = '';
                   1578:         if ($endaccess) {
                   1579: 	    $showend = &Apache::lonlocal::locallocaltime($endaccess);
                   1580:         } else {
                   1581: 	    $showend = "'No end date'";
                   1582:         }
1.15      albertel 1583: 
1.19      raeburn  1584:         my %cenv = ('default_enrollment_start_date' => $startaccess,
1.15      albertel 1585: 		'default_enrollment_end_date' => $endaccess);
1.19      raeburn  1586:         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1587:         if ($reply !~ /^ok$/) {
                   1588: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1589:         } else {
                   1590: 	    if ($currstart == $startaccess) {
                   1591: 	        $response = "The first access date for students added via automated enrollment has been left unchanged as $showstart.<br/>";
                   1592: 	    } else {
                   1593: 	        $response = "The first access date for students added via automated enrollment has been changed to
1.14      raeburn  1594: $showstart.<br/>";
1.19      raeburn  1595: 	    }
                   1596: 	    if ($currend == $endaccess) {
                   1597: 	        $response .= "The last access date for students added via automated enrollment has been left unchanged as $showend.<br/>";
                   1598: 	    } else {
                   1599: 	        $response .= "The last access date for students automated enrollment has been changed to
1.14      raeburn  1600: $showend.<br/>";
1.19      raeburn  1601: 	    }
1.15      albertel 1602: 	
1.14      raeburn  1603: # 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 1604: 	
1.19      raeburn  1605: 	    my $accessgiven= 0;
                   1606: 	    my $firstaccess = "";
                   1607: 	    my $nextupdate = "";
                   1608: 	    my $lastupdate = "";
                   1609: 
                   1610: 	    my $nowstamp = time;
                   1611: 	    my @date_list=localtime(time);
                   1612: 	    my $cur_year = $date_list[5];
                   1613: 	    my $curday = $date_list[3];
                   1614: 	    my $curmonth = $date_list[4];
                   1615: 	    my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1616: 	    my $nextmidnt = 86400 + $lastmidnt;
                   1617: 
                   1618: 	    my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
                   1619: 	    my $tomorrowupdate = $todayupdate + 86400;
                   1620: 	    my $lastupdate = $todayupdate - 86400;
                   1621: 
                   1622: 	    if ($autostart < $nextmidnt) {
                   1623: 	        if ($nowstamp < $todayupdate) {
                   1624: 		    $nextupdate = "at 1.30 am today";
                   1625: 	        } else {
                   1626: 		    $nextupdate = "at 1.30 am tomorrow";
                   1627: 	        }
1.15      albertel 1628: 	    } else {
1.19      raeburn  1629: 	        my @enrollstart = localtime($autostart);
                   1630: 	        $nextupdate = timelocal(0,30,1,$enrollstart[3],$enrollstart[4],$enrollstart[5]);
                   1631: 	        unless (($enrollstart[2] < 1) || ($enrollstart[2] == 1 && $enrollstart[1] <=30))  {
                   1632: 		    $nextupdate += 86400; 
                   1633: 	        }
                   1634: 	        $nextupdate = &Apache::lonlocal::locallocaltime($nextupdate);
                   1635: 	    }
                   1636: 	    if (($currstart < $lastupdate) && ($autostart < $lastupdate)) {
                   1637: 	        $accessgiven = 1;
                   1638: 	    }
                   1639: 	    if ($startaccess < $nextmidnt ) {
                   1640: 	        if ( $startaccess >= $lastmidnt) {
                   1641: 	    	    $firstaccess = "today";
                   1642: 	        } else {
                   1643: 		    $firstaccess = "a date prior to today";
                   1644: 	        }
                   1645: 	        if (($nowstamp >= $startaccess) && ($accessgiven == 0)) {
1.39      albertel 1646: 		    $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  1647: 	        }
1.15      albertel 1648: 	    }
1.19      raeburn  1649: 	    $warning = &warning_message($dom,$crs,$action);
                   1650: 	    $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/>";
                   1651: 	    unless ($warning eq '') {
                   1652: 	        $response .= $warn_prefix.$warning;
1.15      albertel 1653: 	    }
1.19      raeburn  1654:         }
1.15      albertel 1655:     }
                   1656:     &print_reply($r,$response,$$tasktitleref{$action});
                   1657:     return;
1.14      raeburn  1658: }
                   1659: 
1.1       raeburn  1660: sub print_notify_response {
1.15      albertel 1661:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.1       raeburn  1662: 
                   1663: # Get current settings
1.15      albertel 1664:     my %settings = &Apache::lonnet::get('environment',['internal.notifylist','internal.coursecode'],$dom,$crs);
                   1665:     my $notifylist = $settings{'internal.notifylist'};
                   1666:     my $coursecode = $settings{'internal.coursecode'};
1.28      albertel 1667:     my @currpeople = split(/,/,$notifylist);
1.15      albertel 1668:     my $notify = 0;
                   1669:     my @people = ();
                   1670:     my $peoplestr = "";
                   1671:     my $response = "";
                   1672:     my $noprocess = 0;
1.1       raeburn  1673: 
1.15      albertel 1674:     my $currcount = 0;
                   1675:     foreach  (@currpeople) {
                   1676: 	unless ($_ eq '') { $currcount ++; } 
                   1677:     }
                   1678: 
1.23      albertel 1679:     if ( exists($env{'form.notify'}) ) {
                   1680: 	$notify=$env{'form.notify'};
1.15      albertel 1681:     }
1.23      albertel 1682:     if ( exists($env{'form.notifyshow'}) ) {
                   1683: 	my $notifyshow = $env{'form.notifyshow'};
1.15      albertel 1684: 	for (my $i=0; $i<$notifyshow; $i++) {
1.23      albertel 1685: 	    if ( exists($env{"form.note_$i"}) ) {
                   1686: 		if ( exists($env{"form.notifyname_$i"}) ) {
                   1687: 		    unless ( $env{"form.notifyname_$i"} eq '' ) {
                   1688: 			push @people, $env{"form.notifyname_$i"};
1.15      albertel 1689: 		    }
                   1690: 		}
                   1691: 	    }
                   1692: 	}
                   1693: 	if ($notify) { $peoplestr = join(",",@people); }
                   1694:     } else {
                   1695: 	if ($notify) {
                   1696: 	    if ($currcount) {
                   1697: 		$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/>.";
                   1698: 		$peoplestr = $notifylist;
                   1699: 		@people = @currpeople;
                   1700: 		$noprocess = 1;
                   1701: 	    }
                   1702: 	}
                   1703:     }
                   1704:     unless ($noprocess == 1) {
                   1705: 	my %cenv = ('internal.notifylist' => $peoplestr);
                   1706: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1707: 	if ($reply !~ /^ok$/) {
                   1708: 	    $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
                   1709: 	} else {
                   1710: 	    if ($notify) {
                   1711: 		if (@people) {
                   1712: 		    if ($currcount) {
                   1713: 			$response .= "Notification of enrollment changes still <b>enabled</b><br/>";
                   1714: 		    } else {
                   1715: 			$response .= "Notification of enrollment changes now <b>enabled</b><br/>";
                   1716: 		    }
                   1717: 		    $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";
                   1718: 		    foreach my $person (@people) {
                   1719: 			$response .= "<li>$person</li>\n";
                   1720: 		    }
                   1721: 		    $response .= "</ul>\n";
                   1722: 		} else {
1.44      raeburn  1723: 		    $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 1724: 		}
                   1725: 	    } else {
                   1726: 		if ($currcount) {
                   1727: 		    $response = "Notification of enrollment changes now <b>disabled</b><br/>";
                   1728: 		} else {
                   1729: 		    $response = "Notification of enrollment changes still <b>disabled</b><br/>";
                   1730: 		}
                   1731: 	    }
                   1732: 	}
                   1733:     }
                   1734:     &print_reply($r,$response,$$tasktitleref{$action});
                   1735:     return;
1.1       raeburn  1736: }
                   1737: 
                   1738: sub print_crosslistings_menu () {
1.15      albertel 1739:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1740:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
                   1741:     my @currxlists = ();
                   1742:     my @xlists = ();
                   1743:     my $crosscount = 0;
                   1744:     my $removecount = 0;
                   1745:     my $xliststr = '';
                   1746:     my $response = '';
                   1747:     my $coursecode = $settings{'internal.coursecode'};
1.28      albertel 1748:     if ($settings{'internal.crosslistings'} ne '') {
                   1749: 	@currxlists = split(/,/,$settings{'internal.crosslistings'});
1.15      albertel 1750:     }
                   1751: 
                   1752:     if (@currxlists > 0) {
                   1753: 	for (my $i=0; $i<@currxlists; $i++) {
                   1754: 	    my $xlist = "cross_".$i;
1.42      raeburn  1755: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 1756: 	    if ( exists($env{"form.$xlist"}) ) {
1.15      albertel 1757: 		my $xlistentry = '';
                   1758: 		if ($currxlists[$i] =~ m/^([^:]+)/) {
                   1759: 		    $xlistentry = $1.':';
                   1760: 		}
1.42      raeburn  1761: 		if ( exists($env{"form.$lc_sec"}) ) {
                   1762: 		    $xlistentry .= $env{"form.$lc_sec"};
1.15      albertel 1763: 		}
                   1764: 		push @xlists,$xlistentry;
                   1765: 		$crosscount ++;
                   1766: 	    } else {
                   1767: 		$removecount ++;
                   1768: 	    }
                   1769: 	}
                   1770:     }
1.1       raeburn  1771: 
1.28      albertel 1772:     $xliststr = join(",",@xlists);
                   1773: 
1.15      albertel 1774:     my %cenv = ('internal.crosslistings' => $xliststr);
                   1775:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1776:     if ($reply !~ /^ok$/) {
                   1777: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1778:     } else {
                   1779: 	if ($removecount > 0) {
                   1780: 	    $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
                   1781: 	}
                   1782: 	if ($crosscount > 0) {
                   1783: 	    $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";
                   1784: 	    foreach (@xlists) {
1.42      raeburn  1785: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1786: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1787: 	    }
                   1788: 	    $response .= "</ul><br/>\n";
                   1789: 	}
                   1790:     }
1.23      albertel 1791:     if ( exists($env{'form.numcross'}) ) {
                   1792: 	my $numcross = $env{'form.numcross'};
1.15      albertel 1793: 	if ($numcross > 0) {
                   1794: 	    my @bgcolors=("#eeeeee","#cccccc");
1.42      raeburn  1795: 	    $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 1796:            <form name="enter" method="post">); #' stupid emacs
1.42      raeburn  1797:            $response .= &Apache::loncommon::start_data_table();
                   1798:            $response .= &Apache::loncommon::start_data_table_row();
                   1799:            $response .= qq(
                   1800:                  <th>Crosslisting</th>
                   1801:                  <th>LON-CAPA section ID</th>
1.15      albertel 1802: 			    );
1.42      raeburn  1803:            $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 1804: 	    for (my $i=0; $i<$numcross; $i++) {
1.42      raeburn  1805:                 $response .= &Apache::loncommon::start_data_table_row();
1.15      albertel 1806: 		$response .= qq(
1.1       raeburn  1807:                  <td><input type="text" size="15" name="newcross_$i" /></td>
1.42      raeburn  1808:                  <td align="right"><input type="text" size="10" name="newlcsec_$i" /></td>
1.15      albertel 1809: 				);
1.42      raeburn  1810:                 $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 1811: 	    }
1.42      raeburn  1812:             $response .= &Apache::loncommon::end_data_table();
                   1813: 	    $response .= qq(
1.1       raeburn  1814:               </td>
                   1815:              </tr>
                   1816:              <tr>
                   1817:               <td align="right">
1.39      albertel 1818:                <input type="button" name="newcross" value="Go" onclick="process('newcross')" />
1.1       raeburn  1819:               </td>
                   1820:              </tr>
                   1821:             </table>
1.39      albertel 1822:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\" />
                   1823:             <input type=\"hidden\" name=\"action\" value=\"newcross\" />
                   1824:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  1825:             </form>
1.15      albertel 1826: 			      );
                   1827:         }
                   1828:     }
                   1829:     &print_reply($r,$response,$$tasktitleref{$action});
                   1830:     return;
1.1       raeburn  1831: }
                   1832: 
                   1833: sub print_crosslistings_response () {
1.15      albertel 1834:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1835:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
                   1836:     my @currxlists = ();
                   1837:     my @xlists = ();
                   1838:     my @allxlists = ();
                   1839:     my @badxlists = ();
                   1840:     my @badowner = ();
1.42      raeburn  1841:     my @reserved = ();
                   1842:     my @matchgroup = ();
1.15      albertel 1843:     my $numcross = 0;
                   1844:     my $xliststr =  $settings{'internal.crosslistings'};
                   1845:     my $coursecode = $settings{'internal.coursecode'};
                   1846:     my $owner = $settings{'internal.courseowner'};
                   1847:     my $response = '';
                   1848:     my $warning = '';
                   1849:     my $warn_prefix = '';
1.1       raeburn  1850: 
1.28      albertel 1851:     if ($xliststr ne '') {
                   1852: 	@allxlists = split(/,/,$xliststr);
1.15      albertel 1853:     }
1.1       raeburn  1854: 
1.23      albertel 1855:     if ( exists($env{'form.numcross'}) ) {
                   1856: 	$numcross = $env{'form.numcross'};
1.15      albertel 1857:     }
1.1       raeburn  1858: 
1.15      albertel 1859:     if ($numcross > 0) {
1.43      raeburn  1860:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 1861: 	for (my $i=0; $i<$numcross; $i++) {
                   1862: 	    my $xl = "newcross_".$i;
1.42      raeburn  1863: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 1864: 	    if ( exists($env{"form.$xl"}) ) {
1.42      raeburn  1865:                 if (exists($env{"form.$lc_sec"})) {
                   1866:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,
                   1867:                                                     $env{"form.$lc_sec"});
                   1868:                     if ($lc_sec_check eq 'reserved') {
                   1869:                         push(@reserved,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1870:                         next;
                   1871:                     } elsif ($lc_sec_check eq 'group') {
                   1872:                         push (@matchgroup,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1873:                         next;
                   1874:                     }
                   1875:                 }
1.15      albertel 1876: 		my $coursecheck = '';
1.23      albertel 1877: 		$coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});
1.15      albertel 1878: 		if ($coursecheck eq 'ok') {
                   1879: 		    my $addcheck = '';
1.23      albertel 1880: 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner);
1.15      albertel 1881: 		    if ($addcheck eq 'ok') {
1.42      raeburn  1882: 			push @xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1883: 		    } else {
1.42      raeburn  1884: 			push @badowner,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1885: 		    }
                   1886: 		} else {
1.42      raeburn  1887: 		    push @badxlists, $env{"form.$xl"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 1888: 		}
                   1889: 	    }
                   1890: 	}
                   1891: 	push @allxlists, @xlists;
                   1892:     }
                   1893:     
                   1894:     if (@xlists > 0 ) {
                   1895: 	unless ($xliststr eq '') { $xliststr .= ","; }
1.28      albertel 1896: 	$xliststr .= join(",",@xlists);
                   1897: 
1.15      albertel 1898: 	my %cenv = ('internal.crosslistings' => $xliststr);
                   1899: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1900: 	if ($reply !~ /^ok$/) {
                   1901: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1902: 	} else {
                   1903: 	    $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";
                   1904: 	    foreach (@allxlists) {
1.42      raeburn  1905: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1906: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1907: 	    }
                   1908: 	    $response .= "</ul><br/><br/>\n";
                   1909: 	}
                   1910:     } else {
                   1911: 	if ($xliststr =~ m/:/) {
1.28      albertel 1912: 	    my @oldxlists = (split/,/,$xliststr);
1.15      albertel 1913: 	    $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1914: 	    foreach (@oldxlists) {
1.42      raeburn  1915: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1916: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1917: 	    }
                   1918: 	    $response .= "</ul><br/><br/>\n";
                   1919: 	}
                   1920:     }
                   1921:     if (@badxlists > 0) {
                   1922: 	$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";
                   1923: 	foreach (@badxlists) {
1.42      raeburn  1924: 	    my ($xlist,$lc_sec,$prob) = split/:/,$_;
                   1925: 	    $response .= "<li>$xlist - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 1926: 	}
                   1927: 	$response .= "</ul><br/><br/>\n";
                   1928:     }
                   1929:     
                   1930:     if (@badowner > 0) {
                   1931: 	$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";
                   1932: 	foreach (@badowner) {
1.42      raeburn  1933: 	    my ($xlist,$lc_sec) = split/:/,$_;
                   1934: 	    $response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1935: 	}
                   1936: 	$response .= "</ul><br/><br/>\n";
                   1937:     }
1.42      raeburn  1938:     if (@reserved > 0) {
                   1939:         $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";  
                   1940:         foreach (@reserved) {
                   1941:             my ($xlist,$lc_sec) = split/:/,$_;
                   1942:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   1943:         }
                   1944:         $response .= "</ul><br/><br/>\n";
                   1945:     }
                   1946: 
                   1947:     if (@matchgroup > 0) {
                   1948:         $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";
                   1949:         foreach (@matchgroup) {
                   1950:             my ($xlist,$lc_sec) = split/:/,$_;
                   1951:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   1952:         }
                   1953:         $response .= "</ul><br/><br/>\n";
                   1954:     }
1.5       raeburn  1955: 
1.15      albertel 1956:     if (@allxlists > 0) {
                   1957: 	$warning = &warning_message($dom,$crs,$action);
                   1958: 	$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/>";
                   1959: 	unless ($warning eq '') {
                   1960: 	    $response .= $warn_prefix.$warning;
                   1961: 	}
                   1962:     }
1.1       raeburn  1963: 
1.15      albertel 1964:     &print_reply($r,$response,$$tasktitleref{$action});
                   1965:     return;
1.1       raeburn  1966: }
                   1967: 
                   1968: sub print_sections_menu () {
1.15      albertel 1969:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1970:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   1971:     my @currsections = ();
                   1972:     my @sections = ();
                   1973:     my @badowner = ();
                   1974:     my @badsections = ();
                   1975:     my $seccount = 0;
                   1976:     my $removecount = 0;
                   1977:     my $addcount = 0;
                   1978:     my $secstr = '';
                   1979:     my $response = '';
                   1980:     my $warning = "";
                   1981:     my $warn_prefix = "";
                   1982:     my $coursecode = $settings{'internal.coursecode'};
                   1983:     my $owner = $settings{'internal.courseowner'};
1.28      albertel 1984:     if ($settings{'internal.sectionnums'} ne '') {
                   1985: 	@currsections = split(/,/,$settings{'internal.sectionnums'});
1.15      albertel 1986:     }
                   1987:     
1.23      albertel 1988:     if ( exists($env{'form.secshow'}) ) {
                   1989: 	for (my $i=0; $i<$env{'form.secshow'}; $i++) {
1.42      raeburn  1990: 	    my $lc_sec = "loncapasec_".$i;
1.15      albertel 1991: 	    my $secnum = "secnum_".$i;
                   1992: 	    my $sec = "sec_".$i;
1.23      albertel 1993: 	    if ( exists( $env{"form.$sec"} ) ) {
1.15      albertel 1994: 		my $secentry;
1.23      albertel 1995: 		if ( exists( $env{"form.$secnum"} ) ) { 
                   1996: 		    $secentry = $env{"form.$secnum"}.':';
1.15      albertel 1997: 		}
1.42      raeburn  1998: 		if ( exists( $env{"form.$lc_sec"} ) ) {
                   1999: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2000: 		}
1.23      albertel 2001: 		if ( grep/^$env{"form.$secnum"}:/,@currsections) {
1.15      albertel 2002: 		    push @sections, $secentry;
                   2003: 		    $seccount ++;
                   2004: 		} else {
1.23      albertel 2005: 		    my $newsec = $coursecode.$env{"form.$secnum"};
1.15      albertel 2006: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2007: 		    if ($coursecheck eq 'ok') {
                   2008: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   2009: 			if ($addcheck eq 'ok') {
1.42      raeburn  2010: 			    push @sections,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2011: 			    $seccount ++;
                   2012: 			    $addcount ++;
                   2013: 			} else {
1.42      raeburn  2014: 			    push @badowner,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2015: 			}
                   2016: 		    } else {
1.42      raeburn  2017: 			push @badsections, $env{"form.$secnum"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2018: 		    }
                   2019: 		}
                   2020: 	    }
                   2021: 	}
                   2022: 	if (@currsections > 0) {
                   2023: 	    for (my $i=0; $i<@currsections; $i++) {
                   2024: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2025: 		    my $oldsec  = $1;
                   2026: 		    unless (grep/^$oldsec/,@sections) {
                   2027: 			$removecount ++;
                   2028: 		    }
                   2029: 		}
                   2030: 	    }
                   2031: 	}
                   2032:     } elsif (@currsections > 0) {
                   2033: 	for (my $i=0; $i<@currsections; $i++) {
                   2034: 	    my $sec = "sec_".$i;
1.42      raeburn  2035: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 2036: 	    if ( exists($env{"form.$sec"}) ) {
1.15      albertel 2037: 		my $secentry = '';
                   2038: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2039: 		    $secentry = $1;
                   2040: 		}
1.42      raeburn  2041: 		if ( exists($env{"form.$lc_sec"}) ) {
                   2042: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2043: 		}
                   2044: 		push @sections,$secentry;
                   2045: 		$seccount ++;
                   2046: 	    } else {
                   2047: 		$removecount ++;
                   2048: 	    }
                   2049: 	}
                   2050:     }
                   2051:     
1.28      albertel 2052:     $secstr = join(",",@sections);
                   2053: 
1.15      albertel 2054:     my %cenv = ('internal.sectionnums' => $secstr);
                   2055:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2056:     if ($reply !~ /^ok$/) {
                   2057: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   2058:     } else {
                   2059: 	if ($removecount > 0) {
                   2060: 	    $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/>";
                   2061: 	}
                   2062: 	if ($addcount > 0) {
                   2063: 	    $response .= "A total of $addcount sections have been added to the list of
1.6       raeburn  2064: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.15      albertel 2065: 	}
                   2066: 	if ($seccount > 0) { 
                   2067: 	    $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";
                   2068: 	    foreach (@sections) {
1.42      raeburn  2069: 		my ($sec,$lc_sec) = split/:/,$_;
                   2070: 		$response .= "<li>$sec  - ID: $lc_sec</li>\n";
1.15      albertel 2071: 	    }
                   2072: 	    $response .= "</ul><br/>\n";
                   2073: 	}
                   2074:     }
                   2075:     
                   2076:     if (@badsections > 0) {
                   2077: 	$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";
                   2078: 	foreach (@badsections) {
1.42      raeburn  2079: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2080: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2081: 	}
                   2082: 	$response .= "</ul><br/><br/>\n";
                   2083:     }
                   2084:     
                   2085:     if (@badowner > 0) {
                   2086: 	$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";
                   2087: 	foreach (@badowner) {
1.42      raeburn  2088: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2089: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2090: 	}
                   2091: 	$response .= "</ul><br/><br/>\n";
                   2092:     }
                   2093:     
                   2094:     if ($seccount > 0) {
                   2095: 	$warning = &warning_message($dom,$crs,$action);
                   2096: 	$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/>";
                   2097: 	unless ($warning eq '') {
                   2098: 	    $response .= $warn_prefix.$warning;
                   2099: 	}
                   2100:     }
                   2101:     
1.23      albertel 2102:     if ( exists($env{'form.numsec'}) ) {
                   2103: 	my $numsec = $env{'form.numsec'};
1.15      albertel 2104: 	if ($numsec > 0) {
                   2105: 	    my @bgcolors=("#eeeeee","#cccccc");
                   2106: 	    $response .= qq(
1.42      raeburn  2107: 			    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  2108:            <form name="enter" method="post">
                   2109:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   2110:              <tr>
1.42      raeburn  2111:               <td>);
                   2112:             $response .= &Apache::loncommon::start_data_table();
                   2113:             $response .= &Apache::loncommon::start_data_table_row();
                   2114:             $response .= qq(
                   2115:                  <th>Section number</th>
                   2116:                  <th>LON-CAPA section ID</th>
                   2117: 			 );
                   2118:             $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2119: 	    for (my $i=0; $i<$numsec; $i++) {
1.42      raeburn  2120:                 $response .= &Apache::loncommon::start_data_table_row();
1.15      albertel 2121: 		$response .= qq(
1.42      raeburn  2122:                  <td><input type="text" size="10" name="newsec_$i" /></td>
                   2123:                  <td align="right">
                   2124:                    <input type="text" size="10" name="newlcsec_$i" />
                   2125:                  </td>
                   2126: 			     );
                   2127:                 $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2128: 	    }
1.42      raeburn  2129:             $response .= &Apache::loncommon::end_data_table();
                   2130: 	    $response .= qq(
1.1       raeburn  2131:               </td>
                   2132:              </tr>
                   2133:              <tr>
                   2134:               <td align="right">
1.39      albertel 2135:                <input type="button" name="newsections" value="Go" onclick="process('newsections')" />
1.1       raeburn  2136:               </td>
                   2137:              </tr>
                   2138:             </table>
1.39      albertel 2139:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\" />
                   2140:             <input type=\"hidden\" name=\"action\" value=\"newsections\" />
                   2141:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  2142:             </form>
1.15      albertel 2143: 			      );
                   2144: 	}
                   2145:     }
                   2146:     &print_reply($r,$response,$$tasktitleref{$action});
                   2147:     return;
1.1       raeburn  2148: }
                   2149: 
                   2150: sub print_sections_response () {
1.15      albertel 2151:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2152:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   2153:     my @currsections = ();
                   2154:     my @sections = ();
                   2155:     my @allsections = ();
                   2156:     my @badowner = ();
                   2157:     my @badsections = ();
1.42      raeburn  2158:     my @reserved = ();
                   2159:     my @matchgroup = ();
1.15      albertel 2160:     my $numsec = 0;
                   2161:     my $secstr =  $settings{'internal.sectionnums'};
                   2162:     my $coursecode = $settings{'internal.coursecode'};
                   2163:     my $owner = $settings{'internal.courseowner'};
                   2164:     my $response = '';
                   2165:     my $putreply = '';
                   2166:     my $warning = '';
                   2167:     my $warn_prefix = '';
1.28      albertel 2168:     if ($secstr ne '') {
                   2169: 	@allsections = split(/,/,$secstr);
1.15      albertel 2170:     }
                   2171:     
1.23      albertel 2172:     if ( exists($env{'form.numsec'}) ) {
                   2173: 	$numsec = $env{'form.numsec'};
1.15      albertel 2174:     }
                   2175:     
                   2176:     if ($numsec > 0) {
1.43      raeburn  2177:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 2178: 	for (my $i=0; $i<$numsec; $i++) {
                   2179: 	    my $sec = "newsec_".$i;
1.42      raeburn  2180: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 2181: 	    if ( exists($env{"form.$sec"}) ) {
                   2182: 		unless ( (grep/^$env{"form.$sec"}:/,@allsections) || (grep/^$env{"form.$sec"}:/,@sections) ) {
1.42      raeburn  2183:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,                                                     $env{"form.$lc_sec"});
                   2184:                     if ($lc_sec_check eq 'reserved') {
                   2185:                         push(@reserved,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2186:                         next;
                   2187:                     } elsif ($lc_sec_check eq 'group') {
                   2188:                         push (@matchgroup,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2189:                         next;
                   2190:                     }
1.23      albertel 2191: 		    my $newsec = $coursecode.$env{"form.$sec"};
1.15      albertel 2192: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2193: 		    if ($coursecheck eq 'ok') {
                   2194: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   2195: 			if ($addcheck eq 'ok') {
1.42      raeburn  2196: 			    push @sections,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2197: 			} else {
1.42      raeburn  2198: 			    push @badowner,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2199: 			}
                   2200: 		    } else {
1.42      raeburn  2201: 			push @badsections, $env{"form.$sec"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2202: 		    }
                   2203: 		}
                   2204: 	    }
                   2205: 	}
                   2206: 	push @allsections, @sections;
                   2207:     }
                   2208:     
                   2209:     if (@sections > 0 ) {
                   2210: 	unless ($secstr eq '') { $secstr .= ","; } 
1.28      albertel 2211: 	$secstr .= join(",",@sections);
1.15      albertel 2212: 	my %cenv = ('internal.sectionnums' => $secstr);
                   2213: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2214: 	if ($putreply !~ /^ok$/) {
                   2215: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   2216: 	}
                   2217:     }
                   2218: 
                   2219:     if ($putreply =~ /^ok/) {
                   2220: 	$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";
                   2221: 	foreach (@allsections) {
1.42      raeburn  2222: 	    my ($sec,$lc_sec) = split/:/,$_;
                   2223: 	    $response .= "<li>$sec - ID: $lc_sec</li>\n";
1.15      albertel 2224: 	}
                   2225: 	$response .= "</ul><br/><br/>\n";
                   2226:     }
                   2227: 
                   2228:     if (@badsections > 0) {
                   2229: 	$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";
                   2230: 	foreach (@badsections) {
1.42      raeburn  2231: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2232: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2233: 	}
                   2234: 	$response .= "</ul><br/><br/>\n";
                   2235:     }
                   2236: 
                   2237:     if (@badowner > 0) {
                   2238: 	$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";
                   2239: 	foreach (@badowner) {
1.42      raeburn  2240: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2241: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2242: 	}
                   2243: 	$response .= "</ul><br/><br/>\n";
                   2244:     }
                   2245: 
1.42      raeburn  2246:     if (@reserved > 0) {
                   2247:         $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";
                   2248:         foreach (@reserved) {
                   2249:             my ($xlist,$lc_sec) = split/:/,$_;
                   2250:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2251:         }
                   2252:         $response .= "</ul><br/><br/>\n";
                   2253:     }
                   2254:                                                                                  
                   2255:     if (@matchgroup > 0) {
                   2256:         $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";
                   2257:         foreach (@matchgroup) {
                   2258:             my ($xlist,$lc_sec) = split/:/,$_;
                   2259:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2260:         }
                   2261:         $response .= "</ul><br/><br/>\n";
                   2262:     }
                   2263: 
                   2264: 
1.15      albertel 2265:     if (@allsections > 0) {
                   2266: 	$warning = &warning_message($dom,$crs,$action);
                   2267: 	$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/>";
                   2268: 	unless ($warning eq '') {
                   2269: 	    $response .= $warn_prefix.$warning;
                   2270: 	}
                   2271:     }
1.1       raeburn  2272: 
1.15      albertel 2273:     &print_reply($r,$response,$$tasktitleref{$action});
                   2274:     return;
1.1       raeburn  2275: }
                   2276: 
1.34      raeburn  2277: sub photo_permission {
1.15      albertel 2278:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.35      albertel 2279:     my %settings = &Apache::lonnet::get('environment',
                   2280: 					['internal.courseowner',
                   2281: 					 'internal.photopermission',
1.37      raeburn  2282: 					 'internal.showphoto'],
1.35      albertel 2283: 					$dom,$crs);
1.34      raeburn  2284:     my ($showphotos,$response);
                   2285:     if (exists($env{'form.cancel_agreement'})) {
                   2286:         if ($env{'user.name'} eq $settings{'internal.courseowner'}) {
                   2287:             my %cenv = (
                   2288:                 'internal.photopermission' => 'no',
                   2289:             );
                   2290:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2291:             if ($reply !~ /^ok$/) {
                   2292:                 $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";
                   2293:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2294:             } else {
                   2295:                 &print_photos_response($r,$realm,$dom,$crs,$action,
                   2296:                        $tasktitleref,$showphotos,'no',\%cenv);
                   2297:             }
                   2298:             return;            
                   2299:         }
                   2300:     } 
                   2301:     if (exists($env{'form.showphotos'})) {
                   2302:         $showphotos=$env{'form.showphotos'};
                   2303:     }
                   2304:     if ($showphotos) {
                   2305:         if ($env{'form.photopermission'}) {
                   2306:             my %cenv = (
                   2307:                 'internal.photopermission' => $env{'form.photopermission'},
                   2308:             );
                   2309:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2310:             if ($reply !~ /^ok$/) {
                   2311:                 $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";
                   2312:             } else {
                   2313:                 &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2314: 				       $tasktitleref,$showphotos,
                   2315: 				       $env{'form.photopermission'},\%cenv);
1.34      raeburn  2316:             }
                   2317:         } else {
                   2318:             my ($result,$perm_reqd,$conditions) = 
1.35      albertel 2319: 		&Apache::lonnet::auto_photo_permission($crs,$dom);
1.34      raeburn  2320:             my $permcheck;
                   2321:             if ($result eq 'ok') { 
                   2322:                 if ($perm_reqd eq 'yes') {
                   2323:                     if ($settings{'internal.photopermission'} eq 'yes') {
                   2324:                         &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2325: 					       $tasktitleref,$showphotos);
1.34      raeburn  2326:                     } else {
                   2327:                         return(&print_photo_agreement($r,$realm,$dom,$crs,
1.35      albertel 2328: 						      $action,$tasktitleref,
                   2329: 						      $conditions,
                   2330: 						      $settings{'internal.courseowner'}));
1.34      raeburn  2331:                     }
                   2332:                 } elsif ($perm_reqd eq 'no') {
                   2333:                     &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2334: 					   $tasktitleref,$showphotos);
1.34      raeburn  2335:                 } else {
                   2336:                     $permcheck = 'fail';
                   2337:                 }
                   2338:             } else {
                   2339:                 $permcheck = 'fail';
                   2340:             }
                   2341:             if ($permcheck eq 'fail') {
                   2342:                 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/>';
                   2343:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2344:             }
                   2345:         }
                   2346:     } else {
                   2347:         &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref);
                   2348:     }
                   2349:     return;
                   2350: }
                   2351: 
                   2352: sub print_photo_agreement {
                   2353:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_;
                   2354:     my $response;
                   2355:     my $institution = $Apache::lonnet::domaindescription{$dom};
                   2356:     if ($env{'user.name'} eq $courseowner) {
                   2357:         $response = '
                   2358: <script type="text/javascript">
                   2359: function agreement_result(caller) {
                   2360:     document.permission.photopermission.value = caller;
                   2361:     if (caller == 0) {
                   2362:         document.location.href="/adm/populate";
                   2363:     } else {
                   2364:         document.permission.submit();
                   2365:     }
                   2366:     return;
                   2367: }
                   2368: </script>
                   2369:   <form name="permission" method="post">
                   2370:    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   2371:     <tr>
                   2372:      <td align="left"><b>Use of student photos</b><br/>'."\n".
                   2373:       &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).'
                   2374:      </td>
                   2375:     </tr>
                   2376:    </table>
                   2377:    <table border="0" cellpadding="3" cellspacing="3">
                   2378:     <tr>
                   2379:      <td colspan="2">
                   2380:       <textarea rows="20" cols="80">'.$conditions.'</textarea>
                   2381:      </td>
                   2382:      <tr>
                   2383:       <td align="left">  
                   2384:        <input type="button" name="disagree" value="I do not agree" onclick="javascript:agreement_result('."'no'".');" />
                   2385:       </td>
                   2386:       <td align="right">
                   2387:        <input type="button" name="agree" value="I agree" onclick="javscript:agreement_result('."'yes'".');" />
                   2388:       </td>
                   2389:     </tr>
                   2390:    </table>
                   2391:    <input type ="hidden" name="action" value="'.$action.'" />
                   2392:    <input type ="hidden" name="state" value="process" />
                   2393:    <input type ="hidden" name="showphotos" value="1" />
                   2394:    <input type= "hidden" name="photopermission" value="" />
                   2395:   </form>
                   2396: ';
                   2397:     } else {
1.44      raeburn  2398:         my ($ownername,$owneremail) = &get_ownerinfo($dom,$courseowner);
                   2399:         my $emailstr;
                   2400:         if ($owneremail) {
                   2401:             $emailstr = "(e-mail: $owneremail)";
                   2402:         }
                   2403:         $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  2404:     }
                   2405:     &print_reply($r,$response,$$tasktitleref{$action});
                   2406: }
                   2407: 
                   2408: sub print_photos_response {
                   2409:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission,
1.35      albertel 2410: 	$permissionenv)=@_;
1.34      raeburn  2411:     my %newenv;
                   2412:     if (defined($permissionenv)) {
                   2413:         foreach my $key (keys(%{$permissionenv})) {
                   2414:             if (exists($env{'request.course.id'})) {
                   2415:                 $newenv{$env{'request.course.id'}.'.'.$key} =
1.35      albertel 2416: 		    $$permissionenv{$key};
1.34      raeburn  2417:             }
                   2418:         }
                   2419:     }
1.37      raeburn  2420:     my %settings = &Apache::lonnet::get('environment',['internal.showphoto'],
1.35      albertel 2421: 					$dom,$crs);
1.37      raeburn  2422:     my $currphotos = $settings{'internal.showphoto'};
1.34      raeburn  2423:     my $response = "";
                   2424:     if (defined($photopermission)) {
                   2425:         if ($photopermission eq 'yes') {
                   2426:             $response = &mt('Acceptance of photo use policy recorded.').'<br />'."\n";
                   2427:         } else {
                   2428:             $response = &mt('Non-acceptance of photo use policy recorded.').'<br />'."\n";
                   2429:             $showphotos = 0;
                   2430:         }
1.15      albertel 2431:     }
1.37      raeburn  2432:     my %cenv = ('internal.showphoto' => $showphotos);
1.15      albertel 2433:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2434:     if ($reply !~ /^ok$/) {
1.34      raeburn  2435: 	$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 2436:     } else {
                   2437: 	if ($showphotos) {
                   2438: 	    if ($currphotos) {
1.34      raeburn  2439: 		$response .= "Retrieval of student photos is still <b>enabled</b>.<br/>";
1.15      albertel 2440: 	    } else {
1.34      raeburn  2441: 		$response .= "Retrieval of student photos in now <b>enabled</b>.<br/>";
1.35      albertel 2442:                 my ($update,$commentary) = 
                   2443: 		    &Apache::lonnet::auto_photochoice($crs,$dom);
1.34      raeburn  2444:                 if ($update) {
                   2445:                     $response .= '<br />'.$commentary.'<br /><br />
                   2446: <form name="photoupdate" method="post">
                   2447: <input type ="button" name="retrieve" value="'.&mt('Update photo repository').'" 
                   2448: onclick="javascript:document.photoupdate.submit()" /> 
                   2449: <input type ="hidden" name="action" value="'.$action.'" />
                   2450: <input type ="hidden" name="state" value="photoupdate" />
                   2451: </form>';
                   2452:                 }
1.15      albertel 2453: 	    }
                   2454: 	} else {
                   2455: 	    if ($currphotos) {
1.34      raeburn  2456: 		$response .= "Retrieval of student photos is now <b>disabled</b>.<br/>";
1.15      albertel 2457: 	    } else {
1.34      raeburn  2458: 		$response .= "Retrieval of student photos is still <b>disabled</b>.<br/>";
1.15      albertel 2459: 	    }
                   2460: 	}
1.34      raeburn  2461:         foreach my $key (keys(%cenv)) {
                   2462:             if (exists($env{'request.course.id'})) {
                   2463:                 $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = 
1.35      albertel 2464: 		    $cenv{$key};
1.34      raeburn  2465:             }
                   2466:         }
                   2467:     }
                   2468:     if (keys(%newenv) > 0) {
                   2469:         &Apache::lonnet::appenv(%newenv);
                   2470:     }
                   2471:     &print_reply($r,$response,$$tasktitleref{$action});
                   2472:     return;
                   2473: }
                   2474: 
                   2475: sub print_photoupdate_response {
                   2476:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2477:     my $response;
                   2478:     my %changes;
                   2479:     my %lt = &LONCAPA::Enrollment::photo_response_types();
1.35      albertel 2480:     my %settings = &Apache::lonnet::get('environment',
                   2481: 					['internal.coursecode',
                   2482: 					 'internal.sectionnums',
                   2483: 					 'internal.crosslistings'],
                   2484: 					$dom,$crs);
1.34      raeburn  2485:     my @allcourses = ();
                   2486:     my %LC_code;
                   2487:     my %affiliates;
                   2488:     my $outcome;
                   2489:     &get_institutional_codes(\%settings,,\@allcourses,\%LC_code);
                   2490:     if (@allcourses > 0) {
                   2491:         @{$affiliates{$crs}} = @allcourses;
                   2492:         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
                   2493:         unless ($outcome eq 'ok') {
                   2494:             &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response".
1.35      albertel 2495: 				     "failed to update student photos".
                   2496: 				     " for ".$crs."\@".$dom." by ".
                   2497: 				     $env{'user.name'}." \@ ".$env{'user.domain'}.
                   2498: 				     ": ".$outcome);
1.34      raeburn  2499:         }
                   2500:         if ($outcome eq 'ok') {
                   2501:             if (keys(%changes) > 0) {
                   2502:                 $response = &mt('Update of photos for registered students resulted in the following ').': <br /><script type="text/javascript">
                   2503: function photowindow(photolink) {
                   2504:     var title = "Photo_Viewer";
                   2505:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2506:     options += ",width=240,height=240";
                   2507:     stdeditbrowser = open(photolink,title,options,"1");
                   2508:     stdeditbrowser.focus();
                   2509: }
                   2510: </script>
                   2511: ';
                   2512:                 foreach my $type (sort(keys(%changes))) {
                   2513:                     my @usernames = sort(split(/\&/,$changes{$type})); 
                   2514:                     my $count = @usernames; 
                   2515:                     $response .= '<b>'.&mt('For [_1] students, photos ',
1.35      albertel 2516: 					   $count).$lt{$type}.'</b><ul>';
1.34      raeburn  2517:                     foreach my $username (@usernames) {
                   2518:                         $response .= '<li>'.$username;
                   2519:                         if (($type eq 'new') || ($type eq 'same') || ($type eq 'update')) {
                   2520:                             $response .= '&nbsp;<a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($dom,$username,'jpg')."'".')">View</a></li>';  
                   2521:                         }
                   2522:                     }
                   2523:                     $response .= '</ul><br />';
                   2524:                 }
                   2525:             } else {
                   2526:                 $response = &mt('No updates of photos of registered students occurred').
                   2527:                          '<br />';
                   2528:             }    
                   2529:         } else {
                   2530:             $response = "There was a problem updating student photos for registered students in this course. <br/>";
                   2531:         }
                   2532:     } else {
                   2533:         $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 2534:     }
                   2535:     &print_reply($r,$response,$$tasktitleref{$action});
                   2536:     return;
1.1       raeburn  2537: }
                   2538: 
1.34      raeburn  2539: sub get_ownerinfo {
                   2540:     my ($dom,$owner) = @_; 
1.44      raeburn  2541:     my ($ownername,$owneremail,$own_uname,$own_udom);
1.34      raeburn  2542:     if ($owner) {
1.44      raeburn  2543:         if ($owner =~ /^([^:]+):([^:]+)$/) {
                   2544:             $own_uname = $1;
                   2545:             $own_udom = $2; 
                   2546:         } else {
                   2547:             $own_uname = $owner;
                   2548:             $own_udom = $dom; 
                   2549:         }
                   2550:         $ownername=&Apache::loncommon::plainname($own_uname,$own_udom,
                   2551:                                                  'firstname');
1.36      raeburn  2552:         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
1.44      raeburn  2553: 					     $own_udom,$own_uname);
1.34      raeburn  2554:         $owneremail = $ownerinfo{'permanentemail'};
                   2555:     }
                   2556:     return ($ownername,$owneremail);
                   2557: }
                   2558: 
1.1       raeburn  2559: sub print_update_result () {
1.15      albertel 2560:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2561:     my $response = '';
                   2562:     my $updateadds = 0;
                   2563:     my $updatedrops = 0;
                   2564:     my $changecount = 0;
                   2565:     my %affiliates = ();
                   2566:     my %reply = ();
                   2567:     my @allcourses = ();
                   2568:     my %LC_code = ();
                   2569:     my $logmsg = '';
                   2570:     my $newusermsg = '';
1.34      raeburn  2571:     my %phototypes = ();
1.37      raeburn  2572:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.showphoto'],$dom,$crs);
1.15      albertel 2573:     my $coursecode = $settings{'internal.coursecode'};
                   2574:     my $authtype = $settings{'internal.authtype'};
                   2575:     my $autharg = $settings{'internal.autharg'};
1.37      raeburn  2576:     my $showphotos = $settings{'internal.showphoto'};
1.15      albertel 2577:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.23      albertel 2578:     if ( exists($env{'form.updateadds'}) ) {
                   2579:         $updateadds = $env{'form.updateadds'};
1.15      albertel 2580:     }
1.23      albertel 2581:     if ( exists($env{'form.updatedrops'}) ) {
                   2582:         $updatedrops = $env{'form.updatedrops'};
1.15      albertel 2583:     }
1.19      raeburn  2584:     if (($startaccess eq '') || ($endaccess eq '')) {
                   2585:         $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 />"; 
                   2586:     } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
                   2587:         $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";
                   2588:     } elsif (!$updateadds && !$updatedrops) {
1.15      albertel 2589: 	$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.";
                   2590:     } elsif ($coursecode eq '') {
                   2591: 	$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";
                   2592:     } else {
1.34      raeburn  2593:         &get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.15      albertel 2594: 	if (@allcourses > 0) {
                   2595: 	    @{$affiliates{$crs}} = @allcourses;
                   2596: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
1.19      raeburn  2597:             unless ($outcome eq 'ok') {
                   2598:                 &Apache::lonnet::logthis("lonpopulate:update roster".
                   2599:                                          "failed to retrieve classlist".
                   2600:                                  " data for ".$crs."\@".$dom." by ".
1.23      albertel 2601:                                  $env{'user.name'}." \@ ".$env{'user.domain'}.
1.19      raeburn  2602:                                  ": ".$outcome);
                   2603:             }
1.15      albertel 2604: 	    if ($reply{$crs} > 0) {
1.34      raeburn  2605: 		($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes);
1.15      albertel 2606: 	    } else {
                   2607: 		$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.";
                   2608: 	    }  
                   2609: 	} else {
                   2610: 	    $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)";
                   2611: 	}
                   2612:     }
                   2613:     unless ($logmsg eq '') {
                   2614: 	my $loglength = length($logmsg);
                   2615: 	$logmsg = substr($logmsg,0,$loglength-4);
                   2616: 	$logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   2617:     }
                   2618:     unless ($newusermsg eq '') {
                   2619: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
1.19      raeburn  2620: 	$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 2621:     }
                   2622:     $response .= $logmsg.$newusermsg;
                   2623:     &print_reply($r,$response,$$tasktitleref{$action});
                   2624:     return;
1.10      raeburn  2625: }
                   2626: 
1.34      raeburn  2627: sub get_institutional_codes {
                   2628:     my ($settings,$allcourses,$LC_code) = @_;
                   2629: # Get complete list of course sections to update
                   2630:     my @currsections = ();
                   2631:     my @currxlists = ();
                   2632:     my $coursecode = $$settings{'internal.coursecode'};
1.39      albertel 2633:     
1.34      raeburn  2634:     if ($$settings{'internal.sectionnums'} ne '') {
                   2635:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   2636:     }
1.39      albertel 2637:     
1.34      raeburn  2638:     if ($$settings{'internal.crosslistings'} ne '') {
                   2639:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   2640:     }
1.39      albertel 2641:     
1.34      raeburn  2642:     if (@currxlists > 0) {
                   2643:         foreach (@currxlists) {
                   2644:             if (m/^([^:]+):(\w*)$/) {
                   2645:                 unless (grep/^$1$/,@{$allcourses}) {
                   2646:                     push @{$allcourses},$1;
                   2647:                     $$LC_code{$1} = $2;
                   2648:                 }
                   2649:             }
                   2650:         }
                   2651:     }
                   2652:                                                                                        
                   2653:     if (@currsections > 0) {
                   2654:         foreach (@currsections) {
                   2655:             if (m/^(\w+):(\w*)$/) {
                   2656:                 my $sec = $coursecode.$1;
1.42      raeburn  2657:                 my $lc_sec = $2;
1.34      raeburn  2658:                 unless (grep/^$sec$/,@{$allcourses}) {
                   2659:                     push @{$allcourses},$sec;
1.42      raeburn  2660:                     $$LC_code{$sec} = $lc_sec;
1.34      raeburn  2661:                 }
                   2662:             }
                   2663:         }
                   2664:     }
                   2665:     return; 
                   2666: }
                   2667: 
                   2668: 
1.14      raeburn  2669: sub print_viewclass_response {
                   2670:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2671:     my $response;
                   2672:     my $chgtotal = 0;
                   2673:     my $chgok = 0;
                   2674:     my $chgfail = 0;
                   2675:     my $othdom = 0;
1.16      raeburn  2676:     my $locktotal = 0;
                   2677:     my $lockok = 0;
                   2678:     my $lockfail = 0;
1.14      raeburn  2679:     my $cid = $dom."_".$crs;
                   2680:     my %chg = ();
                   2681:     my %nochg = ();
                   2682:     my %otherdom = ();
1.16      raeburn  2683:     my %lockchg = ();
                   2684:     my %nolockchg = ();
1.27      albertel 2685:     my $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2686:     my $endidx = &Apache::loncoursedata::CL_END;
                   2687:     my $startidx = &Apache::loncoursedata::CL_START;
                   2688:     my $ididx=&Apache::loncoursedata::CL_ID;
                   2689:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   2690:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
1.16      raeburn  2691:     my $lockedidx=&Apache::loncoursedata::CL_LOCKEDTYPE;
                   2692:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chgauto','chgmanual','lockchg','unlockchg']);
1.24      albertel 2693:     my @typechglist = (&Apache::loncommon::get_env_multiple('form.chgauto'),
                   2694: 		       &Apache::loncommon::get_env_multiple('form.chgmanual'));
                   2695:     my @lockchglist = (&Apache::loncommon::get_env_multiple('form.lockchg'),
                   2696: 		       &Apache::loncommon::get_env_multiple('form.unlockchg'));
                   2697: 
1.16      raeburn  2698:     foreach my $student (sort @typechglist) {
                   2699:         my ($uname,$udom) = split/:/,$student;
                   2700:         my $sdata    = $classlist->{$student};
                   2701:         my $section  = $sdata->[$secidx];
                   2702:         my $uid       = $sdata->[$ididx];
                   2703:         my $start    = $sdata->[$startidx];
                   2704:         my $end      = $sdata->[$endidx];
                   2705:         my $type     = $sdata->[$typeidx];
                   2706:         my $lock   = $sdata->[$lockedidx];
                   2707:         my $newlock = $lock;
                   2708:         $chgtotal ++;
                   2709:         my $newtype = 'auto';
                   2710:         my $change = 'auto';
                   2711:         my $oldtype = 'manual';
                   2712:         if ($type eq 'auto') { 
                   2713:             $oldtype = 'auto';
                   2714:             $newtype = '';
                   2715:             $change = 'manual';
                   2716:         }
                   2717:         if ($udom eq $dom) {
                   2718:             if ($newtype eq 'auto') {
                   2719:                 $newlock = '';
                   2720:             } elsif ($newtype eq '') {
                   2721:                 $newlock = '1';
1.14      raeburn  2722:             }
1.16      raeburn  2723:             my $modreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$newtype,$newlock,$cid);
                   2724:             if ($modreply eq 'ok') {
                   2725:                 $chgok ++;
                   2726:                 $chg{$student} = "Changed to $change";
                   2727:             } else {
                   2728:                 $chgfail ++;
                   2729:                 $nochg{$student} = "Still set to $oldtype";
                   2730:             } 
                   2731:         } else {
                   2732:             $othdom ++;
                   2733:             $otherdom{$student} = "Still set to $oldtype"; 
                   2734:         }
                   2735:     }
                   2736:     foreach my $student (@lockchglist) {
                   2737:         my ($uname,$udom) = split/:/,$student;
                   2738:         my $sdata    = $classlist->{$student};
                   2739:         my $section  = $sdata->[$secidx];
                   2740:         my $uid       = $sdata->[$ididx];
                   2741:         my $start    = $sdata->[$startidx];
                   2742:         my $end      = $sdata->[$endidx];
                   2743:         my $type     = $sdata->[$typeidx];
                   2744:         my $lock   = $sdata->[$lockedidx];
                   2745:         my $newlock = 1;
                   2746:         my $oldlockname = &mt('unlocked');
                   2747:         my $newlockname = &mt('locked');
                   2748:         $locktotal++;
                   2749:         unless ($type eq 'auto') {
                   2750:             if ($lock) {
                   2751:                 $newlock = '';
                   2752:                 $newlockname = &mt('unlocked');
                   2753:                 $oldlockname = &mt('locked'); 
                   2754:             }
                   2755:             my $lockreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$type,$newlock,$cid);
                   2756:             if ($lockreply eq 'ok') {
                   2757:                 $lockok ++;
                   2758:                 $lockchg{$student} = 'Changed to '.$newlockname;
1.14      raeburn  2759:             } else {
1.16      raeburn  2760:                 $lockfail ++;
                   2761:                 $nolockchg{$student} = 'Still set to '.$oldlockname;
1.14      raeburn  2762:             }
                   2763:         }
                   2764:     }
                   2765:     if ($chgtotal > 0) {
                   2766:         $response = "You requested a change in enrollment type for $chgtotal students.<br /><br />\n";
1.27      albertel 2767:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2768:         if ($chgok > 0) {
                   2769:             $response .= "The following $chgok changes were successful:<br />";
                   2770:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2771:         }
                   2772:         if ($chgfail > 0) {
                   2773:             $response .= "The following $chgfail students were not modified successfully:&nbsp;<br />";
                   2774:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2775:         }
                   2776:         if ($othdom > 0) {
                   2777:             $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 />"; 
                   2778:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2779:         }
1.16      raeburn  2780:         $response .= "<br /><br />";
                   2781:     }
                   2782:     if ($locktotal > 0) {
                   2783:         $response .= "You requested locking/unlocking for $locktotal manually enrolled students.<br /><br />\n";
1.27      albertel 2784:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.16      raeburn  2785:         if ($lockok > 0) {
                   2786:             $response .= "The following $lockok changes were successful:<br />";
                   2787:             $response .= &enrolltype_result(\%lockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2788:         }
                   2789:         if ($lockfail > 0) {
                   2790:             $response .= "The following $lockfail students were not modified successfully:&nbsp;<br />";
                   2791:             $response .= &enrolltype_result(\%nolockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2792:         }
1.14      raeburn  2793:     }
                   2794:     &print_reply($r,$response,$$tasktitleref{$action});
                   2795:     return;
                   2796: }
                   2797: 
                   2798: sub enrolltype_result {
1.16      raeburn  2799:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx) = @_;
1.14      raeburn  2800:     my $reply = "
                   2801:             <table border='2'>
                   2802:              <tr>
                   2803:               <th>username</th>
                   2804:               <th>domain</th>
                   2805:               <th>ID</th>
                   2806:               <th>student name</th>
                   2807:               <th>section</th>
                   2808:               <th>start date</th>
                   2809:               <th>end date</th>
                   2810:               <th>enrollment change</th>
                   2811:              </tr>";
                   2812:     foreach (sort keys %{$changes}) {
                   2813:         my $sdata  = $classlist->{$_};
                   2814:         my ($uname,$udom) = split/:/,$_;
                   2815:         my $section  = $sdata->[$secidx];
                   2816:         my $uid      = $sdata->[$ididx];
                   2817:         my $start    = $sdata->[$startidx];
                   2818:         my $end      = $sdata->[$endidx];
                   2819:         my $type     = $sdata->[$typeidx];
                   2820:         if (! defined($start) || $start == 0) {
                   2821:             $start = &mt('none');
                   2822:         } else {
                   2823:             $start = &Apache::lonlocal::locallocaltime($start);
                   2824:         }
                   2825:         if (! defined($end) || $end == 0) {
                   2826:             $end = &mt('none');
                   2827:         } else {
                   2828:             $end = &Apache::lonlocal::locallocaltime($end);
                   2829:         }
                   2830:         if (!defined($section) || ($section eq '')) {
                   2831:             $section eq '&nbsp;';
                   2832:         }
                   2833:         if (!defined($uid) || ($uid eq '')) {
                   2834:             $uid = '&nbsp';
                   2835:         }
                   2836:         $reply .= "
                   2837:              <tr>
                   2838:               <td>$uname</td>
                   2839:               <td>$udom</td>
                   2840:               <td>$uid</td>
                   2841:               <td>".&Apache::loncommon::plainname($uname,$udom)."</td>
                   2842:               <td>$section</td>
                   2843:               <td>$start</td>
                   2844:               <td>$end</td>
                   2845:               <td>$$changes{$_}</td>
                   2846:              </tr>";
                   2847:     }
                   2848:     $reply .= "</table>";
                   2849:     return $reply;
                   2850: }
                   2851: 
1.10      raeburn  2852: sub warning_message {
                   2853:     my ($dom,$crs,$caller) = @_;
                   2854:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   2855:     my $currend = '';
                   2856:     my $currstart = '';
                   2857:     my $currsecs = '';
                   2858:     my $currxlists = '';
                   2859:     my $warning = '';
                   2860:     my $curradds = '';
                   2861:     my $currdrops = '';
                   2862:     if ( defined($settings{'internal.autoadds'}) ) {
                   2863:         $curradds = $settings{'internal.autoadds'};
                   2864:     }
                   2865:     if (defined($settings{'internal.autodrops'}) ) {
                   2866:         $currdrops = $settings{'internal.autodrops'};
                   2867:     }
                   2868:     if ( defined($settings{'internal.autostart'}) ) {
                   2869:         $currstart = $settings{'internal.autostart'};
                   2870:     }
                   2871:     if ( defined($settings{'internal.autoend'}) ) {
                   2872:         $currend = $settings{'internal.autoend'};
                   2873:     }
                   2874:     if ( defined($settings{'internal.sectionnums'}) ) {
                   2875:         $currsecs = $settings{'internal.sectionnums'};
                   2876:     }
                   2877:     if ( defined($settings{'internal.crosslistings'}) ) {
                   2878:         $currxlists = $settings{'internal.crosslistings'}
                   2879:     }
                   2880:     unless ($caller eq 'setdates') {
                   2881:         if ( ($currstart eq '') && ($currend eq '') )  {
                   2882:             $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>";
                   2883:         }
                   2884:     }
                   2885:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   2886:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   2887:             $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/>";
                   2888:         }
                   2889:     }
                   2890:     unless ( $caller eq 'chgsettings') {
                   2891:         if ( (!$curradds) && (!$currdrops) ) {
                   2892:             $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/>.";
                   2893:         }
                   2894:     }
                   2895:     return $warning;
1.1       raeburn  2896: }
                   2897: 
                   2898: sub print_reply () {
                   2899:   my ($r,$response,$caller) = @_;
                   2900:   $r->print("
                   2901:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   2902:              <tr>
1.14      raeburn  2903:               <td align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
1.1       raeburn  2904:              </tr>
                   2905:             </table>
                   2906:   ");
                   2907:   return;
                   2908: }
                   2909: 
                   2910: sub setup_date_selectors {
1.14      raeburn  2911:     my ($starttime,$endtime,$action) = @_;
1.1       raeburn  2912:     if (! defined($starttime)) {
                   2913:         $starttime = time;
1.14      raeburn  2914:         if ($action eq 'setdates') {
1.23      albertel 2915:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2916:                             '.default_enrollment_start_date'})) {
1.23      albertel 2917:                 $starttime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2918:                                   '.default_enrollment_start_date'};
1.14      raeburn  2919:             }
1.1       raeburn  2920:         }
                   2921:     }
                   2922:     if (! defined($endtime)) {
                   2923:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  2924:         if ($action eq 'setdates') {
1.23      albertel 2925:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2926:                             '.default_enrollment_end_date'})) {
1.23      albertel 2927:                 $endtime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2928:                                 '.default_enrollment_end_date'};
1.14      raeburn  2929:             }
1.1       raeburn  2930:         }
                   2931:     }
                   2932:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2933:                                                             'startdate',
                   2934:                                                             $starttime);
                   2935:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2936:                                                           'enddate',
                   2937:                                                           $endtime);
                   2938:     return ($startdateform,$enddateform);
                   2939: }
                   2940: 
                   2941: sub get_dates_from_form {
1.14      raeburn  2942:     my $startdate;
                   2943:     my $enddate;
                   2944:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   2945:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.23      albertel 2946:     if ( exists ($env{'form.no_end_date'}) ) {
1.1       raeburn  2947:         $enddate = 0;
                   2948:     }
                   2949:     return ($startdate,$enddate);
                   2950: }
                   2951: 
                   2952: sub date_setting_table {
1.14      raeburn  2953:     my ($starttime,$endtime,$action) = @_;
                   2954:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime,$action);
1.39      albertel 2955:     my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date"';
1.14      raeburn  2956:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || (($action eq 'setaccess' || $action eq 'updatenow') && ($endtime eq '' || $endtime == 0)) ) {
1.1       raeburn  2957:         $perpetual .= ' checked';
                   2958:     }
1.39      albertel 2959:     $perpetual.= ' />'.' no ending date</label></nobr>';
1.1       raeburn  2960:     my $start_table = '';
                   2961:     $start_table .= "<table>\n";
                   2962:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   2963:         '<td>'.$startform.'</td>'.
                   2964:         '<td>&nbsp;</td>'."</tr>\n";
                   2965:     $start_table .= "</table>";
                   2966:     my $end_table = '';
                   2967:     $end_table .= "<table>\n";
                   2968:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   2969:         '<td>'.$endform.'</td>'.
                   2970:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   2971:     $end_table .= "</table>\n";
                   2972:     return ($start_table, $end_table);
                   2973: }
                   2974: 
1.42      raeburn  2975: sub validate_lcsec {
                   2976:     my ($curr_groups,$lcsec) = @_;
                   2977:     if (($lcsec eq 'all') || ($lcsec eq 'none')) {
                   2978:         return 'reserved';
                   2979:     } else {
                   2980:         if (exists($$curr_groups{$lcsec})) {
                   2981:             return 'group'; 
                   2982:         }
                   2983:     }
                   2984:     return 'ok';
                   2985: }
                   2986: 
1.1       raeburn  2987: ###################################################################
                   2988: sub handler {
                   2989:     my $r = shift;
                   2990:     if ($r->header_only) {
1.22      albertel 2991: 	&Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  2992:         $r->send_http_header;
                   2993:         return OK;
                   2994:     }
                   2995:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   2996:     #  Needs to be in a course
1.23      albertel 2997:     if (! (($env{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) {
1.1       raeburn  2998:         # Not in a course, or not allowed to modify parms
1.23      albertel 2999:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
1.34      raeburn  3000:         return HTTP_NOT_ACCEPTABLE;
1.1       raeburn  3001:     }
                   3002:     # Start page
1.22      albertel 3003:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3004:     $r->send_http_header;
                   3005: 
1.34      raeburn  3006:     my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","updatephotos","viewclass");
1.1       raeburn  3007:                                                                                  
                   3008:     my %tasklong = (
                   3009:                information => "Task information",
                   3010:                chgsettings => "Automated adds/drops",
                   3011:                setdates => "Change enrollment dates",
1.14      raeburn  3012:                setaccess => "Change access dates",
1.1       raeburn  3013:                notify => "Notification of changes",
                   3014:                crosslist => "Change crosslistings",
                   3015:                sections => "Section settings",
1.34      raeburn  3016:                photos => "Student photo settings",
                   3017:                updatephotos => "Update student photos",
1.1       raeburn  3018:                updatenow => "Update roster now",
                   3019:                newcross => "Add crosslistings",
1.14      raeburn  3020:                newsections => "Add sections",
1.16      raeburn  3021:                viewclass => "View students and change type",
1.1       raeburn  3022:     );
                   3023:                                                                                  
                   3024:     my %tasktitle = (
                   3025:                chgsettings => "Changes to nightly automated enrollments",
                   3026:                setdates => "Changes to first and/or last automated enrollment dates",
1.14      raeburn  3027:                setaccess => "Changes to default start and/or end dates for student access",
1.1       raeburn  3028:                notify => "Notification of enrollment changes",
                   3029:                crosslist => "Changes to crosslistings",
                   3030:                sections => "Changes to section settings",
1.34      raeburn  3031:                photos => "Student photo settings",
                   3032:                updatephotos => "Update student photos",
1.1       raeburn  3033:                updatenow => "Immediate course roster update",
                   3034:                newcross => "Adding new crosslisted courses",
1.14      raeburn  3035:                newsections => "Adding new course sections",
                   3036:                viewclass => "Viewing class roster and enrollment type"
1.1       raeburn  3037:     );
                   3038: 
                   3039:     my $realm = '';
1.23      albertel 3040:     if ( exists($env{'request.course.id'}) ) {
                   3041:         $realm= $env{'course.'.$env{'request.course.id'}.'.description'};
1.1       raeburn  3042:     }
                   3043:     unless ($realm) { $realm='&nbsp;'; }
1.23      albertel 3044:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3045:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1       raeburn  3046:     
                   3047:     #
                   3048:     # Main switch on form.action and form.state, as appropriate
                   3049:     #
                   3050: 
                   3051:     my $action = "information";
1.23      albertel 3052:     if ( exists($env{'form.action'}) ) {
                   3053:         $action = $env{'form.action'};
1.1       raeburn  3054:     }
                   3055:     my $state = "choose";
                   3056: 
1.23      albertel 3057:     if ( exists($env{'form.state'}) ) {
                   3058:         $state = $env{'form.state'};
1.1       raeburn  3059:     }
                   3060: 
                   3061:     if ($action eq "information") {
                   3062:         $r->print(&header()); 
                   3063:     } else {
                   3064:         if ($state eq "choose") {
1.16      raeburn  3065:             $r->print(&choose_header($action));
1.1       raeburn  3066:         } else {
                   3067:             if ($action eq "crosslist") {
1.23      albertel 3068:                 if ( exists($env{'form.numcross'}) ) {
                   3069:                     if ( $env{'form.numcross'} > 0 ) {
1.16      raeburn  3070:                         $r->print(&choose_header($action));
1.1       raeburn  3071:                     } else {
                   3072:                         $r->print(&header());
                   3073:                     }
                   3074:                 } else {
                   3075:                     $r->print(&header());
                   3076:                 }
                   3077:             } elsif ($action eq "sections") {
1.23      albertel 3078:                 if ( exists($env{'form.numsec'}) ) {
                   3079:                     if ( $env{'form.numsec'} > 0 ) {
1.16      raeburn  3080:                         $r->print(&choose_header($action));
1.1       raeburn  3081:                     } else {
                   3082:                         $r->print(&header());
                   3083:                     }
                   3084:                 } else {
                   3085:                     $r->print(&header());
                   3086:                 }
                   3087:             } else {
                   3088:                 $r->print(&header());
                   3089:             }
                   3090:         }
                   3091:     }
1.12      raeburn  3092: 
1.1       raeburn  3093:     my $reply = 0;
                   3094:     unless ($state eq "choose") { $reply = 1; }
                   3095: 
                   3096:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   3097:     &print_navmenu($r,\@tasks,\%tasklong);
                   3098:     
                   3099:     if (($state eq "choose") || ($action eq "information")) {
1.13      raeburn  3100:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
1.1       raeburn  3101:     } elsif ($action eq "chgsettings") {
                   3102:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3103:     } elsif ($action eq "setdates") {
                   3104:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3105:     } elsif ($action eq "setaccess") {
                   3106:         &print_setaccess_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3107:     } elsif ($action eq "notify") {
                   3108:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3109:     } elsif ($action eq "sections") {
1.13      raeburn  3110:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3111:     } elsif ($action eq "crosslist") {
1.13      raeburn  3112:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3113:     } elsif ($action eq "updatenow") {
1.13      raeburn  3114:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3115:     } elsif ($action eq "photos") {
1.34      raeburn  3116:         if ($state eq "photoupdate") {
                   3117:             &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3118:         } else { 
                   3119:             &photo_permission($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3120:         }
                   3121:     } elsif ($action eq "updatephotos") {
                   3122:         &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3123:     } elsif ($action eq "newcross") {
1.13      raeburn  3124:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
1.1       raeburn  3125:     } elsif ($action eq "newsections") {
1.13      raeburn  3126:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3127:     } elsif ($action eq "viewclass") {
                   3128:         &print_viewclass_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3129:     }
                   3130:     &print_doc_base($r);  
                   3131:     return OK;
                   3132: }
                   3133: ###################################################################
                   3134: 1;

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