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

1.4       albertel    1: # automated enrollment configuration handler
1.68    ! raeburn     2: # $Id: lonpopulate.pm,v 1.67 2009/11/24 14:26:15 wenzelju 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) {
                    695:               $r->print(&mt("Uncheck the checkbox(es) to terminate notification for people currently informed of roster changes from the nightly enrollment update.<br />"));
                    696:          }
                    697:          if ((@ccs + @showdom) > $notifycount) {
                    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 />"));
                    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.52      raeburn  1330:          'ncds'  => 'changing default start and end access dates will affect <b>future enrollments</b> and also <b>currently inactive</b> students (i.e., those for whom access will begin in the future).',
1.64      droeschl 1331:          'tcha' => 'To change access dates for <b>currently active</b> 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".',
1.14      raeburn  1332:     );
                   1333:     my $dateshow;
                   1334:     if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
1.67      wenzelju 1335:        $dateshow = "<br/>".&mt('Warning').".&nbsp;".$lt{'cuno'}." ";
1.14      raeburn  1336:        if ($action eq 'setaccess') {
                   1337:            $dateshow .= $lt{'ifyo'}."\n";
                   1338:        } elsif ($action eq 'updatenow') {
                   1339:            $dateshow .= $lt{'ifyd'}."\n";
                   1340:        }
                   1341:     } else {
                   1342:         $dateshow = &mt('Currently: default first access').": <b><i>$oldstartshow</i></b>, ".&mt('default last access').": <b><i>$oldendshow</i></b>\n";
                   1343:     }
                   1344:     if ($action eq 'setaccess') {
                   1345:         $r->print(<<ENDONE);
                   1346:                 <form name="enter" method="post"><br/>
                   1347:                 <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   1348:                  <tr>
                   1349:                   <td align="left"><b>$$tasktitleref{$action}</b>
                   1350:                   <br /><br />
                   1351:                    $dateshow
                   1352:                   </td>
                   1353:                  </tr>
                   1354:                 </table>
                   1355: ENDONE
                   1356:     } elsif ($action eq 'updatenow') {
                   1357:         $r->print("
                   1358:                 <br /><br />$dateshow\n");
                   1359:     }
                   1360:     $r->print(<<ENDTWO);
                   1361:                 <table width="100%" border="0" cellpadding="3" cellspacing="3">
                   1362:                  <tr>
                   1363:                   <td align="left" colspan="2">
                   1364:                    <table border="0" cellspacing="0" cellpadding="2">
                   1365:                     <tr>
                   1366:                      <td colspan="3">
                   1367: ENDTWO
                   1368:       if ($action eq 'setaccess') {
                   1369:           $r->print("<i>$lt{'setf'} $lt{'freg'}</i>");
                   1370:       } elsif ($action eq 'updatenow') {
                   1371:           $r->print("<i>$lt{'setf'} $lt{'fnew'}</i>");
                   1372:       }
                   1373:       $r->print(<<ENDTHREE); 
                   1374:                        </td>
                   1375:                       </tr>
                   1376:                       <tr>
                   1377:                        <td>$start_table
                   1378:                        </td>
                   1379:                       </tr>
                   1380:                      </table>
                   1381:                     </td>
                   1382:                    </tr>
                   1383:                    <tr>
                   1384:                     <td align="left" colspan="2">
1.15      albertel 1385:                      <table border="0" cellspacing="0" cellpadding="2">
1.14      raeburn  1386:                       <tr>
                   1387:                        <td colspan="3">
                   1388: ENDTHREE
                   1389:     if ($action eq 'setaccess') {
                   1390:         $r->print("<i>$lt{'setl'} $lt{'freg'}</i>");
                   1391:     } elsif ($action eq 'updatenow') {
                   1392:         $r->print("<i>$lt{'setl'} $lt{'fnew'}</i>");
                   1393:     }
                   1394:     $r->print(<<ENDFOUR); 
                   1395:                        </td>
                   1396:                       </tr>
                   1397:                       <tr>
                   1398:                        <td>$end_table
                   1399:                        </td>
                   1400:                       </tr>
                   1401:                      </table>
                   1402:                     </td>
                   1403:                    </tr>
                   1404: ENDFOUR
                   1405:     if ($action eq 'setaccess') {
                   1406:         $r->print("
                   1407:                    <tr>
                   1408:                     <td colspan=\"2\"><font color=\"#888888\">$lt{'ifad'}</font></td>
                   1409:                    </tr>
1.16      raeburn  1410:                    <tr>
                   1411:                     <td colspan=\"2\">&nbsp;</td>
                   1412:                    </tr>
                   1413:                    <tr>
1.52      raeburn  1414:                     <td colspan=\"2\"><b>".&mt('Note').":</b> ".$lt{'ncds'}.' '.$lt{'tcha'}."</td>
1.16      raeburn  1415:                    </tr>
1.14      raeburn  1416:                   </table>
                   1417:         ");
                   1418:     } elsif ($action eq 'updatenow') {
                   1419:         $r->print("
                   1420:                    </tr>
                   1421:                   </table>
                   1422:         ");
                   1423:     }
                   1424: }
                   1425: 
1.1       raeburn  1426: ###############################################################
                   1427: sub print_doc_base {
1.41      albertel 1428:     my ($r) = @_;
1.15      albertel 1429:     $r->print(<<ENDBASE);
1.1       raeburn  1430:   </td>
                   1431:  </tr>
                   1432: </table>
1.41      albertel 1433: <br />
1.1       raeburn  1434: ENDBASE
1.41      albertel 1435:     $r->print(&Apache::loncommon::end_page());
1.1       raeburn  1436: }
                   1437:  
                   1438: ###################################################################
                   1439: sub print_chgsettings_response {
1.15      albertel 1440:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1441:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
                   1442:     my $currend = '';
                   1443:     my $currstart = '';
                   1444:     my $currsecs = '';
                   1445:     my $currxlists = '';
                   1446:     my $curradds = '';
                   1447:     my $currdrops = '';
                   1448:     if ( defined($settings{'internal.autoadds'}) ) {
                   1449: 	$curradds = $settings{'internal.autoadds'};
                   1450:     }
                   1451:     if ( defined($settings{'internal.autodrops'}) ) {
                   1452: 	$currdrops = $settings{'internal.autodrops'};
                   1453:     }
                   1454:     if ( defined($settings{'internal.autostart'}) ) {
                   1455: 	$currstart = $settings{'internal.autostart'};
                   1456:     }
                   1457:     if ( defined($settings{'internal.autoend'}) ) {
                   1458: 	$currend = $settings{'internal.autoend'};
                   1459:     }
                   1460:     if ( defined($settings{'internal.sectionnums'}) ) {
                   1461: 	$currsecs = $settings{'internal.sectionnums'};
                   1462:     }
                   1463:     if ( defined($settings{'internal.crosslistings'}) ) {
                   1464: 	$currxlists = $settings{'internal.crosslistings'}
                   1465:     }
                   1466:     my $autoadds = '';
                   1467:     my $autodrops = '';
1.1       raeburn  1468: 
1.23      albertel 1469:     if ( exists($env{'form.autoadds'}) ) {
                   1470: 	$autoadds=$env{'form.autoadds'};
1.15      albertel 1471:     }
1.23      albertel 1472:     if ( exists($env{'form.autodrops'}) ) {
                   1473: 	$autodrops=$env{'form.autodrops'};
1.15      albertel 1474:     }
                   1475: 
                   1476:     my $response = "";
                   1477:     my $warning = "";
                   1478:     my $warn_prefix = "";
                   1479:     my $warn_suffix = "";
                   1480:     my $warnfiller = "";
                   1481:     my %cenv = ('internal.autoadds' => $autoadds,
                   1482: 		'internal.autodrops' => $autodrops);
                   1483:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1484:     if ($reply !~ /^ok$/) {
                   1485: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1486:     } else {
                   1487: 	if ($autoadds) {
                   1488: 	    if ($curradds) {
                   1489: 		$response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
                   1490: 	    } else {
                   1491: 		$response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
                   1492: 	    }
                   1493: 	} else {
                   1494: 	    if ($curradds) {
                   1495: 		$response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
                   1496: 	    } else {
                   1497: 		$response = "Nightly additions based on classlist changes still <b>disabled</b><br/>";
                   1498: 	    }
                   1499: 	}
                   1500: 	if ($autodrops) {
                   1501: 	    if ($currdrops) {
1.39      albertel 1502: 		$response .= "Nightly removals based on classlist changes still <b>enabled</b><br />";
1.15      albertel 1503: 	    } else {
                   1504: 		$response .= "Nightly removals based on classlist changes now <b>enabled</b><br/>";
                   1505: 	    }
                   1506: 	} else {
                   1507: 	    if ($currdrops) {
1.39      albertel 1508: 		$response .= "Nightly removals based on classlist changes now <b>disabled</b><br />";
1.15      albertel 1509: 	    } else {
                   1510: 		$response .= "Nightly removals based on classlist changes still <b>disabled</b>";
                   1511: 	    }
                   1512: 	}
                   1513: 	if ($autoadds || $autodrops) {
                   1514: 	    $warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 1515: 	    $warn_prefix = "<br/><b>Warning</b>. Although you indicated that nightly ";
1.15      albertel 1516: 	    $warn_suffix = " should be enabled, additional action is required.<br/>";
                   1517: 	}
                   1518: 	if ($autoadds) {
                   1519: 	    if ($autodrops) {
                   1520: 		$warnfiller = "adds and drops";
                   1521: 	    } else {
                   1522: 		$warnfiller = "adds";
                   1523: 	    }
                   1524: 	} else {
                   1525: 	    if ($autodrops) {
                   1526: 		$warnfiller = "drops";
                   1527: 	    }
                   1528: 	}
                   1529: 	unless ($warning eq '') {
                   1530: 	    $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
                   1531: 	}
                   1532:     }
                   1533:     &print_reply($r,$response,$$tasktitleref{$action});
                   1534:     return;
1.1       raeburn  1535: }
                   1536: 
                   1537: sub print_setdates_response {
1.15      albertel 1538:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1539:     my %settings = &Apache::lonnet::get('environment',['internal.autostart','internal.autoend'],$dom,$crs);
                   1540:     my $currstart = $settings{'internal.autostart'};
                   1541:     my $currend = $settings{'internal.autoend'};
                   1542:     my $response = '';
1.19      raeburn  1543:     my $showstart = '';
1.15      albertel 1544:     my $showend = '';
                   1545:     my $warning = '';
                   1546:     my $warn_prefix = '';
1.19      raeburn  1547:     my ($autostart,$autoend) = &get_dates_from_form();
                   1548:     if ( ($autostart eq '') || ($autoend eq '') ) {
                   1549:         $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1550:     } elsif (($autoend > 0) && ($autoend <= $autostart)) {
                   1551:         $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";
                   1552:     } else {       
                   1553:         $showstart = &Apache::lonlocal::locallocaltime($autostart);
                   1554:         if ($autoend) {
                   1555: 	    $showend = &Apache::lonlocal::locallocaltime($autoend);
                   1556:         } else {
                   1557: 	    $showend = "'No end date'";
                   1558:         } 
1.15      albertel 1559: 
1.19      raeburn  1560:         my %cenv = ('internal.autostart' => $autostart,
                   1561:   		    'internal.autoend' => $autoend);
                   1562:         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1563:         if ($reply !~ /^ok$/) {
                   1564: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1565:         } else {
                   1566: 	    if ($currstart == $autostart) {
                   1567: 	        $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
                   1568: 	    } else {
                   1569: 	        $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
                   1570: 	    } 
                   1571: 	    if ($currend == $autoend) {
                   1572: 	        $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
                   1573: 	    } else {
                   1574: 	        $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
                   1575: 	    }
1.1       raeburn  1576:  
1.14      raeburn  1577: # 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  1578: 
1.19      raeburn  1579: 	    my $rosterupdated = 0;
                   1580: 	    my $firstaccess = "";
                   1581: 	    my $nextupdate = "";
                   1582: 	    my $lastupdate = "";
                   1583: 
                   1584: 	    my $nowstamp = time;
                   1585: 	    my @date_list=localtime(time);
                   1586: 	    my $cur_year = $date_list[5];
                   1587: 	    my $curday = $date_list[3];
                   1588: 	    my $curmonth = $date_list[4];
                   1589: 	    my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1590: 	    my $nextmidnt = 86400 + $lastmidnt;
                   1591: 
                   1592: 	    my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
                   1593: 	    my $lastupdate = $todayupdate - 86400;
                   1594: 	    if ($nowstamp < $todayupdate) {
                   1595: 	      $nextupdate = "today";
1.15      albertel 1596: 	    } else {
1.19      raeburn  1597: 	      $nextupdate = "tomorrow";
1.15      albertel 1598: 	    }
1.19      raeburn  1599: 	    if ($currstart < $lastupdate) {
                   1600: 	        $rosterupdated = 1;
1.15      albertel 1601: 	    }
1.19      raeburn  1602: 	    if ($autostart < $nextmidnt ) {
                   1603: 	        if ( $autostart >= $lastmidnt) {
                   1604: 		    $firstaccess = "today";
                   1605: 	        } else {
                   1606: 	  	    $firstaccess = "a date prior to today";
                   1607: 	        }
                   1608: 	        if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
1.39      albertel 1609: 		    $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  1610: 	        }
                   1611: 	    }
                   1612: 	    $warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 1613: 	    $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  1614: 	    unless ($warning eq '') {
                   1615: 	        $response .= $warn_prefix.$warning;
                   1616: 	    }
                   1617:         }
1.15      albertel 1618:     }
                   1619:     &print_reply($r,$response,$$tasktitleref{$action});
                   1620:     return;
1.1       raeburn  1621: }
                   1622: 
1.14      raeburn  1623: sub print_setaccess_response {
1.15      albertel 1624:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1625:     my %settings = &Apache::lonnet::get('environment',['default_enrollment_start_date','default_enrollment_end_date','internal.autostart'],$dom,$crs);
                   1626:     my $currstart = $settings{'default_enrollment_start_date'};
                   1627:     my $currend = $settings{'default_enrollment_end_date'};
                   1628:     my $autostart = $settings{'internal.autostart'};
                   1629:     my $response = '';
                   1630:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.19      raeburn  1631:     if (($startaccess eq '') || ($endaccess eq '')) {
                   1632:         $response = "There was a problem processing your requested changes. The default
                   1633: start and end access dates for this course have been left unchanged.<br/>";
                   1634:     } elsif (($endaccess > 0) && ($endaccess <= $startaccess)) {
                   1635:         $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 1636:     } else {
1.19      raeburn  1637:         my $showstart = &Apache::lonlocal::locallocaltime($startaccess);
                   1638:         my $showend = '';
                   1639:         my $warning = '';
                   1640:         my $warn_prefix = '';
                   1641:         if ($endaccess) {
                   1642: 	    $showend = &Apache::lonlocal::locallocaltime($endaccess);
                   1643:         } else {
                   1644: 	    $showend = "'No end date'";
                   1645:         }
1.15      albertel 1646: 
1.19      raeburn  1647:         my %cenv = ('default_enrollment_start_date' => $startaccess,
1.15      albertel 1648: 		'default_enrollment_end_date' => $endaccess);
1.19      raeburn  1649:         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1650:         if ($reply !~ /^ok$/) {
                   1651: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1652:         } else {
                   1653: 	    if ($currstart == $startaccess) {
1.52      raeburn  1654: 	        $response = "The first access date for students being added via automated enrollment has been left unchanged as $showstart.<br/>";
1.19      raeburn  1655: 	    } else {
1.52      raeburn  1656: 	        $response = "The first access date for students being added via automated enrollment has been changed to $showstart.<br/>";
1.19      raeburn  1657: 	    }
                   1658: 	    if ($currend == $endaccess) {
1.52      raeburn  1659: 	        $response .= "The last access date for students being added via automated enrollment has been left unchanged as $showend.<br/>";
1.19      raeburn  1660: 	    } else {
1.52      raeburn  1661: 	        $response .= "The last access date for students being added via automated enrollment has been changed to $showend.<br/>";
1.19      raeburn  1662: 	    }
1.64      droeschl 1663:             $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 1664: 	
1.14      raeburn  1665: # 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 1666: 	
1.19      raeburn  1667: 	    my $accessgiven= 0;
                   1668: 	    my $firstaccess = "";
                   1669: 	    my $nextupdate = "";
                   1670: 	    my $lastupdate = "";
                   1671: 
                   1672: 	    my $nowstamp = time;
                   1673: 	    my @date_list=localtime(time);
                   1674: 	    my $cur_year = $date_list[5];
                   1675: 	    my $curday = $date_list[3];
                   1676: 	    my $curmonth = $date_list[4];
                   1677: 	    my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
                   1678: 	    my $nextmidnt = 86400 + $lastmidnt;
                   1679: 
                   1680: 	    my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
                   1681: 	    my $tomorrowupdate = $todayupdate + 86400;
                   1682: 	    my $lastupdate = $todayupdate - 86400;
                   1683: 
                   1684: 	    if ($autostart < $nextmidnt) {
                   1685: 	        if ($nowstamp < $todayupdate) {
                   1686: 		    $nextupdate = "at 1.30 am today";
                   1687: 	        } else {
                   1688: 		    $nextupdate = "at 1.30 am tomorrow";
                   1689: 	        }
1.15      albertel 1690: 	    } else {
1.19      raeburn  1691: 	        my @enrollstart = localtime($autostart);
                   1692: 	        $nextupdate = timelocal(0,30,1,$enrollstart[3],$enrollstart[4],$enrollstart[5]);
                   1693: 	        unless (($enrollstart[2] < 1) || ($enrollstart[2] == 1 && $enrollstart[1] <=30))  {
                   1694: 		    $nextupdate += 86400; 
                   1695: 	        }
                   1696: 	        $nextupdate = &Apache::lonlocal::locallocaltime($nextupdate);
                   1697: 	    }
                   1698: 	    if (($currstart < $lastupdate) && ($autostart < $lastupdate)) {
                   1699: 	        $accessgiven = 1;
                   1700: 	    }
                   1701: 	    if ($startaccess < $nextmidnt ) {
                   1702: 	        if ( $startaccess >= $lastmidnt) {
                   1703: 	    	    $firstaccess = "today";
                   1704: 	        } else {
                   1705: 		    $firstaccess = "a date prior to today";
                   1706: 	        }
                   1707: 	        if (($nowstamp >= $startaccess) && ($accessgiven == 0)) {
1.39      albertel 1708: 		    $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  1709: 	        }
1.15      albertel 1710: 	    }
1.19      raeburn  1711: 	    $warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 1712: 	    $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  1713: 	    unless ($warning eq '') {
                   1714: 	        $response .= $warn_prefix.$warning;
1.15      albertel 1715: 	    }
1.19      raeburn  1716:         }
1.15      albertel 1717:     }
                   1718:     &print_reply($r,$response,$$tasktitleref{$action});
                   1719:     return;
1.14      raeburn  1720: }
                   1721: 
1.1       raeburn  1722: sub print_notify_response {
1.15      albertel 1723:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.1       raeburn  1724: 
                   1725: # Get current settings
1.15      albertel 1726:     my %settings = &Apache::lonnet::get('environment',['internal.notifylist','internal.coursecode'],$dom,$crs);
                   1727:     my $notifylist = $settings{'internal.notifylist'};
                   1728:     my $coursecode = $settings{'internal.coursecode'};
1.28      albertel 1729:     my @currpeople = split(/,/,$notifylist);
1.15      albertel 1730:     my $notify = 0;
                   1731:     my @people = ();
                   1732:     my $peoplestr = "";
                   1733:     my $response = "";
                   1734:     my $noprocess = 0;
1.1       raeburn  1735: 
1.15      albertel 1736:     my $currcount = 0;
                   1737:     foreach  (@currpeople) {
                   1738: 	unless ($_ eq '') { $currcount ++; } 
                   1739:     }
                   1740: 
1.23      albertel 1741:     if ( exists($env{'form.notify'}) ) {
                   1742: 	$notify=$env{'form.notify'};
1.15      albertel 1743:     }
1.23      albertel 1744:     if ( exists($env{'form.notifyshow'}) ) {
                   1745: 	my $notifyshow = $env{'form.notifyshow'};
1.15      albertel 1746: 	for (my $i=0; $i<$notifyshow; $i++) {
1.23      albertel 1747: 	    if ( exists($env{"form.note_$i"}) ) {
                   1748: 		if ( exists($env{"form.notifyname_$i"}) ) {
                   1749: 		    unless ( $env{"form.notifyname_$i"} eq '' ) {
                   1750: 			push @people, $env{"form.notifyname_$i"};
1.15      albertel 1751: 		    }
                   1752: 		}
                   1753: 	    }
                   1754: 	}
                   1755: 	if ($notify) { $peoplestr = join(",",@people); }
                   1756:     } else {
                   1757: 	if ($notify) {
                   1758: 	    if ($currcount) {
                   1759: 		$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/>.";
                   1760: 		$peoplestr = $notifylist;
                   1761: 		@people = @currpeople;
                   1762: 		$noprocess = 1;
                   1763: 	    }
                   1764: 	}
                   1765:     }
                   1766:     unless ($noprocess == 1) {
                   1767: 	my %cenv = ('internal.notifylist' => $peoplestr);
                   1768: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1769: 	if ($reply !~ /^ok$/) {
                   1770: 	    $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
                   1771: 	} else {
                   1772: 	    if ($notify) {
                   1773: 		if (@people) {
                   1774: 		    if ($currcount) {
                   1775: 			$response .= "Notification of enrollment changes still <b>enabled</b><br/>";
                   1776: 		    } else {
                   1777: 			$response .= "Notification of enrollment changes now <b>enabled</b><br/>";
                   1778: 		    }
                   1779: 		    $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";
                   1780: 		    foreach my $person (@people) {
                   1781: 			$response .= "<li>$person</li>\n";
                   1782: 		    }
                   1783: 		    $response .= "</ul>\n";
                   1784: 		} else {
1.44      raeburn  1785: 		    $response = &mt('Notification of enrollment changes was <b> not enabled</b> as no [_1]s were selected as recipients.<br/>',&Apache::lonnet::plaintext('cc'));
1.15      albertel 1786: 		}
                   1787: 	    } else {
                   1788: 		if ($currcount) {
                   1789: 		    $response = "Notification of enrollment changes now <b>disabled</b><br/>";
                   1790: 		} else {
                   1791: 		    $response = "Notification of enrollment changes still <b>disabled</b><br/>";
                   1792: 		}
                   1793: 	    }
                   1794: 	}
                   1795:     }
                   1796:     &print_reply($r,$response,$$tasktitleref{$action});
                   1797:     return;
1.1       raeburn  1798: }
                   1799: 
                   1800: sub print_crosslistings_menu () {
1.15      albertel 1801:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   1802:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
                   1803:     my @currxlists = ();
                   1804:     my @xlists = ();
                   1805:     my $crosscount = 0;
                   1806:     my $removecount = 0;
                   1807:     my $xliststr = '';
                   1808:     my $response = '';
                   1809:     my $coursecode = $settings{'internal.coursecode'};
1.28      albertel 1810:     if ($settings{'internal.crosslistings'} ne '') {
                   1811: 	@currxlists = split(/,/,$settings{'internal.crosslistings'});
1.15      albertel 1812:     }
                   1813: 
                   1814:     if (@currxlists > 0) {
                   1815: 	for (my $i=0; $i<@currxlists; $i++) {
                   1816: 	    my $xlist = "cross_".$i;
1.42      raeburn  1817: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 1818: 	    if ( exists($env{"form.$xlist"}) ) {
1.15      albertel 1819: 		my $xlistentry = '';
                   1820: 		if ($currxlists[$i] =~ m/^([^:]+)/) {
                   1821: 		    $xlistentry = $1.':';
                   1822: 		}
1.42      raeburn  1823: 		if ( exists($env{"form.$lc_sec"}) ) {
                   1824: 		    $xlistentry .= $env{"form.$lc_sec"};
1.15      albertel 1825: 		}
                   1826: 		push @xlists,$xlistentry;
                   1827: 		$crosscount ++;
                   1828: 	    } else {
                   1829: 		$removecount ++;
                   1830: 	    }
                   1831: 	}
                   1832:     }
1.1       raeburn  1833: 
1.28      albertel 1834:     $xliststr = join(",",@xlists);
                   1835: 
1.15      albertel 1836:     my %cenv = ('internal.crosslistings' => $xliststr);
                   1837:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1838:     if ($reply !~ /^ok$/) {
                   1839: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   1840:     } else {
                   1841: 	if ($removecount > 0) {
                   1842: 	    $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
                   1843: 	}
                   1844: 	if ($crosscount > 0) {
                   1845: 	    $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";
                   1846: 	    foreach (@xlists) {
1.42      raeburn  1847: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1848: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1849: 	    }
                   1850: 	    $response .= "</ul><br/>\n";
                   1851: 	}
                   1852:     }
1.23      albertel 1853:     if ( exists($env{'form.numcross'}) ) {
                   1854: 	my $numcross = $env{'form.numcross'};
1.15      albertel 1855: 	if ($numcross > 0) {
                   1856: 	    my @bgcolors=("#eeeeee","#cccccc");
1.42      raeburn  1857: 	    $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 1858:            <form name="enter" method="post">); #' stupid emacs
1.42      raeburn  1859:            $response .= &Apache::loncommon::start_data_table();
                   1860:            $response .= &Apache::loncommon::start_data_table_row();
                   1861:            $response .= qq(
                   1862:                  <th>Crosslisting</th>
                   1863:                  <th>LON-CAPA section ID</th>
1.15      albertel 1864: 			    );
1.42      raeburn  1865:            $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 1866: 	    for (my $i=0; $i<$numcross; $i++) {
1.42      raeburn  1867:                 $response .= &Apache::loncommon::start_data_table_row();
1.15      albertel 1868: 		$response .= qq(
1.1       raeburn  1869:                  <td><input type="text" size="15" name="newcross_$i" /></td>
1.42      raeburn  1870:                  <td align="right"><input type="text" size="10" name="newlcsec_$i" /></td>
1.15      albertel 1871: 				);
1.42      raeburn  1872:                 $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 1873: 	    }
1.42      raeburn  1874:             $response .= &Apache::loncommon::end_data_table();
                   1875: 	    $response .= qq(
1.1       raeburn  1876:               </td>
                   1877:              </tr>
                   1878:              <tr>
                   1879:               <td align="right">
1.39      albertel 1880:                <input type="button" name="newcross" value="Go" onclick="process('newcross')" />
1.1       raeburn  1881:               </td>
                   1882:              </tr>
                   1883:             </table>
1.39      albertel 1884:             <input type=\"hidden\" name=\"numcross\" value=\"$numcross\" />
                   1885:             <input type=\"hidden\" name=\"action\" value=\"newcross\" />
                   1886:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  1887:             </form>
1.15      albertel 1888: 			      );
                   1889:         }
                   1890:     }
                   1891:     &print_reply($r,$response,$$tasktitleref{$action});
                   1892:     return;
1.1       raeburn  1893: }
                   1894: 
                   1895: sub print_crosslistings_response () {
1.15      albertel 1896:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.68    ! raeburn  1897:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner','internal.co-owners'],$dom,$crs);
1.15      albertel 1898:     my @currxlists = ();
                   1899:     my @xlists = ();
                   1900:     my @allxlists = ();
                   1901:     my @badxlists = ();
                   1902:     my @badowner = ();
1.42      raeburn  1903:     my @reserved = ();
                   1904:     my @matchgroup = ();
1.15      albertel 1905:     my $numcross = 0;
                   1906:     my $xliststr =  $settings{'internal.crosslistings'};
                   1907:     my $coursecode = $settings{'internal.coursecode'};
                   1908:     my $owner = $settings{'internal.courseowner'};
1.68    ! raeburn  1909:     my $coowners = $settings{'internal.co-owners'};
1.15      albertel 1910:     my $response = '';
                   1911:     my $warning = '';
                   1912:     my $warn_prefix = '';
1.1       raeburn  1913: 
1.28      albertel 1914:     if ($xliststr ne '') {
                   1915: 	@allxlists = split(/,/,$xliststr);
1.15      albertel 1916:     }
1.1       raeburn  1917: 
1.23      albertel 1918:     if ( exists($env{'form.numcross'}) ) {
                   1919: 	$numcross = $env{'form.numcross'};
1.15      albertel 1920:     }
1.1       raeburn  1921: 
1.15      albertel 1922:     if ($numcross > 0) {
1.43      raeburn  1923:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 1924: 	for (my $i=0; $i<$numcross; $i++) {
                   1925: 	    my $xl = "newcross_".$i;
1.42      raeburn  1926: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 1927: 	    if ( exists($env{"form.$xl"}) ) {
1.42      raeburn  1928:                 if (exists($env{"form.$lc_sec"})) {
                   1929:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,
                   1930:                                                     $env{"form.$lc_sec"});
                   1931:                     if ($lc_sec_check eq 'reserved') {
                   1932:                         push(@reserved,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1933:                         next;
                   1934:                     } elsif ($lc_sec_check eq 'group') {
                   1935:                         push (@matchgroup,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1936:                         next;
                   1937:                     }
                   1938:                 }
1.15      albertel 1939: 		my $coursecheck = '';
1.23      albertel 1940: 		$coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});
1.15      albertel 1941: 		if ($coursecheck eq 'ok') {
                   1942: 		    my $addcheck = '';
1.68    ! raeburn  1943: 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner,$coowners);
1.15      albertel 1944: 		    if ($addcheck eq 'ok') {
1.42      raeburn  1945: 			push @xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1946: 		    } else {
1.42      raeburn  1947: 			push @badowner,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1948: 		    }
                   1949: 		} else {
1.42      raeburn  1950: 		    push @badxlists, $env{"form.$xl"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 1951: 		}
                   1952: 	    }
                   1953: 	}
                   1954: 	push @allxlists, @xlists;
                   1955:     }
                   1956:     
                   1957:     if (@xlists > 0 ) {
                   1958: 	unless ($xliststr eq '') { $xliststr .= ","; }
1.28      albertel 1959: 	$xliststr .= join(",",@xlists);
                   1960: 
1.15      albertel 1961: 	my %cenv = ('internal.crosslistings' => $xliststr);
                   1962: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1963: 	if ($reply !~ /^ok$/) {
                   1964: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1965: 	} else {
                   1966: 	    $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";
                   1967: 	    foreach (@allxlists) {
1.42      raeburn  1968: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1969: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1970: 	    }
                   1971: 	    $response .= "</ul><br/><br/>\n";
                   1972: 	}
                   1973:     } else {
                   1974: 	if ($xliststr =~ m/:/) {
1.28      albertel 1975: 	    my @oldxlists = (split/,/,$xliststr);
1.15      albertel 1976: 	    $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1977: 	    foreach (@oldxlists) {
1.42      raeburn  1978: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1979: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1980: 	    }
                   1981: 	    $response .= "</ul><br/><br/>\n";
                   1982: 	}
                   1983:     }
                   1984:     if (@badxlists > 0) {
                   1985: 	$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";
                   1986: 	foreach (@badxlists) {
1.42      raeburn  1987: 	    my ($xlist,$lc_sec,$prob) = split/:/,$_;
                   1988: 	    $response .= "<li>$xlist - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 1989: 	}
                   1990: 	$response .= "</ul><br/><br/>\n";
                   1991:     }
                   1992:     
                   1993:     if (@badowner > 0) {
                   1994: 	$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";
                   1995: 	foreach (@badowner) {
1.42      raeburn  1996: 	    my ($xlist,$lc_sec) = split/:/,$_;
                   1997: 	    $response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1998: 	}
                   1999: 	$response .= "</ul><br/><br/>\n";
                   2000:     }
1.42      raeburn  2001:     if (@reserved > 0) {
                   2002:         $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";  
                   2003:         foreach (@reserved) {
                   2004:             my ($xlist,$lc_sec) = split/:/,$_;
                   2005:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2006:         }
                   2007:         $response .= "</ul><br/><br/>\n";
                   2008:     }
                   2009: 
                   2010:     if (@matchgroup > 0) {
                   2011:         $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";
                   2012:         foreach (@matchgroup) {
                   2013:             my ($xlist,$lc_sec) = split/:/,$_;
                   2014:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2015:         }
                   2016:         $response .= "</ul><br/><br/>\n";
                   2017:     }
1.5       raeburn  2018: 
1.15      albertel 2019:     if (@allxlists > 0) {
                   2020: 	$warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 2021: 	$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 2022: 	unless ($warning eq '') {
                   2023: 	    $response .= $warn_prefix.$warning;
                   2024: 	}
                   2025:     }
1.1       raeburn  2026: 
1.15      albertel 2027:     &print_reply($r,$response,$$tasktitleref{$action});
                   2028:     return;
1.1       raeburn  2029: }
                   2030: 
                   2031: sub print_sections_menu () {
1.15      albertel 2032:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.68    ! raeburn  2033:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner','internal.co-owners'],$dom,$crs);
1.15      albertel 2034:     my @currsections = ();
                   2035:     my @sections = ();
                   2036:     my @badowner = ();
                   2037:     my @badsections = ();
                   2038:     my $seccount = 0;
                   2039:     my $removecount = 0;
                   2040:     my $addcount = 0;
                   2041:     my $secstr = '';
                   2042:     my $response = '';
                   2043:     my $warning = "";
                   2044:     my $warn_prefix = "";
                   2045:     my $coursecode = $settings{'internal.coursecode'};
                   2046:     my $owner = $settings{'internal.courseowner'};
1.68    ! raeburn  2047:     my $coowners = $settings{'internal.co-owners'};
1.28      albertel 2048:     if ($settings{'internal.sectionnums'} ne '') {
                   2049: 	@currsections = split(/,/,$settings{'internal.sectionnums'});
1.15      albertel 2050:     }
                   2051:     
1.23      albertel 2052:     if ( exists($env{'form.secshow'}) ) {
                   2053: 	for (my $i=0; $i<$env{'form.secshow'}; $i++) {
1.42      raeburn  2054: 	    my $lc_sec = "loncapasec_".$i;
1.15      albertel 2055: 	    my $secnum = "secnum_".$i;
                   2056: 	    my $sec = "sec_".$i;
1.23      albertel 2057: 	    if ( exists( $env{"form.$sec"} ) ) {
1.15      albertel 2058: 		my $secentry;
1.23      albertel 2059: 		if ( exists( $env{"form.$secnum"} ) ) { 
                   2060: 		    $secentry = $env{"form.$secnum"}.':';
1.15      albertel 2061: 		}
1.42      raeburn  2062: 		if ( exists( $env{"form.$lc_sec"} ) ) {
                   2063: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2064: 		}
1.23      albertel 2065: 		if ( grep/^$env{"form.$secnum"}:/,@currsections) {
1.15      albertel 2066: 		    push @sections, $secentry;
                   2067: 		    $seccount ++;
                   2068: 		} else {
1.23      albertel 2069: 		    my $newsec = $coursecode.$env{"form.$secnum"};
1.15      albertel 2070: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2071: 		    if ($coursecheck eq 'ok') {
1.68    ! raeburn  2072: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner,$coowners);
1.15      albertel 2073: 			if ($addcheck eq 'ok') {
1.42      raeburn  2074: 			    push @sections,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2075: 			    $seccount ++;
                   2076: 			    $addcount ++;
                   2077: 			} else {
1.42      raeburn  2078: 			    push @badowner,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2079: 			}
                   2080: 		    } else {
1.42      raeburn  2081: 			push @badsections, $env{"form.$secnum"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2082: 		    }
                   2083: 		}
                   2084: 	    }
                   2085: 	}
                   2086: 	if (@currsections > 0) {
                   2087: 	    for (my $i=0; $i<@currsections; $i++) {
                   2088: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2089: 		    my $oldsec  = $1;
                   2090: 		    unless (grep/^$oldsec/,@sections) {
                   2091: 			$removecount ++;
                   2092: 		    }
                   2093: 		}
                   2094: 	    }
                   2095: 	}
                   2096:     } elsif (@currsections > 0) {
                   2097: 	for (my $i=0; $i<@currsections; $i++) {
                   2098: 	    my $sec = "sec_".$i;
1.42      raeburn  2099: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 2100: 	    if ( exists($env{"form.$sec"}) ) {
1.15      albertel 2101: 		my $secentry = '';
                   2102: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2103: 		    $secentry = $1;
                   2104: 		}
1.42      raeburn  2105: 		if ( exists($env{"form.$lc_sec"}) ) {
                   2106: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2107: 		}
                   2108: 		push @sections,$secentry;
                   2109: 		$seccount ++;
                   2110: 	    } else {
                   2111: 		$removecount ++;
                   2112: 	    }
                   2113: 	}
                   2114:     }
                   2115:     
