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

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

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