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

1.4       albertel    1: # automated enrollment configuration handler
1.89    ! raeburn     2: # $Id: lonpopulate.pm,v 1.88 2021/06/20 22:44:23 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.89    ! raeburn  2446:                     my $newsec;
        !          2447:                     my $crskey = $crs.':'.$coursecode;
        !          2448:                     my %formattedsec = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',
        !          2449:                                                                   {$crskey => [$env{"form.$secnum"}]});
        !          2450:                     if (ref($formattedsec{$crskey}) eq 'ARRAY') {
        !          2451:                         $newsec = $coursecode.$formattedsec{$crskey}->[0];
        !          2452:                     } else {
        !          2453:                         $newsec = $coursecode.$env{"form.$secnum"};
        !          2454:                     }
1.15      albertel 2455: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2456: 		    if ($coursecheck eq 'ok') {
1.68      raeburn  2457: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner,$coowners);
1.15      albertel 2458: 			if ($addcheck eq 'ok') {
1.74      raeburn  2459: 			    push(@sections,$env{"form.$secnum"}.":".$env{"form.$lc_sec"});
1.15      albertel 2460: 			    $seccount ++;
                   2461: 			    $addcount ++;
                   2462: 			} else {
1.74      raeburn  2463: 			    push(@badowner,$env{"form.$secnum"}.":".$env{"form.$lc_sec"});
1.15      albertel 2464: 			}
                   2465: 		    } else {
1.74      raeburn  2466: 			push(@badsections,$env{"form.$secnum"}.":".$env{"form.$lc_sec"}.":".$coursecheck);
1.15      albertel 2467: 		    }
                   2468: 		}
                   2469: 	    }
                   2470: 	}
                   2471: 	if (@currsections > 0) {
                   2472: 	    for (my $i=0; $i<@currsections; $i++) {
1.74      raeburn  2473: 		if ($currsections[$i] =~ /^(\w+:)/) {
1.15      albertel 2474: 		    my $oldsec  = $1;
                   2475: 		    unless (grep/^$oldsec/,@sections) {
                   2476: 			$removecount ++;
                   2477: 		    }
                   2478: 		}
                   2479: 	    }
                   2480: 	}
                   2481:     } elsif (@currsections > 0) {
                   2482: 	for (my $i=0; $i<@currsections; $i++) {
                   2483: 	    my $sec = "sec_".$i;
1.42      raeburn  2484: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 2485: 	    if ( exists($env{"form.$sec"}) ) {
1.15      albertel 2486: 		my $secentry = '';
1.74      raeburn  2487: 		if ($currsections[$i] =~ /^(\w+:)/) {
1.15      albertel 2488: 		    $secentry = $1;
                   2489: 		}
1.42      raeburn  2490: 		if ( exists($env{"form.$lc_sec"}) ) {
                   2491: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2492: 		}
1.74      raeburn  2493: 		push(@sections,$secentry);
1.15      albertel 2494: 		$seccount ++;
                   2495: 	    } else {
                   2496: 		$removecount ++;
                   2497: 	    }
                   2498: 	}
                   2499:     }
                   2500:     
1.74      raeburn  2501:     $secstr = join(',',@sections);
1.28      albertel 2502: 
1.15      albertel 2503:     my %cenv = ('internal.sectionnums' => $secstr);
                   2504:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
1.74      raeburn  2505:     if ($reply ne 'ok') {
                   2506: 	$response = &mt('There was a problem processing your requested changes.').' '.
                   2507:                      &mt('The automated enrollment settings for this course have been left unchanged.').'<br />';
1.15      albertel 2508:     } else {
1.74      raeburn  2509: 	if ($removecount) {
                   2510: 	    $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)").
                   2511:                         '<br /><br />';
                   2512: 	}
                   2513: 	if ($addcount) {
                   2514: 	    $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].',
                   2515:                              $addcount,"$realm ($coursecode)").
                   2516:                              '<br /><br />';
                   2517: 	}
                   2518: 	if ($seccount) { 
                   2519: 	    $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).
                   2520:                          '<br /><ul>'."\n";
                   2521: 	    foreach my $section (@sections) {
                   2522: 		my ($sec,$lc_sec) = split(/:/,$section);
                   2523: 		$response .= '<li>'.&mt('[_1] - ID: [_2]',$sec,$lc_sec).'</li>'
                   2524: .
                   2525:                               "\n";
1.15      albertel 2526: 	    }
1.74      raeburn  2527: 	    $response .= '</ul><br />'."\n";
1.15      albertel 2528: 	}
                   2529:     }
                   2530:     if (@badsections > 0) {
1.74      raeburn  2531: 	$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.").
                   2532:                      '<br /><ul>'."\n";
                   2533: 	foreach my $section (@badsections) {
                   2534: 	    my ($secnum,$lc_sec,$prob) = split(/:/,$section);
                   2535: 	    $response .= '<li>'.&mt('[_1] - ID: [_2] - Error: [_3]',
                   2536:                                     $secnum,$lc_sec,$prob).'</li>'."\n";
1.15      albertel 2537: 	}
1.74      raeburn  2538: 	$response .= "</ul><br /><br />\n";
1.15      albertel 2539:     }
                   2540:     
                   2541:     if (@badowner > 0) {
1.74      raeburn  2542: 	$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).
                   2543:                      '<br /><ul>'."\n";
                   2544: 	foreach my $section (@badowner) {
                   2545: 	    my ($secnum,$lc_sec) = split(/:/,$section);
                   2546: 	    $response .= '<li>'.&mt('[_1] - ID: [_2]',$secnum,$lc_sec).'</li>'.
                   2547:                          "\n";
1.15      albertel 2548: 	}
1.74      raeburn  2549: 	$response .= '</ul><br /><br />'."\n";
1.15      albertel 2550:     }
                   2551:     
                   2552:     if ($seccount > 0) {
                   2553: 	$warning = &warning_message($dom,$crs,$action);
1.74      raeburn  2554:         unless ($warning eq '') { 
                   2555: 	    $response .= '<br /><span class="LC_warning">'.
                   2556:                          '<b>'.&mt('Warning.').'</b> '.
                   2557:                          &mt('Although you have selected sections to contribute enrollment to this course, additional action is required.').
                   2558:                          '</span><br />'.$warning;
1.15      albertel 2559: 	}
                   2560:     }
1.23      albertel 2561:     if ( exists($env{'form.numsec'}) ) {
                   2562: 	my $numsec = $env{'form.numsec'};
1.15      albertel 2563: 	if ($numsec > 0) {
1.74      raeburn  2564: 	    $response .= 
                   2565:                 &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  2566:                &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  2567:                &mt('The LON-CAPA section ID can be left blank, if you do not wish to designate a section ID for this course section.').' '.
                   2568:                &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.").'
                   2569:                <br /><br />
                   2570:            <form name="enter" method="post" action="">
1.1       raeburn  2571:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   2572:              <tr>
1.74      raeburn  2573:               <td>'.
                   2574:             &Apache::loncommon::start_data_table().
                   2575:             &Apache::loncommon::start_data_table_row().'
                   2576:                  <th>'.&mt('Section number').'</th>
                   2577:                  <th>'.&mt('LON-CAPA section ID').'</th>'.
                   2578:             &Apache::loncommon::end_data_table_row();
1.15      albertel 2579: 	    for (my $i=0; $i<$numsec; $i++) {
1.74      raeburn  2580:                 $response .= &Apache::loncommon::start_data_table_row().'
                   2581:                  <td><input type="text" size="10" name="newsec_'.$i.'" /></td>
1.42      raeburn  2582:                  <td align="right">
1.74      raeburn  2583:                    <input type="text" size="10" name="newlcsec_'.$i.'" />
1.42      raeburn  2584:                  </td>
1.74      raeburn  2585:                 '.&Apache::loncommon::end_data_table_row();
1.15      albertel 2586: 	    }
1.74      raeburn  2587:             $response .= &Apache::loncommon::end_data_table().'
1.1       raeburn  2588:               </td>
                   2589:              </tr>
                   2590:              <tr>
                   2591:               <td align="right">
1.74      raeburn  2592:                <input type="button" name="newsections" value="'.&mt('Go').'" onclick="'."process('newsections')".'" />
1.1       raeburn  2593:               </td>
                   2594:              </tr>
                   2595:             </table>
1.74      raeburn  2596:             <input type="hidden" name="numsec" value="'.$numsec.'" />
                   2597:             <input type="hidden" name="action" value="newsections" />
                   2598:             <input type="hidden" name="state" value="process" />
1.1       raeburn  2599:             </form>
1.74      raeburn  2600: 	    ';
1.15      albertel 2601: 	}
                   2602:     }
                   2603:     &print_reply($r,$response,$$tasktitleref{$action});
                   2604:     return;