1.28      albertel 2116:     $secstr = join(",",@sections);
                   2117: 
1.15      albertel 2118:     my %cenv = ('internal.sectionnums' => $secstr);
                   2119:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2120:     if ($reply !~ /^ok$/) {
                   2121: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   2122:     } else {
                   2123: 	if ($removecount > 0) {
                   2124: 	    $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/>";
                   2125: 	}
                   2126: 	if ($addcount > 0) {
                   2127: 	    $response .= "A total of $addcount sections have been added to the list of
1.6       raeburn  2128: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.15      albertel 2129: 	}
                   2130: 	if ($seccount > 0) { 
                   2131: 	    $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";
                   2132: 	    foreach (@sections) {
1.42      raeburn  2133: 		my ($sec,$lc_sec) = split/:/,$_;
                   2134: 		$response .= "<li>$sec  - ID: $lc_sec</li>\n";
1.15      albertel 2135: 	    }
                   2136: 	    $response .= "</ul><br/>\n";
                   2137: 	}
                   2138:     }
                   2139:     
                   2140:     if (@badsections > 0) {
                   2141: 	$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";
                   2142: 	foreach (@badsections) {
1.42      raeburn  2143: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2144: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2145: 	}
                   2146: 	$response .= "</ul><br/><br/>\n";
                   2147:     }
                   2148:     
                   2149:     if (@badowner > 0) {
                   2150: 	$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";
                   2151: 	foreach (@badowner) {
1.42      raeburn  2152: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2153: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2154: 	}
                   2155: 	$response .= "</ul><br/><br/>\n";
                   2156:     }
                   2157:     
                   2158:     if ($seccount > 0) {
                   2159: 	$warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 2160: 	$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 2161: 	unless ($warning eq '') {
                   2162: 	    $response .= $warn_prefix.$warning;
                   2163: 	}
                   2164:     }
                   2165:     
