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

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

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