--- loncom/interface/lonpopulate.pm 2003/12/15 07:55:59 1.7 +++ loncom/interface/lonpopulate.pm 2004/04/16 13:26:44 1.11 @@ -1,5 +1,5 @@ # automated enrollment configuration handler -# $Id: lonpopulate.pm,v 1.7 2003/12/15 07:55:59 raeburn Exp $ +# $Id: lonpopulate.pm,v 1.11 2004/04/16 13:26:44 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -329,17 +329,29 @@ Note: Any students added manually by cou "); } elsif ($action eq "setdates") { my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend}); - my $oldstartshow = localtime($enrollvar{autostart}); - my $oldendshow = localtime($enrollvar{autoend}); - if ($enrollvar{autoend} == 0) { - $oldendshow = "No ending date"; + my $oldstartshow = ''; + my $oldendshow = ''; + if ( defined($enrollvar{autostart}) ) { + $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 = "
Warning. Currently NO first enrollment or last enrollment dates are set. You must 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: $oldstartshow, Last enrollment: $oldendshow\n"; } $r->print(<
-
$$tasktitleref{$action}
- Currently: First enrollment: $oldstartshow, Last enrollment: $oldendshow +
$$tasktitleref{$action}

+ $dateshow
@@ -645,9 +657,8 @@ ENDTWO } } if (@sections > 0) { - if (@sections > 1) { - my $secshow = @sections; - $r->print(" + my $secshow = @sections; + $r->print("

@@ -669,27 +680,27 @@ your changes. - "); - for (my $i=0; $i<@sections; $i++) { - my $colflag = $i%2; - my $shrflag = 0; - $r->print(" + "); + for (my $i=0; $i<@sections; $i++) { + my $colflag = $i%2; + my $shrflag = 0; + $r->print(""); - } else { - $r->print(""); - } + "); + if (grep/^$sections[$i]$/,@currsections) { + $r->print("Enrollment active"); + $shrflag = 1; + } else { + $r->print("Enrollment inactive"); } - $r->print(" + if ($shrflag) { + $r->print(""); + } else { + $r->print(""); + } + } + $r->print("
LON-CAPA section/group ID Enrollment in this course?
$sections[$i] - "); - if (grep/^$sections[$i]$/,@currsections) { - $r->print("Enrollment active"); - $shrflag = 1; - } else { - $r->print("Enrollment inactive"); - } - if ($shrflag) { - $r->print("

@@ -703,23 +714,7 @@ your changes. - "); - } else { - $r->print("
-
- - - -
- $$tasktitleref{$action}
-
- - - - -
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.
- "); - } + "); } else { $r->print("

@@ -902,9 +897,31 @@ ENDBASE ################################################################### sub print_chgsettings_response { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops'],$dom,$crs); - my $curradds = $settings{'internal.autoadds'}; - my $currdrops = $settings{'internal.autodrops'}; + my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs); + my $currend = ''; + 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 $autodrops = ''; @@ -916,6 +933,10 @@ sub print_chgsettings_response { } my $response = ""; + my $warning = ""; + my $warn_prefix = ""; + my $warn_suffix = ""; + my $warnfiller = ""; my %cenv = ('internal.autoadds' => $autoadds, 'internal.autodrops' => $autodrops); my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); @@ -927,7 +948,7 @@ sub print_chgsettings_response { $response = "Nightly additions based on classlist changes still enabled
"; } else { $response = "Nightly additions based on classlist changes now enabled
"; - } + } } else { if ($curradds) { $response = "Nightly additions based on classlist changes now disabled
"; @@ -948,6 +969,25 @@ sub print_chgsettings_response { $response .= "Nightly removals based on classlist changes still disabled"; } } + if ($autoadds || $autodrops) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you indicated that nightly "; + $warn_suffix = " should be enabled, additional action is required.
"; + } + 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}); return; @@ -962,6 +1002,8 @@ sub print_setdates_response { my ($autostart,$autoend) = &get_dates_from_form(); my $showstart = localtime($autostart); my $showend = ''; + my $warning = ''; + my $warn_prefix = ''; if ($autoend) { $showend = localtime($autoend); } else { @@ -982,7 +1024,7 @@ sub print_setdates_response { if ($currend == $autoend) { $response .= "The last date for automated enrollment has been left unchanged as $showend.
"; } else { - $response .= "The last date for enrollment has been left unchanged as $showend.
"; + $response .= "The last date for automated enrollment has been changed to $showend.
"; } # Generate message in case where old first access date was later than today, but new first access date is now today or earlier. @@ -1000,7 +1042,7 @@ sub print_setdates_response { my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]); 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; if ($nowstamp < $todayupdate) { $nextupdate = "today"; @@ -1017,9 +1059,14 @@ sub print_setdates_response { $firstaccess = "a date prior to today"; } if (($nowstamp >= $autostart) && ($rosterupdated == 0)) { - $response .= qq|
Although you have now set the first enrollment date to $firstaccess, automatic enrollment will not 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 roster update page.
|; + $response .= qq|
Although you have now set the first enrollment date to $firstaccess, automatic enrollment will not 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 roster update page.
|; } } + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you set a start and end date for auto-enrollment, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } } &print_reply($r,$response,$$tasktitleref{$action}); return; @@ -1224,6 +1271,8 @@ sub print_crosslistings_response () { my $coursecode = $settings{'internal.coursecode'}; my $owner = $settings{'internal.courseowner'}; my $response = ''; + my $warning = ''; + my $warn_prefix = ''; if ($xliststr =~ m/,/) { @allxlists = split/,/,$xliststr; @@ -1309,21 +1358,34 @@ sub print_crosslistings_response () { $response .= "

\n"; } + if (@allxlists > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected crosslisted courses to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + &print_reply($r,$response,$$tasktitleref{$action}); return; } sub print_sections_menu () { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - 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 @sections = (); + my @badowner = (); + my @badsections = (); my $seccount = 0; my $removecount = 0; my $addcount = 0; my $secstr = ''; my $response = ''; + my $warning = ""; + my $warn_prefix = ""; my $coursecode = $settings{'internal.coursecode'}; + my $owner = $settings{'internal.courseowner'}; if ($settings{'internal.sectionnums'} =~ m/,/) { @currsections = split/,/,$settings{'internal.sectionnums'}; } elsif ($settings{'internal.sectionnums'} ne '') { @@ -1331,35 +1393,49 @@ sub print_sections_menu () { } 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"}; - } - push @sections, $secentry; - $seccount ++; - unless (grep/^$ENV{"form.$secnum"}:/,@currsections) { - $addcount ++; - } - } - } - if (@currsections > 0) { - for (my $i=0; $i<@currsections; $i++) { - if ($currsections[$i] =~ m/^(\w+:)/ ) { - my $oldsec = $1; - unless (grep/^$oldsec/,@sections) { - $removecount ++; - } - } - } - } + 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 = &localenroll::validate_courseID($newsec); + if ($coursecheck eq 'ok') { + my $addcheck = &localenroll::new_course($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++) { my $sec = "sec_".$i; @@ -1407,6 +1483,32 @@ sections which contribute to enrollment } } + 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.
    \n"; + foreach (@badsections) { + my ($secnum,$gp,$prob) = split/:/,$_; + $response .= "
  • $secnum - ID: $gp - Error: $prob
  • \n"; + } + $response .= "


