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

1.4       albertel    1: # automated enrollment configuration handler
1.67    ! wenzelju    2: # $Id: lonpopulate.pm,v 1.66 2009/10/30 20:35:34 raeburn Exp $
1.4       albertel    3: #
                      4: # Copyright Michigan State University Board of Trustees
                      5: #
                      6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      7: #
                      8: # LON-CAPA is free software; you can redistribute it and/or modify
                      9: # it under the terms of the GNU General Public License as published by
                     10: # the Free Software Foundation; either version 2 of the License, or
                     11: # (at your option) any later version.
                     12: #
                     13: # LON-CAPA is distributed in the hope that it will be useful,
                     14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: # GNU General Public License for more details.
                     17: #
                     18: # You should have received a copy of the GNU General Public License
                     19: # along with LON-CAPA; if not, write to the Free Software
                     20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     21: #
                     22: # /home/httpd/html/adm/gpl.txt
                     23: #
                     24: # http://www.lon-capa.org/
                     25: #
1.1       raeburn    26: package Apache::lonpopulate;
                     27: 
                     28: use strict;
                     29: use lib qw(/home/httpd/lib/perl);
1.7       raeburn    30: use Apache::lonnet;
                     31: use Apache::loncommon;
                     32: use Apache::lonhtmlcommon;
1.3       albertel   33: use Apache::lonlocal;
1.14      raeburn    34: use Apache::loncoursedata;
1.43      raeburn    35: use Apache::longroup;
1.51      raeburn    36: use Apache::lonuserutils;
1.1       raeburn    37: use Apache::Constants qw(:common :http REDIRECT);
                     38: use Time::Local;
1.7       raeburn    39: use LONCAPA::Enrollment;
1.1       raeburn    40: 
                     41: ###############################################################
                     42: sub header {
1.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) = @_;
                   1897:     my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
                   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'};
                   1909:     my $response = '';
                   1910:     my $warning = '';
                   1911:     my $warn_prefix = '';
1.1       raeburn  1912: 
1.28      albertel 1913:     if ($xliststr ne '') {
                   1914: 	@allxlists = split(/,/,$xliststr);
1.15      albertel 1915:     }
1.1       raeburn  1916: 
1.23      albertel 1917:     if ( exists($env{'form.numcross'}) ) {
                   1918: 	$numcross = $env{'form.numcross'};
1.15      albertel 1919:     }
1.1       raeburn  1920: 
1.15      albertel 1921:     if ($numcross > 0) {
1.43      raeburn  1922:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 1923: 	for (my $i=0; $i<$numcross; $i++) {
                   1924: 	    my $xl = "newcross_".$i;
1.42      raeburn  1925: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 1926: 	    if ( exists($env{"form.$xl"}) ) {
1.42      raeburn  1927:                 if (exists($env{"form.$lc_sec"})) {
                   1928:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,
                   1929:                                                     $env{"form.$lc_sec"});
                   1930:                     if ($lc_sec_check eq 'reserved') {
                   1931:                         push(@reserved,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1932:                         next;
                   1933:                     } elsif ($lc_sec_check eq 'group') {
                   1934:                         push (@matchgroup,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
                   1935:                         next;
                   1936:                     }
                   1937:                 }
1.15      albertel 1938: 		my $coursecheck = '';
1.23      albertel 1939: 		$coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});
1.15      albertel 1940: 		if ($coursecheck eq 'ok') {
                   1941: 		    my $addcheck = '';
1.23      albertel 1942: 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner);
1.15      albertel 1943: 		    if ($addcheck eq 'ok') {
1.42      raeburn  1944: 			push @xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1945: 		    } else {
1.42      raeburn  1946: 			push @badowner,$env{"form.$xl"}.":".$env{"form.$lc_sec"};
1.15      albertel 1947: 		    }
                   1948: 		} else {
1.42      raeburn  1949: 		    push @badxlists, $env{"form.$xl"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 1950: 		}
                   1951: 	    }
                   1952: 	}
                   1953: 	push @allxlists, @xlists;
                   1954:     }
                   1955:     
                   1956:     if (@xlists > 0 ) {
                   1957: 	unless ($xliststr eq '') { $xliststr .= ","; }
1.28      albertel 1958: 	$xliststr .= join(",",@xlists);
                   1959: 
1.15      albertel 1960: 	my %cenv = ('internal.crosslistings' => $xliststr);
                   1961: 	my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   1962: 	if ($reply !~ /^ok$/) {
                   1963: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   1964: 	} else {
                   1965: 	    $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";
                   1966: 	    foreach (@allxlists) {
1.42      raeburn  1967: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1968: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1969: 	    }
                   1970: 	    $response .= "</ul><br/><br/>\n";
                   1971: 	}
                   1972:     } else {
                   1973: 	if ($xliststr =~ m/:/) {
1.28      albertel 1974: 	    my @oldxlists = (split/,/,$xliststr);
1.15      albertel 1975: 	    $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
                   1976: 	    foreach (@oldxlists) {
1.42      raeburn  1977: 		my ($xlist,$lc_sec) = split/:/,$_;
                   1978: 		$response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1979: 	    }
                   1980: 	    $response .= "</ul><br/><br/>\n";
                   1981: 	}
                   1982:     }
                   1983:     if (@badxlists > 0) {
                   1984: 	$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";
                   1985: 	foreach (@badxlists) {
1.42      raeburn  1986: 	    my ($xlist,$lc_sec,$prob) = split/:/,$_;
                   1987: 	    $response .= "<li>$xlist - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 1988: 	}
                   1989: 	$response .= "</ul><br/><br/>\n";
                   1990:     }
                   1991:     
                   1992:     if (@badowner > 0) {
                   1993: 	$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";
                   1994: 	foreach (@badowner) {
1.42      raeburn  1995: 	    my ($xlist,$lc_sec) = split/:/,$_;
                   1996: 	    $response .= "<li>$xlist - ID: $lc_sec</li>\n";
1.15      albertel 1997: 	}
                   1998: 	$response .= "</ul><br/><br/>\n";
                   1999:     }
1.42      raeburn  2000:     if (@reserved > 0) {
                   2001:         $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";  
                   2002:         foreach (@reserved) {
                   2003:             my ($xlist,$lc_sec) = split/:/,$_;
                   2004:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2005:         }
                   2006:         $response .= "</ul><br/><br/>\n";
                   2007:     }
                   2008: 
                   2009:     if (@matchgroup > 0) {
                   2010:         $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";
                   2011:         foreach (@matchgroup) {
                   2012:             my ($xlist,$lc_sec) = split/:/,$_;
                   2013:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2014:         }
                   2015:         $response .= "</ul><br/><br/>\n";
                   2016:     }
1.5       raeburn  2017: 
1.15      albertel 2018:     if (@allxlists > 0) {
                   2019: 	$warning = &warning_message($dom,$crs,$action);
1.67    ! wenzelju 2020: 	$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 2021: 	unless ($warning eq '') {
                   2022: 	    $response .= $warn_prefix.$warning;
                   2023: 	}
                   2024:     }
1.1       raeburn  2025: 
1.15      albertel 2026:     &print_reply($r,$response,$$tasktitleref{$action});
                   2027:     return;
1.1       raeburn  2028: }
                   2029: 
                   2030: sub print_sections_menu () {
1.15      albertel 2031:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2032:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   2033:     my @currsections = ();
                   2034:     my @sections = ();
                   2035:     my @badowner = ();
                   2036:     my @badsections = ();
                   2037:     my $seccount = 0;
                   2038:     my $removecount = 0;
                   2039:     my $addcount = 0;
                   2040:     my $secstr = '';
                   2041:     my $response = '';
                   2042:     my $warning = "";
                   2043:     my $warn_prefix = "";
                   2044:     my $coursecode = $settings{'internal.coursecode'};
                   2045:     my $owner = $settings{'internal.courseowner'};
1.28      albertel 2046:     if ($settings{'internal.sectionnums'} ne '') {
                   2047: 	@currsections = split(/,/,$settings{'internal.sectionnums'});
1.15      albertel 2048:     }
                   2049:     
1.23      albertel 2050:     if ( exists($env{'form.secshow'}) ) {
                   2051: 	for (my $i=0; $i<$env{'form.secshow'}; $i++) {
1.42      raeburn  2052: 	    my $lc_sec = "loncapasec_".$i;
1.15      albertel 2053: 	    my $secnum = "secnum_".$i;
                   2054: 	    my $sec = "sec_".$i;
1.23      albertel 2055: 	    if ( exists( $env{"form.$sec"} ) ) {
1.15      albertel 2056: 		my $secentry;
1.23      albertel 2057: 		if ( exists( $env{"form.$secnum"} ) ) { 
                   2058: 		    $secentry = $env{"form.$secnum"}.':';
1.15      albertel 2059: 		}
1.42      raeburn  2060: 		if ( exists( $env{"form.$lc_sec"} ) ) {
                   2061: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2062: 		}
1.23      albertel 2063: 		if ( grep/^$env{"form.$secnum"}:/,@currsections) {
1.15      albertel 2064: 		    push @sections, $secentry;
                   2065: 		    $seccount ++;
                   2066: 		} else {
1.23      albertel 2067: 		    my $newsec = $coursecode.$env{"form.$secnum"};
1.15      albertel 2068: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2069: 		    if ($coursecheck eq 'ok') {
                   2070: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   2071: 			if ($addcheck eq 'ok') {
1.42      raeburn  2072: 			    push @sections,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2073: 			    $seccount ++;
                   2074: 			    $addcount ++;
                   2075: 			} else {
1.42      raeburn  2076: 			    push @badowner,$env{"form.$secnum"}.":".$env{"form.$lc_sec"};
1.15      albertel 2077: 			}
                   2078: 		    } else {
1.42      raeburn  2079: 			push @badsections, $env{"form.$secnum"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2080: 		    }
                   2081: 		}
                   2082: 	    }
                   2083: 	}
                   2084: 	if (@currsections > 0) {
                   2085: 	    for (my $i=0; $i<@currsections; $i++) {
                   2086: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2087: 		    my $oldsec  = $1;
                   2088: 		    unless (grep/^$oldsec/,@sections) {
                   2089: 			$removecount ++;
                   2090: 		    }
                   2091: 		}
                   2092: 	    }
                   2093: 	}
                   2094:     } elsif (@currsections > 0) {
                   2095: 	for (my $i=0; $i<@currsections; $i++) {
                   2096: 	    my $sec = "sec_".$i;
1.42      raeburn  2097: 	    my $lc_sec = "lcsec_".$i;
1.23      albertel 2098: 	    if ( exists($env{"form.$sec"}) ) {
1.15      albertel 2099: 		my $secentry = '';
                   2100: 		if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   2101: 		    $secentry = $1;
                   2102: 		}
1.42      raeburn  2103: 		if ( exists($env{"form.$lc_sec"}) ) {
                   2104: 		    $secentry .= $env{"form.$lc_sec"};
1.15      albertel 2105: 		}
                   2106: 		push @sections,$secentry;
                   2107: 		$seccount ++;
                   2108: 	    } else {
                   2109: 		$removecount ++;
                   2110: 	    }
                   2111: 	}
                   2112:     }
                   2113:     