1.1       raeburn  2605: }
                   2606: 
1.74      raeburn  2607: sub print_sections_response {
1.15      albertel 2608:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.74      raeburn  2609:     my %settings = &Apache::lonnet::get('environment',
                   2610:                        ['internal.sectionnums','internal.coursecode',
                   2611:                         'internal.courseowner','internal.co-owners'],
                   2612:                        $dom,$crs);
                   2613:     my (@currsections,@sections,@allsections,@badowner,@badsections,
                   2614:         @reserved,@matchgroup,$response,$putreply,$warning,$warn_prefix); 
1.15      albertel 2615:     my $numsec = 0;
                   2616:     my $secstr =  $settings{'internal.sectionnums'};
                   2617:     my $coursecode = $settings{'internal.coursecode'};
                   2618:     my $owner = $settings{'internal.courseowner'};
1.68      raeburn  2619:     my $coowners = $settings{'internal.co-owners'};
1.28      albertel 2620:     if ($secstr ne '') {
                   2621: 	@allsections = split(/,/,$secstr);
1.15      albertel 2622:     }
1.23      albertel 2623:     if ( exists($env{'form.numsec'}) ) {
                   2624: 	$numsec = $env{'form.numsec'};
1.15      albertel 2625:     }
                   2626:     if ($numsec > 0) {
1.43      raeburn  2627:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 2628: 	for (my $i=0; $i<$numsec; $i++) {
                   2629: 	    my $sec = "newsec_".$i;
1.42      raeburn  2630: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 2631: 	    if ( exists($env{"form.$sec"}) ) {
1.74      raeburn  2632: 		unless ( (grep/^\Q$env{"form.$sec"}:\E/,@allsections) || 
                   2633:                          (grep/^\Q$env{"form.$sec"}:\E/,@sections) ) {
1.42      raeburn  2634:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,                                                     $env{"form.$lc_sec"});
                   2635:                     if ($lc_sec_check eq 'reserved') {
                   2636:                         push(@reserved,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2637:                         next;
                   2638:                     } elsif ($lc_sec_check eq 'group') {
1.74      raeburn  2639:                         push(@matchgroup,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
1.42      raeburn  2640:                         next;
                   2641:                     }
1.89    ! raeburn  2642:                     my $newsec;
        !          2643:                     my $crskey = $crs.':'.$coursecode;
        !          2644:                     my %formattedsec = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',
        !          2645:                                                                   {$crskey => [$env{"form.$sec"}]});
        !          2646:                     if (ref($formattedsec{$crskey}) eq 'ARRAY') {
        !          2647:                         $newsec = $coursecode.$formattedsec{$crskey}->[0];
        !          2648:                     } else {
        !          2649:                         $newsec = $coursecode.$env{"form.$sec"};
        !          2650:                     }
1.15      albertel 2651: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2652: 		    if ($coursecheck eq 'ok') {
1.68      raeburn  2653: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner,$coowners);
1.15      albertel 2654: 			if ($addcheck eq 'ok') {
1.74      raeburn  2655: 			    push(@sections,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
1.15      albertel 2656: 			} else {
1.74      raeburn  2657: 			    push(@badowner,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
1.15      albertel 2658: 			}
                   2659: 		    } else {
1.74      raeburn  2660: 			push(@badsections,$env{"form.$sec"}.":".$env{"form.$lc_sec"}.":".$coursecheck);
1.15      albertel 2661: 		    }
                   2662: 		}
                   2663: 	    }
                   2664: 	}
1.74      raeburn  2665: 	push(@allsections,@sections);
1.15      albertel 2666:     }
                   2667:     
1.74      raeburn  2668:     if (@sections > 0) {
1.15      albertel 2669: 	unless ($secstr eq '') { $secstr .= ","; } 
1.74      raeburn  2670: 	$secstr .= join(',',@sections);
1.15      albertel 2671: 	my %cenv = ('internal.sectionnums' => $secstr);
                   2672: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
1.74      raeburn  2673: 	if ($putreply ne 'ok') {
                   2674: 	    $response = &mt('There was a problem processing your requested changes.').' '.
                   2675:                         &mt('The automated enrollment settings for this course have been left unchanged.').
                   2676:                         '<br /><br />';
1.15      albertel 2677: 	}
                   2678:     }
                   2679: 
1.78      raeburn  2680:     if ($putreply eq 'ok') {
1.74      raeburn  2681: 	$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.',
                   2682:                         "$realm ($coursecode)").'<br /><ul>'."\n";
                   2683: 	foreach my $section (@allsections) {
                   2684: 	    my ($sec,$lc_sec) = split(/:/,$section);
                   2685: 	    $response .= '<li>'.&mt('[_1] - ID: [_2]',$sec,$lc_sec).'</li>'.
                   2686:                          "\n";
1.15      albertel 2687: 	}
1.74      raeburn  2688: 	$response .= '</ul><br /><br />'."\n";
1.15      albertel 2689:     }
                   2690: 
                   2691:     if (@badsections > 0) {
1.74      raeburn  2692: 	$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.").
                   2693:                      '<br /><ul>'."\n";
                   2694: 	foreach my $item (@badsections) {
                   2695: 	    my ($secnum,$lc_sec,$prob) = split(/:/,$item);
                   2696: 	    $response .= '<li>'.
                   2697:                          &mt('[_1] - ID: [_2] - Error: [_3]',
                   2698:                              $secnum,$lc_sec,$prob).
                   2699:                          '</li>'."\n";
1.15      albertel 2700: 	}
1.74      raeburn  2701: 	$response .= '</ul><br /><br />'."\n";
1.15      albertel 2702:     }
                   2703: 
                   2704:     if (@badowner > 0) {
1.74      raeburn  2705: 	$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).
                   2706:                      '<br /><ul>'."\n";
                   2707: 	foreach my $item (@badowner) {
                   2708: 	    my ($secnum,$lc_sec) = split(/:/,$item);
                   2709: 	    $response .= '<li>'.&mt('[_1] - ID: [_2]',$secnum,$lc_sec).'</li>'.
                   2710:                          "\n";
1.15      albertel 2711: 	}
1.74      raeburn  2712: 	$response .= '</ul><br /><br />'."\n";
1.15      albertel 2713:     }
                   2714: 
1.42      raeburn  2715:     if (@reserved > 0) {
1.74      raeburn  2716:         $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.').' '.
                   2717:                      &mt('Please [_1]go back[_2] and change the section ID for each of these sections.',
                   2718:                         '<a href="javascript:history.go(-1)">','</a>').
                   2719:                      '<br /><ul>'."\n";
                   2720:         foreach my $xl (@reserved) {
                   2721:             my ($xlist,$lc_sec) = split(/:/,$xl);
                   2722:             $response .= '<li>'.
                   2723:                          &mt('[_1] - ID: [_2]',$xlist,$lc_sec).
                   2724:                          '</li>'."\n";
1.42      raeburn  2725:         }
1.74      raeburn  2726:         $response .= "</ul><br /><br />\n";
1.42      raeburn  2727:     }
                   2728:                                                                                  
                   2729:     if (@matchgroup > 0) {
1.74      raeburn  2730:         $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.').' '.
                   2731:                      &mt('Please [_1]go back[_2] and change the section ID for each of these sections.','<a href="javascript:history.go(-1)">','</a>').
                   2732:                      '<br /><ul>'."\n";
                   2733:         foreach my $section (@matchgroup) {
                   2734:             my ($xlist,$lc_sec) = split(/:/,$section);
                   2735:             $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).
                   2736:                          '</li>'."\n";
1.42      raeburn  2737:         }
1.74      raeburn  2738:         $response .= '</ul><br /><br />'."\n";
1.42      raeburn  2739:     }
1.15      albertel 2740:     if (@allsections > 0) {
                   2741: 	$warning = &warning_message($dom,$crs,$action);
1.74      raeburn  2742:         unless ($warning eq '') {
                   2743: 	    '<br />'.
                   2744:             '<span class="LC_warning"><b>'.&mt('Warning.').'</b> '."\n".
                   2745:             &mt('Although you have selected sections to contribute enrollment to this course, additional action is required.').'<span><br />'.$warning;
1.15      albertel 2746: 	}
                   2747:     }
                   2748:     &print_reply($r,$response,$$tasktitleref{$action});
                   2749:     return;