1.23      albertel 2166:     if ( exists($env{'form.numsec'}) ) {
                   2167: 	my $numsec = $env{'form.numsec'};
1.15      albertel 2168: 	if ($numsec > 0) {
                   2169: 	    my @bgcolors=("#eeeeee","#cccccc");
                   2170: 	    $response .= qq(
1.42      raeburn  2171: 			    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  2172:            <form name="enter" method="post">
                   2173:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   2174:              <tr>
1.42      raeburn  2175:               <td>);
                   2176:             $response .= &Apache::loncommon::start_data_table();
                   2177:             $response .= &Apache::loncommon::start_data_table_row();
                   2178:             $response .= qq(
                   2179:                  <th>Section number</th>
                   2180:                  <th>LON-CAPA section ID</th>
                   2181: 			 );
                   2182:             $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2183: 	    for (my $i=0; $i<$numsec; $i++) {
1.42      raeburn  2184:                 $response .= &Apache::loncommon::start_data_table_row();
1.15      albertel 2185: 		$response .= qq(
1.42      raeburn  2186:                  <td><input type="text" size="10" name="newsec_$i" /></td>
                   2187:                  <td align="right">
                   2188:                    <input type="text" size="10" name="newlcsec_$i" />
                   2189:                  </td>
                   2190: 			     );
                   2191:                 $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2192: 	    }
1.42      raeburn  2193:             $response .= &Apache::loncommon::end_data_table();
                   2194: 	    $response .= qq(
1.1       raeburn  2195:               </td>
                   2196:              </tr>
                   2197:              <tr>
                   2198:               <td align="right">
1.39      albertel 2199:                <input type="button" name="newsections" value="Go" onclick="process('newsections')" />
1.1       raeburn  2200:               </td>
                   2201:              </tr>
                   2202:             </table>
1.39      albertel 2203:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\" />
                   2204:             <input type=\"hidden\" name=\"action\" value=\"newsections\" />
                   2205:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  2206:             </form>
1.15      albertel 2207: 			      );
                   2208: 	}
                   2209:     }
                   2210:     &print_reply($r,$response,$$tasktitleref{$action});
                   2211:     return;