1.28      albertel 2114:     $secstr = join(",",@sections);
                   2115: 
1.15      albertel 2116:     my %cenv = ('internal.sectionnums' => $secstr);
                   2117:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2118:     if ($reply !~ /^ok$/) {
                   2119: 	$response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
                   2120:     } else {
                   2121: 	if ($removecount > 0) {
                   2122: 	    $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/>";
                   2123: 	}
                   2124: 	if ($addcount > 0) {
                   2125: 	    $response .= "A total of $addcount sections have been added to the list of
1.6       raeburn  2126: sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
1.15      albertel 2127: 	}
                   2128: 	if ($seccount > 0) { 
                   2129: 	    $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";
                   2130: 	    foreach (@sections) {
1.42      raeburn  2131: 		my ($sec,$lc_sec) = split/:/,$_;
                   2132: 		$response .= "<li>$sec  - ID: $lc_sec</li>\n";
1.15      albertel 2133: 	    }
                   2134: 	    $response .= "</ul><br/>\n";
                   2135: 	}
                   2136:     }
                   2137:     
                   2138:     if (@badsections > 0) {
                   2139: 	$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";
                   2140: 	foreach (@badsections) {
1.42      raeburn  2141: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2142: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2143: 	}
                   2144: 	$response .= "</ul><br/><br/>\n";
                   2145:     }
                   2146:     
                   2147:     if (@badowner > 0) {
                   2148: 	$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";
                   2149: 	foreach (@badowner) {
1.42      raeburn  2150: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2151: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2152: 	}
                   2153: 	$response .= "</ul><br/><br/>\n";
                   2154:     }
                   2155:     
                   2156:     if ($seccount > 0) {
                   2157: 	$warning = &warning_message($dom,$crs,$action);
1.67    ! wenzelju 2158: 	$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 2159: 	unless ($warning eq '') {
                   2160: 	    $response .= $warn_prefix.$warning;
                   2161: 	}
                   2162:     }
                   2163:     
1.23      albertel 2164:     if ( exists($env{'form.numsec'}) ) {
                   2165: 	my $numsec = $env{'form.numsec'};
1.15      albertel 2166: 	if ($numsec > 0) {
                   2167: 	    my @bgcolors=("#eeeeee","#cccccc");
                   2168: 	    $response .= qq(
1.42      raeburn  2169: 			    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  2170:            <form name="enter" method="post">
                   2171:            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                   2172:              <tr>
1.42      raeburn  2173:               <td>);
                   2174:             $response .= &Apache::loncommon::start_data_table();
                   2175:             $response .= &Apache::loncommon::start_data_table_row();
                   2176:             $response .= qq(
                   2177:                  <th>Section number</th>
                   2178:                  <th>LON-CAPA section ID</th>
                   2179: 			 );
                   2180:             $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2181: 	    for (my $i=0; $i<$numsec; $i++) {
1.42      raeburn  2182:                 $response .= &Apache::loncommon::start_data_table_row();
1.15      albertel 2183: 		$response .= qq(
1.42      raeburn  2184:                  <td><input type="text" size="10" name="newsec_$i" /></td>
                   2185:                  <td align="right">
                   2186:                    <input type="text" size="10" name="newlcsec_$i" />
                   2187:                  </td>
                   2188: 			     );
                   2189:                 $response .= &Apache::loncommon::end_data_table_row();
1.15      albertel 2190: 	    }
1.42      raeburn  2191:             $response .= &Apache::loncommon::end_data_table();
                   2192: 	    $response .= qq(
1.1       raeburn  2193:               </td>
                   2194:              </tr>
                   2195:              <tr>
                   2196:               <td align="right">
1.39      albertel 2197:                <input type="button" name="newsections" value="Go" onclick="process('newsections')" />
1.1       raeburn  2198:               </td>
                   2199:              </tr>
                   2200:             </table>
1.39      albertel 2201:             <input type=\"hidden\" name=\"numsec\" value=\"$numsec\" />
                   2202:             <input type=\"hidden\" name=\"action\" value=\"newsections\" />
                   2203:             <input type=\"hidden\" name=\"state\" value=\"process\" />
1.1       raeburn  2204:             </form>
1.15      albertel 2205: 			      );
                   2206: 	}
                   2207:     }
                   2208:     &print_reply($r,$response,$$tasktitleref{$action});
                   2209:     return;
