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

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

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