Diff for /loncom/interface/lonpopulate.pm between versions 1.4 and 1.12

version 1.4, 2003/12/09 20:06:37 version 1.12, 2004/06/08 22:09:44
Line 27  package Apache::lonpopulate; Line 27  package Apache::lonpopulate;
   
 use strict;  use strict;
 use lib qw(/home/httpd/lib/perl);  use lib qw(/home/httpd/lib/perl);
 use Apache::lonnet ();  use Apache::lonnet;
 use Apache::loncommon ();  use Apache::loncommon;
 use Apache::lonhtmlcommon ();  use Apache::lonhtmlcommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::Constants qw(:common :http REDIRECT);  use Apache::Constants qw(:common :http REDIRECT);
 use Time::Local;  use Time::Local;
 use LONCAPA::Enrollment ();  use LONCAPA::Enrollment;
 use localenroll;  use localenroll;
   
 ###############################################################  ###############################################################
Line 207  ENDONE Line 207  ENDONE
 ###############################################################  ###############################################################
   
 sub print_main_frame {  sub print_main_frame {
   my ($r,$realm,$dom,$crs,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$tasktitleref,$homeserver,$server) = @_;
   my $action = "information";    my $action = "information";
   if (exists($ENV{'form.action'}) ) {    if (exists($ENV{'form.action'}) ) {
       $action = $ENV{'form.action'};        $action = $ENV{'form.action'};
Line 329  Note: Any students added manually by cou Line 329  Note: Any students added manually by cou
       ");        ");
   } elsif ($action eq "setdates") {    } elsif ($action eq "setdates") {
       my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend});        my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend});
       my $oldstartshow = localtime($enrollvar{autostart});        my $oldstartshow = '';
       my $oldendshow = localtime($enrollvar{autoend});        my $oldendshow = '';
       if ($enrollvar{autoend} == 0) {        if ( defined($enrollvar{autostart}) ) {
           $oldendshow = "No ending date";            $oldstartshow = localtime($enrollvar{autostart});
         }
         if ( defined($enrollvar{autoend}) ) {
             $oldendshow = localtime($enrollvar{autoend});
             if ($enrollvar{autoend} == 0) {
                 $oldendshow = "No ending date";
             }
         }
         my $dateshow;
         if ( ($oldendshow eq '') && ($oldstartshow eq '') ) {
            $dateshow = "<br/><font size='+1'>Warning</font>. 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 (or check the 'no ending date' checkbox) if you plan to utilise automated adds and/or drops in this course.\n";
         } else {
            $dateshow = "Currently: First enrollment: <b><i>$oldstartshow</i></b>, Last enrollment: <b><i>$oldendshow</i></b>\n";
       }        }
       $r->print(<<ENDTWO);        $r->print(<<ENDTWO);
                   <form name="enter" method="post"><br/>                                  <form name="enter" method="post"><br/>              
                   <table width="100%" border="0" cellpadding="2" cellspacing="2">                    <table width="100%" border="0" cellpadding="2" cellspacing="2">
            <tr>             <tr>
             <td align="left"><b>$$tasktitleref{$action}</b><br/>              <td align="left"><b>$$tasktitleref{$action}</b><br/><br/>
              Currently: First enrollment: <i>$oldstartshow</i>, Last enrollment: <i>$oldendshow</i>                       $dateshow
             </td>              </td>
                    </tr>                     </tr>
           </table>            </table>