1.1       raeburn  2210: }
                   2211: 
                   2212: sub print_sections_response () {
1.15      albertel 2213:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2214:     my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
                   2215:     my @currsections = ();
                   2216:     my @sections = ();
                   2217:     my @allsections = ();
                   2218:     my @badowner = ();
                   2219:     my @badsections = ();
1.42      raeburn  2220:     my @reserved = ();
                   2221:     my @matchgroup = ();
1.15      albertel 2222:     my $numsec = 0;
                   2223:     my $secstr =  $settings{'internal.sectionnums'};
                   2224:     my $coursecode = $settings{'internal.coursecode'};
                   2225:     my $owner = $settings{'internal.courseowner'};
                   2226:     my $response = '';
                   2227:     my $putreply = '';
                   2228:     my $warning = '';
                   2229:     my $warn_prefix = '';
1.28      albertel 2230:     if ($secstr ne '') {
                   2231: 	@allsections = split(/,/,$secstr);
1.15      albertel 2232:     }
                   2233:     
1.23      albertel 2234:     if ( exists($env{'form.numsec'}) ) {
                   2235: 	$numsec = $env{'form.numsec'};
1.15      albertel 2236:     }
                   2237:     
                   2238:     if ($numsec > 0) {
1.43      raeburn  2239:         my %curr_groups = &Apache::longroup::coursegroups();
1.15      albertel 2240: 	for (my $i=0; $i<$numsec; $i++) {
                   2241: 	    my $sec = "newsec_".$i;
1.42      raeburn  2242: 	    my $lc_sec = "newlcsec_".$i;
1.23      albertel 2243: 	    if ( exists($env{"form.$sec"}) ) {
                   2244: 		unless ( (grep/^$env{"form.$sec"}:/,@allsections) || (grep/^$env{"form.$sec"}:/,@sections) ) {
1.42      raeburn  2245:                     my $lc_sec_check = &validate_lcsec(\%curr_groups,                                                     $env{"form.$lc_sec"});
                   2246:                     if ($lc_sec_check eq 'reserved') {
                   2247:                         push(@reserved,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2248:                         next;
                   2249:                     } elsif ($lc_sec_check eq 'group') {
                   2250:                         push (@matchgroup,$env{"form.$sec"}.":".$env{"form.$lc_sec"});
                   2251:                         next;
                   2252:                     }
1.23      albertel 2253: 		    my $newsec = $coursecode.$env{"form.$sec"};
1.15      albertel 2254: 		    my $coursecheck = &Apache::lonnet::auto_validate_courseID($crs,$dom,$newsec);
                   2255: 		    if ($coursecheck eq 'ok') {
                   2256: 			my $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$newsec,$owner);
                   2257: 			if ($addcheck eq 'ok') {
1.42      raeburn  2258: 			    push @sections,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2259: 			} else {
1.42      raeburn  2260: 			    push @badowner,$env{"form.$sec"}.":".$env{"form.$lc_sec"};
1.15      albertel 2261: 			}
                   2262: 		    } else {
1.42      raeburn  2263: 			push @badsections, $env{"form.$sec"}.":".$env{"form.$lc_sec"}.":".$coursecheck;
1.15      albertel 2264: 		    }
                   2265: 		}
                   2266: 	    }
                   2267: 	}
                   2268: 	push @allsections, @sections;
                   2269:     }
                   2270:     
                   2271:     if (@sections > 0 ) {
                   2272: 	unless ($secstr eq '') { $secstr .= ","; } 
1.28      albertel 2273: 	$secstr .= join(",",@sections);
1.15      albertel 2274: 	my %cenv = ('internal.sectionnums' => $secstr);
                   2275: 	$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2276: 	if ($putreply !~ /^ok$/) {
                   2277: 	    $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
                   2278: 	}
                   2279:     }
                   2280: 
                   2281:     if ($putreply =~ /^ok/) {
                   2282: 	$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";
                   2283: 	foreach (@allsections) {
1.42      raeburn  2284: 	    my ($sec,$lc_sec) = split/:/,$_;
                   2285: 	    $response .= "<li>$sec - ID: $lc_sec</li>\n";
1.15      albertel 2286: 	}
                   2287: 	$response .= "</ul><br/><br/>\n";
                   2288:     }
                   2289: 
                   2290:     if (@badsections > 0) {
                   2291: 	$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";
                   2292: 	foreach (@badsections) {
1.42      raeburn  2293: 	    my ($secnum,$lc_sec,$prob) = split/:/,$_;
                   2294: 	    $response .= "<li>$secnum - ID: $lc_sec - Error: $prob</li>\n";
1.15      albertel 2295: 	}
                   2296: 	$response .= "</ul><br/><br/>\n";
                   2297:     }
                   2298: 
                   2299:     if (@badowner > 0) {
                   2300: 	$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";
                   2301: 	foreach (@badowner) {
1.42      raeburn  2302: 	    my ($secnum,$lc_sec) = split/:/,$_;
                   2303: 	    $response .= "<li>$secnum - ID: $lc_sec</li>\n";
1.15      albertel 2304: 	}
                   2305: 	$response .= "</ul><br/><br/>\n";
                   2306:     }
                   2307: 
1.42      raeburn  2308:     if (@reserved > 0) {
                   2309:         $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";
                   2310:         foreach (@reserved) {
                   2311:             my ($xlist,$lc_sec) = split/:/,$_;
                   2312:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2313:         }
                   2314:         $response .= "</ul><br/><br/>\n";
                   2315:     }
                   2316:                                                                                  
                   2317:     if (@matchgroup > 0) {
                   2318:         $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";
                   2319:         foreach (@matchgroup) {
                   2320:             my ($xlist,$lc_sec) = split/:/,$_;
                   2321:             $response .= "<li>$xlist - ID: $lc_sec</li>\n";
                   2322:         }
                   2323:         $response .= "</ul><br/><br/>\n";
                   2324:     }
                   2325: 
                   2326: 
1.15      albertel 2327:     if (@allsections > 0) {
                   2328: 	$warning = &warning_message($dom,$crs,$action);
1.67    ! wenzelju 2329: 	$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 2330: 	unless ($warning eq '') {
                   2331: 	    $response .= $warn_prefix.$warning;
                   2332: 	}
                   2333:     }
1.1       raeburn  2334: 
1.15      albertel 2335:     &print_reply($r,$response,$$tasktitleref{$action});
                   2336:     return;
1.1       raeburn  2337: }
                   2338: 