1.1       raeburn  2750: }
                   2751: 
1.34      raeburn  2752: sub photo_permission {
1.15      albertel 2753:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.35      albertel 2754:     my %settings = &Apache::lonnet::get('environment',
                   2755: 					['internal.courseowner',
                   2756: 					 'internal.photopermission',
1.37      raeburn  2757: 					 'internal.showphoto'],
1.35      albertel 2758: 					$dom,$crs);
1.34      raeburn  2759:     my ($showphotos,$response);
                   2760:     if (exists($env{'form.cancel_agreement'})) {
1.48      albertel 2761:         if (&user_is_courseowner($settings{'internal.courseowner'})) {
1.34      raeburn  2762:             my %cenv = (
                   2763:                 'internal.photopermission' => 'no',
                   2764:             );
                   2765:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
1.74      raeburn  2766:             if ($reply ne 'ok') {
                   2767:                 $response = 
                   2768:                     &mt('There was a problem processing the record of your agreement to the conditions of use.').' '.
                   2769:                     &mt('Settings for this course have been left unchanged.').'<br />'."\n";
1.34      raeburn  2770:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2771:             } else {
                   2772:                 &print_photos_response($r,$realm,$dom,$crs,$action,
                   2773:                        $tasktitleref,$showphotos,'no',\%cenv);
                   2774:             }
                   2775:             return;            
                   2776:         }
                   2777:     } 
                   2778:     if (exists($env{'form.showphotos'})) {
                   2779:         $showphotos=$env{'form.showphotos'};
                   2780:     }
                   2781:     if ($showphotos) {
                   2782:         if ($env{'form.photopermission'}) {
                   2783:             my %cenv = (
                   2784:                 'internal.photopermission' => $env{'form.photopermission'},
                   2785:             );
                   2786:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
1.74      raeburn  2787:             if ($reply ne 'ok') {
                   2788:                 $response = 
                   2789:                     &mt('There was a problem processing the record of your agreement to the conditions of use.').' '.
                   2790:                     &mt('Settings for this course have been left unchanged.').'<br />'."\n";
1.34      raeburn  2791:             } else {
                   2792:                 &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2793: 				       $tasktitleref,$showphotos,
                   2794: 				       $env{'form.photopermission'},\%cenv);
1.34      raeburn  2795:             }
                   2796:         } else {
                   2797:             my ($result,$perm_reqd,$conditions) = 
1.35      albertel 2798: 		&Apache::lonnet::auto_photo_permission($crs,$dom);
1.34      raeburn  2799:             my $permcheck;
                   2800:             if ($result eq 'ok') { 
                   2801:                 if ($perm_reqd eq 'yes') {
                   2802:                     if ($settings{'internal.photopermission'} eq 'yes') {
                   2803:                         &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2804: 					       $tasktitleref,$showphotos);
1.34      raeburn  2805:                     } else {
                   2806:                         return(&print_photo_agreement($r,$realm,$dom,$crs,
1.35      albertel 2807: 						      $action,$tasktitleref,
                   2808: 						      $conditions,
                   2809: 						      $settings{'internal.courseowner'}));
1.34      raeburn  2810:                     }
                   2811:                 } elsif ($perm_reqd eq 'no') {
                   2812:                     &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2813: 					   $tasktitleref,$showphotos);
1.34      raeburn  2814:                 } else {
                   2815:                     $permcheck = 'fail';
                   2816:                 }
                   2817:             } else {
                   2818:                 $permcheck = 'fail';
                   2819:             }
                   2820:             if ($permcheck eq 'fail') {
1.74      raeburn  2821:                 my $response = 
                   2822:                     &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.').' '.
                   2823:                     &mt('The student photo import setting for this course has been left unchanged.').'<br />';
1.34      raeburn  2824:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2825:             }
                   2826:         }
                   2827:     } else {
                   2828:         &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref);
                   2829:     }
                   2830:     return;
                   2831: }
                   2832: 
                   2833: sub print_photo_agreement {
                   2834:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_;
                   2835:     my $response;
1.49      albertel 2836:     my $institution = &Apache::lonnet::domain($dom,'description');
1.48      albertel 2837:     if (&user_is_courseowner($courseowner)) {
1.34      raeburn  2838:         $response = '
1.58      bisitz   2839: <script type="text/javascript" language="JavaScript">
1.34      raeburn  2840: function agreement_result(caller) {
                   2841:     document.permission.photopermission.value = caller;
                   2842:     if (caller == 0) {
                   2843:         document.location.href="/adm/populate";
                   2844:     } else {
                   2845:         document.permission.submit();
                   2846:     }
                   2847:     return;
                   2848: }
                   2849: </script>
1.74      raeburn  2850:   <form name="permission" method="post" action="">
1.34      raeburn  2851:    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   2852:     <tr>
1.74      raeburn  2853:      <td align="left"><b>'.&mt('Use of student photos').'</b><br />'."\n".
                   2854:       &mt('Acceptance by the course owner of the conditions of use of photos is currently [_1]not[_2] set.','<b>','</b>').'<br />'.
                   2855:       &mt('Please indicate your acceptance of the conditions of use of digital photos of registered students in courses at [_1].',$institution).'
1.34      raeburn  2856:      </td>
                   2857:     </tr>
                   2858:    </table>
                   2859:    <table border="0" cellpadding="3" cellspacing="3">
                   2860:     <tr>
                   2861:      <td colspan="2">
                   2862:       <textarea rows="20" cols="80">'.$conditions.'</textarea>
                   2863:      </td>
                   2864:      <tr>
                   2865:       <td align="left">  
1.74      raeburn  2866:        <input type="button" name="disagree" value="'.&mt('I do not agree').'" onclick="javascript:agreement_result('."'no'".');" />
1.34      raeburn  2867:       </td>
                   2868:       <td align="right">
1.74      raeburn  2869:        <input type="button" name="agree" value="'.&mt('I agree').'" onclick="javscript:agreement_result('."'yes'".');" />
1.34      raeburn  2870:       </td>
                   2871:     </tr>
                   2872:    </table>
1.62      bisitz   2873:    <input type="hidden" name="action" value="'.$action.'" />
                   2874:    <input type="hidden" name="state" value="process" />
                   2875:    <input type="hidden" name="showphotos" value="1" />
                   2876:    <input type="hidden" name="photopermission" value="" />
1.34      raeburn  2877:   </form>
                   2878: ';
                   2879:     } else {
1.44      raeburn  2880:         my ($ownername,$owneremail) = &get_ownerinfo($dom,$courseowner);
                   2881:         my $emailstr;
                   2882:         if ($owneremail) {
1.74      raeburn  2883:             $emailstr = &mt('(e-mail: [_1])',$owneremail);
1.44      raeburn  2884:         }
1.56      bisitz   2885:         $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)
                   2886:                    .'<br /><br />'
                   2887:                    .&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  2888:     }
                   2889:     &print_reply($r,$response,$$tasktitleref{$action});
                   2890: }
                   2891: 
                   2892: sub print_photos_response {
                   2893:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission,
1.35      albertel 2894: 	$permissionenv)=@_;
1.34      raeburn  2895:     my %newenv;
                   2896:     if (defined($permissionenv)) {
                   2897:         foreach my $key (keys(%{$permissionenv})) {
                   2898:             if (exists($env{'request.course.id'})) {
                   2899:                 $newenv{$env{'request.course.id'}.'.'.$key} =
1.35      albertel 2900: 		    $$permissionenv{$key};
1.34      raeburn  2901:             }
                   2902:         }
                   2903:     }
