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

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

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