1.34      raeburn  2339: sub photo_permission {
1.15      albertel 2340:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
1.35      albertel 2341:     my %settings = &Apache::lonnet::get('environment',
                   2342: 					['internal.courseowner',
                   2343: 					 'internal.photopermission',
1.37      raeburn  2344: 					 'internal.showphoto'],
1.35      albertel 2345: 					$dom,$crs);
1.34      raeburn  2346:     my ($showphotos,$response);
                   2347:     if (exists($env{'form.cancel_agreement'})) {
1.48      albertel 2348:         if (&user_is_courseowner($settings{'internal.courseowner'})) {
1.34      raeburn  2349:             my %cenv = (
                   2350:                 'internal.photopermission' => 'no',
                   2351:             );
                   2352:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2353:             if ($reply !~ /^ok$/) {
                   2354:                 $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";
                   2355:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2356:             } else {
                   2357:                 &print_photos_response($r,$realm,$dom,$crs,$action,
                   2358:                        $tasktitleref,$showphotos,'no',\%cenv);
                   2359:             }
                   2360:             return;            
                   2361:         }
                   2362:     } 
                   2363:     if (exists($env{'form.showphotos'})) {
                   2364:         $showphotos=$env{'form.showphotos'};
                   2365:     }
                   2366:     if ($showphotos) {
                   2367:         if ($env{'form.photopermission'}) {
                   2368:             my %cenv = (
                   2369:                 'internal.photopermission' => $env{'form.photopermission'},
                   2370:             );
                   2371:             my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2372:             if ($reply !~ /^ok$/) {
                   2373:                 $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";
                   2374:             } else {
                   2375:                 &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2376: 				       $tasktitleref,$showphotos,
                   2377: 				       $env{'form.photopermission'},\%cenv);
1.34      raeburn  2378:             }
                   2379:         } else {
                   2380:             my ($result,$perm_reqd,$conditions) = 
1.35      albertel 2381: 		&Apache::lonnet::auto_photo_permission($crs,$dom);
1.34      raeburn  2382:             my $permcheck;
                   2383:             if ($result eq 'ok') { 
                   2384:                 if ($perm_reqd eq 'yes') {
                   2385:                     if ($settings{'internal.photopermission'} eq 'yes') {
                   2386:                         &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2387: 					       $tasktitleref,$showphotos);
1.34      raeburn  2388:                     } else {
                   2389:                         return(&print_photo_agreement($r,$realm,$dom,$crs,
1.35      albertel 2390: 						      $action,$tasktitleref,
                   2391: 						      $conditions,
                   2392: 						      $settings{'internal.courseowner'}));
1.34      raeburn  2393:                     }
                   2394:                 } elsif ($perm_reqd eq 'no') {
                   2395:                     &print_photos_response($r,$realm,$dom,$crs,$action,
1.35      albertel 2396: 					   $tasktitleref,$showphotos);
1.34      raeburn  2397:                 } else {
                   2398:                     $permcheck = 'fail';
                   2399:                 }
                   2400:             } else {
                   2401:                 $permcheck = 'fail';
                   2402:             }
                   2403:             if ($permcheck eq 'fail') {
                   2404:                 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/>';
                   2405:                 &print_reply($r,$response,$$tasktitleref{$action});
                   2406:             }
                   2407:         }
                   2408:     } else {
                   2409:         &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref);
                   2410:     }
                   2411:     return;
                   2412: }
                   2413: 
                   2414: sub print_photo_agreement {
                   2415:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_;
                   2416:     my $response;
1.49      albertel 2417:     my $institution = &Apache::lonnet::domain($dom,'description');
1.48      albertel 2418:     if (&user_is_courseowner($courseowner)) {
1.34      raeburn  2419:         $response = '
1.58      bisitz   2420: <script type="text/javascript" language="JavaScript">
1.34      raeburn  2421: function agreement_result(caller) {
                   2422:     document.permission.photopermission.value = caller;
                   2423:     if (caller == 0) {
                   2424:         document.location.href="/adm/populate";
                   2425:     } else {
                   2426:         document.permission.submit();
                   2427:     }
                   2428:     return;
                   2429: }
                   2430: </script>
                   2431:   <form name="permission" method="post">
                   2432:    <table width="100%" border="0" cellpadding="2" cellspacing="2">
                   2433:     <tr>
                   2434:      <td align="left"><b>Use of student photos</b><br/>'."\n".
                   2435:       &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).'
                   2436:      </td>
                   2437:     </tr>
                   2438:    </table>
                   2439:    <table border="0" cellpadding="3" cellspacing="3">
                   2440:     <tr>
                   2441:      <td colspan="2">
                   2442:       <textarea rows="20" cols="80">'.$conditions.'</textarea>
                   2443:      </td>
                   2444:      <tr>
                   2445:       <td align="left">  
                   2446:        <input type="button" name="disagree" value="I do not agree" onclick="javascript:agreement_result('."'no'".');" />
                   2447:       </td>
                   2448:       <td align="right">
                   2449:        <input type="button" name="agree" value="I agree" onclick="javscript:agreement_result('."'yes'".');" />
                   2450:       </td>
                   2451:     </tr>
                   2452:    </table>
1.62      bisitz   2453:    <input type="hidden" name="action" value="'.$action.'" />
                   2454:    <input type="hidden" name="state" value="process" />
                   2455:    <input type="hidden" name="showphotos" value="1" />
                   2456:    <input type="hidden" name="photopermission" value="" />
1.34      raeburn  2457:   </form>
                   2458: ';
                   2459:     } else {
1.44      raeburn  2460:         my ($ownername,$owneremail) = &get_ownerinfo($dom,$courseowner);
                   2461:         my $emailstr;
                   2462:         if ($owneremail) {
                   2463:             $emailstr = "(e-mail: $owneremail)";
                   2464:         }
1.56      bisitz   2465:         $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)
                   2466:                    .'<br /><br />'
                   2467:                    .&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  2468:     }
                   2469:     &print_reply($r,$response,$$tasktitleref{$action});
                   2470: }
                   2471: 
                   2472: sub print_photos_response {
                   2473:     my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission,
1.35      albertel 2474: 	$permissionenv)=@_;
1.34      raeburn  2475:     my %newenv;
                   2476:     if (defined($permissionenv)) {
                   2477:         foreach my $key (keys(%{$permissionenv})) {
                   2478:             if (exists($env{'request.course.id'})) {
                   2479:                 $newenv{$env{'request.course.id'}.'.'.$key} =
1.35      albertel 2480: 		    $$permissionenv{$key};
1.34      raeburn  2481:             }
                   2482:         }
                   2483:     }