1.1       raeburn  2212: }
                   2213: 
                   2214: sub print_sections_response () {
1.15      albertel 2215:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.68    ! raeburn  2216:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner','internal.co-owners'],$dom,$crs);
1.15      albertel 2217:     my @currsections = ();
                   2218:     my @sections = ();
                   2219:     my @allsections = ();
                   2220:     my @badowner = ();
                   2221:     my @badsections = ();
1.42      raeburn  2222:     my @reserved = ();
                   2223:     my @matchgroup = ();
1.15      albertel 2224:     my $numsec = 0;
                   2225:     my $secstr =  $settings{'internal.sectionnums'};
                   2226:     my $coursecode = $settings{'internal.coursecode'};
                   2227:     my $owner = $settings{'internal.courseowner'};
1.68    ! raeburn  2228:     my $coowners = $settings{'internal.co-owners'};
1.15      albertel 2229:     my $response = '';
                   2230:     my $putreply = '';
                   2231:     my $warning = '';
                   2232:     my $warn_prefix = '';
1.28      albertel 2233:     if ($secstr ne '') {
                   2234: 	@allsections = split(/,/,$secstr);
1.15      albertel 2235:     }
                   2236:     
1.23      albertel 2237:     if ( exists($env{'form.numsec'}) ) {
                   2238: 	$numsec = $env{'form.numsec'};
1.15      albertel 2239:     }
                   2240:     
                   2241:     if ($numsec > 0) {
1.43      raeburn  2242:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 2243: 	for (my $i=0; $i<$numsec; $i++) {
                   2244: 	    my $sec = "newsec_".$i;
1.42      raeburn  2245: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 2246: 	    if ( exists($env{"form.$sec"}) ) {
                   2247: 		unless ( (grep/^$env{"form.$sec"}:/,@allsections) || (grep/^$env{"form.$sec"}:/,@sections) ) {
1.42      raeburn  2248:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,                                                     $env{"form.$lc_sec"});
                   2249:                     if ($lc_sec_check eq 'reserved') {
                   2250:                         push(@reserved,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2251:                         next;
                   2252:                     } elsif ($lc_sec_check eq 'group') {
                   2253:                         push (@matchgroup,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2254:                         next;
                   2255:                     }
1.23      albertel 2256: 		    my $newsec = $coursecode.$env{"form.$sec"};
1.15      albertel 2257: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2258: 		    if ($coursecheck eq 'ok') {
1.68    ! raeburn  2259: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner,$coowners);
1.15      albertel 2260: 			if ($addcheck eq 'ok') {
1.42      raeburn  2261: 			    push @sections,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2262: 			} else {
1.42      raeburn  2263: 			    push @badowner,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2264: 			}
                   2265: 		    } else {
1.42      raeburn  2266: 			push @badsections, $env{"form.$sec"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2267: 		    }
                   2268: 		}
                   2269: 	    }
                   2270: 	}
                   2271: 	push @allsections, @sections;
                   2272:     }
                   2273:     
                   2274:     if (@sections > 0 ) {
                   2275: 	unless ($secstr eq '') { $secstr .= ","; } 
1.28      albertel 2276: 	$secstr .= join(",",@sections);
1.15      albertel 2277: 	my %cenv = ('internal.sectionnums' => $secstr);
                   2278: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2279: 	if ($putreply !~ /^ok$/) {
                   2280: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   2281: 	}
                   2282:     }
                   2283: 
                   2284:     if ($putreply =~ /^ok/) {
                   2285: 	$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";
                   2286: 	foreach (@allsections) {
1.42      raeburn  2287: 	    my ($sec,$lc_sec) = split/:/,$_;
                   2288: 	    $response .= "<li>$sec - ID: $lc_sec</li>\n";
1.15      albertel 2289: 	}
                   2290: 	$response .= "</ul><br/><br/>\n";
                   2291:     }
                   2292: 
                   2293:     if (@badsections > 0) {
                   2294: 	$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";
                   2295: 	foreach (@badsections) {
1.42      raeburn  2296: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2297: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2298: 	}
                   2299: 	$response .= "</ul><br/><br/>\n";
                   2300:     }
                   2301: 
                   2302:     if (@badowner > 0) {
                   2303: 	$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";
                   2304: 	foreach (@badowner) {
1.42      raeburn  2305: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2306: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2307: 	}
                   2308: 	$response .= "</ul><br/><br/>\n";
                   2309:     }
                   2310: 
1.42      raeburn  2311:     if (@reserved > 0) {
                   2312:         $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";
                   2313:         foreach (@reserved) {
                   2314:             my ($xlist,$lc_sec) = split/:/,$_;
                   2315:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2316:         }
                   2317:         $response .= "</ul><br/><br/>\n";
                   2318:     }
                   2319:                                                                                  
                   2320:     if (@matchgroup > 0) {
                   2321:         $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";
                   2322:         foreach (@matchgroup) {
                   2323:             my ($xlist,$lc_sec) = split/:/,$_;
                   2324:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2325:         }
                   2326:         $response .= "</ul><br/><br/>\n";
                   2327:     }
                   2328: 
                   2329: 
1.15      albertel 2330:     if (@allsections > 0) {
                   2331: 	$warning = &warning_message($dom,$crs,$action);
1.67      wenzelju 2332: 	$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 2333: 	unless ($warning eq '') {
                   2334: 	    $response .= $warn_prefix.$warning;
                   2335: 	}
                   2336:     }
1.1       raeburn  2337: 
1.15      albertel 2338:     &print_reply($r,$response,$$tasktitleref{$action});
                   2339:     return;
1.1       raeburn  2340: }
                   2341: 
1.34      raeburn  2342: sub photo_permission {
1.15      albertel 2343:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.35      albertel 2344:     my %settings = &Apache::lonnet::get('environment',
                   2345: 					['internal.courseowner',
                   2346: 					 'internal.photopermission',
1.37      raeburn  2347: 					 'internal.showphoto'],
1.35      albertel 2348: 					$dom,$crs);
1.34      raeburn  2349:     my ($showphotos,$response);
                   2350:     if (exists($env{'form.cancel_agreement'})) {
1.48      albertel 2351:         if (&user_is_courseowner($settings{'internal.courseowner'})) {
1.34      raeburn  2352:             my %cenv = (
                   2353:                 'internal.photopermission' => 'no',
                   2354:             );
                   2355:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2356:             if ($reply !~ /^ok$/) {
                   2357:                 $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";
                   2358:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2359:             } else {
                   2360:                 &print_photos_response($r,$realm,$dom,$crs,$action,
                   2361:                        $tasktitleref,$showphotos,'no',\%cenv);
                   2362:             }
                   2363:             return;            
                   2364:         }
                   2365:     } 
                   2366:     if (exists($env{'form.showphotos'})) {
                   2367:         $showphotos=$env{'form.showphotos'};
                   2368:     }
                   2369:     if ($showphotos) {
                   2370:         if ($env{'form.photopermission'}) {
                   2371:             my %cenv = (
                   2372:                 'internal.photopermission' => $env{'form.photopermission'},
                   2373:             );
                   2374:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2375:             if ($reply !~ /^ok$/) {
                   2376:                 $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";
                   2377:             } else {
                   2378:                 &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2379: 				       $tasktitleref,$showphotos,
                   2380: 				       $env{'form.photopermission'},\%cenv);
1.34      raeburn  2381:             }
                   2382:         } else {
                   2383:             my ($result,$perm_reqd,$conditions) = 
1.35      albertel 2384: 		&Apache::lonnet::auto_photo_permission($crs,$dom);
1.34      raeburn  2385:             my $permcheck;
                   2386:             if ($result eq 'ok') { 
                   2387:                 if ($perm_reqd eq 'yes') {
                   2388:                     if ($settings{'internal.photopermission'} eq 'yes') {
                   2389:                         &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2390: 					       $tasktitleref,$showphotos);
1.34      raeburn  2391:                     } else {
                   2392:                         return(&print_photo_agreement($r,$realm,$dom,$crs,
1.35      albertel 2393: 						      $action,$tasktitleref,
                   2394: 						      $conditions,
                   2395: 						      $settings{'internal.courseowner'}));
1.34      raeburn  2396:                     }
                   2397:                 } elsif ($perm_reqd eq 'no') {
                   2398:                     &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2399: 					   $tasktitleref,$showphotos);
1.34      raeburn  2400:                 } else {
                   2401:                     $permcheck = 'fail';
                   2402:                 }
                   2403:             } else {
                   2404:                 $permcheck = 'fail';
                   2405:             }
                   2406:             if ($permcheck eq 'fail') {
                   2407:                 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/>';
                   2408:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2409:             }
                   2410:         }
                   2411:     } else {
                   2412:         &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref);
                   2413:     }
                   2414:     return;
                   2415: }
                   2416: 
                   2417: sub print_photo_agreement {
                   2418:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_;
                   2419:     my $response;
1.49      albertel 2420:     my $institution = &Apache::lonnet::domain($dom,'description');
1.48      albertel 2421:     if (&user_is_courseowner($courseowner)) {
1.34      raeburn  2422:         $response = '
1.58      bisitz   2423: <script type="text/javascript" language="JavaScript">
1.34      raeburn  2424: function agreement_result(caller) {
                   2425:     document.permission.photopermission.value = caller;
                   2426:     if (caller == 0) {
                   2427:         document.location.href="/adm/populate";
                   2428:     } else {
                   2429:         document.permission.submit();
                   2430:     }
                   2431:     return;
                   2432: }
                   2433: </script>
                   2434:   <form name="permission" method="post">
                   2435:    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   2436:     <tr>
                   2437:      <td align="left"><b>Use of student photos</b><br/>'."\n".
                   2438:       &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).'
                   2439:      </td>
                   2440:     </tr>
                   2441:    </table>
                   2442:    <table border="0" cellpadding="3" cellspacing="3">
                   2443:     <tr>
                   2444:      <td colspan="2">
                   2445:       <textarea rows="20" cols="80">'.$conditions.'</textarea>
                   2446:      </td>
                   2447:      <tr>
                   2448:       <td align="left">  
                   2449:        <input type="button" name="disagree" value="I do not agree" onclick="javascript:agreement_result('."'no'".');" />
                   2450:       </td>
                   2451:       <td align="right">
                   2452:        <input type="button" name="agree" value="I agree" onclick="javscript:agreement_result('."'yes'".');" />
                   2453:       </td>
                   2454:     </tr>
                   2455:    </table>
1.62      bisitz   2456:    <input type="hidden" name="action" value="'.$action.'" />
                   2457:    <input type="hidden" name="state" value="process" />
                   2458:    <input type="hidden" name="showphotos" value="1" />
                   2459:    <input type="hidden" name="photopermission" value="" />
1.34      raeburn  2460:   </form>
                   2461: ';
                   2462:     } else {
1.44      raeburn  2463:         my ($ownername,$owneremail) = &get_ownerinfo($dom,$courseowner);
                   2464:         my $emailstr;
                   2465:         if ($owneremail) {
                   2466:             $emailstr = "(e-mail: $owneremail)";
                   2467:         }
1.56      bisitz   2468:         $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)
                   2469:                    .'<br /><br />'
                   2470:                    .&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  2471:     }
                   2472:     &print_reply($r,$response,$$tasktitleref{$action});
                   2473: }
                   2474: 
                   2475: sub print_photos_response {
                   2476:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission,
1.35      albertel 2477: 	$permissionenv)=@_;
1.34      raeburn  2478:     my %newenv;
                   2479:     if (defined($permissionenv)) {
                   2480:         foreach my $key (keys(%{$permissionenv})) {
                   2481:             if (exists($env{'request.course.id'})) {
                   2482:                 $newenv{$env{'request.course.id'}.'.'.$key} =
1.35      albertel 2483: 		    $$permissionenv{$key};
1.34      raeburn  2484:             }
                   2485:         }
                   2486:     }
