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

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

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