1.37      raeburn  2484:     my %settings = &Apache::lonnet::get('environment',['internal.showphoto'],
1.35      albertel 2485: 					$dom,$crs);
1.37      raeburn  2486:     my $currphotos = $settings{'internal.showphoto'};
1.34      raeburn  2487:     my $response = "";
                   2488:     if (defined($photopermission)) {
                   2489:         if ($photopermission eq 'yes') {
                   2490:             $response = &mt('Acceptance of photo use policy recorded.').'<br />'."\n";
                   2491:         } else {
                   2492:             $response = &mt('Non-acceptance of photo use policy recorded.').'<br />'."\n";
                   2493:             $showphotos = 0;
                   2494:         }
1.15      albertel 2495:     }
1.37      raeburn  2496:     my %cenv = ('internal.showphoto' => $showphotos);
1.15      albertel 2497:     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
                   2498:     if ($reply !~ /^ok$/) {
1.34      raeburn  2499: 	$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 2500:     } else {
                   2501: 	if ($showphotos) {
                   2502: 	    if ($currphotos) {
1.34      raeburn  2503: 		$response .= "Retrieval of student photos is still <b>enabled</b>.<br/>";
1.15      albertel 2504: 	    } else {
1.34      raeburn  2505: 		$response .= "Retrieval of student photos in now <b>enabled</b>.<br/>";
1.35      albertel 2506:                 my ($update,$commentary) = 
                   2507: 		    &Apache::lonnet::auto_photochoice($crs,$dom);
1.34      raeburn  2508:                 if ($update) {
                   2509:                     $response .= '<br />'.$commentary.'<br /><br />
                   2510: <form name="photoupdate" method="post">
1.62      bisitz   2511: <input type="button" name="retrieve" value="'.&mt('Update photo repository').'" 
1.34      raeburn  2512: onclick="javascript:document.photoupdate.submit()" /> 
1.62      bisitz   2513: <input type="hidden" name="action" value="'.$action.'" />
                   2514: <input type="hidden" name="state" value="photoupdate" />
1.34      raeburn  2515: </form>';
                   2516:                 }
1.15      albertel 2517: 	    }
                   2518: 	} else {
                   2519: 	    if ($currphotos) {
1.34      raeburn  2520: 		$response .= "Retrieval of student photos is now <b>disabled</b>.<br/>";
1.15      albertel 2521: 	    } else {
1.34      raeburn  2522: 		$response .= "Retrieval of student photos is still <b>disabled</b>.<br/>";
1.15      albertel 2523: 	    }
                   2524: 	}
1.34      raeburn  2525:         foreach my $key (keys(%cenv)) {
                   2526:             if (exists($env{'request.course.id'})) {
                   2527:                 $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = 
1.35      albertel 2528: 		    $cenv{$key};
1.34      raeburn  2529:             }
                   2530:         }
                   2531:     }
                   2532:     if (keys(%newenv) > 0) {
1.54      raeburn  2533:         &Apache::lonnet::appenv(\%newenv);
1.34      raeburn  2534:     }
                   2535:     &print_reply($r,$response,$$tasktitleref{$action});
                   2536:     return;
                   2537: }
                   2538: 
                   2539: sub print_photoupdate_response {
                   2540:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2541:     my $response;
                   2542:     my %changes;
                   2543:     my %lt = &LONCAPA::Enrollment::photo_response_types();
1.35      albertel 2544:     my %settings = &Apache::lonnet::get('environment',
                   2545: 					['internal.coursecode',
                   2546: 					 'internal.sectionnums',
                   2547: 					 'internal.crosslistings'],
                   2548: 					$dom,$crs);
1.34      raeburn  2549:     my @allcourses = ();
                   2550:     my %LC_code;
                   2551:     my %affiliates;
                   2552:     my $outcome;
1.53      raeburn  2553:     &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.34      raeburn  2554:     if (@allcourses > 0) {
                   2555:         @{$affiliates{$crs}} = @allcourses;
                   2556:         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
                   2557:         unless ($outcome eq 'ok') {
                   2558:             &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response".
1.35      albertel 2559: 				     "failed to update student photos".
                   2560: 				     " for ".$crs."\@".$dom." by ".
                   2561: 				     $env{'user.name'}." \@ ".$env{'user.domain'}.
                   2562: 				     ": ".$outcome);
1.34      raeburn  2563:         }
                   2564:         if ($outcome eq 'ok') {
                   2565:             if (keys(%changes) > 0) {
1.58      bisitz   2566:                 $response = &mt('Update of photos for registered students resulted in the following ').': <br />'
                   2567:                            .'<script type="text/javascript" language="JavaScript">
1.34      raeburn  2568: function photowindow(photolink) {
                   2569:     var title = "Photo_Viewer";
                   2570:     var options = "scrollbars=1,resizable=1,menubar=0";
                   2571:     options += ",width=240,height=240";
                   2572:     stdeditbrowser = open(photolink,title,options,"1");
                   2573:     stdeditbrowser.focus();
                   2574: }
                   2575: </script>
                   2576: ';
                   2577:                 foreach my $type (sort(keys(%changes))) {
                   2578:                     my @usernames = sort(split(/\&/,$changes{$type})); 
                   2579:                     my $count = @usernames; 
                   2580:                     $response .= '<b>'.&mt('For [_1] students, photos ',
1.35      albertel 2581: 					   $count).$lt{$type}.'</b><ul>';
1.34      raeburn  2582:                     foreach my $username (@usernames) {
                   2583:                         $response .= '<li>'.$username;
                   2584:                         if (($type eq 'new') || ($type eq 'same') || ($type eq 'update')) {
                   2585:                             $response .= '&nbsp;<a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($dom,$username,'jpg')."'".')">View</a></li>';  
                   2586:                         }
                   2587:                     }
                   2588:                     $response .= '</ul><br />';
                   2589:                 }
                   2590:             } else {
                   2591:                 $response = &mt('No updates of photos of registered students occurred').
                   2592:                          '<br />';
                   2593:             }    
                   2594:         } else {
                   2595:             $response = "There was a problem updating student photos for registered students in this course. <br/>";
                   2596:         }
                   2597:     } else {
                   2598:         $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 2599:     }
                   2600:     &print_reply($r,$response,$$tasktitleref{$action});
                   2601:     return;
1.1       raeburn  2602: }
                   2603: 
1.34      raeburn  2604: sub get_ownerinfo {
                   2605:     my ($dom,$owner) = @_; 
1.44      raeburn  2606:     my ($ownername,$owneremail,$own_uname,$own_udom);
1.34      raeburn  2607:     if ($owner) {
1.44      raeburn  2608:         if ($owner =~ /^([^:]+):([^:]+)$/) {
                   2609:             $own_uname = $1;
                   2610:             $own_udom = $2; 
                   2611:         } else {
                   2612:             $own_uname = $owner;
                   2613:             $own_udom = $dom; 
                   2614:         }
                   2615:         $ownername=&Apache::loncommon::plainname($own_uname,$own_udom,
                   2616:                                                  'firstname');
1.36      raeburn  2617:         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
1.44      raeburn  2618: 					     $own_udom,$own_uname);
1.34      raeburn  2619:         $owneremail = $ownerinfo{'permanentemail'};
                   2620:     }
                   2621:     return ($ownername,$owneremail);
                   2622: }
                   2623: 
1.1       raeburn  2624: sub print_update_result () {
1.15      albertel 2625:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2626:     my $response = '';
                   2627:     my $updateadds = 0;
                   2628:     my $updatedrops = 0;
                   2629:     my $changecount = 0;
                   2630:     my %affiliates = ();
                   2631:     my %reply = ();
                   2632:     my @allcourses = ();
                   2633:     my %LC_code = ();
                   2634:     my $logmsg = '';
                   2635:     my $newusermsg = '';
1.34      raeburn  2636:     my %phototypes = ();
1.37      raeburn  2637:     my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.showphoto'],$dom,$crs);
1.15      albertel 2638:     my $coursecode = $settings{'internal.coursecode'};
                   2639:     my $authtype = $settings{'internal.authtype'};
                   2640:     my $autharg = $settings{'internal.autharg'};
1.37      raeburn  2641:     my $showphotos = $settings{'internal.showphoto'};
1.15      albertel 2642:     my ($startaccess,$endaccess) = &get_dates_from_form();
1.23      albertel 2643:     if ( exists($env{'form.updateadds'}) ) {
                   2644:         $updateadds = $env{'form.updateadds'};
1.15      albertel 2645:     }
1.23      albertel 2646:     if ( exists($env{'form.updatedrops'}) ) {
                   2647:         $updatedrops = $env{'form.updatedrops'};
1.15      albertel 2648:     }
1.19      raeburn  2649:     if (($startaccess eq '') || ($endaccess eq '')) {
                   2650:         $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 />"; 
                   2651:     } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
                   2652:         $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";
                   2653:     } elsif (!$updateadds && !$updatedrops) {
1.15      albertel 2654: 	$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.";
                   2655:     } elsif ($coursecode eq '') {
                   2656: 	$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";
                   2657:     } else {
1.53      raeburn  2658:         &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);
1.15      albertel 2659: 	if (@allcourses > 0) {
                   2660: 	    @{$affiliates{$crs}} = @allcourses;
                   2661: 	    my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);
1.19      raeburn  2662:             unless ($outcome eq 'ok') {
                   2663:                 &Apache::lonnet::logthis("lonpopulate:update roster".
                   2664:                                          "failed to retrieve classlist".
                   2665:                                  " data for ".$crs."\@".$dom." by ".
1.23      albertel 2666:                                  $env{'user.name'}." \@ ".$env{'user.domain'}.
1.19      raeburn  2667:                                  ": ".$outcome);
                   2668:             }
1.15      albertel 2669: 	    if ($reply{$crs} > 0) {
1.34      raeburn  2670: 		($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes);
1.15      albertel 2671: 	    } else {
                   2672: 		$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.";
                   2673: 	    }  
                   2674: 	} else {
                   2675: 	    $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)";
                   2676: 	}
                   2677:     }
                   2678:     unless ($logmsg eq '') {
                   2679: 	my $loglength = length($logmsg);
                   2680: 	$logmsg = substr($logmsg,0,$loglength-4);
                   2681: 	$logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
                   2682:     }
                   2683:     unless ($newusermsg eq '') {
                   2684: 	$newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
1.19      raeburn  2685: 	$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 2686:     }
                   2687:     $response .= $logmsg.$newusermsg;
                   2688:     &print_reply($r,$response,$$tasktitleref{$action});
                   2689:     return;
1.10      raeburn  2690: }
                   2691: 