\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.
    \n"; + foreach (@badowner) { + my ($secnum,$gp) = split/:/,$_; + $response .= "
  • $secnum - ID: $gp
  • \n"; + } + $response .= "


\n"; + } + + if ($seccount > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected sections to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + if ( exists($ENV{'form.numsec'}) ) { my $numsec = $ENV{'form.numsec'}; if ($numsec > 0) { @@ -1454,15 +1556,20 @@ sections which contribute to enrollment sub print_sections_response () { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - 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 @sections = (); my @allsections = (); + my @badowner = (); + my @badsections = (); my $numsec = 0; my $secstr = $settings{'internal.sectionnums'}; my $coursecode = $settings{'internal.coursecode'}; + my $owner = $settings{'internal.courseowner'}; my $response = ''; - + my $putreply = ''; + my $warning = ''; + my $warn_prefix = ''; if ($secstr =~ m/,/) { @allsections = split/,/,$secstr; } else { @@ -1472,18 +1579,31 @@ sub print_sections_response () { if ( exists($ENV{'form.numsec'}) ) { $numsec = $ENV{'form.numsec'}; } - + if ($numsec > 0) { for (my $i=0; $i<$numsec; $i++) { my $sec = "newsec_".$i; my $gp = "newsecgp_".$i; 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 = &localenroll::validate_courseID($newsec); + if ($coursecheck eq 'ok') { + my $addcheck = &localenroll::new_course($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; } - + if (@sections > 0 ) { unless ($secstr eq '') { $secstr .= ","; } if (@sections > 1) { @@ -1492,20 +1612,47 @@ sub print_sections_response () { $secstr .= $sections[0]; } my %cenv = ('internal.sectionnums' => $secstr); - my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); - if ($reply !~ /^ok$/) { - $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.
"; - } 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.
    \n"; + $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); + if ($putreply !~ /^ok$/) { + $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.

    "; } } - - foreach (@allsections) { - my ($sec,$gp) = split/:/,$_; - $response .= "
  • $sec - ID: $gp
  • \n"; + + if ($putreply =~ /^ok/) { + $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.
      \n"; + foreach (@allsections) { + my ($sec,$gp) = split/:/,$_; + $response .= "
    • $sec - ID: $gp
    • \n"; + } + $response .= "


    \n"; } - $response .= "