1.37      raeburn  2487:     my %settings = &Apache::lonnet::get('environment',['internal.showphoto'],
1.35      albertel 2488: 					$dom,$crs);
1.37      raeburn  2489:     my $currphotos = $settings{'internal.showphoto'};
1.34      raeburn  2490:     my $response = "";
                   2491:     if (defined($photopermission)) {
                   2492:         if ($photopermission eq 'yes') {
                   2493:             $response = &mt('Acceptance of photo use policy recorded.').'<br />'."\n";
                   2494:         } else {
                   2495:             $response = &mt('Non-acceptance of photo use policy recorded.').'<br />'."\n";
                   2496:             $showphotos = 0;
                   2497:         }
1.15      albertel 2498:     }
1.37      raeburn  2499:     my %cenv = ('internal.showphoto' => $showphotos);
1.15      albertel 2500:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2501:     if ($reply !~ /^ok$/) {
1.34      raeburn  2502: 	$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 2503:     } else {
                   2504: 	if ($showphotos) {
                   2505: 	    if ($currphotos) {
1.34      raeburn  2506: 		$response .= "Retrieval of student photos is still <b>enabled</b>.<br/>";
1.15      albertel 2507: 	    } else {
1.34      raeburn  2508: 		$response .= "Retrieval of student photos in now <b>enabled</b>.<br/>";
1.35      albertel 2509:                 my ($update,$commentary) = 
                   2510: 		    &Apache::lonnet::auto_photochoice($crs,$dom);
1.34      raeburn  2511:                 if ($update) {
                   2512:                     $response .= '<br />'.$commentary.'<br /><br />
                   2513: <form name="photoupdate" method="post">
1.62      bisitz   2514: <input type="button" name="retrieve" value="'.&mt('Update photo repository').'" 
1.34      raeburn  2515: onclick="javascript:document.photoupdate.submit()" /> 
1.62      bisitz   2516: <input type="hidden" name="action" value="'.$action.'" />
                   2517: <input type="hidden" name="state" value="photoupdate" />
1.34      raeburn  2518: </form>';
                   2519:                 }
1.15      albertel 2520: 	    }
                   2521: 	} else {
                   2522: 	    if ($currphotos) {
1.34      raeburn  2523: 		$response .= "Retrieval of student photos is now <b>disabled</b>.<br/>";
1.15      albertel 2524: 	    } else {
1.34      raeburn  2525: 		$response .= "Retrieval of student photos is still <b>disabled</b>.<br/>";
1.15      albertel 2526: 	    }
                   2527: 	}
1.34      raeburn  2528:         foreach my $key (keys(%cenv)) {
                   2529:             if (exists($env{'request.course.id'})) {
                   2530:                 $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = 
1.35      albertel 2531: 		    $cenv{$key};
1.34      raeburn  2532:             }
                   2533:         }
                   2534:     }
                   2535:     if (keys(%newenv) > 0) {
1.54      raeburn  2536:         &Apache::lonnet::appenv(\%newenv);
1.34      raeburn  2537:     }
                   2538:     &print_reply($r,$response,$$tasktitleref{$action});
                   2539:     return;
                   2540: }
                   2541: 
                   2542: sub print_photoupdate_response {
                   2543:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2544:     my $response;
                   2545:     my %changes;
                   2546:     my %lt = &LONCAPA::Enrollment::photo_response_types();
1.35      albertel 2547:     my %settings = &Apache::lonnet::get('environment',
                   2548: 					['internal.coursecode',
                   2549: 					 'internal.sectionnums',
                   2550: 					 'internal.crosslistings'],
                   2551: 					$dom,$crs);
1.34      raeburn  2552:     my @allcourses = ();
                   2553:     my %LC_code;
                   2554:     my %affiliates;
                   2555:     my $outcome;
1.53      raeburn  2556:     &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.34      raeburn  2557:     if (@allcourses > 0) {
                   2558:         @{$affiliates{$crs}} = @allcourses;
                   2559:         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
                   2560:         unless ($outcome eq 'ok') {
                   2561:             &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response".
1.35      albertel 2562: 				     "failed to update student photos".
                   2563: 				     " for ".$crs."\@".$dom." by ".
                   2564: 				     $env{'user.name'}." \@ ".$env{'user.domain'}.
                   2565: 				     ": ".$outcome);
1.34      raeburn  2566:         }
                   2567:         if ($outcome eq 'ok') {
                   2568:             if (keys(%changes) > 0) {
1.58      bisitz   2569:                 $response = &mt('Update of photos for registered students resulted in the following ').': <br />'
                   2570:                            .'<script type="text/javascript" language="JavaScript">
1.34      raeburn  2571: function photowindow(photolink) {
                   2572:     var title = "Photo_Viewer";
                   2573:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2574:     options += ",width=240,height=240";
                   2575:     stdeditbrowser = open(photolink,title,options,"1");
                   2576:     stdeditbrowser.focus();
                   2577: }
                   2578: </script>
                   2579: ';
                   2580:                 foreach my $type (sort(keys(%changes))) {
                   2581:                     my @usernames = sort(split(/\&/,$changes{$type})); 
                   2582:                     my $count = @usernames; 
                   2583:                     $response .= '<b>'.&mt('For [_1] students, photos ',
1.35      albertel 2584: 					   $count).$lt{$type}.'</b><ul>';
1.34      raeburn  2585:                     foreach my $username (@usernames) {
                   2586:                         $response .= '<li>'.$username;
                   2587:                         if (($type eq 'new') || ($type eq 'same') || ($type eq 'update')) {
                   2588:                             $response .= '&nbsp;<a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($dom,$username,'jpg')."'".')">View</a></li>';  
                   2589:                         }
                   2590:                     }
                   2591:                     $response .= '</ul><br />';
                   2592:                 }
                   2593:             } else {
                   2594:                 $response = &mt('No updates of photos of registered students occurred').
                   2595:                          '<br />';
                   2596:             }    
                   2597:         } else {
                   2598:             $response = "There was a problem updating student photos for registered students in this course. <br/>";
                   2599:         }
                   2600:     } else {
                   2601:         $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 2602:     }
                   2603:     &print_reply($r,$response,$$tasktitleref{$action});
                   2604:     return;