Line 439  ENDTWO Line 451  ENDTWO
               </td>                </td>
              </tr>               </tr>
       ");        ");
       my $option_str = '';        my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs);
       my $lastpname = '';        my @ccs = ();
       my $option_count = 0;        my @oldccs = ();
         my %pname = ();
       my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($dom.'/'.$crs);        my %notifystate = ();
       foreach (sort keys %coursepersonnel) {        foreach (@coursepersonnel) {
           if ($_ eq &mt("Course Coordinator") )            my @roleinfo = split/:/,$_;
           {            if ($roleinfo[0] eq 'cc')  {
               my @ccs = ();                unless (grep/^$roleinfo[1]\@$roleinfo[2]/,@ccs) {
               if ($coursepersonnel{$_} =~ m/,/) {                    my $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc');
                   @ccs = split(/,/,$coursepersonnel{$_});                    if ($active_cc eq 'ok') {
               } else {                        push @ccs, "$roleinfo[1]\@$roleinfo[2]";
                   @ccs = $coursepersonnel{$_};                        $pname{"$roleinfo[1]\@$roleinfo[2]"} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
               }                        if (grep/^$roleinfo[1]\@$roleinfo[2]$/,@notified) {
               foreach (@ccs) {                            $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 1;
                   my ($puname,$pudom)=split(/\:/,$_);                        } else {
                   my $pname = &Apache::loncommon::plainname($puname,$pudom);                            $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 0;
                   if (grep/^$puname\@$pudom$/,@notified) {                        }
                       $option_str .="<option value=\"$puname\@$pudom\" selected>$pname</option>\n";  
                   } else {                    } else {
                       $option_str .="<option value=\"$puname\@$pudom\">$pname</option>\n";                        push @oldccs, "$roleinfo[1]\@$roleinfo[2]";
                   }                    }
                   $option_count ++;  
                   $lastpname = $pname.'@'.$pudom;  
               }                }
           }            }
       }        }
       if ($option_count > 1) {        if ($notifycount > 0) {
           my $optionsize = $option_count;            foreach my $person (@notified) {
           if ($optionsize > 6) {                unless ( (grep/^$person$/,@ccs) || ($person eq '') || (grep/^$person$/,@oldccs) ) {
               $optionsize = 6;                    push @ccs, $person;
           }                     my ($puname,$pdom) = split/\@/,$person;
                     $pname{$person} =  &Apache::loncommon::plainname($puname,$pdom);
                     $notifystate{$person} = 1;
                 }
             }
         }
         my $viewer = $ENV{'user.name'}.'@'.$ENV{'user.domain'};
         unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') )  {
             push @ccs,$viewer;
             $pname{$viewer} =  &Apache::loncommon::plainname($ENV{'user.name'},$ENV{'user.domain'});
             $notifystate{$viewer} = 0;
         }
   
         my $notifyshow = @ccs;
   
         if (@ccs > 0) {
             @ccs = sort @ccs;
           $r->print("            $r->print("
              <tr>               <tr>
               <td>                 <td>The table below contains a list of course coordinators in this course. Uncheck the 'Notification?' checkbox for each person who is to be removed from the list of recipients who are currently informed of roster changes whenever any adds or drops occur during the nightly enrollment check. To include individuals who are not currently recipients, simply check the 'Notification?' checkbox. Click 'Go' to store your changes.
 Select which course coordinators should receive information about roster changes whenever any adds or drops occur during the nightly enrollment check.<br/><br/>  
                 <select name=\"notifylist\" multiple size=\"$optionsize\">$option_str</select>  
               </td>                </td>
              </tr>               </tr>
              <tr>               <tr>
               <td>                <td>
                Select more than one recipient by using the following keyboard and mouse combinations:<br/>                 <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
              <ul>                  <tr bgcolor=\"#CCCCFF\">
               <li>Apple-click: MacOS</li>                   <td><b>Name</b></td>
               <li>Ctrl-click: Windows</li>                   <td><b>username</b></td>
               <li>Left click: Linux</li>                   <td><b>Current status</b></td>
              </ul>                   <td><b>Notification?</b></td>
             </td>                  </tr>
            </tr>   
           ");            ");
       } else {             for (my $i=0; $i<@ccs; $i++) {
                 my $colflag = $i%2;
                 $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    <td>$pname{$ccs[$i]}</td>
                    <td><input type=\"hidden\" name=\"notifyname_$i\" value=\"$ccs[$i]\" />$ccs[$i]</td>
                    <td>
                 ");
                 if ($notifystate{$ccs[$i]} == 1) {
                     $r->print("Notification active");
                 } else {
                     $r->print("Notification inactive");
                 }
                 if ($notifystate{$ccs[$i]} == 1) {
                     $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" checked=\"true\" /></td></tr>");
                 } else {
                     $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" /></td></tr>");
                 }
             }
           $r->print("            $r->print("
            <tr>                 </table>
             <td>                 <br/>
 As you are the only user with the role of course coordinator in this course, if you choose to enable notification of roster changes, you will be the sole recipient of LON-CAPA messages generated whenever any adds or drops occur during the nightly enrollment check.                 <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
               <input type=\"hidden\" name=\"notifylist\" value=\"$lastpname\" />                  <tr>
             </td>                   <td align=\"right\">
            </tr>                    <input type=\"button\" name=\"notifyset\" value=\"Go\" onClick=\"process('notify')\" />
                    </td>
                   </tr>
                  </table>
                 </td>
                </tr>
           ");            ");
         } else {
             $r->print("
                <tr>
                 <td>
                No course coordinators found.
               </td>
              </tr>");
       }        }
       $r->print("        $r->print("
              <tr>            </table>
               <td align=\"right\">            <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\">
                <input type=\"button\" name=\"notifyset\" value=\"Go\" onClick=\"process('notify')\" />            <input type=\"hidden\" name=\"action\" value=\"$action\">
               </td>            <input type=\"hidden\" name=\"state\" value=\"process\">
              </tr>            </form>
             </table>  
             <input type=\"hidden\" name=\"action\" value=\"$action\">  
             <input type=\"hidden\" name=\"state\" value=\"process\">  
             </form>  
       ");        ");
   } elsif ($action eq "crosslist") {    } elsif ($action eq "crosslist") {
       my @xlists = ();        my @xlists = ();
Line 526  As you are the only user with the role o Line 573  As you are the only user with the role o
       ");        ");
       if ($cross_str > 0) {        if ($cross_str > 0) {
           $r->print("            $r->print("
                 Currently, LON-CAPA course: $realm ($enrollvar{coursecode}) 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/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group 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 store your changes.                  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/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group 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 store your changes.
               </td>                </td>
              </tr>               </tr>
             </table>              </table>
Line 594  As you are the only user with the role o Line 641  As you are the only user with the role o
             </form>               </form> 
       ");        ");
   } elsif ($action eq "sections") {    } elsif ($action eq "sections") {
       my @sections = &localenroll::get_sections($enrollvar{coursecode});        my @sections = ();
         @sections = &Apache::lonnet::auto_get_sections($homeserver,$enrollvar{coursecode});
       my @storedsections = ();        my @storedsections = ();
       my @currsections = ();        my @currsections = ();
       my %sec_id = ();        my %sec_id = ();
Line 610  As you are the only user with the role o Line 658  As you are the only user with the role o
           }            }
       }        }
       if (@sections > 0) {        if (@sections > 0) {
           if (@sections > 1) {            my $secshow = @sections;
               my $secshow = @sections;            $r->print("
               $r->print("  
             <form name=\"enter\" method=\"post\"><br/>              <form name=\"enter\" method=\"post\"><br/>
             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">              <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
              <tr>               <tr>
Line 622  As you are the only user with the role o Line 669  As you are the only user with the role o
               </td>                </td>
              </tr>               </tr>
              <tr>               <tr>
               <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/group designation used for this section in LON-CAPA, delete the currecnt value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. 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 store your changes.</td>                <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/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. To add a new section, check the 'Enrollment in this course?' checkbox, and enter the desired LON-CAPA section/groupID in the appropriate textbox. Click 'Go' to store
   your changes.</td>
              </tr>               </tr>
             </table>              </table>
             <br/>              <br/>
             <table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">              <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
              <tr>               <tr bgcolor=\"#CCCCFF\">
               <td>                <td><b>Section</b></td>
                <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">                <td><b>Current status</b></td>              
                 <tr bgcolor=\"#CCCCFF\">                <td><b>LON-CAPA section/group ID</b></td>
                  <td><b>Course code</b>/td>                <td><b>Enrollment in this course?</b></td>
                  <td><b>Current status</b></td>                             </tr>
                  <td><b>LON-CAPA section/group ID</b></td>            ");
                  <td><b>Enrollment in this course?</b></td>            for (my $i=0; $i<@sections; $i++) {
                 </tr>                my $colflag = $i%2;
               ");                my $shrflag = 0;
               for (my $i=0; $i<@sections; $i++) {                $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                   my $colflag = $i%2;                     <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" /></td>
                   my $shrflag = 0;  
                   $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"center\">  
                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" value=\"$sections[$i]\" />/td>  
                    <td>                     <td>
                   ");  
                   if (grep/^$sections[$i]$/,@currsections) {  
                       $r->print("Enrollment active");  
                       $shrflag = 1;  
                   } else {  
                       $r->print("Enrollment inactive");  
                   }  
                   if ($shrflag) {  
                       $r->print("</td><td><input type=\"text\" name=\"loncapasec_$i\" value=\"$sec_id{$sections[$i]}\"></td><td><input type=\"checkbox\" name=\"sec_$i\" checked=\"true\" /></td></tr>");   
                   } else {  
                       $r->print("</td><td><input type=\"text\" name=\"loncapasec_$i\" value=\"\"><td><input type=\"checkbox\" name=\"sec_$i\" /></td></tr>");  
                   }  
               }  
               $r->print("  
                   </tr>  
                  </table>  
                 </td>  
                </tr>  
               </table>  
               <br/>  
               <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">  
                <tr>   
                 <td align=\"right\">  
                  <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />  
                  <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />  
                 </td>  
                </tr>  
               </table>  
               <input type=\"hidden\" name=\"action\" value=\"$action\">  
               <input type=\"hidden\" name=\"state\" value=\"process\">  
               </form>  
               ");                ");
           } else {                if (grep/^$sections[$i]$/,@currsections) {
               $r->print("<br/>                                $r->print("Enrollment active");
             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">                    $shrflag = 1;
              <tr>                } else {
               <td align=\"left\">                    $r->print("Enrollment inactive");
                <b>$$tasktitleref{$action}</b><br/>                }
                 if ($shrflag) {
                     $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=\"true\" /></td></tr>"); 
                 } else {
                     $r->print("</td><td><input type=\"text\" size=\"10\" name=\"loncapasec_$i\" value=\"\"><td><input type=\"checkbox\" name=\"sec_$i\" /></td></tr>");
                 }
             }
             $r->print("
               </table>
               <br/>
               <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
                <tr> 
                 <td align=\"right\">
                  <input type=\"hidden\" name=\"secshow\" value=\"$secshow\" />
                  <input type=\"button\" name=\"sections\" value=\"Go\" onClick=\"process('sections')\" />
               </td>                </td>
              </tr>               </tr>
             </table>              </table>
             <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">              <input type=\"hidden\" name=\"action\" value=\"$action\">
              <tr>              <input type=\"hidden\" name=\"state\" value=\"process\">
               <td>As your institution's course catalog only includes a single section for this course, there are no additional sections that can be set for inclusion in the LON-CAPA roster for the course.</td>              </form>
             </tr>            ");
            </table>  
               ");  
           }   
       } else {        } else {
           $r->print("            $r->print("
             <form name=\"enter\" method=\"post\"><br/>              <form name=\"enter\" method=\"post\"><br/>
Line 701  As you are the only user with the role o Line 726  As you are the only user with the role o
           if (@currsections) {            if (@currsections) {
               my $secshow = @currsections;                my $secshow = @currsections;
               $r->print("                $r->print("
                 Currently, LON-CAPA course: $realm ($enrollvar{coursecode}) 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/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID 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 store your changes.                  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/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID 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 store your changes.
               </td>                </td>
              </tr>               </tr>
             </table>              </table>
Line 873  ENDBASE Line 898  ENDBASE
 ###################################################################  ###################################################################
 sub print_chgsettings_response {  sub print_chgsettings_response {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs);
   my $curradds = $settings{'internal.autoadds'};    my $currend = '';
   my $currdrops = $settings{'internal.autodrops'};    my $currstart = '';
     my $currsecs = '';
     my $currxlists = '';
     my $curradds = '';
     my $currdrops = '';
     if ( defined($settings{'internal.autoadds'}) ) {
         $curradds = $settings{'internal.autoadds'};
     }
     if ( defined($settings{'internal.autodrops'}) ) {
         $currdrops = $settings{'internal.autodrops'};
     }
     if ( defined($settings{'internal.autostart'}) ) {
         $currstart = $settings{'internal.autostart'};
     }
     if ( defined($settings{'internal.autoend'}) ) {
         $currend = $settings{'internal.autoend'};
     }
     if ( defined($settings{'internal.sectionnums'}) ) {
         $currsecs = $settings{'internal.sectionnums'};
     }
     if ( defined($settings{'internal.crosslistings'}) ) {
         $currxlists = $settings{'internal.crosslistings'}
     }
   my $autoadds = '';    my $autoadds = '';
   my $autodrops = '';    my $autodrops = '';
   
Line 887  sub print_chgsettings_response { Line 934  sub print_chgsettings_response {
   }    }
   
   my $response = "";    my $response = "";
     my $warning = "";
     my $warn_prefix = "";
     my $warn_suffix = "";
     my $warnfiller = "";
   my %cenv = ('internal.autoadds' => $autoadds,    my %cenv = ('internal.autoadds' => $autoadds,
               'internal.autodrops' => $autodrops);                'internal.autodrops' => $autodrops);
   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);    my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
Line 898  sub print_chgsettings_response { Line 949  sub print_chgsettings_response {
               $response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";                $response = "Nightly additions based on classlist changes still <b>enabled</b><br/>";
           } else {            } else {
               $response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";                $response = "Nightly additions based on classlist changes now <b>enabled</b><br/>";
           }             }
       } else {        } else {
           if ($curradds) {            if ($curradds) {
               $response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";                $response = "Nightly additions based on classlist changes now <b>disabled</b><br/>";
Line 919  sub print_chgsettings_response { Line 970  sub print_chgsettings_response {
               $response .= "Nightly removals based on classlist changes still <b>disabled</b>";                $response .= "Nightly removals based on classlist changes still <b>disabled</b>";
           }            }
       }        }
         if ($autoadds || $autodrops) {
             $warning = &warning_message($dom,$crs,$action);
             $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you indicated that nightly ";
             $warn_suffix = " should be enabled, additional action is required.<br/>";
         }
         if ($autoadds) {
             if ($autodrops) {
                 $warnfiller = "adds and drops";
             } else {
                 $warnfiller = "adds";
             }
         } else {
             if ($autodrops) {
                 $warnfiller = "drops";
             }
         }
         unless ($warning eq '') {
             $response = $warn_prefix.$warnfiller.$warn_suffix.$warning;
         }
   }    }
   &print_reply($r,$response,$$tasktitleref{$action});    &print_reply($r,$response,$$tasktitleref{$action});
   return;    return;
Line 933  sub print_setdates_response { Line 1003  sub print_setdates_response {
   my ($autostart,$autoend) = &get_dates_from_form();    my ($autostart,$autoend) = &get_dates_from_form();
   my $showstart = localtime($autostart);    my $showstart = localtime($autostart);
   my $showend = '';    my $showend = '';
     my $warning = '';
     my $warn_prefix = '';
   if ($autoend) {    if ($autoend) {
       $showend = localtime($autoend);        $showend = localtime($autoend);
   } else {    } else {
Line 953  sub print_setdates_response { Line 1025  sub print_setdates_response {
       if ($currend == $autoend) {        if ($currend == $autoend) {
           $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";            $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
       } else {        } else {
           $response .= "The last date for enrollment has been left unchanged as $showend.<br/>";            $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
       }        }
     
 # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.  # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.
Line 971  sub print_setdates_response { Line 1043  sub print_setdates_response {
       my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);        my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
       my $nextmidnt = 86400 + $lastmidnt;        my $nextmidnt = 86400 + $lastmidnt;
   
       my $todayupdate = timelocal(0,40,4,$date_list[3],$date_list[4],$date_list[5]);        my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
       my $lastupdate = $todayupdate - 86400;        my $lastupdate = $todayupdate - 86400;
       if ($nowstamp < $todayupdate) {        if ($nowstamp < $todayupdate) {
           $nextupdate = "today";            $nextupdate = "today";
Line 988  sub print_setdates_response { Line 1060  sub print_setdates_response {
               $firstaccess = "a date prior to today";                $firstaccess = "a date prior to today";
           }            }
           if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {            if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
               $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 4.40 am $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>|;                $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 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>|;
           }            }
       }        }
         $warning = &warning_message($dom,$crs,$action);
         $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you set a start and end date for auto-enrollment, additional action is required.<br/>";
         unless ($warning eq '') {
             $response .= $warn_prefix.$warning;
         }
   }    }
   &print_reply($r,$response,$$tasktitleref{$action});    &print_reply($r,$response,$$tasktitleref{$action});
   return;    return;
Line 1006  sub print_notify_response { Line 1083  sub print_notify_response {
   my @currpeople = ();    my @currpeople = ();
   my $notify = 0;    my $notify = 0;
   my @people = ();    my @people = ();
     my $peoplestr = "";
     my $response = "";
     my $noprocess = 0;
   
   if ($notifylist =~ m/,/) {    if ($notifylist =~ m/,/) {
       @currpeople = split/,/,$notifylist;        @currpeople = split/,/,$notifylist;
   } else {    } else {
       @currpeople = $notifylist;        $currpeople[0] = $notifylist;
   }    }
   my $currcount = 0;    my $currcount = 0;
   foreach  (@currpeople) {    foreach  (@currpeople) {
Line 1019  sub print_notify_response { Line 1099  sub print_notify_response {
   
   if ( exists($ENV{'form.notify'}) ) {    if ( exists($ENV{'form.notify'}) ) {
       $notify=$ENV{'form.notify'};        $notify=$ENV{'form.notify'};
   }   
   if ( exists($ENV{'form.notifylist'}) ) {  
         if (ref($ENV{'form.notifylist'})) {  
             @people=@{ $ENV{'form.notifylist'} };  
         } else {  
             $people[0]=$ENV{'form.notifylist'};  
         }  
   }    }
   my $response = "";    if ( exists($ENV{'form.notifyshow'}) ) {
   my $peoplestr = "";        my $notifyshow = $ENV{'form.notifyshow'};
   if ($notify) { $peoplestr = join(",",@people); }        for (my $i=0; $i<$notifyshow; $i++) {
   my %cenv = ('internal.notifylist' => $peoplestr);            if ( exists($ENV{"form.note_$i"}) ) {
   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);                if ( exists($ENV{"form.notifyname_$i"}) ) {
   if ($reply !~ /^ok$/) {                    unless ( $ENV{"form.notifyname_$i"} eq '' ) {
        $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";                          push @people, $ENV{"form.notifyname_$i"};
                     }
                 }
             }
         }
         if ($notify) { $peoplestr = join(",",@people); }
   } else {    } else {
       if ($notify) {        if ($notify) {
           if (@people) {             if ($currcount) {
               if ($currcount) {                $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/>.";
                   $response = "Notification of enrollment changes still <b>enabled</b><br/>";                $peoplestr = $notifylist;
               } else {                @people = @currpeople;
                   $response = "Notification of enrollment changes now <b>enabled</b><br/>";                $noprocess = 1;
               }  
               $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";  
               foreach my $person (@people) {  
                   $response .= "<li>$person</li>\n";  
               }  
               $response .= "</ul>\n";  
           } else {  
               $response = "Notification of enrollment changes was <b> not enabled</b> as no course coordinators were selected as recipients.<br/>";  
           }            }
         }
     }
     unless ($noprocess == 1) {
         my %cenv = ('internal.notifylist' => $peoplestr);
         my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
         if ($reply !~ /^ok$/) {
              $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.<br/>";
       } else {        } else {
           if ($currcount) {             if ($notify) {
               $response = "Notification of enrollment changes now <b>disabled</b><br/>";                if (@people) {
                     if ($currcount) {
                         $response .= "Notification of enrollment changes still <b>enabled</b><br/>";
                     } else {
                         $response .= "Notification of enrollment changes now <b>enabled</b><br/>";
                     }
                     $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";
                     foreach my $person (@people) {
                         $response .= "<li>$person</li>\n";
                     }
                     $response .= "</ul>\n";
                 } else {
                     $response = "Notification of enrollment changes was <b> not enabled</b> as no course coordinators were selected as recipients.<br/>";
                 }
           } else {            } else {
               $response = "Notification of enrollment changes still <b>disabled</b><br/>";                if ($currcount) {
                     $response = "Notification of enrollment changes now <b>disabled</b><br/>";
                 } else {
                     $response = "Notification of enrollment changes still <b>disabled</b><br/>";
                 }
           }            }
       }        }
   }    }
Line 1064  the nightly enrollment check: <br/><ul>\ Line 1157  the nightly enrollment check: <br/><ul>\
 }  }
   
 sub print_crosslistings_menu () {  sub print_crosslistings_menu () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);
   my @currxlists = ();    my @currxlists = ();
   my @xlists = ();    my @xlists = ();
Line 1110  sub print_crosslistings_menu () { Line 1203  sub print_crosslistings_menu () {
       $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";        $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
   } else {    } else {
       if ($removecount > 0) {        if ($removecount > 0) {
           $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br>/<br/>";            $response = "A total of $removecount courses are no longer crosslisted with LON-CAPA course: $realm ($coursecode).<br/><br/>";
       }        }
       if ($crosscount > 0) {        if ($crosscount > 0) {
           $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";            $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";
Line 1167  sub print_crosslistings_menu () { Line 1260  sub print_crosslistings_menu () {
 }  }
   
 sub print_crosslistings_response () {  sub print_crosslistings_response () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currxlists = ();    my @currxlists = ();
   my @xlists = ();    my @xlists = ();
   my @allxlists = ();    my @allxlists = ();
     my @badxlists = ();
     my @badowner = ();
   my $numcross = 0;    my $numcross = 0;
   my $xliststr =  $settings{'internal.crosslistings'};    my $xliststr =  $settings{'internal.crosslistings'};
   my $coursecode = $settings{'internal.coursecode'};    my $coursecode = $settings{'internal.coursecode'};
     my $owner = $settings{'internal.courseowner'};
   my $response = '';    my $response = '';
     my $warning = '';
     my $warn_prefix = '';
   
   if ($xliststr =~ m/,/) {    if ($xliststr =~ m/,/) {
       @allxlists = split/,/,$xliststr;        @allxlists = split/,/,$xliststr;
Line 1192  sub print_crosslistings_response () { Line 1290  sub print_crosslistings_response () {
           my $xl = "newcross_".$i;            my $xl = "newcross_".$i;
           my $gp = "newgroupid_".$i;            my $gp = "newgroupid_".$i;
           if ( exists($ENV{"form.$xl"}) ) {            if ( exists($ENV{"form.$xl"}) ) {
               push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};                my $coursecheck = '';
   #              if ($homeserver eq $server) {
   #                  $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"});
   #              } else {
                     $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$ENV{"form.$xl"});
   #              }
                 if ($coursecheck eq 'ok') {
                     my $addcheck = '';
   #                  if ($homeserver eq $server) {
   #                      $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner);
   #                  } else {
                         $addcheck = &Apache::lonnet::auto_new_course($homeserver,$ENV{"form.$xl"},$owner);
   #                  }
                     if ($addcheck eq 'ok') {
                        push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                     } else {
                        push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"};
                     }
                 } else {
                     push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                 }
           }            }
       }        }
       push @allxlists, @xlists;        push @allxlists, @xlists;
Line 1208  sub print_crosslistings_response () { Line 1326  sub print_crosslistings_response () {
       my %cenv = ('internal.crosslistings' => $xliststr);        my %cenv = ('internal.crosslistings' => $xliststr);
       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);        my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
       if ($reply !~ /^ok$/) {        if ($reply !~ /^ok$/) {
           $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";            $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
       } else {        } else {
           $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";            $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";
             foreach (@allxlists) {
                 my ($xlist,$gp) = split/:/,$_;
                 $response .= "<li>$xlist - ID: $gp</li>\n";
             }
             $response .= "</ul><br/><br/>\n";
       }        }
     } else {
         if ($xliststr =~ m/:/) {
             my @oldxlists = ();
             if ($xliststr =~ m/,/) {
                 @oldxlists = split/,/,$xliststr;
             } else {
                 $oldxlists[0] = $xliststr;
             }
             $response .= "Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.<br/><ul>\n";
             foreach (@oldxlists) {
                 my ($xlist,$gp) = split/:/,$_;
                 $response .= "<li>$xlist - ID: $gp</li>\n";
             }
             $response .= "</ul><br/><br/>\n";
         }
     }
     if (@badxlists > 0) {
         $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";
         foreach (@badxlists) {
             my ($xlist,$gp,$prob) = split/:/,$_;
             $response .= "<li>$xlist - ID: $gp - Error: $prob</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
     }
   
     if (@badowner > 0) {
         $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";
         foreach (@badowner) {
             my ($xlist,$gp) = split/:/,$_;
             $response .= "<li>$xlist - ID: $gp</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
   }    }
   
   foreach (@allxlists) {    if (@allxlists > 0) {
       my ($xlist,$gp) = split/:/,$_;        $warning = &warning_message($dom,$crs,$action);
       $response .= "<li>$xlist - ID: $gp</li>\n";        $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected crosslisted courses to contribute enrollment to this course, additional action is required.<br/>";
         unless ($warning eq '') {
             $response .= $warn_prefix.$warning;
         }
   }    }
   $response .= "</ul><br/>\n";  
   
   &print_reply($r,$response,$$tasktitleref{$action});    &print_reply($r,$response,$$tasktitleref{$action});
   return;    return;
 }  }
   
 sub print_sections_menu () {  sub print_sections_menu () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currsections = ();    my @currsections = ();
   my @sections = ();    my @sections = ();
     my @badowner = ();
     my @badsections = ();
   my $seccount = 0;    my $seccount = 0;
   my $removecount = 0;    my $removecount = 0;
     my $addcount = 0;
   my $secstr = '';    my $secstr = '';
   my $response = '';    my $response = '';
     my $warning = "";
     my $warn_prefix = "";
   my $coursecode = $settings{'internal.coursecode'};    my $coursecode = $settings{'internal.coursecode'};
     my $owner = $settings{'internal.courseowner'};
   if ($settings{'internal.sectionnums'} =~ m/,/) {    if ($settings{'internal.sectionnums'} =~ m/,/) {
       @currsections = split/,/,$settings{'internal.sectionnums'};        @currsections = split/,/,$settings{'internal.sectionnums'};
   } elsif ($settings{'internal.sectionnums'} ne '') {    } elsif ($settings{'internal.sectionnums'} ne '') {
       $currsections[0] = $settings{'internal.sectionnums'};        $currsections[0] = $settings{'internal.sectionnums'};
   }    }
                                                                                                        
   if (@currsections > 0) {    if ( exists($ENV{'form.secshow'}) ) {
         for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
             my $gp = "loncapasec_".$i;
             my $secnum = "secnum_".$i;
             my $sec = "sec_".$i;
             if ( exists( $ENV{"form.$sec"} ) ) {
                 my $secentry;
                 if ( exists( $ENV{"form.$secnum"} ) ) { 
                     $secentry = $ENV{"form.$secnum"}.':';
                 }
                 if ( exists( $ENV{"form.$gp"} ) ) {
                     $secentry .= $ENV{"form.$gp"};
                 }
                 if ( grep/^$ENV{"form.$secnum"}:/,@currsections) {
                     push @sections, $secentry;
                     $seccount ++;
                 } else {
                     my $newsec = $coursecode.$ENV{"form.$secnum"};
                     my $coursecheck = '';
   #                  if ($homeserver eq $server) {
   #                      $coursecheck = &localenroll::validate_courseID($newsec);
   #                  } else  {
                         $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
   #                  }
                     if ($coursecheck eq 'ok') {
                         my $addcheck = '';
   #                      if ($homeserver eq $server) {
   #                          $addcheck = &localenroll::new_course($newsec,$owner);
   #                      } else {
                             $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
   #                      }
                         if ($addcheck eq 'ok') {
                             push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                             $seccount ++;
                             $addcount ++;
                         } else {
                             push @badowner,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
                         }
                     } else {
                         push @badsections, $ENV{"form.$secnum"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                     }
                 }
             }
         }
         if (@currsections > 0) {
             for (my $i=0; $i<@currsections; $i++) {
                 if ($currsections[$i] =~ m/^(\w+:)/ ) {
                     my $oldsec  = $1;
                     unless (grep/^$oldsec/,@sections) {
                         $removecount ++;
                     }
                 }
             }
         }
     } elsif (@currsections > 0) {
       for (my $i=0; $i<@currsections; $i++) {        for (my $i=0; $i<@currsections; $i++) {
           my $sec = "sec_".$i;            my $sec = "sec_".$i;
           my $gp = "secgp_".$i;            my $gp = "secgp_".$i;
           if ( exists($ENV{"form.$sec"}) ) {            if ( exists($ENV{"form.$sec"}) ) {
               my $secentry = '';                my $secentry = '';
               if ($currsections[$i] =~ m/^(\w+:)/) {                if ($currsections[$i] =~ m/^(\w+:)/ ) {
                   $secentry = $1;                    $secentry = $1;
               }                }
               if ( exists($ENV{"form.$gp"}) ) {                if ( exists($ENV{"form.$gp"}) ) {
Line 1273  sub print_sections_menu () { Line 1490  sub print_sections_menu () {
       if ($removecount > 0) {        if ($removecount > 0) {
           $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/>";            $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/>";
       }        }
         if ($addcount > 0) {
             $response .= "A total of $addcount sections have been added to the list of
   sections which contribute to enrollment in LON-CAPA course: $realm ($coursecode).<br/><br/>";
         }
       if ($seccount > 0) {         if ($seccount > 0) { 
           $response .= "Students enrolling in the $seccount section(s) listed below will continue to be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.<br/><ul>\n";            $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";
           foreach (@sections) {            foreach (@sections) {
               my ($sec,$gp) = split/:/,$_;                my ($sec,$gp) = split/:/,$_;
               $response .= "<li>$sec  - ID: $gp</li>\n";                $response .= "<li>$sec  - ID: $gp</li>\n";
Line 1283  sub print_sections_menu () { Line 1504  sub print_sections_menu () {
       }        }
   }    }
   
     if (@badsections > 0) {
         $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";
         foreach (@badsections) {
             my ($secnum,$gp,$prob) = split/:/,$_;
             $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
     }
   
     if (@badowner > 0) {
         $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";
         foreach (@badowner) {
             my ($secnum,$gp) = split/:/,$_;
             $response .= "<li>$secnum - ID: $gp</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
     }
   
     if ($seccount > 0) {
         $warning = &warning_message($dom,$crs,$action);
         $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected sections to contribute enrollment to this course, additional action is required.<br/>";
         unless ($warning eq '') {
             $response .= $warn_prefix.$warning;
         }
     }
   
   if ( exists($ENV{'form.numsec'}) ) {    if ( exists($ENV{'form.numsec'}) ) {
       my $numsec = $ENV{'form.numsec'};        my $numsec = $ENV{'form.numsec'};
       if ($numsec > 0) {        if ($numsec > 0) {
Line 1329  sub print_sections_menu () { Line 1576  sub print_sections_menu () {
 }  }
   
 sub print_sections_response () {  sub print_sections_response () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
   my @currsections = ();    my @currsections = ();
   my @sections = ();    my @sections = ();
   my @allsections = ();    my @allsections = ();
     my @badowner = ();
     my @badsections = ();
   my $numsec = 0;    my $numsec = 0;
   my $secstr =  $settings{'internal.sectionnums'};    my $secstr =  $settings{'internal.sectionnums'};
   my $coursecode = $settings{'internal.coursecode'};    my $coursecode = $settings{'internal.coursecode'};
     my $owner = $settings{'internal.courseowner'};
   my $response = '';    my $response = '';
                                                                                                          my $putreply = '';
     my $warning = '';
     my $warn_prefix = '';
   if ($secstr =~ m/,/) {    if ($secstr =~ m/,/) {
       @allsections = split/,/,$secstr;        @allsections = split/,/,$secstr;
   } else {    } else {
Line 1348  sub print_sections_response () { Line 1600  sub print_sections_response () {
   if ( exists($ENV{'form.numsec'}) ) {    if ( exists($ENV{'form.numsec'}) ) {
       $numsec = $ENV{'form.numsec'};        $numsec = $ENV{'form.numsec'};
   }    }
                                                                                                        
   if ($numsec > 0) {    if ($numsec > 0) {
       for (my $i=0; $i<$numsec; $i++) {        for (my $i=0; $i<$numsec; $i++) {
           my $sec = "newsec_".$i;            my $sec = "newsec_".$i;
           my $gp = "newsecgp_".$i;            my $gp = "newsecgp_".$i;
           if ( exists($ENV{"form.$sec"}) ) {            if ( exists($ENV{"form.$sec"}) ) {
               push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};                unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) {
                     my $newsec = $coursecode.$ENV{"form.$sec"};
                     my $coursecheck = '';
   #                  if ($homeserver eq $server) {
   #                      $coursecheck = &localenroll::validate_courseID($newsec);
   #                  } else {
                         $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec);
   #                  }
                     if ($coursecheck eq 'ok') {
                         my $addcheck = '';
   #                      if ($homeserver eq $server) {
   #                          $addcheck = &localenroll::new_course($newsec,$owner);
   #                      } else {
                             $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner);
   #                      }
                         if ($addcheck eq 'ok') {
                             push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                         } else {
                             push @badowner,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
                         }
                     } else {
                         push @badsections, $ENV{"form.$sec"}.":".$ENV{"form.$gp"}.":".$coursecheck;
                     }
                 }
           }            }
       }        }
       push @allsections, @sections;        push @allsections, @sections;
   }    }
                                                                                                        
   if (@sections > 0 ) {    if (@sections > 0 ) {
       unless ($secstr eq '') { $secstr .= ","; }         unless ($secstr eq '') { $secstr .= ","; } 
       if (@sections > 1) {        if (@sections > 1) {
Line 1368  sub print_sections_response () { Line 1643  sub print_sections_response () {
           $secstr .= $sections[0];            $secstr .= $sections[0];
       }        }
       my %cenv = ('internal.sectionnums' => $secstr);        my %cenv = ('internal.sectionnums' => $secstr);
       my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);        $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
       if ($reply !~ /^ok$/) {        if ($putreply !~ /^ok$/) {
           $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";            $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/><br/>";
       } else {  
           $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";  
       }        }
   }    }
                                                                                                        
   foreach (@allsections) {    if ($putreply =~ /^ok/) {
       my ($sec,$gp) = split/:/,$_;        $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";
       $response .= "<li>$sec - ID: $gp</li>\n";        foreach (@allsections) {
             my ($sec,$gp) = split/:/,$_;
             $response .= "<li>$sec - ID: $gp</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
   }    }
   $response .= "</ul><br/>\n";  
                                                                                                          if (@badsections > 0) {
         $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";
         foreach (@badsections) {
             my ($secnum,$gp,$prob) = split/:/,$_;
             $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
     }
   
     if (@badowner > 0) {
         $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";
         foreach (@badowner) {
             my ($secnum,$gp) = split/:/,$_;
             $response .= "<li>$secnum - ID: $gp</li>\n";
         }
         $response .= "</ul><br/><br/>\n";
     }
   
     if (@allsections > 0) {
         $warning = &warning_message($dom,$crs,$action);
         $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have selected sections to contribute enrollment to this course, additional action is required.<br/>";
         unless ($warning eq '') {
             $response .= $warn_prefix.$warning;
         }
     }
   
   &print_reply($r,$response,$$tasktitleref{$action});    &print_reply($r,$response,$$tasktitleref{$action});
   return;    return;
 }  }
Line 1394  sub print_photos_response () { Line 1696  sub print_photos_response () {
   if ( exists($ENV{'form.showphotos'}) ) {    if ( exists($ENV{'form.showphotos'}) ) {
       $showphotos=$ENV{'form.showphotos'};        $showphotos=$ENV{'form.showphotos'};
   }    }
                                                                                               
   my $response = "";    my $response = "";
   my %cenv = ('internal.showphotos' => $showphotos);    my %cenv = ('internal.showphotos' => $showphotos);
   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);    my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
Line 1420  sub print_photos_response () { Line 1722  sub print_photos_response () {
 }  }
   
 sub print_update_result () {  sub print_update_result () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;    my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_;
   my $response = '';    my $response = '';
   my $updateadds = 0;    my $updateadds = 0;
   my $updatedrops = 0;    my $updatedrops = 0;
Line 1430  sub print_update_result () { Line 1732  sub print_update_result () {
   my @allcourses = ();    my @allcourses = ();
   my %LC_code = ();    my %LC_code = ();
   my $logmsg = '';    my $logmsg = '';
     my $newusermsg = '';
   
   my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.autostart','internal.autoend'],$dom,$crs);    my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.autostart','internal.autoend'],$dom,$crs);
   my $coursecode = $settings{'internal.coursecode'};    my $coursecode = $settings{'internal.coursecode'};
Line 1491  sub print_update_result () { Line 1794  sub print_update_result () {
   
       if (@allcourses > 0) {        if (@allcourses > 0) {
           @{$affiliates{$crs}} = @allcourses;            @{$affiliates{$crs}} = @allcourses;
           &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);  #          if ($homeserver eq $server) {
   #              &localenroll::fetch_enrollment($dom,\%affiliates,\%reply);
   #          } else {
                 &Apache::lonnet::fetch_enrollment_query($homeserver,$dom,\%affiliates,\%reply);
   #          }
           if ($reply{$crs} > 0) {            if ($reply{$crs} > 0) {
               ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,"updatenow");                ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
               unless ($changecount == 0) {  
                   my $responselength = length($response);  
                   $response = substr($response,0,$responselength-4);  
               }  
           } else {            } else {
               $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.";                $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.";
           }              }  
Line 1510  sub print_update_result () { Line 1813  sub print_update_result () {
       $logmsg = substr($logmsg,0,$loglength-4);        $logmsg = substr($logmsg,0,$loglength-4);
       $logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";        $logmsg = "<br/><br/>The following messages were generated by the roster update process: <br/><ul><li>".$logmsg."</ul><br/>";
   }    }
   $response .= $logmsg;    unless ($newusermsg eq '') {
         $newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
         $newusermsg = "<br/><br/>The following new system user(s) who was/were created will be using 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/>";
     }
     $response .= $logmsg.$newusermsg;
   &print_reply($r,$response,$$tasktitleref{$action});    &print_reply($r,$response,$$tasktitleref{$action});
   return;    return;
 }  }
   
   sub warning_message {
       my ($dom,$crs,$caller) = @_;
       my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs);
       my $currend = '';
       my $currstart = '';
       my $currsecs = '';
       my $currxlists = '';
       my $warning = '';
       my $curradds = '';
       my $currdrops = '';
       if ( defined($settings{'internal.autoadds'}) ) {
           $curradds = $settings{'internal.autoadds'};
       }
       if (defined($settings{'internal.autodrops'}) ) {
           $currdrops = $settings{'internal.autodrops'};
       }
       if ( defined($settings{'internal.autostart'}) ) {
           $currstart = $settings{'internal.autostart'};
       }
       if ( defined($settings{'internal.autoend'}) ) {
           $currend = $settings{'internal.autoend'};
       }
       if ( defined($settings{'internal.sectionnums'}) ) {
           $currsecs = $settings{'internal.sectionnums'};
       }
       if ( defined($settings{'internal.crosslistings'}) ) {
           $currxlists = $settings{'internal.crosslistings'}
       }
       unless ($caller eq 'setdates') {
           if ( ($currstart eq '') && ($currend eq '') )  {
               $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>";
           }
       }
       unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) {
           if ( ($currsecs eq '') && ($currxlists eq '') ) {
               $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/>";
           }
       }
       unless ( $caller eq 'chgsettings') {
           if ( (!$curradds) && (!$currdrops) ) {
               $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/>.";
           }
       }
       return $warning;
   }
   
 sub print_reply () {  sub print_reply () {
   my ($r,$response,$caller) = @_;    my ($r,$response,$caller) = @_;
   $r->print("    $r->print("
Line 1530  sub print_reply () { Line 1883  sub print_reply () {
   
 sub setup_date_selectors {  sub setup_date_selectors {
     my ($starttime,$endtime) = @_;      my ($starttime,$endtime) = @_;
     if ($endtime == 0) {  
         $endtime = 1999915200;  
     }  
     if (! defined($starttime)) {      if (! defined($starttime)) {
         $starttime = time;          $starttime = time;
         if (exists($ENV{'course.'.$ENV{'request.course.id'}.          if (exists($ENV{'course.'.$ENV{'request.course.id'}.
Line 1689  sub handler { Line 2039  sub handler {
             }              }
         }          }
     }      }
   
   # Determine course home server and current server
       my $homeserver = &Apache::lonnet::homeserver($crs,$dom);
       my $server = $Apache::lonnet::perlvar{'lonHostID'};
       
     my $reply = 0;      my $reply = 0;
     unless ($state eq "choose") { $reply = 1; }      unless ($state eq "choose") { $reply = 1; }
Line 1697  sub handler { Line 2051  sub handler {
     &print_navmenu($r,\@tasks,\%tasklong);      &print_navmenu($r,\@tasks,\%tasklong);
           
     if (($state eq "choose") || ($action eq "information")) {      if (($state eq "choose") || ($action eq "information")) {
         &print_main_frame($r,$realm,$dom,$crs,\%tasktitle);          &print_main_frame($r,$realm,$dom,$crs,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "chgsettings") {      } elsif ($action eq "chgsettings") {
         &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "setdates") {      } elsif ($action eq "setdates") {
Line 1705  sub handler { Line 2059  sub handler {
     } elsif ($action eq "notify") {      } elsif ($action eq "notify") {
         &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "sections") {      } elsif ($action eq "sections") {
         &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "crosslist") {      } elsif ($action eq "crosslist") {
         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "updatenow") {      } elsif ($action eq "updatenow") {
         &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     } elsif ($action eq "photos") {      } elsif ($action eq "photos") {
         &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle);
     } elsif ($action eq "newcross") {      } elsif ($action eq "newcross") {
         &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle);              &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);    
     } elsif ($action eq "newsections") {      } elsif ($action eq "newsections") {
         &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle);          &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server);
     }      }
     &print_doc_base($r);        &print_doc_base($r);  
     return OK;      return OK;

Removed from v.1.4  
changed lines
  Added in v.1.12


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