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

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

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