1.1       raeburn  2605: }
                   2606: 
1.34      raeburn  2607: sub get_ownerinfo {
                   2608:     my ($dom,$owner) = @_; 
1.44      raeburn  2609:     my ($ownername,$owneremail,$own_uname,$own_udom);
1.34      raeburn  2610:     if ($owner) {
1.44      raeburn  2611:         if ($owner =~ /^([^:]+):([^:]+)$/) {
                   2612:             $own_uname = $1;
                   2613:             $own_udom = $2; 
                   2614:         } else {
                   2615:             $own_uname = $owner;
                   2616:             $own_udom = $dom; 
                   2617:         }
                   2618:         $ownername=&Apache::loncommon::plainname($own_uname,$own_udom,
                   2619:                                                  'firstname');
1.36      raeburn  2620:         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
1.44      raeburn  2621: 					     $own_udom,$own_uname);
1.34      raeburn  2622:         $owneremail = $ownerinfo{'permanentemail'};
                   2623:     }
                   2624:     return ($ownername,$owneremail);
                   2625: }
                   2626: 
1.1       raeburn  2627: sub print_update_result () {
1.15      albertel 2628:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2629:     my $response = '';
                   2630:     my $updateadds = 0;
                   2631:     my $updatedrops = 0;
                   2632:     my $changecount = 0;
                   2633:     my %affiliates = ();
                   2634:     my %reply = ();
                   2635:     my @allcourses = ();
                   2636:     my %LC_code = ();
                   2637:     my $logmsg = '';
                   2638:     my $newusermsg = '';
1.34      raeburn  2639:     my %phototypes = ();
1.37      raeburn  2640:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.showphoto'],$dom,$crs);
1.15      albertel 2641:     my $coursecode = $settings{'internal.coursecode'};
                   2642:     my $authtype = $settings{'internal.authtype'};
                   2643:     my $autharg = $settings{'internal.autharg'};
1.37      raeburn  2644:     my $showphotos = $settings{'internal.showphoto'};
1.15      albertel 2645:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.23      albertel 2646:     if ( exists($env{'form.updateadds'}) ) {
                   2647:         $updateadds = $env{'form.updateadds'};
1.15      albertel 2648:     }
1.23      albertel 2649:     if ( exists($env{'form.updatedrops'}) ) {
                   2650:         $updatedrops = $env{'form.updatedrops'};
1.15      albertel 2651:     }
1.19      raeburn  2652:     if (($startaccess eq '') || ($endaccess eq '')) {
                   2653:         $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 />"; 
                   2654:     } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
                   2655:         $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";
                   2656:     } elsif (!$updateadds && !$updatedrops) {
1.15      albertel 2657: 	$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.";
                   2658:     } elsif ($coursecode eq '') {
                   2659: 	$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";
                   2660:     } else {
1.53      raeburn  2661:         &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.15      albertel 2662: 	if (@allcourses > 0) {
                   2663: 	    @{$affiliates{$crs}} = @allcourses;
                   2664: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
1.19      raeburn  2665:             unless ($outcome eq 'ok') {
                   2666:                 &Apache::lonnet::logthis("lonpopulate:update roster".
                   2667:                                          "failed to retrieve classlist".
                   2668:                                  " data for ".$crs."\@".$dom." by ".
1.23      albertel 2669:                                  $env{'user.name'}." \@ ".$env{'user.domain'}.
1.19      raeburn  2670:                                  ": ".$outcome);
                   2671:             }
1.15      albertel 2672: 	    if ($reply{$crs} > 0) {
1.34      raeburn  2673: 		($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes);
1.15      albertel 2674: 	    } else {
                   2675: 		$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.";
                   2676: 	    }  
                   2677: 	} else {
                   2678: 	    $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)";
                   2679: 	}
                   2680:     }
                   2681:     unless ($logmsg eq '') {
                   2682: 	my $loglength = length($logmsg);
                   2683: 	$logmsg = substr($logmsg,0,$loglength-4);
                   2684: 	$logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   2685:     }
                   2686:     unless ($newusermsg eq '') {
                   2687: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
1.19      raeburn  2688: 	$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 2689:     }
                   2690:     $response .= $logmsg.$newusermsg;
                   2691:     &print_reply($r,$response,$$tasktitleref{$action});
                   2692:     return;
1.10      raeburn  2693: }
                   2694: 
