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

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

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