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

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

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