1.14      raeburn  2695: sub print_viewclass_response {
                   2696:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2697:     my $response;
                   2698:     my $chgtotal = 0;
                   2699:     my $chgok = 0;
                   2700:     my $chgfail = 0;
                   2701:     my $othdom = 0;
1.16      raeburn  2702:     my $locktotal = 0;
                   2703:     my $lockok = 0;
                   2704:     my $lockfail = 0;
1.14      raeburn  2705:     my $cid = $dom."_".$crs;
                   2706:     my %chg = ();
                   2707:     my %nochg = ();
                   2708:     my %otherdom = ();
1.16      raeburn  2709:     my %lockchg = ();
                   2710:     my %nolockchg = ();
1.27      albertel 2711:     my $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2712:     my $endidx = &Apache::loncoursedata::CL_END;
                   2713:     my $startidx = &Apache::loncoursedata::CL_START;
                   2714:     my $ididx=&Apache::loncoursedata::CL_ID;
                   2715:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   2716:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
1.16      raeburn  2717:     my $lockedidx=&Apache::loncoursedata::CL_LOCKEDTYPE;
                   2718:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chgauto','chgmanual','lockchg','unlockchg']);
1.24      albertel 2719:     my @typechglist = (&Apache::loncommon::get_env_multiple('form.chgauto'),
                   2720: 		       &Apache::loncommon::get_env_multiple('form.chgmanual'));
                   2721:     my @lockchglist = (&Apache::loncommon::get_env_multiple('form.lockchg'),
                   2722: 		       &Apache::loncommon::get_env_multiple('form.unlockchg'));
                   2723: 
1.16      raeburn  2724:     foreach my $student (sort @typechglist) {
1.51      raeburn  2725:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  2726:         my $sdata    = $classlist->{$student};
                   2727:         my $section  = $sdata->[$secidx];
                   2728:         my $uid       = $sdata->[$ididx];
                   2729:         my $start    = $sdata->[$startidx];
                   2730:         my $end      = $sdata->[$endidx];
                   2731:         my $type     = $sdata->[$typeidx];
                   2732:         my $lock   = $sdata->[$lockedidx];
                   2733:         my $newlock = $lock;
                   2734:         $chgtotal ++;
                   2735:         my $newtype = 'auto';
                   2736:         my $change = 'auto';
                   2737:         my $oldtype = 'manual';
                   2738:         if ($type eq 'auto') { 
                   2739:             $oldtype = 'auto';
                   2740:             $newtype = '';
                   2741:             $change = 'manual';
                   2742:         }
                   2743:         if ($udom eq $dom) {
                   2744:             if ($newtype eq 'auto') {
                   2745:                 $newlock = '';
                   2746:             } elsif ($newtype eq '') {
                   2747:                 $newlock = '1';
1.14      raeburn  2748:             }
1.55      raeburn  2749:             my $modreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$newtype,$newlock,$cid,'','chgtype');
1.16      raeburn  2750:             if ($modreply eq 'ok') {
                   2751:                 $chgok ++;
                   2752:                 $chg{$student} = "Changed to $change";
                   2753:             } else {
                   2754:                 $chgfail ++;
                   2755:                 $nochg{$student} = "Still set to $oldtype";
                   2756:             } 
                   2757:         } else {
                   2758:             $othdom ++;
                   2759:             $otherdom{$student} = "Still set to $oldtype"; 
                   2760:         }
                   2761:     }
                   2762:     foreach my $student (@lockchglist) {
1.51      raeburn  2763:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  2764:         my $sdata    = $classlist->{$student};
                   2765:         my $section  = $sdata->[$secidx];
                   2766:         my $uid       = $sdata->[$ididx];
                   2767:         my $start    = $sdata->[$startidx];
                   2768:         my $end      = $sdata->[$endidx];
                   2769:         my $type     = $sdata->[$typeidx];
                   2770:         my $lock   = $sdata->[$lockedidx];
                   2771:         my $newlock = 1;
                   2772:         my $oldlockname = &mt('unlocked');
                   2773:         my $newlockname = &mt('locked');
                   2774:         $locktotal++;
                   2775:         unless ($type eq 'auto') {
                   2776:             if ($lock) {
                   2777:                 $newlock = '';
                   2778:                 $newlockname = &mt('unlocked');
                   2779:                 $oldlockname = &mt('locked'); 
                   2780:             }
1.55      raeburn  2781:             my $lockreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$type,$newlock,$cid,'','chgtype');
1.16      raeburn  2782:             if ($lockreply eq 'ok') {
                   2783:                 $lockok ++;
                   2784:                 $lockchg{$student} = 'Changed to '.$newlockname;
1.14      raeburn  2785:             } else {
1.16      raeburn  2786:                 $lockfail ++;
                   2787:                 $nolockchg{$student} = 'Still set to '.$oldlockname;
1.14      raeburn  2788:             }
                   2789:         }
                   2790:     }
                   2791:     if ($chgtotal > 0) {
1.51      raeburn  2792:         $response = &mt('You requested a change in enrollment type for [quant,_1,student].',$chgtotal).'<br /><br />'."\n";
1.27      albertel 2793:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2794:         if ($chgok > 0) {
1.51      raeburn  2795:             $response .= &mt('The following [quant,_1,change was,changes were] successful;',$chgtotal).':<br /><br />';
1.14      raeburn  2796:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2797:         }
                   2798:         if ($chgfail > 0) {
1.51      raeburn  2799:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$chgfail).':&nbsp;<br />';
1.14      raeburn  2800:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2801:         }
                   2802:         if ($othdom > 0) {
1.51      raeburn  2803:             $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  2804:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2805:         }
1.16      raeburn  2806:         $response .= "<br /><br />";
                   2807:     }
                   2808:     if ($locktotal > 0) {
1.51      raeburn  2809:         $response .= &mt('You requested locking/unlocking for [quant,_1,manually enrolled student]',$locktotal).'<br /><br />'."\n";
1.27      albertel 2810:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.16      raeburn  2811:         if ($lockok > 0) {
1.51      raeburn  2812:             $response .= &mt('The following [quant,_1,change was,changes were] successful',$lockok).':<br /><br />';
1.16      raeburn  2813:             $response .= &enrolltype_result(\%lockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2814:         }
                   2815:         if ($lockfail > 0) {
1.51      raeburn  2816:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$lockfail).':&nbsp;<br />';
1.16      raeburn  2817:             $response .= &enrolltype_result(\%nolockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2818:         }
1.14      raeburn  2819:     }
                   2820:     &print_reply($r,$response,$$tasktitleref{$action});
                   2821:     return;
                   2822: }
                   2823: 
                   2824: sub enrolltype_result {
1.16      raeburn  2825:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx) = @_;
1.51      raeburn  2826:     my $reply = &Apache::loncommon::start_data_table().
                   2827:                 &Apache::loncommon::start_data_table_header_row().'
1.14      raeburn  2828:               <th>username</th>
                   2829:               <th>domain</th>
                   2830:               <th>ID</th>
                   2831:               <th>student name</th>
                   2832:               <th>section</th>
                   2833:               <th>start date</th>
                   2834:               <th>end date</th>
1.51      raeburn  2835:               <th>enrollment change</th>'."\n".
                   2836:                 &Apache::loncommon::end_data_table_header_row();
                   2837:     foreach my $chg (sort keys %{$changes}) {
                   2838:         my $sdata  = $classlist->{$chg};
                   2839:         my ($uname,$udom) = split(/:/,$chg);
1.14      raeburn  2840:         my $section  = $sdata->[$secidx];
                   2841:         my $uid      = $sdata->[$ididx];
                   2842:         my $start    = $sdata->[$startidx];
                   2843:         my $end      = $sdata->[$endidx];
                   2844:         my $type     = $sdata->[$typeidx];
                   2845:         if (! defined($start) || $start == 0) {
                   2846:             $start = &mt('none');
                   2847:         } else {
                   2848:             $start = &Apache::lonlocal::locallocaltime($start);
                   2849:         }
                   2850:         if (! defined($end) || $end == 0) {
                   2851:             $end = &mt('none');
                   2852:         } else {
                   2853:             $end = &Apache::lonlocal::locallocaltime($end);
                   2854:         }
                   2855:         if (!defined($section) || ($section eq '')) {
1.51      raeburn  2856:             $section = '&nbsp;';
1.14      raeburn  2857:         }
                   2858:         if (!defined($uid) || ($uid eq '')) {
1.51      raeburn  2859:             $uid = '&nbsp;';
1.14      raeburn  2860:         }
1.51      raeburn  2861:         $reply .= &Apache::loncommon::start_data_table_row().' 
                   2862:               <td>'.$uname.'</td>
                   2863:               <td>'.$udom.'</td>
                   2864:               <td>'.$uid.'</td>
                   2865:               <td>'.&Apache::loncommon::plainname($uname,$udom).'</td>
                   2866:               <td>'.$section.'</td>
                   2867:               <td>'.$start.'</td>
                   2868:               <td>'.$end.'</td>
                   2869:               <td>'.$$changes{$chg}.'</td>'."\n".
                   2870:              &Apache::loncommon::end_data_table_row();
1.14      raeburn  2871:     }
1.51      raeburn  2872:     $reply .= &Apache::loncommon::end_data_table();
1.14      raeburn  2873:     return $reply;
                   2874: }
                   2875: 
1.10      raeburn  2876: sub warning_message {
                   2877:     my ($dom,$crs,$caller) = @_;
                   2878:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   2879:     my $currend = '';
                   2880:     my $currstart = '';
                   2881:     my $currsecs = '';
                   2882:     my $currxlists = '';
                   2883:     my $warning = '';
                   2884:     my $curradds = '';
                   2885:     my $currdrops = '';
                   2886:     if ( defined($settings{'internal.autoadds'}) ) {
                   2887:         $curradds = $settings{'internal.autoadds'};
                   2888:     }
                   2889:     if (defined($settings{'internal.autodrops'}) ) {
                   2890:         $currdrops = $settings{'internal.autodrops'};
                   2891:     }
                   2892:     if ( defined($settings{'internal.autostart'}) ) {
                   2893:         $currstart = $settings{'internal.autostart'};
                   2894:     }
                   2895:     if ( defined($settings{'internal.autoend'}) ) {
                   2896:         $currend = $settings{'internal.autoend'};
                   2897:     }
                   2898:     if ( defined($settings{'internal.sectionnums'}) ) {
                   2899:         $currsecs = $settings{'internal.sectionnums'};
                   2900:     }
                   2901:     if ( defined($settings{'internal.crosslistings'}) ) {
                   2902:         $currxlists = $settings{'internal.crosslistings'}
                   2903:     }
                   2904:     unless ($caller eq 'setdates') {
                   2905:         if ( ($currstart eq '') && ($currend eq '') )  {
                   2906:             $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>";
                   2907:         }
                   2908:     }
                   2909:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   2910:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   2911:             $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/>";
                   2912:         }
                   2913:     }
                   2914:     unless ( $caller eq 'chgsettings') {
                   2915:         if ( (!$curradds) && (!$currdrops) ) {
                   2916:             $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/>.";
                   2917:         }
                   2918:     }
                   2919:     return $warning;