1.37      raeburn  2904:     my %settings = &Apache::lonnet::get('environment',['internal.showphoto'],
1.35      albertel 2905: 					$dom,$crs);
1.37      raeburn  2906:     my $currphotos = $settings{'internal.showphoto'};
1.34      raeburn  2907:     my $response = "";
                   2908:     if (defined($photopermission)) {
                   2909:         if ($photopermission eq 'yes') {
                   2910:             $response = &mt('Acceptance of photo use policy recorded.').'<br />'."\n";
                   2911:         } else {
1.74      raeburn  2912:             $response = &mt('Rejection of photo use policy recorded.').'<br />'."\n";
1.34      raeburn  2913:             $showphotos = 0;
                   2914:         }
1.15      albertel 2915:     }
1.37      raeburn  2916:     my %cenv = ('internal.showphoto' => $showphotos);
1.15      albertel 2917:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
1.74      raeburn  2918:     if ($reply ne 'ok') {
                   2919: 	$response .= &mt('There was a problem processing your requested change.').' '.
                   2920:                      &mt('The student photo retrieval setting for this course has been left unchanged.').'<br />';
1.15      albertel 2921:     } else {
                   2922: 	if ($showphotos) {
                   2923: 	    if ($currphotos) {
1.74      raeburn  2924: 		$response .= &mt('Retrieval of student photos is still [_1]enabled[_2].','<b>','</b>').'<br />';
1.15      albertel 2925: 	    } else {
1.74      raeburn  2926: 		$response .= &mt('Retrieval of student photos in now [_1]enabled[_2].','<b>','</b>').'<br />';
1.35      albertel 2927:                 my ($update,$commentary) = 
                   2928: 		    &Apache::lonnet::auto_photochoice($crs,$dom);
1.34      raeburn  2929:                 if ($update) {
                   2930:                     $response .= '<br />'.$commentary.'<br /><br />
1.74      raeburn  2931: <form name="photoupdate" method="post" action="">
1.62      bisitz   2932: <input type="button" name="retrieve" value="'.&mt('Update photo repository').'" 
1.34      raeburn  2933: onclick="javascript:document.photoupdate.submit()" /> 
1.62      bisitz   2934: <input type="hidden" name="action" value="'.$action.'" />
                   2935: <input type="hidden" name="state" value="photoupdate" />
1.34      raeburn  2936: </form>';
                   2937:                 }
1.15      albertel 2938: 	    }
                   2939: 	} else {
                   2940: 	    if ($currphotos) {
1.74      raeburn  2941: 		$response .= &mt('Retrieval of student photos is now [_1]disabled[_2].','<b>','</b>').'<br />';
1.15      albertel 2942: 	    } else {
1.74      raeburn  2943: 		$response .= &mt('Retrieval of student photos is still [_1]disabled[_2].','<b>','</b>').'<br />';
1.15      albertel 2944: 	    }
                   2945: 	}
1.34      raeburn  2946:         foreach my $key (keys(%cenv)) {
                   2947:             if (exists($env{'request.course.id'})) {
                   2948:                 $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = 
1.35      albertel 2949: 		    $cenv{$key};
1.34      raeburn  2950:             }
                   2951:         }
                   2952:     }
                   2953:     if (keys(%newenv) > 0) {
1.54      raeburn  2954:         &Apache::lonnet::appenv(\%newenv);
1.34      raeburn  2955:     }
                   2956:     &print_reply($r,$response,$$tasktitleref{$action});
                   2957:     return;
                   2958: }
                   2959: 
                   2960: sub print_photoupdate_response {
                   2961:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.74      raeburn  2962:     my ($response,$outcome,%changes,@allcourses,%LC_code,%affiliates);
1.34      raeburn  2963:     my %lt = &LONCAPA::Enrollment::photo_response_types();
1.35      albertel 2964:     my %settings = &Apache::lonnet::get('environment',
                   2965: 					['internal.coursecode',
                   2966: 					 'internal.sectionnums',
                   2967: 					 'internal.crosslistings'],
                   2968: 					$dom,$crs);
1.87      raeburn  2969:     &Apache::loncommon::get_institutional_codes($dom,$crs,\%settings,\@allcourses,\%LC_code);
1.34      raeburn  2970:     if (@allcourses > 0) {
                   2971:         @{$affiliates{$crs}} = @allcourses;
                   2972:         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
                   2973:         unless ($outcome eq 'ok') {
                   2974:             &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response".
1.35      albertel 2975: 				     "failed to update student photos".
                   2976: 				     " for ".$crs."\@".$dom." by ".
                   2977: 				     $env{'user.name'}." \@ ".$env{'user.domain'}.
                   2978: 				     ": ".$outcome);
1.34      raeburn  2979:         }
                   2980:         if ($outcome eq 'ok') {
                   2981:             if (keys(%changes) > 0) {
1.58      bisitz   2982:                 $response = &mt('Update of photos for registered students resulted in the following ').': <br />'
                   2983:                            .'<script type="text/javascript" language="JavaScript">
1.34      raeburn  2984: function photowindow(photolink) {
                   2985:     var title = "Photo_Viewer";
                   2986:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2987:     options += ",width=240,height=240";
                   2988:     stdeditbrowser = open(photolink,title,options,"1");
                   2989:     stdeditbrowser.focus();
                   2990: }
                   2991: </script>
                   2992: ';
                   2993:                 foreach my $type (sort(keys(%changes))) {
                   2994:                     my @usernames = sort(split(/\&/,$changes{$type})); 
                   2995:                     my $count = @usernames; 
1.74      raeburn  2996:                     $response .= '<b>'.&mt('For [quant,_1,student], photos [_2]',
                   2997: 					   $count,$lt{$type}).'</b><ul>';
1.34      raeburn  2998:                     foreach my $username (@usernames) {
                   2999:                         $response .= '<li>'.$username;
                   3000:                         if (($type eq 'new') || ($type eq 'same') || ($type eq 'update')) {
1.74      raeburn  3001:                             $response .= '&nbsp;<a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($dom,$username,'jpg')."'".')">'.&mt('View').'</a></li>';
1.34      raeburn  3002:                         }
                   3003:                     }
                   3004:                     $response .= '</ul><br />';
                   3005:                 }
                   3006:             } else {
                   3007:                 $response = &mt('No updates of photos of registered students occurred').
                   3008:                          '<br />';
                   3009:             }    
                   3010:         } else {
1.74      raeburn  3011:             $response = &mt('There was a problem updating student photos for registered students in this course.').'<br />';
1.34      raeburn  3012:         }
                   3013:     } else {
1.74      raeburn  3014:         $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 3015:     }
                   3016:     &print_reply($r,$response,$$tasktitleref{$action});
                   3017:     return;
1.1       raeburn  3018: }
                   3019: 
1.34      raeburn  3020: sub get_ownerinfo {
                   3021:     my ($dom,$owner) = @_; 
1.44      raeburn  3022:     my ($ownername,$owneremail,$own_uname,$own_udom);
1.34      raeburn  3023:     if ($owner) {
1.44      raeburn  3024:         if ($owner =~ /^([^:]+):([^:]+)$/) {
                   3025:             $own_uname = $1;
                   3026:             $own_udom = $2; 
                   3027:         } else {
                   3028:             $own_uname = $owner;
                   3029:             $own_udom = $dom; 
                   3030:         }
                   3031:         $ownername=&Apache::loncommon::plainname($own_uname,$own_udom,
                   3032:                                                  'firstname');
1.36      raeburn  3033:         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
1.44      raeburn  3034: 					     $own_udom,$own_uname);
1.34      raeburn  3035:         $owneremail = $ownerinfo{'permanentemail'};
                   3036:     }
                   3037:     return ($ownername,$owneremail);
                   3038: }
                   3039: 
1.74      raeburn  3040: sub print_update_result {
1.15      albertel 3041:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.74      raeburn  3042:     my ($response,$logmsg,$newusermsg,%affiliates,%reply,@allcourses,
                   3043:         %LC_code,%phototypes);
1.15      albertel 3044:     my $updateadds = 0;
                   3045:     my $updatedrops = 0;
                   3046:     my $changecount = 0;
1.74      raeburn  3047:     my %settings = 
                   3048:         &Apache::lonnet::get('environment',
                   3049:             ['internal.coursecode','internal.sectionnums','internal.crosslistings',
1.80      raeburn  3050:              'internal.authtype','internal.autharg','internal.showphoto','internal.defaultcredits',
1.84      raeburn  3051:              'internal.autodropfailsafe','internal.textbook'],
1.74      raeburn  3052:             $dom,$crs);
1.15      albertel 3053:     my $coursecode = $settings{'internal.coursecode'};
                   3054:     my $authtype = $settings{'internal.authtype'};
                   3055:     my $autharg = $settings{'internal.autharg'};
1.37      raeburn  3056:     my $showphotos = $settings{'internal.showphoto'};
1.80      raeburn  3057:     my $textbook = $settings{'internal.textbook'};
1.76      raeburn  3058:     my ($showcredits,$defaultcredits);
                   3059:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.80      raeburn  3060:     if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.76      raeburn  3061:         $showcredits = 1;
                   3062:         $defaultcredits = $settings{'internal.defaultcredits'};
                   3063:         if ($defaultcredits eq '') {
                   3064:             if ($coursecode ne '') {
                   3065:                 $defaultcredits = $domdefaults{'officialcredits'};   
1.80      raeburn  3066:             } elsif ($textbook ne '') {
                   3067:                 $defaultcredits = $domdefaults{'textbookcredits'};
1.76      raeburn  3068:             } else {
                   3069:                 $defaultcredits = $domdefaults{'unofficialcredits'};
                   3070:             }
                   3071:         }
                   3072:     }
