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

1.4       albertel    1: # automated enrollment configuration handler
1.41    ! albertel    2: # $Id: lonpopulate.pm,v 1.40 2006/02/10 02:59:02 raeburn Exp $
1.4       albertel    3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
1.1       raeburn    26: package Apache::lonpopulate;
                     27: 
                     28: use strict;
                     29: use lib qw(/home/httpd/lib/perl);
1.7       raeburn    30: use Apache::lonnet;
                     31: use Apache::loncommon;
                     32: use Apache::lonhtmlcommon;
1.3       albertel   33: use Apache::lonlocal;
1.14      raeburn    34: use Apache::loncoursedata;
1.1       raeburn    35: use Apache::Constants qw(:common :http REDIRECT);
                     36: use Time::Local;
1.7       raeburn    37: use LONCAPA::Enrollment;
1.1       raeburn    38: 
                     39: ###############################################################
                     40: sub header {
1.41    ! albertel   41:     return &Apache::loncommon::start_page('Classlist Manager');
1.1       raeburn    42: }
                     43: 
                     44: ###############################################################
                     45: 
                     46: sub choose_header {
1.41    ! albertel   47:     my ($action) = @_;
        !            48: 
1.1       raeburn    49:     my $scripttag = qq|
                     50: <script language='javascript' type='text/javascript'>
                     51: <!--
1.16      raeburn    52: function process(calling,numauto,nummanual,numlock,numunlock) {
1.1       raeburn    53:  var checker = 1
                     54:  var rad1 = 0
                     55:  var rad2 = 0
                     56:  var formName = document.forms.enter
1.14      raeburn    57:  if (calling == "viewclass") {
                     58:      formName = document.forms.studentform
                     59:  }
1.1       raeburn    60:  formName.action.value = calling
                     61:  if (calling == "chgsettings") {
                     62:    for (var j=0; j<formName.autoadds.length; j++) {
                     63:        if (formName.autoadds[j].checked) {
                     64:            rad1 = 1
                     65:        }
                     66:    }
                     67:    for (var k=0; k<formName.autodrops.length; k++) {
                     68:        if (formName.autodrops[k].checked) {
                     69:            rad2 = 1
                     70:        }
                     71:    }
                     72:    if (rad1 == 0) {
1.17      raeburn    73:        alert("You must select either 'Enable' or 'Disable' for nightly additions based on classlist changes")
1.1       raeburn    74:        checker = 0
                     75:    }
                     76:    if (rad2 == 0) {
1.17      raeburn    77:        alert("You must select either 'Enable' or 'Disable' for nightly removals based on classlist changes")
1.1       raeburn    78:        checker = 0
                     79:    }
                     80:  }
                     81:  if (calling == "updatenow") {
                     82:      var enrolldis
                     83:      var unenrolldis
                     84:      for (var j=0; j<formName.updateadds.length; j++) {
                     85:          if (formName.updateadds[j].value == 0) {
                     86:              enrolldis = j
                     87:          }
                     88:          if (formName.updateadds[j].checked) {
                     89:              rad1 = 1
                     90:          }
                     91:      }
                     92:      for (var k=0; k<formName.updatedrops.length; k++) {
                     93:          if (formName.updatedrops[k].value == 0) {
                     94:              unenrolldis = k 
                     95:          }
                     96:          if (formName.updatedrops[k].checked) {
                     97:              rad2 = 1
                     98:          }
                     99:      }
                    100:      if (rad1 == 0) {
1.17      raeburn   101:          alert("You must select either 'Yes' or 'No' for immediate addition of newly registered students to the roster")
1.1       raeburn   102:          checker = 0
                    103:      }
                    104:      if (rad2 == 0) {
1.17      raeburn   105:          alert("You must select either 'Yes' or 'No' for immediate removal of unregistered students from the roster")
1.1       raeburn   106:          checker = 0
                    107:      }
                    108:      if (formName.updatedrops[unenrolldis].checked && formName.updateadds[enrolldis].checked ) {
1.17      raeburn   109:          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   110:          checker = 0
                    111:      }
                    112:  }
1.14      raeburn   113:  if (calling == "viewclass") {
1.16      raeburn   114:      var totcheck = 0
1.20      raeburn   115:      var numchk = 0
1.16      raeburn   116:      if (numauto > 0) {
1.20      raeburn   117:          numchk = countChecked(document.studentform.chgauto);
                    118:          totcheck = totcheck + numchk
1.16      raeburn   119:      }
                    120:      if (nummanual > 0) {
1.20      raeburn   121:          numchk = countChecked(document.studentform.chgmanual);
                    122:          totcheck = totcheck + numchk
1.16      raeburn   123:      }
                    124:      if (numlock > 0) {
1.20      raeburn   125:          numchk = countChecked(document.studentform.lockchg);
                    126:          totcheck = totcheck + numchk
1.16      raeburn   127:      }
                    128:      if (numunlock > 0) {
1.20      raeburn   129:          numchk = countChecked(document.studentform.unlockchg);
                    130:          totcheck = totcheck + numchk
1.16      raeburn   131:      }
                    132:      if (totcheck > 0) {
1.20      raeburn   133:         document.forms.studentform.state.value = "process";
                    134:      }
                    135:      if (totcheck == 0) {
1.16      raeburn   136:         alert("You must check at least one checkbox, before proceeding to the next page")
                    137:         checker = 0
                    138:      }
1.14      raeburn   139:  } 
1.1       raeburn   140:  if (checker == 1) {  
                    141:      formName.submit();
                    142:  }
                    143: }
1.16      raeburn   144: |;
                    145:     if ($action eq 'viewclass') {
1.25      raeburn   146:         $scripttag .= &Apache::loncommon::check_uncheck_jscript();
1.16      raeburn   147:         $scripttag .= qq|
1.20      raeburn   148: function countChecked(field) {
                    149:     var count = 0;
                    150:     if (field.length > 0) {
                    151:         for (var i=0; i<field.length; i++) {
                    152:             if (field[i].checked == true) {
                    153:                 count ++
                    154:             }
                    155:         }
                    156:     } else {
                    157:         if (field.checked == true) {
                    158:             count ++
                    159:         }
                    160:     }
                    161:     return count
                    162: }
                    163: 
1.16      raeburn   164: |;
                    165:     }
                    166:     $scripttag .= qq|
1.1       raeburn   167: // End hiding -->
                    168: </script>
                    169: |;
1.41    ! albertel  170: 
        !           171:     return &Apache::loncommon::start_page('Classlist Manager',
        !           172: 					  $scripttag);
1.1       raeburn   173: }
                    174: 
                    175: sub print_mainbox {
                    176:     my ($r,$tasklongref,$realm,$reply) = @_;
                    177:     my $action = "information";
1.23      albertel  178:     if ( exists($env{'form.action'}) ) {
                    179:         $action = $env{'form.action'};
1.1       raeburn   180:     }
                    181:     my $page = '';
                    182:     if ($action eq "information") {
                    183:         $page = "<b>Automated Enrollment</b>";
                    184:     } else {
                    185:         $page =  '<a href="/adm/populate">Automated Enrollment</a>';
                    186:         if ($reply) {
                    187:             if ($action eq "newcross") {
                    188:                 $action = "crosslist";
                    189:             } elsif ($action eq "newsections") {
                    190:                 $action = "sections"; 
                    191:             }
                    192:             $page .= "-&gt; <a href=\"/adm/populate?action=$action\">".$$tasklongref{$action}."</a> -&gt; <b>result</b>";
                    193:         } else {
                    194:             $page .=  " -&gt; <b>".$$tasklongref{$action}."</b>"; 
                    195:         }
                    196:     }
                    197:     $r->print(<<ENDTHIS);
                    198: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    199:  <tr>
                    200:   <td bgcolor="#CCCCFF"> 
                    201:    <font size="2"><a href="/adm/menu">$realm</a> -&gt; <a href="/adm/dropadd">Enrollment Manager</a> -&gt; $page</font><br/>
                    202:   </td>
                    203:   <td align="right" bgcolor="#CCCCFF" valign="top">
                    204:    <font size="+1">Automated Enrollment Manager&nbsp;</font>
                    205:   </td>
                    206:  </tr>
                    207: </table>
                    208: <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    209:  <tr>
                    210: ENDTHIS
                    211: }
                    212: 
                    213: sub print_navmenu {
                    214:     my ($r,$tasksref,$tasklongref) = @_;
                    215:     my $action = "information";
1.23      albertel  216:     if (exists($env{'form.action'}) ) {
                    217:         $action = $env{'form.action'};
1.1       raeburn   218:     }
                    219:     $r->print(<<ENDONE);
                    220:   <td width="10" valign="top" bgcolor="#DDFFFF">&nbsp;</td>
                    221:   <td width="20%" valign="top" bgcolor="#DDFFFF">
                    222:    <br/>
                    223: ENDONE
                    224:     foreach my $task (@{$tasksref}) {
                    225:         if ($task eq $action) {
                    226:             $r->print(" 
                    227:    <p>
                    228:    <font color=\"#999999\">
                    229:     <b>$$tasklongref{$task}</b><br/>
                    230:    </font>
                    231:    </p>"); 
                    232:         } else {
                    233:             $r->print("
                    234:    <p>
                    235:    <font color=\"#004263\">
                    236:     <b><a href=\"/adm/populate?action=$task\">$$tasklongref{$task}</a></b><br/>
                    237:    </font> 
                    238:    </p>");
                    239: 
                    240:         }
                    241:     }
                    242:     $r->print("
                    243:   <p>&nbsp;</p>
                    244:   </td>
                    245:   <td width=\"10\" valign=\"top\" bgcolor=\"#CCCCFF\">&nbsp;</td>
                    246:   <td width=\"10\" valign=\"top\" bgcolor=\"#FFFFFF\">&nbsp;</td>
                    247:   <td bgcolor=\"#ffffff\" valign=\"top\">");
                    248: }
                    249: 
                    250: ###############################################################
                    251: 
                    252: sub print_main_frame {
1.13      raeburn   253:   my ($r,$realm,$dom,$crs,$tasktitleref) = @_;
1.1       raeburn   254:   my $action = "information";
1.23      albertel  255:   if (exists($env{'form.action'}) ) {
                    256:       $action = $env{'form.action'};
1.1       raeburn   257:   }
                    258: 
                    259: # Get course settings
                    260:   my %enrollvar;
                    261:   my @bgcolors=("#eeeeee","#cccccc");
                    262:   my %settings = &Apache::lonnet::dump('environment',$dom,$crs);
                    263:   foreach my $item (keys %settings) {
                    264:       if ($item =~ m/^internal\.(.+)$/) {
                    265:           $enrollvar{$1} = $settings{$item};
1.14      raeburn   266:       } elsif ($item =~ /^default_enrollment_(start|end)_date$/) {
                    267:           $enrollvar{$item} = $settings{$item};
1.1       raeburn   268:       }
                    269:   }
                    270: 
                    271:   if ($action eq "information") {
                    272:       $r->print(<<ENDONE);
1.2       raeburn   273:           <br/><table border='0' width='100%'>
1.1       raeburn   274:             <tr>
                    275:               <td>&nbsp;</td>
                    276:               <td><b>Use the menu on the left to choose an enrollment management task.</b><br/><br/></td>
                    277:             <tr>
                    278:               <td>&nbsp;</td>
1.16      raeburn   279:               <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   280:             </tr>
                    281:             <tr>
                    282:               <td>&nbsp;</td>
                    283:               <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>
                    284:             </tr>
                    285:             <tr>
                    286:               <td>&nbsp;</td>
1.14      raeburn   287:               <td>Use <i>"Change access dates"</i> to change the default start and/or end dates for student roles created by automated enrollment.</td>
                    288:             </tr>
                    289:             <tr>
                    290:               <td>&nbsp;</td>
1.1       raeburn   291:               <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>
                    292:             </tr>
                    293:             <tr>
                    294:               <td>&nbsp;</td>
                    295:               <td>Use <i>"Change crosslisting"</i> to include or exclude enrollment from crosslisted classes.</td>
                    296:             </tr>
                    297:             <tr>
                    298:               <td>&nbsp;</td>
                    299:               <td>Use <i>"Section settings"</i> to make changes to the choice of sections included for enrollment in your LON-CAPA course.</td>
                    300:             </tr>
                    301:               <td>&nbsp;</td>
1.34      raeburn   302:               <td>Use <i>"Student photos settings"</i> to enable or disable automatic import of photos for registered students in your course.</td>
1.1       raeburn   303:             </tr>
                    304:             <tr>
                    305:               <td>&nbsp;</td>
                    306:               <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>
                    307:             </tr>
                    308:             <tr>
1.16      raeburn   309:               <td>&nbsp;</td>
1.34      raeburn   310:               <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>
                    311:             </tr>
                    312:             <tr>
                    313:               <td>&nbsp;</td>
1.16      raeburn   314:               <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>
                    315:             </tr>
                    316:             <tr>
1.1       raeburn   317:              <td colspan='2'>&nbsp;</td>
                    318:             </tr>
                    319:             <tr>
                    320:              <td>&nbsp;</td>
                    321:              <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>
                    322:             </tr>
                    323:           </table>
                    324: ENDONE
                    325:   } elsif ($action eq "chgsettings") {
                    326:       my @autosets = ("OFF","ON");
                    327:       $r->print(<<ENDTWO);
                    328:                   <form name="enter" method="post"><br/>
                    329: 		  <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    330: 		   <tr>
                    331: 		    <td align="left"><b>$$tasktitleref{$action}</b><br/>
                    332: 		       Currently: Nightly adds: <i>$autosets[$enrollvar{autoadds}]</i>, Nightly drops: <i>$autosets[$enrollvar{autodrops}]</i>
                    333: 		    </td>
                    334:                    </tr>
                    335: 		  </table>
                    336: 		  <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    337: 		    <tr>
                    338: 		     <td>
                    339: 		         Additions based on classlist changes:&nbsp;&nbsp;
                    340: ENDTWO
                    341:       if ($enrollvar{autoadds}) {
                    342:           $r->print("
1.39      albertel  343: 			    <label><input type=\"radio\" name=\"autoadds\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;</label>
                    344: 			    <label><input type=\"radio\" name=\"autoadds\" value=\"0\" />&nbsp;Disable</label>
1.1       raeburn   345:          ");
                    346:       } else {
                    347:           $r->print("
1.39      albertel  348:                             <label><input type=\"radio\" name=\"autoadds\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;</label>
                    349:                             <label><input type=\"radio\" name=\"autoadds\" value=\"0\" checked=\"true\" />&nbsp;Disable</label>
1.1       raeburn   350:          ");
                    351:       }
                    352:       $r->print("
                    353:               </td>
                    354:              </tr>
                    355:              <tr>
                    356:               <td>
                    357:  	       Removals based on classlist changes:&nbsp;&nbsp;");
                    358:       if ($enrollvar{autodrops}) {
                    359:           $r->print("
1.39      albertel  360:                 <label><input type=\"radio\" name=\"autodrops\" value=\"1\" checked=\"true\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;</label>
                    361:                 <label><input type=\"radio\" name=\"autodrops\" value=\"0\" />&nbsp;Disable</label>");
1.1       raeburn   362:       } else {
                    363:           $r->print("
1.39      albertel  364:                 <label><input type=\"radio\" name=\"autodrops\" value=\"1\" />&nbsp;Enable&nbsp;&nbsp;&nbsp;</label>
                    365:                 <label><input type=\"radio\" name=\"autodrops\" value=\"0\" checked=\"true\" />&nbsp;Disable</label>");
1.1       raeburn   366:       }
                    367:       $r->print("
                    368:               </td>
                    369:              </tr>
                    370:              <tr>
                    371:               <td>
                    372:                <font color=\"#888888\">
                    373: 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.
                    374:                </font>
                    375:               </td>
                    376:              </tr>
                    377:              <tr>
                    378:               <td align=\"right\">
1.39      albertel  379:                <input type=\"button\" name=\"chgsettings\" value=\"Go\" onclick=\"process('chgsettings')\" />
1.1       raeburn   380: 	      </td>
                    381:              </tr>
                    382: 	    </table>
1.39      albertel  383:             <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    384:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn   385:             </form>
                    386:       ");
                    387:   } elsif ($action eq "setdates") {
1.14      raeburn   388:       my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend},$action);
1.10      raeburn   389:       my $oldstartshow = '';
                    390:       my $oldendshow = '';
                    391:       if ( defined($enrollvar{autostart}) ) {
1.14      raeburn   392:           $oldstartshow = &Apache::lonlocal::locallocaltime($enrollvar{autostart});
1.10      raeburn   393:       }
                    394:       if ( defined($enrollvar{autoend}) ) {
1.14      raeburn   395:           $oldendshow = &Apache::lonlocal::locallocaltime($enrollvar{autoend});
1.10      raeburn   396:           if ($enrollvar{autoend} == 0) {
                    397:               $oldendshow = "No ending date";
                    398:           }
                    399:       }
                    400:       my $dateshow;
                    401:       if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
1.14      raeburn   402:          $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   403:       } else {
                    404:          $dateshow = "Currently: First enrollment: <b><i>$oldstartshow</i></b>, Last enrollment: <b><i>$oldendshow</i></b>\n";
1.1       raeburn   405:       }
                    406:       $r->print(<<ENDTWO);
                    407:                   <form name="enter" method="post"><br/>              
                    408:                   <table width="100%" border="0" cellpadding="2" cellspacing="2">
                    409: 	           <tr>
1.10      raeburn   410: 	            <td align="left"><b>$$tasktitleref{$action}</b><br/><br/>
                    411:                      $dateshow
1.1       raeburn   412: 	            </td>
                    413:                    </tr>
                    414: 	          </table>
                    415:                   <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    416:                    <tr>
                    417:                     <td align="left" colspan="2">
                    418:                      <table border="0" cellspacing="0" cellpadding="2">
                    419:                       <tr>
                    420:                        <td colspan="3">
                    421:                         <i>Set date of first automated enrollment for registered students</i>
                    422:                        </td>
                    423:                       </tr>
                    424:                       <tr>
                    425:                        <td>$start_table
                    426:                        </td>
                    427:                       </tr>
                    428:                      </table>
                    429:                     </td>
                    430:                    </tr>
                    431:                    <tr>
                    432:                     <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>
                    433:                    </tr>
                    434:                    <tr>
                    435:                     <td align="left" colspan="2">
                    436:                      <table border="0' cellspacing="0" cellpadding="2">
                    437:                       <tr>
                    438:                        <td colspan="3">
                    439:                         <i>Set date of last automated enrollment for registered students</i>
                    440:                        </td>
                    441:                       </tr>
                    442:                       <tr>
                    443:                        <td>$end_table
                    444:                        </td>
                    445:                       </tr>
                    446:                      </table>
                    447:                     </td>
                    448:                    </tr>
                    449:                    <tr>
                    450:                     <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>
                    451:                    </tr>
                    452:                   </table>
                    453:                   <table width="100%">
                    454:                    <tr>
                    455:                     <td align="right">
1.39      albertel  456:                       <input type="button" name="setdates" value="Go" onclick="process('setdates')" />
1.1       raeburn   457:                     </td>
                    458: 	           </tr>
                    459:                   </table>
1.39      albertel  460:                   <input type="hidden" name="action" value="$action" />
                    461:                   <input type="hidden" name="state" value="process" />
1.14      raeburn   462:                   </form>
                    463: ENDTWO
                    464:   } elsif ($action eq "setaccess") {
                    465:       &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
                    466:       $r->print(<<ENDTWO);
                    467:                   <table width="100%">
                    468:                    <tr>
                    469:                     <td align="right">
1.39      albertel  470:                       <input type="button" name="$action" value="Go" onclick="process('$action')" />
1.14      raeburn   471:                     </td>
                    472:                    </tr>
                    473:                   </table>
1.39      albertel  474:                   <input type="hidden" name="action" value="$action" />
                    475:                   <input type="hidden" name="state" value="process" />
1.1       raeburn   476:                   </form>
                    477: ENDTWO
                    478:   } elsif ($action eq "notify") {
1.30      raeburn   479:       my $notifycount = 0;
1.28      albertel  480:       my @notified = split(/,/,$enrollvar{notifylist});
1.1       raeburn   481:       foreach  (@notified) {
1.28      albertel  482: 	  unless ($_ eq '') { $notifycount ++; } 
1.1       raeburn   483:       }
                    484:       my $noteset = '';
                    485:       if ($notifycount) {
                    486:           $noteset = "ON";
                    487:       } else {
                    488:           $noteset = "OFF";
                    489:       }
                    490:     
                    491:       $r->print("
                    492:                   <form name=\"enter\" method=\"post\"><br/>
                    493:                    <table width=\"100%\" border=\"0\" cellpadding=\"6\" cellspacing=\"0\">
                    494:                     <tr>
                    495:                      <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    496:                       Currently: Notification: $noteset
                    497:                      </td>
                    498:                     </tr>
                    499:                    </table>
                    500:                    <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    501:                     <tr>
                    502:                      <td>
                    503:                       Notification of LON-CAPA course roster changes resulting from nightly automated enrollment process?
                    504:       ");
                    505:       if ($notifycount) {
                    506:           $r->print("
1.39      albertel  507:                         <label><input type=\"radio\" name=\"notify\" value=\"1\" checked=\"true\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;</label>
                    508:                         <label><input type=\"radio\" name=\"notify\" value=\"0\" />&nbsp;No</label>
1.1       raeburn   509:           ");
                    510:       } else {
                    511:           $r->print("
1.39      albertel  512:                         <label><input type=\"radio\" name=\"notify\" value=\"1\" />&nbsp;Yes&nbsp;&nbsp;&nbsp;</label>
                    513:                         <label><input type=\"radio\" name=\"notify\" value=\"0\" checked=\"true\" />&nbsp;No</label>
1.1       raeburn   514:           ");
                    515:       }
                    516:       $r->print("
                    517:               </td>
                    518:              </tr>
                    519:       ");
1.7       raeburn   520:       my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs);
                    521:       my @ccs = ();
                    522:       my @oldccs = ();
                    523:       my %pname = ();
                    524:       my %notifystate = ();
                    525:       foreach (@coursepersonnel) {
                    526:           my @roleinfo = split/:/,$_;
                    527:           if ($roleinfo[0] eq 'cc')  {
                    528:               unless (grep/^$roleinfo[1]\@$roleinfo[2]/,@ccs) {
1.26      raeburn   529:                   my $active_cc = &Apache::loncommon::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc');
                    530:                   if ($active_cc eq 'active') {
1.7       raeburn   531:                       push @ccs, "$roleinfo[1]\@$roleinfo[2]";
                    532:                       $pname{"$roleinfo[1]\@$roleinfo[2]"} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
                    533:                       if (grep/^$roleinfo[1]\@$roleinfo[2]$/,@notified) {
                    534:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 1;
                    535:                       } else {
                    536:                           $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 0;
                    537:                       }
1.1       raeburn   538:                   } else {
1.7       raeburn   539:                       push @oldccs, "$roleinfo[1]\@$roleinfo[2]";
1.1       raeburn   540:                   }
                    541:               }
                    542:           }
                    543:       }
1.7       raeburn   544:       if ($notifycount > 0) {
                    545:           foreach my $person (@notified) {
                    546:               unless ( (grep/^$person$/,@ccs) || ($person eq '') || (grep/^$person$/,@oldccs) ) {
                    547:                   push @ccs, $person;
                    548:                   my ($puname,$pdom) = split/\@/,$person;
                    549:                   $pname{$person} =  &Apache::loncommon::plainname($puname,$pdom);
                    550:                   $notifystate{$person} = 1;
                    551:               }
                    552:           }
                    553:       }
1.23      albertel  554:       my $viewer = $env{'user.name'}.'@'.$env{'user.domain'};
1.7       raeburn   555:       unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') )  {
                    556:           push @ccs,$viewer;
1.23      albertel  557:           $pname{$viewer} =  &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
1.7       raeburn   558:           $notifystate{$viewer} = 0;
                    559:       }
                    560: 
1.29      albertel  561:       my $notifyshow = @ccs;
1.7       raeburn   562: 
                    563:       if (@ccs > 0) {
                    564:           @ccs = sort @ccs;
1.1       raeburn   565:           $r->print("
                    566:              <tr>
1.7       raeburn   567:                <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   568:               </td>
                    569:              </tr>
                    570:              <tr>
                    571:               <td>
1.7       raeburn   572:                <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    573:                 <tr bgcolor=\"#CCCCFF\">
                    574:                  <td><b>Name</b></td>
                    575:                  <td><b>username</b></td>
                    576:                  <td><b>Current status</b></td>
                    577:                  <td><b>Notification?</b></td>
                    578:                 </tr>
                    579:           ");
                    580:           for (my $i=0; $i<@ccs; $i++) {
                    581:               my $colflag = $i%2;
                    582:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    583:                  <td>$pname{$ccs[$i]}</td>
                    584:                  <td><input type=\"hidden\" name=\"notifyname_$i\" value=\"$ccs[$i]\" />$ccs[$i]</td>
                    585:                  <td>
                    586:               ");
                    587:               if ($notifystate{$ccs[$i]} == 1) {
                    588:                   $r->print("Notification active");
                    589:               } else {
                    590:                   $r->print("Notification inactive");
                    591:               }
                    592:               if ($notifystate{$ccs[$i]} == 1) {
                    593:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" checked=\"true\" /></td></tr>");
                    594:               } else {
                    595:                   $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" /></td></tr>");
                    596:               }
                    597:           }
                    598:           $r->print("
                    599:                </table>
                    600:                <br/>
                    601:                <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    602:                 <tr>
                    603:                  <td align=\"right\">
1.39      albertel  604:                   <input type=\"button\" name=\"notifyset\" value=\"Go\" onclick=\"process('notify')\" />
1.7       raeburn   605:                  </td>
                    606:                 </tr>
                    607:                </table>
                    608:               </td>
                    609:              </tr>
1.1       raeburn   610:           ");
1.7       raeburn   611:       } else {
1.1       raeburn   612:           $r->print("
1.7       raeburn   613:              <tr>
                    614:               <td>
                    615:              No course coordinators found.
1.1       raeburn   616:             </td>
1.7       raeburn   617:            </tr>");
1.1       raeburn   618:       }
                    619:       $r->print("
1.7       raeburn   620:           </table>
1.39      albertel  621:           <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\" />
                    622:           <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    623:           <input type=\"hidden\" name=\"state\" value=\"process\" />
1.7       raeburn   624:           </form>
1.1       raeburn   625:       ");
                    626:   } elsif ($action eq "crosslist") {
1.28      albertel  627:       my @xlists;
                    628:       if ($enrollvar{crosslistings} ne '') {
                    629: 	  @xlists = split(/,/,$enrollvar{crosslistings});
1.1       raeburn   630:       }
1.29      albertel  631:       my $cross_str = @xlists;
1.1       raeburn   632:       $r->print("
                    633:             <form name=\"enter\" method=\"post\"><br/>
                    634:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    635:              <tr>
                    636:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    637:       ");
                    638:       if ($cross_str > 0) {
                    639:           $r->print("
1.7       raeburn   640:                 Currently, this LON-CAPA course is crosslisted with $cross_str course section(s).  Students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.  For each crosslisting, leave the checkbox checked if you want registered students in that course to be included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise uncheck it. If you wish to change the section/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this crosslisting. If you wish to add new crosslisted courses, enter the number of new courses to add in the textbox at the bottom of the page. You will provide information about each of the new crosslistings on a subsequent page.  Click 'Go' to store your changes.
1.1       raeburn   641:               </td>
                    642:              </tr>
                    643:             </table>
                    644:             <br/>
                    645:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    646:              <tr>
                    647:               <td>
                    648:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    649:                 <tr bgcolor=\"#CCCCFF\" align=\"left\">
                    650:                  <td><b>Enrollment?</b></td>
                    651:                  <td><b>Crosslisted course</b></td>
                    652:                  <td><b>LON-CAPA section/groupID</b></td>
                    653:                 </tr>
                    654:           ");
                    655:           for (my $i=0; $i<@xlists; $i++) {
                    656:               my $xl = '&nbsp;';
                    657:               my $gp = '&nbsp;';
1.31      raeburn   658:               if ($xlists[$i] =~ /^([^:]+):?(.*)$/) {
1.1       raeburn   659:                   $xl = $1;
                    660:                   $gp = $2;
                    661:               }               
                    662:               my $colflag = $i%2;
                    663:               $r->print("
                    664:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.39      albertel  665:                  <td><input type=\"checkbox\" name=\"cross_$i\" checked=\"true\" /></td>
1.1       raeburn   666:                  <td>$xl</td>
1.39      albertel  667:                  <td><input type =\"text\" size=\"10\" name=\"gp_$i\" value=\"$gp\" /></td>
1.1       raeburn   668:                 </tr> 
                    669:               ");
                    670:           }
                    671:           $r->print("  </table>
                    672:               </td>
                    673:              </tr>
                    674:             </table>
                    675:           ");
                    676:       }
                    677:       else {
                    678:           $r->print("
                    679:                 Currently no crosslisted courses are recorded for $enrollvar{coursecode}.
                    680:               </td>
                    681:              </tr>
                    682:             </table>
                    683:           ");
                    684:       }
                    685:       $r->print("   
                    686:             <br/>
                    687:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    688:              <tr>
                    689:               <td align=\"left\">
                    690:                <b>Add new crosslistings.</b><br/>
                    691:                Number of new crosslistings to add:&nbsp;&nbsp;<input type=\"text\" size=\"2\" name=\"numcross\" value=\"0\" />
                    692:               </td>
                    693:              </tr>
                    694:             </table>
                    695:             <br/>
                    696:             <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
                    697:              <tr>
                    698:               <td align=\"right\">
1.39      albertel  699:                <input type=\"button\" name=\"crosslist\" value=\"Go\" onclick=\"process('crosslist')\" />
1.1       raeburn   700:               </td>
                    701:              </tr>
                    702:             </table>
1.39      albertel  703:             <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    704:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn   705:             </form> 
                    706:       ");
                    707:   } elsif ($action eq "sections") {
1.12      raeburn   708:       my @sections = ();
1.13      raeburn   709:       @sections = &Apache::lonnet::auto_get_sections($crs,$dom,$enrollvar{coursecode});
1.28      albertel  710:       my @storedsections = split(/,/,$enrollvar{sectionnums});
1.1       raeburn   711:       my @currsections = ();
                    712:       my %sec_id = ();
                    713:       foreach (@storedsections) {
                    714:           if ($_ =~ m/^(\w+):(\w*)$/) {
                    715:               push @currsections, $1;
                    716:               $sec_id{$1} = $2;
                    717:           }
                    718:       }
                    719:       if (@sections > 0) {
1.29      albertel  720:           my $secshow = @sections;
1.8       raeburn   721:           $r->print("
1.1       raeburn   722:             <form name=\"enter\" method=\"post\"><br/>
                    723:             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    724:              <tr>
                    725:               <td align=\"left\">
                    726:                <b>$$tasktitleref{$action}</b><br/>
                    727:                Your institution's course catalog includes $secshow sections for course code: $enrollvar{coursecode}.
                    728:               </td>
                    729:              </tr>
                    730:              <tr>
1.5       raeburn   731:               <td>For each section, check the checkbox if you want registered students in that section to be included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise uncheck it. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. To add a new section, check the 'Enrollment in this course?' checkbox, and enter the desired LON-CAPA section/groupID in the appropriate textbox. Click 'Go' to store
                    732: your changes.</td>
1.1       raeburn   733:              </tr>
                    734:             </table>
                    735:             <br/>
1.7       raeburn   736:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    737:              <tr bgcolor=\"#CCCCFF\">
                    738:               <td><b>Section</b></td>
                    739:               <td><b>Current status</b></td>              
                    740:               <td><b>LON-CAPA section/group ID</b></td>
                    741:               <td><b>Enrollment in this course?</b></td>
                    742:              </tr>
1.8       raeburn   743:           ");
                    744:           for (my $i=0; $i<@sections; $i++) {
                    745:               my $colflag = $i%2;
                    746:               my $shrflag = 0;
                    747:               $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.5       raeburn   748:                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" /></td>
1.1       raeburn   749:                    <td>
1.8       raeburn   750:               ");
                    751:               if (grep/^$sections[$i]$/,@currsections) {
                    752:                   $r->print("Enrollment active");
                    753:                   $shrflag = 1;
                    754:               } else {
                    755:                   $r->print("Enrollment inactive");
                    756:               }
                    757:               if ($shrflag) {
                    758:                   $r->print("</td><td><input type=\"text\" size=\"10\" name=\"loncapasec_$i\" value=\"$sec_id{$sections[$i]}\"></td><td><input type=\"checkbox\" name=\"sec_$i\" checked=\"true\" /></td></tr>"); 
                    759:               } else {
1.39      albertel  760:                   $r->print("</td><td><input type=\"text\" size=\"10\" name=\"loncapasec_$i\" value=\"\" /></td><td><input type=\"checkbox\" name=\"sec_$i\" /></td></tr>");
1.1       raeburn   761:               }
1.8       raeburn   762:           }
                    763:           $r->print("
1.7       raeburn   764:             </table>
                    765:             <br/>
                    766:             <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
                    767:              <tr> 
                    768:               <td align=\"right\">
                    769:                <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />
1.39      albertel  770:                <input type=\"button\" name=\"sections\" value=\"Go\" onclick=\"process('sections')\" />
1.7       raeburn   771:               </td>
                    772:              </tr>
                    773:             </table>
1.39      albertel  774:             <input type=\"hidden\" name=\"action\" value=\"$action\" />
                    775:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.7       raeburn   776:             </form>
1.8       raeburn   777:           ");
1.1       raeburn   778:       } else {
                    779:           $r->print("
                    780:             <form name=\"enter\" method=\"post\"><br/>
                    781:             <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                    782:              <tr>
                    783:               <td align=\"left\"><b>$$tasktitleref{$action}</b><br/>
                    784:           ");
                    785:           if (@currsections) {
1.29      albertel  786:               my $secshow = @currsections;
1.1       raeburn   787:               $r->print("
1.7       raeburn   788:                 Currently, this LON-CAPA course incorporates enrollment from $secshow sections.  Students enrolling in any of these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update. For each section, uncheck the checkbox if you want registered students in that section to cease being included in the student roster for LON-CAPA course: <b>$realm ($enrollvar{coursecode})</b>; otherwise leave it checked. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID textbox and enter the new value.  If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes.
1.1       raeburn   789:               </td>
                    790:              </tr>
                    791:             </table>
                    792:             <br/>
                    793:             <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
                    794:              <tr>
                    795:               <td>
                    796:                <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">
                    797:                 <tr bgcolor=\"#CCCCFF\">
                    798:                  <td><b>Enrollment?</b></td>
                    799:                  <td><b>Section</b></td>
                    800:                  <td><b>LON-CAPA section/groupID</b></td>
                    801:                 </tr>
                    802:               ");
                    803:               for (my $j=0; $j<@currsections; $j++) {
                    804:                   my $colflag = $j%2;
                    805:                   $r->print("
                    806:                 <tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
1.39      albertel  807:                  <td><input type=\"checkbox\" name=\"sec_$j\" checked=\"true\" /></td>
1.1       raeburn   808:                  <td>$currsections[$j]</td>
1.39      albertel  809:                  <td><input type=\"text\" name=\"secgp_$j\" size=\"10\" value=\"$sec_id{$currsections[$j]}\" /></td>
1.1       raeburn   810:                 </tr> 
                    811:                   ");
                    812:               }
                    813:               $r->print("  </table>
                    814:               </td>
                    815:              </tr>
                    816:             </table>
                    817:               ");
                    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;
                   1647: 	    my $gp = "gp_".$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.23      albertel 1653: 		if ( exists($env{"form.$gp"}) ) {
                   1654: 		    $xlistentry .= $env{"form.$gp"};
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) {
                   1677: 		my ($xlist,$gp) = split/:/,$_;
                   1678: 		$response .= "<li>$xlist - ID: $gp</li>\n";
                   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");
                   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/group ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in the crosslisted course section. The LON-CAPA section/group ID can be left blank, if you do not wish to tie a section/group ID to this crosslisting.  The institutional course section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course codes (and section numbers) to your institution\'s student information system.<br/><br/>
1.1       raeburn  1688:            <form name="enter" method="post">
                   1689:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1690:              <tr>
                   1691:               <td>
                   1692:                <table border="0" cellspacing="3" cellpadding="3">
                   1693:                 <tr bgcolor="#CCCCFF" align="left">
                   1694:                  <td><b>Crosslisting</b></td>
                   1695:                  <td><b>LON-CAPA section/groupID</b></td>
                   1696:                 </tr>
1.15      albertel 1697: 			    );
                   1698: 	    for (my $i=0; $i<$numcross; $i++) {
                   1699: 		my $colflag = $i%2;
                   1700: 		$response .= qq(
1.1       raeburn  1701:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1702:                  <td><input type="text" size="15" name="newcross_$i" /></td>
                   1703:                  <td><input type="text" size="10" name="newgroupid_$i" /></td>
                   1704:                 </tr>
1.15      albertel 1705: 				);
                   1706: 	    }
                   1707: 	    $response .= qq(  </table>
1.1       raeburn  1708:               </td>
                   1709:              </tr>
                   1710:              <tr>
                   1711:               <td align="right">
1.39      albertel 1712:                <input type="button" name="newcross" value="Go" onclick="process('newcross')" />
1.1       raeburn  1713:               </td>
                   1714:              </tr>
                   1715:             </table>
1.39      albertel 1716:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\" />
                   1717:             <input type=\"hidden\" name=\"action\" value=\"newcross\" />
                   1718:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  1719:             </form>
1.15      albertel 1720: 			      );
                   1721:         }
                   1722:     }
                   1723:     &print_reply($r,$response,$$tasktitleref{$action});
                   1724:     return;
1.1       raeburn  1725: }
                   1726: 
                   1727: sub print_crosslistings_response () {
1.15      albertel 1728:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1729:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
                   1730:     my @currxlists = ();
                   1731:     my @xlists = ();
                   1732:     my @allxlists = ();
                   1733:     my @badxlists = ();
                   1734:     my @badowner = ();
                   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) {
                   1752: 	for (my $i=0; $i<$numcross; $i++) {
                   1753: 	    my $xl = "newcross_".$i;
                   1754: 	    my $gp = "newgroupid_".$i;
1.23      albertel 1755: 	    if ( exists($env{"form.$xl"}) ) {
1.15      albertel 1756: 		my $coursecheck = '';
1.23      albertel 1757: 		$coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});
1.15      albertel 1758: 		if ($coursecheck eq 'ok') {
                   1759: 		    my $addcheck = '';
1.23      albertel 1760: 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner);
1.15      albertel 1761: 		    if ($addcheck eq 'ok') {
1.23      albertel 1762: 			push @xlists,$env{"form.$xl"}.":".$env{"form.$gp"};
1.15      albertel 1763: 		    } else {
1.23      albertel 1764: 			push @badowner,$env{"form.$xl"}.":".$env{"form.$gp"};
1.15      albertel 1765: 		    }
                   1766: 		} else {
1.23      albertel 1767: 		    push @badxlists, $env{"form.$xl"}.":".$env{"form.$gp"}.":".$coursecheck;
1.15      albertel 1768: 		}
                   1769: 	    }
                   1770: 	}
                   1771: 	push @allxlists, @xlists;
                   1772:     }
                   1773:     
                   1774:     if (@xlists > 0 ) {
                   1775: 	unless ($xliststr eq '') { $xliststr .= ","; }
1.28      albertel 1776: 	$xliststr .= join(",",@xlists);
                   1777: 
1.15      albertel 1778: 	my %cenv = ('internal.crosslistings' => $xliststr);
                   1779: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1780: 	if ($reply !~ /^ok$/) {
                   1781: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1782: 	} else {
                   1783: 	    $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";
                   1784: 	    foreach (@allxlists) {
                   1785: 		my ($xlist,$gp) = split/:/,$_;
                   1786: 		$response .= "<li>$xlist - ID: $gp</li>\n";
                   1787: 	    }
                   1788: 	    $response .= "</ul><br/><br/>\n";
                   1789: 	}
                   1790:     } else {
                   1791: 	if ($xliststr =~ m/:/) {
1.28      albertel 1792: 	    my @oldxlists = (split/,/,$xliststr);
1.15      albertel 1793: 	    $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1794: 	    foreach (@oldxlists) {
                   1795: 		my ($xlist,$gp) = split/:/,$_;
                   1796: 		$response .= "<li>$xlist - ID: $gp</li>\n";
                   1797: 	    }
                   1798: 	    $response .= "</ul><br/><br/>\n";
                   1799: 	}
                   1800:     }
                   1801:     if (@badxlists > 0) {
                   1802: 	$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";
                   1803: 	foreach (@badxlists) {
                   1804: 	    my ($xlist,$gp,$prob) = split/:/,$_;
                   1805: 	    $response .= "<li>$xlist - ID: $gp - Error: $prob</li>\n";
                   1806: 	}
                   1807: 	$response .= "</ul><br/><br/>\n";
                   1808:     }
                   1809:     
                   1810:     if (@badowner > 0) {
                   1811: 	$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";
                   1812: 	foreach (@badowner) {
                   1813: 	    my ($xlist,$gp) = split/:/,$_;
                   1814: 	    $response .= "<li>$xlist - ID: $gp</li>\n";
                   1815: 	}
                   1816: 	$response .= "</ul><br/><br/>\n";
                   1817:     }
1.5       raeburn  1818: 
1.15      albertel 1819:     if (@allxlists > 0) {
                   1820: 	$warning = &warning_message($dom,$crs,$action);
                   1821: 	$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/>";
                   1822: 	unless ($warning eq '') {
                   1823: 	    $response .= $warn_prefix.$warning;
                   1824: 	}
                   1825:     }
1.1       raeburn  1826: 
1.15      albertel 1827:     &print_reply($r,$response,$$tasktitleref{$action});
                   1828:     return;
1.1       raeburn  1829: }
                   1830: 
                   1831: sub print_sections_menu () {
1.15      albertel 1832:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1833:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   1834:     my @currsections = ();
                   1835:     my @sections = ();
                   1836:     my @badowner = ();
                   1837:     my @badsections = ();
                   1838:     my $seccount = 0;
                   1839:     my $removecount = 0;
                   1840:     my $addcount = 0;
                   1841:     my $secstr = '';
                   1842:     my $response = '';
                   1843:     my $warning = "";
                   1844:     my $warn_prefix = "";
                   1845:     my $coursecode = $settings{'internal.coursecode'};
                   1846:     my $owner = $settings{'internal.courseowner'};
1.28      albertel 1847:     if ($settings{'internal.sectionnums'} ne '') {
                   1848: 	@currsections = split(/,/,$settings{'internal.sectionnums'});
1.15      albertel 1849:     }
                   1850:     
1.23      albertel 1851:     if ( exists($env{'form.secshow'}) ) {
                   1852: 	for (my $i=0; $i<$env{'form.secshow'}; $i++) {
1.15      albertel 1853: 	    my $gp = "loncapasec_".$i;
                   1854: 	    my $secnum = "secnum_".$i;
                   1855: 	    my $sec = "sec_".$i;
1.23      albertel 1856: 	    if ( exists( $env{"form.$sec"} ) ) {
1.15      albertel 1857: 		my $secentry;
1.23      albertel 1858: 		if ( exists( $env{"form.$secnum"} ) ) { 
                   1859: 		    $secentry = $env{"form.$secnum"}.':';
1.15      albertel 1860: 		}
1.23      albertel 1861: 		if ( exists( $env{"form.$gp"} ) ) {
                   1862: 		    $secentry .= $env{"form.$gp"};
1.15      albertel 1863: 		}
1.23      albertel 1864: 		if ( grep/^$env{"form.$secnum"}:/,@currsections) {
1.15      albertel 1865: 		    push @sections, $secentry;
                   1866: 		    $seccount ++;
                   1867: 		} else {
1.23      albertel 1868: 		    my $newsec = $coursecode.$env{"form.$secnum"};
1.15      albertel 1869: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   1870: 		    if ($coursecheck eq 'ok') {
                   1871: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   1872: 			if ($addcheck eq 'ok') {
1.23      albertel 1873: 			    push @sections,$env{"form.$secnum"}.":".$env{"form.$gp"};
1.15      albertel 1874: 			    $seccount ++;
                   1875: 			    $addcount ++;
                   1876: 			} else {
1.23      albertel 1877: 			    push @badowner,$env{"form.$secnum"}.":".$env{"form.$gp"};
1.15      albertel 1878: 			}
                   1879: 		    } else {
1.23      albertel 1880: 			push @badsections, $env{"form.$secnum"}.":".$env{"form.$gp"}.":".$coursecheck;
1.15      albertel 1881: 		    }
                   1882: 		}
                   1883: 	    }
                   1884: 	}
                   1885: 	if (@currsections > 0) {
                   1886: 	    for (my $i=0; $i<@currsections; $i++) {
                   1887: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   1888: 		    my $oldsec  = $1;
                   1889: 		    unless (grep/^$oldsec/,@sections) {
                   1890: 			$removecount ++;
                   1891: 		    }
                   1892: 		}
                   1893: 	    }
                   1894: 	}
                   1895:     } elsif (@currsections > 0) {
                   1896: 	for (my $i=0; $i<@currsections; $i++) {
                   1897: 	    my $sec = "sec_".$i;
                   1898: 	    my $gp = "secgp_".$i;
1.23      albertel 1899: 	    if ( exists($env{"form.$sec"}) ) {
1.15      albertel 1900: 		my $secentry = '';
                   1901: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   1902: 		    $secentry = $1;
                   1903: 		}
1.23      albertel 1904: 		if ( exists($env{"form.$gp"}) ) {
                   1905: 		    $secentry .= $env{"form.$gp"};
1.15      albertel 1906: 		}
                   1907: 		push @sections,$secentry;
                   1908: 		$seccount ++;
                   1909: 	    } else {
                   1910: 		$removecount ++;
                   1911: 	    }
                   1912: 	}
                   1913:     }
                   1914:     
1.28      albertel 1915:     $secstr = join(",",@sections);
                   1916: 
1.15      albertel 1917:     my %cenv = ('internal.sectionnums' => $secstr);
                   1918:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1919:     if ($reply !~ /^ok$/) {
                   1920: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1921:     } else {
                   1922: 	if ($removecount > 0) {
                   1923: 	    $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/>";
                   1924: 	}
                   1925: 	if ($addcount > 0) {
                   1926: 	    $response .= "A total of $addcount sections have been added to the list of
1.6       raeburn  1927: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.15      albertel 1928: 	}
                   1929: 	if ($seccount > 0) { 
                   1930: 	    $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";
                   1931: 	    foreach (@sections) {
                   1932: 		my ($sec,$gp) = split/:/,$_;
                   1933: 		$response .= "<li>$sec  - ID: $gp</li>\n";
                   1934: 	    }
                   1935: 	    $response .= "</ul><br/>\n";
                   1936: 	}
                   1937:     }
                   1938:     
                   1939:     if (@badsections > 0) {
                   1940: 	$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";
                   1941: 	foreach (@badsections) {
                   1942: 	    my ($secnum,$gp,$prob) = split/:/,$_;
                   1943: 	    $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
                   1944: 	}
                   1945: 	$response .= "</ul><br/><br/>\n";
                   1946:     }
                   1947:     
                   1948:     if (@badowner > 0) {
                   1949: 	$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";
                   1950: 	foreach (@badowner) {
                   1951: 	    my ($secnum,$gp) = split/:/,$_;
                   1952: 	    $response .= "<li>$secnum - ID: $gp</li>\n";
                   1953: 	}
                   1954: 	$response .= "</ul><br/><br/>\n";
                   1955:     }
                   1956:     
                   1957:     if ($seccount > 0) {
                   1958: 	$warning = &warning_message($dom,$crs,$action);
                   1959: 	$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/>";
                   1960: 	unless ($warning eq '') {
                   1961: 	    $response .= $warn_prefix.$warning;
                   1962: 	}
                   1963:     }
                   1964:     
1.23      albertel 1965:     if ( exists($env{'form.numsec'}) ) {
                   1966: 	my $numsec = $env{'form.numsec'};
1.15      albertel 1967: 	if ($numsec > 0) {
                   1968: 	    my @bgcolors=("#eeeeee","#cccccc");
                   1969: 	    $response .= qq(
                   1970: 			    You indicated that you wish to incorporate student enrollment in your LON-CAPA course from an additional $numsec section(s).  For each new section enter the insititutional section code (e.g., 004), and the LON-CAPA section/group ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in this particular section. The LON-CAPA section/group ID can be left blank, if you do not wish to designate a section/group ID for this course section.  The institutional section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course section numbers to your institution\'s student information system.<br/><br/> 
1.1       raeburn  1971:            <form name="enter" method="post">
                   1972:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   1973:              <tr>
                   1974:               <td>
                   1975:                <table border="0" cellspacing="3" cellpadding="3">
                   1976:                 <tr bgcolor="#CCCCFF" align="left">
                   1977:                  <td><b>Section number</b></td>
                   1978:                  <td><b>LON-CAPA section/groupID</b></td>
                   1979:                 </tr>
1.15      albertel 1980: 			    );
                   1981: 	    for (my $i=0; $i<$numsec; $i++) {
                   1982: 		my $colflag = $i%2;
                   1983: 		$response .= qq(
1.1       raeburn  1984:                 <tr bgcolor="$bgcolors[$colflag]" align="left">
                   1985:                  <td><input type="text" size="15" name="newsec_$i" /></td>
                   1986:                  <td><input type="text" size="10" name="newsecgp_$i" /></td>
                   1987:                 </tr>
1.15      albertel 1988: 				);
                   1989: 	    }
                   1990: 	    $response .= qq(  </table>
1.1       raeburn  1991:               </td>
                   1992:              </tr>
                   1993:              <tr>
                   1994:               <td align="right">
1.39      albertel 1995:                <input type="button" name="newsections" value="Go" onclick="process('newsections')" />
1.1       raeburn  1996:               </td>
                   1997:              </tr>
                   1998:             </table>
1.39      albertel 1999:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\" />
                   2000:             <input type=\"hidden\" name=\"action\" value=\"newsections\" />
                   2001:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  2002:             </form>
1.15      albertel 2003: 			      );
                   2004: 	}
                   2005:     }
                   2006:     &print_reply($r,$response,$$tasktitleref{$action});
                   2007:     return;
1.1       raeburn  2008: }
                   2009: 
                   2010: sub print_sections_response () {
1.15      albertel 2011:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2012:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   2013:     my @currsections = ();
                   2014:     my @sections = ();
                   2015:     my @allsections = ();
                   2016:     my @badowner = ();
                   2017:     my @badsections = ();
                   2018:     my $numsec = 0;
                   2019:     my $secstr =  $settings{'internal.sectionnums'};
                   2020:     my $coursecode = $settings{'internal.coursecode'};
                   2021:     my $owner = $settings{'internal.courseowner'};
                   2022:     my $response = '';
                   2023:     my $putreply = '';
                   2024:     my $warning = '';
                   2025:     my $warn_prefix = '';
1.28      albertel 2026:     if ($secstr ne '') {
                   2027: 	@allsections = split(/,/,$secstr);
1.15      albertel 2028:     }
                   2029:     
1.23      albertel 2030:     if ( exists($env{'form.numsec'}) ) {
                   2031: 	$numsec = $env{'form.numsec'};
1.15      albertel 2032:     }
                   2033:     
                   2034:     if ($numsec > 0) {
                   2035: 	for (my $i=0; $i<$numsec; $i++) {
                   2036: 	    my $sec = "newsec_".$i;
                   2037: 	    my $gp = "newsecgp_".$i;
1.23      albertel 2038: 	    if ( exists($env{"form.$sec"}) ) {
                   2039: 		unless ( (grep/^$env{"form.$sec"}:/,@allsections) || (grep/^$env{"form.$sec"}:/,@sections) ) {
                   2040: 		    my $newsec = $coursecode.$env{"form.$sec"};
1.15      albertel 2041: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2042: 		    if ($coursecheck eq 'ok') {
                   2043: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   2044: 			if ($addcheck eq 'ok') {
1.23      albertel 2045: 			    push @sections,$env{"form.$sec"}.":".$env{"form.$gp"};
1.15      albertel 2046: 			} else {
1.23      albertel 2047: 			    push @badowner,$env{"form.$sec"}.":".$env{"form.$gp"};
1.15      albertel 2048: 			}
                   2049: 		    } else {
1.23      albertel 2050: 			push @badsections, $env{"form.$sec"}.":".$env{"form.$gp"}.":".$coursecheck;
1.15      albertel 2051: 		    }
                   2052: 		}
                   2053: 	    }
                   2054: 	}
                   2055: 	push @allsections, @sections;
                   2056:     }
                   2057:     
                   2058:     if (@sections > 0 ) {
                   2059: 	unless ($secstr eq '') { $secstr .= ","; } 
1.28      albertel 2060: 	$secstr .= join(",",@sections);
1.15      albertel 2061: 	my %cenv = ('internal.sectionnums' => $secstr);
                   2062: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2063: 	if ($putreply !~ /^ok$/) {
                   2064: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   2065: 	}
                   2066:     }
                   2067: 
                   2068:     if ($putreply =~ /^ok/) {
                   2069: 	$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";
                   2070: 	foreach (@allsections) {
                   2071: 	    my ($sec,$gp) = split/:/,$_;
                   2072: 	    $response .= "<li>$sec - ID: $gp</li>\n";
                   2073: 	}
                   2074: 	$response .= "</ul><br/><br/>\n";
                   2075:     }
                   2076: 
                   2077:     if (@badsections > 0) {
                   2078: 	$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";
                   2079: 	foreach (@badsections) {
                   2080: 	    my ($secnum,$gp,$prob) = split/:/,$_;
                   2081: 	    $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
                   2082: 	}
                   2083: 	$response .= "</ul><br/><br/>\n";
                   2084:     }
                   2085: 
                   2086:     if (@badowner > 0) {
                   2087: 	$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";
                   2088: 	foreach (@badowner) {
                   2089: 	    my ($secnum,$gp) = split/:/,$_;
                   2090: 	    $response .= "<li>$secnum - ID: $gp</li>\n";
                   2091: 	}
                   2092: 	$response .= "</ul><br/><br/>\n";
                   2093:     }
                   2094: 
                   2095:     if (@allsections > 0) {
                   2096: 	$warning = &warning_message($dom,$crs,$action);
                   2097: 	$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/>";
                   2098: 	unless ($warning eq '') {
                   2099: 	    $response .= $warn_prefix.$warning;
                   2100: 	}
                   2101:     }
1.1       raeburn  2102: 
1.15      albertel 2103:     &print_reply($r,$response,$$tasktitleref{$action});
                   2104:     return;
1.1       raeburn  2105: }
                   2106: 
1.34      raeburn  2107: sub photo_permission {
1.15      albertel 2108:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.35      albertel 2109:     my %settings = &Apache::lonnet::get('environment',
                   2110: 					['internal.courseowner',
                   2111: 					 'internal.photopermission',
1.37      raeburn  2112: 					 'internal.showphoto'],
1.35      albertel 2113: 					$dom,$crs);
1.34      raeburn  2114:     my ($showphotos,$response);
                   2115:     if (exists($env{'form.cancel_agreement'})) {
                   2116:         if ($env{'user.name'} eq $settings{'internal.courseowner'}) {
                   2117:             my %cenv = (
                   2118:                 'internal.photopermission' => 'no',
                   2119:             );
                   2120:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2121:             if ($reply !~ /^ok$/) {
                   2122:                 $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";
                   2123:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2124:             } else {
                   2125:                 &print_photos_response($r,$realm,$dom,$crs,$action,
                   2126:                        $tasktitleref,$showphotos,'no',\%cenv);
                   2127:             }
                   2128:             return;            
                   2129:         }
                   2130:     } 
                   2131:     if (exists($env{'form.showphotos'})) {
                   2132:         $showphotos=$env{'form.showphotos'};
                   2133:     }
                   2134:     if ($showphotos) {
                   2135:         if ($env{'form.photopermission'}) {
                   2136:             my %cenv = (
                   2137:                 'internal.photopermission' => $env{'form.photopermission'},
                   2138:             );
                   2139:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2140:             if ($reply !~ /^ok$/) {
                   2141:                 $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";
                   2142:             } else {
                   2143:                 &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2144: 				       $tasktitleref,$showphotos,
                   2145: 				       $env{'form.photopermission'},\%cenv);
1.34      raeburn  2146:             }
                   2147:         } else {
                   2148:             my ($result,$perm_reqd,$conditions) = 
1.35      albertel 2149: 		&Apache::lonnet::auto_photo_permission($crs,$dom);
1.34      raeburn  2150:             my $permcheck;
                   2151:             if ($result eq 'ok') { 
                   2152:                 if ($perm_reqd eq 'yes') {
                   2153:                     if ($settings{'internal.photopermission'} eq 'yes') {
                   2154:                         &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2155: 					       $tasktitleref,$showphotos);
1.34      raeburn  2156:                     } else {
                   2157:                         return(&print_photo_agreement($r,$realm,$dom,$crs,
1.35      albertel 2158: 						      $action,$tasktitleref,
                   2159: 						      $conditions,
                   2160: 						      $settings{'internal.courseowner'}));
1.34      raeburn  2161:                     }
                   2162:                 } elsif ($perm_reqd eq 'no') {
                   2163:                     &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2164: 					   $tasktitleref,$showphotos);
1.34      raeburn  2165:                 } else {
                   2166:                     $permcheck = 'fail';
                   2167:                 }
                   2168:             } else {
                   2169:                 $permcheck = 'fail';
                   2170:             }
                   2171:             if ($permcheck eq 'fail') {
                   2172:                 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/>';
                   2173:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2174:             }
                   2175:         }
                   2176:     } else {
                   2177:         &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref);
                   2178:     }
                   2179:     return;
                   2180: }
                   2181: 
                   2182: sub print_photo_agreement {
                   2183:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_;
                   2184:     my $response;
                   2185:     my $institution = $Apache::lonnet::domaindescription{$dom};
                   2186:     if ($env{'user.name'} eq $courseowner) {
                   2187:         $response = '
                   2188: <script type="text/javascript">
                   2189: function agreement_result(caller) {
                   2190:     document.permission.photopermission.value = caller;
                   2191:     if (caller == 0) {
                   2192:         document.location.href="/adm/populate";
                   2193:     } else {
                   2194:         document.permission.submit();
                   2195:     }
                   2196:     return;
                   2197: }
                   2198: </script>
                   2199:   <form name="permission" method="post">
                   2200:    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   2201:     <tr>
                   2202:      <td align="left"><b>Use of student photos</b><br/>'."\n".
                   2203:       &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).'
                   2204:      </td>
                   2205:     </tr>
                   2206:    </table>
                   2207:    <table border="0" cellpadding="3" cellspacing="3">
                   2208:     <tr>
                   2209:      <td colspan="2">
                   2210:       <textarea rows="20" cols="80">'.$conditions.'</textarea>
                   2211:      </td>
                   2212:      <tr>
                   2213:       <td align="left">  
                   2214:        <input type="button" name="disagree" value="I do not agree" onclick="javascript:agreement_result('."'no'".');" />
                   2215:       </td>
                   2216:       <td align="right">
                   2217:        <input type="button" name="agree" value="I agree" onclick="javscript:agreement_result('."'yes'".');" />
                   2218:       </td>
                   2219:     </tr>
                   2220:    </table>
                   2221:    <input type ="hidden" name="action" value="'.$action.'" />
                   2222:    <input type ="hidden" name="state" value="process" />
                   2223:    <input type ="hidden" name="showphotos" value="1" />
                   2224:    <input type= "hidden" name="photopermission" value="" />
                   2225:   </form>
                   2226: ';
                   2227:     } else {
                   2228:         my ($ownername,$owneremail) = &get_oenerinfo($dom,$courseowner);
                   2229:         $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);
                   2230:     }
                   2231:     &print_reply($r,$response,$$tasktitleref{$action});
                   2232: }
                   2233: 
                   2234: sub print_photos_response {
                   2235:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission,
1.35      albertel 2236: 	$permissionenv)=@_;
1.34      raeburn  2237:     my %newenv;
                   2238:     if (defined($permissionenv)) {
                   2239:         foreach my $key (keys(%{$permissionenv})) {
                   2240:             if (exists($env{'request.course.id'})) {
                   2241:                 $newenv{$env{'request.course.id'}.'.'.$key} =
1.35      albertel 2242: 		    $$permissionenv{$key};
1.34      raeburn  2243:             }
                   2244:         }
                   2245:     }
1.37      raeburn  2246:     my %settings = &Apache::lonnet::get('environment',['internal.showphoto'],
1.35      albertel 2247: 					$dom,$crs);
1.37      raeburn  2248:     my $currphotos = $settings{'internal.showphoto'};
1.34      raeburn  2249:     my $response = "";
                   2250:     if (defined($photopermission)) {
                   2251:         if ($photopermission eq 'yes') {
                   2252:             $response = &mt('Acceptance of photo use policy recorded.').'<br />'."\n";
                   2253:         } else {
                   2254:             $response = &mt('Non-acceptance of photo use policy recorded.').'<br />'."\n";
                   2255:             $showphotos = 0;
                   2256:         }
1.15      albertel 2257:     }
1.37      raeburn  2258:     my %cenv = ('internal.showphoto' => $showphotos);
1.15      albertel 2259:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2260:     if ($reply !~ /^ok$/) {
1.34      raeburn  2261: 	$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 2262:     } else {
                   2263: 	if ($showphotos) {
                   2264: 	    if ($currphotos) {
1.34      raeburn  2265: 		$response .= "Retrieval of student photos is still <b>enabled</b>.<br/>";
1.15      albertel 2266: 	    } else {
1.34      raeburn  2267: 		$response .= "Retrieval of student photos in now <b>enabled</b>.<br/>";
1.35      albertel 2268:                 my ($update,$commentary) = 
                   2269: 		    &Apache::lonnet::auto_photochoice($crs,$dom);
1.34      raeburn  2270:                 if ($update) {
                   2271:                     $response .= '<br />'.$commentary.'<br /><br />
                   2272: <form name="photoupdate" method="post">
                   2273: <input type ="button" name="retrieve" value="'.&mt('Update photo repository').'" 
                   2274: onclick="javascript:document.photoupdate.submit()" /> 
                   2275: <input type ="hidden" name="action" value="'.$action.'" />
                   2276: <input type ="hidden" name="state" value="photoupdate" />
                   2277: </form>';
                   2278:                 }
1.15      albertel 2279: 	    }
                   2280: 	} else {
                   2281: 	    if ($currphotos) {
1.34      raeburn  2282: 		$response .= "Retrieval of student photos is now <b>disabled</b>.<br/>";
1.15      albertel 2283: 	    } else {
1.34      raeburn  2284: 		$response .= "Retrieval of student photos is still <b>disabled</b>.<br/>";
1.15      albertel 2285: 	    }
                   2286: 	}
1.34      raeburn  2287:         foreach my $key (keys(%cenv)) {
                   2288:             if (exists($env{'request.course.id'})) {
                   2289:                 $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = 
1.35      albertel 2290: 		    $cenv{$key};
1.34      raeburn  2291:             }
                   2292:         }
                   2293:     }
                   2294:     if (keys(%newenv) > 0) {
                   2295:         &Apache::lonnet::appenv(%newenv);
                   2296:     }
                   2297:     &print_reply($r,$response,$$tasktitleref{$action});
                   2298:     return;
                   2299: }
                   2300: 
                   2301: sub print_photoupdate_response {
                   2302:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2303:     my $response;
                   2304:     my %changes;
                   2305:     my %lt = &LONCAPA::Enrollment::photo_response_types();
1.35      albertel 2306:     my %settings = &Apache::lonnet::get('environment',
                   2307: 					['internal.coursecode',
                   2308: 					 'internal.sectionnums',
                   2309: 					 'internal.crosslistings'],
                   2310: 					$dom,$crs);
1.34      raeburn  2311:     my @allcourses = ();
                   2312:     my %LC_code;
                   2313:     my %affiliates;
                   2314:     my $outcome;
                   2315:     &get_institutional_codes(\%settings,,\@allcourses,\%LC_code);
                   2316:     if (@allcourses > 0) {
                   2317:         @{$affiliates{$crs}} = @allcourses;
                   2318:         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
                   2319:         unless ($outcome eq 'ok') {
                   2320:             &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response".
1.35      albertel 2321: 				     "failed to update student photos".
                   2322: 				     " for ".$crs."\@".$dom." by ".
                   2323: 				     $env{'user.name'}." \@ ".$env{'user.domain'}.
                   2324: 				     ": ".$outcome);
1.34      raeburn  2325:         }
                   2326:         if ($outcome eq 'ok') {
                   2327:             if (keys(%changes) > 0) {
                   2328:                 $response = &mt('Update of photos for registered students resulted in the following ').': <br /><script type="text/javascript">
                   2329: function photowindow(photolink) {
                   2330:     var title = "Photo_Viewer";
                   2331:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2332:     options += ",width=240,height=240";
                   2333:     stdeditbrowser = open(photolink,title,options,"1");
                   2334:     stdeditbrowser.focus();
                   2335: }
                   2336: </script>
                   2337: ';
                   2338:                 foreach my $type (sort(keys(%changes))) {
                   2339:                     my @usernames = sort(split(/\&/,$changes{$type})); 
                   2340:                     my $count = @usernames; 
                   2341:                     $response .= '<b>'.&mt('For [_1] students, photos ',
1.35      albertel 2342: 					   $count).$lt{$type}.'</b><ul>';
1.34      raeburn  2343:                     foreach my $username (@usernames) {
                   2344:                         $response .= '<li>'.$username;
                   2345:                         if (($type eq 'new') || ($type eq 'same') || ($type eq 'update')) {
                   2346:                             $response .= '&nbsp;<a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($dom,$username,'jpg')."'".')">View</a></li>';  
                   2347:                         }
                   2348:                     }
                   2349:                     $response .= '</ul><br />';
                   2350:                 }
                   2351:             } else {
                   2352:                 $response = &mt('No updates of photos of registered students occurred').
                   2353:                          '<br />';
                   2354:             }    
                   2355:         } else {
                   2356:             $response = "There was a problem updating student photos for registered students in this course. <br/>";
                   2357:         }
                   2358:     } else {
                   2359:         $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 2360:     }
                   2361:     &print_reply($r,$response,$$tasktitleref{$action});
                   2362:     return;
1.1       raeburn  2363: }
                   2364: 
1.34      raeburn  2365: sub get_ownerinfo {
                   2366:     my ($dom,$owner) = @_; 
                   2367:     my ($ownername,$owneremail);
                   2368:     if ($owner) {
                   2369:         $ownername=&Apache::loncommon::plainname($owner,$dom,'firstname');
1.36      raeburn  2370:         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
1.35      albertel 2371: 					     $dom,$owner);
1.34      raeburn  2372:         $owneremail = $ownerinfo{'permanentemail'};
                   2373:     }
                   2374:     return ($ownername,$owneremail);
                   2375: }
                   2376: 
1.1       raeburn  2377: sub print_update_result () {
1.15      albertel 2378:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2379:     my $response = '';
                   2380:     my $updateadds = 0;
                   2381:     my $updatedrops = 0;
                   2382:     my $changecount = 0;
                   2383:     my %affiliates = ();
                   2384:     my %reply = ();
                   2385:     my @allcourses = ();
                   2386:     my %LC_code = ();
                   2387:     my $logmsg = '';
                   2388:     my $newusermsg = '';
1.34      raeburn  2389:     my %phototypes = ();
1.37      raeburn  2390:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.showphoto'],$dom,$crs);
1.15      albertel 2391:     my $coursecode = $settings{'internal.coursecode'};
                   2392:     my $authtype = $settings{'internal.authtype'};
                   2393:     my $autharg = $settings{'internal.autharg'};
1.37      raeburn  2394:     my $showphotos = $settings{'internal.showphoto'};
1.15      albertel 2395:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.23      albertel 2396:     if ( exists($env{'form.updateadds'}) ) {
                   2397:         $updateadds = $env{'form.updateadds'};
1.15      albertel 2398:     }
1.23      albertel 2399:     if ( exists($env{'form.updatedrops'}) ) {
                   2400:         $updatedrops = $env{'form.updatedrops'};
1.15      albertel 2401:     }
1.19      raeburn  2402:     if (($startaccess eq '') || ($endaccess eq '')) {
                   2403:         $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 />"; 
                   2404:     } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
                   2405:         $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";
                   2406:     } elsif (!$updateadds && !$updatedrops) {
1.15      albertel 2407: 	$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.";
                   2408:     } elsif ($coursecode eq '') {
                   2409: 	$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";
                   2410:     } else {
1.34      raeburn  2411:         &get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.15      albertel 2412: 	if (@allcourses > 0) {
                   2413: 	    @{$affiliates{$crs}} = @allcourses;
                   2414: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
1.19      raeburn  2415:             unless ($outcome eq 'ok') {
                   2416:                 &Apache::lonnet::logthis("lonpopulate:update roster".
                   2417:                                          "failed to retrieve classlist".
                   2418:                                  " data for ".$crs."\@".$dom." by ".
1.23      albertel 2419:                                  $env{'user.name'}." \@ ".$env{'user.domain'}.
1.19      raeburn  2420:                                  ": ".$outcome);
                   2421:             }
1.15      albertel 2422: 	    if ($reply{$crs} > 0) {
1.34      raeburn  2423: 		($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes);
1.15      albertel 2424: 	    } else {
                   2425: 		$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.";
                   2426: 	    }  
                   2427: 	} else {
                   2428: 	    $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)";
                   2429: 	}
                   2430:     }
                   2431:     unless ($logmsg eq '') {
                   2432: 	my $loglength = length($logmsg);
                   2433: 	$logmsg = substr($logmsg,0,$loglength-4);
                   2434: 	$logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   2435:     }
                   2436:     unless ($newusermsg eq '') {
                   2437: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
1.19      raeburn  2438: 	$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 2439:     }
                   2440:     $response .= $logmsg.$newusermsg;
                   2441:     &print_reply($r,$response,$$tasktitleref{$action});
                   2442:     return;
1.10      raeburn  2443: }
                   2444: 
1.34      raeburn  2445: sub get_institutional_codes {
                   2446:     my ($settings,$allcourses,$LC_code) = @_;
                   2447: # Get complete list of course sections to update
                   2448:     my @currsections = ();
                   2449:     my @currxlists = ();
                   2450:     my $coursecode = $$settings{'internal.coursecode'};
1.39      albertel 2451:     
1.34      raeburn  2452:     if ($$settings{'internal.sectionnums'} ne '') {
                   2453:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   2454:     }
1.39      albertel 2455:     
1.34      raeburn  2456:     if ($$settings{'internal.crosslistings'} ne '') {
                   2457:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   2458:     }
1.39      albertel 2459:     
1.34      raeburn  2460:     if (@currxlists > 0) {
                   2461:         foreach (@currxlists) {
                   2462:             if (m/^([^:]+):(\w*)$/) {
                   2463:                 unless (grep/^$1$/,@{$allcourses}) {
                   2464:                     push @{$allcourses},$1;
                   2465:                     $$LC_code{$1} = $2;
                   2466:                 }
                   2467:             }
                   2468:         }
                   2469:     }
                   2470:                                                                                        
                   2471:     if (@currsections > 0) {
                   2472:         foreach (@currsections) {
                   2473:             if (m/^(\w+):(\w*)$/) {
                   2474:                 my $sec = $coursecode.$1;
                   2475:                 my $gp = $2;
                   2476:                 unless (grep/^$sec$/,@{$allcourses}) {
                   2477:                     push @{$allcourses},$sec;
                   2478:                     $$LC_code{$sec} = $gp;
                   2479:                 }
                   2480:             }
                   2481:         }
                   2482:     }
                   2483:     return; 
                   2484: }
                   2485: 
                   2486: 
1.14      raeburn  2487: sub print_viewclass_response {
                   2488:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2489:     my $response;
                   2490:     my $chgtotal = 0;
                   2491:     my $chgok = 0;
                   2492:     my $chgfail = 0;
                   2493:     my $othdom = 0;
1.16      raeburn  2494:     my $locktotal = 0;
                   2495:     my $lockok = 0;
                   2496:     my $lockfail = 0;
1.14      raeburn  2497:     my $cid = $dom."_".$crs;
                   2498:     my %chg = ();
                   2499:     my %nochg = ();
                   2500:     my %otherdom = ();
1.16      raeburn  2501:     my %lockchg = ();
                   2502:     my %nolockchg = ();
1.27      albertel 2503:     my $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2504:     my $endidx = &Apache::loncoursedata::CL_END;
                   2505:     my $startidx = &Apache::loncoursedata::CL_START;
                   2506:     my $ididx=&Apache::loncoursedata::CL_ID;
                   2507:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   2508:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
1.16      raeburn  2509:     my $lockedidx=&Apache::loncoursedata::CL_LOCKEDTYPE;
                   2510:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chgauto','chgmanual','lockchg','unlockchg']);
1.24      albertel 2511:     my @typechglist = (&Apache::loncommon::get_env_multiple('form.chgauto'),
                   2512: 		       &Apache::loncommon::get_env_multiple('form.chgmanual'));
                   2513:     my @lockchglist = (&Apache::loncommon::get_env_multiple('form.lockchg'),
                   2514: 		       &Apache::loncommon::get_env_multiple('form.unlockchg'));
                   2515: 
1.16      raeburn  2516:     foreach my $student (sort @typechglist) {
                   2517:         my ($uname,$udom) = split/:/,$student;
                   2518:         my $sdata    = $classlist->{$student};
                   2519:         my $section  = $sdata->[$secidx];
                   2520:         my $uid       = $sdata->[$ididx];
                   2521:         my $start    = $sdata->[$startidx];
                   2522:         my $end      = $sdata->[$endidx];
                   2523:         my $type     = $sdata->[$typeidx];
                   2524:         my $lock   = $sdata->[$lockedidx];
                   2525:         my $newlock = $lock;
                   2526:         $chgtotal ++;
                   2527:         my $newtype = 'auto';
                   2528:         my $change = 'auto';
                   2529:         my $oldtype = 'manual';
                   2530:         if ($type eq 'auto') { 
                   2531:             $oldtype = 'auto';
                   2532:             $newtype = '';
                   2533:             $change = 'manual';
                   2534:         }
                   2535:         if ($udom eq $dom) {
                   2536:             if ($newtype eq 'auto') {
                   2537:                 $newlock = '';
                   2538:             } elsif ($newtype eq '') {
                   2539:                 $newlock = '1';
1.14      raeburn  2540:             }
1.16      raeburn  2541:             my $modreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$newtype,$newlock,$cid);
                   2542:             if ($modreply eq 'ok') {
                   2543:                 $chgok ++;
                   2544:                 $chg{$student} = "Changed to $change";
                   2545:             } else {
                   2546:                 $chgfail ++;
                   2547:                 $nochg{$student} = "Still set to $oldtype";
                   2548:             } 
                   2549:         } else {
                   2550:             $othdom ++;
                   2551:             $otherdom{$student} = "Still set to $oldtype"; 
                   2552:         }
                   2553:     }
                   2554:     foreach my $student (@lockchglist) {
                   2555:         my ($uname,$udom) = split/:/,$student;
                   2556:         my $sdata    = $classlist->{$student};
                   2557:         my $section  = $sdata->[$secidx];
                   2558:         my $uid       = $sdata->[$ididx];
                   2559:         my $start    = $sdata->[$startidx];
                   2560:         my $end      = $sdata->[$endidx];
                   2561:         my $type     = $sdata->[$typeidx];
                   2562:         my $lock   = $sdata->[$lockedidx];
                   2563:         my $newlock = 1;
                   2564:         my $oldlockname = &mt('unlocked');
                   2565:         my $newlockname = &mt('locked');
                   2566:         $locktotal++;
                   2567:         unless ($type eq 'auto') {
                   2568:             if ($lock) {
                   2569:                 $newlock = '';
                   2570:                 $newlockname = &mt('unlocked');
                   2571:                 $oldlockname = &mt('locked'); 
                   2572:             }
                   2573:             my $lockreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$type,$newlock,$cid);
                   2574:             if ($lockreply eq 'ok') {
                   2575:                 $lockok ++;
                   2576:                 $lockchg{$student} = 'Changed to '.$newlockname;
1.14      raeburn  2577:             } else {
1.16      raeburn  2578:                 $lockfail ++;
                   2579:                 $nolockchg{$student} = 'Still set to '.$oldlockname;
1.14      raeburn  2580:             }
                   2581:         }
                   2582:     }
                   2583:     if ($chgtotal > 0) {
                   2584:         $response = "You requested a change in enrollment type for $chgtotal students.<br /><br />\n";
1.27      albertel 2585:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2586:         if ($chgok > 0) {
                   2587:             $response .= "The following $chgok changes were successful:<br />";
                   2588:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2589:         }
                   2590:         if ($chgfail > 0) {
                   2591:             $response .= "The following $chgfail students were not modified successfully:&nbsp;<br />";
                   2592:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2593:         }
                   2594:         if ($othdom > 0) {
                   2595:             $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 />"; 
                   2596:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2597:         }
1.16      raeburn  2598:         $response .= "<br /><br />";
                   2599:     }
                   2600:     if ($locktotal > 0) {
                   2601:         $response .= "You requested locking/unlocking for $locktotal manually enrolled students.<br /><br />\n";
1.27      albertel 2602:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.16      raeburn  2603:         if ($lockok > 0) {
                   2604:             $response .= "The following $lockok changes were successful:<br />";
                   2605:             $response .= &enrolltype_result(\%lockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2606:         }
                   2607:         if ($lockfail > 0) {
                   2608:             $response .= "The following $lockfail students were not modified successfully:&nbsp;<br />";
                   2609:             $response .= &enrolltype_result(\%nolockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2610:         }
1.14      raeburn  2611:     }
                   2612:     &print_reply($r,$response,$$tasktitleref{$action});
                   2613:     return;
                   2614: }
                   2615: 
                   2616: sub enrolltype_result {
1.16      raeburn  2617:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx) = @_;
1.14      raeburn  2618:     my $reply = "
                   2619:             <table border='2'>
                   2620:              <tr>
                   2621:               <th>username</th>
                   2622:               <th>domain</th>
                   2623:               <th>ID</th>
                   2624:               <th>student name</th>
                   2625:               <th>section</th>
                   2626:               <th>start date</th>
                   2627:               <th>end date</th>
                   2628:               <th>enrollment change</th>
                   2629:              </tr>";
                   2630:     foreach (sort keys %{$changes}) {
                   2631:         my $sdata  = $classlist->{$_};
                   2632:         my ($uname,$udom) = split/:/,$_;
                   2633:         my $section  = $sdata->[$secidx];
                   2634:         my $uid      = $sdata->[$ididx];
                   2635:         my $start    = $sdata->[$startidx];
                   2636:         my $end      = $sdata->[$endidx];
                   2637:         my $type     = $sdata->[$typeidx];
                   2638:         if (! defined($start) || $start == 0) {
                   2639:             $start = &mt('none');
                   2640:         } else {
                   2641:             $start = &Apache::lonlocal::locallocaltime($start);
                   2642:         }
                   2643:         if (! defined($end) || $end == 0) {
                   2644:             $end = &mt('none');
                   2645:         } else {
                   2646:             $end = &Apache::lonlocal::locallocaltime($end);
                   2647:         }
                   2648:         if (!defined($section) || ($section eq '')) {
                   2649:             $section eq '&nbsp;';
                   2650:         }
                   2651:         if (!defined($uid) || ($uid eq '')) {
                   2652:             $uid = '&nbsp';
                   2653:         }
                   2654:         $reply .= "
                   2655:              <tr>
                   2656:               <td>$uname</td>
                   2657:               <td>$udom</td>
                   2658:               <td>$uid</td>
                   2659:               <td>".&Apache::loncommon::plainname($uname,$udom)."</td>
                   2660:               <td>$section</td>
                   2661:               <td>$start</td>
                   2662:               <td>$end</td>
                   2663:               <td>$$changes{$_}</td>
                   2664:              </tr>";
                   2665:     }
                   2666:     $reply .= "</table>";
                   2667:     return $reply;
                   2668: }
                   2669: 
1.10      raeburn  2670: sub warning_message {
                   2671:     my ($dom,$crs,$caller) = @_;
                   2672:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   2673:     my $currend = '';
                   2674:     my $currstart = '';
                   2675:     my $currsecs = '';
                   2676:     my $currxlists = '';
                   2677:     my $warning = '';
                   2678:     my $curradds = '';
                   2679:     my $currdrops = '';
                   2680:     if ( defined($settings{'internal.autoadds'}) ) {
                   2681:         $curradds = $settings{'internal.autoadds'};
                   2682:     }
                   2683:     if (defined($settings{'internal.autodrops'}) ) {
                   2684:         $currdrops = $settings{'internal.autodrops'};
                   2685:     }
                   2686:     if ( defined($settings{'internal.autostart'}) ) {
                   2687:         $currstart = $settings{'internal.autostart'};
                   2688:     }
                   2689:     if ( defined($settings{'internal.autoend'}) ) {
                   2690:         $currend = $settings{'internal.autoend'};
                   2691:     }
                   2692:     if ( defined($settings{'internal.sectionnums'}) ) {
                   2693:         $currsecs = $settings{'internal.sectionnums'};
                   2694:     }
                   2695:     if ( defined($settings{'internal.crosslistings'}) ) {
                   2696:         $currxlists = $settings{'internal.crosslistings'}
                   2697:     }
                   2698:     unless ($caller eq 'setdates') {
                   2699:         if ( ($currstart eq '') && ($currend eq '') )  {
                   2700:             $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>";
                   2701:         }
                   2702:     }
                   2703:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   2704:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   2705:             $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/>";
                   2706:         }
                   2707:     }
                   2708:     unless ( $caller eq 'chgsettings') {
                   2709:         if ( (!$curradds) && (!$currdrops) ) {
                   2710:             $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/>.";
                   2711:         }
                   2712:     }
                   2713:     return $warning;
1.1       raeburn  2714: }
                   2715: 
                   2716: sub print_reply () {
                   2717:   my ($r,$response,$caller) = @_;
                   2718:   $r->print("
                   2719:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   2720:              <tr>
1.14      raeburn  2721:               <td align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
1.1       raeburn  2722:              </tr>
                   2723:             </table>
                   2724:   ");
                   2725:   return;
                   2726: }
                   2727: 
                   2728: sub setup_date_selectors {
1.14      raeburn  2729:     my ($starttime,$endtime,$action) = @_;
1.1       raeburn  2730:     if (! defined($starttime)) {
                   2731:         $starttime = time;
1.14      raeburn  2732:         if ($action eq 'setdates') {
1.23      albertel 2733:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2734:                             '.default_enrollment_start_date'})) {
1.23      albertel 2735:                 $starttime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2736:                                   '.default_enrollment_start_date'};
1.14      raeburn  2737:             }
1.1       raeburn  2738:         }
                   2739:     }
                   2740:     if (! defined($endtime)) {
                   2741:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  2742:         if ($action eq 'setdates') {
1.23      albertel 2743:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2744:                             '.default_enrollment_end_date'})) {
1.23      albertel 2745:                 $endtime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2746:                                 '.default_enrollment_end_date'};
1.14      raeburn  2747:             }
1.1       raeburn  2748:         }
                   2749:     }
                   2750:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2751:                                                             'startdate',
                   2752:                                                             $starttime);
                   2753:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2754:                                                           'enddate',
                   2755:                                                           $endtime);
                   2756:     return ($startdateform,$enddateform);
                   2757: }
                   2758: 
                   2759: sub get_dates_from_form {
1.14      raeburn  2760:     my $startdate;
                   2761:     my $enddate;
                   2762:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   2763:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.23      albertel 2764:     if ( exists ($env{'form.no_end_date'}) ) {
1.1       raeburn  2765:         $enddate = 0;
                   2766:     }
                   2767:     return ($startdate,$enddate);
                   2768: }
                   2769: 
                   2770: sub date_setting_table {
1.14      raeburn  2771:     my ($starttime,$endtime,$action) = @_;
                   2772:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime,$action);
