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

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

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