1.84      raeburn  3073:     my $failsafe = $settings{'internal.autodropfailsafe'};
                   3074:     if ($failsafe eq '') {
                   3075:         $failsafe = $domdefaults{'autofailsafe'};
                   3076:     }
1.15      albertel 3077:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.23      albertel 3078:     if ( exists($env{'form.updateadds'}) ) {
                   3079:         $updateadds = $env{'form.updateadds'};
1.15      albertel 3080:     }
1.23      albertel 3081:     if ( exists($env{'form.updatedrops'}) ) {
                   3082:         $updatedrops = $env{'form.updatedrops'};
1.15      albertel 3083:     }
1.19      raeburn  3084:     if (($startaccess eq '') || ($endaccess eq '')) {
1.74      raeburn  3085:         $response = &mt('There was a problem processing your requested roster update because start and and access dates could not be determined.').' '.
                   3086:                     &mt('No changes have been made to the class roster.').
                   3087:                     '<br />'; 
1.19      raeburn  3088:     } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
1.74      raeburn  3089:         $response = &mt('The start access date/time is the same or later than the end access date/time.').' '.
                   3090:                     &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.').' '.
                   3091:                     &mt('Please [_1]go back[_2] to the previous page to try your changes again.',
                   3092:                         '<a href="javascript:history.go(-1)">','</a>')."\n";
1.19      raeburn  3093:     } elsif (!$updateadds && !$updatedrops) {
1.74      raeburn  3094: 	$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 3095:     } elsif ($coursecode eq '') {
1.74      raeburn  3096: 	$response = &mt('There was a problem retrieving the course code for this LON-CAPA course.').' '.
                   3097:                     &mt('An update of the class roster has not been carried out, and enrollment remains unchanged.');
1.15      albertel 3098:     } else {
1.87      raeburn  3099:         &Apache::loncommon::get_institutional_codes($dom,$crs,\%settings,\@allcourses,\%LC_code);
1.15      albertel 3100: 	if (@allcourses > 0) {
                   3101: 	    @{$affiliates{$crs}} = @allcourses;
                   3102: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
1.19      raeburn  3103:             unless ($outcome eq 'ok') {
                   3104:                 &Apache::lonnet::logthis("lonpopulate:update roster".
                   3105:                                          "failed to retrieve classlist".
1.74      raeburn  3106:                                  " data for ".$crs.':'.$dom." by ".
1.23      albertel 3107:                                  $env{'user.name'}." \@ ".$env{'user.domain'}.
1.19      raeburn  3108:                                  ": ".$outcome);
                   3109:             }
1.15      albertel 3110: 	    if ($reply{$crs} > 0) {
1.84      raeburn  3111: 		($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 3112: 	    } else {
1.74      raeburn  3113: 		$response = &mt('There was a problem retrieving institutional class list data for the course sections and crosslisted courses which contribute enrollment to this course.').' '.
                   3114:                             &mt('No updates have been carried out, and the roster remains unchanged.');
1.15      albertel 3115: 	    }  
                   3116: 	} else {
1.74      raeburn  3117: 	    $response = &mt('There are currently no course sections or crosslisted courses designated as contributors to enrollment in this LON-CAPA course.').' '.
                   3118:                         &mt('As a result a student roster update has not been carried out for [_1].',"$realm ($coursecode)");
1.15      albertel 3119: 	}
                   3120:     }
                   3121:     unless ($logmsg eq '') {
                   3122: 	my $loglength = length($logmsg);
                   3123: 	$logmsg = substr($logmsg,0,$loglength-4);
1.74      raeburn  3124: 	$logmsg = '<br /><br />'.&mt('The following messages were generated by the roster update process: [_1]','<br /><ul><li>'.$logmsg.'</ul><br />');
1.15      albertel 3125:     }
                   3126:     unless ($newusermsg eq '') {
                   3127: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
1.74      raeburn  3128: 	$newusermsg = '<br /><br />'.
                   3129:                       &mt('The following new system user(s) who was/were created will be using local or internal authentication with an initial randomly generated password.').' '.
                   3130:                       &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.').
                   3131:                       '<br /><ul><li>'.$newusermsg.'</ul><br />';
1.15      albertel 3132:     }
                   3133:     $response .= $logmsg.$newusermsg;
                   3134:     &print_reply($r,$response,$$tasktitleref{$action});
                   3135:     return;
1.10      raeburn  3136: }
                   3137: 
1.14      raeburn  3138: sub print_viewclass_response {
                   3139:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.74      raeburn  3140:     my ($response,%chg,%nochg,%otherdom,%lockchg,%nolockchg);
1.14      raeburn  3141:     my $chgtotal = 0;
                   3142:     my $chgok = 0;
                   3143:     my $chgfail = 0;
                   3144:     my $othdom = 0;
1.16      raeburn  3145:     my $locktotal = 0;
                   3146:     my $lockok = 0;
                   3147:     my $lockfail = 0;
1.74      raeburn  3148:     my $cid = $dom.'_'.$crs;
1.27      albertel 3149:     my $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  3150:     my $endidx = &Apache::loncoursedata::CL_END;
                   3151:     my $startidx = &Apache::loncoursedata::CL_START;
                   3152:     my $ididx=&Apache::loncoursedata::CL_ID;
                   3153:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   3154:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
1.16      raeburn  3155:     my $lockedidx=&Apache::loncoursedata::CL_LOCKEDTYPE;
1.76      raeburn  3156:     my $creditsidx=&Apache::loncoursedata::CL_CREDITS;
1.74      raeburn  3157:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   3158:                                ['chgauto','chgmanual','lockchg','unlockchg']);
1.24      albertel 3159:     my @typechglist = (&Apache::loncommon::get_env_multiple('form.chgauto'),
                   3160: 		       &Apache::loncommon::get_env_multiple('form.chgmanual'));
                   3161:     my @lockchglist = (&Apache::loncommon::get_env_multiple('form.lockchg'),
                   3162: 		       &Apache::loncommon::get_env_multiple('form.unlockchg'));
                   3163: 