1.39      albertel 2773:     my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date"';
1.14      raeburn  2774:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || (($action eq 'setaccess' || $action eq 'updatenow') && ($endtime eq '' || $endtime == 0)) ) {
1.1       raeburn  2775:         $perpetual .= ' checked';
                   2776:     }
1.39      albertel 2777:     $perpetual.= ' />'.' no ending date</label></nobr>';
1.1       raeburn  2778:     my $start_table = '';
                   2779:     $start_table .= "<table>\n";
                   2780:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   2781:         '<td>'.$startform.'</td>'.
                   2782:         '<td>&nbsp;</td>'."</tr>\n";
                   2783:     $start_table .= "</table>";
                   2784:     my $end_table = '';
                   2785:     $end_table .= "<table>\n";
                   2786:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   2787:         '<td>'.$endform.'</td>'.
                   2788:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   2789:     $end_table .= "</table>\n";
                   2790:     return ($start_table, $end_table);
                   2791: }
                   2792: 
                   2793: ###################################################################
                   2794: sub handler {
                   2795:     my $r = shift;
                   2796:     if ($r->header_only) {
1.22      albertel 2797: 	&Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  2798:         $r->send_http_header;
                   2799:         return OK;
                   2800:     }
                   2801:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   2802:     #  Needs to be in a course
1.23      albertel 2803:     if (! (($env{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) {
1.1       raeburn  2804:         # Not in a course, or not allowed to modify parms
1.23      albertel 2805:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
1.34      raeburn  2806:         return HTTP_NOT_ACCEPTABLE;
1.1       raeburn  2807:     }
                   2808:     # Start page
1.22      albertel 2809:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  2810:     $r->send_http_header;
                   2811: 
1.34      raeburn  2812:     my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","updatephotos","viewclass");
1.1       raeburn  2813:                                                                                  
                   2814:     my %tasklong = (
                   2815:                information => "Task information",
                   2816:                chgsettings => "Automated adds/drops",
                   2817:                setdates => "Change enrollment dates",
1.14      raeburn  2818:                setaccess => "Change access dates",
1.1       raeburn  2819:                notify => "Notification of changes",
                   2820:                crosslist => "Change crosslistings",
                   2821:                sections => "Section settings",
1.34      raeburn  2822:                photos => "Student photo settings",
                   2823:                updatephotos => "Update student photos",
1.1       raeburn  2824:                updatenow => "Update roster now",
                   2825:                newcross => "Add crosslistings",
1.14      raeburn  2826:                newsections => "Add sections",
1.16      raeburn  2827:                viewclass => "View students and change type",
1.1       raeburn  2828:     );
                   2829:                                                                                  
                   2830:     my %tasktitle = (
                   2831:                chgsettings => "Changes to nightly automated enrollments",
                   2832:                setdates => "Changes to first and/or last automated enrollment dates",
1.14      raeburn  2833:                setaccess => "Changes to default start and/or end dates for student access",
1.1       raeburn  2834:                notify => "Notification of enrollment changes",
                   2835:                crosslist => "Changes to crosslistings",
                   2836:                sections => "Changes to section settings",
1.34      raeburn  2837:                photos => "Student photo settings",
                   2838:                updatephotos => "Update student photos",
1.1       raeburn  2839:                updatenow => "Immediate course roster update",
                   2840:                newcross => "Adding new crosslisted courses",
1.14      raeburn  2841:                newsections => "Adding new course sections",
                   2842:                viewclass => "Viewing class roster and enrollment type"
1.1       raeburn  2843:     );
                   2844: 
                   2845:     my $realm = '';
1.23      albertel 2846:     if ( exists($env{'request.course.id'}) ) {
                   2847:         $realm= $env{'course.'.$env{'request.course.id'}.'.description'};
1.1       raeburn  2848:     }
                   2849:     unless ($realm) { $realm='&nbsp;'; }
1.23      albertel 2850:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2851:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1       raeburn  2852:     
                   2853:     #
                   2854:     # Main switch on form.action and form.state, as appropriate
                   2855:     #
                   2856: 
                   2857:     my $action = "information";
1.23      albertel 2858:     if ( exists($env{'form.action'}) ) {
                   2859:         $action = $env{'form.action'};
1.1       raeburn  2860:     }
                   2861:     my $state = "choose";
                   2862: 
1.23      albertel 2863:     if ( exists($env{'form.state'}) ) {
                   2864:         $state = $env{'form.state'};
1.1       raeburn  2865:     }
                   2866: 
                   2867:     if ($action eq "information") {
                   2868:         $r->print(&header()); 
                   2869:     } else {
                   2870:         if ($state eq "choose") {
1.16      raeburn  2871:             $r->print(&choose_header($action));
1.1       raeburn  2872:         } else {
                   2873:             if ($action eq "crosslist") {
1.23      albertel 2874:                 if ( exists($env{'form.numcross'}) ) {
                   2875:                     if ( $env{'form.numcross'} > 0 ) {
1.16      raeburn  2876:                         $r->print(&choose_header($action));
1.1       raeburn  2877:                     } else {
                   2878:                         $r->print(&header());
                   2879:                     }
                   2880:                 } else {
                   2881:                     $r->print(&header());
                   2882:                 }
                   2883:             } elsif ($action eq "sections") {
1.23      albertel 2884:                 if ( exists($env{'form.numsec'}) ) {
                   2885:                     if ( $env{'form.numsec'} > 0 ) {
1.16      raeburn  2886:                         $r->print(&choose_header($action));
1.1       raeburn  2887:                     } else {
                   2888:                         $r->print(&header());
                   2889:                     }
                   2890:                 } else {
                   2891:                     $r->print(&header());
                   2892:                 }
                   2893:             } else {
                   2894:                 $r->print(&header());
                   2895:             }
                   2896:         }
                   2897:     }
1.12      raeburn  2898: 
1.1       raeburn  2899:     my $reply = 0;
                   2900:     unless ($state eq "choose") { $reply = 1; }
                   2901: 
                   2902:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   2903:     &print_navmenu($r,\@tasks,\%tasklong);
                   2904:     
                   2905:     if (($state eq "choose") || ($action eq "information")) {
1.13      raeburn  2906:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
1.1       raeburn  2907:     } elsif ($action eq "chgsettings") {
                   2908:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2909:     } elsif ($action eq "setdates") {
                   2910:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  2911:     } elsif ($action eq "setaccess") {
                   2912:         &print_setaccess_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2913:     } elsif ($action eq "notify") {
                   2914:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2915:     } elsif ($action eq "sections") {
1.13      raeburn  2916:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2917:     } elsif ($action eq "crosslist") {
1.13      raeburn  2918:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2919:     } elsif ($action eq "updatenow") {
1.13      raeburn  2920:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2921:     } elsif ($action eq "photos") {
1.34      raeburn  2922:         if ($state eq "photoupdate") {
                   2923:             &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2924:         } else { 
                   2925:             &photo_permission($r,$realm,$dom,$crs,$action,\%tasktitle);
                   2926:         }
                   2927:     } elsif ($action eq "updatephotos") {
                   2928:         &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2929:     } elsif ($action eq "newcross") {
1.13      raeburn  2930:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
1.1       raeburn  2931:     } elsif ($action eq "newsections") {
1.13      raeburn  2932:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  2933:     } elsif ($action eq "viewclass") {
                   2934:         &print_viewclass_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  2935:     }
                   2936:     &print_doc_base($r);  
                   2937:     return OK;
                   2938: }
                   2939: ###################################################################
                   2940: 1;

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