1.14      raeburn  2692: sub print_viewclass_response {
                   2693:     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
                   2694:     my $response;
                   2695:     my $chgtotal = 0;
                   2696:     my $chgok = 0;
                   2697:     my $chgfail = 0;
                   2698:     my $othdom = 0;
1.16      raeburn  2699:     my $locktotal = 0;
                   2700:     my $lockok = 0;
                   2701:     my $lockfail = 0;
1.14      raeburn  2702:     my $cid = $dom."_".$crs;
                   2703:     my %chg = ();
                   2704:     my %nochg = ();
                   2705:     my %otherdom = ();
1.16      raeburn  2706:     my %lockchg = ();
                   2707:     my %nolockchg = ();
1.27      albertel 2708:     my $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2709:     my $endidx = &Apache::loncoursedata::CL_END;
                   2710:     my $startidx = &Apache::loncoursedata::CL_START;
                   2711:     my $ididx=&Apache::loncoursedata::CL_ID;
                   2712:     my $secidx=&Apache::loncoursedata::CL_SECTION;
                   2713:     my $typeidx=&Apache::loncoursedata::CL_TYPE;
1.16      raeburn  2714:     my $lockedidx=&Apache::loncoursedata::CL_LOCKEDTYPE;
                   2715:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chgauto','chgmanual','lockchg','unlockchg']);
1.24      albertel 2716:     my @typechglist = (&Apache::loncommon::get_env_multiple('form.chgauto'),
                   2717: 		       &Apache::loncommon::get_env_multiple('form.chgmanual'));
                   2718:     my @lockchglist = (&Apache::loncommon::get_env_multiple('form.lockchg'),
                   2719: 		       &Apache::loncommon::get_env_multiple('form.unlockchg'));
                   2720: 
1.16      raeburn  2721:     foreach my $student (sort @typechglist) {
1.51      raeburn  2722:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  2723:         my $sdata    = $classlist->{$student};
                   2724:         my $section  = $sdata->[$secidx];
                   2725:         my $uid       = $sdata->[$ididx];
                   2726:         my $start    = $sdata->[$startidx];
                   2727:         my $end      = $sdata->[$endidx];
                   2728:         my $type     = $sdata->[$typeidx];
                   2729:         my $lock   = $sdata->[$lockedidx];
                   2730:         my $newlock = $lock;
                   2731:         $chgtotal ++;
                   2732:         my $newtype = 'auto';
                   2733:         my $change = 'auto';
                   2734:         my $oldtype = 'manual';
                   2735:         if ($type eq 'auto') { 
                   2736:             $oldtype = 'auto';
                   2737:             $newtype = '';
                   2738:             $change = 'manual';
                   2739:         }
                   2740:         if ($udom eq $dom) {
                   2741:             if ($newtype eq 'auto') {
                   2742:                 $newlock = '';
                   2743:             } elsif ($newtype eq '') {
                   2744:                 $newlock = '1';
1.14      raeburn  2745:             }
1.55      raeburn  2746:             my $modreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$newtype,$newlock,$cid,'','chgtype');
1.16      raeburn  2747:             if ($modreply eq 'ok') {
                   2748:                 $chgok ++;
                   2749:                 $chg{$student} = "Changed to $change";
                   2750:             } else {
                   2751:                 $chgfail ++;
                   2752:                 $nochg{$student} = "Still set to $oldtype";
                   2753:             } 
                   2754:         } else {
                   2755:             $othdom ++;
                   2756:             $otherdom{$student} = "Still set to $oldtype"; 
                   2757:         }
                   2758:     }
                   2759:     foreach my $student (@lockchglist) {
1.51      raeburn  2760:         my ($uname,$udom) = split(/:/,$student);
1.16      raeburn  2761:         my $sdata    = $classlist->{$student};
                   2762:         my $section  = $sdata->[$secidx];
                   2763:         my $uid       = $sdata->[$ididx];
                   2764:         my $start    = $sdata->[$startidx];
                   2765:         my $end      = $sdata->[$endidx];
                   2766:         my $type     = $sdata->[$typeidx];
                   2767:         my $lock   = $sdata->[$lockedidx];
                   2768:         my $newlock = 1;
                   2769:         my $oldlockname = &mt('unlocked');
                   2770:         my $newlockname = &mt('locked');
                   2771:         $locktotal++;
                   2772:         unless ($type eq 'auto') {
                   2773:             if ($lock) {
                   2774:                 $newlock = '';
                   2775:                 $newlockname = &mt('unlocked');
                   2776:                 $oldlockname = &mt('locked'); 
                   2777:             }
1.55      raeburn  2778:             my $lockreply = &Apache::lonnet::modify_student_enrollment($udom,$uname,$uid,'','','','',$section,$end,$start,$type,$newlock,$cid,'','chgtype');
1.16      raeburn  2779:             if ($lockreply eq 'ok') {
                   2780:                 $lockok ++;
                   2781:                 $lockchg{$student} = 'Changed to '.$newlockname;
1.14      raeburn  2782:             } else {
1.16      raeburn  2783:                 $lockfail ++;
                   2784:                 $nolockchg{$student} = 'Still set to '.$oldlockname;
1.14      raeburn  2785:             }
                   2786:         }
                   2787:     }
                   2788:     if ($chgtotal > 0) {
1.51      raeburn  2789:         $response = &mt('You requested a change in enrollment type for [quant,_1,student].',$chgtotal).'<br /><br />'."\n";
1.27      albertel 2790:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.14      raeburn  2791:         if ($chgok > 0) {
1.51      raeburn  2792:             $response .= &mt('The following [quant,_1,change was,changes were] successful;',$chgtotal).':<br /><br />';
1.14      raeburn  2793:             $response .= &enrolltype_result(\%chg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2794:         }
                   2795:         if ($chgfail > 0) {
1.51      raeburn  2796:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$chgfail).':&nbsp;<br />';
1.14      raeburn  2797:             $response .= &enrolltype_result(\%nochg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2798:         }
                   2799:         if ($othdom > 0) {
1.51      raeburn  2800:             $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  2801:             $response .= &enrolltype_result(\%otherdom,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx);
                   2802:         }
1.16      raeburn  2803:         $response .= "<br /><br />";
                   2804:     }
                   2805:     if ($locktotal > 0) {
1.51      raeburn  2806:         $response .= &mt('You requested locking/unlocking for [quant,_1,manually enrolled student]',$locktotal).'<br /><br />'."\n";
1.27      albertel 2807:         $classlist = &Apache::loncoursedata::get_classlist($dom,$crs);
1.16      raeburn  2808:         if ($lockok > 0) {
1.51      raeburn  2809:             $response .= &mt('The following [quant,_1,change was,changes were] successful',$lockok).':<br /><br />';
1.16      raeburn  2810:             $response .= &enrolltype_result(\%lockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2811:         }
                   2812:         if ($lockfail > 0) {
1.51      raeburn  2813:             $response .= &mt('The following [quant,_1,student was,students were] not modified successfully',$lockfail).':&nbsp;<br />';
1.16      raeburn  2814:             $response .= &enrolltype_result(\%nolockchg,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx);
                   2815:         }
1.14      raeburn  2816:     }
                   2817:     &print_reply($r,$response,$$tasktitleref{$action});
                   2818:     return;
                   2819: }
                   2820: 
                   2821: sub enrolltype_result {
1.16      raeburn  2822:     my ($changes,$classlist,$endidx,$startidx,$ididx,$secidx,$typeidx,$lockedidx) = @_;
1.51      raeburn  2823:     my $reply = &Apache::loncommon::start_data_table().
                   2824:                 &Apache::loncommon::start_data_table_header_row().'
1.14      raeburn  2825:               <th>username</th>
                   2826:               <th>domain</th>
                   2827:               <th>ID</th>
                   2828:               <th>student name</th>
                   2829:               <th>section</th>
                   2830:               <th>start date</th>
                   2831:               <th>end date</th>
1.51      raeburn  2832:               <th>enrollment change</th>'."\n".
                   2833:                 &Apache::loncommon::end_data_table_header_row();
                   2834:     foreach my $chg (sort keys %{$changes}) {
                   2835:         my $sdata  = $classlist->{$chg};
                   2836:         my ($uname,$udom) = split(/:/,$chg);
1.14      raeburn  2837:         my $section  = $sdata->[$secidx];
                   2838:         my $uid      = $sdata->[$ididx];
                   2839:         my $start    = $sdata->[$startidx];
                   2840:         my $end      = $sdata->[$endidx];
                   2841:         my $type     = $sdata->[$typeidx];
                   2842:         if (! defined($start) || $start == 0) {
                   2843:             $start = &mt('none');
                   2844:         } else {
                   2845:             $start = &Apache::lonlocal::locallocaltime($start);
                   2846:         }
                   2847:         if (! defined($end) || $end == 0) {
                   2848:             $end = &mt('none');
                   2849:         } else {
                   2850:             $end = &Apache::lonlocal::locallocaltime($end);
                   2851:         }
                   2852:         if (!defined($section) || ($section eq '')) {
1.51      raeburn  2853:             $section = '&nbsp;';
1.14      raeburn  2854:         }
                   2855:         if (!defined($uid) || ($uid eq '')) {
1.51      raeburn  2856:             $uid = '&nbsp;';
1.14      raeburn  2857:         }
1.51      raeburn  2858:         $reply .= &Apache::loncommon::start_data_table_row().' 
                   2859:               <td>'.$uname.'</td>
                   2860:               <td>'.$udom.'</td>
                   2861:               <td>'.$uid.'</td>
                   2862:               <td>'.&Apache::loncommon::plainname($uname,$udom).'</td>
                   2863:               <td>'.$section.'</td>
                   2864:               <td>'.$start.'</td>
                   2865:               <td>'.$end.'</td>
                   2866:               <td>'.$$changes{$chg}.'</td>'."\n".
                   2867:              &Apache::loncommon::end_data_table_row();
1.14      raeburn  2868:     }
1.51      raeburn  2869:     $reply .= &Apache::loncommon::end_data_table();
1.14      raeburn  2870:     return $reply;
                   2871: }
                   2872: 
1.10      raeburn  2873: sub warning_message {
                   2874:     my ($dom,$crs,$caller) = @_;
                   2875:     my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
                   2876:     my $currend = '';
                   2877:     my $currstart = '';
                   2878:     my $currsecs = '';
                   2879:     my $currxlists = '';
                   2880:     my $warning = '';
                   2881:     my $curradds = '';
                   2882:     my $currdrops = '';
                   2883:     if ( defined($settings{'internal.autoadds'}) ) {
                   2884:         $curradds = $settings{'internal.autoadds'};
                   2885:     }
                   2886:     if (defined($settings{'internal.autodrops'}) ) {
                   2887:         $currdrops = $settings{'internal.autodrops'};
                   2888:     }
                   2889:     if ( defined($settings{'internal.autostart'}) ) {
                   2890:         $currstart = $settings{'internal.autostart'};
                   2891:     }
                   2892:     if ( defined($settings{'internal.autoend'}) ) {
                   2893:         $currend = $settings{'internal.autoend'};
                   2894:     }
                   2895:     if ( defined($settings{'internal.sectionnums'}) ) {
                   2896:         $currsecs = $settings{'internal.sectionnums'};
                   2897:     }
                   2898:     if ( defined($settings{'internal.crosslistings'}) ) {
                   2899:         $currxlists = $settings{'internal.crosslistings'}
                   2900:     }
                   2901:     unless ($caller eq 'setdates') {
                   2902:         if ( ($currstart eq '') && ($currend eq '') )  {
                   2903:             $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>";
                   2904:         }
                   2905:     }
                   2906:     unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
                   2907:         if ( ($currsecs eq '') && ($currxlists eq '') ) {
                   2908:             $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/>";
                   2909:         }
                   2910:     }
                   2911:     unless ( $caller eq 'chgsettings') {
                   2912:         if ( (!$curradds) && (!$currdrops) ) {
                   2913:             $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/>.";
                   2914:         }
                   2915:     }
                   2916:     return $warning;
1.1       raeburn  2917: }
                   2918: 
                   2919: sub print_reply () {
                   2920:   my ($r,$response,$caller) = @_;
                   2921:   $r->print("
                   2922:             <br/><table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">
                   2923:              <tr>
1.14      raeburn  2924:               <td align=\"left\"><b>$caller</b> - result<br/><br/>$response</td>
1.1       raeburn  2925:              </tr>
                   2926:             </table>
                   2927:   ");
                   2928:   return;
                   2929: }
                   2930: 
                   2931: sub setup_date_selectors {
1.14      raeburn  2932:     my ($starttime,$endtime,$action) = @_;
1.1       raeburn  2933:     if (! defined($starttime)) {
                   2934:         $starttime = time;
1.14      raeburn  2935:         if ($action eq 'setdates') {
1.23      albertel 2936:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2937:                             '.default_enrollment_start_date'})) {
1.23      albertel 2938:                 $starttime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2939:                                   '.default_enrollment_start_date'};
1.14      raeburn  2940:             }
1.1       raeburn  2941:         }
                   2942:     }
                   2943:     if (! defined($endtime)) {
                   2944:         $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1.14      raeburn  2945:         if ($action eq 'setdates') {
1.23      albertel 2946:             if (exists($env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2947:                             '.default_enrollment_end_date'})) {
1.23      albertel 2948:                 $endtime = $env{'course.'.$env{'request.course.id'}.
1.1       raeburn  2949:                                 '.default_enrollment_end_date'};
1.14      raeburn  2950:             }
1.1       raeburn  2951:         }
                   2952:     }
                   2953:     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2954:                                                             'startdate',
                   2955:                                                             $starttime);
                   2956:     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                   2957:                                                           'enddate',
                   2958:                                                           $endtime);
                   2959:     return ($startdateform,$enddateform);
                   2960: }
                   2961: 
                   2962: sub get_dates_from_form {
1.14      raeburn  2963:     my $startdate;
                   2964:     my $enddate;
                   2965:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
                   2966:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate');
1.23      albertel 2967:     if ( exists ($env{'form.no_end_date'}) ) {
1.1       raeburn  2968:         $enddate = 0;
                   2969:     }
                   2970:     return ($startdate,$enddate);
                   2971: }
                   2972: 
                   2973: sub date_setting_table {
1.14      raeburn  2974:     my ($starttime,$endtime,$action) = @_;
                   2975:     my ($startform,$endform) = &setup_date_selectors($starttime,$endtime,$action);
1.57      bisitz   2976:     my $perpetual = '<span class="LC_nobreak"><label><input type="checkbox" name="no_end_date"';
1.14      raeburn  2977:     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || (($action eq 'setaccess' || $action eq 'updatenow') && ($endtime eq '' || $endtime == 0)) ) {
1.1       raeburn  2978:         $perpetual .= ' checked';
                   2979:     }