1.76      raeburn  3164:     foreach my $student (sort(@typechglist)) {
1.51      raeburn  3165:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  3166:         my $sdata    = $classlist->{$student};
                   3167:         my $section  = $sdata->[$secidx];
                   3168:         my $uid       = $sdata->[$ididx];
                   3169:         my $start    = $sdata->[$startidx];
                   3170:         my $end      = $sdata->[$endidx];
                   3171:         my $type     = $sdata->[$typeidx];
                   3172:         my $lock   = $sdata->[$lockedidx];
1.76      raeburn  3173:         my $credits = $sdata->[$creditsidx];
1.16      raeburn  3174:         my $newlock = $lock;
                   3175:         $chgtotal ++;
                   3176:         my $newtype = 'auto';
                   3177:         my $change = 'auto';
                   3178:         my $oldtype = 'manual';
                   3179:         if ($type eq 'auto') { 
                   3180:             $oldtype = 'auto';
                   3181:             $newtype = '';
                   3182:             $change = 'manual';
                   3183:         }
                   3184:         if ($udom eq $dom) {
                   3185:             if ($newtype eq 'auto') {
                   3186:                 $newlock = '';
                   3187:             } elsif ($newtype eq '') {
                   3188:                 $newlock = '1';
1.14      raeburn  3189:             }
1.76      raeburn  3190:             my $modreply = 
                   3191:                 &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'',
                   3192:                                                            '','','',$section,$end,
                   3193:                                                            $start,$newtype,
                   3194:                                                            $newlock,$cid,'',
                   3195:                                                            'chgtype',$credits);
1.16      raeburn  3196:             if ($modreply eq 'ok') {
                   3197:                 $chgok ++;
1.74      raeburn  3198:                 $chg{$student} = &mt("Changed to $change");
1.16      raeburn  3199:             } else {
                   3200:                 $chgfail ++;
1.74      raeburn  3201:                 $nochg{$student} = &mt("Still set to $oldtype");
1.16      raeburn  3202:             } 
                   3203:         } else {
                   3204:             $othdom ++;
1.74      raeburn  3205:             $otherdom{$student} = &mt("Still set to $oldtype"); 
1.16      raeburn  3206:         }
                   3207:     }
                   3208:     foreach my $student (@lockchglist) {
1.51      raeburn  3209:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  3210:         my $sdata    = $classlist->{$student};
                   3211:         my $section  = $sdata->[$secidx];
                   3212:         my $uid       = $sdata->[$ididx];
                   3213:         my $start    = $sdata->[$startidx];
                   3214:         my $end      = $sdata->[$endidx];
                   3215:         my $type     = $sdata->[$typeidx];
                   3216:         my $lock   = $sdata->[$lockedidx];
1.76      raeburn  3217:         my $credits = $sdata->[$creditsidx];
1.16      raeburn  3218:         my $newlock = 1;
                   3219:         my $oldlockname = &mt('unlocked');
                   3220:         my $newlockname = &mt('locked');
                   3221:         $locktotal++;
                   3222:         unless ($type eq 'auto') {
                   3223:             if ($lock) {
                   3224:                 $newlock = '';
                   3225:                 $newlockname = &mt('unlocked');
                   3226:                 $oldlockname = &mt('locked'); 
                   3227:             }
1.76      raeburn  3228:             my $lockreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$type,$newlock,$cid,'','chgtype',$credits);
1.16      raeburn  3229:             if ($lockreply eq 'ok') {
                   3230:                 $lockok ++;
1.74      raeburn  3231:                 $lockchg{$student} = &mt('Changed to [_1]',$newlockname);
1.14      raeburn  3232:             } else {
1.16      raeburn  3233:                 $lockfail ++;
1.74      raeburn  3234:                 $nolockchg{$student} = &mt('Still set to [_1]',$oldlockname);
1.14      raeburn  3235:             }
                   3236:         }
                   3237:     }
                   3238:     if ($chgtotal > 0) {
1.51      raeburn  3239:         $response = &mt('You requested a change in enrollment type for [quant,_1,student].',$chgtotal).'<br /><br />'."\n";
1.27      albertel 3240:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  3241:         if ($chgok > 0) {
1.51      raeburn  3242:             $response .= &mt('The following [quant,_1,change was,changes were] successful;',$chgtotal).':<br /><br />';
1.14      raeburn  3243:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   3244:         }
                   3245:         if ($chgfail > 0) {
1.51      raeburn  3246:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$chgfail).':&nbsp;<br />';
1.14      raeburn  3247:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   3248:         }
                   3249:         if ($othdom > 0) {
1.51      raeburn  3250:             $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  3251:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   3252:         }
1.74      raeburn  3253:         $response .= '<br /><br />';
1.16      raeburn  3254:     }
                   3255:     if ($locktotal > 0) {
1.51      raeburn  3256:         $response .= &mt('You requested locking/unlocking for [quant,_1,manually enrolled student]',$locktotal).'<br /><br />'."\n";
1.27      albertel 3257:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.16      raeburn  3258:         if ($lockok > 0) {
1.51      raeburn  3259:             $response .= &mt('The following [quant,_1,change was,changes were] successful',$lockok).':<br /><br />';
1.16      raeburn  3260:             $response .= &enrolltype_result(\%lockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   3261:         }
                   3262:         if ($lockfail > 0) {
1.51      raeburn  3263:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$lockfail).':&nbsp;<br />';
1.16      raeburn  3264:             $response .= &enrolltype_result(\%nolockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   3265:         }
1.14      raeburn  3266:     }
                   3267:     &print_reply($r,$response,$$tasktitleref{$action});
                   3268:     return;
                   3269: }
                   3270: 
                   3271: sub enrolltype_result {
1.16      raeburn  3272:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx) = @_;
1.51      raeburn  3273:     my $reply = &Apache::loncommon::start_data_table().
                   3274:                 &Apache::loncommon::start_data_table_header_row().'
1.74      raeburn  3275:               <th>'.&mt('username').'</th>
                   3276:               <th>'.&mt('domain').'</th>
                   3277:               <th>'.&mt('ID').'</th>
                   3278:               <th>'.&mt('student name').'</th>
                   3279:               <th>'.&mt('section').'</th>
                   3280:               <th>'.&mt('start date').'</th>
                   3281:               <th>'.&mt('end date').'</th>
                   3282:               <th>'.&mt('enrollment change').'</th>'."\n".
1.51      raeburn  3283:                 &Apache::loncommon::end_data_table_header_row();
1.74      raeburn  3284:     foreach my $chg (sort(keys(%{$changes}))) {
1.51      raeburn  3285:         my $sdata  = $classlist->{$chg};
                   3286:         my ($uname,$udom) = split(/:/,$chg);
1.14      raeburn  3287:         my $section  = $sdata->[$secidx];
                   3288:         my $uid      = $sdata->[$ididx];
                   3289:         my $start    = $sdata->[$startidx];
                   3290:         my $end      = $sdata->[$endidx];
                   3291:         my $type     = $sdata->[$typeidx];
                   3292:         if (! defined($start) || $start == 0) {
                   3293:             $start = &mt('none');
                   3294:         } else {
                   3295:             $start = &Apache::lonlocal::locallocaltime($start);
                   3296:         }
                   3297:         if (! defined($end) || $end == 0) {
                   3298:             $end = &mt('none');
                   3299:         } else {
                   3300:             $end = &Apache::lonlocal::locallocaltime($end);
                   3301:         }
                   3302:         if (!defined($section) || ($section eq '')) {
1.51      raeburn  3303:             $section = '&nbsp;';
1.14      raeburn  3304:         }
                   3305:         if (!defined($uid) || ($uid eq '')) {
1.51      raeburn  3306:             $uid = '&nbsp;';
1.14      raeburn  3307:         }
1.51      raeburn  3308:         $reply .= &Apache::loncommon::start_data_table_row().' 
                   3309:               <td>'.$uname.'</td>
                   3310:               <td>'.$udom.'</td>
                   3311:               <td>'.$uid.'</td>
                   3312:               <td>'.&Apache::loncommon::plainname($uname,$udom).'</td>
                   3313:               <td>'.$section.'</td>
                   3314:               <td>'.$start.'</td>
                   3315:               <td>'.$end.'</td>
                   3316:               <td>'.$$changes{$chg}.'</td>'."\n".
                   3317:              &Apache::loncommon::end_data_table_row();
1.14      raeburn  3318:     }
1.51      raeburn  3319:     $reply .= &Apache::loncommon::end_data_table();
1.14      raeburn  3320:     return $reply;
                   3321: }
                   3322: 
1.10      raeburn  3323: sub warning_message {
                   3324:     my ($dom,$crs,$caller) = @_;
1.74      raeburn  3325:     my %settings = 
                   3326:         &Apache::lonnet::get('environment',
                   3327:              ['internal.autoadds','internal.autodrops','internal.sectionnums',
                   3328:               'internal.crosslistings','internal.autostart','internal.autoend'],
                   3329:              $dom,$crs);
                   3330:     my ($currend,$currstart,$currsecs,$currxlists,$curradds,$currdrops);
1.10      raeburn  3331:     if ( defined($settings{'internal.autoadds'}) ) {
                   3332:         $curradds = $settings{'internal.autoadds'};
                   3333:     }
                   3334:     if (defined($settings{'internal.autodrops'}) ) {
                   3335:         $currdrops = $settings{'internal.autodrops'};
                   3336:     }
                   3337:     if ( defined($settings{'internal.autostart'}) ) {
                   3338:         $currstart = $settings{'internal.autostart'};
                   3339:     }
                   3340:     if ( defined($settings{'internal.autoend'}) ) {
                   3341:         $currend = $settings{'internal.autoend'};
                   3342:     }
                   3343:     if ( defined($settings{'internal.sectionnums'}) ) {
                   3344:         $currsecs = $settings{'internal.sectionnums'};
                   3345:     }
                   3346:     if ( defined($settings{'internal.crosslistings'}) ) {
                   3347:         $currxlists = $settings{'internal.crosslistings'}
                   3348:     }
1.74      raeburn  3349:     my $warning = '';
1.10      raeburn  3350:     unless ($caller eq 'setdates') {
                   3351:         if ( ($currstart eq '') && ($currend eq '') )  {
1.74      raeburn  3352:             $warning .= '<li>'.
                   3353:                 &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  3354:         }
                   3355:     }
                   3356:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   3357:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
1.74      raeburn  3358:             $warning .= '<li>'.
                   3359:                 &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">').' '.
                   3360:                         &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  3361:         }
                   3362:     }
                   3363:     unless ( $caller eq 'chgsettings') {
                   3364:         if ( (!$curradds) && (!$currdrops) ) {
1.74      raeburn  3365:             $warning .= '<li>'.
1.78      raeburn  3366:                 &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  3367:         }
                   3368:     }
