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

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

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