1.57      bisitz   2980:     $perpetual.= ' />'.' no ending date</label></span>';
1.1       raeburn  2981:     my $start_table = '';
                   2982:     $start_table .= "<table>\n";
                   2983:     $start_table .= '<tr><td align="right">Starting Date</td>'.
                   2984:         '<td>'.$startform.'</td>'.
                   2985:         '<td>&nbsp;</td>'."</tr>\n";
                   2986:     $start_table .= "</table>";
                   2987:     my $end_table = '';
                   2988:     $end_table .= "<table>\n";
                   2989:     $end_table .= '<tr><td align="right">Ending Date</td>'.
                   2990:         '<td>'.$endform.'</td>'.
                   2991:         '<td>'.$perpetual.'</td>'."</tr>\n";
                   2992:     $end_table .= "</table>\n";
                   2993:     return ($start_table, $end_table);
                   2994: }
                   2995: 
1.42      raeburn  2996: sub validate_lcsec {
                   2997:     my ($curr_groups,$lcsec) = @_;
                   2998:     if (($lcsec eq 'all') || ($lcsec eq 'none')) {
                   2999:         return 'reserved';
                   3000:     } else {
                   3001:         if (exists($$curr_groups{$lcsec})) {
                   3002:             return 'group'; 
                   3003:         }
                   3004:     }
                   3005:     return 'ok';
                   3006: }
                   3007: 