1.74      raeburn  3369:     if ($warning) {
                   3370:         return '<p class="LC_info"><ul>'.$warning.'</ul></p>';
                   3371:     }
                   3372:     return;
1.1       raeburn  3373: }
                   3374: 
1.74      raeburn  3375: sub print_reply {
1.1       raeburn  3376:   my ($r,$response,$caller) = @_;
1.74      raeburn  3377:   $r->print('
                   3378:             <br /><table width="100%" border="0" cellpadding="2" cellspacing="2">
1.1       raeburn  3379:              <tr>
1.74      raeburn  3380:               <td align="left"><b>'.$caller.'</b> - '.&mt('result').'
                   3381:               <br /><br />'.$response.'</td>
1.1       raeburn  3382:              </tr>
                   3383:             </table>
1.74      raeburn  3384:   ');
1.1       raeburn  3385:   return;
                   3386: }
                   3387: 
                   3388: sub setup_date_selectors {
1.85      raeburn  3389:     my ($starttime,$endtime,$action,$readonly) = @_;
                   3390:     my $disabled;
                   3391:     if ($readonly) {
                   3392:         $disabled = 'disabled';
                   3393:     }
1.1       raeburn  3394:     if (! defined($starttime)) {
                   3395:         $starttime = time;
1.14      raeburn  3396:         if ($action eq 'setdates') {
1.23      albertel 3397:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  3398:                             '.default_enrollment_start_date'})) {
1.23      albertel 3399:                 $starttime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  3400:                                   '.default_enrollment_start_date'};
1.14      raeburn  3401:             }
1.1       raeburn  3402:         }
                   3403:     }
                   3404:     if (! defined($endtime)) {
                   3405:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  3406:         if ($action eq 'setdates') {
1.23      albertel 3407:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  3408:                             '.default_enrollment_end_date'})) {
1.23      albertel 3409:                 $endtime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  3410:                                 '.default_enrollment_end_date'};
1.14      raeburn  3411:             }
1.1       raeburn  3412:         }
                   3413:     }
                   3414:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   3415:                                                             'startdate',
1.85      raeburn  3416:                                                             $starttime,'','',$disabled);
1.1       raeburn  3417:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   3418:                                                           'enddate',
1.85      raeburn  3419:                                                           $endtime,'','',$disabled);
1.1       raeburn  3420:     return ($startdateform,$enddateform);
                   3421: }
                   3422: 
                   3423: sub get_dates_from_form {
1.74      raeburn  3424:     my ($startdate,$enddate);
1.14      raeburn  3425:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   3426:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.23      albertel 3427:     if ( exists ($env{'form.no_end_date'}) ) {
1.1       raeburn  3428:         $enddate = 0;
                   3429:     }
                   3430:     return ($startdate,$enddate);
                   3431: }
                   3432: 
                   3433: sub date_setting_table {
1.85      raeburn  3434:     my ($starttime,$endtime,$action,$readonly) = @_;
                   3435:     my $disabled;
                   3436:     if ($readonly) {
                   3437:         $disabled = ' disabled="disabled"';
                   3438:     }
1.74      raeburn  3439:     my ($startform,$endform) = 
1.85      raeburn  3440:         &setup_date_selectors($starttime,$endtime,$action,$readonly);
1.74      raeburn  3441:     my $perpetual = '<span class="LC_nobreak"><label>'.
                   3442:                     '<input type="checkbox" name="no_end_date"';
                   3443:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || 
                   3444:         (($action eq 'setaccess' || $action eq 'updatenow') && 
                   3445:          ($endtime eq '' || $endtime == 0)) ) {
                   3446:         $perpetual .= ' checked="checked"';
                   3447:     }
1.85      raeburn  3448:     $perpetual.= $disabled.' /> '.&mt('no end date').'</label></span>';
1.74      raeburn  3449:     my $start_table = "<table>\n".
                   3450:                       '<tr><td align="right">'.&mt('Starting Date').'</td>'.
                   3451:                       '<td>'.$startform.'</td>'.
                   3452:                       '<td>&nbsp;</td>'."</tr>\n".
                   3453:                       "</table>";
                   3454:     my $end_table = "<table>\n".
                   3455:                     '<tr><td align="right">'.&mt('Ending Date').'</td>'.
                   3456:                     '<td>'.$endform.'</td>'.
                   3457:                     '<td>'.$perpetual.'</td>'."</tr>\n".
                   3458:                     "</table>\n";
1.1       raeburn  3459:     return ($start_table, $end_table);
                   3460: }
                   3461: 
1.42      raeburn  3462: sub validate_lcsec {
                   3463:     my ($curr_groups,$lcsec) = @_;
                   3464:     if (($lcsec eq 'all') || ($lcsec eq 'none')) {
                   3465:         return 'reserved';
                   3466:     } else {
                   3467:         if (exists($$curr_groups{$lcsec})) {
                   3468:             return 'group'; 
                   3469:         }
                   3470:     }
                   3471:     return 'ok';
                   3472: }
                   3473: 
1.48      albertel 3474: sub user_is_courseowner {
                   3475:     my ($courseowner) = @_;
                   3476:     my $user;
                   3477:     if ($courseowner =~ /^[^:]+:[^:]+$/) {
                   3478: 	$user = $env{'user.name'}.':'.$env{'user.domain'};
                   3479:     } else {
                   3480: 	$user = $env{'user.name'};
                   3481:     }
                   3482:     return ($user eq $courseowner);
                   3483: }
1.74      raeburn  3484: 
                   3485: sub get_task_text {
1.85      raeburn  3486:     my ($permref) = @_;
                   3487:     my %tasklong =
1.74      raeburn  3488:         &Apache::lonlocal::texthash(
1.85      raeburn  3489:            information   => 'Task information',
                   3490:            chgsettings   => 'Automated adds/drops',
                   3491:            chgfailsafe   => 'Change zero enrollment failsafe',
                   3492:            setdates      => 'Change enrollment dates',
                   3493:            setaccess     => 'Change access dates',
                   3494:            notify        => 'Notification of changes',
                   3495:            crosslist     => 'Change crosslistings',
                   3496:            sections      => 'Section settings',
                   3497:            photos        => 'Student photo settings',
                   3498:            updatephotos  => 'Update student photos',
                   3499:            updatenow     => 'Update roster now',
                   3500:            newcross      => 'Add crosslistings',
                   3501:            newsections   => 'Add sections',
                   3502:            viewclass     => 'View students and change type',
1.74      raeburn  3503:     );
                   3504: 
1.85      raeburn  3505:     my %tasktitle =
1.74      raeburn  3506:         &Apache::lonlocal::texthash(
1.85      raeburn  3507:            chgsettings  => 'Changes to nightly automated enrollments',
                   3508:            chgfailsafe  => 'Changes to failsafe protection for data retrieval problems',
                   3509:            setdates     => 'Changes to first and/or last automated enrollment dates',
                   3510:            setaccess    => 'Changes to default start and/or end dates for student access',
                   3511:            notify       => 'Notification of enrollment changes',
                   3512:            crosslist    => 'Changes to crosslistings',
                   3513:            sections     => 'Changes to section settings',
                   3514:            photos       => 'Student photo settings',
                   3515:            updatephotos => 'Update student photos',
                   3516:            updatenow => "Immediate course roster update",
                   3517:            newcross => "Adding new crosslisted courses",
                   3518:            newsections => "Adding new course sections",
                   3519:            viewclass => "Viewing class roster and enrollment type"
1.74      raeburn  3520:     );
1.85      raeburn  3521: 
                   3522:     if ((ref($permref) eq 'HASH') && (!$permref->{'edit'})) {
                   3523:         $tasklong{'chgfailsafe'} = &mt('Zero enrollment failsafe');
                   3524:         $tasklong{'setdates'}    = &mt('Enrollment dates');
                   3525:         $tasklong{'setaccess'}   = &mt('Access dates');
                   3526:         $tasklong{'crosslist'}   = &mt('Crosslistings');
                   3527:         $tasklong{'viewclass'}   = &mt('View students and type');
                   3528:     }
1.74      raeburn  3529:     return (\%tasklong,\%tasktitle);
                   3530: }
