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

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

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