1.48      albertel 3008: sub user_is_courseowner {
                   3009:     my ($courseowner) = @_;
                   3010:     my $user;
                   3011:     if ($courseowner =~ /^[^:]+:[^:]+$/) {
                   3012: 	$user = $env{'user.name'}.':'.$env{'user.domain'};
                   3013:     } else {
                   3014: 	$user = $env{'user.name'};
                   3015:     }
                   3016:     return ($user eq $courseowner);
                   3017: }
                   3018:     
1.1       raeburn  3019: ###################################################################
                   3020: sub handler {
                   3021:     my $r = shift;
                   3022:     if ($r->header_only) {
1.22      albertel 3023: 	&Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3024:         $r->send_http_header;
                   3025:         return OK;
                   3026:     }
                   3027:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','state']);
                   3028:     #  Needs to be in a course
1.23      albertel 3029:     if (! (($env{'request.course.fn'}) &&  (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) {
1.1       raeburn  3030:         # Not in a course, or not allowed to modify parms
1.23      albertel 3031:         $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
1.34      raeburn  3032:         return HTTP_NOT_ACCEPTABLE;
1.1       raeburn  3033:     }
                   3034:     # Start page
1.22      albertel 3035:     &Apache::loncommon::content_type($r,'text/html');
1.1       raeburn  3036:     $r->send_http_header;
                   3037: 
1.34      raeburn  3038:     my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","updatephotos","viewclass");
1.1       raeburn  3039:                                                                                  
                   3040:     my %tasklong = (
                   3041:                information => "Task information",
                   3042:                chgsettings => "Automated adds/drops",
                   3043:                setdates => "Change enrollment dates",
1.14      raeburn  3044:                setaccess => "Change access dates",
1.1       raeburn  3045:                notify => "Notification of changes",
                   3046:                crosslist => "Change crosslistings",
                   3047:                sections => "Section settings",
1.34      raeburn  3048:                photos => "Student photo settings",
                   3049:                updatephotos => "Update student photos",
1.1       raeburn  3050:                updatenow => "Update roster now",
                   3051:                newcross => "Add crosslistings",
1.14      raeburn  3052:                newsections => "Add sections",
1.16      raeburn  3053:                viewclass => "View students and change type",
1.1       raeburn  3054:     );
                   3055:                                                                                  
                   3056:     my %tasktitle = (
                   3057:                chgsettings => "Changes to nightly automated enrollments",
                   3058:                setdates => "Changes to first and/or last automated enrollment dates",
1.14      raeburn  3059:                setaccess => "Changes to default start and/or end dates for student access",
1.1       raeburn  3060:                notify => "Notification of enrollment changes",
                   3061:                crosslist => "Changes to crosslistings",
                   3062:                sections => "Changes to section settings",
1.34      raeburn  3063:                photos => "Student photo settings",
                   3064:                updatephotos => "Update student photos",
1.1       raeburn  3065:                updatenow => "Immediate course roster update",
                   3066:                newcross => "Adding new crosslisted courses",
1.14      raeburn  3067:                newsections => "Adding new course sections",
                   3068:                viewclass => "Viewing class roster and enrollment type"
1.1       raeburn  3069:     );
                   3070: 
                   3071:     my $realm = '';
1.23      albertel 3072:     if ( exists($env{'request.course.id'}) ) {
                   3073:         $realm= $env{'course.'.$env{'request.course.id'}.'.description'};
1.1       raeburn  3074:     }
                   3075:     unless ($realm) { $realm='&nbsp;'; }
1.23      albertel 3076:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   3077:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1       raeburn  3078:     
                   3079:     #
                   3080:     # Main switch on form.action and form.state, as appropriate
                   3081:     #
                   3082: 
                   3083:     my $action = "information";
1.23      albertel 3084:     if ( exists($env{'form.action'}) ) {
                   3085:         $action = $env{'form.action'};
1.1       raeburn  3086:     }
                   3087:     my $state = "choose";
                   3088: 
1.23      albertel 3089:     if ( exists($env{'form.state'}) ) {
                   3090:         $state = $env{'form.state'};
1.1       raeburn  3091:     }
                   3092: 
                   3093:     if ($action eq "information") {
                   3094:         $r->print(&header()); 
                   3095:     } else {
                   3096:         if ($state eq "choose") {
1.16      raeburn  3097:             $r->print(&choose_header($action));
1.1       raeburn  3098:         } else {
                   3099:             if ($action eq "crosslist") {
1.23      albertel 3100:                 if ( exists($env{'form.numcross'}) ) {
                   3101:                     if ( $env{'form.numcross'} > 0 ) {
1.16      raeburn  3102:                         $r->print(&choose_header($action));
1.1       raeburn  3103:                     } else {
                   3104:                         $r->print(&header());
                   3105:                     }
                   3106:                 } else {
                   3107:                     $r->print(&header());
                   3108:                 }
                   3109:             } elsif ($action eq "sections") {
1.23      albertel 3110:                 if ( exists($env{'form.numsec'}) ) {
                   3111:                     if ( $env{'form.numsec'} > 0 ) {
1.16      raeburn  3112:                         $r->print(&choose_header($action));
1.1       raeburn  3113:                     } else {
                   3114:                         $r->print(&header());
                   3115:                     }
                   3116:                 } else {
                   3117:                     $r->print(&header());
                   3118:                 }
                   3119:             } else {
                   3120:                 $r->print(&header());
                   3121:             }
                   3122:         }
                   3123:     }
1.12      raeburn  3124: 
1.1       raeburn  3125:     my $reply = 0;
                   3126:     unless ($state eq "choose") { $reply = 1; }
                   3127: 
                   3128:     &print_mainbox($r,\%tasklong,$realm,$reply);
                   3129:     &print_navmenu($r,\@tasks,\%tasklong);
                   3130:     
                   3131:     if (($state eq "choose") || ($action eq "information")) {
1.13      raeburn  3132:         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);
1.1       raeburn  3133:     } elsif ($action eq "chgsettings") {
                   3134:         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3135:     } elsif ($action eq "setdates") {
                   3136:         &print_setdates_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3137:     } elsif ($action eq "setaccess") {
                   3138:         &print_setaccess_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3139:     } elsif ($action eq "notify") {
                   3140:         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3141:     } elsif ($action eq "sections") {
1.13      raeburn  3142:         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3143:     } elsif ($action eq "crosslist") {
1.13      raeburn  3144:         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3145:     } elsif ($action eq "updatenow") {
1.13      raeburn  3146:         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3147:     } elsif ($action eq "photos") {
1.34      raeburn  3148:         if ($state eq "photoupdate") {
                   3149:             &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3150:         } else { 
                   3151:             &photo_permission($r,$realm,$dom,$crs,$action,\%tasktitle);
                   3152:         }
                   3153:     } elsif ($action eq "updatephotos") {
                   3154:         &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3155:     } elsif ($action eq "newcross") {
1.13      raeburn  3156:         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);    
1.1       raeburn  3157:     } elsif ($action eq "newsections") {
1.13      raeburn  3158:         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.14      raeburn  3159:     } elsif ($action eq "viewclass") {
                   3160:         &print_viewclass_response($r,$realm,$dom,$crs,$action,\%tasktitle);
1.1       raeburn  3161:     }
                   3162:     &print_doc_base($r);  
                   3163:     return OK;
                   3164: }
                   3165: ###################################################################
                   3166: 1;

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