1.85      raeburn  3531: 
                   3532: sub check_permission {
                   3533:     my ($permref) = @_;
                   3534:     return unless (ref($permref) eq 'HASH');
                   3535:     my $hasaccess;
                   3536:     if ($env{'request.course.id'}) {
                   3537:         foreach my $priv ('cst','vpa','vcl') {
                   3538:             my ($allowed,$section);
                   3539:             if (&Apache::lonnet::allowed($priv,$env{'request.course.id'})) {
                   3540:                 $allowed = 1;
                   3541:             } elsif ($env{'request.course.sec'} ne '') {
                   3542:                 if (&Apache::lonnet::allowed($priv,$env{'request.course.id'}.'/'.
                   3543:                                                    $env{'request.course.sec'})) {
                   3544:                     $allowed = 1;
                   3545:                     $section = $env{'request.course.sec'};
                   3546:                 }
                   3547:             }
                   3548:             if ($allowed) {
                   3549:                 $hasaccess = 1;
                   3550:                 if ($priv eq 'cst') {
                   3551:                     if ($section ne '') {
                   3552:                         $permref->{'edit_section'} = $section;
                   3553:                     } else {
                   3554:                         $permref->{'edit'} = 1;
                   3555:                     }
                   3556:                 } elsif ($priv eq 'vpa') {
                   3557:                     if ($section ne '') {
                   3558:                         $permref->{'view_section'} = $section;
                   3559:                     } else {
                   3560:                         $permref->{'view'} = 1;
                   3561:                     }
                   3562:                 } elsif ($priv eq 'vcl') {
                   3563:                     if ($section ne '') {
                   3564:                         $permref->{'show_section'} = $section;
                   3565:                     } else {
                   3566:                         $permref->{'show'} = 1;
                   3567:                     }
                   3568:                 }
                   3569:             }
                   3570:         }
                   3571:     }
                   3572:     return $hasaccess;
                   3573: }
                   3574: 
1.48      albertel 3575:     
1.1       raeburn  3576: ###################################################################
                   3577: sub handler {
                   3578:     my $r = shift;
                   3579:     if ($r->header_only) {
1.22      albertel 3580: 	&Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3581:         $r->send_http_header;
                   3582:         return OK;
                   3583:     }
1.74      raeburn  3584:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   3585:                                             ['action','state']);
1.85      raeburn  3586:     my %permhash;
1.1       raeburn  3587:     #  Needs to be in a course
1.85      raeburn  3588:     if (!($env{'request.course.fn'})) {
                   3589:         # Not in a course
                   3590:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot display automated enrollment";
1.34      raeburn  3591:         return HTTP_NOT_ACCEPTABLE;
1.85      raeburn  3592:     } elsif (!&check_permission(\%permhash)) {
                   3593:         # Not allowed to modify students, view settings, or view classlist.
                   3594:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot display automated enrollment";
                   3595:         return HTTP_NOT_ACCEPTABLE; 
1.1       raeburn  3596:     }
                   3597:     # Start page
1.22      albertel 3598:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3599:     $r->send_http_header;
                   3600: 
1.74      raeburn  3601:     my @tasks = ('information','chgsettings','setdates','setaccess','notify','crosslist',
1.84      raeburn  3602:                  'sections','photos','updatenow','updatephotos','viewclass','chgfailsafe');
1.74      raeburn  3603:  
1.85      raeburn  3604:     my ($tasklong,$tasktitle) = &get_task_text(\%permhash);
1.74      raeburn  3605:     my $realm;
1.23      albertel 3606:     if ( exists($env{'request.course.id'}) ) {
1.74      raeburn  3607:         $realm=$env{'course.'.$env{'request.course.id'}.'.description'};
1.1       raeburn  3608:     }
                   3609:     unless ($realm) { $realm='&nbsp;'; }
1.23      albertel 3610:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3611:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.85      raeburn  3612: 
1.1       raeburn  3613:     #
                   3614:     # Main switch on form.action and form.state, as appropriate
                   3615:     #
                   3616: 
                   3617:     my $action = "information";
1.23      albertel 3618:     if ( exists($env{'form.action'}) ) {
                   3619:         $action = $env{'form.action'};
1.1       raeburn  3620:     }
                   3621:     my $state = "choose";
                   3622: 
1.23      albertel 3623:     if ( exists($env{'form.state'}) ) {
                   3624:         $state = $env{'form.state'};
1.1       raeburn  3625:     }
                   3626: 
                   3627:     if ($action eq "information") {
1.85      raeburn  3628:         $r->print(&header($action,\%permhash));
1.1       raeburn  3629:     } else {
                   3630:         if ($state eq "choose") {
1.85      raeburn  3631:             $r->print(&choose_header($action,\%permhash));
1.1       raeburn  3632:         } else {
                   3633:             if ($action eq "crosslist") {
1.23      albertel 3634:                 if ( exists($env{'form.numcross'}) ) {
                   3635:                     if ( $env{'form.numcross'} > 0 ) {
1.85      raeburn  3636:                         $r->print(&choose_header($action,\%permhash));
1.1       raeburn  3637:                     } else {
1.85      raeburn  3638:                         $r->print(&header($action,\%permhash));
1.1       raeburn  3639:                     }
                   3640:                 } else {
1.85      raeburn  3641:                     $r->print(&header(undef,\%permhash));
1.1       raeburn  3642:                 }
                   3643:             } elsif ($action eq "sections") {
1.23      albertel 3644:                 if ( exists($env{'form.numsec'}) ) {
                   3645:                     if ( $env{'form.numsec'} > 0 ) {
1.85      raeburn  3646:                         $r->print(&choose_header($action,\%permhash));
1.1       raeburn  3647:                     } else {
1.85      raeburn  3648:                         $r->print(&header($action,\%permhash));
1.1       raeburn  3649:                     }
                   3650:                 } else {
1.85      raeburn  3651:                     $r->print(&header($action,\%permhash));
1.1       raeburn  3652:                 }
                   3653:             } else {
1.85      raeburn  3654:                 $r->print(&header($action,\%permhash));
1.1       raeburn  3655:             }
                   3656:         }
                   3657:     }
1.12      raeburn  3658: 
1.1       raeburn  3659:     my $reply = 0;
                   3660:     unless ($state eq "choose") { $reply = 1; }
                   3661: 
1.74      raeburn  3662:     &print_navmenu($r,\@tasks,$tasklong,$action,$state);
                   3663: 
1.1       raeburn  3664:     if (($state eq "choose") || ($action eq "information")) {
1.85      raeburn  3665:         &print_main_frame($r,$realm,$dom,$crs,$tasktitle,\%permhash);
                   3666:     } elsif (($action eq "chgsettings") && ($permhash{'edit'})) {
1.74      raeburn  3667:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3668:     } elsif (($action eq "chgfailsafe") && ($permhash{'edit'})) {
1.84      raeburn  3669:         &print_chgfailsafe_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3670:     } elsif (($action eq "setdates") && ($permhash{'edit'})) {
1.74      raeburn  3671:         &print_setdates_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3672:     } elsif (($action eq "setaccess") && ($permhash{'edit'})) {
1.74      raeburn  3673:         &print_setaccess_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3674:     } elsif (($action eq "notify") && ($permhash{'edit'})) {
1.74      raeburn  3675:         &print_notify_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3676:     } elsif (($action eq "sections") && ($permhash{'edit'})) {
1.74      raeburn  3677:         &print_sections_menu($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3678:     } elsif (($action eq "crosslist") && ($permhash{'edit'})) {
1.74      raeburn  3679:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3680:     } elsif (($action eq "updatenow") && ($permhash{'edit'})) {
1.74      raeburn  3681:         &print_update_result($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3682:     } elsif (($action eq "photos") && ($permhash{'edit'})) {
1.34      raeburn  3683:         if ($state eq "photoupdate") {
1.74      raeburn  3684:             &print_photoupdate_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3685:         } else {
1.74      raeburn  3686:             &photo_permission($r,$realm,$dom,$crs,$action,$tasktitle);
1.34      raeburn  3687:         }
1.85      raeburn  3688:     } elsif (($action eq "updatephotos") && ($permhash{'edit'})) {
1.74      raeburn  3689:         &print_photoupdate_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3690:     } elsif (($action eq "newcross") && ($permhash{'edit'})) {
1.74      raeburn  3691:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,$tasktitle);    
1.85      raeburn  3692:     } elsif (($action eq "newsections") && ($permhash{'edit'})) {
1.74      raeburn  3693:         &print_sections_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.85      raeburn  3694:     } elsif (($action eq "viewclass") && ($permhash{'edit'})) {
1.74      raeburn  3695:         &print_viewclass_response($r,$realm,$dom,$crs,$action,$tasktitle);
1.1       raeburn  3696:     }
                   3697:     &print_doc_base($r);  
                   3698:     return OK;
                   3699: }
                   3700: ###################################################################
                   3701: 1;

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