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

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

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