\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.
    \n"; + foreach (@badsections) { + my ($secnum,$gp,$prob) = split/:/,$_; + $response .= "
  • $secnum - ID: $gp - Error: $prob
  • \n"; + } + $response .= "


\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.
    \n"; + foreach (@badowner) { + my ($secnum,$gp) = split/:/,$_; + $response .= "
  • $secnum - ID: $gp
  • \n"; + } + $response .= "


\n"; + } + + if (@allsections > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected sections to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + &print_reply($r,$response,$$tasktitleref{$action}); return; } @@ -1518,7 +1665,7 @@ sub print_photos_response () { if ( exists($ENV{'form.showphotos'}) ) { $showphotos=$ENV{'form.showphotos'}; } - + my $response = ""; my %cenv = ('internal.showphotos' => $showphotos); my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); @@ -1640,6 +1787,52 @@ sub print_update_result () { 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 must now use Change enrollment dates to set a start date and an end date for the enrollment (or check the 'No end date' checkbox) for the nightly adds process to actually occur.

"; + } + } + unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) { + if ( ($currsecs eq '') && ($currxlists eq '') ) { + $warning .= "You must now use Section settings and/or Change crosslistings 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 NO sections or crosslisted courses that are affiliated with this course that are set to contribute to the automated enrollment process.

"; + } + } + unless ( $caller eq 'chgsettings') { + if ( (!$curradds) && (!$currdrops) ) { + $warning .= "You must now use Automated adds/drops to enable automated adds and/or drops if you want automatic enrollment updates to occur in this course.

."; + } + } + return $warning; +} + sub print_reply () { my ($r,$response,$caller) = @_; $r->print(" @@ -1655,9 +1848,6 @@ sub print_reply () { sub setup_date_selectors { my ($starttime,$endtime) = @_; - if ($endtime == 0) { - $endtime = 1999915200; - } if (! defined($starttime)) { $starttime = time; if (exists($ENV{'course.'.$ENV{'request.course.id'}.