1.1       raeburn  2920: }
                   2921: 
                   2922: sub print_reply () {
                   2923:   my ($r,$response,$caller) = @_;
                   2924:   $r->print("
                   2925:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   2926:              <tr>
1.14      raeburn  2927:               <td align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
1.1       raeburn  2928:              </tr>
                   2929:             </table>
                   2930:   ");
                   2931:   return;
                   2932: }
                   2933: 
                   2934: sub setup_date_selectors {
1.14      raeburn  2935:     my ($starttime,$endtime,$action) = @_;
1.1       raeburn  2936:     if (! defined($starttime)) {
                   2937:         $starttime = time;
1.14      raeburn  2938:         if ($action eq 'setdates') {
1.23      albertel 2939:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2940:                             '.default_enrollment_start_date'})) {
1.23      albertel 2941:                 $starttime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2942:                                   '.default_enrollment_start_date'};
1.14      raeburn  2943:             }
1.1       raeburn  2944:         }
                   2945:     }
                   2946:     if (! defined($endtime)) {
                   2947:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  2948:         if ($action eq 'setdates') {
1.23      albertel 2949:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2950:                             '.default_enrollment_end_date'})) {
1.23      albertel 2951:                 $endtime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2952:                                 '.default_enrollment_end_date'};
1.14      raeburn  2953:             }
1.1       raeburn  2954:         }
                   2955:     }
                   2956:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2957:                                                             'startdate',
                   2958:                                                             $starttime);
                   2959:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2960:                                                           'enddate',
                   2961:                                                           $endtime);
                   2962:     return ($startdateform,$enddateform);
                   2963: }
                   2964: 
                   2965: sub get_dates_from_form {
1.14      raeburn  2966:     my $startdate;
                   2967:     my $enddate;
                   2968:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   2969:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.23      albertel 2970:     if ( exists ($env{'form.no_end_date'}) ) {
1.1       raeburn  2971:         $enddate = 0;
                   2972:     }
                   2973:     return ($startdate,$enddate);
                   2974: }
                   2975: 
                   2976: sub date_setting_table {
1.14      raeburn  2977:     my ($starttime,$endtime,$action) = @_;
                   2978:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime,$action);
1.57      bisitz   2979:     my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.14      raeburn  2980:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || (($action eq 'setaccess' || $action eq 'updatenow') && ($endtime eq '' || $endtime == 0)) ) {
1.1       raeburn  2981:         $perpetual .= ' checked';
                   2982:     }
1.57      bisitz   2983:     $perpetual.= ' />'.' no ending date</label></span>';
1.1       raeburn  2984:     my $start_table = '';
                   2985:     $start_table .= "<table>\n";
                   2986:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   2987:         '<td>'.$startform.'</td>'.
                   2988:         '<td>&nbsp;</td>'."</tr>\n";
                   2989:     $start_table .= "</table>";
                   2990:     my $end_table = '';
                   2991:     $end_table .= "<table>\n";
                   2992:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   2993:         '<td>'.$endform.'</td>'.
                   2994:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   2995:     $end_table .= "</table>\n";
                   2996:     return ($start_table, $end_table);
                   2997: }
                   2998: 
1.42      raeburn  2999: sub validate_lcsec {
                   3000:     my ($curr_groups,$lcsec) = @_;
                   3001:     if (($lcsec eq 'all') || ($lcsec eq 'none')) {
                   3002:         return 'reserved';
                   3003:     } else {
                   3004:         if (exists($$curr_groups{$lcsec})) {
                   3005:             return 'group'; 
                   3006:         }
                   3007:     }
                   3008:     return 'ok';
                   3009: }
                   3010: 
1.48      albertel 3011: sub user_is_courseowner {
                   3012:     my ($courseowner) = @_;
                   3013:     my $user;
                   3014:     if ($courseowner =~ /^[^:]+:[^:]+$/) {
                   3015: 	$user = $env{'user.name'}.':'.$env{'user.domain'};
                   3016:     } else {
                   3017: 	$user = $env{'user.name'};
                   3018:     }
                   3019:     return ($user eq $courseowner);
                   3020: }
                   3021:     
1.1       raeburn  3022: ###################################################################
                   3023: sub handler {
                   3024:     my $r = shift;
                   3025:     if ($r->header_only) {
1.22      albertel 3026: 	&Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3027:         $r->send_http_header;
                   3028:         return OK;
                   3029:     }
                   3030:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   3031:     #  Needs to be in a course
1.23      albertel 3032:     if (! (($env{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) {
1.1       raeburn  3033:         # Not in a course, or not allowed to modify parms
1.23      albertel 3034:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
1.34      raeburn  3035:         return HTTP_NOT_ACCEPTABLE;
1.1       raeburn  3036:     }
                   3037:     # Start page
1.22      albertel 3038:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3039:     $r->send_http_header;
                   3040: 
1.34      raeburn  3041:     my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","updatephotos","viewclass");
1.1       raeburn  3042:                                                                                  
                   3043:     my %tasklong = (
                   3044:                information => "Task information",
                   3045:                chgsettings => "Automated adds/drops",
                   3046:                setdates => "Change enrollment dates",
1.14      raeburn  3047:                setaccess => "Change access dates",
1.1       raeburn  3048:                notify => "Notification of changes",
                   3049:                crosslist => "Change crosslistings",
                   3050:                sections => "Section settings",
1.34      raeburn  3051:                photos => "Student photo settings",
                   3052:                updatephotos => "Update student photos",
1.1       raeburn  3053:                updatenow => "Update roster now",
                   3054:                newcross => "Add crosslistings",
1.14      raeburn  3055:                newsections => "Add sections",
1.16      raeburn  3056:                viewclass => "View students and change type",
1.1       raeburn  3057:     );
                   3058:                                                                                  
                   3059:     my %tasktitle = (
                   3060:                chgsettings => "Changes to nightly automated enrollments",
                   3061:                setdates => "Changes to first and/or last automated enrollment dates",
1.14      raeburn  3062:                setaccess => "Changes to default start and/or end dates for student access",
1.1       raeburn  3063:                notify => "Notification of enrollment changes",
                   3064:                crosslist => "Changes to crosslistings",
                   3065:                sections => "Changes to section settings",
1.34      raeburn  3066:                photos => "Student photo settings",
                   3067:                updatephotos => "Update student photos",
1.1       raeburn  3068:                updatenow => "Immediate course roster update",
                   3069:                newcross => "Adding new crosslisted courses",
1.14      raeburn  3070:                newsections => "Adding new course sections",
                   3071:                viewclass => "Viewing class roster and enrollment type"
1.1       raeburn  3072:     );
                   3073: 
                   3074:     my $realm = '';
1.23      albertel 3075:     if ( exists($env{'request.course.id'}) ) {
                   3076:         $realm= $env{'course.'.$env{'request.course.id'}.'.description'};
1.1       raeburn  3077:     }
                   3078:     unless ($realm) { $realm='&nbsp;'; }
1.23      albertel 3079:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3080:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1       raeburn  3081:     
                   3082:     #
                   3083:     # Main switch on form.action and form.state, as appropriate
                   3084:     #
                   3085: 
                   3086:     my $action = "information";
1.23      albertel 3087:     if ( exists($env{'form.action'}) ) {
                   3088:         $action = $env{'form.action'};
1.1       raeburn  3089:     }
                   3090:     my $state = "choose";
                   3091: 
1.23      albertel 3092:     if ( exists($env{'form.state'}) ) {
                   3093:         $state = $env{'form.state'};
1.1       raeburn  3094:     }
                   3095: 
                   3096:     if ($action eq "information") {
                   3097:         $r->print(&header()); 
                   3098:     } else {
                   3099:         if ($state eq "choose") {
1.16      raeburn  3100:             $r->print(&choose_header($action));
1.1       raeburn  3101:         } else {
                   3102:             if ($action eq "crosslist") {
1.23      albertel 3103:                 if ( exists($env{'form.numcross'}) ) {
                   3104:                     if ( $env{'form.numcross'} > 0 ) {
1.16      raeburn  3105:                         $r->print(&choose_header($action));
1.1       raeburn  3106:                     } else {
                   3107:                         $r->print(&header());
                   3108:                     }
                   3109:                 } else {
                   3110:                     $r->print(&header());
                   3111:                 }
                   3112:             } elsif ($action eq "sections") {
1.23      albertel 3113:                 if ( exists($env{'form.numsec'}) ) {
                   3114:                     if ( $env{'form.numsec'} > 0 ) {
1.16      raeburn  3115:                         $r->print(&choose_header($action));
1.1       raeburn  3116:                     } else {
                   3117:                         $r->print(&header());
                   3118:                     }
                   3119:                 } else {
                   3120:                     $r->print(&header());
                   3121:                 }
                   3122:             } else {
                   3123:                 $r->print(&header());
                   3124:             }
                   3125:         }
                   3126:     }
1.12      raeburn  3127: 
1.1       raeburn  3128:     my $reply = 0;
                   3129:     unless ($state eq "choose") { $reply = 1; }
                   3130: 
                   3131:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   3132:     &print_navmenu($r,\@tasks,\%tasklong);
                   3133:     
                   3134:     if (($state eq "choose") || ($action eq "information")) {
1.13      raeburn  3135:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
1.1       raeburn  3136:     } elsif ($action eq "chgsettings") {
                   3137:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3138:     } elsif ($action eq "setdates") {
                   3139:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3140:     } elsif ($action eq "setaccess") {
                   3141:         &print_setaccess_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3142:     } elsif ($action eq "notify") {
                   3143:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3144:     } elsif ($action eq "sections") {
1.13      raeburn  3145:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3146:     } elsif ($action eq "crosslist") {
1.13      raeburn  3147:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3148:     } elsif ($action eq "updatenow") {
1.13      raeburn  3149:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3150:     } elsif ($action eq "photos") {
1.34      raeburn  3151:         if ($state eq "photoupdate") {
                   3152:             &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3153:         } else { 
                   3154:             &photo_permission($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3155:         }
                   3156:     } elsif ($action eq "updatephotos") {
                   3157:         &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3158:     } elsif ($action eq "newcross") {
1.13      raeburn  3159:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
1.1       raeburn  3160:     } elsif ($action eq "newsections") {
1.13      raeburn  3161:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3162:     } elsif ($action eq "viewclass") {
                   3163:         &print_viewclass_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3164:     }
                   3165:     &print_doc_base($r);  
                   3166:     return OK;
                   3167: }
                   3168: ###################################################################
                   3169: 1;

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